urn_perun_user_attribute_def_def_vsupMailAlias extends UserAttributesModuleAbstract implements UserAttributesModuleImplApi { @Override public void checkAttributeSemantics(PerunSessionImpl sess, User user, Attribute attribute) throws WrongReferenceAttributeValueException { if (attribute.getValue() == null) return; try { Attribute reservedMailsAttribute = sess.getPerunBl().getAttributesManagerBl().getEntitylessAttributeForUpdate(sess, usedMailsKeyVsup, usedMailsUrn); if (reservedMailsAttribute.getValue() != null) { Map<String,String> reservedMailsAttributeValue = reservedMailsAttribute.valueAsMap(); String ownersUserId = reservedMailsAttributeValue.get(attribute.valueAsString()); if (ownersUserId != null && !Objects.equals(ownersUserId, String.valueOf(user.getId()))) { User ownersUser = sess.getPerunBl().getUsersManagerBl().getUserById(sess, Integer.parseInt(ownersUserId)); throw new WrongReferenceAttributeValueException(attribute, reservedMailsAttribute, user, null, ownersUser, null, "VŠUP mail alias: '"+attribute.getValue()+"' is already in use by User ID: " + ownersUserId + "."); } } } catch (AttributeNotExistsException ex) { throw new ConsistencyErrorException("Attribute doesn't exists.", ex); } catch (UserNotExistsException e) { throw new ConsistencyErrorException("User doesn't exists.", e); } }  @Override void checkAttributeSyntax(PerunSessionImpl sess, User user, Attribute attribute); @Override void checkAttributeSemantics(PerunSessionImpl sess, User user, Attribute attribute); @Override List<String> getDependencies(); @Override Attribute fillAttribute(PerunSessionImpl session, User user, AttributeDefinition attribute); @Override void changedAttributeHook(PerunSessionImpl session, User user, Attribute attribute); @Override AttributeDefinition getAttributeDefinition();  }
@Test(expected = WrongReferenceAttributeValueException.class) public void testCheckSemanticsWithInvalidLogin() throws Exception { System.out.println("testCheckSemanticsWithInvalidLogin()"); Map<String, String> value = new LinkedHashMap<>(); value.put("john.doe@vsup.cz", "5"); reqAttribute.setValue(value); attributeToCheck.setValue("john.doe@vsup.cz"); classInstance.checkAttributeSemantics(session, user, attributeToCheck); }
@Test public void testCorrectSemantics() throws Exception { System.out.println("testCheckSemanticsWithInvalidLogin()"); Map<String, String> value = new LinkedHashMap<>(); value.put("john.doe@vsup.cz", "5"); reqAttribute.setValue(value); attributeToCheck.setValue("john.doe1@vsup.cz"); classInstance.checkAttributeSemantics(session, user, attributeToCheck); }