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.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.codehaus.jackson.map.ObjectMapper;
22 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
23 import org.kuali.rice.krad.uif.UifConstants;
24 import org.kuali.rice.krad.uif.UifConstants.ViewType;
25 import org.kuali.rice.krad.uif.UifParameters;
26 import org.kuali.rice.krad.uif.service.ViewService;
27 import org.kuali.rice.krad.uif.util.SessionTransient;
28 import org.kuali.rice.krad.uif.view.DialogManager;
29 import org.kuali.rice.krad.uif.view.History;
30 import org.kuali.rice.krad.uif.view.View;
31 import org.kuali.rice.krad.uif.view.ViewModel;
32 import org.kuali.rice.krad.util.KRADUtils;
33 import org.springframework.web.multipart.MultipartFile;
34
35 import javax.servlet.http.HttpServletRequest;
36 import java.io.IOException;
37 import java.util.ArrayList;
38 import java.util.HashMap;
39 import java.util.List;
40 import java.util.Map;
41 import java.util.Properties;
42 import java.util.Set;
43 import java.util.UUID;
44
45
46
47
48
49
50
51
52
53
54
55 public class UifFormBase implements ViewModel {
56 private static final long serialVersionUID = 8432543267099454434L;
57
58
59 private static final Log LOG = LogFactory.getLog(UifFormBase.class);
60
61
62 protected String viewId;
63 protected String viewName;
64 protected ViewType viewTypeName;
65 protected String pageId;
66 protected String methodToCall;
67 protected String formKey;
68
69 @SessionTransient
70 protected String jumpToId;
71 @SessionTransient
72 protected String jumpToName;
73 @SessionTransient
74 protected String focusId;
75
76 protected String formPostUrl;
77 protected String controllerMapping;
78
79 @SessionTransient
80 private Map<String, String> requestParameters;
81
82 protected String state;
83 protected boolean defaultsApplied;
84 protected boolean renderedInLightBox;
85
86 @SessionTransient
87 protected String growlScript;
88 @SessionTransient
89 protected String lightboxScript;
90
91 protected View view;
92 protected View postedView;
93
94 protected Map<String, String> viewRequestParameters;
95 protected List<String> readOnlyFieldsList;
96 protected Map<String, Object> newCollectionLines;
97
98 @SessionTransient
99 protected Map<String, String> actionParameters;
100 protected Map<String, Object> clientStateForSyncing;
101 @SessionTransient
102 protected Map<String, Set<String>> selectedCollectionLines;
103
104 protected List<Object> addedCollectionItems;
105
106 @SessionTransient
107 protected MultipartFile attachmentFile;
108
109
110 protected String returnLocation;
111 protected String returnFormKey;
112
113 @SessionTransient
114 protected boolean ajaxRequest;
115 @SessionTransient
116 protected String ajaxReturnType;
117
118 protected History formHistory;
119
120
121 @SessionTransient
122 protected String dialogExplanation;
123 @SessionTransient
124 protected String dialogResponse;
125 protected DialogManager dialogManager;
126
127 @SessionTransient
128 protected boolean requestRedirected;
129 @SessionTransient
130 protected String updateComponentId;
131
132 protected Map<String, Object> extensionData;
133
134 public UifFormBase() {
135 formKey = generateFormKey();
136 defaultsApplied = false;
137 renderedInLightBox = false;
138 requestRedirected = false;
139
140 readOnlyFieldsList = new ArrayList<String>();
141 viewRequestParameters = new HashMap<String, String>();
142 newCollectionLines = new HashMap<String, Object>();
143 actionParameters = new HashMap<String, String>();
144 clientStateForSyncing = new HashMap<String, Object>();
145 selectedCollectionLines = new HashMap<String, Set<String>>();
146 addedCollectionItems = new ArrayList();
147 dialogManager = new DialogManager();
148 extensionData = new HashMap<String, Object>();
149 }
150
151
152
153
154
155
156
157 protected String generateFormKey() {
158 return UUID.randomUUID().toString();
159 }
160
161
162
163
164 @Override
165 public void postBind(HttpServletRequest request) {
166
167 formPostUrl = request.getRequestURL().toString();
168
169
170 controllerMapping = request.getPathInfo();
171
172
173 if (request.getParameterMap().containsKey(UifParameters.CLIENT_VIEW_STATE)) {
174 String clientStateJSON = request.getParameter(UifParameters.CLIENT_VIEW_STATE);
175 if (StringUtils.isNotBlank(clientStateJSON)) {
176
177 clientStateJSON = StringUtils.replace(clientStateJSON, "'", "\"");
178
179 ObjectMapper mapper = new ObjectMapper();
180 try {
181 clientStateForSyncing = mapper.readValue(clientStateJSON, Map.class);
182 } catch (IOException e) {
183 throw new RuntimeException("Unable to decode client side state JSON", e);
184 }
185 }
186 }
187
188
189 if (request.getParameter(UifParameters.READ_ONLY_FIELDS) != null) {
190 String readOnlyFields = request.getParameter(UifParameters.READ_ONLY_FIELDS);
191 setReadOnlyFieldsList(KRADUtils.convertStringParameterToList(readOnlyFields));
192 }
193 }
194
195
196
197
198 @Override
199 public String getViewId() {
200 return this.viewId;
201 }
202
203
204
205
206 @Override
207 public void setViewId(String viewId) {
208 this.viewId = viewId;
209 }
210
211
212
213
214 @Override
215 public String getViewName() {
216 return this.viewName;
217 }
218
219
220
221
222 @Override
223 public void setViewName(String viewName) {
224 this.viewName = viewName;
225 }
226
227
228
229
230 @Override
231 public ViewType getViewTypeName() {
232 return this.viewTypeName;
233 }
234
235
236
237
238 @Override
239 public void setViewTypeName(ViewType viewTypeName) {
240 this.viewTypeName = viewTypeName;
241 }
242
243
244
245
246 @Override
247 public String getPageId() {
248 return this.pageId;
249 }
250
251
252
253
254 @Override
255 public void setPageId(String pageId) {
256 this.pageId = pageId;
257 }
258
259
260
261
262 @Override
263 public String getFormPostUrl() {
264 return this.formPostUrl;
265 }
266
267
268
269
270 @Override
271 public void setFormPostUrl(String formPostUrl) {
272 this.formPostUrl = formPostUrl;
273 }
274
275
276
277
278
279
280 public String getControllerMapping() {
281 return controllerMapping;
282 }
283
284
285
286
287
288
289
290 public Map<String, String> getRequestParameters() {
291 return requestParameters;
292 }
293
294
295
296
297
298
299 public void setRequestParameters(Map<String, String> requestParameters) {
300 this.requestParameters = requestParameters;
301 }
302
303 public String getReturnLocation() {
304 return this.returnLocation;
305 }
306
307 public void setReturnLocation(String returnLocation) {
308 this.returnLocation = returnLocation;
309 }
310
311 public String getReturnFormKey() {
312 return this.returnFormKey;
313 }
314
315 public void setReturnFormKey(String returnFormKey) {
316 this.returnFormKey = returnFormKey;
317 }
318
319
320
321
322
323
324
325
326 public String getMethodToCall() {
327 return this.methodToCall;
328 }
329
330
331
332
333
334
335 public void setMethodToCall(String methodToCall) {
336 this.methodToCall = methodToCall;
337 }
338
339
340
341
342 @Override
343 public Map<String, String> getViewRequestParameters() {
344 return this.viewRequestParameters;
345 }
346
347
348
349
350 @Override
351 public void setViewRequestParameters(Map<String, String> viewRequestParameters) {
352 this.viewRequestParameters = viewRequestParameters;
353 }
354
355
356
357
358 @Override
359 public List<String> getReadOnlyFieldsList() {
360 return readOnlyFieldsList;
361 }
362
363
364
365
366 @Override
367 public void setReadOnlyFieldsList(List<String> readOnlyFieldsList) {
368 this.readOnlyFieldsList = readOnlyFieldsList;
369 }
370
371
372
373
374 @Override
375 public Map<String, Object> getNewCollectionLines() {
376 return this.newCollectionLines;
377 }
378
379
380
381
382 @Override
383 public void setNewCollectionLines(Map<String, Object> newCollectionLines) {
384 this.newCollectionLines = newCollectionLines;
385 }
386
387
388
389
390 @Override
391 public Map<String, String> getActionParameters() {
392 return this.actionParameters;
393 }
394
395
396
397
398
399
400 public Properties getActionParametersAsProperties() {
401 return KRADUtils.convertMapToProperties(actionParameters);
402 }
403
404
405
406
407 @Override
408 public void setActionParameters(Map<String, String> actionParameters) {
409 this.actionParameters = actionParameters;
410 }
411
412
413
414
415
416
417
418
419 public String getActionParamaterValue(String actionParameterName) {
420 if ((actionParameters != null) && actionParameters.containsKey(actionParameterName)) {
421 return actionParameters.get(actionParameterName);
422 }
423
424 return "";
425 }
426
427
428
429
430
431
432
433
434
435
436
437
438
439 public String getActionEvent() {
440 if ((actionParameters != null) && actionParameters.containsKey(UifConstants.UrlParams.ACTION_EVENT)) {
441 return actionParameters.get(UifConstants.UrlParams.ACTION_EVENT);
442 }
443
444 return "";
445 }
446
447
448
449
450 @Override
451 public Map<String, Object> getClientStateForSyncing() {
452 return clientStateForSyncing;
453 }
454
455
456
457
458
459
460 public void setClientStateForSyncing(Map<String, Object> clientStateForSyncing) {
461 this.clientStateForSyncing = clientStateForSyncing;
462 }
463
464
465
466
467 @Override
468 public Map<String, Set<String>> getSelectedCollectionLines() {
469 return selectedCollectionLines;
470 }
471
472
473
474
475 @Override
476 public void setSelectedCollectionLines(Map<String, Set<String>> selectedCollectionLines) {
477 this.selectedCollectionLines = selectedCollectionLines;
478 }
479
480
481
482
483
484
485
486
487
488
489
490
491 public String getFormKey() {
492 return this.formKey;
493 }
494
495
496
497
498
499
500 public void setFormKey(String formKey) {
501 this.formKey = formKey;
502 }
503
504
505
506
507 @Override
508 public boolean isDefaultsApplied() {
509 return this.defaultsApplied;
510 }
511
512
513
514
515 @Override
516 public void setDefaultsApplied(boolean defaultsApplied) {
517 this.defaultsApplied = defaultsApplied;
518 }
519
520
521
522
523
524
525 public boolean isRequestRedirected() {
526 return requestRedirected;
527 }
528
529
530
531
532
533
534 public void setRequestRedirected(boolean requestRedirected) {
535 this.requestRedirected = requestRedirected;
536 }
537
538
539
540
541
542
543 public MultipartFile getAttachmentFile() {
544 return this.attachmentFile;
545 }
546
547
548
549
550
551
552 public void setAttachmentFile(MultipartFile attachmentFile) {
553 this.attachmentFile = attachmentFile;
554 }
555
556
557
558
559
560
561 public String getUpdateComponentId() {
562 return updateComponentId;
563 }
564
565
566
567
568
569
570 public void setUpdateComponentId(String updateComponentId) {
571 this.updateComponentId = updateComponentId;
572 }
573
574
575
576
577 @Override
578 public View getView() {
579 return this.view;
580 }
581
582
583
584
585 @Override
586 public void setView(View view) {
587 this.view = view;
588 }
589
590
591
592
593 @Override
594 public View getPostedView() {
595 return this.postedView;
596 }
597
598
599
600
601 @Override
602 public void setPostedView(View postedView) {
603 this.postedView = postedView;
604 }
605
606
607
608
609
610
611
612 protected ViewService getViewService() {
613 return KRADServiceLocatorWeb.getViewService();
614 }
615
616
617
618
619
620
621
622
623
624 public String getJumpToId() {
625 return this.jumpToId;
626 }
627
628
629
630
631 public void setJumpToId(String jumpToId) {
632 this.jumpToId = jumpToId;
633 }
634
635
636
637
638
639
640
641
642 public String getJumpToName() {
643 return this.jumpToName;
644 }
645
646
647
648
649 public void setJumpToName(String jumpToName) {
650 this.jumpToName = jumpToName;
651 }
652
653
654
655
656
657
658
659 public String getFocusId() {
660 return this.focusId;
661 }
662
663
664
665
666 public void setFocusId(String focusId) {
667 this.focusId = focusId;
668 }
669
670
671
672
673
674
675
676
677
678
679
680
681 public History getFormHistory() {
682 return formHistory;
683 }
684
685
686
687
688
689
690 public void setFormHistory(History history) {
691 this.formHistory = history;
692 }
693
694
695
696
697
698
699
700
701
702
703
704
705 public boolean isRenderedInLightBox() {
706 return this.renderedInLightBox;
707 }
708
709
710
711
712
713
714 public void setRenderedInLightBox(boolean renderedInLightBox) {
715 this.renderedInLightBox = renderedInLightBox;
716 }
717
718
719
720
721 @Override
722 public String getGrowlScript() {
723 return growlScript;
724 }
725
726
727
728
729 @Override
730 public void setGrowlScript(String growlScript) {
731 this.growlScript = growlScript;
732 }
733
734
735
736
737 public String getState() {
738 return state;
739 }
740
741
742
743
744 public void setState(String state) {
745 this.state = state;
746 }
747
748
749
750
751 @Override
752 public String getLightboxScript() {
753 return lightboxScript;
754 }
755
756
757
758
759 @Override
760 public void setLightboxScript(String lightboxScript) {
761 this.lightboxScript = lightboxScript;
762 }
763
764
765
766
767 @Override
768 public boolean isAjaxRequest() {
769 return ajaxRequest;
770 }
771
772
773
774
775 @Override
776 public void setAjaxRequest(boolean ajaxRequest) {
777 this.ajaxRequest = ajaxRequest;
778 }
779
780
781
782
783 @Override
784 public String getAjaxReturnType() {
785 return ajaxReturnType;
786 }
787
788
789
790
791 @Override
792 public boolean isUpdateComponentRequest() {
793 return isAjaxRequest() && StringUtils.isNotBlank(getAjaxReturnType()) && getAjaxReturnType().equals(
794 UifConstants.AjaxReturnTypes.UPDATECOMPONENT.getKey());
795 }
796
797
798
799
800 @Override
801 public boolean isUpdateDialogRequest() {
802 return isAjaxRequest() && StringUtils.isNotBlank(getAjaxReturnType()) && getAjaxReturnType().equals(
803 UifConstants.AjaxReturnTypes.UPDATEDIALOG.getKey());
804 }
805
806
807
808
809 @Override
810 public boolean isUpdatePageRequest() {
811 return isAjaxRequest() && StringUtils.isNotBlank(getAjaxReturnType()) && getAjaxReturnType().equals(
812 UifConstants.AjaxReturnTypes.UPDATEPAGE.getKey());
813 }
814
815
816
817
818 @Override
819 public boolean isUpdateNoneRequest() {
820 return isAjaxRequest() && StringUtils.isNotBlank(getAjaxReturnType()) && getAjaxReturnType().equals(
821 UifConstants.AjaxReturnTypes.UPDATENONE.getKey());
822 }
823
824
825
826
827 @Override
828 public boolean isBuildViewRequest() {
829 return !isAjaxRequest() || (StringUtils.isNotBlank(getAjaxReturnType()) && (getAjaxReturnType().equals(
830 UifConstants.AjaxReturnTypes.UPDATEVIEW.getKey()) || isUpdatePageRequest()));
831 }
832
833
834
835
836 @Override
837 public boolean isUpdateViewRequest() {
838 return isAjaxRequest() &&
839 StringUtils.isNotBlank(getAjaxReturnType()) &&
840 (isUpdateComponentRequest() || getAjaxReturnType().equals(
841 UifConstants.AjaxReturnTypes.DISPLAYLIGHTBOX.getKey()));
842 }
843
844
845
846
847 @Override
848 public void setAjaxReturnType(String ajaxReturnType) {
849 this.ajaxReturnType = ajaxReturnType;
850 }
851
852
853
854
855
856
857
858
859
860
861 public String getDialogExplanation() {
862 return dialogExplanation;
863 }
864
865
866
867
868
869
870 public void setDialogExplanation(String dialogExplanation) {
871 this.dialogExplanation = dialogExplanation;
872 }
873
874
875
876
877
878
879
880
881
882
883
884 public String getDialogResponse() {
885 return dialogResponse;
886 }
887
888
889
890
891
892
893 public void setDialogResponse(String dialogResponse) {
894 this.dialogResponse = dialogResponse;
895 }
896
897
898
899
900
901
902
903
904
905
906 public DialogManager getDialogManager() {
907 return dialogManager;
908 }
909
910
911
912
913
914
915 public void setDialogManager(DialogManager dialogManager) {
916 this.dialogManager = dialogManager;
917 }
918
919
920
921
922 public Map<String, Object> getExtensionData() {
923 return extensionData;
924 }
925
926
927
928
929 public void setExtensionData(Map<String, Object> extensionData) {
930 this.extensionData = extensionData;
931 }
932
933
934
935
936
937
938
939
940
941
942 public List getAddedCollectionItems() {
943 return addedCollectionItems;
944 }
945
946
947
948
949
950
951 public void setAddedCollectionItems(List addedCollectionItems) {
952 this.addedCollectionItems = addedCollectionItems;
953 }
954
955
956
957
958
959
960
961
962
963
964
965
966 public boolean isAddedCollectionItem(Object item) {
967 return addedCollectionItems.contains(item);
968 }
969
970 }