1 package org.kuali.ole.ncip.service.impl;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.apache.log4j.Logger;
5 import org.kuali.ole.DataCarrierService;
6 import org.kuali.ole.OLEConstants;
7 import org.kuali.ole.deliver.bo.*;
8 import org.kuali.ole.deliver.processor.LoanProcessor;
9 import org.kuali.ole.deliver.service.OleDeliverRequestDocumentHelperServiceImpl;
10 import org.kuali.ole.deliver.service.OleLoanDocumentDaoOjb;
11 import org.kuali.ole.deliver.service.impl.OleDeliverDaoJdbc;
12 import org.kuali.ole.describe.bo.InstanceEditorFormDataHandler;
13 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
14 import org.kuali.ole.docstore.common.document.Bib;
15 import org.kuali.ole.docstore.common.document.Holdings;
16 import org.kuali.ole.docstore.common.document.ItemOleml;
17 import org.kuali.ole.docstore.common.document.content.enums.DocType;
18 import org.kuali.ole.docstore.common.document.content.instance.Item;
19 import org.kuali.ole.docstore.common.document.content.instance.Location;
20 import org.kuali.ole.docstore.common.document.content.instance.OleHoldings;
21 import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
22 import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
23 import org.kuali.ole.docstore.common.search.SearchResponse;
24 import org.kuali.ole.docstore.common.search.SearchResult;
25 import org.kuali.ole.docstore.common.search.SearchResultField;
26 import org.kuali.ole.docstore.model.xstream.work.instance.oleml.WorkItemOlemlRecordProcessor;
27 import org.kuali.ole.ncip.bo.*;
28 import org.kuali.ole.ncip.converter.*;
29 import org.kuali.ole.ncip.service.OLECirculationService;
30 import org.kuali.ole.sys.context.SpringContext;
31 import org.kuali.ole.util.DocstoreUtil;
32 import org.kuali.rice.core.api.config.property.ConfigContext;
33 import org.kuali.rice.core.api.config.property.ConfigurationService;
34 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
35 import org.kuali.rice.kim.impl.identity.address.EntityAddressBo;
36 import org.kuali.rice.kim.impl.identity.email.EntityEmailBo;
37 import org.kuali.rice.kim.impl.identity.name.EntityNameBo;
38 import org.kuali.rice.kim.impl.identity.phone.EntityPhoneBo;
39 import org.kuali.rice.kim.impl.identity.principal.PrincipalBo;
40 import org.kuali.rice.krad.service.BusinessObjectService;
41 import org.kuali.rice.krad.service.KRADServiceLocator;
42 import org.kuali.rice.krad.util.GlobalVariables;
43 import org.kuali.rice.krms.api.engine.EngineResults;
44 import org.kuali.rice.krms.api.engine.ResultEvent;
45
46 import java.sql.Timestamp;
47 import java.text.SimpleDateFormat;
48 import java.util.*;
49
50
51
52
53
54
55
56
57 public class OLECirculationServiceImpl implements OLECirculationService {
58 private static final Logger LOG = Logger.getLogger(OLECirculationServiceImpl.class);
59 private BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
60 private OLECirculationHelperServiceImpl oleCirculationHelperService = new OLECirculationHelperServiceImpl();
61 private OLELookupUserConverter oleLookupUserConverter = new OLELookupUserConverter();
62 private OLECheckInItemConverter oleCheckInItemConverter = new OLECheckInItemConverter();
63 private OLECheckOutItemConverter oleCheckOutItemConverter = new OLECheckOutItemConverter();
64 private OLEHoldsConverter oleHoldsConverter = new OLEHoldsConverter();
65 private OLEItemFineConverter oleItemFineConverter = new OLEItemFineConverter();
66 private OLECheckoutItemsConverter oleCheckoutItemsConverter = new OLECheckoutItemsConverter();
67 private OleDeliverRequestDocumentHelperServiceImpl oleDeliverRequestDocumentHelperService = new OleDeliverRequestDocumentHelperServiceImpl();
68 private LoanProcessor loanProcessor = new LoanProcessor();
69 private DocstoreUtil docstoreUtil;
70 private ConfigurationService kualiConfigurationService;
71 private Map<String,OleCirculationDesk> oleCirculationDeskMap = getAvailableCirculationDesks();
72 private Map<String,OleDeliverRequestType> oleDeliverRequestTypeMap = getAvailableRequestTypes();
73
74 public ConfigurationService getKualiConfigurationService() {
75 if (kualiConfigurationService == null) {
76 kualiConfigurationService = (ConfigurationService) SpringContext.getBean("kualiConfigurationService");
77 }
78 return kualiConfigurationService;
79 }
80
81 public void setKualiConfigurationService(ConfigurationService kualiConfigurationService) {
82 this.kualiConfigurationService = kualiConfigurationService;
83 }
84
85 public DocstoreUtil getDocstoreUtil() {
86
87 if (docstoreUtil == null) {
88 docstoreUtil = SpringContext.getBean(DocstoreUtil.class);
89
90 }
91 return docstoreUtil;
92 }
93
94 private DocstoreClientLocator docstoreClientLocator;
95
96 public DocstoreClientLocator getDocstoreClientLocator() {
97
98 if (docstoreClientLocator == null) {
99 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
100
101 }
102 return docstoreClientLocator;
103 }
104
105 public BusinessObjectService getBusinessObjectService() {
106 return businessObjectService;
107 }
108
109 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
110 this.businessObjectService = businessObjectService;
111 }
112
113 public OLECirculationHelperServiceImpl getOleCirculationHelperService() {
114 return oleCirculationHelperService;
115 }
116
117 public void setOleCirculationHelperService(OLECirculationHelperServiceImpl oleCirculationHelperService) {
118 this.oleCirculationHelperService = oleCirculationHelperService;
119 }
120
121 public OLELookupUserConverter getOleLookupUserConverter() {
122 return oleLookupUserConverter;
123 }
124
125 public void setOleLookupUserConverter(OLELookupUserConverter oleLookupUserConverter) {
126 this.oleLookupUserConverter = oleLookupUserConverter;
127 }
128
129 public OLECheckInItemConverter getOleCheckInItemConverter() {
130 return oleCheckInItemConverter;
131 }
132
133 public void setOleCheckInItemConverter(OLECheckInItemConverter oleCheckInItemConverter) {
134 this.oleCheckInItemConverter = oleCheckInItemConverter;
135 }
136
137 public OLECheckOutItemConverter getOleCheckOutItemConverter() {
138 return oleCheckOutItemConverter;
139 }
140
141 public void setOleCheckOutItemConverter(OLECheckOutItemConverter oleCheckOutItemConverter) {
142 this.oleCheckOutItemConverter = oleCheckOutItemConverter;
143 }
144
145 @Override
146 public String lookupUser(String patronBarcode, String operator, String agencyId, boolean isSIP2Request) {
147 LOG.info("Inside the look up user : patron Barcode : " + patronBarcode + "operator : "+ operator + "agencyId : " + agencyId );
148 OLELookupUser lookupUser = new OLELookupUser();
149 if (!loanProcessor.hasCirculationDesk(operator)) {
150 lookupUser.setCode("001");
151 lookupUser.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_OPRTR_ID));
152 } else {
153 Map<String, String> patronMap = new HashMap<String, String>();
154 patronMap.put(OLEConstants.BARCODE, patronBarcode);
155 List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, patronMap);
156 if (olePatronDocumentList.size() > 0) {
157 OlePatronDocument olePatronDocument = olePatronDocumentList.get(0);
158 lookupUser = oleCirculationHelperService.initialiseLookupUser(olePatronDocument, agencyId);
159 if (olePatronDocument.isGeneralBlock() || oleCirculationHelperService.isPatronExpired(olePatronDocument) || !olePatronDocument.isActiveIndicator() || oleCirculationHelperService.isPatronActivated(olePatronDocument)){
160 lookupUser.setValidPatron(false);
161 }else{
162 lookupUser.setValidPatron(true);
163 }
164 try {
165 List<OleLoanDocument> oleLoanDocumentList = loanProcessor.getPatronLoanedItemBySolr(olePatronDocument.getOlePatronId());
166 List<OLECheckedOutItem> oleCheckedOutItemList = getPatronCheckedOutItemList(oleLoanDocumentList,olePatronDocument.getOleBorrowerType().getBorrowerTypeCode(),agencyId!=null?false:true);
167
168 OLECheckedOutItems oleCheckedOutItems = new OLECheckedOutItems();
169 if (oleCheckedOutItemList != null && oleCheckedOutItemList.size() > 0) {
170 oleCheckedOutItems.setCheckedOutItems(oleCheckedOutItemList);
171 }
172 lookupUser.setOleCheckedOutItems(oleCheckedOutItems);
173 } catch (Exception e) {
174 LOG.info("Exception Occurred While Retrieving the checked out items");
175 LOG.error(e);
176 }
177 try {
178 List<OLEHold> oleHoldList = getHoldsList(olePatronDocument.getOleDeliverRequestBos());
179 OLEHolds oleHolds = new OLEHolds();
180 if (oleHoldList != null && oleHoldList.size() > 0) {
181 oleHolds.setOleHoldList(oleHoldList);
182 }
183 lookupUser.setOleHolds(oleHolds);
184 } catch (Exception e) {
185 LOG.info("Exception Occurred While Retrieving the Hold items");
186 LOG.error(e);
187 }
188 try {
189 OLEItemFines oleItemFines = (OLEItemFines) oleItemFineConverter.generateCheckoutItemObject(getFine(patronBarcode, operator));
190 lookupUser.setOleItemFines(oleItemFines);
191 } catch (Exception e) {
192 LOG.info("Exception Occurred While Retrieving Fine");
193 LOG.error(e);
194 }
195 lookupUser.setCode("000");
196 lookupUser.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RTRVD_SUCCESS));
197 } else {
198 lookupUser.setCode("002");
199 lookupUser.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_PATRON_INFO));
200 }
201 }
202 String responseMessage = "";
203 if(isSIP2Request){
204 responseMessage = oleLookupUserConverter.generateLookupUserResponseXmlForSip2(lookupUser);
205 }else{
206 responseMessage = oleLookupUserConverter.generateLookupUserResponseXml(lookupUser);
207 }
208 return responseMessage;
209 }
210
211 @Override
212 public String getCheckedOutItems(String patronBarcode, String operator) throws Exception {
213 LOG.info("Inside the look up user : patron Barcode : " + patronBarcode + "operator : "+ operator );
214 LOG.info("Start CHECK out " + System.currentTimeMillis());
215 OLECheckedOutItems oleCheckedOutItems = new OLECheckedOutItems();
216 String patronType = "";
217 String checkoutItemString = "";
218 if (!loanProcessor.hasCirculationDesk(operator)) {
219 oleCheckedOutItems.setCode("001");
220 oleCheckedOutItems.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_OPRTR_ID));
221 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_OPRTR_ID));
222 } else {
223
224 Map<String, String> patronMap = new HashMap<String, String>();
225 patronMap.put(OLEConstants.BARCODE, patronBarcode);
226 List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, patronMap);
227 if (olePatronDocumentList.size() > 0) {
228 Map<String, String> patronDocMap = new HashMap<String, String>();
229 OlePatronDocument olePatronDocument = olePatronDocumentList.get(0);
230 patronType = olePatronDocument.getBorrowerType();
231 Map<String, String> borrowerTypeMap = new HashMap<String, String>();
232 borrowerTypeMap.put(OLEConstants.BORROWER_TYPE_ID, patronType);
233 List<OleBorrowerType> oleBorrowerTypeList = (List<OleBorrowerType>) businessObjectService.findMatching(OleBorrowerType.class, borrowerTypeMap);
234 if (oleBorrowerTypeList.size() > 0) {
235 patronType = oleBorrowerTypeList.get(0).getBorrowerTypeCode();
236 }
237 patronDocMap.put(OLEConstants.PATRON_ID, olePatronDocument.getOlePatronId());
238 List<OleLoanDocument> oleLoanDocumentList = loanProcessor.getPatronLoanedItemBySolr(olePatronDocument.getOlePatronId());
239 if (oleLoanDocumentList != null && oleLoanDocumentList.size() > 0) {
240 List<OLECheckedOutItem> oleCheckedOutItemList = getPatronCheckedOutItemList(oleLoanDocumentList,patronType,true);
241 oleCheckedOutItems.setCheckedOutItems(oleCheckedOutItemList);
242 oleCheckedOutItems.setCode("000");
243 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RTRVD_SUCCESS));
244 oleCheckedOutItems.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RTRVD_SUCCESS));
245 } else {
246 oleCheckedOutItems.setCode("004");
247 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_LOAN));
248 oleCheckedOutItems.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_LOAN));
249 }
250 } else {
251 oleCheckedOutItems.setCode("002");
252 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_PATRON_INFO));
253 oleCheckedOutItems.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_PATRON_INFO));
254
255 }
256 }
257 checkoutItemString = oleCheckoutItemsConverter.generateCheckOutItemXml(oleCheckedOutItems);
258 LOG.info("END CHECK out " + System.currentTimeMillis());
259 return checkoutItemString;
260 }
261
262 @Override
263 public String placeRequest(String patronBarcode, String operatorId, String itemBarcode, String requestType, String pickUpLocation, String itemLocation,String bibId,String requestLevel,java.sql.Date requestExpiryDate) {
264 String responseMessage = oleDeliverRequestDocumentHelperService.placeRequest(patronBarcode, operatorId, itemBarcode, requestType, pickUpLocation, null, itemLocation, null, null, null, null, false,bibId,requestLevel,requestExpiryDate);
265 return responseMessage;
266 }
267
268 @Override
269 public String overridePlaceRequest(String patronBarcode, String operatorId, String itemBarcode, String requestType, String pickUpLocation, String itemLocation,String bibId,String requestLevel,java.sql.Date requestExpiryDate) {
270 String responseMessage = oleDeliverRequestDocumentHelperService.overridePlaceRequest(patronBarcode, operatorId, itemBarcode, requestType, pickUpLocation, null, itemLocation, null, null, null, null, false,bibId,requestLevel,requestExpiryDate);
271 return responseMessage;
272 }
273
274 @Override
275 public String cancelRequest(String operator, String patronBarcode, String itemBarcode) {
276 LOG.info("Inside cancel Request : Operator : " + operator + "patron Barcode : " + patronBarcode + "item barcode");
277 OLECancelRequest oleCancelRequest = new OLECancelRequest();
278 OlePatronDocument olePatronDocument = null;
279 if (!loanProcessor.hasCirculationDesk(operator)) {
280 oleCancelRequest.setCode("001");
281 oleCancelRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_OPRTR_ID));
282 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_OPRTR_ID));
283 } else {
284 Map<String, String> queryMap = new HashMap<String, String>();
285 queryMap.put(OLEConstants.BARCODE, patronBarcode);
286 List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, queryMap);
287 if (olePatronDocumentList.size() > 0) {
288 olePatronDocument = olePatronDocumentList.get(0);
289 } else if (olePatronDocumentList.size() == 0) {
290 oleCancelRequest.setCode("002");
291 oleCancelRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_PATRON_INFO));
292 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_PATRON_INFO));
293 }
294 if (olePatronDocument != null) {
295 queryMap = new HashMap<String, String>();
296 queryMap.put(OLEConstants.OleDeliverRequest.BORROWER_ID, olePatronDocument.getOlePatronId());
297 queryMap.put(OLEConstants.OleDeliverRequest.ITEM_ID, itemBarcode);
298 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, queryMap);
299 if (oleDeliverRequestBoList != null && oleDeliverRequestBoList.size() > 0) {
300 OleDeliverRequestBo oleDeliverRequestBo = oleDeliverRequestBoList.get(0);
301 oleDeliverRequestBo.setOperatorCreateId(operator);
302 oleDeliverRequestDocumentHelperService.cancelDocument(oleDeliverRequestBo);
303 oleCancelRequest.setCode("007");
304 oleCancelRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.REQUEST_SUCCESSFULLEY_CANCELLED));
305 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.REQUEST_SUCCESSFULLEY_CANCELLED));
306 } else {
307 oleCancelRequest.setCode("008");
308 oleCancelRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_REQUEST_FOUND));
309 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_REQUEST_FOUND));
310 return new OLECancelRequestConverter().generateCancelRequestXml(oleCancelRequest);
311 }
312 }
313 }
314
315 return new OLECancelRequestConverter().generateCancelRequestXml(oleCancelRequest);
316 }
317
318
319 @Override
320 public String cancelRequests(String operator, String requestId) {
321 LOG.info("Inside cancel request : Operator : " + operator + "Request id : " + requestId);
322 OLECancelRequest oleCancelRequest = new OLECancelRequest();
323 if (!loanProcessor.hasCirculationDesk(operator)) {
324 oleCancelRequest.setCode("001");
325 oleCancelRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_OPRTR_ID));
326 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_OPRTR_ID));
327 } else {
328 Map<String, String> requestMap = new HashMap<String, String>();
329 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_ID, requestId);
330 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, requestMap);
331 if (oleDeliverRequestBoList != null && oleDeliverRequestBoList.size() > 0) {
332 OleDeliverRequestBo oleDeliverRequestBo = oleDeliverRequestBoList.get(0);
333 oleDeliverRequestBo.setOperatorCreateId(operator);
334 oleDeliverRequestDocumentHelperService.cancelDocument(oleDeliverRequestBo);
335 oleCancelRequest.setCode("007");
336 oleCancelRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.REQUEST_SUCCESSFULLEY_CANCELLED));
337 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.REQUEST_SUCCESSFULLEY_CANCELLED));
338 } else {
339 oleCancelRequest.setCode("008");
340 oleCancelRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_REQUEST_FOUND_REQUEST_ID));
341 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_REQUEST_FOUND_REQUEST_ID));
342 return new OLECancelRequestConverter().generateCancelRequestXml(oleCancelRequest);
343 }
344 }
345 return new OLECancelRequestConverter().generateCancelRequestXml(oleCancelRequest);
346 }
347
348 @Override
349 public String renewItem(String patronBarcode, String operator, String itemBarcode, boolean isSIP2Request) {
350 LOG.info("Inside cancel request : Operator : " + operator + "Patron Barcode : " + patronBarcode + "Item barcode : "+ itemBarcode);
351 String responseMessage = oleCirculationHelperService.renewItem(patronBarcode, operator, itemBarcode, isSIP2Request);
352 return responseMessage;
353 }
354
355 @Override
356 public String renewItemList(String patronBarcode, String operator, String itemBarcode, boolean isSIP2Request) {
357 LOG.info("Inside cancel request : Operator : " + operator + "Patron Barcode : " + patronBarcode + "Item barcode : "+ itemBarcode);
358 String responseMessage = oleCirculationHelperService.renewItemList(patronBarcode, operator, itemBarcode,isSIP2Request);
359 return responseMessage;
360 }
361
362 @Override
363 public String acceptItem(String patronBarcode, String operator, String itemBarcode, String callNumber, String title, String author, String itemType, String itemLocation, String dateExpires, String requestType, String pickUpLocation) {
364 OLEAcceptItem oleAcceptItem = new OLEAcceptItem();
365 String itemIdentifier = null;
366 if (!loanProcessor.hasCirculationDesk(operator)) {
367 oleAcceptItem.setCode("026");
368 oleAcceptItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.CIRCULATION_DESK_NOT_MAPPED_OPERATOR));
369 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.CIRCULATION_DESK_NOT_MAPPED_OPERATOR));
370 return new OLEAcceptItemConverter().generateAcceptItemXml(oleAcceptItem);
371 } if(!vaildPatron(patronBarcode)){
372 oleAcceptItem.setCode("002");
373 oleAcceptItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_PATRON_INFO));
374 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_PATRON_INFO));
375 return new OLEAcceptItemConverter().generateAcceptItemXml(oleAcceptItem);
376 }
377
378 if (requestType == null || (requestType != null && requestType.trim().isEmpty())) {
379 oleAcceptItem.setCode("012");
380 oleAcceptItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_RQST_TYP));
381 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_RQST_TYP));
382 return new OLEAcceptItemConverter().generateAcceptItemXml(oleAcceptItem);
383 }
384 if (requestType != null && !requestType.trim().isEmpty()) {
385 Map<String, String> requestTypeMap = new HashMap<String, String>();
386 requestTypeMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_CD, requestType);
387 List<OleDeliverRequestType> oleDeliverRequestTypeList = (List<OleDeliverRequestType>) getBusinessObjectService().findMatching(OleDeliverRequestType.class, requestTypeMap);
388 if (oleDeliverRequestTypeList != null && (oleDeliverRequestTypeList.size() == 0)) {
389 oleAcceptItem.setCode("012");
390 oleAcceptItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_RQST_TYP));
391 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_RQST_TYP));
392 return new OLEAcceptItemConverter().generateAcceptItemXml(oleAcceptItem);
393 }
394 }
395 if (pickUpLocation != null) {
396 Map<String, String> circulationDeskMap = new HashMap<String, String>();
397 circulationDeskMap.put(OLEConstants.OleCirculationDesk.OLE_CIRCULATION_DESK_CD, pickUpLocation);
398 List<OleCirculationDesk> oleCirculationDeskList = (List<OleCirculationDesk>) getBusinessObjectService().findMatching(OleCirculationDesk.class, circulationDeskMap);
399 if (oleCirculationDeskList != null && oleCirculationDeskList.size() == 0) {
400 oleAcceptItem.setCode("013");
401 oleAcceptItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_PK_UP_LOCN));
402 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_PK_UP_LOCN));
403 return new OLEAcceptItemConverter().generateAcceptItemXml(oleAcceptItem);
404 }
405 }
406 try {
407 itemIdentifier = oleCirculationHelperService.acceptItem(patronBarcode, operator, itemBarcode, callNumber, title, author, itemType, itemLocation, dateExpires, requestType, pickUpLocation);
408 if (null == itemIdentifier) {
409 oleAcceptItem.setCode("031");
410 oleAcceptItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_EXIST));
411 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_EXIST));
412 return new OLEAcceptItemConverter().generateAcceptItemXml(oleAcceptItem);
413 }
414 if ("".equals(itemIdentifier)) {
415 itemIdentifier = null;
416 }
417 String responseMessage = oleDeliverRequestDocumentHelperService.placeRequest(patronBarcode, operator, itemBarcode, requestType, pickUpLocation, itemIdentifier, itemLocation, itemType, title, author, callNumber, true,null,null,null);
418 responseMessage = responseMessage.replaceAll("<br/>", "");
419 responseMessage = responseMessage.replaceAll("<br/>", "");
420 OLEPlaceRequestConverter olePlaceRequestConverter = new OLEPlaceRequestConverter();
421 OLEPlaceRequest olePlaceRequest = (OLEPlaceRequest) olePlaceRequestConverter.generatePlaceRequestObject(responseMessage);
422 if(!olePlaceRequest.getMessage().contains(OLEConstants.RQST_SUCCESS)){
423 org.kuali.ole.docstore.common.document.Item item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(itemIdentifier);
424 String bibId = item.getHolding().getBib().getId();
425
426 getDocstoreClientLocator().getDocstoreClient().deleteBib(bibId);
427 }
428 oleAcceptItem.setMessage(olePlaceRequest.getMessage());
429 oleAcceptItem.setCode(olePlaceRequest.getCode());
430 return new OLEAcceptItemConverter().generateAcceptItemXml(oleAcceptItem);
431
432 } catch (Exception e) {
433 oleAcceptItem.setCode("033");
434 oleAcceptItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_NOT_CREATED));
435 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_NOT_CREATED));
436 return new OLEAcceptItemConverter().generateAcceptItemXml(oleAcceptItem);
437 }
438 }
439
440 @Override
441 public String checkInItem(String patronBarcode, String operator, String itemBarcode, String deleteIndicator, boolean isSIP2Request) {
442 LOG.info( " Inside check in item : Patron Barcode :" +patronBarcode + "operator : "+ operator + "item barcode : "+ itemBarcode);
443 if (!loanProcessor.hasCirculationDesk(operator)) {
444 OLECheckInItem oleCheckInItem = new OLECheckInItem();
445 oleCheckInItem.setCode("026");
446 oleCheckInItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.CIRCULATION_DESK_NOT_MAPPED_OPERATOR));
447 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.CIRCULATION_DESK_NOT_MAPPED_OPERATOR));
448 return oleCheckInItemConverter.generateCheckInItemXml(oleCheckInItem);
449 }
450 String responseMessage = oleCirculationHelperService.checkInItem(patronBarcode, operator, itemBarcode, deleteIndicator,isSIP2Request);
451 return responseMessage;
452 }
453
454 @Override
455 public String checkOutItem(String patronBarcode, String operator, String itemBarcode, boolean isSIP2Request) {
456 LOG.info( " Inside checkOutItem : Patron Barcode :" +patronBarcode + "operator : "+ operator + "item barcode : "+ itemBarcode);
457 String responseMessage = oleCirculationHelperService.checkOutItem(patronBarcode, operator, itemBarcode,isSIP2Request);
458 return responseMessage;
459 }
460
461
462
463
464
465 public List<OLECheckedOutItem> getOleCheckOutItemList(List<OleLoanDocument> oleLoanDocumentList, String patronType) throws Exception {
466 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OleDeliverRequest.DATE_FORMAT);
467 List<OLECheckedOutItem> checkedOutItemList = new ArrayList<OLECheckedOutItem>();
468 HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
469 for (OleLoanDocument oleLoanDocument : oleLoanDocumentList) {
470 Map<String, Object> detailMap = oleDeliverRequestDocumentHelperService.retrieveBIbItemHoldingData(oleLoanDocument.getItemUuid());
471 Bib bib = (Bib) detailMap.get(OLEConstants.BIB);
472 Item item = (Item) detailMap.get(OLEConstants.ITEM);
473 OleHoldings oleHoldings = (OleHoldings) detailMap.get(OLEConstants.HOLDING);
474 org.kuali.ole.docstore.common.document.Item item1 = (org.kuali.ole.docstore.common.document.Item) detailMap.get("documentItem");
475 String itemLocation = null;
476 if (item1.getLocation() == null || (item1.getLocation() != null && item1.getLocation().trim().isEmpty())) {
477 itemLocation = getDocstoreUtil().getLocation(oleHoldings.getLocation(), new StringBuffer(""));
478 } else {
479 itemLocation = item1.getLocation();
480 }
481 Map<String, String> locationMap = oleDeliverRequestDocumentHelperService.getLocationMap(itemLocation);
482 oleLoanDocument.setItemInstitution(locationMap.get(OLEConstants.ITEM_INSTITUTION));
483 oleLoanDocument.setItemCampus(locationMap.get(OLEConstants.ITEM_CAMPUS));
484 oleLoanDocument.setItemCollection(locationMap.get(OLEConstants.ITEM_COLLECTION));
485 oleLoanDocument.setItemLibrary(locationMap.get(OLEConstants.ITEM_LIBRARY));
486 oleLoanDocument.setItemLocation(locationMap.get(OLEConstants.ITEM_SHELVING));
487 oleLoanDocument.setInstanceUuid(oleHoldings.getHoldingsIdentifier());
488 oleLoanDocument.setBibUuid(bib.getId());
489 oleLoanDocument.setAuthor(bib.getAuthor());
490 oleLoanDocument.setTitle(bib.getTitle());
491 OLECheckedOutItem oleCheckedOutItem = new OLECheckedOutItem();
492 if (item != null) {
493 oleLoanDocument.setItemUuid(item.getItemIdentifier());
494 if (item.getItemType() != null) {
495 oleCheckedOutItem.setItemType(item.getItemType().getCodeValue());
496 }
497 if (item.getCallNumber() != null) {
498 oleCheckedOutItem.setCallNumber(item.getCallNumber().getNumber());
499 } else if (oleHoldings != null && oleHoldings.getCallNumber() != null) {
500 oleCheckedOutItem.setCallNumber(oleHoldings.getCallNumber().getNumber());
501 }
502 if (item.getCopyNumber() != null && !item.getCopyNumber().isEmpty()) {
503 oleCheckedOutItem.setCopyNumber(item.getCopyNumber());
504 } else if (oleHoldings != null && oleHoldings.getCopyNumber() != null && !oleHoldings.getCopyNumber().isEmpty()) {
505 oleCheckedOutItem.setCopyNumber(oleHoldings.getCopyNumber());
506 }
507 if(item.getEnumeration()!=null){
508 oleCheckedOutItem.setVolumeNumber(item.getEnumeration());
509 }else{
510 oleCheckedOutItem.setVolumeNumber(item.getVolumeNumber());
511 }
512 }
513 oleCheckedOutItem.setCatalogueId(bib.getId());
514 oleCheckedOutItem.setItemId(oleLoanDocument.getItemId());
515 oleCheckedOutItem.setLoanDate(new Timestamp(oleLoanDocument.getCreateDate().getTime()).toString());
516 if (oleLoanDocument.getLoanDueDate() != null) {
517 oleCheckedOutItem.setDueDate(oleLoanDocument.getLoanDueDate().toString());
518 if ((fmt.format(oleLoanDocument.getLoanDueDate())).compareTo(fmt.format(new Date(System.currentTimeMillis()))) > 0) {
519 oleCheckedOutItem.setOverDue(false);
520 }
521 else{
522 oleCheckedOutItem.setOverDue(true);
523 }
524 } else {
525 oleCheckedOutItem.setDueDate((new java.sql.Timestamp(new Date(2025, 1, 1).getTime()).toString()));
526 }
527
528 if (oleLoanDocument.getRenewalLoanDueDate() != null){
529 oleCheckedOutItem.setDateRenewed(oleLoanDocument.getRenewalLoanDueDate().toString());
530 }
531 else{
532 oleCheckedOutItem.setDateRenewed("");
533 }
534
535 int renewalDaysFromPolicy = getRenewalDays(oleCheckedOutItem.getItemType(), oleLoanDocument, patronType, oleLoanDocument.getNumberOfRenewals());
536
537 oleCheckedOutItem.setNumberOfRenewals(String.valueOf(renewalDaysFromPolicy));
538 oleCheckedOutItem.setTitle(oleLoanDocument.getTitle());
539 oleCheckedOutItem.setAuthor(oleLoanDocument.getAuthor());
540 oleCheckedOutItem.setAcquiredFine("");
541 oleCheckedOutItem.setDateRecalled("");
542 if (oleLoanDocument.getNoOfOverdueNoticesSentForBorrower() != null) {
543 oleCheckedOutItem.setNumberOfOverdueSent(oleLoanDocument.getNoOfOverdueNoticesSentForBorrower());
544 } else {
545 oleCheckedOutItem.setNumberOfOverdueSent("1");
546 }
547
548 checkedOutItemList.add(oleCheckedOutItem);
549 }
550
551 return checkedOutItemList;
552 }
553
554 @Override
555 public String getFine(String patronBarcode, String operator) throws Exception {
556 LOG.info("Inside Get Fine : Patron Barcode : " + patronBarcode + "Operator : " + operator);
557 OLEItemFineConverter oleItemFineConverter = new OLEItemFineConverter();
558 OLEItemFines oleItemFines = new OLEItemFines();
559 String itemFineString = "";
560 if (!loanProcessor.hasCirculationDesk(operator)) {
561 oleItemFines.setCode("001");
562 oleItemFines.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_OPRTR_ID));
563 } else {
564 Map<String, String> patronMap = new HashMap<String, String>();
565 patronMap.put(OLEConstants.BARCODE, patronBarcode);
566 List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, patronMap);
567 if (olePatronDocumentList.size() > 0) {
568 Map<String, String> patronDocMap = new HashMap<String, String>();
569 OlePatronDocument olePatronDocument = olePatronDocumentList.get(0);
570 patronDocMap.put(OLEConstants.PATRON_ID, olePatronDocument.getOlePatronId());
571 List<PatronBillPayment> patronBillPaymentList = (List<PatronBillPayment>) businessObjectService.findMatching(PatronBillPayment.class, patronDocMap);
572 if (patronBillPaymentList.size() > 0) {
573 List<OLEItemFine> oleItemFineList = getFineItemList(patronBillPaymentList);
574 oleItemFines.setOleItemFineList(oleItemFineList);
575 oleItemFines.setCode("000");
576 oleItemFines.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RTRVD_SUCCESS));
577 } else {
578
579 oleItemFines.setCode("005");
580 oleItemFines.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_FINE));
581 itemFineString = itemFineString = oleItemFineConverter.generateCheckOutItemXml(oleItemFines);
582 }
583
584 } else {
585 oleItemFines.setCode("002");
586 oleItemFines.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_PATRON_INFO));
587 }
588 }
589 return oleItemFineConverter.generateCheckOutItemXml(oleItemFines);
590 }
591
592 public List<OLEItemFine> getFineItemList(List<PatronBillPayment> olePatronBillDocumentList) throws Exception {
593 List<OLEItemFine> oleItemFineList = new ArrayList<OLEItemFine>();
594
595 org.kuali.ole.docstore.common.document.Item item = null;
596 for (PatronBillPayment olePatronBillPayment : olePatronBillDocumentList) {
597
598 List<FeeType> feeTypeList = olePatronBillPayment.getFeeType();
599 for (FeeType feeType : feeTypeList) {
600 OLEItemFine oleItemFine = new OLEItemFine();
601 if (feeType.getItemUuid() != null) {
602 item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(feeType.getItemUuid());
603 oleItemFine.setCatalogueId(item.getHolding().getBib().getId());
604 oleItemFine.setTitle(item.getHolding().getBib().getTitle());
605 oleItemFine.setAuthor(item.getHolding().getBib().getAuthor());
606 }
607 oleItemFine.setAmount((feeType.getFeeAmount() != null ? feeType.getFeeAmount().bigDecimalValue() : OLEConstants.BIGDECIMAL_DEF_VALUE));
608 oleItemFine.setBalance((feeType.getBalFeeAmount() != null ? feeType.getBalFeeAmount().bigDecimalValue() : OLEConstants.BIGDECIMAL_DEF_VALUE));
609 oleItemFine.setBillDate(feeType.getBillDate().toString());
610 int noOfPayment = feeType.getItemLevelBillPaymentList().size();
611 oleItemFine.setNoOfPayments(new Integer(noOfPayment).toString());
612 if (feeType.getOleFeeType() != null) {
613 oleItemFine.setReason(feeType.getOleFeeType().getFeeTypeName());
614 oleItemFine.setFeeType(feeType.getOleFeeType().getFeeTypeCode());
615 } else {
616 oleItemFine.setReason(feeType.getFeeType());
617 oleItemFine.setFeeType(feeType.getFeeType());
618 }
619 oleItemFine.setDateCharged(feeType.getBillDate().toString());
620 oleItemFineList.add(oleItemFine);
621 }
622 }
623
624 return oleItemFineList;
625 }
626
627 @Override
628 public String getHolds(String patronBarcode, String operator) throws Exception {
629 LOG.info("Inside Get Holds . Patron Barcode : " +patronBarcode + "Operator : "+ operator );
630 OLEHoldsConverter oleHoldConverter = new OLEHoldsConverter();
631 OLEHolds oleHolds = new OLEHolds();
632 String itemFineString = "";
633 if (!loanProcessor.hasCirculationDesk(operator)) {
634 oleHolds.setCode("001");
635 oleHolds.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_OPRTR_ID));
636 } else {
637 Map<String, String> patronMap = new HashMap<String, String>();
638 patronMap.put(OLEConstants.BARCODE, patronBarcode);
639 List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, patronMap);
640 if (olePatronDocumentList.size() > 0) {
641 Map<String, String> patronDocMap = new HashMap<String, String>();
642 OlePatronDocument olePatronDocument = olePatronDocumentList.get(0);
643 patronDocMap.put(OLEConstants.OleDeliverRequest.BORROWER_ID, olePatronDocument.getOlePatronId());
644 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, patronDocMap);
645 if (oleDeliverRequestBoList.size() > 0) {
646 List<OLEHold> oleHoldsList = getHoldsList(oleDeliverRequestBoList);
647 oleHolds.setOleHoldList(oleHoldsList);
648 oleHolds.setCode("000");
649 oleHolds.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RTRVD_SUCCESS));
650 } else {
651 oleHolds.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_HOLD));
652 oleHolds.setCode("006");
653 }
654 } else {
655 oleHolds.setCode("002");
656 oleHolds.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_PATRON_INFO));
657 }
658 }
659 return oleHoldConverter.generateHoldsmXml(oleHolds);
660 }
661
662 public List<OLEHold> getHoldsList(List<OleDeliverRequestBo> oleDeliverRequestBoList) throws Exception {
663
664
665 String copyNumber="";
666
667 String[] availableDates;
668 List<OLEHold> oleHoldList = new ArrayList<OLEHold>();
669 for (OleDeliverRequestBo oleDeliverRequestBo : oleDeliverRequestBoList) {
670 OLEHold oleHold = new OLEHold();
671 oleHold.setItemId(oleDeliverRequestBo.getItemId());
672 Map<String, Object> detailMap = oleDeliverRequestDocumentHelperService.retrieveBIbItemHoldingData(oleDeliverRequestBo.getItemUuid());
673 Bib bib = (Bib) detailMap.get(OLEConstants.BIB);
674 Item item = (Item) detailMap.get(OLEConstants.ITEM);
675 OleHoldings oleHoldings = (OleHoldings) detailMap.get(OLEConstants.HOLDING);
676 org.kuali.ole.docstore.common.document.Item item1 = (org.kuali.ole.docstore.common.document.Item) detailMap.get("documentItem");
677 oleHold.setCatalogueId(bib.getId());
678 oleHold.setRequestId(oleDeliverRequestBo.getRequestId());
679 if (item.getItemStatus() != null) {
680 oleHold.setAvailableStatus(item.getItemStatus().getCodeValue());
681 }
682
683
684
685
686
687
688 if(item.getCopyNumber()!=null && !item.getCopyNumber().isEmpty()){
689 copyNumber=item.getCopyNumber();
690 }
691 else{
692 copyNumber=oleHoldings.getCopyNumber()!=null? oleHoldings.getCopyNumber():"";
693 }
694 oleHold.setTitle(bib.getTitle());
695 oleHold.setAuthor(bib.getAuthor());
696 oleHold.setVolumeNumber(item.getEnumeration()!=null ? item.getEnumeration():"");
697 oleHold.setCallNumber(loanProcessor.getItemCallNumber(item.getCallNumber(),oleHoldings.getCallNumber()));
698 oleHold.setCopyNumber(copyNumber);
699 if (item.getItemType() != null)
700 oleHold.setItemType(item.getItemType().getCodeValue());
701 if (oleDeliverRequestBo.getRequestTypeId() != null && !oleDeliverRequestBo.getRequestTypeId().isEmpty()) {
702 if (oleDeliverRequestBo.getRequestTypeId().equals("1") || oleDeliverRequestBo.getRequestTypeId().equals("2")) {
703 oleHold.setRecallStatus(OLEConstants.YES);
704 } else {
705 oleHold.setRecallStatus(OLEConstants.NO);
706 }
707 }
708 if (oleDeliverRequestBo.getRequestExpiryDate() != null) {
709 oleHold.setExpiryDate(oleDeliverRequestBo.getRequestExpiryDate().toString());
710 }
711 if (oleDeliverRequestBo.getCreateDate() != null) {
712 oleHold.setCreateDate(oleDeliverRequestBo.getCreateDate().toString());
713 }
714 if (oleDeliverRequestBo.getBorrowerQueuePosition() != null) {
715 oleHold.setPriority(oleDeliverRequestBo.getBorrowerQueuePosition().toString());
716 }
717 oleHold.setPickupLocation(oleDeliverRequestBo.getPickUpLocationId());
718 if (oleDeliverRequestBo.getRecallDueDate() != null) {
719 oleHold.setDateRecalled(oleDeliverRequestBo.getRecallDueDate().toString());
720 }
721 if (oleDeliverRequestBo.getRecallDueDate() != null) {
722 oleHold.setDateRecalled(oleDeliverRequestBo.getRecallDueDate().toString());
723 }
724 if (oleDeliverRequestTypeMap!=null && oleDeliverRequestTypeMap.size() > 0) {
725 if(oleDeliverRequestTypeMap.get(oleDeliverRequestBo.getRequestTypeId())!=null){
726 oleHold.setRequestType(oleDeliverRequestTypeMap.get(oleDeliverRequestBo.getRequestTypeId()).getRequestTypeCode());
727 }
728 }
729 Map<String, String> loanMap = new HashMap<String, String>();
730 loanMap.put(OLEConstants.OleDeliverRequest.ITEM_ID, oleDeliverRequestBo.getItemId());
731 List<OleLoanDocument> oleLoanDocumentList = (List<OleLoanDocument>) KRADServiceLocator.getBusinessObjectService().findMatching(OleLoanDocument.class, loanMap);
732 if (oleLoanDocumentList.size() > 0) {
733 if (oleLoanDocumentList.get(0).getLoanDueDate() != null) {
734 availableDates = oleLoanDocumentList.get(0).getLoanDueDate().toString().split(" ");
735 if (availableDates != null && availableDates.length > 0) {
736 oleHold.setAvailableDate(availableDates[0]);
737 } else {
738 oleHold.setAvailableDate(oleLoanDocumentList.get(0).getLoanDueDate().toString());
739 }
740 if (oleDeliverRequestBo.getPickUpLocationId() != null) {
741 if (oleCirculationDeskMap.size()>0 && oleCirculationDeskMap.get(oleDeliverRequestBo.getPickUpLocationId())!=null) {
742 oleHold.setDateAvailableExpires(addDate(new java.sql.Date(oleLoanDocumentList.get(0).getLoanDueDate().getTime()), Integer.parseInt(oleCirculationDeskMap.get(oleDeliverRequestBo.getPickUpLocationId()).getOnHoldDays())).toString());
743 }
744 }
745 } else {
746 oleHold.setAvailableDate(OLEConstants.INDEFINITE);
747 oleHold.setDateAvailableExpires(OLEConstants.INDEFINITE);
748 }
749 }
750 if (oleDeliverRequestBo.getRequestTypeId().equals("2") || oleDeliverRequestBo.getRequestTypeId().equals("4") || oleDeliverRequestBo.getRequestTypeId().equals("6")) {
751 oleHold.setReserve(true);
752 } else {
753 oleHold.setReserve(false);
754 }
755
756 oleHoldList.add(oleHold);
757 }
758
759 return oleHoldList;
760 }
761
762 private java.sql.Date addDate(java.sql.Date in, int daysToAdd) {
763 if (in == null) {
764 return null;
765 }
766 GregorianCalendar cal = new GregorianCalendar();
767 cal.setTime(in);
768 cal.add(Calendar.DAY_OF_MONTH, daysToAdd);
769 return new java.sql.Date(cal.getTime().getTime());
770 }
771
772 private int getRenewalDays(String itemType, OleLoanDocument oleLoanDocument, String borrowerType, String numberOfRenewals) {
773 String agendaName = OLEConstants.RENEWAL_AGENDA_NM;
774 int renewalCount = 1;
775 boolean renewalExceeds = false;
776 Map<String,String> requestMap = new HashMap<String,String>();
777 requestMap.put("itemUuid",oleLoanDocument.getItemUuid());
778 List<OleDeliverRequestBo> oleDeliverRequestBos = (List<OleDeliverRequestBo>)businessObjectService.findMatching(OleDeliverRequestBo.class,requestMap);
779 if(oleDeliverRequestBos != null && oleDeliverRequestBos.size() > 0){
780 renewalExceeds =true;
781 } else{
782 HashMap<String, Object> termValues = new HashMap<String, Object>();
783 DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
784 String patronId = oleLoanDocument.getPatronId()!=null ? oleLoanDocument.getPatronId() : "";
785 String itemId = oleLoanDocument.getItemId()!=null ? oleLoanDocument.getItemId() : "";
786 dataCarrierService.removeData(patronId+itemId);
787 termValues.put(OLEConstants.BORROWER_TYPE, borrowerType);
788 termValues.put(OLEConstants.ITEM_TYPE, itemType);
789 termValues.put(OLEConstants.ITEM_STATUS, oleLoanDocument.getItemLoanStatus());
790 termValues.put(OLEConstants.ITEM_SHELVING, oleLoanDocument.getItemLocation());
791 termValues.put(OLEConstants.ITEM_COLLECTION, oleLoanDocument.getItemCollection());
792 termValues.put(OLEConstants.ITEM_LIBRARY, oleLoanDocument.getItemLibrary());
793 termValues.put(OLEConstants.ITEM_CAMPUS, oleLoanDocument.getItemCampus());
794 termValues.put(OLEConstants.ITEM_INSTITUTION, oleLoanDocument.getItemInstitution());
795 termValues.put(OLEConstants.NUM_RENEWALS, oleLoanDocument.getNumberOfRenewals());
796 termValues.put(OLEConstants.PATRON_ID_POLICY, patronId);
797 termValues.put(OLEConstants.ITEM_ID_POLICY, itemId);
798 try {
799 EngineResults engineResults = loanProcessor.getEngineResults(agendaName, termValues);
800 dataCarrierService.removeData(patronId+itemId);
801 List<ResultEvent> allResults = engineResults.getAllResults();
802 for (Iterator<ResultEvent> resultEventIterator = allResults.iterator(); resultEventIterator.hasNext(); ) {
803 ResultEvent resultEvent = resultEventIterator.next();
804 if (resultEvent.getType().equals(OLEConstants.RULE_EVALUATED) && resultEvent.getSource().equals(OLEConstants.RENEWAL_LIMIT)) {
805 renewalExceeds = true;
806 }
807 }
808 if (renewalExceeds) {
809 renewalCount = 0;
810 } else {
811 renewalCount = 1;
812 }
813 } catch (Exception e) {
814
815 }
816
817 }
818 return renewalCount;
819 }
820
821
822
823
824
825
826 public String getOperatorId(String operatorName) {
827 Map<String, String> principalMap = new HashMap<String, String>();
828 String principalId = null;
829 principalMap.put("principalName", operatorName);
830 List<PrincipalBo> principalBos = (List<PrincipalBo>) businessObjectService.findMatching(PrincipalBo.class, principalMap);
831 if (principalBos != null && principalBos.size() > 0) {
832 principalId = principalBos.get(0).getPrincipalId();
833 }
834 return principalId;
835 }
836
837
838
839
840
841
842 public boolean vaildPatron(String patronBarcode){
843 boolean valid= false;
844 Map<String,String> patronMap = new HashMap<String,String>();
845 patronMap.put("barcode",patronBarcode);
846 List<OlePatronDocument> olePatronDocuments =(List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class,patronMap);
847 if(olePatronDocuments!=null && olePatronDocuments.size()>0){
848 valid=true;
849 }
850 return valid;
851 }
852
853
854
855
856
857
858 public List<OLECheckedOutItem> getPatronCheckedOutItemList(List<OleLoanDocument> oleLoanDocumentList,String patronType,boolean renewableNeeded){
859 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OleDeliverRequest.DATE_FORMAT);
860 String renewParameter = loanProcessor.getParameter(OLEConstants.RENEW_INFO_INDICATOR);
861 boolean renewInfoNeeded = true;
862 if(renewParameter!=null && !renewParameter.isEmpty()){
863 if(renewParameter.equalsIgnoreCase("N")){
864 renewInfoNeeded = false;
865 }
866 }
867 List<OLECheckedOutItem> oleCheckedOutItems = new ArrayList<OLECheckedOutItem>();
868 if(oleLoanDocumentList.size()>0){
869 OLECheckedOutItem oleCheckedOutItem = null;
870 for(OleLoanDocument oleLoanDocument : oleLoanDocumentList){
871 oleCheckedOutItem = new OLECheckedOutItem();
872 oleCheckedOutItem.setCopyNumber(oleLoanDocument.getItemCopyNumber());
873 oleCheckedOutItem.setVolumeNumber(oleLoanDocument.getEnumeration());
874 oleCheckedOutItem.setAcquiredFine("");
875 oleCheckedOutItem.setDateRecalled("");
876 oleCheckedOutItem.setTitle(oleLoanDocument.getTitle());
877 oleCheckedOutItem.setAuthor(oleLoanDocument.getAuthor());
878 oleCheckedOutItem.setCallNumber(oleLoanDocument.getItemCallNumber());
879 oleCheckedOutItem.setCatalogueId(oleLoanDocument.getBibUuid());
880 if (oleLoanDocument.getLoanDueDate() != null) {
881 oleCheckedOutItem.setDueDate(oleLoanDocument.getLoanDueDate().toString());
882 if ((fmt.format(oleLoanDocument.getLoanDueDate())).compareTo(fmt.format(new Date(System.currentTimeMillis()))) > 0) {
883 oleCheckedOutItem.setOverDue(false);
884 }
885 else{
886 oleCheckedOutItem.setOverDue(true);
887 }
888 } else {
889 oleCheckedOutItem.setDueDate((new java.sql.Timestamp(new Date(2025, 1, 1).getTime()).toString()));
890 }
891 if (oleLoanDocument.getRenewalLoanDueDate() != null){
892 oleCheckedOutItem.setDateRenewed(oleLoanDocument.getRenewalLoanDueDate().toString());
893 }
894 else{
895 oleCheckedOutItem.setDateRenewed("");
896 }
897 oleCheckedOutItem.setItemType(oleLoanDocument.getItemType());
898 if (null!= oleLoanDocument.getCreateDate()) {
899 oleCheckedOutItem.setLoanDate(new Timestamp(oleLoanDocument.getCreateDate().getTime()).toString());
900 }
901 oleCheckedOutItem.setItemId(oleLoanDocument.getItemId());
902 if (oleLoanDocument.getNoOfOverdueNoticesSentForBorrower() != null) {
903 oleCheckedOutItem.setNumberOfOverdueSent(oleLoanDocument.getNoOfOverdueNoticesSentForBorrower());
904 } else {
905 oleCheckedOutItem.setNumberOfOverdueSent("1");
906 }
907 Map<String, String> locationMap = oleDeliverRequestDocumentHelperService.getLocationMap(oleLoanDocument.getItemFullLocation());
908 oleLoanDocument.setItemInstitution(locationMap.get(OLEConstants.ITEM_INSTITUTION));
909 oleLoanDocument.setItemCampus(locationMap.get(OLEConstants.ITEM_CAMPUS));
910 oleLoanDocument.setItemCollection(locationMap.get(OLEConstants.ITEM_COLLECTION));
911 oleLoanDocument.setItemLibrary(locationMap.get(OLEConstants.ITEM_LIBRARY));
912 oleLoanDocument.setItemLocation(locationMap.get(OLEConstants.ITEM_SHELVING));
913 oleLoanDocument.setBorrowerTypeCode(patronType);
914 if(renewableNeeded && renewInfoNeeded){
915
916 int renewalDaysFromPolicy = getRenewalDays(oleCheckedOutItem.getItemType(), oleLoanDocument, patronType, oleLoanDocument.getNumberOfRenewals());
917 oleCheckedOutItem.setNumberOfRenewals(String.valueOf(renewalDaysFromPolicy));
918 }
919 oleCheckedOutItems.add(oleCheckedOutItem);
920 }
921 }
922 return oleCheckedOutItems;
923 }
924
925 public Map<String,OleCirculationDesk> getAvailableCirculationDesks(){
926 Map<String,OleCirculationDesk> circulationDeskMap = new HashMap<String,OleCirculationDesk>();
927 List<OleCirculationDesk> oleCirculationDeskList = (List<OleCirculationDesk>)getBusinessObjectService().findAll(OleCirculationDesk.class);
928 if(oleCirculationDeskList!=null && oleCirculationDeskList.size()>0){
929 for(OleCirculationDesk oleCirculationDesk : oleCirculationDeskList){
930 circulationDeskMap.put(oleCirculationDesk.getCirculationDeskId(),oleCirculationDesk);
931 }
932 }
933 return circulationDeskMap;
934 }
935
936 public Map<String,OleDeliverRequestType> getAvailableRequestTypes(){
937 Map<String,OleDeliverRequestType> requestTypeMap = new HashMap<String,OleDeliverRequestType>();
938 List<OleDeliverRequestType> oleDeliverRequestTypeList = (List<OleDeliverRequestType>)getBusinessObjectService().findAll(OleDeliverRequestType.class);
939 if(oleDeliverRequestTypeList!=null && oleDeliverRequestTypeList.size()>0){
940 for(OleDeliverRequestType oleDeliverRequestType : oleDeliverRequestTypeList){
941 requestTypeMap.put(oleDeliverRequestType.getRequestTypeId(),oleDeliverRequestType);
942 }
943 }
944 return requestTypeMap;
945 }
946
947
948
949
950
951
952
953
954
955 @Override
956 public String lookupUserForNCIP(String patronBarcode, String operator, String agencyId) {
957 Long startTime =System.currentTimeMillis();
958 LOG.info("Inside the look up user : patron Barcode : " + patronBarcode + "operator : "+ operator + "agencyId : " + agencyId );
959 OLELookupUser lookupUser = new OLELookupUser();
960 if (!loanProcessor.hasCirculationDesk(operator)) {
961 lookupUser.setCode("001");
962 lookupUser.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_OPRTR_ID));
963 } else {
964 OleLoanDocumentDaoOjb oleLoanDocumentDaoOjb = (OleLoanDocumentDaoOjb)SpringContext.getBean("oleLoanDao");
965 OleDeliverDaoJdbc oleDeliverDaoJdbc = (OleDeliverDaoJdbc)SpringContext.getBean("oleDeliverDaoJdbc");
966 OlePatronDocument olePatronDocument = oleDeliverDaoJdbc.getPatronDocument(patronBarcode);
967
968 if (olePatronDocument!=null) {
969 Long startTimeInit = System.currentTimeMillis();
970 lookupUser = oleCirculationHelperService.initialiseLookupUser(olePatronDocument, agencyId);
971 Long endTimeInit = System.currentTimeMillis();
972 Long timeDiffInit = endTimeInit-startTimeInit;
973 LOG.info("Time taken to set the init details : " +timeDiffInit);
974 try {
975 Long startTimeLoan = System.currentTimeMillis();
976
977 List<OleLoanDocument> oleLoanDocumentList = oleLoanDocumentDaoOjb.getDeliverLoans(olePatronDocument.getOlePatronId());
978 if(oleLoanDocumentList!=null){
979 List<OLECheckedOutItem> oleCheckedOutItemList = oleDeliverDaoJdbc.getCheckedOutItemsList(oleLoanDocumentList);
980
981 if(oleCheckedOutItemList!=null){
982 OLECheckedOutItems oleCheckedOutItems = new OLECheckedOutItems();
983 if (oleCheckedOutItemList != null && oleCheckedOutItemList.size() > 0) {
984 oleCheckedOutItems.setCheckedOutItems(oleCheckedOutItemList);
985 }
986 lookupUser.setOleCheckedOutItems(oleCheckedOutItems);
987 }
988 }
989 Long endTimeLoan = System.currentTimeMillis();
990 Long timeDiffLoan = endTimeLoan-startTimeLoan;
991 LOG.info("Time taken to set the loan details : " +timeDiffLoan);
992 } catch (Exception e) {
993 LOG.info("Exception Occurred While Retrieving the checked out items");
994 LOG.error(e);
995 }
996 try {
997 Long startTimeHold = System.currentTimeMillis();
998
999
1000 List<OleDeliverRequestBo> oleDeliverRequestBoList = oleLoanDocumentDaoOjb.getDeliverRequests(patronBarcode);
1001
1002 if(oleDeliverRequestBoList!=null){
1003 List<OLEHold> oleHoldList = oleDeliverDaoJdbc.getHoldRecordsList(oleDeliverRequestBoList);
1004 if(oleHoldList!=null){
1005 OLEHolds oleHolds = new OLEHolds();
1006 if (oleHoldList != null && oleHoldList.size() > 0) {
1007 oleHolds.setOleHoldList(oleHoldList);
1008 }
1009 lookupUser.setOleHolds(oleHolds);
1010 }
1011 }
1012 Long endTimeHold = System.currentTimeMillis();
1013 Long timeDiffHold = endTimeHold-startTimeHold;
1014 LOG.info("Time taken to set the hold details : " +timeDiffHold);
1015 } catch (Exception e) {
1016 LOG.info("Exception Occurred While Retrieving the Hold items");
1017 LOG.error(e);
1018 }
1019 try {
1020 Long startTimeFine = System.currentTimeMillis();
1021 List<PatronBillPayment> patronBillPaymentList = oleLoanDocumentDaoOjb.getPatronBillPayments(olePatronDocument.getOlePatronId());
1022 if(patronBillPaymentList!=null){
1023 List<OLEItemFine> oleItemFineList = oleDeliverDaoJdbc.getFineItemLists(patronBillPaymentList);
1024 if(oleItemFineList!=null){
1025 OLEItemFines oleItemFines = new OLEItemFines();
1026 oleItemFines.setOleItemFineList(oleItemFineList);
1027 lookupUser.setOleItemFines(oleItemFines);
1028 }
1029 }
1030 Long endTimeFine = System.currentTimeMillis();
1031 Long timeDiffFine = endTimeFine-startTimeFine;
1032 LOG.info("Time taken to set the fine details : " +timeDiffFine);
1033 } catch (Exception e) {
1034 LOG.info("Exception Occurred While Retrieving Fine");
1035 LOG.error(e);
1036 }
1037 lookupUser.setCode("000");
1038 lookupUser.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RTRVD_SUCCESS));
1039 } else {
1040 lookupUser.setCode("002");
1041 lookupUser.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_PATRON_INFO));
1042 }
1043 }
1044 String responseMessage = oleLookupUserConverter.generateLookupUserResponseXml(lookupUser);
1045 Long endTime = System.currentTimeMillis();
1046 Long timediff = endTime-startTime;
1047 LOG.info("Time taken to complete the lookup user service " + timediff);
1048 return responseMessage;
1049 }
1050
1051
1052 }
1053
1054
1055