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 && tempDocument.isActiveIndicator()) {
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 if (olePatronDocument.isActiveIndicator()) {
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