Search in sources :

Example 6 with MemberResourceMismatchException

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

the class MembersManagerBlImpl method getRichMembersWithAttributesByNames.

@Override
public List<RichMember> getRichMembersWithAttributesByNames(PerunSession sess, Group group, Resource resource, List<String> attrsNames) throws AttributeNotExistsException, GroupResourceMismatchException {
    getPerunBl().getAttributesManagerBl().checkGroupIsFromTheSameVoLikeResource(sess, group, resource);
    List<Member> members = new ArrayList<>(perunBl.getGroupsManagerBl().getGroupMembers(sess, group));
    List<RichMember> richMembers = this.convertMembersToRichMembers(sess, members);
    List<AttributeDefinition> attrsDef = new ArrayList<>();
    for (String atrrName : attrsNames) {
        AttributeDefinition attrDef = perunBl.getAttributesManagerBl().getAttributeDefinition(sess, atrrName);
        attrsDef.add(attrDef);
    }
    List<RichMember> richMembersWithAttributes;
    try {
        richMembersWithAttributes = this.convertMembersToRichMembersWithAttributes(sess, group, resource, richMembers, attrsDef);
    } catch (MemberResourceMismatchException | MemberGroupMismatchException ex) {
        throw new ConsistencyErrorException(ex);
    }
    return richMembersWithAttributes;
}
Also used : MemberGroupMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) RichMember(cz.metacentrum.perun.core.api.RichMember)

Example 7 with MemberResourceMismatchException

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

the class urn_perun_member_resource_attribute_def_virt_fileQuotas method getAttributeValue.

@Override
public Attribute getAttributeValue(PerunSessionImpl sess, Member member, Resource resource, AttributeDefinition attributeDefinition) {
    Attribute attribute = new Attribute(attributeDefinition);
    // get resource quotas
    Map<String, Pair<BigDecimal, BigDecimal>> resourceTransferedQuotas;
    Attribute resourceQuotas;
    try {
        resourceQuotas = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, A_R_defaultFileQuotas);
    } catch (AttributeNotExistsException ex) {
        throw new ConsistencyErrorException(ex);
    } catch (WrongAttributeAssignmentException ex) {
        throw new InternalErrorException(ex);
    }
    if (resourceQuotas == null || resourceQuotas.getValue() == null)
        resourceTransferedQuotas = new HashMap<>();
    else {
        try {
            resourceTransferedQuotas = sess.getPerunBl().getModulesUtilsBl().checkAndTransferQuotas(resourceQuotas, resource, null, false);
        } catch (WrongAttributeValueException ex) {
            throw new ConsistencyErrorException("Quotas on resource " + resource + " are in bad format.", ex);
        }
    }
    // get members quotas
    Map<String, Pair<BigDecimal, BigDecimal>> memberTransferedQuotas;
    Attribute memberQuotas;
    try {
        memberQuotas = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, member, resource, A_MR_fileQuotas);
    } catch (AttributeNotExistsException ex) {
        throw new ConsistencyErrorException(ex);
    } catch (WrongAttributeAssignmentException | MemberResourceMismatchException ex) {
        throw new InternalErrorException(ex);
    }
    if (memberQuotas == null || memberQuotas.getValue() == null)
        memberTransferedQuotas = new HashMap<>();
    else {
        try {
            memberTransferedQuotas = sess.getPerunBl().getModulesUtilsBl().checkAndTransferQuotas(memberQuotas, resource, member, false);
        } catch (WrongAttributeValueException ex) {
            throw new ConsistencyErrorException("Quotas on resource " + resource + " for member " + member + " are in bad format.", ex);
        }
    }
    // get members quotas override
    Map<String, Pair<BigDecimal, BigDecimal>> memberTransferedQuotasOverride;
    Attribute memberQuotasOverride;
    try {
        memberQuotasOverride = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, member, resource, A_MR_fileQuotasOverride);
    } catch (AttributeNotExistsException ex) {
        throw new ConsistencyErrorException(ex);
    } catch (WrongAttributeAssignmentException | MemberResourceMismatchException ex) {
        throw new InternalErrorException(ex);
    }
    if (memberQuotasOverride == null || memberQuotasOverride.getValue() == null)
        memberTransferedQuotasOverride = new HashMap<>();
    else {
        try {
            memberTransferedQuotasOverride = sess.getPerunBl().getModulesUtilsBl().checkAndTransferQuotas(memberQuotasOverride, resource, member, false);
        } catch (WrongAttributeValueException ex) {
            throw new ConsistencyErrorException("Override quotas on resource " + resource + " for member " + member + " are in bad format.", ex);
        }
    }
    // Merge quotas for member on resource
    Map<String, Pair<BigDecimal, BigDecimal>> finalMemberResourceQuotas = sess.getPerunBl().getModulesUtilsBl().mergeMemberAndResourceTransferredQuotas(resourceTransferedQuotas, memberTransferedQuotas, memberTransferedQuotasOverride);
    // set final value to attribute
    attribute.setValue(sess.getPerunBl().getModulesUtilsBl().transferQuotasBackToAttributeValue(finalMemberResourceQuotas, false));
    // return attribute
    return attribute;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) Attribute(cz.metacentrum.perun.core.api.Attribute) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) Pair(cz.metacentrum.perun.core.api.Pair)

