} catch (GroupDefinitionException gde) {
throw new GroupDefinitionUpdateException(gde.getMessage());
}
RecursivityChangeType changeType = RecursivityChangeType.None;
GroupDefinition attachedGroupDefinition = null;
try {
attachedGroupDefinition = getById(groupDefinition.getId());
} catch (GroupDefinitionNotFoundException gdnfe) {
throw new GroupDefinitionUpdateException(gdnfe.getMessage());
}
if (groupDefinition.isRecursive() == true && attachedGroupDefinition.isRecursive() == false) {
// making a recursive group into a "normal" group
changeType = RecursivityChangeType.AddedRecursion;
} else if (groupDefinition.isRecursive() == false && attachedGroupDefinition.isRecursive() == true) {
// making a "normal" group into a recursive group
changeType = RecursivityChangeType.RemovedRecursion;
} else {
// recursive bit didn't change
}
if (nameChanged || changeType != RecursivityChangeType.None) {
String oldGroupDefinitionName = attachedGroupDefinition.getName();
Subject overlord = subjectManager.getOverlord();
for (ResourceGroup dynaGroup : attachedGroupDefinition.getManagedResourceGroups()) {
String dynaGroupName = dynaGroup.getName();
String newDynaGroupName = updateDynaGroupName(oldGroupDefinitionName, groupDefinition.getName(),
dynaGroupName);
dynaGroup.setName(newDynaGroupName);
// do not set recursive bit here
// the update method will figure out whether to flip it by inspecting its managing GroupDefinition
//dynaGroup.setRecursive(groupDefinition.isRecursive());
resourceGroupManager.updateResourceGroup(overlord, dynaGroup, changeType);
}
}
// do not call entityManager.merge, it could overwrite managed fields
// merge fields explicitly to control precisely which fields get updated
attachedGroupDefinition.setName(groupDefinition.getName());
attachedGroupDefinition.setDescription(groupDefinition.getDescription());
attachedGroupDefinition.setRecursive(groupDefinition.isRecursive());
attachedGroupDefinition.setExpression(groupDefinition.getExpression());
attachedGroupDefinition.setRecalculationInterval(groupDefinition.getRecalculationInterval());
if (detachFromCannedExpression) {
attachedGroupDefinition.setCannedExpression(null);
}
return attachedGroupDefinition;
}