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 -");
}
}
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");
}
}
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);
}
}
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').");
}
}
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!");
}
}
}
Aggregations