Example 8 with MemberResourceMismatchException

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

the class urn_perun_user_facility_attribute_def_virt_dataQuotas method getAttributeValue.

@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, Facility facility, AttributeDefinition attributeDefinition) {
    Attribute attribute = new Attribute(attributeDefinition);
    // merge attribute settings for every allowed resource
    List<Map<String, Pair<BigDecimal, BigDecimal>>> mergedMemberResourceQuotas = new ArrayList<>();
    List<Resource> allowedResources = sess.getPerunBl().getResourcesManagerBl().getAllowedResources(sess, facility, user);
    for (Resource resource : allowedResources) {
        // get allowed member of this user on this resource (using his VO)
        Vo membersVo;
        try {
            membersVo = sess.getPerunBl().getVosManagerBl().getVoById(sess, resource.getVoId());
        } catch (VoNotExistsException ex) {
            throw new ConsistencyErrorException("Vo should exists, because resource with this id exists " + resource);
        }
        Member memberOnResource;
        try {
            memberOnResource = sess.getPerunBl().getMembersManagerBl().getMemberByUser(sess, membersVo, user);
        } catch (MemberNotExistsException ex) {
            throw new ConsistencyErrorException("User should have member in this VO, because he was listed in allowed assigned resources " + user + ", " + membersVo + " , " + resource);
        }
        // Get member-resource final counted quotas for the member on the resource
        Map<String, Pair<BigDecimal, BigDecimal>> memberResourceFinalDataQuotas;
        Attribute memberResourceFinalDataQuotasAttribute;
        try {
            memberResourceFinalDataQuotasAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, memberOnResource, resource, A_MR_V_dataQuotas);
        } catch (MemberResourceMismatchException | WrongAttributeAssignmentException ex) {
            throw new InternalErrorException(ex);
        } catch (AttributeNotExistsException ex) {
            throw new ConsistencyErrorException(ex);
        }
        if (memberResourceFinalDataQuotasAttribute == null || memberResourceFinalDataQuotasAttribute.getValue() == null)
            memberResourceFinalDataQuotas = new LinkedHashMap<>();
        else {
            try {
                memberResourceFinalDataQuotas = sess.getPerunBl().getModulesUtilsBl().checkAndTransferQuotas(memberResourceFinalDataQuotasAttribute, resource, memberOnResource, true);
            } catch (WrongAttributeValueException ex) {
                throw new ConsistencyErrorException("Final counted quotas on " + resource + " for member " + memberOnResource + " are in bad format.", ex);
            }
        }
        // Add merged quotas to the big map by resources
        mergedMemberResourceQuotas.add(memberResourceFinalDataQuotas);
    }
    // now we have all resource and member merged quotas, so we need to create 1 transfered map with sum of values
    Map<String, Pair<BigDecimal, BigDecimal>> finalTransferredQuotas = sess.getPerunBl().getModulesUtilsBl().countUserFacilityQuotas(mergedMemberResourceQuotas);
    // transfer map back to attribute value
    attribute.setValue(sess.getPerunBl().getModulesUtilsBl().transferQuotasBackToAttributeValue(finalTransferredQuotas, true));
    // return attribute
    return attribute;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) ArrayList(java.util.ArrayList) Resource(cz.metacentrum.perun.core.api.Resource) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) BigDecimal(java.math.BigDecimal) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) LinkedHashMap(java.util.LinkedHashMap) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) Vo(cz.metacentrum.perun.core.api.Vo) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Member(cz.metacentrum.perun.core.api.Member) Pair(cz.metacentrum.perun.core.api.Pair)

