View Javadoc
1   package org.kuali.ole.deliver.controller;
2   
3   import org.apache.log4j.Logger;
4   import org.kuali.ole.deliver.form.OleCirculationDeskDetailForm;
5   import org.kuali.ole.deliver.service.OleCirculationDeskDetailServiceImpl;
6   import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
7   import org.kuali.rice.kim.api.permission.PermissionService;
8   import org.kuali.rice.kim.api.services.KimApiServiceLocator;
9   import org.kuali.rice.krad.exception.DocumentAuthorizationException;
10  import org.kuali.rice.krad.util.GlobalVariables;
11  import org.kuali.rice.krad.web.controller.UifControllerBase;
12  import org.kuali.rice.krad.web.form.UifFormBase;
13  import org.springframework.stereotype.Controller;
14  import org.springframework.validation.BindingResult;
15  import org.springframework.web.bind.annotation.ModelAttribute;
16  import org.springframework.web.bind.annotation.RequestMapping;
17  import org.springframework.web.servlet.ModelAndView;
18  
19  import javax.servlet.http.HttpServletRequest;
20  import javax.servlet.http.HttpServletResponse;
21  
22  
23  /**
24   * The OleCirculationDeskDetailController is the controller class for processing all the actions that corresponds to the Circulation Desk functionality in OLE.
25   * The request mapping tag takes care of mapping the individual action to the corresponding functions.
26   */
27  @Controller
28  @RequestMapping(value = "/circulationDeskDetailController")
29  public class OleCirculationDeskDetailController extends UifControllerBase {
30  
31      private static final Logger LOG = Logger.getLogger(OleCirculationDeskDetailController.class);
32      private OleCirculationDeskDetailServiceImpl oleCirculationDeskDetailService;
33  
34      private OleCirculationDeskDetailServiceImpl getCirculationDeskDetailService() {
35          if (null == oleCirculationDeskDetailService) {
36              oleCirculationDeskDetailService = GlobalResourceLoader.getService("oleCirculationDeskDetailService");
37          }
38          return oleCirculationDeskDetailService;
39      }
40  
41      /**
42       * This method creates new OleCirculationDeskDetailForm
43       *
44       * @param request
45       * @return OleCirculationDeskDetailForm
46       */
47      @Override
48      protected OleCirculationDeskDetailForm createInitialForm(HttpServletRequest request) {
49          return new OleCirculationDeskDetailForm();
50      }
51  
52      /**
53       * This method is for setting the form to the screen
54       *
55       * @param form
56       * @param result
57       * @param request
58       * @param response
59       * @return ModelAndView
60       */
61      @Override
62      @RequestMapping(params = "methodToCall=start")
63      public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
64                                HttpServletRequest request, HttpServletResponse response) {
65          OleCirculationDeskDetailForm oleCirculationDeskDetailForm = (OleCirculationDeskDetailForm) form;
66  
67          PermissionService service = KimApiServiceLocator.getPermissionService();
68          boolean isAuthorized = service.hasPermission(GlobalVariables.getUserSession().getPrincipalId(), "OLE-PTRN", "Mapping Circulation Desk");
69          if (!isAuthorized) {
70              throw new DocumentAuthorizationException(GlobalVariables.getUserSession().getPrincipalId(), "not Authorized to map ", "CirculationDesk");
71              //oleCirculationDeskDetailForm.setErrorAuthrisedUserMessage(OLEConstants.OleCirculationDeskDetail.OLE_CIRCULATION_UNAUTHORISED_USER_MSG);
72              // return new OLEKRADAuthorizationResolver().resolveException(request,response,null,new Exception("is not authorized"));
73          }
74          oleCirculationDeskDetailForm.setMessage(null);
75          oleCirculationDeskDetailForm.setOperatorId(null);
76  
77          oleCirculationDeskDetailForm.setOleCirculationDetailsCreateList(getCirculationDeskDetailService().populateCreateList());
78          return getUIFModelAndView(oleCirculationDeskDetailForm, "OleCirculationDeskDetailViewPage");
79      }
80  
81      /**
82       * This method is for searching the circulation details
83       *
84       * @param form
85       * @param result
86       * @param request
87       * @param response
88       * @return ModelAndView
89       */
90      @RequestMapping(params = "methodToCall=search")
91      public ModelAndView search(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
92                                 HttpServletRequest request, HttpServletResponse response) {
93          OleCirculationDeskDetailForm oleCirculationDeskDetailForm = (OleCirculationDeskDetailForm) form;
94          OleCirculationDeskDetailForm deskDetailForm = getCirculationDeskDetailService().performSearch(oleCirculationDeskDetailForm);
95          deskDetailForm .setViewId("OleCirculationDeskDetailView");
96          return getUIFModelAndView(deskDetailForm, "OleCirculationDeskDetailViewPage");
97      }
98  
99      /**
100      * This method is for saving the circulation desk details for the operator
101      *
102      * @param form
103      * @param result
104      * @param request
105      * @param response
106      * @return ModelAndView
107      */
108     @RequestMapping(params = "methodToCall=save")
109     public ModelAndView save(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
110                              HttpServletRequest request, HttpServletResponse response) throws Exception {
111 
112 
113         OleCirculationDeskDetailForm oleCirculationDeskDetailForm = (OleCirculationDeskDetailForm) form;
114         OleCirculationDeskDetailForm deskDetailForm = getCirculationDeskDetailService().performSave(oleCirculationDeskDetailForm);
115         return getUIFModelAndView(deskDetailForm, "OleCirculationDeskDetailViewPage");
116     }
117 
118     /**
119      * This method is overridden for performing the search when the operator value is populated
120      *
121      * @param form
122      * @param result
123      * @param request
124      * @param response
125      * @return ModelAndView
126      * @throws Exception
127      */
128     @Override
129     @RequestMapping(params = "methodToCall=refresh")
130     public ModelAndView refresh(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
131                                 HttpServletRequest request, HttpServletResponse response) throws Exception {
132         form.setView(getViewService().getViewById("OleCirculationDeskDetailView"));
133         super.refresh(form, result, request, response);
134         return search(form, result, request, response);
135     }
136 }