Skip to content
Snippets Groups Projects
Commit 0265ee59 authored by gnaegi's avatar gnaegi
Browse files

OO-2936 minor code refactoring, rename method

parent 327c8756
No related branches found
No related tags found
No related merge requests found
...@@ -163,8 +163,10 @@ public class ValidationStepForm extends StepFormBasicController { ...@@ -163,8 +163,10 @@ public class ValidationStepForm extends StepFormBasicController {
} }
for(String prop : userPropsToSearch) { for(String prop : userPropsToSearch) {
identity = userManager.findIdentityKeyWithProperty(prop, assessedId); List<Identity> found = userManager.findIdentitiesWithProperty(prop, assessedId);
if(identity != null) { if(found.size() > 0) {
// ignore multiple hits, just take the first one
identity = found.get(0);
idToIdentityMap.put(assessedId, identity); idToIdentityMap.put(assessedId, identity);
continue; continue;
} }
......
...@@ -84,9 +84,25 @@ public abstract class UserManager extends BasicManager { ...@@ -84,9 +84,25 @@ public abstract class UserManager extends BasicManager {
*/ */
public abstract User createUser(String firstName, String lastName, String eMail); 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 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 * Find the identity (and the user) that match the given email address. The
......
...@@ -159,7 +159,7 @@ public class UserManagerImpl extends UserManager { ...@@ -159,7 +159,7 @@ public class UserManagerImpl extends UserManager {
} }
@Override @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 ") StringBuilder sb = new StringBuilder("select identity from ").append(IdentityImpl.class.getName()).append(" identity ")
.append(" inner join fetch identity.user user ") .append(" inner join fetch identity.user user ")
.append(" where user.").append(propName).append("=:propValue"); .append(" where user.").append(propName).append("=:propValue");
...@@ -170,7 +170,7 @@ public class UserManagerImpl extends UserManager { ...@@ -170,7 +170,7 @@ public class UserManagerImpl extends UserManager {
if(userKeys.isEmpty()) { if(userKeys.isEmpty()) {
return null; return null;
} }
return userKeys.get(0); return userKeys;
} }
/** /**
......
...@@ -47,10 +47,15 @@ public class GenericUnique127CharTextPropertyHandler extends Generic127CharTextP ...@@ -47,10 +47,15 @@ public class GenericUnique127CharTextPropertyHandler extends Generic127CharTextP
if(formItem instanceof TextElement) { if(formItem instanceof TextElement) {
String value = ((TextElement)formItem).getValue(); String value = ((TextElement)formItem).getValue();
if(!isUnique(user, value)) { if(!isUnique(user, value)) {
Identity propId = UserManager.getInstance().findIdentityKeyWithProperty(getName(), value); List<Identity> found = UserManager.getInstance().findIdentitiesWithProperty(getName(), value);
String email = propId.getUser().getProperty(UserConstants.EMAIL, null); Identity propId = null;
formItem.setErrorKey("general.error.unique", new String[]{ email }); if(found.size() > 0) {
allOk &= false; // 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 ...@@ -62,11 +67,16 @@ public class GenericUnique127CharTextPropertyHandler extends Generic127CharTextP
boolean allOk = super.isValidValue(user, value, validationError, locale); boolean allOk = super.isValidValue(user, value, validationError, locale);
if(!isUnique(user, value)) { if(!isUnique(user, value)) {
Identity propId = UserManager.getInstance().findIdentityKeyWithProperty(getName(), value); List<Identity> found = UserManager.getInstance().findIdentitiesWithProperty(getName(), value);
String email = propId.getUser().getProperty(UserConstants.EMAIL, null); Identity propId = null;
validationError.setErrorKey("general.error.unique"); if(found.size() > 0) {
validationError.setArgs(new String[]{ email }); // only display first one
allOk &= false; 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; return allOk;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment