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
28
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
46
47
48
49
50 @Override
51 protected OleCirculationDeskDetailForm createInitialForm(HttpServletRequest request) {
52 return new OleCirculationDeskDetailForm();
53 }
54
55
56
57
58
59
60
61
62
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
75
76 }
77 oleCirculationDeskDetailForm.setMessage(null);
78 oleCirculationDeskDetailForm.setOperatorId(null);
79
80 oleCirculationDeskDetailForm.setOleCirculationDetailsCreateList(getCirculationDeskDetailService().populateCreateList());
81 return getUIFModelAndView(oleCirculationDeskDetailForm, "OleCirculationDeskDetailViewPage");
82 }
83
84
85
86
87
88
89
90
91
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
104
105
106
107
108
109
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
137
138
139
140
141
142
143
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 }