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