View Javadoc
1   /**
2    * Copyright 2005-2014 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 org.kuali.rice.krad.web.service.impl;
17  
18  import org.kuali.rice.kim.api.identity.Person;
19  import org.kuali.rice.krad.exception.AuthorizationException;
20  import org.kuali.rice.krad.uif.view.View;
21  import org.kuali.rice.krad.util.GlobalVariables;
22  import org.kuali.rice.krad.web.form.UifFormBase;
23  import org.kuali.rice.krad.web.service.ControllerService;
24  import org.kuali.rice.krad.web.service.ModelAndViewService;
25  import org.kuali.rice.krad.web.service.NavigationControllerService;
26  import org.springframework.web.servlet.ModelAndView;
27  
28  /**
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   */
31  public class ControllerServiceImpl implements ControllerService {
32  
33      private ModelAndViewService modelAndViewService;
34      private NavigationControllerService navigationControllerService;
35  
36      /**
37       * {@inheritDoc}
38       */
39      @Override
40      public ModelAndView start(UifFormBase form) {
41          checkViewAuthorization(form);
42  
43          if (form.getView() != null) {
44              form.setApplyDefaultValues(true);
45          }
46  
47          return getModelAndViewService().getModelAndView(form);
48      }
49  
50      /**
51       * {@inheritDoc}
52       */
53      @Override
54      public void checkViewAuthorization(UifFormBase form) throws AuthorizationException {
55          // if user session or view not established we cannnot authorize the view request
56          View view = form.getView();
57          if ((GlobalVariables.getUserSession() == null) || view == null) {
58              return;
59          }
60  
61          Person user = GlobalVariables.getUserSession().getPerson();
62          boolean viewAuthorized = view.getAuthorizer().canOpenView(view, form, user);
63  
64          if (!viewAuthorized) {
65              throw new AuthorizationException(user.getPrincipalName(), "open", view.getId(),
66                      "User '" + user.getPrincipalName() + "' is not authorized to open view ID: " +
67                              view.getId(), null);
68          }
69      }
70  
71      /**
72       * Default impl does nothing but render the view.
73       *
74       * {@inheritDoc}
75       */
76      @Override
77      public ModelAndView sessionTimeout(UifFormBase form) {
78          return getModelAndViewService().getModelAndView(form);
79      }
80  
81      /**
82       * Navigates back to a previous point (depending on how the view was requested).
83       *
84       * {@inheritDoc}
85       * org.kuali.rice.krad.web.service.impl.NavigationControllerServiceImpl#back(org.kuali.rice.krad.web.form.UifFormBase,
86       * boolean)
87       */
88      @Override
89      public ModelAndView cancel(UifFormBase form) {
90          GlobalVariables.getUifFormManager().removeSessionForm(form);
91  
92          return getNavigationControllerService().returnToHistory(form, false, false, true);
93      }
94  
95      protected ModelAndViewService getModelAndViewService() {
96          return modelAndViewService;
97      }
98  
99      public void setModelAndViewService(ModelAndViewService modelAndViewService) {
100         this.modelAndViewService = modelAndViewService;
101     }
102 
103     protected NavigationControllerService getNavigationControllerService() {
104         return navigationControllerService;
105     }
106 
107     public void setNavigationControllerService(NavigationControllerService navigationControllerService) {
108         this.navigationControllerService = navigationControllerService;
109     }
110 }