urn_perun_group_resource_attribute_def_def_projectName extends GroupResourceAttributesModuleAbstract implements GroupResourceAttributesModuleImplApi { @Override public void checkAttributeSemantics(PerunSessionImpl sess, Group group, Resource resource, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException { String name = attribute.valueAsString(); if (name == null) return; Attribute thisResourceProjectsBasePath; try { thisResourceProjectsBasePath = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, A_R_projectsBasePath); } catch (AttributeNotExistsException ex) { throw new ConsistencyErrorException("Attribute projectBasePath not exists!", ex); } String thisResourceProjectBasePathValue; if(thisResourceProjectsBasePath.getValue() != null) { thisResourceProjectBasePathValue = thisResourceProjectsBasePath.valueAsString(); } else { throw new WrongReferenceAttributeValueException(attribute, thisResourceProjectsBasePath, group, resource, resource, null, "Resource must have set projectsBasePath if attribute projectName for it's group need to be set."); } Facility facility = sess.getPerunBl().getResourcesManagerBl().getFacility(sess, resource); List<Resource> resources = sess.getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility); resources.remove(resource); Iterator<Resource> iterator = resources.iterator(); while(iterator.hasNext()) { Resource r = iterator.next(); Attribute otherResourceProjectsBasePath; try { otherResourceProjectsBasePath = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, r, A_R_projectsBasePath); } catch (AttributeNotExistsException ex) { throw new ConsistencyErrorException("Attribute projectBasePath not exists!", ex); } if(otherResourceProjectsBasePath.getValue() != null) { String otherResourceProjectsBasePathValue = otherResourceProjectsBasePath.valueAsString(); if(!thisResourceProjectBasePathValue.equals(otherResourceProjectsBasePathValue)) iterator.remove(); } else { iterator.remove(); } } for(Resource r: resources) { List<Group> groups = sess.getPerunBl().getGroupsManagerBl().getAssignedGroupsToResource(sess, r); groups.remove(group); for(Group g: groups) { Attribute groupProjectName; try { groupProjectName = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, r, g, A_GR_projectName); } catch (AttributeNotExistsException ex) { throw new ConsistencyErrorException("Attribute projectName not exists!", ex); } catch (GroupResourceMismatchException ex) { throw new InternalErrorException(ex); } String groupProjectNameValue = null; if(groupProjectName.getValue() != null) { groupProjectNameValue = groupProjectName.valueAsString(); } if(name.equals(groupProjectNameValue)) { throw new WrongReferenceAttributeValueException(attribute, groupProjectName, group, resource, g, r, "Group " + group + " and " + g + " have the same projectName in the same projectsBasePath."); } } } }  @Override void checkAttributeSyntax(PerunSessionImpl sess, Group group, Resource resource, Attribute attribute); @Override void checkAttributeSemantics(PerunSessionImpl sess, Group group, Resource resource, Attribute attribute); @Override List<String> getDependencies(); @Override AttributeDefinition getAttributeDefinition();  }
@Test(expected = WrongReferenceAttributeValueException.class) public void testSemanticsReqAttributeWithNullValue() throws Exception { System.out.println("testSemanticsReqAttributeWithNullValue()"); attributeToCheck.setValue("correct_value"); reqAttribute.setValue(null); classInstance.checkAttributeSemantics(sess, group, resource, attributeToCheck); }
@Test(expected = WrongReferenceAttributeValueException.class) public void testSemanticsMultipleGroupsWithSameName() throws Exception { System.out.println("testSemanticsMultipleGroupsWithSameName()"); attributeToCheck.setValue("correct_value"); reqAttribute.setValue("correct_value"); classInstance.checkAttributeSemantics(sess, group, resource, attributeToCheck); }
@Test public void testCorrectSemantics() throws Exception { System.out.println("testCorrectSemantics()"); attributeToCheck.setValue("correct_value"); reqAttribute.setValue("another_correct_value"); classInstance.checkAttributeSemantics(sess, group, resource, attributeToCheck); }