throw new PermissionException(msg);
}
@Override
public BundleGroup updateBundleGroup(Subject subject, BundleGroup bundleGroup) throws Exception {
BundleGroup attachedBundleGroup = entityManager.find(BundleGroup.class, bundleGroup.getId());
if (attachedBundleGroup == null) {
throw new IllegalArgumentException("Cannot update " + bundleGroup
+ ", because no bundle group exists with id [" + bundleGroup.getId() + "].");
}
// First update the simple fields and the permissions.
attachedBundleGroup.setName(bundleGroup.getName());
attachedBundleGroup.setDescription(bundleGroup.getDescription());
Set<Bundle> newBundles = bundleGroup.getBundles();
if (newBundles != null) {
// wrap in new HashSet to avoid ConcurrentModificationExceptions.
Set<Bundle> currentBundles = attachedBundleGroup.getBundles();
Set<Bundle> BundlesToRemove = new HashSet<Bundle>(currentBundles);
for (Bundle bg : newBundles) {
BundlesToRemove.remove(bg);
}
for (Bundle bg : BundlesToRemove) {
attachedBundleGroup.removeBundle(bg);
}
for (Bundle bg : newBundles) {
Bundle attachedBundle = entityManager.find(Bundle.class, bg.getId());
attachedBundleGroup.addBundle(attachedBundle);
}
}
// Fetch the lazy Set for the return
attachedBundleGroup.getBundles().size();
return attachedBundleGroup;
}