001    /*
002     * Copyright 2007 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 1.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl1.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package edu.sampleu.travel.krad.controller;
017    
018    import edu.sampleu.travel.bo.FiscalOfficer;
019    import edu.sampleu.travel.bo.TravelAccount;
020    import edu.sampleu.travel.krad.form.UITestForm;
021    import org.kuali.rice.core.api.util.type.KualiPercent;
022    import org.kuali.rice.krad.util.GlobalVariables;
023    import org.kuali.rice.krad.web.controller.UifControllerBase;
024    import org.kuali.rice.krad.web.form.UifFormBase;
025    import org.springframework.stereotype.Controller;
026    import org.springframework.validation.BindingResult;
027    import org.springframework.web.bind.annotation.ModelAttribute;
028    import org.springframework.web.bind.annotation.RequestMapping;
029    import org.springframework.web.bind.annotation.RequestMethod;
030    import org.springframework.web.servlet.ModelAndView;
031    
032    import javax.servlet.http.HttpServletRequest;
033    import javax.servlet.http.HttpServletResponse;
034    import java.util.ArrayList;
035    import java.util.List;
036    
037    /**
038     * Controller for the Test UI Page
039     * 
040     * @author Kuali Rice Team (rice.collab@kuali.org)
041     */
042    @Controller
043    @RequestMapping(value = "/uitest")
044    public class UITestController extends UifControllerBase {
045    
046            @Override
047        protected UITestForm createInitialForm(HttpServletRequest request) {
048            return new UITestForm();
049        }
050    
051            @Override
052            @RequestMapping(params = "methodToCall=start")
053            public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
054                            HttpServletRequest request, HttpServletResponse response) {
055                UITestForm uiTestForm = (UITestForm) form;
056                    
057                    // populate model for testing
058                    TravelAccount travelAccount = new TravelAccount();
059                    travelAccount.setNumber("101");
060                    travelAccount.setName("Account 101");
061    
062                    FiscalOfficer fiscalOfficer = new FiscalOfficer();
063                    fiscalOfficer.setId(new Long(1));
064                    FiscalOfficer fiscalOfficer2 = new FiscalOfficer();
065            fiscalOfficer.setId(new Long(1));
066            FiscalOfficer fiscalOfficer3 = new FiscalOfficer();
067            fiscalOfficer.setId(new Long(1));
068            FiscalOfficer fiscalOfficer4 = new FiscalOfficer();
069            fiscalOfficer.setId(new Long(1));
070            
071    
072                    List<TravelAccount> officerAccounts = new ArrayList<TravelAccount>();
073    
074                    TravelAccount travelAccount2 = new TravelAccount();
075                    travelAccount2.setNumber("102");
076                    travelAccount2.setName("Account 102");
077                    travelAccount2.setSubAccount("34");
078                    travelAccount2.setSubAccountName("G34 So");
079                    travelAccount2.setSubsidizedPercent(new KualiPercent(45.0));
080                    officerAccounts.add(travelAccount2);
081    
082                    TravelAccount travelAccount3 = new TravelAccount();
083                    travelAccount3.setNumber("103");
084                    travelAccount3.setName("Account 103");
085                    officerAccounts.add(travelAccount3);
086    
087                    TravelAccount travelAccount4 = new TravelAccount();
088                    travelAccount4.setNumber("104");
089                    travelAccount4.setName("Account 104");
090                    travelAccount4.setSubAccount("i84n");
091                    travelAccount4.setSubAccountName("Supplies");
092                    travelAccount4.setSubsidizedPercent(new KualiPercent(10));
093                    officerAccounts.add(travelAccount4);
094    
095                    fiscalOfficer.setAccounts(officerAccounts);
096                    travelAccount.setFiscalOfficer(fiscalOfficer);
097                    
098                    // build sub-collections
099                    travelAccount2.setFiscalOfficer(fiscalOfficer2);
100                    travelAccount3.setFiscalOfficer(fiscalOfficer3);
101                    travelAccount4.setFiscalOfficer(fiscalOfficer4);
102    
103                    uiTestForm.setTravelAccount1(travelAccount);
104                    uiTestForm.setTravelAccount2(travelAccount2);
105                    uiTestForm.setTravelAccount3(travelAccount3);
106                    uiTestForm.setTravelAccount4(travelAccount4);
107                    
108                    uiTestForm.setField5("a14");
109                    
110                    uiTestForm.setField1("Field1");
111                    uiTestForm.setField2("Field2");
112    
113            uiTestForm.setHidden1("Hidden1");
114            uiTestForm.setHidden2("Hidden2");
115    
116                    return super.start(uiTestForm, result, request, response);
117            }
118    
119            @RequestMapping(method = RequestMethod.POST, params = "methodToCall=save")
120            public ModelAndView save(@ModelAttribute("KualiForm") UITestForm uiTestForm, BindingResult result,
121                            HttpServletRequest request, HttpServletResponse response) {
122                    //For testing server side errors:
123                    if(uiTestForm.getField2().equals("server_error")){
124                            GlobalVariables.getMessageMap().putError("field2", "serverTestError");
125                            GlobalVariables.getMessageMap().putError("field2", "serverTestError2");
126                            GlobalVariables.getMessageMap().putWarning("field2", "serverTestWarning");
127                            GlobalVariables.getMessageMap().putInfo("field2", "serverTestInfo");
128                            GlobalVariables.getMessageMap().putInfo("field3", "serverTestInfo");
129                            GlobalVariables.getMessageMap().putError("field13", "serverTestError");
130                            GlobalVariables.getMessageMap().putWarning("field4", "serverTestWarning");
131                            GlobalVariables.getMessageMap().putWarning("TEST_WARNING", "serverTestError3");
132                            GlobalVariables.getMessageMap().putError("TEST_ERROR", "serverTestError3");
133                            GlobalVariables.getMessageMap().putError("vField5", "serverTestError");
134                            GlobalVariables.getMessageMap().putError("vField6", "serverTestError");
135                            //GlobalVariables.getMessageMap().clearErrorMessages();
136                            return getUIFModelAndView(uiTestForm, uiTestForm.getViewId(), uiTestForm.getPageId());
137                    }
138                    
139                    return getUIFModelAndView(uiTestForm, uiTestForm.getViewId(), "page1");
140            }
141            
142            @RequestMapping(method = RequestMethod.POST, params = "methodToCall=close")
143            public ModelAndView close(@ModelAttribute("KualiForm") UITestForm uiTestForm, BindingResult result,
144                            HttpServletRequest request, HttpServletResponse response) {
145    
146                    return getUIFModelAndView(uiTestForm, uiTestForm.getViewId(), "page1");
147            }
148    
149    }