public String createUser(){
return displayAddUser();
}
public String saveUser() {
User user = null;
String id = getRequest().getParameter(ServletConstants.EE.ADD_USER.ID);
String login = getRequest().getParameter(ServletConstants.EE.ADD_USER.LOGIN);
String password = getRequest().getParameter(ServletConstants.EE.ADD_USER.PASSWORD);
String email = getRequest().getParameter(ServletConstants.EE.ADD_USER.EMAIL);
user = new User();
user.setLogin(login);
user.setPassword(ChecksumUtil.encodeAsString(ChecksumUtil.SHA_1, password));
user.setEmail(email);
long idLong = StringUtils.isEmpty(id)?0:Long.valueOf(id).longValue();
user.setId(idLong);
if(StringUtils.isEmpty(login) || StringUtils.isEmpty(email)) {
addWarning("adduser.warning.fillallfield"); //$NON-NLS-1$
} else {
try {
if(idLong != 0) {
// It is an update
if (StringUtils.isEmpty(password)) {
User userStored = WOJServer.getInstance().getUserManagementService().getUser(login);
user.setPassword(userStored.getPassword());
}
WOJServer.getInstance().getUserManagementService().updateUser(new User[]{user});
} else {
// It is a creation
if(StringUtils.isEmpty(password)) {
addWarning("adduser.warning.fillallfield"); //$NON-NLS-1$
} else {
WOJServer.getInstance().getUserManagementService().addUser(new User[]{user});
//insert ok create new user for form
user = new User();
}
}
return display();
} catch (IllegalArgumentException e) {
addError("adduser.error.unabletoadduser", new Object[]{"User with same login or email already exist"}); //$NON-NLS-1$ //$NON-NLS-2$