urn_perun_group_resource_attribute_def_def_projectDataLimit extends GroupResourceAttributesModuleAbstract implements GroupResourceAttributesModuleImplApi { @Override public void checkAttributeSemantics(PerunSessionImpl perunSession, Group group, Resource resource, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException { Attribute attrProjectDataQuota; String projectDataQuota = null; if(attribute.getValue() == null) return; Pair<BigDecimal, String> limitNumberAndLetter = ModulesUtilsBlImpl.getNumberAndUnitFromString(attribute.valueAsString()); BigDecimal limitNumber = limitNumberAndLetter.getLeft(); String projectDataLimitLetter = limitNumberAndLetter.getRight(); try { attrProjectDataQuota = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, resource, group, A_GR_projectDataQuota); } catch (AttributeNotExistsException ex) { throw new ConsistencyErrorException("Attribute with projectDataQuota from resource " + resource.getId() + " and group + " + group.getId() + " could not obtain.", ex); } catch (GroupResourceMismatchException ex) { throw new InternalErrorException(ex); } if (attrProjectDataQuota != null) projectDataQuota = attrProjectDataQuota.valueAsString(); Pair<BigDecimal, String> quotaNumberAndLetter = ModulesUtilsBlImpl.getNumberAndUnitFromString(projectDataQuota); BigDecimal quotaNumber = quotaNumberAndLetter.getLeft(); String projectDataQuotaLetter = quotaNumberAndLetter.getRight(); if (quotaNumber.compareTo(BigDecimal.valueOf(0)) < 0) { throw new WrongReferenceAttributeValueException(attribute, attrProjectDataQuota, attrProjectDataQuota + " cant be less than 0."); } if (quotaNumber.compareTo(BigDecimal.valueOf(0)) == 0) { if (limitNumber.compareTo(BigDecimal.valueOf(0)) != 0) { throw new WrongReferenceAttributeValueException(attribute, attrProjectDataQuota, "Try to set limited limit, but there is still set unlimited Quota."); } } else if ((quotaNumber.compareTo(BigDecimal.valueOf(0)) != 0) && (limitNumber.compareTo(BigDecimal.valueOf(0)) != 0) && projectDataQuotaLetter != null) { switch (projectDataLimitLetter) { case "K": limitNumber = limitNumber.multiply(BigDecimal.valueOf(K)); break; case "M": limitNumber = limitNumber.multiply(BigDecimal.valueOf(M)); break; case "T": limitNumber = limitNumber.multiply(BigDecimal.valueOf(T)); break; case "P": limitNumber = limitNumber.multiply(BigDecimal.valueOf(P)); break; case "E": limitNumber = limitNumber.multiply(BigDecimal.valueOf(E)); break; default: limitNumber = limitNumber.multiply(BigDecimal.valueOf(G)); break; } switch (projectDataQuotaLetter) { case "K": quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(K)); break; case "M": quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(M)); break; case "T": quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(T)); break; case "P": quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(P)); break; case "E": quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(E)); break; default: quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(G)); break; } if (limitNumber.compareTo(quotaNumber) < 0) { throw new WrongReferenceAttributeValueException(attribute, attrProjectDataQuota, group, resource, group, resource, attribute + " must be more than or equals to " + attrProjectDataQuota); } } }  @Override void checkAttributeSyntax(PerunSessionImpl perunSession, Group group, Resource resource, Attribute attribute); @Override void checkAttributeSemantics(PerunSessionImpl perunSession, Group group, Resource resource, Attribute attribute); @Override List<String> getDependencies(); @Override AttributeDefinition getAttributeDefinition();  }
@Test(expected = WrongReferenceAttributeValueException.class) public void testSemanticsQuotaHigherThanLimit() throws Exception { System.out.println("testSemanticsQuotaHigherThanLimit()"); attributeToCheck.setValue("22M"); reqAttribute.setValue("10T"); classInstance.checkAttributeSemantics(sess, group, resource, attributeToCheck); }
@Test public void testCorrectSemantics() throws Exception { System.out.println("testCorrectSemantics()"); attributeToCheck.setValue("22T"); reqAttribute.setValue("10M"); classInstance.checkAttributeSemantics(sess, group, resource, attributeToCheck); }