urn_perun_group_resource_attribute_def_def_systemUnixGroupName extends GroupResourceAttributesModuleAbstract implements GroupResourceAttributesModuleImplApi { @Override public void checkAttributeSemantics(PerunSessionImpl sess, Group group, Resource resource, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException{ String groupName = attribute.valueAsString(); Attribute isSystemGroup; if(groupName==null) { try { isSystemGroup = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, group, A_GR_systemIsUnixGroup); } catch(AttributeNotExistsException ex) { throw new ConsistencyErrorException("Not exist Attribute " + A_GR_systemIsUnixGroup + " for group " + group,ex); } catch (GroupResourceMismatchException ex) { throw new InternalErrorException(ex); } if(isSystemGroup.getValue() != null && isSystemGroup.valueAsInteger()==1) { throw new WrongReferenceAttributeValueException(attribute, isSystemGroup, group, resource, "Attribute cant be null if " + group + " on " + resource + " is system unix group."); } return; } Facility facility = sess.getPerunBl().getResourcesManagerBl().getFacility(sess, resource); List<Pair<Group,Resource>> listGroupPairsResource =sess.getPerunBl().getGroupsManagerBl().getGroupResourcePairsByAttribute(sess, attribute); for(Pair<Group,Resource> p : listGroupPairsResource) { if(!p.getLeft().equals(group) || !p.getRight().equals(resource)) { Facility facilityForTest = sess.getPerunBl().getResourcesManagerBl().getFacility(sess, p.getRight()); Attribute group1GID; Attribute group2GID; try { group1GID = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, group, A_GR_systemUnixGID); } catch (AttributeNotExistsException ex) { throw new ConsistencyErrorException("Attribute "+ A_GR_systemUnixGID +" not exists for group " + group + " and resource " + resource,ex); } catch (GroupResourceMismatchException ex) { throw new InternalErrorException(ex); } try { group2GID = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, p.getRight(), p.getLeft(), A_GR_systemUnixGID); } catch (AttributeNotExistsException ex) { throw new ConsistencyErrorException("Attribute "+ A_GR_systemUnixGID +" not exists for group " + p.getLeft() + " and resource " + p.getRight() ,ex); } catch (GroupResourceMismatchException ex) { throw new InternalErrorException(ex); } if(facilityForTest.equals(facility) && (group1GID.getValue() != null ? (! group1GID.getValue().equals(group2GID.getValue())) : group2GID != null)) { throw new WrongReferenceAttributeValueException(attribute, attribute, group, resource, "Group name " + groupName + "is already used by another group-resource and these have not the same GID and GroupName. " + p.getLeft() + " " + p.getRight()); } } } }  @Override Attribute fillAttribute(PerunSessionImpl sess, Group group, Resource resource, AttributeDefinition attributeDefinition); @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 testSemanticsNullValueWithUnixGroup() throws Exception { System.out.println("testSemanticsNullValueWithUnixGroup()"); attributeToCheck.setValue(null); reqAttribute.setValue(1); classInstance.checkAttributeSemantics(sess, group, resource, attributeToCheck); }
@Test(expected = WrongReferenceAttributeValueException.class) public void testSemanticsGroupNameAlreadyUsed() throws Exception { System.out.println("testSemanticsGroupNameAlreadyUsed()"); attributeToCheck.setValue("name"); reqAttribute.setValue(1); reqAttribute2.setValue(2); classInstance.checkAttributeSemantics(sess, group, resource, attributeToCheck); }
@Test public void testCorrectSemantics() throws Exception { System.out.println("testCorrectSemantics()"); attributeToCheck.setValue("name"); reqAttribute.setValue(1); reqAttribute2.setValue(1); classInstance.checkAttributeSemantics(sess, group, resource, attributeToCheck); }