class urn_perun_user_attribute_def_def_cnCeitecAD extends UserAttributesModuleAbstract implements UserAttributesModuleImplApi {

	@Override
	public void checkAttributeSemantics(PerunSessionImpl perunSession, User user, Attribute attribute) throws WrongReferenceAttributeValueException {

		if (attribute.getValue() == null) {
			throw new WrongReferenceAttributeValueException(attribute, null, user, null, "Value can't be null");
		}

		// check existing DN
		Set<User> usersWithSameCN = new HashSet<>(perunSession.getPerunBl().getUsersManagerBl().getUsersByAttribute(perunSession, attribute));
		// check existing DN without accents
		String normalizedValue = java.text.Normalizer.normalize((String)attribute.getValue(), java.text.Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+","");
		if (!Objects.equals(normalizedValue, attribute.getValue())) {
			Attribute changedAttribute = new Attribute(attribute);
			changedAttribute.setValue(normalizedValue);
			usersWithSameCN.addAll(perunSession.getPerunBl().getUsersManagerBl().getUsersByAttribute(perunSession, changedAttribute));
		}
		usersWithSameCN.remove(user); //remove self
		if (!usersWithSameCN.isEmpty()) {
			if(usersWithSameCN.size() > 1) throw new ConsistencyErrorException("FATAL ERROR: Duplicated CN detected." +  attribute + " " + usersWithSameCN);
			throw new WrongReferenceAttributeValueException(attribute, attribute, user, null, usersWithSameCN.iterator().next(), null, "This CN " + attribute.getValue() + " is already occupied for CEITEC AD");
		}

	}

}