Search in sources :

Example 66 with AttributeNotExistsException

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

the class urn_perun_user_facility_attribute_def_virt_dataQuotas 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_defaultDataQuotas);
        } 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, true);
            } 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_dataQuotas);
        } 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, true);
            } 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, true));
    //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 67 with AttributeNotExistsException

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

the class urn_perun_user_facility_attribute_def_virt_defaultUnixGID method checkAttributeValue.

@Override
public void checkAttributeValue(PerunSessionImpl perunSession, Facility facility, User user, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    if (attribute.getValue() == null)
        throw new WrongAttributeValueException(attribute, user, facility, "Attribute can't be null.");
    try {
        Attribute defaultUnixGID = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, facility, user, AttributesManager.NS_USER_FACILITY_ATTR_DEF + ":defaultUnixGID");
        defaultUnixGID.setValue(attribute.getValue());
        perunSession.getPerunBl().getAttributesManagerBl().checkAttributeValue(perunSession, facility, user, defaultUnixGID);
    } catch (AttributeNotExistsException ex) {
        throw new ConsistencyErrorException(ex);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 68 with AttributeNotExistsException

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

the class urn_perun_user_facility_attribute_def_virt_defaultUnixGID method setAttributeValue.

public boolean setAttributeValue(PerunSessionImpl sess, Facility facility, User user, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
    try {
        Attribute attributeToSet = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, user, AttributesManager.NS_USER_FACILITY_ATTR_DEF + ":defaultUnixGID");
        attributeToSet.setValue(attribute.getValue());
        return sess.getPerunBl().getAttributesManagerBl().setAttributeWithoutCheck(sess, facility, user, attributeToSet);
    } catch (WrongAttributeAssignmentException ex) {
        throw new ConsistencyErrorException(ex);
    } catch (WrongAttributeValueException ex) {
        throw new InternalErrorException(ex);
    } catch (AttributeNotExistsException ex) {
        throw new ConsistencyErrorException(ex);
    }
}
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) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 69 with AttributeNotExistsException

use of cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException 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 70 with AttributeNotExistsException

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

the class urn_perun_user_facility_attribute_def_virt_login method checkAttributeValue.

@Override
public /**
	 * Calls checkAttribute on u:login-namespace:[login-namespace]
	 */
void checkAttributeValue(PerunSessionImpl sess, Facility facility, User user, Attribute attribute) throws WrongAttributeValueException, WrongReferenceAttributeValueException, InternalErrorException, WrongAttributeAssignmentException {
    try {
        Attribute loginNamespaceAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":login-namespace");
        Attribute loginAttribute = null;
        if (loginNamespaceAttribute.getValue() != null) {
            loginAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:" + (String) loginNamespaceAttribute.getValue());
            if (attribute.getValue() == null)
                throw new WrongAttributeValueException(loginAttribute, user, facility, "Login can't be null");
            loginAttribute.setValue(attribute.getValue());
            sess.getPerunBl().getAttributesManagerBl().checkAttributeValue(sess, user, loginAttribute);
        } else {
            throw new WrongAttributeValueException(loginNamespaceAttribute, user, facility, "Login-namespace for facility can not be empty.");
        }
    } catch (AttributeNotExistsException e) {
        throw new ConsistencyErrorException(e);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Aggregations

AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)138 Attribute (cz.metacentrum.perun.core.api.Attribute)120 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)94 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)81 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)75 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)64 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)59 ArrayList (java.util.ArrayList)30 Resource (cz.metacentrum.perun.core.api.Resource)25 Matcher (java.util.regex.Matcher)19 Facility (cz.metacentrum.perun.core.api.Facility)17 User (cz.metacentrum.perun.core.api.User)17 LinkedHashMap (java.util.LinkedHashMap)15 Group (cz.metacentrum.perun.core.api.Group)14 Map (java.util.Map)13 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)12 List (java.util.List)11 HashSet (java.util.HashSet)8 BigDecimal (java.math.BigDecimal)7 Pattern (java.util.regex.Pattern)6