ZeroView view = new ZeroView(getMessages(), request.getLocale());
if (user.checkAuthorisation(UserModule.AUTH_USER_EDIT)) {
ZeroUser selectedUser = (ZeroUser) session.getAttribute(SESSION_USER_SELECTEDUSER);
if (validate(new UserSettingsValidator(userDao, selectedUser.getId()), userForm, result, view)) {
String missingPermission = checkRoles(selectedUser);
if (missingPermission != null && ignoreWarning == null) {
String[] param = new String[1];
param[0] = missingPermission;
view.getJson().element("warning", getMessages().getMessage("base.user.settings.permission_missing", param, getLocale(request)));
view.addWidget(new PopupWidget("user_warning", "base.user.warning", PopupWidget.TYPE_OVERLAY));
return new ModelAndView(view);
}
ZeroUser selectedUser2 = null;
if (selectedUser.getId().equals("")) {
selectedUser2 = new ZeroUser(selectedUser.getUsername(), selectedUser.getPassword());
selectedUser2.setCreatedBy((ZeroUser) getUser());
} else {
selectedUser2 = userDao.findById(selectedUser.getId());
}
selectedUser2.setUsername(userForm.getUsername());
log.debug(userForm.getFirstname() + ", " + userForm.getLastname() + ", " + userForm.getEmail() + ", " + userForm.getPhone());
// if usergroup is set to space - remove group from user
if (userForm.getUserGroup().equals("")) {
selectedUser2.setUserGroup(null);
} else {
// if user group changed, update group
if (selectedUser.getUserGroup() == null
|| !userForm.getUserGroup().equals(selectedUser.getUserGroup().getGroupKey())) {
log.debug("set user group: " + userForm.getUserGroup());
UserGroup userGroup = userGroupDao.getUserGroup(userForm.getUserGroup());
log.debug(userGroup.getGroupKey());
selectedUser2.setUserGroup(userGroup);
}
}
selectedUser2.getPerson().setEmail(userForm.getEmail());
selectedUser2.getPerson().setFirstname(userForm.getFirstname());
selectedUser2.getPerson().setLastname(userForm.getLastname());
selectedUser2.getPerson().setPhone(userForm.getPhone());
//selectedUser.setLanguage(userForm.getLanguage());
selectedUser2.setRoles(selectedUser.getRoles());
for (UserParameter up : selectedUser.getParameters().values()) {
log.debug("1: " + up.getKey());
if (selectedUser2.getParameter(up.getKey()) != null
&& !(selectedUser2.getParameter(up.getKey()) instanceof EmptyUserParameter)) {
log.debug("1: setValue");
selectedUser2.getParameter(up.getKey()).setValue(up.getValue());
} else {
log.debug("1: put");
selectedUser2.getParameters().put(up.getKey(), up);
}
}
for (UserParameter up : selectedUser2.getParameters().values()) {
log.debug("1b: " + up.getKey() + " " + up.getValue());
}
if (!userForm.getPassword().equals("")) {
selectedUser2.setPassword(userForm.getPassword());
}
boolean error = false;
for (String key : userForm.getValues().keySet()) {
log.debug("2 - form: " + key);
UserParameter parameter = selectedUser2.getParameters().get(key);
if (parameter != null) {
log.debug("3 - found");
/*PermissionTemplate permissionTemplate = getModuleController().getPermissionTemplate(permissionKey);
if (permissionTemplate != null) {
String value = roleForm.getValues().get(permissionKey);
if (permissionTemplate.checkValue(value)) {
permission.setValue(value);
} else {
if (permissionTemplate.getValueRangeMessage() != null) {
view.setMessage(permissionTemplate.getValueRangeMessage());
error = true;
}
}
}*/
parameter.setValue(userForm.getValues().get(key));
}
}
log.debug(selectedUser2.getUserGroup().getId() + " " + selectedUser2.getUserGroup().getGroupKey());
try {
UserTransaction transaction = (UserTransaction) session.getAttribute(SESSION_USER_TRANSACTION);
UserTransactionEvent event = new UserTransactionEvent();
event.setUser(selectedUser2);
event.setRequest(request);
for (String roleKey : selectedUser2.getParameters().keySet()) {
log.debug(roleKey);
}
for (UserParameter up : selectedUser2.getParameters().values()) {
log.debug(up.getKey() + " " + up.getValue());
}
for (UserTransactionListener listener : transaction.getListeners()) {
listener.userUpdated(event);
}
for (UserParameter up : selectedUser2.getParameters().values()) {
log.debug(up.getKey() + " " + up.getValue());
}
selectedUser2.setModificationDate(new Date());
selectedUser2.setLastModifiedBy((ZeroUser) getUser());
userDao.makePersistent(selectedUser2);
} catch (org.hibernate.NonUniqueObjectException e) {
log.warn("save user: ", e);