Search in sources :

Example 26 with WrongAttributeAssignmentException

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

the class urn_perun_user_facility_attribute_def_virt_fileQuotas method getAttributeValue.

@Override
public Attribute getAttributeValue(PerunSessionImpl sess, Facility facility, User user, AttributeDefinition attributeDefinition) throws InternalErrorException {
    Attribute attribute = new Attribute(attributeDefinition);
    Map<String, String> countedQuotas = new HashMap<>();
    //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 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, resource, memberOnResource, A_MR_fileQuotas);
        } catch (AttributeNotExistsException ex) {
            throw new ConsistencyErrorException(ex);
        } catch (WrongAttributeAssignmentException ex) {
            throw new InternalErrorException(ex);
        }
        if (memberQuotas == null || memberQuotas.getValue() == null)
            memberTransferedQuotas = new HashMap<>();
        else {
            try {
                memberTransferedQuotas = sess.getPerunBl().getModulesUtilsBl().checkAndTransferQuotas(memberQuotas, resource, memberOnResource, false);
            } catch (WrongAttributeValueException ex) {
                throw new ConsistencyErrorException("Quotas on resource " + resource + " for member " + memberOnResource + " are in bad format.", ex);
            }
        }
        //merge quotas and add them to the big map by resources
        mergedMemberResourceQuotas.add(sess.getPerunBl().getModulesUtilsBl().mergeMemberAndResourceTransferedQuotas(memberTransferedQuotas, resourceTransferedQuotas));
    }
    //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) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) 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) BigDecimal(java.math.BigDecimal) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 27 with WrongAttributeAssignmentException

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

the class urn_perun_user_facility_attribute_def_virt_login method setAttributeValue.

@Override
public boolean setAttributeValue(PerunSessionImpl sess, Facility facility, User user, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
    AttributeDefinition userLoginAttributeDefinition;
    try {
        // Get the f:login-namespace attribute
        Attribute loginNamespaceAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":login-namespace");
        if (loginNamespaceAttribute.getValue() == null) {
            throw new WrongReferenceAttributeValueException(attribute, loginNamespaceAttribute, user, facility, "Facility need to have nonempty login-namespace attribute.");
        }
        userLoginAttributeDefinition = sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:" + (String) loginNamespaceAttribute.getValue());
    } catch (AttributeNotExistsException e) {
        throw new InternalErrorException(e);
    } catch (WrongAttributeAssignmentException e) {
        throw new ConsistencyErrorException(e);
    }
    Attribute userLoginAttribute = new Attribute(userLoginAttributeDefinition);
    userLoginAttribute.setValue(attribute.getValue());
    try {
        return sess.getPerunBl().getAttributesManagerBl().setAttributeWithoutCheck(sess, user, userLoginAttribute);
    } catch (WrongAttributeValueException e) {
        throw new InternalErrorException(e);
    } catch (WrongAttributeAssignmentException e) {
        throw new ConsistencyErrorException(e);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 28 with WrongAttributeAssignmentException

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

the class urn_perun_user_facility_attribute_def_virt_UID method getAttributeValue.

/**
	 * Gets the value of the attribute f:uid-namespace and then finds the value of the attribute u:uid-namespace:[uid-namespace]
	 */
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, Facility facility, User user, AttributeDefinition attributeDefinition) throws InternalErrorException {
    Attribute attr = new Attribute(attributeDefinition);
    Attribute uidAttribute = null;
    try {
        // Get the f:uid-namespace attribute
        Attribute uidNamespaceAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":uid-namespace");
        if (uidNamespaceAttribute.getValue() != null) {
            // Get the u:uid-namespace[uidNamespaceAttribute]
            uidAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":uid-namespace:" + (String) uidNamespaceAttribute.getValue());
            attr = Utils.copyAttributeToVirtualAttributeWithValue(uidAttribute, attr);
        } else {
            attr.setValue(null);
        }
    } catch (AttributeNotExistsException e) {
        throw new ConsistencyErrorException(e);
    } catch (WrongAttributeAssignmentException e) {
        throw new ConsistencyErrorException(e);
    }
    return attr;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)

Example 29 with WrongAttributeAssignmentException

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

the class urn_perun_user_facility_attribute_def_virt_UID method setAttributeValue.

@Override
public boolean setAttributeValue(PerunSessionImpl sess, Facility facility, User user, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
    AttributeDefinition userUidAttributeDefinition;
    try {
        // Get the f:uid-namespace attribute
        Attribute uidNamespaceAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":uid-namespace");
        if (uidNamespaceAttribute.getValue() == null) {
            throw new WrongReferenceAttributeValueException(attribute, uidNamespaceAttribute);
        }
        userUidAttributeDefinition = sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_USER_ATTR_DEF + ":uid-namespace:" + (String) uidNamespaceAttribute.getValue());
    } catch (AttributeNotExistsException e) {
        throw new InternalErrorException(e);
    } catch (WrongAttributeAssignmentException e) {
        throw new ConsistencyErrorException(e);
    }
    Attribute userUidAttribute = new Attribute(userUidAttributeDefinition);
    userUidAttribute.setValue(attribute.getValue());
    try {
        return sess.getPerunBl().getAttributesManagerBl().setAttributeWithoutCheck(sess, user, userUidAttribute);
    } catch (WrongAttributeValueException e) {
        throw new InternalErrorException(e);
    } catch (WrongAttributeAssignmentException e) {
        throw new ConsistencyErrorException(e);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 30 with WrongAttributeAssignmentException

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

the class AttributesManagerBlImpl method setAttributeWithoutCheck.

public boolean setAttributeWithoutCheck(PerunSession sess, Resource resource, Attribute attribute) throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    getAttributesManagerImpl().checkNamespace(sess, attribute, AttributesManager.NS_RESOURCE_ATTR);
    if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
        throw new WrongAttributeAssignmentException(attribute);
    boolean changed = true;
    if (isVirtAttribute(sess, attribute)) {
        try {
            changed = getAttributesManagerImpl().setVirtualAttribute(sess, resource, attribute);
        } catch (WrongReferenceAttributeValueException ex) {
            throw new InternalErrorException(ex);
        }
    } else {
        changed = getAttributesManagerImpl().setAttribute(sess, resource, attribute);
    }
    if (changed) {
        getPerunBl().getAuditer().log(sess, "{} set for {}.", attribute, resource);
        getAttributesManagerImpl().changedAttributeHook(sess, resource, attribute);
    }
    return changed;
}
Also used : WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Aggregations

WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)127 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)97 Attribute (cz.metacentrum.perun.core.api.Attribute)95 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)61 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)59 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)55 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)52 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)42 User (cz.metacentrum.perun.core.api.User)31 ArrayList (java.util.ArrayList)31 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)14 Facility (cz.metacentrum.perun.core.api.Facility)14 LinkedHashMap (java.util.LinkedHashMap)11 Member (cz.metacentrum.perun.core.api.Member)10 Map (java.util.Map)9 Group (cz.metacentrum.perun.core.api.Group)8 List (java.util.List)8 Resource (cz.metacentrum.perun.core.api.Resource)7 Vo (cz.metacentrum.perun.core.api.Vo)6 HashMap (java.util.HashMap)6