Search in sources :

Example 1 with GroupUpdated

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;
}
Also used : EnrichedGroup(cz.metacentrum.perun.core.api.EnrichedGroup) IndirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup) CandidateGroup(cz.metacentrum.perun.core.api.CandidateGroup) RichGroup(cz.metacentrum.perun.core.api.RichGroup) MemberExpiredInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup) MemberValidatedInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup) DirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup) Group(cz.metacentrum.perun.core.api.Group) DirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup) IndirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup) GroupUpdated(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupUpdated)

Example 2 with GroupUpdated

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;
}
Also used : GroupUpdated(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupUpdated) GroupExistsException(cz.metacentrum.perun.core.api.exceptions.GroupExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 3 with GroupUpdated

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);
    }
}
Also used : EnrichedGroup(cz.metacentrum.perun.core.api.EnrichedGroup) IndirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup) CandidateGroup(cz.metacentrum.perun.core.api.CandidateGroup) RichGroup(cz.metacentrum.perun.core.api.RichGroup) MemberExpiredInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup) MemberValidatedInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup) DirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup) Group(cz.metacentrum.perun.core.api.Group) DirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup) IndirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup) GroupUpdated(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupUpdated)

Aggregations

GroupUpdated (cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupUpdated)3 DirectMemberAddedToGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup)2 DirectMemberRemovedFromGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup)2 IndirectMemberAddedToGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup)2 IndirectMemberRemovedFromGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup)2 MemberExpiredInGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup)2 MemberValidatedInGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup)2 CandidateGroup (cz.metacentrum.perun.core.api.CandidateGroup)2 EnrichedGroup (cz.metacentrum.perun.core.api.EnrichedGroup)2 Group (cz.metacentrum.perun.core.api.Group)2 RichGroup (cz.metacentrum.perun.core.api.RichGroup)2 GroupExistsException (cz.metacentrum.perun.core.api.exceptions.GroupExistsException)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1