Search in sources :

Example 1 with MemberAlreadyRemovedException

use of cz.metacentrum.perun.core.api.exceptions.MemberAlreadyRemovedException in project perun by CESNET.

the class GroupsManagerBlImpl method removeFormerMemberWhileSynchronization.

/**
 * Remove former member from group (if he is not listed in ExtSource).
 *
 * If this is membersGroup (of some Vo) try to disableMember, if not possible then delete him.
 * If this is regular group (of some Vo) remove him and if this group is also
 * his last authoritative group, disable or delete him also in the Vo.
 *
 * This method runs in separate transaction.
 *
 * @param sess perun session
 * @param group to be synchronized
 * @param memberToRemove member to be removed from Group
 *
 * @throws GroupNotExistsException if group does not exist
 */
public void removeFormerMemberWhileSynchronization(PerunSession sess, Group group, RichMember memberToRemove, boolean isAuthoritative) throws GroupNotExistsException {
    // Member is missing in the external group, so remove him from the perun group
    try {
        // members group
        if (group.getName().equals(VosManager.MEMBERS_GROUP)) {
            // If the group is members group, the member must be disabled as a member of VO
            removeMemberFromMembersGroup(sess, group, memberToRemove);
        // not members group
        } else {
            // If Yes = deleteMember (from Vo), if No = only removeMember
            if (isAuthoritative) {
                removeMemberFromAuthoritativeGroup(sess, group, memberToRemove);
            } else {
                getPerunBl().getGroupsManagerBl().removeMember(sess, group, memberToRemove);
                log.info("Group synchronization {}: Member id {} removed.", group, memberToRemove.getId());
            }
        }
    } catch (NotGroupMemberException e) {
        throw new ConsistencyErrorException("Trying to remove non-existing user");
    } catch (MemberAlreadyRemovedException ex) {
        // Member was probably removed before starting of synchronization removing process, log it and skip this member
        log.debug("Member {} was removed from group {} before removing process. Skip this member.", memberToRemove, group);
    }
}
Also used : NotGroupMemberException(cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) MemberAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.MemberAlreadyRemovedException)

Example 2 with MemberAlreadyRemovedException

use of cz.metacentrum.perun.core.api.exceptions.MemberAlreadyRemovedException in project perun by CESNET.

the class MembersManagerBlImpl method moveMembership.

@Override
public void moveMembership(PerunSession sess, Vo vo, User sourceUser, User targetUser) throws MemberNotExistsException, AlreadyMemberException, ExtendMembershipException {
    Member sourceMember = this.getMemberByUserId(sess, vo, sourceUser.getId());
    List<Group> directGroups = getPerunBl().getGroupsManagerBl().getMemberDirectGroups(sess, sourceMember);
    List<Group> synchronizedGroups = new ArrayList<>();
    try {
        for (Group group : directGroups) {
            Attribute attrSynchronizeEnabled = getPerunBl().getAttributesManagerBl().getAttribute(sess, group, getPerunBl().getGroupsManager().GROUPSYNCHROENABLED_ATTRNAME);
            if ("true".equals(attrSynchronizeEnabled.getValue())) {
                synchronizedGroups.add(group);
            }
        }
    } catch (WrongAttributeAssignmentException | AttributeNotExistsException e) {
        throw new InternalErrorException(e);
    }
    Member targetMember;
    try {
        // create targetMember and add him to all direct groups that are not synchronized
        directGroups.removeAll(synchronizedGroups);
        targetMember = this.createMember(sess, vo, targetUser, directGroups);
    } catch (WrongAttributeValueException | WrongReferenceAttributeValueException e) {
        throw new InternalErrorException(e);
    }
    // add 'members' group to directGroups to move its member-group attributes too
    try {
        directGroups.add(getPerunBl().getGroupsManagerBl().getGroupByName(sess, vo, VosManager.MEMBERS_GROUP));
    } catch (GroupNotExistsException e) {
        throw new InternalErrorException(e);
    }
    moveMembersAttributes(sess, vo, sourceMember, targetMember, directGroups);
    // first validate member to prevent MemberNotValidYetException later
    try {
        this.validateMember(sess, targetMember);
    } catch (WrongAttributeValueException | WrongReferenceAttributeValueException e) {
        throw new InternalErrorException(e);
    }
    if (sourceMember.getStatus() != Status.VALID) {
        try {
            this.setStatus(sess, targetMember, sourceMember.getStatus());
        } catch (WrongAttributeValueException | WrongReferenceAttributeValueException | MemberNotValidYetException e) {
            throw new InternalErrorException(e);
        }
    }
    getMembersManagerImpl().moveMembersApplications(sess, sourceMember, targetMember);
    moveMembersSponsorships(sess, vo, sourceUser, targetUser, sourceMember, targetMember);
    moveMembersBans(sess, sourceMember, targetMember);
    try {
        this.deleteMember(sess, sourceMember);
    } catch (MemberAlreadyRemovedException e) {
        log.warn("Trying to delete already deleted member {}. Exception: {}", sourceMember, e);
    }
}
Also used : Group(cz.metacentrum.perun.core.api.Group) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) ParentGroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException) Attribute(cz.metacentrum.perun.core.api.Attribute) MemberNotValidYetException(cz.metacentrum.perun.core.api.exceptions.MemberNotValidYetException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) MemberAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.MemberAlreadyRemovedException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member)

Aggregations

MemberAlreadyRemovedException (cz.metacentrum.perun.core.api.exceptions.MemberAlreadyRemovedException)2 Attribute (cz.metacentrum.perun.core.api.Attribute)1 Group (cz.metacentrum.perun.core.api.Group)1 Member (cz.metacentrum.perun.core.api.Member)1 RichMember (cz.metacentrum.perun.core.api.RichMember)1 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)1 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)1 GroupNotExistsException (cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 MemberNotValidYetException (cz.metacentrum.perun.core.api.exceptions.MemberNotValidYetException)1 NotGroupMemberException (cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException)1 ParentGroupNotExistsException (cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException)1 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)1 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)1 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)1 ArrayList (java.util.ArrayList)1