1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
@Secured(roles={Role.ADMIN})
public class AdminUpdateUserSupport extends PersoSupport {
private static final long serialVersionUID = 1L;
@Autowired
private UserDao userDao;
@Autowired
private CivilityDao civilityDao;
@Autowired
private EncryptionService encryptionService;
private Long userId;
private User user;
private String password;
private String roleCode;
public String execute() throws Exception {
if(user.getId() == null) {
addActionMessage(getText("user.created",new String[]{user.getDisplayName()}));
} else {
addActionMessage(getText("user.updated",new String[]{user.getDisplayName()}));
}
user.setPassword(encryptionService.encrypt(password));
user.setRole(User.Role.valueOf(roleCode));
userDao.saveOrUpdate(user);
userId = user.getId();
return SUCCESS;
}
public String input() throws Exception {
if(userId == null) {
this.user = new User();
this.roleCode = User.Role.values()[0].toString();
} else {
this.user = userDao.get(userId);
this.roleCode = this.user.getRole().toString();
}
return SUCCESS;
}
/** fields **/
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getRoleCode() {
return roleCode;
}
public void setRoleCode(String roleCode) {
this.roleCode = roleCode;
}
/** end fields **/
/** lists **/
public List<Civility> getAllCivilities() {
return civilityDao.findAll();
}
public Map<String,String> getAllUserRoles() {
Map<String,String> roles = new TreeMap<String,String>();
for(Role r:User.Role.values()) {
roles.put(r.toString(),getText("usertype."+r.toString().toLowerCase()));
}
return roles;
}
/** end lists **/
} |