use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class urn_perun_user_attribute_def_def_vsupMailAlias method checkAttributeValue.
@Override
public void checkAttributeValue(PerunSessionImpl sess, User user, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongAttributeAssignmentException {
// can be empty
if (attribute.getValue() == null)
return;
// if set, must match generic format
Matcher emailMatcher = emailAliasPattern.matcher((String) attribute.getValue());
if (!emailMatcher.find())
throw new WrongAttributeValueException(attribute, user, "School mail alias is not in a correct form: \"firstName.lastName[counter]@vsup.cz\".");
try {
Attribute reservedMailsAttribute = sess.getPerunBl().getAttributesManagerBl().getEntitylessAttributeForUpdate(sess, usedMailsKeyVsup, usedMailsUrn);
if (reservedMailsAttribute.getValue() != null) {
Map<String, String> reservedMailsAttributeValue = (Map<String, String>) reservedMailsAttribute.getValue();
String ownersUserId = reservedMailsAttributeValue.get((String) attribute.getValue());
if (ownersUserId != null && !Objects.equals(ownersUserId, String.valueOf(user.getId()))) {
throw new WrongAttributeValueException("VŠUP mail alias: '" + attribute.getValue() + "' is already in use by User ID: " + ownersUserId + ".");
}
}
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Attribute doesn't exists.", ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class FacilitiesManagerBlImpl method getAllowedVos.
public List<Vo> getAllowedVos(PerunSession sess, Facility facility) throws InternalErrorException {
List<Vo> vos = new ArrayList<Vo>();
List<Integer> voIds = getFacilitiesManagerImpl().getAllowedVosIds(sess, facility);
try {
for (Integer id : voIds) {
vos.add(getPerunBl().getVosManagerBl().getVoById(sess, id));
}
} catch (VoNotExistsException ex) {
throw new ConsistencyErrorException("Non-existent VO is allowed on the facility", ex);
}
return vos;
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException 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.ConsistencyErrorException 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.ConsistencyErrorException 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);
}
}
}
Aggregations