urn_perun_group_resource_attribute_def_def_freeipaGroupName extends GroupResourceAttributesModuleAbstract implements GroupResourceAttributesModuleImplApi { @Override public void checkAttributeSemantics(PerunSessionImpl sess, Group group, Resource resource, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException { String groupName = attribute.valueAsString(); if (groupName == null) { throw new WrongReferenceAttributeValueException(attribute, null, group, resource, "Attribute cannot be null."); } Facility facility = sess.getPerunBl().getResourcesManagerBl().getFacility(sess, resource); List<Resource> facilityResources = sess.getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility); for(Resource rs : facilityResources){ List<Group> resourceGroups = sess.getPerunBl().getResourcesManagerBl().getAssignedGroups(sess, rs); if (rs.getId() == resource.getId()){ resourceGroups.remove(group); } for(Group gr : resourceGroups){ Attribute freeipaGroupNameAttribute; try{ freeipaGroupNameAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, rs, gr, A_GR_freeipaGroupName); } catch(AttributeNotExistsException ex) { throw new ConsistencyErrorException("Attribute "+ A_GR_freeipaGroupName +" does not exists for group " + gr + " and resource " + rs ,ex); } catch (GroupResourceMismatchException ex) { throw new InternalErrorException(ex); } if (freeipaGroupNameAttribute.getValue() != null){ String name = freeipaGroupNameAttribute.valueAsString(); if (name.toLowerCase().equals(groupName.toLowerCase())){ throw new WrongReferenceAttributeValueException(attribute, freeipaGroupNameAttribute, group, resource, rs, gr, "Attribute has to be unique within one facility (case insensitive)."); } } } } }  @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 testSemanticsWithNullValue() throws Exception { System.out.println("testSemanticsWithNullValue()"); attributeToCheck.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); }