Example 9 with MemberResourceMismatchException

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

the class urn_perun_user_facility_attribute_def_virt_fileQuotas method getAttributeValue.

@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, Facility facility, AttributeDefinition attributeDefinition) {
    Attribute attribute = new Attribute(attributeDefinition);
    // merge attribute settings for every allowed resource
    List<Map<String, Pair<BigDecimal, BigDecimal>>> mergedMemberResourceQuotas = new ArrayList<>();
    List<Resource> allowedResources = sess.getPerunBl().getResourcesManagerBl().getAllowedResources(sess, facility, user);
    for (Resource resource : allowedResources) {
        // get allowed member of this user on this resource (using his VO)
        Vo membersVo;
        try {
            membersVo = sess.getPerunBl().getVosManagerBl().getVoById(sess, resource.getVoId());
        } catch (VoNotExistsException ex) {
            throw new ConsistencyErrorException("Vo should exists, because resource with this id exists " + resource);
        }
        Member memberOnResource;
        try {
            memberOnResource = sess.getPerunBl().getMembersManagerBl().getMemberByUser(sess, membersVo, user);
        } catch (MemberNotExistsException ex) {
            throw new ConsistencyErrorException("User should have member in this VO, because he was listed in allowed assigned resources " + user + ", " + membersVo + " , " + resource);
        }
        // Get member-resource final counted quotas for the member on the resource
        Map<String, Pair<BigDecimal, BigDecimal>> memberResourceFinalFileQuotas;
        Attribute memberResourceFinalFileQuotasAttribute;
        try {
            memberResourceFinalFileQuotasAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, memberOnResource, resource, A_MR_V_fileQuotas);
        } catch (MemberResourceMismatchException | WrongAttributeAssignmentException ex) {
            throw new InternalErrorException(ex);
        } catch (AttributeNotExistsException ex) {
            throw new ConsistencyErrorException(ex);
        }
        if (memberResourceFinalFileQuotasAttribute == null || memberResourceFinalFileQuotasAttribute.getValue() == null)
            memberResourceFinalFileQuotas = new LinkedHashMap<>();
        else {
            try {
                memberResourceFinalFileQuotas = sess.getPerunBl().getModulesUtilsBl().checkAndTransferQuotas(memberResourceFinalFileQuotasAttribute, resource, memberOnResource, false);
            } catch (WrongAttributeValueException ex) {
                throw new ConsistencyErrorException("Final counted quotas on " + resource + " for member " + memberOnResource + " are in bad format.", ex);
            }
        }
        // Add merged quotas to the big map by resources
        mergedMemberResourceQuotas.add(memberResourceFinalFileQuotas);
    }
    // now we have all resource and member merged quotas, so we need to create 1 transfered map with sum of values
    Map<String, Pair<BigDecimal, BigDecimal>> finalTransferredQuotas = sess.getPerunBl().getModulesUtilsBl().countUserFacilityQuotas(mergedMemberResourceQuotas);
    // transfer map back to attribute value
    attribute.setValue(sess.getPerunBl().getModulesUtilsBl().transferQuotasBackToAttributeValue(finalTransferredQuotas, false));
    // return attribute
    return attribute;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) ArrayList(java.util.ArrayList) Resource(cz.metacentrum.perun.core.api.Resource) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) BigDecimal(java.math.BigDecimal) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) LinkedHashMap(java.util.LinkedHashMap) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) Vo(cz.metacentrum.perun.core.api.Vo) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Member(cz.metacentrum.perun.core.api.Member) Pair(cz.metacentrum.perun.core.api.Pair)

