Search in sources :

Example 1 with IndirectMemberRemovedFromGroup

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

the class GroupsManagerBlImpl method removeIndirectMembers.

/**
 * Remove records of the members with an INDIRECT membership type from the group.
 *
 * @param sess perun session
 * @param group group to remove records of INDIRECT members from
 * @param members list of members to remove
 * @param sourceGroupId id of a group from which members originate
 * @return list of members that were removed (their only record in the group was deleted)
 */
private List<Member> removeIndirectMembers(PerunSession sess, Group group, List<Member> members, int sourceGroupId) throws WrongAttributeValueException, WrongReferenceAttributeValueException, NotGroupMemberException {
    List<Member> membersToRemove = new ArrayList<>(members);
    lockGroupMembership(group, membersToRemove);
    for (Member member : membersToRemove) {
        member.setSourceGroupId(sourceGroupId);
        groupsManagerImpl.removeMember(sess, group, member);
    }
    // get list of new members
    List<Member> newMembers = this.getGroupMembers(sess, group);
    // get only removed members
    membersToRemove.removeAll(newMembers);
    for (Member removedIndirectMember : membersToRemove) {
        addMemberToGroupsFromTriggerAttribute(sess, group, removedIndirectMember);
        notifyMemberRemovalFromGroup(sess, group, removedIndirectMember);
        // remove all member-group attributes because member is not part of group any more
        try {
            getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, removedIndirectMember, group);
        } catch (MemberGroupMismatchException e) {
            throw new InternalErrorException("Member we tried to remove all member-group attributes is not from the same VO as Group.", e);
        }
        getPerunBl().getAuditer().log(sess, new IndirectMemberRemovedFromGroup(removedIndirectMember, group));
    }
    return membersToRemove;
}
Also used : MemberGroupMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException) IndirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member)

Aggregations

IndirectMemberRemovedFromGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup)1 Member (cz.metacentrum.perun.core.api.Member)1 RichMember (cz.metacentrum.perun.core.api.RichMember)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 MemberGroupMismatchException (cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException)1 ArrayList (java.util.ArrayList)1