Search in sources :

Example 1 with DirectMemberRemovedFromGroup

use of cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup in project perun by CESNET.

the class GroupsManagerBlImpl method removeDirectMember.

private void removeDirectMember(PerunSession sess, Group group, Member member) throws NotGroupMemberException, GroupNotExistsException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    lockGroupMembership(group, Collections.singletonList(member));
    Map<Integer, Map<Integer, MemberGroupStatus>> previousStatuses = getPreviousStatuses(sess, group, List.of(member));
    member.setSourceGroupId(group.getId());
    getGroupsManagerImpl().removeMember(sess, group, member);
    if (this.getGroupsManagerImpl().isGroupMember(sess, group, member)) {
        getPerunBl().getAuditer().log(sess, new DirectMemberRemovedFromGroup(member, group));
        // If member was indirect in group before, we don't need to change anything in other groups
        return;
    } else {
        notifyMemberRemovalFromGroup(sess, group, member);
        // remove all member-group attributes because member is not part of group any more
        try {
            getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, member, group);
        } catch (MemberGroupMismatchException e) {
            throw new InternalErrorException(e);
        }
        getPerunBl().getAuditer().log(sess, new MemberRemovedFromGroupTotally(member, group));
    }
    // check all relations with this group and call removeRelationMembers to reflect changes of removing member from group
    List<Integer> relations = groupsManagerImpl.getResultGroupsIds(sess, group.getId());
    for (Integer groupId : relations) {
        removeRelationMembers(sess, groupsManagerImpl.getGroupById(sess, groupId), Collections.singletonList(member), group.getId());
    }
    if (!VosManager.MEMBERS_GROUP.equals(group.getName())) {
        recalculateMemberGroupStatusRecursively(sess, member, group, previousStatuses);
    }
    if (!getGroupsManagerImpl().isGroupMember(sess, group, member)) {
        addMemberToGroupsFromTriggerAttribute(sess, group, member);
    }
}
Also used : DirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup) MemberGroupMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException) MemberRemovedFromGroupTotally(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberRemovedFromGroupTotally) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Aggregations

DirectMemberRemovedFromGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup)1 MemberRemovedFromGroupTotally (cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberRemovedFromGroupTotally)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 MemberGroupMismatchException (cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1