/** * This also updates the inverse relation (add this bundle group to role) * @param role */ public void addRole(Role role) { getRoles().add(role); role.addBundleGroup(this); }
/** * This also updates the inverse relation (remove this bundle group from role) * @param role * @return true if role was removed, otherwise false */ public boolean removeRole(Role role) { role.removeBundleGroup(this); return getRoles().remove(role); }
@Override @RequiredPermission(Permission.MANAGE_SECURITY) public void removeRolesFromBundleGroup(Subject subject, int bundleGroupId, int[] roleIds) { if ((roleIds != null) && (roleIds.length > 0)) { BundleGroup bundleGroup = entityManager.find(BundleGroup.class, bundleGroupId); if (bundleGroup == null) { throw new IllegalArgumentException("Could not find BundleGroup[" + bundleGroupId + "] in order to remove roles"); } bundleGroup.getRoles().size(); // load them in for (Integer roleId : roleIds) { Role doomedRole = entityManager.find(Role.class, roleId); if (doomedRole == null) { throw new IllegalArgumentException("Tried to remove role[" + roleId + "] from BundleGroup[" + bundleGroupId + "], but role was not found"); } doomedRole.removeBundleGroup(bundleGroup); } } return; }
@Override @RequiredPermission(Permission.MANAGE_SECURITY) public void addRolesToBundleGroup(Subject subject, int bundleGroupId, int[] roleIds) { if ((roleIds != null) && (roleIds.length > 0)) { BundleGroup bundleGroup = entityManager.find(BundleGroup.class, bundleGroupId); if (bundleGroup == null) { throw new IllegalArgumentException("Could not find bundleGroup[" + bundleGroupId + "] in order to add roles"); } bundleGroup.getRoles().size(); // load them in for (Integer roleId : roleIds) { Role role = entityManager.find(Role.class, roleId); if (role == null) { throw new IllegalArgumentException("Tried to add role[" + roleId + "] to bundleGroup[" + bundleGroupId + "], but role was not found"); } role.addBundleGroup(bundleGroup); } } return; }
@Override @RequiredPermission(Permission.MANAGE_BUNDLE_GROUPS) public void deleteBundleGroups(Subject subject, int[] bundleGroupIds) throws Exception { for (int bundleGroupId : bundleGroupIds) { BundleGroup bundleGroup = this.entityManager.find(BundleGroup.class, bundleGroupId); if (null == bundleGroup) { return; } // unassign any bundles assigned to the bundle group // wrap in new HashSet to avoid ConcurrentModificationExceptions. Set<Bundle> bundlesToRemove = new HashSet<Bundle>(bundleGroup.getBundles()); for (Bundle b : bundlesToRemove) { bundleGroup.removeBundle(b); } // remove from any roles for (Role r : bundleGroup.getRoles()) { r.removeBundleGroup(bundleGroup); } bundleGroup = entityManager.merge(bundleGroup); // now remove the bundle group entityManager.remove(bundleGroup); } }