urn_perun_group_attribute_def_def_adName_o365mu extends GroupAttributesModuleAbstract implements GroupAttributesModuleImplApi { @Override public void checkAttributeSemantics(PerunSessionImpl sess, Group group, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException { if(attribute.getValue() == null) { return; } Map<Integer, Set<Resource>> mapOfResourcesByFacility = sess.getPerunBl().getResourcesManagerBl() .getAssignedResources(sess, group).stream() .collect(groupingBy(Resource::getFacilityId, toSet())); for(Set<Resource> setOfResourcesWithSameFacilityId : mapOfResourcesByFacility.values()) { boolean resourceWithOuSet = false; for (Resource resource : setOfResourcesWithSameFacilityId) { try { Attribute resourceAdOuName = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, A_R_D_AD_OU_NAME); if (resourceAdOuName.getValue() != null) { if(resourceWithOuSet) { throw new WrongReferenceAttributeValueException(attribute, resourceAdOuName, group, null, resource, null, "There is more than one resource where group is assigned and OU is also set there (on the same facility)!"); } else { resourceWithOuSet = true; } } } catch (AttributeNotExistsException ex) { throw new ConsistencyErrorException(ex); } } } }  @Override void checkAttributeSyntax(PerunSessionImpl sess, Group group, Attribute attribute); @Override void checkAttributeSemantics(PerunSessionImpl sess, Group group, Attribute attribute); @Override List<String> getDependencies(); @Override AttributeDefinition getAttributeDefinition();  }
@Test(expected = WrongReferenceAttributeValueException.class) public void testWrongSemanticsTwoResourcesWithOuSet() throws Exception { System.out.println("testSemanticsWithSameADNameAlreadySetElsewhere()"); attributeToCheck.setValue("correctValue"); reqAttribute1.setValue("ouTest1"); reqAttribute2.setValue("ouTest2"); when(resourcesManagerBl.getAssignedResources(sess, group)) .thenReturn(Arrays.asList(resource1, resource2)); classInstance.checkAttributeSemantics(sess, group, attributeToCheck); }
@Test public void testCorrectSemantics() throws Exception { System.out.println("testCorrectSemantics()"); attributeToCheck.setValue("correctValue"); reqAttribute1.setValue("ouTest1"); reqAttribute2.setValue(null); when(resourcesManagerBl.getAssignedResources(sess, group)) .thenReturn(Arrays.asList(resource1, resource2)); classInstance.checkAttributeSemantics(sess, group, attributeToCheck); }