UpdateUserBean.java
8.49 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
package org.legrog.web.user;
import org.legrog.web.xyz.SharedService;
import org.legrog.entities.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Named
@SessionScoped
public class UpdateUserBean {
Logger logger = LoggerFactory.getLogger(getClass());
private UserService userService;
private SharedService sharedService;
private List<DisplayNameMask> allDisplayNameMasks;
private List<AccountRole> availableAccountRoles;
private List<AccountProperty> availableUserProperties;
@ManagedProperty("#{param.userId}")
private int userId;
private String username;
private String firstName;
private String lastName;
private String nickName;
private DisplayNameMask displayNameMask;
private String email;
private boolean anonymous;
private String password;
private List<AccountRole> roles;
private String presentation;
private List<AccountAttribute> accountAttributes;
private boolean criticProvider;
private boolean visible;
private boolean activated;
@Inject
public UpdateUserBean(UserService userService, SharedService sharedService) {
this.userService = userService;
this.sharedService = sharedService;
}
//no args constructor to make it proxyable
UpdateUserBean() {
}
@PostConstruct
public void init() {
logger.info("init");
allDisplayNameMasks = sharedService.getAllDisplayNameMasks();
availableAccountRoles = sharedService.getAvailableUserRoles();
availableUserProperties = sharedService.getAvailableUserProperties();
}
public String add() {
Account account = new Account();
account.setActivated(activated);
account.setAnonymous(anonymous);
if (accountAttributes != null) {
account.setAttributes(accountAttributes);
}
account.setCriticProvider(criticProvider);
if (displayNameMask != null) {
account.setDisplayNameMask(displayNameMask);
} else {
account.setDisplayNameMask(DisplayNameMask.PRENOMNOM);
}
account.setEmail(email);
account.setFirstName(firstName);
account.setLastName(lastName);
if (nickName != null && !nickName.isEmpty()) {
account.setNickName(nickName);
}
account.setPassword(password);
if (presentation != null) {
account.setPresentation(presentation);
}
if (roles != null) {
account.setRoles(roles);
}
account.setUsername(username);
account.setVisible(visible);
account.setCreationDate(new Date());
userService.addUser(account);
return "success";
}
public String prepareUpdate(int userId) {
logger.info("prepareUpdate");
logger.info("userId =" + userId);
this.userId = userId;
if (userId != 0) {
Account account = userService.findUserById(userId);
if (account != null) {
activated = account.isActivated();
anonymous = account.isAnonymous();
accountAttributes = account.getAttributes();
criticProvider = account.isCriticProvider();
displayNameMask = account.getDisplayNameMask();
email = account.getEmail();
firstName = account.getFirstName();
lastName = account.getLastName();
nickName = account.getNickName();
password = account.getPassword();
presentation = account.getPresentation();
roles = account.getRoles();
if (roles == null) {
roles = new ArrayList<AccountRole>();
}
username = account.getUsername();
visible = account.isVisible();
return "updateUser.xhtml";
}
}
return "listUsers.xhtml";
}
public String update() {
logger.info("update");
logger.info("userId =" + userId);
Account account = userService.findUserById(userId);
account.setActivated(activated);
account.setAnonymous(anonymous);
account.setAttributes(accountAttributes);
account.setCriticProvider(criticProvider);
account.setDisplayNameMask(displayNameMask);
account.setEmail(email);
account.setFirstName(firstName);
account.setLastName(lastName);
account.setNickName(nickName);
account.setPassword(password);
account.setPresentation(presentation);
account.setRoles(roles);
account.setUsername(username);
account.setVisible(visible);
userService.updateUser(account);
return "success";
}
public List<AccountRole> getAvailableAccountRoles() {
return availableAccountRoles;
}
public void setAvailableAccountRoles(List<AccountRole> availableAccountRoles) {
this.availableAccountRoles = availableAccountRoles;
}
public String getPresentation() {
return presentation;
}
public void setPresentation(String presentation) {
this.presentation = presentation;
}
public List<AccountProperty> getAvailableUserProperties() {
return availableUserProperties;
}
public void setAvailableUserProperties(List<AccountProperty> availableUserProperties) {
this.availableUserProperties = availableUserProperties;
}
public List<AccountAttribute> getAccountAttributes() {
return accountAttributes;
}
public void setAccountAttributes(List<AccountAttribute> accountAttributes) {
this.accountAttributes = accountAttributes;
}
public boolean isCriticProvider() {
return criticProvider;
}
public void setCriticProvider(boolean criticProvider) {
this.criticProvider = criticProvider;
}
public boolean isVisible() {
return visible;
}
public void setVisible(boolean visible) {
this.visible = visible;
}
public boolean isActivated() {
return activated;
}
public void setActivated(boolean activated) {
this.activated = activated;
}
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
public SharedService getSharedService() {
return sharedService;
}
public void setSharedService(SharedService sharedService) {
this.sharedService = sharedService;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getNickName() {
return nickName;
}
public void setNickName(String nickName) {
this.nickName = nickName;
}
public DisplayNameMask getDisplayNameMask() {
return displayNameMask;
}
public void setDisplayNameMask(DisplayNameMask displayNameMask) {
this.displayNameMask = displayNameMask;
}
public List<DisplayNameMask> getAllDisplayNameMasks() {
return allDisplayNameMasks;
}
public void setAllDisplayNameMasks(List<DisplayNameMask> allDisplayNameMasks) {
this.allDisplayNameMasks = allDisplayNameMasks;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public boolean isAnonymous() {
return anonymous;
}
public void setAnonymous(boolean anonymous) {
this.anonymous = anonymous;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public List<AccountRole> getRoles() {
return roles;
}
public void setRoles(List<AccountRole> roles) {
this.roles = roles;
}
}