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