1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package edu.sampleu.demo.kitchensink;
17  
18  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
19  import org.kuali.rice.krad.uif.UifConstants;
20  import org.kuali.rice.krad.uif.UifParameters;
21  import org.kuali.rice.krad.util.AuditCluster;
22  import org.kuali.rice.krad.util.AuditError;
23  import org.kuali.rice.krad.util.GlobalVariables;
24  import org.kuali.rice.krad.util.KRADConstants;
25  import org.kuali.rice.krad.web.controller.UifControllerBase;
26  import org.kuali.rice.krad.web.form.UifFormBase;
27  import org.springframework.stereotype.Controller;
28  import org.springframework.validation.BindingResult;
29  import org.springframework.web.bind.annotation.ModelAttribute;
30  import org.springframework.web.bind.annotation.RequestMapping;
31  import org.springframework.web.bind.annotation.RequestMethod;
32  import org.springframework.web.servlet.ModelAndView;
33  
34  import javax.servlet.http.HttpServletRequest;
35  import javax.servlet.http.HttpServletResponse;
36  import java.util.ArrayList;
37  import java.util.List;
38  import java.util.Properties;
39  import java.util.Set;
40  
41  
42  
43  
44  
45  
46  @Controller
47  @RequestMapping(value = "/uicomponents")
48  public class UifComponentsTestController extends UifControllerBase {
49  
50      
51  
52  
53      @Override
54      protected UifComponentsTestForm createInitialForm() {
55          return new UifComponentsTestForm();
56      }
57  
58      @Override
59      @RequestMapping(params = "methodToCall=start")
60      public ModelAndView start(UifFormBase form) {
61          UifComponentsTestForm uiTestForm = (UifComponentsTestForm) form;
62          form.setState("state1");
63          
64          if (form.getView().getId().equals("UifGeneratedFields")) {
65              for (int i = 0; i < 100; i++) {
66                  ((UifComponentsTestForm) form).getList1generated().add(new UITestObject("A" + i, "B" + i, "C" + i,
67                          "D" + i));
68              }
69              for (int i = 0; i < 100; i++) {
70                  ((UifComponentsTestForm) form).getList2generated().add(new UITestObject("A" + i, "B" + i, "C" + i,
71                          "D" + i));
72              }
73              for (int i = 0; i < 10; i++) {
74                  ((UifComponentsTestForm) form).getList3generated().add(new UITestObject("A" + i, "B" + i, "C" + i,
75                          "D" + i));
76                  for (int j = 0; j < 10; j++) {
77                      ((UifComponentsTestForm) form).getList3generated().get(i).getSubList().add(new UITestObject(
78                              "i" + i + "-" + j, "i" + i + "-" + j, "i" + i + "-" + j, "i" + i + "-" + j));
79                  }
80              }
81          }
82  
83          GlobalVariables.getMessageMap().addGrowlMessage("Welcome!", "kitchenSink.welcome");
84  
85          return super.start(uiTestForm);
86      }
87  
88      @RequestMapping(method = RequestMethod.POST, params = "methodToCall=save")
89      public ModelAndView save(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm, BindingResult result,
90              HttpServletRequest request, HttpServletResponse response) {
91          KRADServiceLocatorWeb.getViewValidationService().validateView(uiTestForm);
92  
93          return getModelAndView(uiTestForm);
94      }
95  
96      @RequestMapping(method = RequestMethod.POST, params = "methodToCall=close")
97      public ModelAndView close(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm, BindingResult result,
98              HttpServletRequest request, HttpServletResponse response) {
99  
100         return getModelAndView(uiTestForm, "UifCompView-Page1");
101     }
102 
103     
104 
105 
106     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=navigate")
107     public ModelAndView navigate(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
108             HttpServletRequest request, HttpServletResponse response) {
109         String pageId = form.getActionParamaterValue(UifParameters.NAVIGATE_TO_PAGE_ID);
110 
111         if (pageId.equals("UifCompView-Page8")) {
112             GlobalVariables.getMessageMap().putError("gField1", "serverTestError");
113             GlobalVariables.getMessageMap().putError("gField1", "serverTestError2");
114             GlobalVariables.getMessageMap().putError("gField2", "serverTestError");
115             GlobalVariables.getMessageMap().putError("gField3", "serverTestError");
116             GlobalVariables.getMessageMap().putWarning("gField1", "serverTestWarning");
117             GlobalVariables.getMessageMap().putWarning("gField2", "serverTestWarning");
118             GlobalVariables.getMessageMap().putInfo("gField2", "serverTestInfo");
119             GlobalVariables.getMessageMap().putInfo("gField3", "serverTestInfo");
120         }
121 
122         return getModelAndView(form, pageId);
123     }
124 
125     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=refreshProgGroup")
126     public ModelAndView refreshProgGroup(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm,
127             BindingResult result, HttpServletRequest request, HttpServletResponse response) {
128 
129         return getModelAndView(uiTestForm);
130     }
131 
132     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=refreshWithServerMessages")
133     public ModelAndView refreshWithServerMessages(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm,
134             BindingResult result, HttpServletRequest request, HttpServletResponse response) {
135         GlobalVariables.getMessageMap().putError("field45", "serverTestError");
136         GlobalVariables.getMessageMap().putWarning("field45", "serverTestWarning");
137         GlobalVariables.getMessageMap().putInfo("field45", "serverTestInfo");
138 
139         return getModelAndView(uiTestForm);
140     }
141 
142     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=genCollectionServerMessages")
143     public ModelAndView genCollectionServerMessages(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm,
144             BindingResult result, HttpServletRequest request, HttpServletResponse response) throws Exception {
145         GlobalVariables.getMessageMap().putError("list2[0].field1", "serverTestError");
146         GlobalVariables.getMessageMap().putWarning("list2[0].field1", "serverTestWarning");
147         GlobalVariables.getMessageMap().putInfo("list2[0].field1", "serverTestInfo");
148 
149         GlobalVariables.getMessageMap().putError("list3[0].field1", "serverTestError");
150         GlobalVariables.getMessageMap().putWarning("list3[0].field1", "serverTestWarning");
151         GlobalVariables.getMessageMap().putInfo("list3[0].field1", "serverTestInfo");
152 
153         GlobalVariables.getMessageMap().putError("list5[0].subList[0].field1", "serverTestError");
154         GlobalVariables.getMessageMap().putWarning("list5[0].subList[0].field1", "serverTestWarning");
155         GlobalVariables.getMessageMap().putInfo("list5[0].subList[0].field1", "serverTestInfo");
156         return refresh(uiTestForm);
157     }
158 
159     
160 
161 
162     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addErrors")
163     public ModelAndView addErrors(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
164             HttpServletRequest request, HttpServletResponse response) {
165 
166         if (form.getPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")) {
167             GlobalVariables.getMessageMap().putError("Demo-ValidationLayout-Section1", "errorSectionTest");
168             GlobalVariables.getMessageMap().putError("Demo-ValidationLayout-Section2", "errorSectionTest");
169         } else if (form.getPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")) {
170             GlobalVariables.getMessageMap().putError("badKey", "unmatchedTest");
171         } else if (form.getPageId().equals("Demo-ValidationLayout-SubSectionsPage")) {
172             GlobalVariables.getMessageMap().putError("Uif-ValidationLayout-SubGroup", "errorSectionTest");
173         }
174 
175         if (form.getViewPostMetadata().getId().equals("RichMessagesView")) {
176             GlobalVariables.getMessageMap().putError("Demo-BasicMessagesSection", "richValidationMessageTest");
177             GlobalVariables.getMessageMap().putError("field5", "richValidationMessageTest2");
178         }
179 
180         Set<String> inputFieldIds = form.getViewPostMetadata().getInputFieldIds();
181         for (String id : inputFieldIds) {
182             if (form.getViewPostMetadata().getComponentPostData(id, UifConstants.PostMetadata.PATH) != null) {
183                 String key = (String) form.getViewPostMetadata().getComponentPostData(id,
184                         UifConstants.PostMetadata.PATH);
185                 GlobalVariables.getMessageMap().putError(key, "error1Test");
186             }
187         }
188 
189         return getModelAndView(form);
190     }
191 
192     
193 
194 
195     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addWarnings")
196     public ModelAndView addWarnings(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
197             HttpServletRequest request, HttpServletResponse response) {
198 
199         if (form.getPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")) {
200             GlobalVariables.getMessageMap().putWarning("Demo-ValidationLayout-Section1", "warningSectionTest");
201             GlobalVariables.getMessageMap().putWarning("Demo-ValidationLayout-Section2", "warningSectionTest");
202         } else if (form.getPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")) {
203             GlobalVariables.getMessageMap().putWarning("badKey", "unmatchedTest");
204         }
205 
206         Set<String> inputFieldIds = form.getViewPostMetadata().getInputFieldIds();
207         for (String id : inputFieldIds) {
208             if (form.getViewPostMetadata().getComponentPostData(id, UifConstants.PostMetadata.PATH) != null) {
209                 String key = (String) form.getViewPostMetadata().getComponentPostData(id,
210                         UifConstants.PostMetadata.PATH);
211                 GlobalVariables.getMessageMap().putWarning(key, "warning1Test");
212             }
213         }
214 
215         return getModelAndView(form);
216     }
217 
218     
219 
220 
221     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addInfo")
222     public ModelAndView addInfo(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
223             HttpServletRequest request, HttpServletResponse response) {
224 
225         if (form.getPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")) {
226             GlobalVariables.getMessageMap().putInfo("Demo-ValidationLayout-Section1", "infoSectionTest");
227             GlobalVariables.getMessageMap().putInfo("Demo-ValidationLayout-Section2", "infoSectionTest");
228         } else if (form.getPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")) {
229             GlobalVariables.getMessageMap().putInfo("badKey", "unmatchedTest");
230         }
231 
232         Set<String> inputFieldIds = form.getViewPostMetadata().getInputFieldIds();
233         for (String id : inputFieldIds) {
234             if (form.getViewPostMetadata().getComponentPostData(id, UifConstants.PostMetadata.PATH) != null) {
235                 String key = (String) form.getViewPostMetadata().getComponentPostData(id,
236                         UifConstants.PostMetadata.PATH);
237                 GlobalVariables.getMessageMap().putInfo(key, "info1Test");
238             }
239         }
240 
241         return getModelAndView(form);
242     }
243 
244     
245 
246 
247     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addAllMessages")
248     public ModelAndView addAllMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
249             HttpServletRequest request, HttpServletResponse response) {
250 
251         this.addErrors(form, result, request, response);
252         this.addWarnings(form, result, request, response);
253         this.addInfo(form, result, request, response);
254 
255         return getModelAndView(form);
256     }
257 
258     
259 
260 
261     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addErrorWarnMessages")
262     public ModelAndView addErrorWarnMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
263             HttpServletRequest request, HttpServletResponse response) {
264 
265         this.addErrors(form, result, request, response);
266         this.addWarnings(form, result, request, response);
267 
268         return getModelAndView(form);
269     }
270 
271     
272 
273 
274     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addErrorInfoMessages")
275     public ModelAndView addErrorInfoMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
276             HttpServletRequest request, HttpServletResponse response) {
277 
278         this.addErrors(form, result, request, response);
279         this.addInfo(form, result, request, response);
280 
281         return getModelAndView(form);
282     }
283 
284     
285 
286 
287     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addSingleErrorMessage")
288     public ModelAndView addSingleErrorMessage(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
289             HttpServletRequest request, HttpServletResponse response) {
290 
291         if (form.getPageId().equals("Demo-ValidationLayout-SubSectionsPage")) {
292             GlobalVariables.getMessageMap().putError("Uif-ValidationLayout-SubGroup", "errorSectionTest");
293         } else {
294             GlobalVariables.getMessageMap().putError("Demo-ValidationLayout-Section1", "errorSectionTest");
295         }
296 
297         return getModelAndView(form);
298     }
299 
300     
301 
302 
303     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addWarnInfoMessages")
304     public ModelAndView addWarnInfoMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
305             HttpServletRequest request, HttpServletResponse response) {
306 
307         this.addWarnings(form, result, request, response);
308         this.addInfo(form, result, request, response);
309 
310         return getModelAndView(form);
311     }
312 
313     
314 
315 
316     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addAuditErrors")
317     public ModelAndView addAuditErrors(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
318             HttpServletRequest request, HttpServletResponse response) {
319 
320         List<AuditError> auditErrors = new ArrayList<AuditError>();
321         List<AuditError> auditWarnings = new ArrayList<AuditError>();
322         Set<String> inputFieldIds = form.getViewPostMetadata().getInputFieldIds();
323         for (String id : inputFieldIds) {
324             if (form.getViewPostMetadata().getComponentPostData(id, UifConstants.PostMetadata.PATH) != null) {
325                 String key = (String) form.getViewPostMetadata().getComponentPostData(id,
326                         UifConstants.PostMetadata.PATH);
327                 auditErrors.add(new AuditError(key, "error1Test", "link"));
328                 auditWarnings.add(new AuditError(key, "warning1Test", "link"));
329             }
330         }
331         auditErrors.add(new AuditError("Demo-ValidationLayout-Section1", "errorSectionTest", "link"));
332 
333         GlobalVariables.getAuditErrorMap().put("A", new AuditCluster("A", auditErrors,
334                 KRADConstants.Audit.AUDIT_ERRORS));
335         GlobalVariables.getAuditErrorMap().put("B", new AuditCluster("B", auditWarnings,
336                 KRADConstants.Audit.AUDIT_WARNINGS));
337 
338         return getModelAndView(form);
339     }
340 
341     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=gotoState2")
342     public ModelAndView gotoState2(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
343             HttpServletRequest request, HttpServletResponse response) {
344 
345         KRADServiceLocatorWeb.getViewValidationService().validateView(form, "state2");
346         if (!GlobalVariables.getMessageMap().hasErrors()) {
347             form.setState("state2");
348         }
349 
350         return getModelAndView(form);
351     }
352 
353     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=gotoState3")
354     public ModelAndView gotoState3(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
355             HttpServletRequest request, HttpServletResponse response) {
356 
357         KRADServiceLocatorWeb.getViewValidationService().validateView(form, "state3");
358         if (!GlobalVariables.getMessageMap().hasErrors()) {
359             form.setState("state3");
360         }
361 
362         return getModelAndView(form);
363     }
364 
365     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=gotoState4")
366     public ModelAndView gotoState4(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
367             HttpServletRequest request, HttpServletResponse response) {
368 
369         KRADServiceLocatorWeb.getViewValidationService().validateView(form, "state4");
370         if (!GlobalVariables.getMessageMap().hasErrors()) {
371             form.setState("state4");
372         }
373 
374         return getModelAndView(form);
375     }
376 
377     
378 
379 
380 
381 
382     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=errorCheck")
383     public ModelAndView errorCheck(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
384             HttpServletRequest request, HttpServletResponse response) {
385 
386         if (true) {
387             throw new RuntimeException("Generate fake incident report");
388         }
389 
390         return getModelAndView(form);
391     }
392 
393     
394 
395 
396 
397 
398     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=redirectCheck")
399     public ModelAndView redirectCheck(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
400             HttpServletRequest request, HttpServletResponse response) {
401         Properties props = new Properties();
402         props.put(UifParameters.VIEW_ID, form.getViewId());
403         props.put(UifParameters.FORM_KEY, form.getFormKey());
404         return performRedirect(form, "http://localhost:8080/kr-dev", props);
405     }
406 
407     @Override
408     public ModelAndView addLine(UifFormBase uifForm) {
409         GlobalVariables.getMessageMap().addGrowlMessage("Greetings!", "kitchenSink.welcome");
410         if (uifForm.getPageId().equals("Demo-ValidationLayout-CollectionsErrorPage")) {
411             GlobalVariables.getMessageMap().putError("Demo-ValidationLayout-CollectionErrorSection",
412                     "errorSectionTest");
413             GlobalVariables.getMessageMap().putErrorForSectionId("Demo-ValidationLayout-CollectionErrorSection",
414                     "errorSectionTest");
415         }
416         return super.addLine(uifForm);
417     }
418 
419     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=customLineAction")
420     public ModelAndView customLineAction(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
421             HttpServletRequest request, HttpServletResponse response) {
422 
423         String actionParm1 = uifForm.getActionParamaterValue("field1");
424         String actionParm2 = uifForm.getActionParamaterValue("field2");
425 
426         GlobalVariables.getMessageMap().addGrowlMessage("Action Parameters", "actionParms.message", actionParm1,
427                 actionParm2);
428 
429         return super.deleteLine(uifForm);
430     }
431 
432     
433 
434 
435 
436     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=updateOfficial")
437     public ModelAndView updateOfficial(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
438             HttpServletRequest request, HttpServletResponse response) {
439 
440         String actionParm1 = uifForm.getActionParamaterValue("field1");
441 
442         GlobalVariables.getMessageMap().addGrowlMessage("Action Parameters", "customLineAction.message", actionParm1);
443 
444         return getModelAndView(uifForm);
445     }
446 
447     
448 
449 
450 
451 
452     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=makeReadOnly")
453     public ModelAndView makeReadOnly(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
454             HttpServletRequest request, HttpServletResponse response) {
455         
456         uifForm.getView().setReadOnly(true);
457         return getModelAndView(uifForm);
458     }
459 }