1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.web.form;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.codehaus.jackson.map.ObjectMapper;
20 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
21 import org.kuali.rice.krad.uif.UifConstants;
22 import org.kuali.rice.krad.uif.UifParameters;
23 import org.kuali.rice.krad.uif.view.History;
24 import org.kuali.rice.krad.uif.view.View;
25 import org.kuali.rice.krad.uif.service.ViewService;
26 import org.kuali.rice.krad.uif.view.ViewModel;
27 import org.kuali.rice.krad.util.KRADUtils;
28 import org.springframework.web.multipart.MultipartFile;
29 import org.kuali.rice.krad.uif.UifConstants.ViewType;
30
31 import javax.servlet.http.HttpServletRequest;
32 import java.io.IOException;
33 import java.util.ArrayList;
34 import java.util.HashMap;
35 import java.util.List;
36 import java.util.Map;
37 import java.util.Properties;
38 import java.util.Set;
39 import java.util.UUID;
40
41
42
43
44
45
46
47
48
49
50
51 public class UifFormBase implements ViewModel {
52 private static final long serialVersionUID = 8432543267099454434L;
53
54
55 protected String viewId;
56 protected String viewName;
57 protected ViewType viewTypeName;
58 protected String pageId;
59 protected String methodToCall;
60 protected String formKey;
61 protected String jumpToId;
62 protected String jumpToName;
63 protected String focusId;
64 protected String formPostUrl;
65
66 protected boolean defaultsApplied;
67
68 protected View view;
69 protected View previousView;
70
71 protected Map<String, String> viewRequestParameters;
72 protected List<String> readOnlyFieldsList;
73
74 protected Map<String, Object> newCollectionLines;
75 protected Map<String, String> actionParameters;
76 protected Map<String, Object> clientStateForSyncing;
77 protected Map<String, Set<String>> selectedCollectionLines;
78
79 protected MultipartFile attachmentFile;
80
81
82 protected String returnLocation;
83 protected String returnFormKey;
84
85 protected History formHistory;
86
87 protected boolean renderFullView;
88 protected boolean validateDirty;
89
90 public UifFormBase() {
91 formKey = generateFormKey();
92 renderFullView = true;
93 defaultsApplied = false;
94
95 readOnlyFieldsList = new ArrayList<String>();
96 viewRequestParameters = new HashMap<String, String>();
97 newCollectionLines = new HashMap<String, Object>();
98 actionParameters = new HashMap<String, String>();
99 clientStateForSyncing = new HashMap<String, Object>();
100 selectedCollectionLines = new HashMap<String, Set<String>>();
101 }
102
103
104
105
106
107
108
109 protected String generateFormKey() {
110 return UUID.randomUUID().toString();
111 }
112
113
114
115
116
117
118
119 public void postBind(HttpServletRequest request) {
120
121 formPostUrl = request.getRequestURL().toString();
122
123
124 if (request.getParameterMap().containsKey(UifParameters.CLIENT_VIEW_STATE)) {
125 String clientStateJSON = request.getParameter(UifParameters.CLIENT_VIEW_STATE);
126 if (StringUtils.isNotBlank(clientStateJSON)) {
127
128 clientStateJSON = StringUtils.replace(clientStateJSON, "'", "\"");
129
130 ObjectMapper mapper = new ObjectMapper();
131 try {
132 clientStateForSyncing = mapper.readValue(clientStateJSON, Map.class);
133 } catch (IOException e) {
134 throw new RuntimeException("Unable to decode client side state JSON", e);
135 }
136 }
137 }
138
139
140 if (request.getParameter(UifParameters.READ_ONLY_FIELDS) != null) {
141 String readOnlyFields = request.getParameter(UifParameters.READ_ONLY_FIELDS);
142 setReadOnlyFieldsList(KRADUtils.convertStringParameterToList(readOnlyFields));
143 }
144 }
145
146
147
148
149 public String getViewId() {
150 return this.viewId;
151 }
152
153
154
155
156 public void setViewId(String viewId) {
157 this.viewId = viewId;
158 }
159
160
161
162
163 public String getViewName() {
164 return this.viewName;
165 }
166
167
168
169
170 public void setViewName(String viewName) {
171 this.viewName = viewName;
172 }
173
174
175
176
177 public ViewType getViewTypeName() {
178 return this.viewTypeName;
179 }
180
181
182
183
184 public void setViewTypeName(ViewType viewTypeName) {
185 this.viewTypeName = viewTypeName;
186 }
187
188
189
190
191 public String getPageId() {
192 return this.pageId;
193 }
194
195
196
197
198 public void setPageId(String pageId) {
199 this.pageId = pageId;
200 }
201
202
203
204
205 public String getFormPostUrl() {
206 return this.formPostUrl;
207 }
208
209
210
211
212 public void setFormPostUrl(String formPostUrl) {
213 this.formPostUrl = formPostUrl;
214 }
215
216 public String getReturnLocation() {
217 return this.returnLocation;
218 }
219
220 public void setReturnLocation(String returnLocation) {
221 this.returnLocation = returnLocation;
222 }
223
224 public String getReturnFormKey() {
225 return this.returnFormKey;
226 }
227
228 public void setReturnFormKey(String returnFormKey) {
229 this.returnFormKey = returnFormKey;
230 }
231
232
233
234
235
236
237
238
239 public String getMethodToCall() {
240 return this.methodToCall;
241 }
242
243
244
245
246
247
248 public void setMethodToCall(String methodToCall) {
249 this.methodToCall = methodToCall;
250 }
251
252
253
254
255 public Map<String, String> getViewRequestParameters() {
256 return this.viewRequestParameters;
257 }
258
259
260
261
262 public void setViewRequestParameters(Map<String, String> viewRequestParameters) {
263 this.viewRequestParameters = viewRequestParameters;
264 }
265
266
267
268
269 public List<String> getReadOnlyFieldsList() {
270 return readOnlyFieldsList;
271 }
272
273
274
275
276 public void setReadOnlyFieldsList(List<String> readOnlyFieldsList) {
277 this.readOnlyFieldsList = readOnlyFieldsList;
278 }
279
280
281
282
283 public Map<String, Object> getNewCollectionLines() {
284 return this.newCollectionLines;
285 }
286
287
288
289
290 public void setNewCollectionLines(Map<String, Object> newCollectionLines) {
291 this.newCollectionLines = newCollectionLines;
292 }
293
294
295
296
297 public Map<String, String> getActionParameters() {
298 return this.actionParameters;
299 }
300
301
302
303
304
305
306 public Properties getActionParametersAsProperties() {
307 Properties actionProperties = new Properties();
308
309 if (actionParameters != null) {
310 for (Map.Entry<String, String> actionParameter : actionParameters.entrySet()) {
311 actionProperties.put(actionParameter.getKey(), actionParameter.getValue());
312 }
313 }
314
315 return actionProperties;
316 }
317
318
319
320
321 public void setActionParameters(Map<String, String> actionParameters) {
322 this.actionParameters = actionParameters;
323 }
324
325
326
327
328
329
330
331
332 public String getActionParamaterValue(String actionParameterName) {
333 if ((actionParameters != null) && actionParameters.containsKey(actionParameterName)) {
334 return actionParameters.get(actionParameterName);
335 }
336
337 return "";
338 }
339
340
341
342
343
344
345
346
347
348
349
350
351
352 public String getActionEvent() {
353 if ((actionParameters != null) && actionParameters.containsKey(UifConstants.UrlParams.ACTION_EVENT)) {
354 return actionParameters.get(UifConstants.UrlParams.ACTION_EVENT);
355 }
356
357 return "";
358 }
359
360
361
362
363 public Map<String, Object> getClientStateForSyncing() {
364 return clientStateForSyncing;
365 }
366
367
368
369
370 public Map<String, Set<String>> getSelectedCollectionLines() {
371 return selectedCollectionLines;
372 }
373
374
375
376
377 public void setSelectedCollectionLines(Map<String, Set<String>> selectedCollectionLines) {
378 this.selectedCollectionLines = selectedCollectionLines;
379 }
380
381
382
383
384
385
386
387
388
389
390
391
392 public String getFormKey() {
393 return this.formKey;
394 }
395
396
397
398
399
400
401 public void setFormKey(String formKey) {
402 this.formKey = formKey;
403 }
404
405
406
407
408 public boolean isDefaultsApplied() {
409 return this.defaultsApplied;
410 }
411
412
413
414
415 public void setDefaultsApplied(boolean defaultsApplied) {
416 this.defaultsApplied = defaultsApplied;
417 }
418
419
420
421
422
423
424 public MultipartFile getAttachmentFile() {
425 return this.attachmentFile;
426 }
427
428
429
430
431
432
433 public void setAttachmentFile(MultipartFile attachmentFile) {
434 this.attachmentFile = attachmentFile;
435 }
436
437
438
439
440 public boolean isRenderFullView() {
441 return this.renderFullView;
442 }
443
444
445
446
447 public void setRenderFullView(boolean renderFullView) {
448 this.renderFullView = renderFullView;
449 }
450
451
452
453
454
455
456 public View getView() {
457 return this.view;
458 }
459
460
461
462
463
464
465 public void setView(View view) {
466 this.view = view;
467 }
468
469
470
471
472
473
474
475
476
477
478 public View getPreviousView() {
479 return this.previousView;
480 }
481
482
483
484
485
486
487 public void setPreviousView(View previousView) {
488 this.previousView = previousView;
489 }
490
491
492
493
494
495
496
497 protected ViewService getViewService() {
498 return KRADServiceLocatorWeb.getViewService();
499 }
500
501
502
503
504
505
506
507
508
509 public String getJumpToId() {
510 return this.jumpToId;
511 }
512
513
514
515
516 public void setJumpToId(String jumpToId) {
517 this.jumpToId = jumpToId;
518 }
519
520
521
522
523
524
525
526
527 public String getJumpToName() {
528 return this.jumpToName;
529 }
530
531
532
533
534 public void setJumpToName(String jumpToName) {
535 this.jumpToName = jumpToName;
536 }
537
538
539
540
541
542
543
544 public String getFocusId() {
545 return this.focusId;
546 }
547
548
549
550
551 public void setFocusId(String focusId) {
552 this.focusId = focusId;
553 }
554
555
556
557
558
559
560
561
562
563
564
565
566 public History getFormHistory() {
567 return formHistory;
568 }
569
570
571
572
573
574
575 public void setFormHistory(History history) {
576 this.formHistory = history;
577 }
578
579
580
581
582
583
584
585
586
587
588
589
590
591 public boolean isValidateDirty() {
592 return this.validateDirty;
593 }
594
595
596
597
598
599
600 public void setValidateDirty(boolean validateDirty) {
601 this.validateDirty = validateDirty;
602 }
603
604 }