Search in sources :

Example 11 with MemberGroupMismatchException

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

Example 12 with MemberGroupMismatchException

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

the class GroupsManagerBlImpl method reactivateMember.

@Override
public void reactivateMember(PerunSession sess, Member member, Group group) throws MemberNotExistsException {
    // only direct membership has own status and expiration, indirect membership get it's status and expiration from origin group
    if (!isDirectGroupMember(sess, group, member))
        throw new MemberNotExistsException("Member does not belong to this group");
    validateMemberInGroup(sess, member, group);
    // Get current membershipExpiration date attribute
    Attribute membershipExpirationAttribute = getMemberExpiration(sess, member, group);
    // Set new value of the membershipExpiration for the member
    membershipExpirationAttribute.setValue(null);
    try {
        getPerunBl().getAttributesManagerBl().setAttribute(sess, member, group, membershipExpirationAttribute);
    } catch (WrongAttributeValueException e) {
        throw new InternalErrorException("Wrong value: " + membershipExpirationAttribute.getValue(), e);
    } catch (WrongReferenceAttributeValueException | WrongAttributeAssignmentException e) {
        throw new InternalErrorException(e);
    } catch (MemberGroupMismatchException e) {
        throw new ConsistencyErrorException(e);
    }
    try {
        extendMembershipInGroup(sess, member, group);
    } catch (ExtendMembershipException ex) {
        // This exception should not be thrown for null membershipExpiration attribute
        throw new InternalErrorException(ex);
    }
}
Also used : MemberGroupMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) ExtendMembershipException(cz.metacentrum.perun.core.api.exceptions.ExtendMembershipException)

Example 13 with MemberGroupMismatchException

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

the class GroupsManagerBlImpl method extendMembershipInGroup.

private void extendMembershipInGroup(PerunSession sess, Member member, Group group, boolean setValue) throws ExtendMembershipException {
    Attribute membershipExpirationRulesAttribute = getMembershipExpirationRulesAttribute(sess, group);
    if (membershipExpirationRulesAttribute == null) {
        return;
    }
    LinkedHashMap<String, String> membershipExpirationRules = membershipExpirationRulesAttribute.valueAsMap();
    LocalDate localDate = LocalDate.now();
    // Get current membershipExpiration date
    Attribute membershipExpirationAttribute = getMemberExpiration(sess, member, group);
    checkLoaForExpiration(sess, membershipExpirationRules, membershipExpirationAttribute, member);
    String period = null;
    // Default extension
    if (membershipExpirationRules.get(AbstractMembershipExpirationRulesModule.membershipPeriodKeyName) != null) {
        period = membershipExpirationRules.get(AbstractMembershipExpirationRulesModule.membershipPeriodKeyName);
    }
    String loaPeriod = getLoaPeriod(sess, member, membershipExpirationRules, membershipExpirationAttribute);
    if (loaPeriod != null) {
        period = loaPeriod;
    }
    // Do we extend for x months or for static date?
    if (period != null) {
        if (period.startsWith("+")) {
            localDate = extendForMonths(localDate, period, membershipExpirationRules, membershipExpirationAttribute, member, group);
        } else {
            // We will extend to particular date
            localDate = extendForStaticDate(localDate, period, membershipExpirationRules, membershipExpirationAttribute, member, group);
        }
    }
    if (setValue) {
        // Set new value of the membershipExpiration for the member
        membershipExpirationAttribute.setValue(localDate.toString());
        try {
            getPerunBl().getAttributesManagerBl().setAttribute(sess, member, group, membershipExpirationAttribute);
        } catch (WrongAttributeValueException e) {
            throw new InternalErrorException("Wrong value: " + membershipExpirationAttribute.getValue(), e);
        } catch (WrongReferenceAttributeValueException | WrongAttributeAssignmentException | MemberGroupMismatchException e) {
            throw new InternalErrorException(e);
        }
    }
}
Also used : MemberGroupMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) LocalDate(java.time.LocalDate)

Example 14 with MemberGroupMismatchException

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

the class GroupsManagerBlImpl method getRichGroupsWithAttributesAssignedToResource.

