diff --git a/src/main/java/org/olat/course/assessment/bulk/ValidationStepForm.java b/src/main/java/org/olat/course/assessment/bulk/ValidationStepForm.java index 2c2709c840a574ba077783ccac8f17d65745f54a..989fc82068aeb73f03d9e52723ce0d8798b26d16 100644 --- a/src/main/java/org/olat/course/assessment/bulk/ValidationStepForm.java +++ b/src/main/java/org/olat/course/assessment/bulk/ValidationStepForm.java @@ -163,8 +163,10 @@ public class ValidationStepForm extends StepFormBasicController { } for(String prop : userPropsToSearch) { - identity = userManager.findIdentityKeyWithProperty(prop, assessedId); - if(identity != null) { + List<Identity> found = userManager.findIdentitiesWithProperty(prop, assessedId); + if(found.size() > 0) { + // ignore multiple hits, just take the first one + identity = found.get(0); idToIdentityMap.put(assessedId, identity); continue; } diff --git a/src/main/java/org/olat/user/UserManager.java b/src/main/java/org/olat/user/UserManager.java index cbcc3c2c5d0acbe57c2ebc117c4602a030b625f9..83019cab1e04559469e8b8dcd115aad4c3ce1a9d 100644 --- a/src/main/java/org/olat/user/UserManager.java +++ b/src/main/java/org/olat/user/UserManager.java @@ -84,9 +84,25 @@ public abstract class UserManager extends BasicManager { */ public abstract User createUser(String firstName, String lastName, String eMail); + /** + * Find all user database keys where the given property name matches the property + * value (exact match) + * + * @param propName + * @param propValue + * @return + */ public abstract List<Long> findUserKeyWithProperty(String propName, String propValue); - public abstract Identity findIdentityKeyWithProperty(String propName, String propValue); + /** + * Find all identities where the given property name matches the property + * value (exact match) + * + * @param propName + * @param propValue + * @return The list of identities or NULL if nothing found + */ + public abstract List<Identity> findIdentitiesWithProperty(String propName, String propValue); /** * Find the identity (and the user) that match the given email address. The diff --git a/src/main/java/org/olat/user/UserManagerImpl.java b/src/main/java/org/olat/user/UserManagerImpl.java index a818d2659ba880ec3640b7468614c3d30103c85f..4cf8b9a35394377d7cd0d20037c0f78b76dc0d35 100644 --- a/src/main/java/org/olat/user/UserManagerImpl.java +++ b/src/main/java/org/olat/user/UserManagerImpl.java @@ -159,7 +159,7 @@ public class UserManagerImpl extends UserManager { } @Override - public Identity findIdentityKeyWithProperty(String propName, String propValue) { + public List<Identity> findIdentitiesWithProperty(String propName, String propValue) { StringBuilder sb = new StringBuilder("select identity from ").append(IdentityImpl.class.getName()).append(" identity ") .append(" inner join fetch identity.user user ") .append(" where user.").append(propName).append("=:propValue"); @@ -170,7 +170,7 @@ public class UserManagerImpl extends UserManager { if(userKeys.isEmpty()) { return null; } - return userKeys.get(0); + return userKeys; } /** diff --git a/src/main/java/org/olat/user/propertyhandlers/GenericUnique127CharTextPropertyHandler.java b/src/main/java/org/olat/user/propertyhandlers/GenericUnique127CharTextPropertyHandler.java index 3c3c85ade21846500b6201844bcd82f236056f5f..ac38b1a8c6f94bd17888cbcd889b4d6d2649fc76 100644 --- a/src/main/java/org/olat/user/propertyhandlers/GenericUnique127CharTextPropertyHandler.java +++ b/src/main/java/org/olat/user/propertyhandlers/GenericUnique127CharTextPropertyHandler.java @@ -47,10 +47,15 @@ public class GenericUnique127CharTextPropertyHandler extends Generic127CharTextP if(formItem instanceof TextElement) { String value = ((TextElement)formItem).getValue(); if(!isUnique(user, value)) { - Identity propId = UserManager.getInstance().findIdentityKeyWithProperty(getName(), value); - String email = propId.getUser().getProperty(UserConstants.EMAIL, null); - formItem.setErrorKey("general.error.unique", new String[]{ email }); - allOk &= false; + List<Identity> found = UserManager.getInstance().findIdentitiesWithProperty(getName(), value); + Identity propId = null; + if(found.size() > 0) { + // only display first one + propId = found.get(0); + String email = propId.getUser().getProperty(UserConstants.EMAIL, null); + formItem.setErrorKey("general.error.unique", new String[]{ email }); + allOk &= false; + } } } @@ -62,11 +67,16 @@ public class GenericUnique127CharTextPropertyHandler extends Generic127CharTextP boolean allOk = super.isValidValue(user, value, validationError, locale); if(!isUnique(user, value)) { - Identity propId = UserManager.getInstance().findIdentityKeyWithProperty(getName(), value); - String email = propId.getUser().getProperty(UserConstants.EMAIL, null); - validationError.setErrorKey("general.error.unique"); - validationError.setArgs(new String[]{ email }); - allOk &= false; + List<Identity> found = UserManager.getInstance().findIdentitiesWithProperty(getName(), value); + Identity propId = null; + if(found.size() > 0) { + // only display first one + propId = found.get(0); + String email = propId.getUser().getProperty(UserConstants.EMAIL, null); + validationError.setErrorKey("general.error.unique"); + validationError.setArgs(new String[]{ email }); + allOk &= false; + } } return allOk;