class 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;

		//Get Facility from resource
		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);
		}

		// facility has namespace for logins
		if (loginNamespaceAttribute != null && loginNamespaceAttribute.valueAsString() != null) {

			try {

				// get login attr
				AttributeDefinition loginAttributeDef = sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:"+loginNamespaceAttribute.valueAsString());

				// check that some user have it with our value
				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) {
				// there is no user login namespace attribute with namespace set on facility
				throw new ConsistencyErrorException(e);
			}

		} else {
			throw new WrongReferenceAttributeValueException(attribute, loginNamespaceAttribute, group, resource, facility, null, "Login-namespace on facility can`t be empty.");
		}

	}

}