use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException 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);
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException in project perun by CESNET.
the class urn_perun_member_resource_attribute_def_def_dataLimit method checkAttributeValue.
@Override
public void checkAttributeValue(PerunSessionImpl perunSession, Resource resource, Member member, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
Attribute attrDataQuota = null;
String dataQuota = null;
String dataLimit = null;
String dataQuotaNumber = null;
String dataQuotaLetter = null;
String dataLimitNumber = null;
String dataLimitLetter = null;
//Get attrDataQuota attribute
try {
attrDataQuota = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, resource, member, A_MR_dataQuota);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Attribute with dataQuota from member " + member.getId() + " and resource " + resource.getId() + " could not obtained.", ex);
}
//Get dataLimit value
if (attribute.getValue() == null) {
try {
attribute = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, resource, A_R_defaultDataLimit);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Attribute with defaultDataLimit from resource " + resource.getId() + " could not obtained.", ex);
}
}
if (attribute.getValue() != null) {
dataLimit = (String) attribute.getValue();
Matcher numberMatcher = numberPattern.matcher(dataLimit);
Matcher letterMatcher = letterPattern.matcher(dataLimit);
numberMatcher.find();
letterMatcher.find();
try {
dataLimitNumber = dataLimit.substring(numberMatcher.start(), numberMatcher.end());
} catch (IllegalStateException ex) {
dataLimitNumber = null;
}
try {
dataLimitLetter = dataLimit.substring(letterMatcher.start(), letterMatcher.end());
} catch (IllegalStateException ex) {
dataLimitLetter = "G";
}
}
BigDecimal limitNumber;
if (dataLimitNumber != null)
limitNumber = new BigDecimal(dataLimitNumber.replace(',', '.').toString());
else
limitNumber = new BigDecimal("0");
if (limitNumber != null && limitNumber.compareTo(BigDecimal.valueOf(0)) < 0) {
throw new WrongAttributeValueException(attribute, resource, member, attribute + " cant be less than 0.");
}
//Get dataQuota value
if (attrDataQuota == null || attrDataQuota.getValue() == null) {
try {
attrDataQuota = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, resource, A_R_defaultDataQuota);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Attribute with defaultDataQuota from resource " + resource.getId() + " could not obtained.", ex);
}
}
if (attrDataQuota != null && attrDataQuota.getValue() != null) {
dataQuota = (String) attrDataQuota.getValue();
Matcher numberMatcher = numberPattern.matcher(dataQuota);
Matcher letterMatcher = letterPattern.matcher(dataQuota);
numberMatcher.find();
letterMatcher.find();
try {
dataQuotaNumber = dataQuota.substring(numberMatcher.start(), numberMatcher.end());
} catch (IllegalStateException ex) {
dataQuotaNumber = null;
}
try {
dataQuotaLetter = dataQuota.substring(letterMatcher.start(), letterMatcher.end());
} catch (IllegalStateException ex) {
dataQuotaLetter = "G";
}
}
BigDecimal quotaNumber;
if (dataQuotaNumber != null)
quotaNumber = new BigDecimal(dataQuotaNumber.replace(',', '.'));
else
quotaNumber = new BigDecimal("0");
if (quotaNumber != null && quotaNumber.compareTo(BigDecimal.valueOf(0)) < 0) {
throw new WrongReferenceAttributeValueException(attribute, attrDataQuota, resource, member, resource, null, attrDataQuota + " cant be less than 0.");
}
//Compare dataLimit with dataQuota
if (quotaNumber == null || quotaNumber.compareTo(BigDecimal.valueOf(0)) == 0) {
if (limitNumber != null && limitNumber.compareTo(BigDecimal.valueOf(0)) != 0) {
throw new WrongReferenceAttributeValueException(attribute, attrDataQuota, resource, member, resource, null, "Try to set limited limit, but there is still set unlimited Quota.");
}
} else if ((quotaNumber != null && quotaNumber.compareTo(BigDecimal.valueOf(0)) != 0) && (limitNumber != null && limitNumber.compareTo(BigDecimal.valueOf(0)) != 0)) {
if (dataLimitLetter.equals("K"))
limitNumber = limitNumber.multiply(BigDecimal.valueOf(K));
else if (dataLimitLetter.equals("M"))
limitNumber = limitNumber.multiply(BigDecimal.valueOf(M));
else if (dataLimitLetter.equals("T"))
limitNumber = limitNumber.multiply(BigDecimal.valueOf(T));
else if (dataLimitLetter.equals("P"))
limitNumber = limitNumber.multiply(BigDecimal.valueOf(P));
else if (dataLimitLetter.equals("E"))
limitNumber = limitNumber.multiply(BigDecimal.valueOf(E));
else
limitNumber = limitNumber.multiply(BigDecimal.valueOf(G));
if (dataQuotaLetter.equals("K"))
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(K));
else if (dataQuotaLetter.equals("M"))
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(M));
else if (dataQuotaLetter.equals("T"))
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(T));
else if (dataQuotaLetter.equals("P"))
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(P));
else if (dataQuotaLetter.equals("E"))
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(E));
else
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(G));
if (limitNumber.compareTo(quotaNumber) < 0) {
throw new WrongReferenceAttributeValueException(attribute, attrDataQuota, resource, member, resource, null, attribute + " must be more than or equals to " + attrDataQuota);
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException in project perun by CESNET.
the class urn_perun_member_resource_attribute_def_def_dataQuota method checkAttributeValue.
@Override
public void checkAttributeValue(PerunSessionImpl perunSession, Resource resource, Member member, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
Attribute attrDataLimit = null;
String dataQuota = null;
String dataLimit = null;
String dataQuotaNumber = null;
String dataQuotaLetter = null;
String dataLimitNumber = null;
String dataLimitLetter = null;
//Get attrDataLimit attribute
try {
attrDataLimit = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, resource, member, A_MR_dataLimit);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Attribute with dataLimit from member " + member.getId() + " and resource " + resource.getId() + " could not obtained.", ex);
}
//Get dataQuota value
if (attribute.getValue() == null) {
try {
attribute = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, resource, A_R_defaultDataQuota);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Attribute with defaultDataQuota from resource " + resource.getId() + " could not obtained.", ex);
}
}
if (attribute.getValue() != null) {
dataQuota = (String) attribute.getValue();
Matcher numberMatcher = numberPattern.matcher(dataQuota);
Matcher letterMatcher = letterPattern.matcher(dataQuota);
numberMatcher.find();
letterMatcher.find();
try {
dataQuotaNumber = dataQuota.substring(numberMatcher.start(), numberMatcher.end());
} catch (IllegalStateException ex) {
dataQuotaNumber = null;
}
try {
dataQuotaLetter = dataQuota.substring(letterMatcher.start(), letterMatcher.end());
} catch (IllegalStateException ex) {
dataQuotaLetter = "G";
}
}
BigDecimal quotaNumber;
if (dataQuotaNumber != null)
quotaNumber = new BigDecimal(dataQuotaNumber.replace(',', '.').toString());
else
quotaNumber = new BigDecimal("0");
if (quotaNumber != null && quotaNumber.compareTo(BigDecimal.valueOf(0)) < 0) {
throw new WrongAttributeValueException(attribute, resource, member, attribute + " cant be less than 0.");
}
//Get dataLimit value
if (attrDataLimit == null || attrDataLimit.getValue() == null) {
try {
attrDataLimit = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, resource, A_R_defaultDataLimit);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Attribute with defaultDataLimit from resource " + resource.getId() + " could not obtained.", ex);
}
}
if (attrDataLimit != null && attrDataLimit.getValue() != null) {
dataLimit = (String) attrDataLimit.getValue();
Matcher numberMatcher = numberPattern.matcher(dataLimit);
Matcher letterMatcher = letterPattern.matcher(dataLimit);
numberMatcher.find();
letterMatcher.find();
try {
dataLimitNumber = dataLimit.substring(numberMatcher.start(), numberMatcher.end());
} catch (IllegalStateException ex) {
dataLimitNumber = null;
}
try {
dataLimitLetter = dataLimit.substring(letterMatcher.start(), letterMatcher.end());
} catch (IllegalStateException ex) {
dataLimitLetter = "G";
}
}
BigDecimal limitNumber;
if (dataLimitNumber != null)
limitNumber = new BigDecimal(dataLimitNumber.replace(',', '.'));
else
limitNumber = new BigDecimal("0");
if (limitNumber != null && limitNumber.compareTo(BigDecimal.valueOf(0)) < 0) {
throw new WrongReferenceAttributeValueException(attribute, attrDataLimit, resource, member, resource, null, attrDataLimit + " cant be less than 0.");
}
//Compare dataQuota with dataLimit
if (quotaNumber == null || quotaNumber.compareTo(BigDecimal.valueOf(0)) == 0) {
if (limitNumber != null && limitNumber.compareTo(BigDecimal.valueOf(0)) != 0) {
throw new WrongReferenceAttributeValueException(attribute, attrDataLimit, resource, member, resource, null, "Try to set unlimited quota, but limit is still " + dataLimitNumber + dataLimitLetter);
}
} else if (limitNumber != null && limitNumber.compareTo(BigDecimal.valueOf(0)) != 0) {
if (dataLimitLetter.equals("K"))
limitNumber = limitNumber.multiply(BigDecimal.valueOf(K));
else if (dataLimitLetter.equals("M"))
limitNumber = limitNumber.multiply(BigDecimal.valueOf(M));
else if (dataLimitLetter.equals("T"))
limitNumber = limitNumber.multiply(BigDecimal.valueOf(T));
else if (dataLimitLetter.equals("P"))
limitNumber = limitNumber.multiply(BigDecimal.valueOf(P));
else if (dataLimitLetter.equals("E"))
limitNumber = limitNumber.multiply(BigDecimal.valueOf(E));
else
limitNumber = limitNumber.multiply(BigDecimal.valueOf(G));
if (dataQuotaLetter.equals("K"))
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(K));
else if (dataQuotaLetter.equals("M"))
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(M));
else if (dataQuotaLetter.equals("T"))
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(T));
else if (dataQuotaLetter.equals("P"))
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(P));
else if (dataQuotaLetter.equals("E"))
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(E));
else
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(G));
if (limitNumber.compareTo(quotaNumber) < 0) {
throw new WrongReferenceAttributeValueException(attribute, attrDataLimit, resource, member, resource, null, attribute + " must be less than or equals to " + attrDataLimit);
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException in project perun by CESNET.
the class urn_perun_resource_attribute_def_def_defaultFilesLimit method checkAttributeValue.
@Override
public void checkAttributeValue(PerunSessionImpl perunSession, Resource resource, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
Attribute attrDefaultFilesQuota = null;
Integer defaultFilesQuota = null;
Integer defaultFilesLimit = null;
//get defaultFilesQuota attribute
try {
attrDefaultFilesQuota = 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);
}
//get defaultFilesLimit value
if (attribute.getValue() != null) {
defaultFilesLimit = (Integer) attribute.getValue();
}
if (defaultFilesLimit != null && defaultFilesLimit < 0)
throw new WrongAttributeValueException(attribute, resource, attribute + " cannot be less than 0.");
//get defaultFilesQuota value
if (attrDefaultFilesQuota != null && attrDefaultFilesQuota.getValue() != null) {
defaultFilesQuota = (Integer) attrDefaultFilesQuota.getValue();
}
if (defaultFilesQuota != null && defaultFilesQuota < 0)
throw new ConsistencyErrorException(attrDefaultFilesQuota + " cannot be less than 0.");
//Compare defaultFilesLimit with defaultFilesQuota
if (defaultFilesQuota == null || defaultFilesQuota == 0) {
if (defaultFilesLimit != null && defaultFilesLimit != 0)
throw new WrongReferenceAttributeValueException(attribute, attrDefaultFilesQuota, resource, null, resource, null, "Try to set limited limit, but there is still set unlimited Quota.");
} else if ((defaultFilesQuota != null && defaultFilesQuota != 0) && (defaultFilesLimit != null && defaultFilesLimit != 0)) {
if (defaultFilesLimit < defaultFilesQuota)
throw new WrongReferenceAttributeValueException(attribute, attrDefaultFilesQuota, resource, null, resource, null, attribute + " must be more than or equals to " + attrDefaultFilesQuota);
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException in project perun by CESNET.
the class urn_perun_resource_attribute_def_def_defaultHomeMountPoint method checkAttributeValue.
/**
* Checks if the homemountpoint is contained in list of homemountpoint at underlying facility
* Allows valid unix paths
* @param perunSession
* @param resource
* @param attribute
* @throws InternalErrorException
* @throws WrongAttributeValueException
* @throws WrongReferenceAttributeValueException
* @throws WrongAttributeAssignmentException
*/
public void checkAttributeValue(PerunSessionImpl perunSession, Resource resource, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
if (attribute.getValue() == null) {
throw new WrongAttributeValueException(attribute);
}
Attribute resourceAttribute = null;
try {
resourceAttribute = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, resource, A_R_homeMountPoints);
} catch (AttributeNotExistsException ex) {
throw new InternalErrorException(ex);
}
if (resourceAttribute.getValue() == null)
throw new WrongReferenceAttributeValueException(resourceAttribute);
List<?> homeMntPoints = (List<?>) resourceAttribute.getValue();
if (!homeMntPoints.contains(attribute.getValue())) {
throw new WrongAttributeValueException(attribute, "Attribute value ins't defined in underlying resource. Attribute name=" + A_R_homeMountPoints);
}
Pattern pattern = Pattern.compile("^/[-a-zA-Z.0-9_/]*$");
Matcher match = pattern.matcher((String) attribute.getValue());
if (!match.matches()) {
throw new WrongAttributeValueException(attribute, "Wrong def. mount point format");
}
}
Aggregations