1 package org.kuali.ole.krad;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.List;
6 import java.util.Map;
7
8 import javax.servlet.http.HttpServletRequest;
9 import javax.servlet.http.HttpServletResponse;
10
11 import org.apache.log4j.Logger;
12 import org.kuali.ole.OLEConstants;
13 import org.kuali.ole.deliver.bo.OleDeliverRequestBo;
14 import org.kuali.ole.deliver.bo.OlePatronDocument;
15 import org.kuali.ole.deliver.bo.OleProxyPatronDocument;
16 import org.kuali.ole.deliver.form.OlePatronDocumentInquiryForm;
17 import org.kuali.ole.deliver.processor.LoanProcessor;
18 import org.kuali.ole.deliver.service.OleDeliverRequestDocumentHelperServiceImpl;
19 import org.kuali.rice.krad.service.KRADServiceLocator;
20 import org.kuali.rice.krad.web.controller.InquiryController;
21 import org.kuali.rice.krad.web.form.InquiryForm;
22 import org.kuali.rice.krad.web.form.UifFormBase;
23 import org.springframework.stereotype.Controller;
24 import org.springframework.validation.BindingResult;
25 import org.springframework.web.bind.annotation.ModelAttribute;
26 import org.springframework.web.bind.annotation.RequestMapping;
27 import org.springframework.web.bind.annotation.RequestMethod;
28 import org.springframework.web.servlet.ModelAndView;
29
30 @Controller
31 @RequestMapping(value = "/inquiry")
32 public class OleInquiryController extends InquiryController {
33
34 private static final Logger LOG = Logger
35 .getLogger(OleInquiryController.class);
36
37 private static String DATA_OBJECT_CN_PARAM = "dataObjectClassName";
38 private static String DATA_OBJECT_CN_ATTRIBUTE = OleInquiryController.class
39 .getName() + '.' + DATA_OBJECT_CN_PARAM;
40
41 private String getDataObjectClassName(HttpServletRequest request) {
42 String rv = request.getParameter(DATA_OBJECT_CN_PARAM);
43 if (rv == null)
44
45 rv = (String) request.getSession().getAttribute(
46 DATA_OBJECT_CN_ATTRIBUTE);
47
48 else
49 request.getSession().setAttribute(DATA_OBJECT_CN_ATTRIBUTE, rv);
50
51 return rv;
52 }
53
54 @Override
55 protected InquiryForm createInitialForm(HttpServletRequest request) {
56 String dataObjectClassName = getDataObjectClassName(request);
57
58 if (OlePatronDocument.class.getName().equals(dataObjectClassName))
59 return new OlePatronDocumentInquiryForm();
60
61 return super.createInitialForm(request);
62 }
63
64 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=refreshLoanSection")
65 public ModelAndView refreshLoanSection(
66 @ModelAttribute("KualiForm") UifFormBase uifForm,
67 BindingResult result, HttpServletRequest request,
68 HttpServletResponse response) throws Exception {
69 if ((uifForm instanceof OlePatronDocumentInquiryForm)
70 && !((OlePatronDocumentInquiryForm) uifForm)
71 .isFilterProxySection()) {
72
73 OlePatronDocumentInquiryForm form = (OlePatronDocumentInquiryForm) uifForm;
74 OlePatronDocument patronDocument = (OlePatronDocument) form
75 .getDataObject();
76
77 LoanProcessor loanProcessor = new LoanProcessor();
78 OleDeliverRequestDocumentHelperServiceImpl requestService = new OleDeliverRequestDocumentHelperServiceImpl();
79 List<OleDeliverRequestBo> oleDeliverRequestBoList = patronDocument
80 .getOleDeliverRequestBos();
81 if (oleDeliverRequestBoList.size() > 0) {
82 for (int i = 0; i < oleDeliverRequestBoList.size(); i++) {
83
84
85
86
87
88
89
90
91
92
93
94
95 requestService.processItem(oleDeliverRequestBoList.get(i));
96 }
97 }
98
99 try {
100 patronDocument.setOleLoanDocuments(loanProcessor
101 .getPatronLoanedItemBySolr(patronDocument
102 .getOlePatronId()));
103 patronDocument
104 .setOleTemporaryCirculationHistoryRecords(loanProcessor
105 .getPatronTemporaryCirculationHistoryRecords(patronDocument
106 .getOlePatronId()));
107 patronDocument.setOleDeliverRequestBos(loanProcessor
108 .getPatronRequestRecords(patronDocument
109 .getOlePatronId()));
110 } catch (Exception e) {
111 LOG.error("Cannot fetch the patron loaned items.", e);
112
113 }
114
115 }
116
117 return super.refresh(uifForm, result, request, response);
118 }
119
120 @SuppressWarnings("unchecked")
121 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=refreshProxyPatron")
122 public ModelAndView refreshProxyPatron(
123 @ModelAttribute("KualiForm") UifFormBase uifForm,
124 BindingResult result, HttpServletRequest request,
125 HttpServletResponse response) throws Exception {
126
127 if ((uifForm instanceof OlePatronDocumentInquiryForm)
128 && !((OlePatronDocumentInquiryForm) uifForm)
129 .isFilterProxySection()) {
130
131 OlePatronDocumentInquiryForm form = (OlePatronDocumentInquiryForm) uifForm;
132 OlePatronDocument patronDocument = (OlePatronDocument) form
133 .getDataObject();
134
135 List<OleProxyPatronDocument> oleProxyPatronDocuments = patronDocument
136 .getOleProxyPatronDocuments();
137 List<OleProxyPatronDocument> proxyPatronDocumentList = new ArrayList<OleProxyPatronDocument>();
138 if (oleProxyPatronDocuments.size() > 0) {
139 for (OleProxyPatronDocument oleProxyPatronDocument : oleProxyPatronDocuments) {
140 Map<String, String> proxyMap = new HashMap<String, String>();
141 proxyMap.put(OLEConstants.OlePatron.PATRON_ID,
142 oleProxyPatronDocument.getProxyPatronId());
143 OlePatronDocument tempDocument = (OlePatronDocument) KRADServiceLocator
144 .getBusinessObjectService().findByPrimaryKey(
145 OlePatronDocument.class, proxyMap);
146 if (tempDocument != null) {
147 oleProxyPatronDocument
148 .setProxyPatronBarcode(tempDocument
149 .getBarcode());
150 oleProxyPatronDocument
151 .setProxyPatronFirstName(tempDocument
152 .getEntity().getNames().get(0)
153 .getFirstName());
154 oleProxyPatronDocument
155 .setProxyPatronLastName(tempDocument
156 .getEntity().getNames().get(0)
157 .getLastName());
158 proxyPatronDocumentList.add(oleProxyPatronDocument);
159 }
160 }
161 patronDocument
162 .setOleProxyPatronDocuments(proxyPatronDocumentList);
163 }
164 OlePatronDocument olePatronDocument;
165 OleProxyPatronDocument proxyPatronDocument = null;
166 List<OleProxyPatronDocument> proxyPatronDocuments = new ArrayList<OleProxyPatronDocument>();
167 Map proxyMap = new HashMap();
168 proxyMap.put(OLEConstants.OlePatron.PROXY_PATRON_ID,
169 patronDocument.getOlePatronId());
170 List<OleProxyPatronDocument> oleProxyPatronDocumentList = (List<OleProxyPatronDocument>) KRADServiceLocator
171 .getBusinessObjectService().findMatching(
172 OleProxyPatronDocument.class, proxyMap);
173 if (oleProxyPatronDocumentList.size() > 0) {
174 proxyMap.remove(OLEConstants.OlePatron.PROXY_PATRON_ID);
175 for (OleProxyPatronDocument oleProxyPatronDocument : oleProxyPatronDocumentList) {
176 proxyMap.put(OLEConstants.OlePatron.PATRON_ID,
177 oleProxyPatronDocument.getOlePatronId());
178 List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) KRADServiceLocator
179 .getBusinessObjectService().findMatching(
180 OlePatronDocument.class, proxyMap);
181 if (olePatronDocumentList.size() > 0) {
182 olePatronDocument = olePatronDocumentList.get(0);
183 proxyPatronDocument = new OleProxyPatronDocument();
184
185 proxyPatronDocument
186 .setOlePatronId(olePatronDocument
187 .getOlePatronId());
188 proxyPatronDocument
189 .setProxyForPatronFirstName(olePatronDocument
190 .getEntity().getNames().get(0)
191 .getFirstName());
192 proxyPatronDocument
193 .setProxyForPatronLastName(olePatronDocument
194 .getEntity().getNames().get(0)
195 .getLastName());
196 proxyPatronDocument
197 .setProxyPatronActivationDate(oleProxyPatronDocument
198 .getProxyPatronActivationDate());
199 proxyPatronDocument
200 .setProxyPatronExpirationDate(oleProxyPatronDocument
201 .getProxyPatronExpirationDate());
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220 proxyPatronDocuments.add(proxyPatronDocument);
221 }
222 }
223 patronDocument
224 .setOleProxyPatronDocumentList(proxyPatronDocuments);
225 }
226 }
227
228 return super.refresh(uifForm, result, request, response);
229 }
230
231 }
232