1 package org.sourceforge.vlibrary.user.forms;
2
3 import javax.servlet.http.HttpServletRequest;
4 import org.apache.struts.action.ActionMessage;
5 import org.apache.struts.action.ActionMessages;
6 import org.apache.struts.action.ActionErrors;
7 import org.apache.struts.action.ActionMapping;
8 import org.apache.struts.util.MessageResources;
9 import org.apache.log4j.Logger;
10
11 import org.sourceforge.vlibrary.exceptions.LibraryException;
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 public final class ReaderForm extends LibraryForm {
36 private static final long serialVersionUID = 0;
37
38
39 private static Logger logger =
40 Logger.getLogger(ReaderForm.class.getName());
41
42
43 private static MessageResources messages =
44 MessageResources.getMessageResources("ApplicationResources");
45
46
47
48
49
50 private String action = "Create";
51 private long id = 0;
52 private String lastName = null;
53 private String firstName = null;
54 private String email=null;
55 private String deskPhone=null;
56 private String mobilePhone=null;
57 private String pager=null;
58 private String screenName=null;
59 private String imService=null;
60 private String uid=null;
61 private String pwd=null;
62 private String confirmPwd=null;
63 private boolean administrator=false;
64
65 public String getClassName() {
66 return ReaderForm.class.getName();
67 }
68
69 public String getAction() {
70 return action;
71 }
72
73 public void setAction(String action) {
74 this.action = action;
75 }
76
77 public String getDeskPhone() {
78 return deskPhone;
79 }
80
81 public void setDeskPhone(String deskPhone) {
82 this.deskPhone = deskPhone;
83 }
84
85 public String getEmail() {
86 return email;
87 }
88
89 public void setEmail(String email) {
90 this.email = email;
91 }
92
93 public String getFirstName() {
94 return firstName;
95 }
96
97 public void setFirstName(String firstName) {
98 this.firstName = firstName;
99 }
100
101 public long getId() {
102 return id;
103 }
104
105 public void setId(long id) {
106 this.id = id;
107 }
108
109 public String getImService() {
110 return imService;
111 }
112
113 public void setImService(String imService) {
114 this.imService = imService;
115 }
116
117 public String getLastName() {
118 return lastName;
119 }
120
121 public void setLastName(String lastName) {
122 this.lastName = lastName;
123 }
124
125 public String getMobilePhone() {
126 return mobilePhone;
127 }
128
129 public void setMobilePhone(String mobilePhone) {
130 this.mobilePhone = mobilePhone;
131 }
132
133 public String getPager() {
134 return pager;
135 }
136
137 public void setPager(String pager) {
138 this.pager = pager;
139 }
140
141 public String getPwd() {
142 return pwd;
143 }
144
145 public void setPwd(String pwd) {
146 this.pwd = pwd;
147 }
148
149 public String getScreenName() {
150 return screenName;
151 }
152
153 public void setScreenName(String screenName) {
154 this.screenName = screenName;
155 }
156
157 public String getUid() {
158 return uid;
159 }
160
161 public void setUid(String uid) {
162 this.uid = uid;
163 }
164
165
166
167
168
169
170
171 public void reset(ActionMapping mapping, HttpServletRequest request) {
172 this.action = "Create";
173 this.email = null;
174 this.lastName = null;
175 this.firstName = null;
176 this.imService = null;
177 this.screenName = null;
178 this.pager = null;
179 this.deskPhone = null;
180 this.mobilePhone = null;
181 this.uid = null;
182 this.pwd = null;
183 this.id=0;
184
185 }
186
187
188
189
190
191
192
193
194
195
196
197 public ActionErrors validate(ActionMapping mapping,
198 HttpServletRequest request) {
199
200 if (logger.isDebugEnabled()) {
201 logger.debug(messages.getMessage("entering.validate"));
202 }
203
204 ActionErrors errors = new ActionErrors();
205
206 if ((email == null) || (email.length() < 1)) {
207 errors.add("email",
208 new ActionMessage("error.reader.email.required"));
209 }
210
211 if ((firstName == null) || (firstName.length() < 1)) {
212 errors.add("firstName",
213 new ActionMessage("error.reader.firstName.required"));
214 }
215
216 if ((lastName == null) || (lastName.length() < 1)) {
217 errors.add("lastName",
218 new ActionMessage("error.reader.lastName.required"));
219 }
220
221 if ((uid == null) || (uid.length() < 1)) {
222 errors.add("uid",
223 new ActionMessage("error.reader.uid.required"));
224 }
225
226 if (action.equals("Create")) {
227 if ((pwd == null) || (pwd.length() < 1)) {
228 errors.add("pwd",
229 new ActionMessage("error.reader.password.required"));
230 }
231
232 if ((confirmPwd == null) || (confirmPwd.length() < 1)) {
233 errors.add("confirmPwd",
234 new ActionMessage("error.reader.password.confirmation.required"));
235 }
236
237
238 if (!(pwd.equals(confirmPwd))) {
239 errors.add("password",
240 new ActionMessage("error.reader.confirmPwdFailed"));
241 }
242
243
244 try {
245 if (libraryManager.isUserIDValid(uid)) {
246 errors.add("uid",
247 new ActionMessage("error.reader.idTaken"));
248 }
249 } catch (LibraryException le) {
250 logger.error(le);
251 errors.add(ActionMessages.GLOBAL_MESSAGE,
252 new ActionMessage("error.reader.update"));
253 }
254
255
256 try {
257 if (libraryManager.readerExists(firstName,lastName)) {
258 errors.add(ActionMessages.GLOBAL_MESSAGE,
259 new ActionMessage("error.reader.already.registered"));
260 }
261 } catch (LibraryException le) {
262 logger.error(le);
263
264 errors.add(ActionMessages.GLOBAL_MESSAGE,
265 new ActionMessage("error.reader.update"));
266 }
267
268 }
269
270 if (logger.isDebugEnabled() && errors.isEmpty()) {
271 logger.debug(messages.getMessage("validate.successful"));
272 }
273
274 return errors;
275 }
276
277 public String getConfirmPwd() {
278 return confirmPwd;
279 }
280
281 public void setConfirmPwd(String confirmPwd) {
282 this.confirmPwd = confirmPwd;
283 }
284
285 public boolean isAdministrator() {
286 return administrator;
287 }
288
289 public void setAdministrator(boolean administrator) {
290 this.administrator = administrator;
291 }
292 }