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