urn_perun_group_resource_attribute_def_def_projectOwnerLogin extends GroupResourceAttributesModuleAbstract implements GroupResourceAttributesModuleImplApi { @Override public void checkAttributeSemantics(PerunSessionImpl sess, Group group, Resource resource, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException { String ownerLogin = attribute.valueAsString(); if (ownerLogin == null) return; Facility facility = sess.getPerunBl().getResourcesManagerBl().getFacility(sess, resource); Attribute loginNamespaceAttribute = null; try { loginNamespaceAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":login-namespace"); } catch (AttributeNotExistsException e) { throw new ConsistencyErrorException(e); } if (loginNamespaceAttribute != null && loginNamespaceAttribute.valueAsString() != null) { try { AttributeDefinition loginAttributeDef = sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:"+loginNamespaceAttribute.valueAsString()); Attribute loginAttribute = new Attribute(loginAttributeDef); loginAttribute.setValue(ownerLogin); List<User> usersWithlogin = sess.getPerunBl().getUsersManagerBl().getUsersByAttribute(sess, loginAttribute); if (usersWithlogin.isEmpty()) { throw new WrongReferenceAttributeValueException(attribute, null, group, resource, "There is no user with login '" + ownerLogin+"' in namespace '"+loginNamespaceAttribute.valueAsString()+"'."); } } catch (AttributeNotExistsException e) { throw new ConsistencyErrorException(e); } } else { throw new WrongReferenceAttributeValueException(attribute, loginNamespaceAttribute, group, resource, facility, null, "Login-namespace on facility can`t be empty."); } }  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 testSemanticsNoUserWithGivenName() throws Exception { System.out.println("testSemanticsNoUserWithGivenName()"); attributeToCheck.setValue("correct_value"); namespaceAttribute.setValue(null); classInstance.checkAttributeSemantics(sess, group, resource, attributeToCheck); }
@Test public void testCorrectSemantics() throws Exception { System.out.println("testCorrectSemantics()"); attributeToCheck.setValue("correct_value"); classInstance.checkAttributeSemantics(sess, group, resource, attributeToCheck); }