Search in sources :

Example 11 with MemberResourceMismatchException

use of cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException 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)

Example 12 with MemberResourceMismatchException

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

the class ServicesManagerBlImpl method getData.

private ServiceAttributes getData(PerunSession sess, Service service, Facility facility, Resource resource, Member member) {
    ServiceAttributes memberServiceAttributes = new ServiceAttributes();
    User user;
    try {
        user = getPerunBl().getUsersManagerBl().getUserById(sess, member.getUserId());
        memberServiceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, facility, resource, user, member));
    } catch (UserNotExistsException e) {
        throw new ConsistencyErrorException("Member has assigned non-existing user.", e);
    } catch (MemberResourceMismatchException ex) {
        throw new InternalErrorException(ex);
    }
    return memberServiceAttributes;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) ServiceAttributes(cz.metacentrum.perun.core.api.ServiceAttributes) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 13 with MemberResourceMismatchException

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

the class ServicesManagerBlImpl method getData.

private ServiceAttributes getData(PerunSession sess, Service service, Facility facility, Resource resource, boolean filterExpiredMembers) {
    ServiceAttributes resourceServiceAttributes = new ServiceAttributes();
    resourceServiceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, resource));
    List<Member> members;
    if (filterExpiredMembers) {
        members = getPerunBl().getResourcesManagerBl().getAllowedMembersNotExpiredInGroups(sess, resource);
    } else {
        members = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resource);
    }
    HashMap<Member, List<Attribute>> attributes;
    try {
        attributes = getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, facility, resource, members, true);
    } catch (MemberResourceMismatchException ex) {
        throw new InternalErrorException(ex);
    }
    for (Member mem : attributes.keySet()) {
        ServiceAttributes serviceAttributes = new ServiceAttributes();
        serviceAttributes.addAttributes(attributes.get(mem));
        resourceServiceAttributes.addChildElement(serviceAttributes);
    }
    return resourceServiceAttributes;
}
Also used : MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) ServiceAttributes(cz.metacentrum.perun.core.api.ServiceAttributes) List(java.util.List) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Member(cz.metacentrum.perun.core.api.Member)

Example 14 with MemberResourceMismatchException

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

the class ServicesManagerBlImpl method getData.

private ServiceAttributes getData(PerunSession sess, Service service, Resource resource) {
    ServiceAttributes resourceServiceAttributes = new ServiceAttributes();
    resourceServiceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, resource));
    List<Member> members;
    members = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resource);
    HashMap<Member, List<Attribute>> attributes;
    try {
        attributes = getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, null, resource, members, true);
    } catch (MemberResourceMismatchException ex) {
        throw new InternalErrorException(ex);
    }
    for (Member mem : attributes.keySet()) {
        ServiceAttributes serviceAttributes = new ServiceAttributes();
        serviceAttributes.addAttributes(attributes.get(mem));
        resourceServiceAttributes.addChildElement(serviceAttributes);
    }
    return resourceServiceAttributes;
}
Also used : MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) ServiceAttributes(cz.metacentrum.perun.core.api.ServiceAttributes) List(java.util.List) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Member(cz.metacentrum.perun.core.api.Member)

Example 15 with MemberResourceMismatchException

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

the class ServicesManagerBlImpl method getDataWithGroups.

private ServiceAttributes getDataWithGroups(PerunSession sess, Service service, Facility facility, Resource resource, boolean filterExpiredMembers) {
    // append resource attributes
    ServiceAttributes resourceServiceAttributes = new ServiceAttributes();
    resourceServiceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, resource));
    // append also vo attributes to resource object
    try {
        Vo resourceVo = getPerunBl().getVosManagerBl().getVoById(sess, resource.getVoId());
        resourceServiceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, resourceVo));
    } catch (VoNotExistsException ex) {
        throw new ConsistencyErrorException("There is missing Vo for existing resource " + resource);
    }
    ServiceAttributes membersAbstractSA = new ServiceAttributes();
    Map<Member, ServiceAttributes> memberAttributes = new HashMap<>();
    List<Member> members;
    if (filterExpiredMembers) {
        members = getPerunBl().getResourcesManagerBl().getAllowedMembersNotExpiredInGroups(sess, resource);
    } else {
        members = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resource);
    }
    HashMap<Member, List<Attribute>> attributes;
    try {
        // append all member/member_resource/user/user_facility attributes
        attributes = getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, facility, resource, members, true);
    } catch (MemberResourceMismatchException ex) {
        throw new InternalErrorException(ex);
    }
    for (Member mem : attributes.keySet()) {
        ServiceAttributes tmpAttributes = new ServiceAttributes();
        tmpAttributes.addAttributes(attributes.get(mem));
        memberAttributes.put(mem, tmpAttributes);
        membersAbstractSA.addChildElement(tmpAttributes);
    }
    // get all groups and append their sub structure
    ServiceAttributes groupsAbstractSA = new ServiceAttributes();
    List<Group> groups = getPerunBl().getResourcesManagerBl().getAssignedGroups(sess, resource);
    for (Group group : groups) {
        groupsAbstractSA.addChildElement(getData(sess, service, facility, resource, group, memberAttributes, filterExpiredMembers));
    }
    // assign abstract services attributes to resource service attributes
    resourceServiceAttributes.addChildElement(groupsAbstractSA);
    resourceServiceAttributes.addChildElement(membersAbstractSA);
    return resourceServiceAttributes;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) HashMap(java.util.HashMap) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) ServiceAttributes(cz.metacentrum.perun.core.api.ServiceAttributes) Vo(cz.metacentrum.perun.core.api.Vo) List(java.util.List) ArrayList(java.util.ArrayList) Member(cz.metacentrum.perun.core.api.Member)

Aggregations

MemberResourceMismatchException (cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException)17 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)13 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)11 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)10 Attribute (cz.metacentrum.perun.core.api.Attribute)8 Member (cz.metacentrum.perun.core.api.Member)8 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)8 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)8 Resource (cz.metacentrum.perun.core.api.Resource)7 ArrayList (java.util.ArrayList)6 Vo (cz.metacentrum.perun.core.api.Vo)5 Facility (cz.metacentrum.perun.core.api.Facility)4 ServiceAttributes (cz.metacentrum.perun.core.api.ServiceAttributes)4 User (cz.metacentrum.perun.core.api.User)4 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)4 BanOnResource (cz.metacentrum.perun.core.api.BanOnResource)3 Group (cz.metacentrum.perun.core.api.Group)3 Pair (cz.metacentrum.perun.core.api.Pair)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3