UpdateUserBean.java
8.35 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<UserRole> availableUserRoles;
private List<UserProperty> 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<UserRole> roles;
private String presentation;
private List<UserAttribute> userAttributes;
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();
availableUserRoles = sharedService.getAvailableUserRoles();
availableUserProperties = sharedService.getAvailableUserProperties();
}
public String add() {
Person person = new Person();
person.setActivated(activated);
person.setAnonymous(anonymous);
if (userAttributes != null) {
person.setAttributes(userAttributes);
}
person.setCriticProvider(criticProvider);
if (displayNameMask != null) {
person.setDisplayNameMask(displayNameMask);
} else {
person.setDisplayNameMask(DisplayNameMask.PRENOMNOM);
}
person.setEmail(email);
person.setFirstName(firstName);
person.setLastName(lastName);
if (nickName != null && !nickName.isEmpty()) {
person.setNickName(nickName);
}
person.setPassword(password);
if (presentation != null) {
person.setPresentation(presentation);
}
if (roles != null) {
person.setRoles(roles);
}
person.setUsername(username);
person.setVisible(visible);
person.setCreationDate(new Date());
userService.addUser(person);
return "success";
}
public String prepareUpdate(int userId) {
logger.info("prepareUpdate");
logger.info("userId =" + userId);
this.userId = userId;
if (userId != 0) {
Person person = userService.findUserById(userId);
if (person != null) {
activated = person.isActivated();
anonymous = person.isAnonymous();
userAttributes = person.getAttributes();
criticProvider = person.isCriticProvider();
displayNameMask = person.getDisplayNameMask();
email = person.getEmail();
firstName = person.getFirstName();
lastName = person.getLastName();
nickName = person.getNickName();
password = person.getPassword();
presentation = person.getPresentation();
roles = person.getRoles();
if (roles == null) {
roles = new ArrayList<UserRole>();
}
username = person.getUsername();
visible = person.isVisible();
return "updateUser.xhtml";
}
}
return "listUsers.xhtml";
}
public String update() {
logger.info("update");
logger.info("userId =" + userId);
Person person = userService.findUserById(userId);
person.setActivated(activated);
person.setAnonymous(anonymous);
person.setAttributes(userAttributes);
person.setCriticProvider(criticProvider);
person.setDisplayNameMask(displayNameMask);
person.setEmail(email);
person.setFirstName(firstName);
person.setLastName(lastName);
person.setNickName(nickName);
person.setPassword(password);
person.setPresentation(presentation);
person.setRoles(roles);
person.setUsername(username);
person.setVisible(visible);
userService.updateUser(person);
return "success";
}
public List<UserRole> getAvailableUserRoles() {
return availableUserRoles;
}
public void setAvailableUserRoles(List<UserRole> availableUserRoles) {
this.availableUserRoles = availableUserRoles;
}
public String getPresentation() {
return presentation;
}
public void setPresentation(String presentation) {
this.presentation = presentation;
}
public List<UserProperty> getAvailableUserProperties() {
return availableUserProperties;
}
public void setAvailableUserProperties(List<UserProperty> availableUserProperties) {
this.availableUserProperties = availableUserProperties;
}
public List<UserAttribute> getUserAttributes() {
return userAttributes;
}
public void setUserAttributes(List<UserAttribute> userAttributes) {
this.userAttributes = userAttributes;
}
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<UserRole> getRoles() {
return roles;
}
public void setRoles(List<UserRole> roles) {
this.roles = roles;
}
}