@Override
public List<RichGroup> getRichGroupsWithAttributesAssignedToResource(PerunSession sess, Member member, Resource resource, List<String> attrNames) {
    List<Group> assignedGroups = getPerunBl().getResourcesManagerBl().getAssignedGroups(sess, resource);
    assignedGroups.retainAll(perunBl.getGroupsManagerBl().getAllMemberGroups(sess, member));
    try {
        return this.convertGroupsToRichGroupsWithAttributes(sess, member, resource, assignedGroups, attrNames);
    } catch (GroupResourceMismatchException | MemberGroupMismatchException ex) {
        throw new ConsistencyErrorException(ex);
    }
}
Also used : EnrichedGroup(cz.metacentrum.perun.core.api.EnrichedGroup) IndirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup) CandidateGroup(cz.metacentrum.perun.core.api.CandidateGroup) RichGroup(cz.metacentrum.perun.core.api.RichGroup) MemberExpiredInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup) MemberValidatedInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup) DirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup) Group(cz.metacentrum.perun.core.api.Group) DirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup) IndirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup) MemberGroupMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)

Example 15 with MemberGroupMismatchException

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

the class ServicesManagerBlImpl method getData.

private ServiceAttributes getData(PerunSession sess, Service service, Facility facility, Resource resource, Group group, Map<Member, ServiceAttributes> memberAttributes, boolean filterExpiredMembers) {
    ServiceAttributes groupServiceAttributes = new ServiceAttributes();
    try {
        // add group and group_resource attributes
        groupServiceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, resource, group, true));
    } catch (GroupResourceMismatchException ex) {
        throw new InternalErrorException(ex);
    }
    ServiceAttributes groupsMembersElement = new ServiceAttributes();
    // Invalid and disabled are not allowed here
    List<Member> members = getPerunBl().getGroupsManagerBl().getGroupMembersExceptInvalidAndDisabled(sess, group);
    if (filterExpiredMembers) {
        List<Member> membersToRemove = new ArrayList<>();
        for (Member member : members) {
            if (member.getGroupStatus() == MemberGroupStatus.EXPIRED) {
                membersToRemove.add(member);
            }
        }
        members.removeAll(membersToRemove);
    }
    for (Member member : members) {
        // append also member_group attributes for each member in a group
        // rest of member/user attributes was passed in a param if present
        ServiceAttributes tempAttrs = new ServiceAttributes();
        if (memberAttributes.get(member) != null) {
            tempAttrs.addAttributes(memberAttributes.get(member).getAttributes());
        }
        try {
            tempAttrs.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, member, group));
        } catch (MemberGroupMismatchException e) {
            throw new InternalErrorException(e);
        }
        groupsMembersElement.addChildElement(tempAttrs);
    }
    // Services expect members to be second child element, so we create empty ServiceAttributes where subgroups used to be.
    groupServiceAttributes.addChildElement(new ServiceAttributes());
    groupServiceAttributes.addChildElement(groupsMembersElement);
    return groupServiceAttributes;
}
Also used : MemberGroupMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException) ServiceAttributes(cz.metacentrum.perun.core.api.ServiceAttributes) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) Member(cz.metacentrum.perun.core.api.Member)

Aggregations

MemberGroupMismatchException (cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException)19 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)14 Attribute (cz.metacentrum.perun.core.api.Attribute)8 Member (cz.metacentrum.perun.core.api.Member)8 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)8 Group (cz.metacentrum.perun.core.api.Group)7 RichMember (cz.metacentrum.perun.core.api.RichMember)7 ArrayList (java.util.ArrayList)7 DirectMemberRemovedFromGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup)5 IndirectMemberRemovedFromGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup)5 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)5 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)5 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)5 DirectMemberAddedToGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup)4 IndirectMemberAddedToGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup)4 MemberExpiredInGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup)4 MemberValidatedInGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup)4 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)4 CandidateGroup (cz.metacentrum.perun.core.api.CandidateGroup)4 EnrichedGroup (cz.metacentrum.perun.core.api.EnrichedGroup)4