@RequiredPermission(Permission.MANAGE_INVENTORY)
public ResourceGroup updateResourceGroup(Subject user, ResourceGroup group, RecursivityChangeType changeType,
boolean updateMembership) throws ResourceGroupUpdateException {
int groupId = group.getId();
ResourceGroup attachedGroup = entityManager.find(ResourceGroup.class, groupId);
if (attachedGroup == null) {
throw new ResourceGroupNotFoundException(groupId);
}
if (!authorizationManager.hasGroupPermission(user, Permission.MODIFY_RESOURCE, groupId)) {
throw new PermissionException("User [" + user
+ "] does not have permission to modify Resource group with id [" + groupId + "].");
}
//roles are not to be updated by this call but the group entity
//owns the relationship. Let's make sure we don't change the assigned roles here.
group.getRoles().clear();
group.getRoles().addAll(attachedGroup.getRoles());
if (changeType == null) {
changeType = RecursivityChangeType.None;
if (attachedGroup.isRecursive() == true && group.isRecursive() == false) {
// making a recursive group into a "normal" group
changeType = RecursivityChangeType.RemovedRecursion;
} else if (attachedGroup.isRecursive() == false && group.isRecursive() == true) {
// making a "normal" group into a recursive group
changeType = RecursivityChangeType.AddedRecursion;
} else {
// recursive bit didn't change
}
}
if (!updateMembership) {
group.setExplicitResources(attachedGroup.getExplicitResources());
group.setImplicitResources(attachedGroup.getImplicitResources());
}
group.setMtime(System.currentTimeMillis());
group.setModifiedBy(user.getName());
ResourceGroup newlyAttachedGroup = entityManager.merge(group);
if (changeType == RecursivityChangeType.AddedRecursion) {
newlyAttachedGroup.setRecursive(true);
enableRecursivityForGroup(user, groupId);
} else if (changeType == RecursivityChangeType.RemovedRecursion) {
newlyAttachedGroup.setRecursive(false);
clearImplicitResources(groupId);
makeImplicitMirrorExplicit(groupId);
}
if (updateMembership) {