Search in sources :

Example 91 with WrongAttributeValueException

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

the class urn_perun_resource_attribute_def_def_redmineProjectID method checkAttributeValue.

@Override
public void checkAttributeValue(PerunSessionImpl perunSession, Resource resource, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    String id = (String) attribute.getValue();
    if (id == null) {
        throw new WrongAttributeValueException(attribute, resource, "Attribute can't be empty. It can start with a-z and then a-z, 0-9, _ or -");
    }
    Matcher match = pattern.matcher(id);
    if (!match.matches()) {
        throw new WrongAttributeValueException(attribute, resource, "Bad format of attribute redmineProjectID. It can start with a-z and then a-z, 0-9, _ or -");
    }
}
Also used : Matcher(java.util.regex.Matcher) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 92 with WrongAttributeValueException

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

the class urn_perun_resource_attribute_def_def_accountExpirationTime method checkAttributeValue.

public void checkAttributeValue(PerunSessionImpl perunSession, Resource resource, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    Integer accExpTime = (Integer) attribute.getValue();
    if (accExpTime == null) {
        throw new WrongAttributeValueException("Attribute value shouldnt be null");
    }
    Facility fac = perunSession.getPerunBl().getResourcesManagerBl().getFacility(perunSession, resource);
    Integer facilityAccExpTime = null;
    try {
        //FIXME this can't work (different namespace!!)
        facilityAccExpTime = (Integer) perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, fac, attribute.getName()).getValue();
    } catch (AttributeNotExistsException ex) {
        throw new InternalErrorException(ex);
    }
    if (facilityAccExpTime == null) {
        throw new WrongReferenceAttributeValueException("cant determine attribute value on underlying facility");
    }
    if (facilityAccExpTime < accExpTime) {
        throw new WrongAttributeValueException("value can be higher than same facility attribute");
    }
}
Also used : WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) Facility(cz.metacentrum.perun.core.api.Facility) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 93 with WrongAttributeValueException

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

the class urn_perun_resource_attribute_def_def_defaultFilesQuota method checkAttributeValue.

@Override
public void checkAttributeValue(PerunSessionImpl perunSession, Resource resource, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    Attribute attrDefaultFilesLimit = null;
    Integer defaultFilesQuota = null;
    Integer defaultFilesLimit = null;
    //Get DefaultFilesLimit attribute
    try {
        attrDefaultFilesLimit = 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);
    }
    //Get defaultFilesQuota value
    if (attribute.getValue() != null) {
        defaultFilesQuota = (Integer) attribute.getValue();
    }
    if (defaultFilesQuota != null && defaultFilesQuota < 0)
        throw new WrongAttributeValueException(attribute, resource, attribute + " cannot be less than 0.");
    //Get defaultFilesLimit value
    if (attrDefaultFilesLimit != null && attrDefaultFilesLimit.getValue() != null) {
        defaultFilesLimit = (Integer) attrDefaultFilesLimit.getValue();
    }
    if (defaultFilesLimit != null && defaultFilesLimit < 0)
        throw new ConsistencyErrorException(attrDefaultFilesLimit + " cannot be less than 0.");
    //Compare DefaultFilesQuota with DefaultFilesLimit
    if (defaultFilesQuota == null || defaultFilesQuota == 0) {
        if (defaultFilesLimit != null && defaultFilesLimit != 0)
            throw new WrongReferenceAttributeValueException(attribute, attrDefaultFilesLimit, resource, null, resource, null, "Try to set unlimited quota, but limit is still " + defaultFilesLimit);
    } else if (defaultFilesLimit != null && defaultFilesLimit != 0) {
        if (defaultFilesLimit < defaultFilesQuota)
            throw new WrongReferenceAttributeValueException(attribute, attrDefaultFilesLimit, resource, null, resource, null, attribute + " must be less than or equals " + attrDefaultFilesLimit);
    }
}
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)

Example 94 with WrongAttributeValueException

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

the class urn_perun_resource_attribute_def_def_projectsBasePath method checkAttributeValue.

public void checkAttributeValue(PerunSessionImpl perunSession, Resource resource, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    String path = (String) attribute.getValue();
    if (path == null) {
        throw new WrongAttributeValueException(attribute, resource, "Attribute can't be empty.");
    }
    Pattern pattern = Pattern.compile("^(/[-_a-zA-Z0-9]+)+$");
    Matcher match = pattern.matcher(path);
    if (!match.matches()) {
        throw new WrongAttributeValueException(attribute, resource, "Bad format of attribute projectsBasePath (expected something like '/first/second').");
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 95 with WrongAttributeValueException

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

the class urn_perun_group_attribute_def_def_groupExtSource method checkAttributeValue.

@Override
public void checkAttributeValue(PerunSessionImpl sess, Group group, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    //prepare groupName value variable
    String extSourceName = null;
    if (attribute.getValue() != null)
        extSourceName = (String) attribute.getValue();
    if (extSourceName == null) {
        //attribute can be removed
        return;
    } else {
        try {
            Vo groupVo = sess.getPerunBl().getVosManagerBl().getVoById(sess, group.getVoId());
            List<ExtSource> allowedExtSources = sess.getPerunBl().getExtSourcesManagerBl().getVoExtSources(sess, groupVo);
            for (ExtSource es : allowedExtSources) {
                if (extSourceName.equals(es.getName()))
                    return;
            }
            throw new WrongAttributeValueException(attribute, group, "ExtSourceName " + extSourceName + " is not valid, because VO " + groupVo + " of this group has no such extSource assigned.");
        } catch (VoNotExistsException ex) {
            throw new ConsistencyErrorException("Vo of this group " + group + " not exists!");
        }
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Vo(cz.metacentrum.perun.core.api.Vo) ExtSource(cz.metacentrum.perun.core.api.ExtSource) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException)

Aggregations

WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)135 Attribute (cz.metacentrum.perun.core.api.Attribute)100 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)83 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)82 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)75 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)66 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)54 Matcher (java.util.regex.Matcher)31 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)27 ArrayList (java.util.ArrayList)17 LinkedHashMap (java.util.LinkedHashMap)16 Facility (cz.metacentrum.perun.core.api.Facility)14 Map (java.util.Map)14 Resource (cz.metacentrum.perun.core.api.Resource)12 User (cz.metacentrum.perun.core.api.User)11 Group (cz.metacentrum.perun.core.api.Group)9 Pattern (java.util.regex.Pattern)8 BigDecimal (java.math.BigDecimal)7 List (java.util.List)7 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)5