class urn_perun_user_attribute_def_def_vsupMail extends UserAttributesModuleAbstract implements UserAttributesModuleImplApi {

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

		// check only if not null
		if (attribute.getValue() != null) {

			// check that mail matches login
			try {
				Attribute login = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, A_U_D_loginNamespace_vsup);

				// if login and mail value is set, they must match !!
				if (login.getValue() != null && attribute.getValue() != null) {
					if (!Objects.equals(login.getValue()+"@vsup.cz", attribute.getValue())) throw new WrongReferenceAttributeValueException(attribute, login, user, null, user, null, "VŠUP mail must match users login at VŠUP.");
				}
				// if only one of them is set, it's OK, because:
				// - we need vsupMail to be required, but it doesn't support fill (by purpose).
				// - it's set in changedAttributeHook() of login-namespace:vsup attribute during same transaction.
				// - always requiring non-null value would cause setRequiredAttributes() to fail, because of above and method implementation.
			} catch (AttributeNotExistsException e) {
				throw new ConsistencyErrorException("Attribute for login-namespace: vsup doesn't exists.", e);
			}

			//if (attribute.getValue() == null) throw new WrongAttributeValueException(attribute, user, "School mail can't be null.");

		}

		// We check uniqueness on all related attributes change, so we don't need to do it here.

	}

}