View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package edu.sampleu.travel.krad.controller;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import javax.servlet.http.HttpServletRequest;
22  import javax.servlet.http.HttpServletResponse;
23  
24  import org.kuali.rice.core.api.util.type.KualiPercent;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  import org.kuali.rice.krad.web.controller.UifControllerBase;
27  import org.kuali.rice.krad.web.form.UifFormBase;
28  import org.springframework.stereotype.Controller;
29  import org.springframework.validation.BindingResult;
30  import org.springframework.web.bind.annotation.ModelAttribute;
31  import org.springframework.web.bind.annotation.RequestMapping;
32  import org.springframework.web.bind.annotation.RequestMethod;
33  import org.springframework.web.servlet.ModelAndView;
34  
35  import edu.sampleu.travel.bo.FiscalOfficer;
36  import edu.sampleu.travel.bo.TravelAccount;
37  import edu.sampleu.travel.krad.form.UITestForm;
38  
39  /**
40   * Controller for the Test UI Page
41   * 
42   * @author Kuali Rice Team (rice.collab@kuali.org)
43   */
44  @Controller
45  @RequestMapping(value = "/uitest")
46  public class UITestController extends UifControllerBase {
47  
48      /**
49       * @see org.kuali.rice.krad.web.controller.UifControllerBase#createInitialForm(javax.servlet.http.HttpServletRequest)
50       */
51      @Override
52      protected UITestForm createInitialForm(HttpServletRequest request) {
53          return new UITestForm();
54      }
55  
56  	@Override
57  	@RequestMapping(params = "methodToCall=start")
58  	public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
59  			HttpServletRequest request, HttpServletResponse response) {
60  	    UITestForm uiTestForm = (UITestForm) form;
61  		
62  		// populate model for testing
63  		TravelAccount travelAccount = new TravelAccount();
64  		travelAccount.setNumber("101");
65  		travelAccount.setName("Account 101");
66  
67  		FiscalOfficer fiscalOfficer = new FiscalOfficer();
68  		fiscalOfficer.setId(new Long(1));
69  		FiscalOfficer fiscalOfficer2 = new FiscalOfficer();
70          fiscalOfficer.setId(new Long(1));
71          FiscalOfficer fiscalOfficer3 = new FiscalOfficer();
72          fiscalOfficer.setId(new Long(1));
73          FiscalOfficer fiscalOfficer4 = new FiscalOfficer();
74          fiscalOfficer.setId(new Long(1));
75          
76  
77  		List<TravelAccount> officerAccounts = new ArrayList<TravelAccount>();
78  
79  		TravelAccount travelAccount2 = new TravelAccount();
80  		travelAccount2.setNumber("102");
81  		travelAccount2.setName("Account 102");
82  		travelAccount2.setSubAccount("34");
83  		travelAccount2.setSubAccountName("G34 So");
84  		travelAccount2.setSubsidizedPercent(new KualiPercent(45.0));
85  		officerAccounts.add(travelAccount2);
86  
87  		TravelAccount travelAccount3 = new TravelAccount();
88  		travelAccount3.setNumber("103");
89  		travelAccount3.setName("Account 103");
90  		officerAccounts.add(travelAccount3);
91  
92  		TravelAccount travelAccount4 = new TravelAccount();
93  		travelAccount4.setNumber("104");
94  		travelAccount4.setName("Account 104");
95  		travelAccount4.setSubAccount("i84n");
96  		travelAccount4.setSubAccountName("Supplies");
97  		travelAccount4.setSubsidizedPercent(new KualiPercent(10));
98  		officerAccounts.add(travelAccount4);
99  
100 		fiscalOfficer.setAccounts(officerAccounts);
101 		travelAccount.setFiscalOfficer(fiscalOfficer);
102 		
103 		// build sub-collections
104 		travelAccount2.setFiscalOfficer(fiscalOfficer2);
105 		travelAccount3.setFiscalOfficer(fiscalOfficer3);
106 		travelAccount4.setFiscalOfficer(fiscalOfficer4);
107 
108 		uiTestForm.setTravelAccount1(travelAccount);
109 		uiTestForm.setTravelAccount2(travelAccount2);
110 		uiTestForm.setTravelAccount3(travelAccount3);
111 		uiTestForm.setTravelAccount4(travelAccount4);
112 		
113 		uiTestForm.setField5("a14");
114 		
115 		uiTestForm.setField1("Field1");
116 		uiTestForm.setField2("Field2");
117 
118         uiTestForm.setHidden1("Hidden1");
119         uiTestForm.setHidden2("Hidden2");
120 
121 		return super.start(uiTestForm, result, request, response);
122 	}
123 
124 	@RequestMapping(method = RequestMethod.POST, params = "methodToCall=save")
125 	public ModelAndView save(@ModelAttribute("KualiForm") UITestForm uiTestForm, BindingResult result,
126 			HttpServletRequest request, HttpServletResponse response) {
127 		//For testing server side errors:
128 		if(uiTestForm.getField2().equals("server_error")){
129 			GlobalVariables.getMessageMap().putError("field2", "serverTestError");
130 			GlobalVariables.getMessageMap().putError("field2", "serverTestError2");
131 			GlobalVariables.getMessageMap().putWarning("field2", "serverTestWarning");
132 			GlobalVariables.getMessageMap().putInfo("field2", "serverTestInfo");
133 			GlobalVariables.getMessageMap().putInfo("field3", "serverTestInfo");
134 			GlobalVariables.getMessageMap().putError("field13", "serverTestError");
135 			GlobalVariables.getMessageMap().putWarning("field4", "serverTestWarning");
136 			GlobalVariables.getMessageMap().putWarning("TEST_WARNING", "serverTestError3");
137 			GlobalVariables.getMessageMap().putError("TEST_ERROR", "serverTestError3");
138 			GlobalVariables.getMessageMap().putError("vField5", "serverTestError");
139 			GlobalVariables.getMessageMap().putError("vField6", "serverTestError");
140 			//GlobalVariables.getMessageMap().clearErrorMessages();
141 			return getUIFModelAndView(uiTestForm, uiTestForm.getPageId());
142 		}
143 		
144 		return getUIFModelAndView(uiTestForm, "page1");
145 	}
146 	
147 	@RequestMapping(method = RequestMethod.POST, params = "methodToCall=close")
148 	public ModelAndView close(@ModelAttribute("KualiForm") UITestForm uiTestForm, BindingResult result,
149 			HttpServletRequest request, HttpServletResponse response) {
150 
151 		return getUIFModelAndView(uiTestForm, "page1");
152 	}
153 
154     /**
155      * The bogus method generates a NPE.  It is used to test incident reporting
156      * @param uiTestForm
157      * @param result
158      * @param request
159      * @param response
160      * @return
161      */
162     @RequestMapping(method = RequestMethod.GET, params = "methodToCall=foo")
163     public ModelAndView foo(@ModelAttribute("KualiForm") UITestForm uiTestForm, BindingResult result,
164             HttpServletRequest request, HttpServletResponse response) {
165 
166         String bogus = null;
167         // intentially generate a null pointer error
168         bogus.charAt(3);
169 
170         // should never get here
171         return getUIFModelAndView(uiTestForm, "page1");
172     }
173 
174 }