View Javadoc

1   /*
2    * Copyright 2007 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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 org.kuali.rice.krms.impl.ui;
17  
18  import javax.servlet.http.HttpServletRequest;
19  import javax.servlet.http.HttpServletResponse;
20  
21  import org.kuali.rice.krad.service.BusinessObjectService;
22  import org.kuali.rice.krad.service.KRADServiceLocator;
23  import org.kuali.rice.krad.web.controller.UifControllerBase;
24  import org.kuali.rice.krms.impl.repository.AgendaBo;
25  import org.kuali.rice.krms.impl.repository.ContextBo;
26  import org.springframework.stereotype.Controller;
27  import org.springframework.validation.BindingResult;
28  import org.springframework.web.bind.annotation.ModelAttribute;
29  import org.springframework.web.bind.annotation.RequestMapping;
30  import org.springframework.web.bind.annotation.RequestMethod;
31  import org.springframework.web.servlet.ModelAndView;
32  
33  /**
34   * Controller for the Test UI Page
35   * 
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  @Controller
39  @RequestMapping(value = "/krmsEditor")
40  public class EditorController extends UifControllerBase {
41  
42  	@Override
43      protected EditorForm createInitialForm(HttpServletRequest request) {
44          return new EditorForm();
45      }
46  
47  	@RequestMapping(params = "methodToCall=start")
48  	public ModelAndView start(@ModelAttribute("KualiForm") EditorForm editorForm, BindingResult result,
49  			HttpServletRequest request, HttpServletResponse response) {
50  		
51  		// populate model for testing
52  		ContextBo context = new ContextBo();
53  		AgendaBo agenda = new AgendaBo();
54  		
55  		String[] agendaIds = request.getParameterValues("agendaId");
56          if (agendaIds == null || agendaIds.length != 1) { 
57              //throw new RiceRuntimeException("one and only one agendaId request parameter may be passed");
58          } else {
59              // TODO: throw out this hacky junk
60              String agendaId = agendaIds[0];
61  
62              agenda = getBoService().findBySinglePrimaryKey(AgendaBo.class, agendaId);
63              String contextId = agenda.getContextId();
64  
65              context = getBoService().findBySinglePrimaryKey(ContextBo.class, contextId);
66          }
67  
68  		editorForm.setContext(context);
69  		editorForm.setAgenda(agenda);
70  
71  		return getUIFModelAndView(editorForm, editorForm.getViewId());
72  	}
73  
74  	@RequestMapping(method = RequestMethod.POST, params = "methodToCall=save")
75  	public ModelAndView save(@ModelAttribute("KualiForm") EditorForm editorForm, BindingResult result,
76  			HttpServletRequest request, HttpServletResponse response) {
77  //		//For testing server side errors:
78  //		if(editorForm.getField2().equals("server_error")){
79  //			GlobalVariables.getMessageMap().putError("field2", "serverTestError");
80  //			GlobalVariables.getMessageMap().putError("field2", "serverTestError2");
81  //			GlobalVariables.getMessageMap().putWarning("field2", "serverTestWarning");
82  //			GlobalVariables.getMessageMap().putInfo("field2", "serverTestInfo");
83  //
84  //			//GlobalVariables.getMessageMap().clearErrorMessages();
85  //			return getUIFModelAndView(editorForm, editorForm.getViewId(), editorForm.getPageId());
86  //		}
87  		return getUIFModelAndView(editorForm, editorForm.getViewId());
88  	}
89  	
90  	@RequestMapping(method = RequestMethod.POST, params = "methodToCall=close")
91  	public ModelAndView close(@ModelAttribute("KualiForm") EditorForm editorForm, BindingResult result,
92  			HttpServletRequest request, HttpServletResponse response) {
93  
94  		return getUIFModelAndView(editorForm, editorForm.getViewId());
95  	}
96  	
97  	private BusinessObjectService getBoService() {
98  	    return KRADServiceLocator.getBusinessObjectService();
99  	}
100 
101 }