001/**
002 * Copyright 2005-2015 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.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/ecl2.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 */
016package org.kuali.rice.krad.web.controller;
017
018import org.kuali.rice.krad.uif.UifConstants;
019import org.kuali.rice.krad.uif.field.AttributeQueryResult;
020import org.kuali.rice.krad.util.GlobalVariables;
021import org.kuali.rice.krad.web.form.UifFormBase;
022import org.kuali.rice.krad.web.service.CollectionControllerService;
023import org.kuali.rice.krad.web.service.ControllerService;
024import org.kuali.rice.krad.web.service.FileControllerService;
025import org.kuali.rice.krad.web.service.ModelAndViewService;
026import org.kuali.rice.krad.web.service.NavigationControllerService;
027import org.kuali.rice.krad.web.service.QueryControllerService;
028import org.kuali.rice.krad.web.service.RefreshControllerService;
029import org.kuali.rice.krad.web.service.SaveControllerService;
030import org.springframework.beans.factory.annotation.Autowired;
031import org.springframework.validation.BindingResult;
032import org.springframework.web.bind.annotation.ModelAttribute;
033import org.springframework.web.bind.annotation.RequestMapping;
034import org.springframework.web.bind.annotation.RequestMethod;
035import org.springframework.web.bind.annotation.ResponseBody;
036import org.springframework.web.servlet.ModelAndView;
037
038import javax.servlet.http.HttpServletRequest;
039import javax.servlet.http.HttpServletResponse;
040import java.util.Map;
041import java.util.Properties;
042
043/**
044 * Base controller class for views within the KRAD User Interface Framework.
045 *
046 * <p>Provides common methods such as navigation, collection handling, queries, and refresh calls.
047 *
048 * All subclass controller methods after processing should call one of the #getModelAndView methods to
049 * setup the {@link org.kuali.rice.krad.uif.view.View} and return the {@link org.springframework.web.servlet.ModelAndView}
050 * instance.</p>
051 *
052 * @author Kuali Rice Team (rice.collab@kuali.org)
053 */
054public abstract class UifControllerBase {
055
056    @Autowired
057    private ControllerService controllerService;
058
059    @Autowired
060    private NavigationControllerService navigationControllerService;
061
062    @Autowired
063    private CollectionControllerService collectionControllerService;
064
065    @Autowired
066    private SaveControllerService saveControllerService;
067
068    @Autowired
069    private RefreshControllerService refreshControllerService;
070
071    @Autowired
072    private QueryControllerService queryControllerService;
073
074    @Autowired
075    private FileControllerService fileControllerService;
076
077    @Autowired
078    private ModelAndViewService modelAndViewService;
079
080    /**
081     * Creates form instance the will be used for the default model.
082     *
083     * @return UifFormBase form instance for holding model data
084     */
085    @ModelAttribute(value = UifConstants.DEFAULT_MODEL_NAME)
086    protected UifFormBase initForm() {
087        return createInitialForm();
088    }
089
090    /**
091     * Invoked to create a new form instance for the request before it is passed to the Binder/BeanWrapper.
092     *
093     * @return UifFormBase instance that will be used for data binding and backing the view.
094     */
095    protected abstract UifFormBase createInitialForm();
096
097    /**
098     * Default method mapping for cases where the method to call is not passed, calls the start method.
099     */
100    @RequestMapping()
101    public ModelAndView defaultMapping(UifFormBase form) {
102        return start(form);
103    }
104
105    /**
106     * @see org.kuali.rice.krad.web.service.ControllerService#start(org.kuali.rice.krad.web.form.UifFormBase)
107     */
108    @RequestMapping(method = RequestMethod.GET, params = "methodToCall=start")
109    public ModelAndView start(UifFormBase form) {
110        return getControllerService().start(form);
111    }
112
113    /**
114     * @see org.kuali.rice.krad.web.service.ControllerService#sessionTimeout(org.kuali.rice.krad.web.form.UifFormBase)
115     */
116    @RequestMapping(params = "methodToCall=sessionTimeout")
117    public ModelAndView sessionTimeout(UifFormBase form) {
118        return getControllerService().sessionTimeout(form);
119    }
120
121    /**
122     * @see org.kuali.rice.krad.web.service.ControllerService#cancel(org.kuali.rice.krad.web.form.UifFormBase)
123     */
124    @RequestMapping(params = "methodToCall=cancel")
125    public ModelAndView cancel(UifFormBase form) {
126        return getControllerService().cancel(form);
127    }
128
129    /**
130     * @see org.kuali.rice.krad.web.service.NavigationControllerService#back(org.kuali.rice.krad.web.form.UifFormBase)
131     */
132    @RequestMapping(params = "methodToCall=back")
133    public ModelAndView back(UifFormBase form) {
134        return getNavigationControllerService().back(form);
135    }
136
137    /**
138     * @see org.kuali.rice.krad.web.service.NavigationControllerService#returnToPrevious(org.kuali.rice.krad.web.form.UifFormBase)
139     */
140    @RequestMapping(params = "methodToCall=returnToPrevious")
141    public ModelAndView returnToPrevious(UifFormBase form) {
142        return getNavigationControllerService().returnToPrevious(form);
143    }
144
145    /**
146     * @see org.kuali.rice.krad.web.service.SaveControllerService#save(org.kuali.rice.krad.web.form.UifFormBase)
147     */
148    @RequestMapping(method = RequestMethod.POST, params = "methodToCall=save")
149    public ModelAndView save(UifFormBase form) throws Exception{
150        // Hook method for saving the form
151        return getSaveControllerService().save(form);
152    }
153
154    /**
155     * @see org.kuali.rice.krad.web.service.SaveControllerService#saveField(org.kuali.rice.krad.web.form.UifFormBase)
156     */
157    @RequestMapping(method = RequestMethod.POST, params = "methodToCall=saveField")
158    public ModelAndView saveField(UifFormBase form) throws Exception{
159        // Hook method for saving individual fields
160        return getSaveControllerService().saveField(form);
161    }
162
163    /**
164     * @see org.kuali.rice.krad.web.service.NavigationControllerService#returnToHub(org.kuali.rice.krad.web.form.UifFormBase)
165     */
166    @RequestMapping(params = "methodToCall=returnToHub")
167    public ModelAndView returnToHub(UifFormBase form) {
168        return getNavigationControllerService().returnToHub(form);
169    }
170
171    /**
172     * @see org.kuali.rice.krad.web.service.FileControllerService#addFileUploadLine(org.kuali.rice.krad.web.form.UifFormBase)
173     */
174    @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addFileUploadLine")
175    public ModelAndView addFileUploadLine(UifFormBase form) {
176        return getFileControllerService().addFileUploadLine(form);
177    }
178
179    /**
180     * @see org.kuali.rice.krad.web.service.FileControllerService#deleteFileUploadLine(org.kuali.rice.krad.web.form.UifFormBase)
181     */
182    @RequestMapping(method = RequestMethod.POST, params = "methodToCall=deleteFileUploadLine")
183    public ModelAndView deleteFileUploadLine(UifFormBase form) {
184        return getFileControllerService().deleteFileUploadLine(form);
185    }
186
187    /**
188     * @see org.kuali.rice.krad.web.service.FileControllerService#getFileFromLine(org.kuali.rice.krad.web.form.UifFormBase,
189     * javax.servlet.http.HttpServletResponse)
190     */
191    @RequestMapping(method = RequestMethod.GET, params = "methodToCall=getFileFromLine")
192    public void getFileFromLine(UifFormBase form, HttpServletResponse response) {
193        getFileControllerService().getFileFromLine(form, response);
194    }
195
196    /**
197     * @see org.kuali.rice.krad.web.service.NavigationControllerService#navigate(org.kuali.rice.krad.web.form.UifFormBase)
198     */
199    @RequestMapping(method = RequestMethod.POST, params = "methodToCall=navigate")
200    public ModelAndView navigate(UifFormBase form) {
201        return getNavigationControllerService().navigate(form);
202    }
203
204    /**
205     * @see org.kuali.rice.krad.web.service.CollectionControllerService#addLine(org.kuali.rice.krad.web.form.UifFormBase)
206     */
207    @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addLine")
208    public ModelAndView addLine(UifFormBase form) {
209        return getCollectionControllerService().addLine(form);
210    }
211
212    /**
213     * @see org.kuali.rice.krad.web.service.CollectionControllerService#addBlankLine(org.kuali.rice.krad.web.form.UifFormBase)
214     */
215    @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addBlankLine")
216    public ModelAndView addBlankLine(UifFormBase form) {
217        return getCollectionControllerService().addBlankLine(form);
218    }
219
220    /**
221     * @see org.kuali.rice.krad.web.service.CollectionControllerService#retrieveEditLineDialog(org.kuali.rice.krad.web.form.UifFormBase)
222     */
223    @RequestMapping(method = RequestMethod.POST, params = "methodToCall=retrieveEditLineDialog")
224    public ModelAndView retrieveEditLineDialog(UifFormBase form) {
225        return getCollectionControllerService().retrieveEditLineDialog(form);
226    }
227
228    /**
229     * @see org.kuali.rice.krad.web.service.CollectionControllerService#editLine(org.kuali.rice.krad.web.form.UifFormBase)
230     */
231    @RequestMapping(method = RequestMethod.POST, params = "methodToCall=editLine")
232    public ModelAndView editLine(UifFormBase form) {
233        return getCollectionControllerService().editLine(form);
234    }
235
236    /**
237     * @see org.kuali.rice.krad.web.service.CollectionControllerService#closeEditLineDialog(org.kuali.rice.krad.web.form.UifFormBase)
238     */
239    @RequestMapping(method = RequestMethod.POST, params = "methodToCall=closeEditLineDialog")
240    public ModelAndView closeEditLineDialog(UifFormBase form) {
241        return getCollectionControllerService().closeEditLineDialog(form);
242    }
243
244    /**
245     * @see org.kuali.rice.krad.web.service.CollectionControllerService#saveLine(org.kuali.rice.krad.web.form.UifFormBase)
246     */
247    @RequestMapping(method = RequestMethod.POST, params = "methodToCall=saveLine")
248    public ModelAndView saveLine(UifFormBase form) {
249        return getCollectionControllerService().saveLine(form);
250    }
251
252    /**
253     * @see org.kuali.rice.krad.web.service.CollectionControllerService#deleteLine(org.kuali.rice.krad.web.form.UifFormBase)
254     */
255    @RequestMapping(method = RequestMethod.POST, params = "methodToCall=deleteLine")
256    public ModelAndView deleteLine(final UifFormBase form) {
257        return getCollectionControllerService().deleteLine(form);
258    }
259
260    /**
261     * @see org.kuali.rice.krad.web.service.CollectionControllerService#retrieveCollectionPage(org.kuali.rice.krad.web.form.UifFormBase)
262     */
263    @RequestMapping(params = "methodToCall=retrieveCollectionPage")
264    public ModelAndView retrieveCollectionPage(UifFormBase form) {
265        return getCollectionControllerService().retrieveCollectionPage(form);
266    }
267
268    /**
269     * @see org.kuali.rice.krad.web.service.CollectionControllerService#tableJsonRetrieval(org.kuali.rice.krad.web.form.UifFormBase)
270     */
271    @RequestMapping(method = RequestMethod.GET, params = "methodToCall=tableJsonRetrieval")
272    public ModelAndView tableJsonRetrieval(UifFormBase form) {
273        return getCollectionControllerService().tableJsonRetrieval(form);
274    }
275
276    /**
277     * @see org.kuali.rice.krad.web.service.RefreshControllerService#refresh(org.kuali.rice.krad.web.form.UifFormBase)
278     */
279    @MethodAccessible
280    @RequestMapping(params = "methodToCall=refresh")
281    public ModelAndView refresh(UifFormBase form) {
282        return getRefreshControllerService().refresh(form);
283    }
284
285    /**
286     * @see org.kuali.rice.krad.web.service.QueryControllerService#performLookup(org.kuali.rice.krad.web.form.UifFormBase)
287     */
288    @RequestMapping(method = RequestMethod.POST, params = "methodToCall=performLookup")
289    public ModelAndView performLookup(UifFormBase form) {
290        return getQueryControllerService().performLookup(form);
291    }
292
293    /**
294     * @see org.kuali.rice.krad.web.service.QueryControllerService#performFieldSuggest(org.kuali.rice.krad.web.form.UifFormBase)
295     */
296    @RequestMapping(method = RequestMethod.GET, params = "methodToCall=performFieldSuggest")
297    @ResponseBody
298    public AttributeQueryResult performFieldSuggest(UifFormBase form) {
299        return getQueryControllerService().performFieldSuggest(form);
300    }
301
302    /**
303     * @see org.kuali.rice.krad.web.service.QueryControllerService#performFieldQuery(org.kuali.rice.krad.web.form.UifFormBase)
304     */
305    @RequestMapping(method = RequestMethod.GET, params = "methodToCall=performFieldQuery")
306    @ResponseBody
307    public AttributeQueryResult performFieldQuery(UifFormBase form) {
308        return getQueryControllerService().performFieldQuery(form);
309    }
310
311    /**
312     * @see org.kuali.rice.krad.web.service.ModelAndViewService#checkForm(org.kuali.rice.krad.web.form.UifFormBase)
313     */
314    @RequestMapping(method = RequestMethod.POST, params = "methodToCall=checkForm")
315    public ModelAndView checkForm(UifFormBase form) {
316        return getModelAndViewService().checkForm(form);
317    }
318
319    /**
320     * @see org.kuali.rice.krad.web.service.ModelAndViewService#showDialog(java.lang.String, boolean,
321     * org.kuali.rice.krad.web.form.UifFormBase)
322     */
323    protected ModelAndView showDialog(String dialogId, boolean confirmation, UifFormBase form) {
324        return getModelAndViewService().showDialog(dialogId, confirmation, form);
325    }
326
327    /**
328     * @see org.kuali.rice.krad.web.service.ModelAndViewService#performRedirect(org.kuali.rice.krad.web.form.UifFormBase,
329     * java.lang.String, java.util.Properties)
330     */
331    protected ModelAndView performRedirect(UifFormBase form, String baseUrl, Properties urlParameters) {
332        return getModelAndViewService().performRedirect(form, baseUrl, urlParameters);
333    }
334
335    /**
336     * @see org.kuali.rice.krad.web.service.ModelAndViewService#performRedirect(org.kuali.rice.krad.web.form.UifFormBase,
337     * java.lang.String)
338     */
339    protected ModelAndView performRedirect(UifFormBase form, String redirectUrl) {
340        return getModelAndViewService().performRedirect(form, redirectUrl);
341    }
342
343    /**
344     * @see org.kuali.rice.krad.web.service.ModelAndViewService#getMessageView(org.kuali.rice.krad.web.form.UifFormBase,
345     * java.lang.String, java.lang.String)
346     */
347    protected ModelAndView getMessageView(UifFormBase form, String headerText, String messageText) {
348        return getModelAndViewService().getMessageView(form, headerText, messageText);
349    }
350
351    /**
352     * @see org.kuali.rice.krad.web.service.ModelAndViewService#getModelAndView(org.kuali.rice.krad.web.form.UifFormBase)
353     */
354    protected ModelAndView getModelAndView(UifFormBase form) {
355        return getModelAndViewService().getModelAndView(form);
356    }
357
358    /**
359     * @see org.kuali.rice.krad.web.service.ModelAndViewService#getModelAndView(org.kuali.rice.krad.web.form.UifFormBase,
360     * java.lang.String)
361     */
362    protected ModelAndView getModelAndView(UifFormBase form, String pageId) {
363        return getModelAndViewService().getModelAndView(form, pageId);
364    }
365
366    /**
367     * @see org.kuali.rice.krad.web.service.ModelAndViewService#getModelAndView(org.kuali.rice.krad.web.form.UifFormBase,
368     * java.util.Map<java.lang.String,java.lang.Object>)
369     */
370    protected ModelAndView getModelAndView(UifFormBase form, Map<String, Object> additionalViewAttributes) {
371        return getModelAndViewService().getModelAndView(form, additionalViewAttributes);
372    }
373
374    /**
375     * @see org.kuali.rice.krad.web.service.ModelAndViewService#getModelAndViewWithInit(org.kuali.rice.krad.web.form.UifFormBase,
376     * java.lang.String)
377     */
378    protected ModelAndView getModelAndViewWithInit(UifFormBase form, String viewId) {
379        return getModelAndViewService().getModelAndViewWithInit(form, viewId);
380    }
381
382    /**
383     * @see org.kuali.rice.krad.web.service.ModelAndViewService#getModelAndViewWithInit(org.kuali.rice.krad.web.form.UifFormBase,
384     * java.lang.String, java.lang.String)
385     */
386    protected ModelAndView getModelAndViewWithInit(UifFormBase form, String viewId, String pageId) {
387        return getModelAndViewService().getModelAndViewWithInit(form, viewId, pageId);
388    }
389
390    protected ControllerService getControllerService() {
391        return controllerService;
392    }
393
394    public void setControllerService(ControllerService controllerService) {
395        this.controllerService = controllerService;
396    }
397
398    protected NavigationControllerService getNavigationControllerService() {
399        return navigationControllerService;
400    }
401
402    public void setNavigationControllerService(NavigationControllerService navigationControllerService) {
403        this.navigationControllerService = navigationControllerService;
404    }
405
406    protected CollectionControllerService getCollectionControllerService() {
407        return collectionControllerService;
408    }
409
410    public void setCollectionControllerService(CollectionControllerService collectionControllerService) {
411        this.collectionControllerService = collectionControllerService;
412    }
413
414    protected RefreshControllerService getRefreshControllerService() {
415        return refreshControllerService;
416    }
417
418    public void setRefreshControllerService(RefreshControllerService refreshControllerService) {
419        this.refreshControllerService = refreshControllerService;
420    }
421
422    public SaveControllerService getSaveControllerService() {
423        return saveControllerService;
424    }
425
426    public void setSaveControllerService(SaveControllerService saveControllerService) {
427        this.saveControllerService = saveControllerService;
428    }
429
430    protected QueryControllerService getQueryControllerService() {
431        return queryControllerService;
432    }
433
434    public void setQueryControllerService(QueryControllerService queryControllerService) {
435        this.queryControllerService = queryControllerService;
436    }
437
438    protected FileControllerService getFileControllerService() {
439        return fileControllerService;
440    }
441
442    public void setFileControllerService(FileControllerService fileControllerService) {
443        this.fileControllerService = fileControllerService;
444    }
445
446    protected ModelAndViewService getModelAndViewService() {
447        return modelAndViewService;
448    }
449
450    public void setModelAndViewService(ModelAndViewService modelAndViewService) {
451        this.modelAndViewService = modelAndViewService;
452    }
453}