1 package org.itracker.web.forms;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import javax.servlet.http.HttpServletRequest;
7
8 import org.apache.struts.action.ActionErrors;
9 import org.apache.struts.action.ActionMapping;
10 import org.apache.struts.action.ActionMessage;
11 import org.apache.struts.action.ActionMessages;
12 import org.apache.struts.validator.ValidatorForm;
13
14 public class UserForm extends ValidatorForm {
15
16 private static final long serialVersionUID = 1L;
17
18 private String action = null;
19 private Integer id = -1;
20 private String login = null;
21 private String currPassword = null;
22 private String password = null;
23 private String confPassword = null;
24 private String firstName = null;
25 private String lastName = null;
26 private String email = null;
27
28 private boolean superUser = false;
29
30 private Map<String, String> permissions = new HashMap<String, String>();
31
32 private String userLocale = null;
33 private String saveLogin = null;
34 private String numItemsOnIndex = null;
35 private String numItemsOnIssueList = null;
36 private String showClosedOnIssueList = null;
37 private String sortColumnOnIssueList = null;
38 private Integer[] hiddenIndexSections = null;
39 private String rememberLastSearch = null;
40 private String useTextActions = null;
41
42 public String getAction() {
43 return action;
44 }
45
46 public void setAction(String value) {
47 action = value;
48 }
49
50 public Integer getId() {
51 return id;
52 }
53
54 public void setId(Integer value) {
55 id = value;
56 }
57
58 public String getLogin() {
59 return login;
60 }
61
62 public void setLogin(String value) {
63 login = value;
64 }
65
66 public String getCurrPassword() {
67 return currPassword;
68 }
69
70 public void setCurrPassword(String value) {
71 currPassword = value;
72 }
73
74 public String getPassword() {
75 return password;
76 }
77
78 public void setPassword(String value) {
79 password = value;
80 }
81
82 public String getConfPassword() {
83 return confPassword;
84 }
85
86 public void setConfPassword(String value) {
87 confPassword = value;
88 }
89
90 public String getFirstName() {
91 return firstName;
92 }
93
94 public void setFirstName(String value) {
95 firstName = value;
96 }
97
98 public String getLastName() {
99 return lastName;
100 }
101
102 public void setLastName(String value) {
103 lastName = value;
104 }
105
106 public String getEmail() {
107 return email;
108 }
109
110 public void setEmail(String value) {
111 email = value;
112 }
113
114 public boolean isSuperUser() {
115 return superUser;
116 }
117
118 public void setSuperUser(boolean value) {
119 superUser = value;
120 }
121
122 public Map<String, String> getPermissions() {
123 return permissions;
124 }
125
126 public void setPermissions(Map<String, String> value) {
127 permissions = value;
128 }
129
130 public String getUserLocale() {
131 return userLocale;
132 }
133
134 public void setUserLocale(String value) {
135 userLocale = value;
136 }
137
138 public String getSaveLogin() {
139 return saveLogin;
140 }
141
142 public void setSaveLogin(String value) {
143 saveLogin = value;
144 }
145
146 public String getNumItemsOnIndex() {
147 return numItemsOnIndex;
148 }
149
150 public void setNumItemsOnIndex(String value) {
151 numItemsOnIndex = value;
152 }
153
154 public String getNumItemsOnIssueList() {
155 return numItemsOnIssueList;
156 }
157
158 public void setNumItemsOnIssueList(String value) {
159 numItemsOnIssueList = value;
160 }
161
162 public String getShowClosedOnIssueList() {
163 return showClosedOnIssueList;
164 }
165
166 public void setShowClosedOnIssueList(String value) {
167 showClosedOnIssueList = value;
168 }
169
170 public String getSortColumnOnIssueList() {
171 return sortColumnOnIssueList;
172 }
173
174 public void setSortColumnOnIssueList(String value) {
175 sortColumnOnIssueList = value;
176 }
177
178 public Integer[] getHiddenIndexSections() {
179 if (null == hiddenIndexSections)
180 return null;
181 return hiddenIndexSections.clone();
182 }
183
184 public void setHiddenIndexSections(Integer[] value) {
185 if (null == value)
186 this.hiddenIndexSections = null;
187 else
188 hiddenIndexSections = value.clone();
189 }
190
191 public String getRememberLastSearch() {
192 return rememberLastSearch;
193 }
194
195 public void setRememberLastSearch(String value) {
196 rememberLastSearch = value;
197 }
198
199 public String getUseTextActions() {
200 return useTextActions;
201 }
202
203 public void setUseTextActions(String value) {
204 useTextActions = value;
205 }
206
207 public void reset(ActionMapping mapping, HttpServletRequest request) {
208 action = null;
209 id = -1;
210 login = null;
211 currPassword = null;
212 password = null;
213 confPassword = null;
214 firstName = null;
215 lastName = null;
216 email = null;
217 superUser = false;
218
219 permissions = new HashMap<String, String>();
220
221 userLocale = null;
222 saveLogin = null;
223 numItemsOnIndex = null;
224 numItemsOnIssueList = null;
225 showClosedOnIssueList = null;
226 sortColumnOnIssueList = null;
227 hiddenIndexSections = null;
228 rememberLastSearch = null;
229 useTextActions = null;
230 }
231
232 public ActionErrors validate(ActionMapping mapping,
233 HttpServletRequest request) {
234
235 ActionErrors errors = super.validate(mapping, request);
236
237 if (password == null || password.trim().equals("")) {
238 return errors;
239 }
240
241 if (!( "register".equalsIgnoreCase(action)
242 || "create".equalsIgnoreCase(action)
243 || "update".equalsIgnoreCase(action)
244 || "preferences".equalsIgnoreCase(action)
245 ) && (currPassword == null || "".equals(currPassword))) {
246
247 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
248 "itracker.web.error.missingpassword"));
249
250 } else if (!password.equals(confPassword)) {
251 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
252 "itracker.web.error.matchingpass"));
253 }
254
255
256 request.setAttribute("warnings", errors);
257 request.setAttribute("isUpdate", true);
258 request.setAttribute("allowProfileUpdate", true);
259 request.setAttribute("allowPasswordUpdate", true);
260
261 return errors;
262 }
263
264 }