Example 10 with MemberResourceMismatchException

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

the class AttributesManagerBlImpl method doTheMagic.

@Override
public void doTheMagic(PerunSession sess, Member member, boolean trueMagic) throws WrongAttributeValueException, WrongReferenceAttributeValueException {
    User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
    List<Resource> resources = getPerunBl().getResourcesManagerBl().getAllowedResources(sess, member);
    for (Resource resource : resources) {
        Facility facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
        List<Attribute> requiredAttributes;
        try {
            requiredAttributes = getResourceRequiredAttributes(sess, resource, facility, resource, user, member);
        } catch (MemberResourceMismatchException ex) {
            throw new ConsistencyErrorException(ex);
        }
        boolean allOk = false;
        AttributeDefinition lastWrongAttribute = null;
        int safetyCounter = 0;
        do {
            try {
                setRequiredAttributes(sess, facility, resource, user, member, requiredAttributes);
                allOk = true;
            } catch (AttributeNotExistsException | MemberResourceMismatchException | WrongAttributeAssignmentException ex) {
                throw new ConsistencyErrorException(ex);
            } catch (WrongAttributeValueException ex) {
                if (!trueMagic)
                    throw ex;
                AttributeDefinition wrongAttributeDefinition = ex.getAttribute();
                if (wrongAttributeDefinition == null)
                    throw new ConsistencyErrorException("WrongAttributeValueException doesn't have set the wrong attribute.", ex);
                if (wrongAttributeDefinition.equals(lastWrongAttribute))
                    throw new WrongAttributeValueException("Method doTheMagic can't fix this attribute value", ex);
                lastWrongAttribute = wrongAttributeDefinition;
                findAndSetValueInList(requiredAttributes, wrongAttributeDefinition, null);
            } catch (WrongReferenceAttributeValueException ex) {
                if (!trueMagic)
                    throw ex;
                AttributeDefinition wrongAttributeDefinition = ex.getReferenceAttribute();
                if (wrongAttributeDefinition == null)
                    throw new ConsistencyErrorException("WrongReferenceAttributeValueException doesn't have set reference attribute.", ex);
                if (wrongAttributeDefinition.equals(lastWrongAttribute))
                    throw new WrongReferenceAttributeValueException("Method doTheMagic can't fix this attribute value", ex);
                lastWrongAttribute = wrongAttributeDefinition;
                if (!findAndSetValueInList(requiredAttributes, wrongAttributeDefinition, null)) {
                    // this attribute can't be fixed here
                    throw ex;
                }
            }
            safetyCounter++;
            if (safetyCounter == 50)
                throw new InternalErrorException("Method doTheMagic possibly stays in infinite loop.");
        } while (trueMagic && !allOk);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) AllUserFacilityAttributesRemovedForFacilitiesAndUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllUserFacilityAttributesRemovedForFacilitiesAndUser) AttributeRemovedForFacilityAndUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForFacilityAndUser) AttributeSetForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForUser) AllAttributesRemovedForFacilityAndUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForFacilityAndUser) AttributeSetForFacilityAndUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForFacilityAndUser) AttributeRemovedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForUser) AllAttributesRemovedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForUser) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) AttributeSetForGroupAndResource(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForGroupAndResource) AttributeRemovedForGroupAndResource(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForGroupAndResource) AllAttributesRemovedForResource(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForResource) AttributeRemovedForResource(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForResource) Resource(cz.metacentrum.perun.core.api.Resource) AttributeSetForResource(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForResource) AllAttributesRemovedForGroupAndResource(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForGroupAndResource) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributeRemovedForFacility(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForFacility) Facility(cz.metacentrum.perun.core.api.Facility) AttributeSetForFacility(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForFacility) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

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