Skip to content

Instantly share code, notes, and snippets.

@novoj
Created October 2, 2013 11:10
Show Gist options
  • Save novoj/6792151 to your computer and use it in GitHub Desktop.
Save novoj/6792151 to your computer and use it in GitHub Desktop.
Validator
package com.fg.doxx.gastro.web.user.validator;
import com.fg.doxx.gastro.business.GastroUserManager;
import com.fg.doxx.gastro.model.user.GastroUser;
import com.fg.form.core.context.RequestContext;
import com.fg.form.core.data.state.State;
import com.fg.form.core.lifecycle.validate.impl.AbstractSingleValueWidgetValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
/**
* Validates uniqueness of the organization email. Cam be used used only for non existing organization.
*
* @author Jakub Příkazský (prikazsky@fg.cz), FG Forrest a.s. (c) 2012
* @version $Id$
*/
public class UniqueUserEmail extends AbstractSingleValueWidgetValidator {
@Autowired
private GastroUserManager userManager;
@Override
protected boolean internalValidate(RequestContext context, Object value, State widgetState) {
if (value != null) {
String email = (String) value;
if (!StringUtils.hasText(email)) {
return false;
}
GastroUser found = userManager.getUserByEmailIgnoringDeletedState(email);
return found == null;
} else {
return false;
}
}
public GastroUserManager getUserManager() {
return userManager;
}
public void setUserManager(GastroUserManager userManager) {
this.userManager = userManager;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment