use of cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupUpdated in project perun by CESNET.
the class GroupsManagerBlImpl method updateGroup.
@Override
public Group updateGroup(PerunSession sess, Group group) throws GroupExistsException {
// return group with correct updated name and shortName
group = getGroupsManagerImpl().updateGroup(sess, group);
getPerunBl().getAuditer().log(sess, new GroupUpdated(group));
List<Group> allSubgroups = this.getAllSubGroups(sess, group);
String[] groupNames = group.getName().split(":");
for (Group g : allSubgroups) {
String[] subGroupNames = g.getName().split(":");
for (int i = 0; i < groupNames.length; i++) {
if (!subGroupNames[i].equals(groupNames[i])) {
// this part of name changed
subGroupNames[i] = groupNames[i];
}
}
// create new name
StringBuilder sb = new StringBuilder();
for (String sgName : subGroupNames) {
sb.append(sgName).append(":");
}
// set name without last ":"
g.setName(sb.toString().substring(0, sb.length() - 1));
// for subgroups we must update whole name
getGroupsManagerImpl().updateGroupName(sess, g);
// create auditer message for every updated group
getPerunBl().getAuditer().log(sess, new GroupUpdated(g));
}
return group;
}
use of cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupUpdated in project perun by CESNET.
the class GroupsManagerBlImpl method updateGroupDescription.
/**
* Update group description.
*
* Method is used by group structure synchronization.
*
* @param sess
* @param groupWithOldDescription group with description which will be chaged
* @param groupWithNewDescription candidate group with description which will replace the old one
* @return true if description changed, false otherwise
* @throws InternalErrorException
*/
private boolean updateGroupDescription(PerunSession sess, Group groupWithOldDescription, CandidateGroup groupWithNewDescription) {
// If the old description is not null, compare it with the newDescription and update it if they differ
if (groupWithOldDescription.getDescription() != null) {
if (!groupWithOldDescription.getDescription().equals(groupWithNewDescription.asGroup().getDescription())) {
groupWithOldDescription.setDescription(groupWithNewDescription.asGroup().getDescription());
try {
groupsManagerImpl.updateGroup(sess, groupWithOldDescription);
} catch (GroupExistsException ex) {
throw new InternalErrorException("Unexpected exception when trying to modify group description!");
}
getPerunBl().getAuditer().log(sess, new GroupUpdated(groupWithOldDescription));
return true;
}
// If the new description is not null set the old description to new one
} else if (groupWithNewDescription.asGroup().getDescription() != null) {
groupWithOldDescription.setDescription(groupWithNewDescription.asGroup().getDescription());
try {
groupsManagerImpl.updateGroup(sess, groupWithOldDescription);
} catch (GroupExistsException ex) {
throw new InternalErrorException("Unexpected exception when trying to modify group description!");
}
getPerunBl().getAuditer().log(sess, new GroupUpdated(groupWithOldDescription));
return true;
}
return false;
}
use of cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupUpdated in project perun by CESNET.
the class GroupsManagerBlImpl method setSubGroupsNames.
/**
* Method sets subGroups names by their parent group
* Private method for moving groups
*
* @param sess perun session
* @param subGroups groups with same parent group
* @param parentGroup of subGroups
* @throws InternalErrorException
*/
private void setSubGroupsNames(PerunSession sess, List<Group> subGroups, Group parentGroup) {
for (Group subGroup : subGroups) {
subGroup.setName(parentGroup.getName() + ":" + subGroup.getShortName());
// we have to update each subGroup name in database
getGroupsManagerImpl().updateGroupName(sess, subGroup);
// create auditer message for every updated group
getPerunBl().getAuditer().log(sess, new GroupUpdated(subGroup));
setSubGroupsNames(sess, getSubGroups(sess, subGroup), subGroup);
}
}
Aggregations