Search in sources :

Example 1 with MemberDeleted

use of cz.metacentrum.perun.audit.events.MembersManagerEvents.MemberDeleted in project perun by CESNET.

the class MembersManagerBlImpl method deleteMember.

@Override
public void deleteMember(PerunSession sess, Member member) throws MemberAlreadyRemovedException {
    Vo vo = this.getMemberVo(sess, member);
    // Remove member from all groups
    List<Group> memberGroups = getPerunBl().getGroupsManagerBl().getMemberDirectGroups(sess, member);
    for (Group group : memberGroups) {
        // Member must be removed from the members group using separate method
        if (group.getName().equals(VosManager.MEMBERS_GROUP))
            continue;
        try {
            getPerunBl().getGroupsManagerBl().removeMember(sess, group, member);
        } catch (NotGroupMemberException e) {
            throw new ConsistencyErrorException("getMemberGroups return group where the member is not member", e);
        } catch (GroupNotExistsException e) {
            throw new ConsistencyErrorException(e);
        }
    }
    // Remove member from the VO members group
    try {
        Group g = getPerunBl().getGroupsManagerBl().getGroupByName(sess, vo, VosManager.MEMBERS_GROUP);
        try {
            getPerunBl().getGroupsManagerBl().removeMemberFromMembersOrAdministratorsGroup(sess, g, member);
        } catch (NotGroupMemberException e) {
            throw new ConsistencyErrorException("Member is not in the \"members\" group." + member + "  " + g, e);
        } catch (WrongAttributeValueException | WrongReferenceAttributeValueException e) {
            throw new InternalErrorException(e);
        }
    } catch (GroupNotExistsException e) {
        throw new InternalErrorException(e);
    }
    // Remove member's  attributes (namespaces: member and resource-member)
    try {
        getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, member);
        List<Resource> resources = getPerunBl().getResourcesManagerBl().getResources(sess, vo);
        for (Resource resource : resources) {
            getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, member, resource);
        }
    } catch (AttributeValueException ex) {
        throw new ConsistencyErrorException("Member is removed from all groups. There are no required attribute for this member. Member's attributes can be removed without problem.", ex);
    } catch (MemberResourceMismatchException ex) {
        throw new InternalErrorException(ex);
    }
    removeAllMemberBans(sess, member);
    // Remove possible links to member's sponsors
    membersManagerImpl.deleteSponsorLinks(sess, member);
    membersManagerImpl.rejectAllMemberOpenApplications(sess, member);
    // Remove member from the DB
    getMembersManagerImpl().deleteMember(sess, member);
    getPerunBl().getAuditer().log(sess, new MemberDeleted(member));
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) ParentGroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException) Resource(cz.metacentrum.perun.core.api.Resource) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) AttributeValueException(cz.metacentrum.perun.core.api.exceptions.AttributeValueException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) NotGroupMemberException(cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) Vo(cz.metacentrum.perun.core.api.Vo) BanOnVo(cz.metacentrum.perun.core.api.BanOnVo) MemberDeleted(cz.metacentrum.perun.audit.events.MembersManagerEvents.MemberDeleted) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Aggregations

MemberDeleted (cz.metacentrum.perun.audit.events.MembersManagerEvents.MemberDeleted)1 BanOnResource (cz.metacentrum.perun.core.api.BanOnResource)1 BanOnVo (cz.metacentrum.perun.core.api.BanOnVo)1 Group (cz.metacentrum.perun.core.api.Group)1 Resource (cz.metacentrum.perun.core.api.Resource)1 Vo (cz.metacentrum.perun.core.api.Vo)1 AttributeValueException (cz.metacentrum.perun.core.api.exceptions.AttributeValueException)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 MemberResourceMismatchException (cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException)1 NotGroupMemberException (cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException)1 ParentGroupNotExistsException (cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException)1 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)1 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)1