Search in sources :

Example 46 with WrongReferenceAttributeValueException

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

the class urn_perun_facility_attribute_def_virt_maxUID method checkAttributeValue.

public void checkAttributeValue(PerunSessionImpl sess, Facility facility, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    try {
        Attribute uidNamespaceAttribute = getUidNamespaceAttribute(sess, facility);
        if (uidNamespaceAttribute.getValue() == null)
            throw new WrongReferenceAttributeValueException(attribute, uidNamespaceAttribute);
        Attribute namespaceMaxUidAttribute = getNamespaceMaxUidAttribute(sess, (String) uidNamespaceAttribute.getValue());
        sess.getPerunBl().getAttributesManagerBl().checkAttributeValue(sess, (String) uidNamespaceAttribute.getValue(), namespaceMaxUidAttribute);
    } catch (WrongReferenceAttributeValueException ex) {
        throw new WrongReferenceAttributeValueException(attribute, ex.getReferenceAttribute());
    }
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)

Example 47 with WrongReferenceAttributeValueException

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

the class urn_perun_facility_attribute_def_virt_maxUID method getAttributeValue.

public Attribute getAttributeValue(PerunSessionImpl sess, Facility facility, AttributeDefinition attributeDefinition) throws InternalErrorException {
    Attribute attribute = new Attribute(attributeDefinition);
    try {
        Attribute uidNamespaceAttribute = getUidNamespaceAttribute(sess, facility);
        if (uidNamespaceAttribute.getValue() == null)
            return attribute;
        Attribute namespaceMaxUidAttribute = getNamespaceMaxUidAttribute(sess, (String) uidNamespaceAttribute.getValue());
        attribute = Utils.copyAttributeToVirtualAttributeWithValue(namespaceMaxUidAttribute, attribute);
        return attribute;
    } catch (WrongReferenceAttributeValueException ex) {
        return attribute;
    }
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)

Example 48 with WrongReferenceAttributeValueException

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

the class urn_perun_facility_attribute_def_virt_minGID method getAttributeValue.

public Attribute getAttributeValue(PerunSessionImpl sess, Facility facility, AttributeDefinition attributeDefinition) throws InternalErrorException {
    Attribute attribute = new Attribute(attributeDefinition);
    try {
        Attribute gidNamespaceAttribute = getUnixGIDNamespaceAttribute(sess, facility);
        if (gidNamespaceAttribute.getValue() == null)
            return attribute;
        Attribute namespaceMinGidAttribute = getNamespaceMinGidAttribute(sess, (String) gidNamespaceAttribute.getValue());
        attribute = Utils.copyAttributeToVirtualAttributeWithValue(namespaceMinGidAttribute, attribute);
        return attribute;
    } catch (WrongReferenceAttributeValueException ex) {
        return attribute;
    }
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)

Example 49 with WrongReferenceAttributeValueException

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

the class urn_perun_facility_attribute_def_virt_minGID method setAttributeValue.

public boolean setAttributeValue(PerunSessionImpl sess, Facility facility, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
    Attribute gidNamespaceAttribute = getUnixGIDNamespaceAttribute(sess, facility);
    if (gidNamespaceAttribute.getValue() == null)
        throw new WrongReferenceAttributeValueException(attribute, gidNamespaceAttribute);
    Attribute namespaceMinGidAttribute = getNamespaceMinGidAttribute(sess, (String) gidNamespaceAttribute.getValue());
    if (!(attribute.getValue() == null ? namespaceMinGidAttribute.getValue() == null : attribute.getValue().equals(namespaceMinGidAttribute.getValue()))) {
        //attribute from param have other vale then physical attribute
        throw new WrongReferenceAttributeValueException(attribute, namespaceMinGidAttribute);
    }
    return false;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)

Example 50 with WrongReferenceAttributeValueException

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

the class urn_perun_member_resource_attribute_def_def_filesQuota method checkAttributeValue.

@Override
public void checkAttributeValue(PerunSessionImpl perunSession, Resource resource, Member member, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    Attribute attrFilesLimit = null;
    Integer filesQuota = null;
    Integer filesLimit = null;
    //Get FilesLimit attribute
    try {
        attrFilesLimit = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, resource, member, A_MR_filesLimit);
    } catch (AttributeNotExistsException ex) {
        throw new ConsistencyErrorException(attribute + " from member " + member.getId() + " and resource " + resource.getId() + " could not obtained.", ex);
    }
    //Get FilesQuota value
    if (attribute.getValue() != null) {
        filesQuota = (Integer) attribute.getValue();
    } else {
        try {
            attribute = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, resource, A_R_defaultFilesQuota);
        } catch (AttributeNotExistsException ex) {
            throw new ConsistencyErrorException("Attribute with defaultFilesQuota from resource " + resource.getId() + " could not obtained.", ex);
        }
        if (attribute != null && attribute.getValue() != null) {
            filesQuota = (Integer) attribute.getValue();
        }
    }
    if (filesQuota != null && filesQuota < 0)
        throw new WrongAttributeValueException(attribute, resource, member, attribute + " cannot be less than 0.");
    //Get FilesLimit value
    if (attrFilesLimit != null && attrFilesLimit.getValue() != null) {
        filesLimit = (Integer) attrFilesLimit.getValue();
    } else if (attrFilesLimit == null || attrFilesLimit.getValue() == null) {
        try {
            attrFilesLimit = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, resource, A_R_defaultFilesLimit);
        } catch (AttributeNotExistsException ex) {
            throw new ConsistencyErrorException("Attribute with defaultFilesLimit from resource " + resource.getId() + " could not obtained.", ex);
        }
        if (attrFilesLimit != null || attrFilesLimit.getValue() != null) {
            filesLimit = (Integer) attrFilesLimit.getValue();
        }
    }
    if (filesLimit != null && filesLimit < 0)
        throw new ConsistencyErrorException(attrFilesLimit + " cannot be less than 0.");
    //Compare filesQuota with filesLimit
    if (filesQuota == null || filesQuota == 0) {
        if (filesLimit != null && filesLimit != 0)
            throw new WrongReferenceAttributeValueException(attribute, attrFilesLimit, resource, member, resource, null, "Try to set unlimited quota, but limit is still " + filesLimit);
    } else if (filesLimit != null && filesLimit != 0) {
        if (filesLimit < filesQuota)
            throw new WrongReferenceAttributeValueException(attribute, attrFilesLimit, resource, member, resource, null, attribute + " must be less than or equal to " + attrFilesLimit);
    }
}
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) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Aggregations

WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)109 Attribute (cz.metacentrum.perun.core.api.Attribute)101 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)83 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)70 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)64 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)62 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)51 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)27 Resource (cz.metacentrum.perun.core.api.Resource)13 ArrayList (java.util.ArrayList)13 Facility (cz.metacentrum.perun.core.api.Facility)12 Matcher (java.util.regex.Matcher)12 User (cz.metacentrum.perun.core.api.User)11 Group (cz.metacentrum.perun.core.api.Group)9 BigDecimal (java.math.BigDecimal)6 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)5 List (java.util.List)5 Pattern (java.util.regex.Pattern)5 Pair (cz.metacentrum.perun.core.api.Pair)3 LinkedHashMap (java.util.LinkedHashMap)3