class urn_perun_resource_attribute_def_def_fairshareGroupName extends ResourceAttributesModuleAbstract implements ResourceAttributesModuleImplApi {

	@Override
	public void checkAttributeSemantics(PerunSessionImpl perunSession, Resource resource, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
		//Null is ok, it means this resource is not fairshare group
		if (attribute.getValue() == null) {
			return;
		}

		String gName = attribute.valueAsString();

		//On facility must be fairshare group name unique (between all resources of this facility)
		Facility facility = perunSession.getPerunBl().getResourcesManagerBl().getFacility(perunSession, resource);
		List<Resource> facilityResources = perunSession.getPerunBl().getFacilitiesManagerBl().getAssignedResources(perunSession, facility);
		facilityResources.remove(resource);
		for(Resource res: facilityResources) {
			try {
				Attribute resFairshareName = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, res, attribute.getName());

				if (resFairshareName.getValue() != null && gName.equals(resFairshareName.valueAsString())) {
					throw new WrongReferenceAttributeValueException(attribute, resFairshareName, resource, null, res, null, "This name is already taken (not unique). Choose another one.");
				}
			} catch (AttributeNotExistsException ex) {
				throw new ConsistencyErrorException(ex);
			}
		}
	}

}