1 package org.kuali.ole.deliver.service;
2
3
4 import com.itextpdf.text.Document;
5 import org.apache.commons.collections.CollectionUtils;
6 import org.apache.commons.lang.StringUtils;
7 import org.apache.log4j.Logger;
8 import org.kuali.asr.ASRConstants;
9 import org.kuali.asr.service.ASRHelperServiceImpl;
10 import org.kuali.ole.DataCarrierService;
11 import org.kuali.ole.OLEConstants;
12 import org.kuali.ole.OLEParameterConstants;
13 import org.kuali.ole.deliver.OleLoanDocumentsFromSolrBuilder;
14 import org.kuali.ole.deliver.batch.OleDeliverBatchServiceImpl;
15 import org.kuali.ole.deliver.batch.OleMailer;
16 import org.kuali.ole.deliver.batch.OleNoticeBo;
17 import org.kuali.ole.deliver.batch.OleSms;
18 import org.kuali.ole.deliver.bo.*;
19 import org.kuali.ole.deliver.calendar.service.OleCalendarService;
20 import org.kuali.ole.deliver.calendar.service.impl.OleCalendarServiceImpl;
21 import org.kuali.ole.deliver.controller.checkout.CircUtilController;
22 import org.kuali.ole.deliver.processor.LoanProcessor;
23 import org.kuali.ole.deliver.service.impl.OLEDeliverNoticeHelperServiceImpl;
24 import org.kuali.ole.deliver.util.DroolsResponse;
25 import org.kuali.ole.deliver.util.ErrorMessage;
26 import org.kuali.ole.deliver.util.NoticeInfo;
27 import org.kuali.ole.deliver.util.OlePatronRecordUtil;
28 import org.kuali.ole.describe.bo.OleInstanceItemType;
29 import org.kuali.ole.describe.bo.OleLocation;
30 import org.kuali.ole.describe.bo.OleLocationLevel;
31 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
32 import org.kuali.ole.docstore.common.document.*;
33 import org.kuali.ole.docstore.common.document.HoldingsTree;
34 import org.kuali.ole.docstore.common.document.content.enums.DocType;
35 import org.kuali.ole.docstore.common.document.content.instance.Item;
36 import org.kuali.ole.docstore.common.document.content.instance.*;
37 import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
38 import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
39 import org.kuali.ole.docstore.common.search.*;
40 import org.kuali.ole.docstore.engine.client.DocstoreLocalClient;
41 import org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemRecord;
42 import org.kuali.ole.ingest.pojo.MatchBo;
43 import org.kuali.ole.ncip.bo.OLEPlaceRequest;
44 import org.kuali.ole.ncip.converter.OLEPlaceRequestConverter;
45 import org.kuali.ole.service.OleCirculationPolicyService;
46 import org.kuali.ole.service.OleCirculationPolicyServiceImpl;
47 import org.kuali.ole.service.OlePatronHelperService;
48 import org.kuali.ole.service.OlePatronHelperServiceImpl;
49 import org.kuali.ole.sys.context.SpringContext;
50 import org.kuali.ole.util.DocstoreUtil;
51 import org.kuali.rice.core.api.config.property.ConfigContext;
52 import org.kuali.rice.core.api.datetime.DateTimeService;
53 import org.kuali.rice.core.api.mail.EmailBody;
54 import org.kuali.rice.core.api.mail.EmailFrom;
55 import org.kuali.rice.core.api.mail.EmailSubject;
56 import org.kuali.rice.core.api.mail.EmailTo;
57 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
58 import org.kuali.rice.core.api.util.RiceConstants;
59 import org.kuali.rice.coreservice.api.CoreServiceApiServiceLocator;
60 import org.kuali.rice.coreservice.api.parameter.Parameter;
61 import org.kuali.rice.coreservice.api.parameter.ParameterKey;
62 import org.kuali.rice.coreservice.impl.parameter.ParameterBo;
63 import org.kuali.rice.kew.api.exception.WorkflowException;
64 import org.kuali.rice.kim.api.identity.Person;
65 import org.kuali.rice.kim.api.identity.PersonService;
66 import org.kuali.rice.kim.api.permission.PermissionService;
67 import org.kuali.rice.kim.api.role.RoleService;
68 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
69 import org.kuali.rice.kim.impl.identity.type.EntityTypeContactInfoBo;
70 import org.kuali.rice.krad.UserSession;
71 import org.kuali.rice.krad.dao.impl.PersistenceDaoOjb;
72 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
73 import org.kuali.rice.krad.service.BusinessObjectService;
74 import org.kuali.rice.krad.service.DocumentService;
75 import org.kuali.rice.krad.service.KRADServiceLocator;
76 import org.kuali.rice.krad.util.GlobalVariables;
77 import org.kuali.rice.krad.util.KRADConstants;
78 import org.kuali.rice.krad.util.ObjectUtils;
79 import org.kuali.rice.krms.api.KrmsApiServiceLocator;
80 import org.kuali.rice.krms.api.engine.*;
81 import org.kuali.rice.krms.api.repository.agenda.AgendaDefinition;
82 import org.kuali.rice.krms.api.repository.context.ContextDefinition;
83 import org.kuali.rice.krms.impl.repository.KrmsRepositoryServiceLocator;
84
85 import java.io.OutputStream;
86 import java.sql.*;
87 import java.text.DateFormat;
88 import java.text.SimpleDateFormat;
89 import java.util.*;
90 import java.util.Date;
91 import java.util.concurrent.ExecutorService;
92 import java.util.concurrent.Executors;
93
94
95
96
97
98
99
100
101 public class OleDeliverRequestDocumentHelperServiceImpl {
102 private static final Logger LOG = Logger.getLogger(OleDeliverRequestDocumentHelperServiceImpl.class);
103 private static final String NAMESPACE_CODE_SELECTOR = "namespaceCode";
104 private static final String NAME_SELECTOR = "name";
105 private final static String RULE_EVALUATED = "Rule Evaluated";
106 private final static String ROUTED_EXTERNAL = "Routed External";
107 private BusinessObjectService businessObjectService;
108 private int queuePosition = 0;
109 private LoanProcessor loanProcessor;
110 private DocstoreUtil docstoreUtil;
111 private ItemOlemlRecordProcessor itemOlemlRecordProcessor;
112 private OLEDeliverNoticeHelperService oleDeliverNoticeHelperService;
113 private DocumentService documentService;
114 private PersonService personService = KimApiServiceLocator.getPersonService();
115 private OleCirculationPolicyService oleCirculationPolicyService;
116 private DateTimeService dateTimeService;
117 private List<OleLoanDocument> laonDocumentsFromLaondId;
118 private OlePatronHelperServiceImpl olePatronHelperService;
119 private CircDeskLocationResolver circDeskLocationResolver;
120 private OleLoanDocumentsFromSolrBuilder oleLoanDocumentsFromSolrBuilder;
121
122 public DateTimeService getDateTimeService() {
123 return (DateTimeService) SpringContext.getService("dateTimeService");
124 }
125
126 private PermissionService getPermissionService() {
127 PermissionService service = KimApiServiceLocator.getPermissionService();
128 return service;
129 }
130
131 private CircDeskLocationResolver getCircDeskLocationResolver() {
132 if (circDeskLocationResolver == null) {
133 circDeskLocationResolver = new CircDeskLocationResolver();
134 }
135 return circDeskLocationResolver;
136 }
137
138 public void setCircDeskLocationResolver(CircDeskLocationResolver circDeskLocationResolver) {
139 this.circDeskLocationResolver = circDeskLocationResolver;
140 }
141
142 private DocstoreClientLocator docstoreClientLocator;
143
144 public DocstoreClientLocator getDocstoreClientLocator() {
145
146 if (docstoreClientLocator == null) {
147 docstoreClientLocator = (DocstoreClientLocator)SpringContext.getService("docstoreClientLocator");
148
149 }
150 return docstoreClientLocator;
151 }
152
153 public OlePatronHelperService getOlePatronHelperService() {
154 if (olePatronHelperService == null)
155 olePatronHelperService = new OlePatronHelperServiceImpl();
156 return olePatronHelperService;
157 }
158
159 public void setOlePatronHelperService(OlePatronHelperServiceImpl olePatronHelperService) {
160 this.olePatronHelperService = olePatronHelperService;
161 }
162
163 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
164 this.businessObjectService = businessObjectService;
165 }
166
167
168 public void setLoanProcessor(LoanProcessor loanProcessor) {
169 this.loanProcessor = loanProcessor;
170 }
171
172 public void setDocstoreUtil(DocstoreUtil docstoreUtil) {
173 this.docstoreUtil = docstoreUtil;
174 }
175
176 public void setDocstoreClientLocator(DocstoreClientLocator docstoreClientLocator) {
177 this.docstoreClientLocator = docstoreClientLocator;
178 }
179
180 public DocstoreUtil getDocstoreUtil() {
181 if (docstoreUtil == null) {
182 docstoreUtil = (DocstoreUtil)SpringContext.getService("docstoreUtil");
183 }
184 return docstoreUtil;
185 }
186
187
188
189
190
191
192
193 private BusinessObjectService getBusinessObjectService() {
194 if (null == businessObjectService) {
195 businessObjectService = KRADServiceLocator.getBusinessObjectService();
196 }
197 return businessObjectService;
198 }
199
200 public LoanProcessor getLoanProcessor() {
201 if (loanProcessor == null) {
202 loanProcessor = (LoanProcessor)SpringContext.getService("loanProcessor");
203 }
204 return loanProcessor;
205 }
206
207 public ItemOlemlRecordProcessor getItemOlemlRecordProcessor() {
208 if (itemOlemlRecordProcessor == null) {
209 itemOlemlRecordProcessor = (ItemOlemlRecordProcessor) SpringContext.getService("itemOlemlRecordProcessor");
210 }
211 return itemOlemlRecordProcessor;
212 }
213
214 public OLEDeliverNoticeHelperService getOleDeliverNoticeHelperService() {
215 if (oleDeliverNoticeHelperService == null) {
216 oleDeliverNoticeHelperService = (OLEDeliverNoticeHelperService)SpringContext.getService("oleDeliverNoticeHelperService");
217 }
218 return oleDeliverNoticeHelperService;
219 }
220
221 public void setOleDeliverNoticeHelperService(OLEDeliverNoticeHelperService oleDeliverNoticeHelperService) {
222 this.oleDeliverNoticeHelperService = oleDeliverNoticeHelperService;
223 }
224
225
226
227
228
229
230
231 public OleCirculationPolicyService getOleCirculationPolicyService() {
232 if (null == oleCirculationPolicyService) {
233 oleCirculationPolicyService = (OleCirculationPolicyService)SpringContext.getService("oleCirculationPolicyService");
234 }
235 return oleCirculationPolicyService;
236 }
237
238
239
240
241
242
243
244 public OleDeliverRequestBo processRequestType(OleDeliverRequestBo oleDeliverRequestBo) {
245 if (LOG.isDebugEnabled()) {
246 LOG.debug("Inside processRequestType for the Request id :" + oleDeliverRequestBo.getRequestId());
247 }
248 oleDeliverRequestBo = processPatron(oleDeliverRequestBo);
249 oleDeliverRequestBo = processItem(oleDeliverRequestBo);
250 oleDeliverRequestBo = processRequestTypeByPickUpLocation(oleDeliverRequestBo);
251 return oleDeliverRequestBo;
252 }
253
254 private OleDeliverRequestBo processRequestTypeByPickUpLocation(OleDeliverRequestBo oleDeliverRequestBo) {
255 if (oleDeliverRequestBo.getRequestTypeId() != null) {
256 if (oleDeliverRequestBo.getRequestTypeId().equals("3") && oleDeliverRequestBo.getPickUpLocationId() != null && !oleDeliverRequestBo.getPickUpLocationId().isEmpty()) {
257 oleDeliverRequestBo.setRequestTypeId("4");
258 } else if (oleDeliverRequestBo.getRequestTypeId().equals("5") && oleDeliverRequestBo.getPickUpLocationId() != null && !oleDeliverRequestBo.getPickUpLocationId().isEmpty()) {
259 oleDeliverRequestBo.setRequestTypeId("6");
260 } else if (oleDeliverRequestBo.getRequestTypeId().equals("1") && oleDeliverRequestBo.getPickUpLocationId() != null && !oleDeliverRequestBo.getPickUpLocationId().isEmpty()) {
261 oleDeliverRequestBo.setRequestTypeId("2");
262 }
263 }
264 return oleDeliverRequestBo;
265 }
266
267
268
269
270
271
272
273
274 public OleDeliverRequestBo processPatron(OleDeliverRequestBo oleDeliverRequestBo) {
275 LOG.debug("Inside processPatron");
276 OleDeliverRequestBo deliver = oleDeliverRequestBo;
277
278 if (oleDeliverRequestBo.getBorrowerBarcode() != null || oleDeliverRequestBo.getProxyBorrowerBarcode() != null) {
279 Map<String, String> patronMap = new HashMap<String, String>();
280 patronMap.put(OLEConstants.OleDeliverRequest.PATRON_BARCODE, oleDeliverRequestBo.getBorrowerBarcode());
281 List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) getBusinessObjectService().findMatching(OlePatronDocument.class, patronMap);
282 if (olePatronDocumentList != null && olePatronDocumentList.size() > 0) {
283 deliver.setOlePatron(olePatronDocumentList.get(0));
284 deliver.setBorrowerName(olePatronDocumentList.get(0).getPatronName());
285 deliver.setBorrowerId(olePatronDocumentList.get(0).getOlePatronId());
286 } else if (olePatronDocumentList != null && olePatronDocumentList.size() == 0) {
287 deliver.setBorrowerId(null);
288 deliver.setFirstName(null);
289 deliver.setLastName(null);
290 deliver.setOlePatron(null);
291 deliver.setBorrowerName(null);
292 deliver.setBorrowerBarcode(null);
293 }
294 if (oleDeliverRequestBo.getRequestCreator().equals(OLEConstants.OleDeliverRequest.REQUESTER_PROXY_PATRON)) {
295 Map<String, String> proxyPatronMap = new HashMap<String, String>();
296 proxyPatronMap.put(OLEConstants.OleDeliverRequest.PATRON_BARCODE, oleDeliverRequestBo.getProxyBorrowerBarcode());
297 List<OlePatronDocument> oleProxyPatronDocumentList = (List<OlePatronDocument>) getBusinessObjectService().findMatching(OlePatronDocument.class, proxyPatronMap);
298 if (oleProxyPatronDocumentList != null && oleProxyPatronDocumentList.size() > 0) {
299 deliver.setOleProxyPatron(oleProxyPatronDocumentList.get(0));
300 deliver.setProxyBorrowerName(oleProxyPatronDocumentList.get(0).getPatronName());
301 deliver.setProxyBorrowerId(oleProxyPatronDocumentList.get(0).getOlePatronId());
302 } else if (oleProxyPatronDocumentList != null && oleProxyPatronDocumentList.size() == 0) {
303 deliver.setProxyBorrowerId(null);
304 deliver.setProxyBorrowerName(null);
305 deliver.setOleProxyPatron(null);
306 }
307 }
308
309 }
310
311 return deliver;
312 }
313
314 public boolean processOperator(String principalId) {
315
316
317
318
319 boolean isOperator = true;
320 Collection<String> roles = getRoleService().getRoleMemberPrincipalIds(OLEConstants.OlePatron.PATRON_NAMESPACE, OLEConstants.OleDeliverRequest.REQUESTER_OPERATOR, null);
321 if (roles != null) {
322 isOperator = roles.contains(principalId);
323 }
324 return isOperator;
325 }
326
327
328
329
330
331
332
333 public boolean validateRequestType(OleDeliverRequestBo oleDeliverRequestBo) {
334 LOG.debug("Inside validateRequestType");
335 boolean validRequest = true;
336 if ((oleDeliverRequestBo.getRequestTypeId().equals("2") || oleDeliverRequestBo.getRequestTypeId().equals("4") || oleDeliverRequestBo.getRequestTypeId().equals("6")) && (oleDeliverRequestBo.getPickUpLocationId() == null) || (oleDeliverRequestBo.getPickUpLocationId() != null && oleDeliverRequestBo.getPickUpLocationId().isEmpty())) {
337 validRequest = false;
338 }
339 return validRequest;
340 }
341
342
343
344
345
346
347
348
349 public boolean validateDeliveryPrivilege(OleDeliverRequestBo oleDeliverRequestBo) {
350 LOG.debug("Inside validateDeliveryPrivilege");
351 boolean hasDeliveryPrivilege = true;
352 if (oleDeliverRequestBo.getRequestTypeId().equals("1") || oleDeliverRequestBo.getRequestTypeId().equals("3") || oleDeliverRequestBo.getRequestTypeId().equals("5")) {
353 if (oleDeliverRequestBo.getOlePatron() != null && !oleDeliverRequestBo.getOlePatron().isDeliveryPrivilege()) {
354 hasDeliveryPrivilege = false;
355 }
356 } else if (oleDeliverRequestBo.getRequestTypeId().equals("2") || oleDeliverRequestBo.getRequestTypeId().equals("4") || oleDeliverRequestBo.getRequestTypeId().equals("6")) {
357 if (oleDeliverRequestBo.getOlePatron() != null && !oleDeliverRequestBo.getOlePatron().isDeliveryPrivilege() && oleDeliverRequestBo.getPickUpLocationId() == null) {
358 hasDeliveryPrivilege = false;
359 }
360 }
361 return hasDeliveryPrivilege;
362 }
363
364
365
366
367
368
369
370
371 public boolean validatePagingPrivilege(OleDeliverRequestBo oleDeliverRequestBo) {
372 LOG.debug("Inside validatePagingPrivilege");
373 boolean hasPagePrivilege = true;
374 if (oleDeliverRequestBo.getRequestTypeId().equals("5") || oleDeliverRequestBo.getRequestTypeId().equals("6")) {
375 if (!oleDeliverRequestBo.getOlePatron().isPagingPrivilege()) {
376 hasPagePrivilege = false;
377 }
378 }
379 return hasPagePrivilege;
380 }
381
382
383
384
385
386
387
388
389 public OleDeliverRequestBo processRequester(OleDeliverRequestBo oleDeliverRequestBo) {
390 LOG.debug("Inside processRequester");
391 if (oleDeliverRequestBo.getRequestCreator().equals(OLEConstants.OleDeliverRequest.REQUESTER_PATRON)) {
392 oleDeliverRequestBo.setProxyBorrowerId(null);
393 oleDeliverRequestBo.setOleProxyPatron(null);
394 oleDeliverRequestBo.setOperatorCreateId(null);
395 oleDeliverRequestBo.setOperatorCreator(null);
396 } else if (oleDeliverRequestBo.getRequestCreator().equals(OLEConstants.OleDeliverRequest.REQUESTER_PROXY_PATRON)) {
397 oleDeliverRequestBo.setOperatorCreateId(null);
398 oleDeliverRequestBo.setOperatorCreator(null);
399 } else if (oleDeliverRequestBo.getRequestCreator().equals(OLEConstants.OleDeliverRequest.REQUESTER_OPERATOR)) {
400 oleDeliverRequestBo.setProxyBorrowerId(null);
401 oleDeliverRequestBo.setOleProxyPatron(null);
402 }
403 return oleDeliverRequestBo;
404 }
405
406
407
408
409
410
411
412
413 public boolean isValidProxyPatron(OleDeliverRequestBo oleDeliverRequestBo) {
414 LOG.debug("Inside isValidProxyPatron");
415 boolean validProxy = true;
416 Map<String, String> proxyMap = new HashMap<String, String>();
417 proxyMap.put(OLEConstants.OleDeliverRequest.PATRON_ID, oleDeliverRequestBo.getBorrowerId());
418 proxyMap.put(OLEConstants.OleDeliverRequest.PROXY_PATRON_ID, oleDeliverRequestBo.getProxyBorrowerId());
419 if (oleDeliverRequestBo.getProxyBorrowerId() != null && !oleDeliverRequestBo.getProxyBorrowerId().isEmpty()) {
420 List<OleProxyPatronDocument> proxyPatronDocuments = (List<OleProxyPatronDocument>) getBusinessObjectService().findMatching(OleProxyPatronDocument.class, proxyMap);
421 if (proxyPatronDocuments.size() == 0) {
422 validProxy = false;
423 }
424 }
425 return validProxy;
426 }
427
428
429
430
431
432
433
434
435 public boolean isRequestAlreadyRaisedByPatron(OleDeliverRequestBo oleDeliverRequestBo) {
436 LOG.debug("Inside isRequestAlreadyRaised");
437 boolean alreadyExist = false;
438 Map<String, String> requestMap = new HashMap<String, String>();
439 requestMap.put(OLEConstants.OleDeliverRequest.BORROWER_ID, oleDeliverRequestBo.getBorrowerId());
440 requestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
441 List<OleDeliverRequestBo> deliverRequestBos = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
442 if (deliverRequestBos != null && deliverRequestBos.size() > 0) {
443 alreadyExist = true;
444 }
445 return alreadyExist;
446 }
447
448
449
450
451
452
453
454
455 public boolean isAlreadyLoaned(OleDeliverRequestBo oleDeliverRequestBo) {
456 LOG.debug("Inside isAlreadyLoaned");
457 boolean alreadyLoaned = false;
458 Map<String, String> loanMap = new HashMap<String, String>();
459 loanMap.put(OLEConstants.OleDeliverRequest.LOAN_PATRON_ID, oleDeliverRequestBo.getBorrowerId());
460 loanMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
461 List<OleLoanDocument> loanDocuments = (List<OleLoanDocument>) getBusinessObjectService().findMatching(OleLoanDocument.class, loanMap);
462 if (loanDocuments != null && loanDocuments.size() > 0) {
463 alreadyLoaned = true;
464 }
465 return alreadyLoaned;
466 }
467
468
469
470
471
472
473
474
475 public boolean isItemAvailable(OleDeliverRequestBo oleDeliverRequestBo) {
476 LOG.debug("Inside isItemAvailable");
477 boolean itemAvailable = true;
478
479 String itemStatuslist = null;
480 String requestTypeCode = oleDeliverRequestBo.getRequestTypeCode();
481 if (requestTypeCode.equals("Recall/Delivery Request")) {
482 itemStatuslist = getLoanProcessor().getParameter(OLEConstants.RECALL_DELIVERY_ITEM_STATUS);
483 } else if (requestTypeCode.equals("Recall/Hold Request")) {
484 itemStatuslist = getLoanProcessor().getParameter(OLEConstants.RECALL_HOLD_ITEM_STATUS);
485 } else if (requestTypeCode.equals("Hold/Delivery Request")) {
486 itemStatuslist = getLoanProcessor().getParameter(OLEConstants.HOLD_DELIVERY_ITEM_STATUS);
487 } else if (requestTypeCode.equals("Hold/Hold Request")) {
488 itemStatuslist = getLoanProcessor().getParameter(OLEConstants.HOLD_HOLD_ITEM_STATUS);
489 } else if (requestTypeCode.equals("Page/Delivery Request")) {
490 itemStatuslist = getLoanProcessor().getParameter(OLEConstants.PAGE_DELIVERY_ITEM_STATUS);
491 } else if (requestTypeCode.equals("Page/Hold Request")) {
492 itemStatuslist = getLoanProcessor().getParameter(OLEConstants.PAGE_HOLD_ITEM_STATUS);
493 } else if (requestTypeCode.equals("Copy Request")) {
494 itemStatuslist = getLoanProcessor().getParameter(OLEConstants.COPY_REQUEST_ITEM_STATUS);
495 } else if (requestTypeCode.equals("ASR Request")) {
496 itemStatuslist = getLoanProcessor().getParameter(OLEConstants.ASR_REQUEST_ITEM_STATUS);
497 } else {
498 GlobalVariables.getMessageMap().putError(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, OLEConstants.OleDeliverRequest.REQUEST_ID_INVALID);
499 }
500 String[] str = itemStatuslist.split(";");
501 for (String itemStatus : str) {
502 if ((itemStatus != null) && (!itemStatus.isEmpty()) && (itemStatus.equals(oleDeliverRequestBo.getItemStatus()))) {
503 itemAvailable = false;
504 }
505 }
506 return itemAvailable;
507 }
508
509
510
511
512
513
514
515
516 public boolean isItemAvailableForLoan(OleDeliverRequestBo oleDeliverRequestBo) {
517 LOG.debug("Inside isItemAvailable");
518 boolean itemAvailable = false;
519 Map<String, String> loanItemMap = new HashMap<String, String>();
520 loanItemMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
521 List<OleLoanDocument> loanItemDocuments = (List<OleLoanDocument>) getBusinessObjectService().findMatching(OleLoanDocument.class, loanItemMap);
522 if (loanItemDocuments.size() == 0) {
523 itemAvailable = true;
524 }
525 return itemAvailable;
526 }
527
528
529
530
531
532
533
534
535 public boolean isItemEligible(OleDeliverRequestBo oleDeliverRequestBo) {
536 LOG.debug("Inside isItemEligible");
537 boolean itemEligible = true;
538 Map<String, String> statusMap = new HashMap<String, String>();
539 statusMap.put(OLEConstants.OleDeliverRequest.LOSTBILLREPLACEMENT, OLEConstants.OleDeliverRequest.LOSTBILLREPLACEMENT);
540 statusMap.put(OLEConstants.OleDeliverRequest.MISSINGFINALOVERDUE, OLEConstants.OleDeliverRequest.MISSINGFINALOVERDUE);
541 statusMap.put(OLEConstants.OleDeliverRequest.WITHDRAWNCLIAMSRETURN, OLEConstants.OleDeliverRequest.WITHDRAWNCLIAMSRETURN);
542
543 if (statusMap.containsKey(oleDeliverRequestBo.getItemStatus())) {
544 itemEligible = false;
545 }
546 return itemEligible;
547 }
548
549
550
551
552
553
554
555 public String patronRecordExpired(OleDeliverRequestBo oleDeliverRequestBo) {
556 LOG.debug("Inside patronRecordExpired");
557 String expired = null;
558
559 OlePatronDocument olePatronDocument = oleDeliverRequestBo.getOlePatron();
560 if (olePatronDocument == null) {
561 Map<String, String> patronMap = new HashMap<String, String>();
562 patronMap.put(OLEConstants.OleDeliverRequest.PATRON_ID, oleDeliverRequestBo.getBorrowerId());
563 List<OlePatronDocument> olePatronDocuments = (List<OlePatronDocument>) getBusinessObjectService().findMatching(OlePatronDocument.class, patronMap);
564 if (olePatronDocuments != null && olePatronDocuments.size() > 0) {
565 olePatronDocument = olePatronDocuments.get(0);
566 }
567 }
568 if (olePatronDocument != null) {
569 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OleDeliverRequest.DATE_FORMAT);
570 Date expirationDate = olePatronDocument.getExpirationDate();
571 Date activationDate = olePatronDocument.getActivationDate();
572 if ((fmt.format(activationDate)).compareTo(fmt.format(new Date(System.currentTimeMillis()))) <= 0) {
573 if (expirationDate != null) {
574 if ((fmt.format(expirationDate)).compareTo(fmt.format(new Date(System.currentTimeMillis()))) < 0) {
575 expired = OLEConstants.OleDeliverRequest.PATRON_RECORD_EXPIRE;
576 }
577 }
578 } else {
579 expired = OLEConstants.OleDeliverRequest.PATRON_RECORD_FUTURE;
580 }
581 }
582 return expired;
583 }
584
585
586
587
588
589
590
591
592 public List<OleDeliverRequestBo> getRequestedItems(String olePatronId) {
593 LOG.debug("Inside getRequestedItems");
594 Map<String, String> requestMap = new HashMap<String, String>();
595 requestMap.put(OLEConstants.OleDeliverRequest.BORROWER_ID, olePatronId);
596 List<OleDeliverRequestBo> deliverRequestBos = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
597 for (int i = 0; i < deliverRequestBos.size(); i++) {
598 processItem(deliverRequestBos.get(i));
599 }
600 return deliverRequestBos;
601
602 }
603
604
605
606
607
608
609
610
611 public String validateQueuePosition(List<OleDeliverRequestBo> itemList) {
612 LOG.debug("Inside validateQueuePosition");
613 String message = OLEConstants.OleDeliverRequest.REORDER_SUCCESS;
614 List<Integer> queuePositionList = new ArrayList<Integer>();
615 if (itemList.get(0).getBorrowerQueuePosition() < 1) {
616 return OLEConstants.OleDeliverRequest.POSITIVE_QUEUE_POSITION;
617 }
618 queuePositionList.add(itemList.get(0).getBorrowerQueuePosition());
619
620 for (int i = 1; i < itemList.size(); i++) {
621 for (int j = 0; j < queuePositionList.size(); j++) {
622 if (itemList.get(i).getBorrowerQueuePosition() != null) {
623 if ((itemList.get(i).getBorrowerQueuePosition() >= 1) && (itemList.get(i).getBorrowerQueuePosition() == queuePositionList.get(j))) {
624 return OLEConstants.OleDeliverRequest.QUEUE_DUPLICATE;
625 } else if ((itemList.get(i).getBorrowerQueuePosition() <= 0)) {
626 return OLEConstants.OleDeliverRequest.POSITIVE_QUEUE_POSITION;
627 }
628 }
629 }
630 queuePositionList.add(itemList.get(i).getBorrowerQueuePosition());
631 }
632 return message;
633 }
634
635
636
637
638
639
640
641
642
643 public boolean isRequestRaised(OleDeliverRequestBo oleDeliverRequestBo) {
644 LOG.debug("Inside isRequestRaised");
645 boolean exist = false;
646 Map<String, String> requestMap = new HashMap<String, String>();
647 requestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
648 List<OleDeliverRequestBo> deliverRequestBos = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
649 if (deliverRequestBos.size() > 0) {
650 exist = true;
651 }
652 return exist;
653 }
654
655
656
657
658
659
660
661 public void cancelDocument(OleDeliverRequestBo oleDeliverRequestBo) {
662 String operatorId = GlobalVariables.getUserSession().getLoggedInUserPrincipalName();
663 try {
664 List<OleNoticeBo> oleNoticeBos = cancelRequestForItem(oleDeliverRequestBo.getItemUuid(), oleDeliverRequestBo.getBorrowerId());
665 ASRHelperServiceImpl asrHelperService = new ASRHelperServiceImpl();
666 createRequestHistoryRecord(oleDeliverRequestBo.getRequestId(), operatorId, oleDeliverRequestBo.getLoanTransactionRecordNumber(), ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.REQUEST_CANCELLED));
667 LOG.debug("Inside cancelDocument");
668 Map<String, String> itemMap = new HashMap<String, String>();
669 itemMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
670 Map<String, String> requestMap = new HashMap<String, String>();
671 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_ID, oleDeliverRequestBo.getRequestId());
672 getBusinessObjectService().deleteMatching(OleDeliverRequestBo.class, requestMap);
673 List<OleDeliverRequestBo> oleDeliverRequestDocumentsList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class, itemMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
674 getBusinessObjectService().delete(oleDeliverRequestDocumentsList);
675 int queuePosition = 1;
676 for (int i = 0; i < oleDeliverRequestDocumentsList.size(); i++) {
677 oleDeliverRequestDocumentsList.get(i).setBorrowerQueuePosition(queuePosition);
678 queuePosition = queuePosition + 1;
679 }
680 getBusinessObjectService().save(oleDeliverRequestDocumentsList);
681 asrHelperService.deleteASRTypeRequest(oleDeliverRequestBo.getRequestId());
682 sendCancelNotice(oleNoticeBos);
683 } catch (Exception e) {
684 LOG.error("Cancellation of Request" + e.getMessage());
685 }
686 }
687
688
689
690
691
692
693
694
695
696 public List<OleNoticeBo> cancelRequestForItem(String itemUuid, String patronId) throws Exception {
697 Map<String, String> requestMap = new HashMap<String, String>();
698 requestMap.put(OLEConstants.ITEM_UUID, itemUuid);
699 requestMap.put(OLEConstants.OleDeliverRequest.BORROWER_ID, patronId);
700 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
701 List<OleNoticeBo> oleNoticeBos = new ArrayList<OleNoticeBo>();
702 if (org.apache.commons.collections.CollectionUtils.isNotEmpty(oleDeliverRequestBoList)) {
703 OleDeliverRequestBo oleDeliverRequestBo = oleDeliverRequestBoList.get(0);
704
705 OleItemSearch itemSearch = getDocstoreUtil().getOleItemSearchList(itemUuid);
706 EntityTypeContactInfoBo entityTypeContactInfoBo = oleDeliverRequestBo.getOlePatron().getEntity().getEntityTypeContactInfos().get(0);
707
708 OleNoticeBo oleNoticeBo = new OleNoticeBo();
709 oleNoticeBo.setNoticeName(OLEConstants.CANCELLATION_NOTICE);
710 oleNoticeBo.setPatronName(oleDeliverRequestBo.getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + oleDeliverRequestBo.getOlePatron().getEntity().getNames().get(0).getLastName());
711 oleNoticeBo.setPatronAddress(getOlePatronHelperService().getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronPreferredAddress(entityTypeContactInfoBo) : "");
712 oleNoticeBo.setPatronEmailAddress(getOlePatronHelperService().getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronHomeEmailId(entityTypeContactInfoBo) : "");
713 oleNoticeBo.setPatronPhoneNumber(getOlePatronHelperService().getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
714 oleNoticeBo.setAuthor(itemSearch.getAuthor() != null ? itemSearch.getAuthor() : "");
715 oleNoticeBo.setItemCallNumber(itemSearch.getCallNumber() != null ? itemSearch.getCallNumber() : "");
716 if (itemSearch.getShelvingLocation() != null && itemSearch.getShelvingLocation().toString().contains("/")) {
717 String[] location = itemSearch.getShelvingLocation().split("/");
718 if (location != null && location.length > 0)
719 oleNoticeBo.setItemShelvingLocation(location[1] != null ? location[1] : "");
720 } else {
721 oleNoticeBo.setItemShelvingLocation("");
722 }
723 oleNoticeBo.setItemId(itemSearch.getItemBarCode() != null ? itemSearch.getItemBarCode() : "");
724 oleNoticeBo.setTitle(itemSearch.getTitle() != null ? itemSearch.getTitle() : "");
725 oleNoticeBo.setOleItem(getItem(oleDeliverRequestBo.getItemUuid()));
726 if (oleNoticeBo.getPatronEmailAddress() != null && !oleNoticeBo.getPatronEmailAddress().isEmpty()) {
727 oleNoticeBos.add(oleNoticeBo);
728 }
729 }
730 return oleNoticeBos;
731 }
732
733
734
735
736
737
738
739
740 public void sendCancelNotice(List<OleNoticeBo> oleNoticeBos) throws Exception {
741 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
742 for (OleNoticeBo oleNoticeBo : oleNoticeBos) {
743 List list = oleDeliverBatchService.getNoticeForPatron(oleNoticeBos);
744 String content = list.toString();
745 content = content.replace('[', ' ');
746 content = content.replace(']', ' ');
747 if (!content.trim().equals("")) {
748 OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
749 String replyToEmail = getCircDeskLocationResolver().getReplyToEmail(oleNoticeBo.getItemShelvingLocation());
750 if (replyToEmail != null) {
751 oleMailer.sendEmail(new EmailFrom(replyToEmail), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.CANCELLATION_NOTICE), new EmailBody(content), true);
752 } else {
753 String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
754 if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
755 fromAddress = OLEConstants.KUALI_MAIL;
756 }
757 oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.CANCELLATION_NOTICE), new EmailBody(content), true);
758 }
759 }
760 }
761 }
762
763
764 public void cancelPendingRequestForClaimsReturnedItem(String itemUuid) throws Exception {
765 Map<String, String> requestMap = new HashMap<String, String>();
766 requestMap.put(OLEConstants.ITEM_UUID, itemUuid);
767 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
768 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
769 for (OleDeliverRequestBo oleDeliverRequestBo : oleDeliverRequestBoList) {
770 cancelDocument(oleDeliverRequestBo);
771 }
772 }
773
774 public void cancelPendingRequestForDamagedItem(String itemUuid) throws Exception {
775 Map<String, String> requestMap = new HashMap<String, String>();
776 requestMap.put(OLEConstants.ITEM_UUID, itemUuid);
777 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
778 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
779 for (OleDeliverRequestBo oleDeliverRequestBo : oleDeliverRequestBoList) {
780 cancelDocument(oleDeliverRequestBo);
781 }
782 }
783
784 public void cancelPendingRequestForMissingPieceItem(String itemUuid) throws Exception {
785 Map<String, String> requestMap = new HashMap<String, String>();
786 requestMap.put(OLEConstants.ITEM_UUID, itemUuid);
787 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
788 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
789 for (OleDeliverRequestBo oleDeliverRequestBo : oleDeliverRequestBoList) {
790 cancelDocument(oleDeliverRequestBo);
791 }
792 }
793
794
795
796
797
798
799
800 public OleDeliverRequestBo processItem(OleDeliverRequestBo oleDeliverRequestBo) {
801 LOG.debug("Inside processItem");
802 OleItemSearch oleItemSearch = null;
803 if (oleDeliverRequestBo.getItemType() == null) {
804
805
806 OleItemSearch itemSearchList = getDocstoreUtil().getOleItemSearchList(oleDeliverRequestBo.getItemUuid());
807 try {
808
809
810
811 if (itemSearchList != null) {
812 oleItemSearch = itemSearchList;
813 oleDeliverRequestBo.setTitle(itemSearchList.getTitle());
814 oleDeliverRequestBo.setAuthor(itemSearchList.getAuthor());
815 oleDeliverRequestBo.setCallNumber(itemSearchList.getCallNumber());
816 oleDeliverRequestBo.setItemType(itemSearchList.getItemType());
817 oleDeliverRequestBo.setItemLocation(itemSearchList.getShelvingLocation());
818 oleDeliverRequestBo.setShelvingLocation(itemSearchList.getShelvingLocation());
819 oleDeliverRequestBo.setCopyNumber(itemSearchList.getCopyNumber());
820 oleDeliverRequestBo.setItemStatus(itemSearchList.getItemStatus());
821 oleDeliverRequestBo.setEnumeration(itemSearchList.getEnumeration());
822 oleDeliverRequestBo.setChronology(itemSearchList.getChronology());
823 }
824 } catch (Exception ex) {
825 ex.printStackTrace();
826 }
827 try {
828 String itemXml = getLoanProcessor().getItemXML(oleDeliverRequestBo.getItemUuid());
829 Item oleItem = getLoanProcessor().getItemPojo(itemXml);
830 if (oleItemSearch == null) {
831 oleItemSearch = new OleItemSearch();
832 oleItemSearch.setCopyNumber(oleItem.getCopyNumber());
833 if (oleItem.getItemStatus() != null) {
834 oleItemSearch.setItemStatus(oleItem.getItemStatus().getCodeValue());
835 }
836 oleItemSearch.setShelvingLocation(getShelvingLocation(oleItem.getLocation()));
837 oleDeliverRequestBo.setCopyNumber(oleItem.getCopyNumber());
838
839 if (oleItem.getItemStatus() != null) {
840 oleDeliverRequestBo.setItemStatus(oleItem.getItemStatus().getCodeValue());
841 }
842 oleDeliverRequestBo.setShelvingLocation(oleItemSearch.getShelvingLocation());
843 }
844
845 if (oleDeliverRequestBo.getRequestTypeId().equals("8")) {
846 oleDeliverRequestBo.setInTransitCheckInNote(oleItem.getCheckinNote());
847 }
848 } catch (Exception e) {
849 LOG.error(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVAL_LOC), e);
850 }
851 }
852 oleDeliverRequestBo.setOleItemSearch(oleItemSearch);
853 oleDeliverRequestBo = processItemType(oleDeliverRequestBo);
854 return oleDeliverRequestBo;
855 }
856
857
858
859
860
861
862
863 public OleDeliverRequestBo processItemType(OleDeliverRequestBo oleDeliverRequestBo) {
864 LOG.debug("Inside process Item Type");
865 Map<String, String> itemMap = new HashMap<String, String>();
866 itemMap = new HashMap<String, String>();
867 itemMap.put(OLEConstants.OleDeliverRequest.ITEM_TYPE_CODE, oleDeliverRequestBo.getItemType());
868 List<OleInstanceItemType> oleInstanceItemTypeList = (List<OleInstanceItemType>) getBusinessObjectService().findMatching(OleInstanceItemType.class, itemMap);
869 if (oleInstanceItemTypeList != null && oleInstanceItemTypeList.size() > 0) {
870 OleInstanceItemType oleInstanceItemType = oleInstanceItemTypeList.get(0);
871 oleDeliverRequestBo.setItemTypeName(oleInstanceItemType.getInstanceItemTypeName());
872 }
873
874 return oleDeliverRequestBo;
875 }
876
877
878
879
880
881
882
883 private String getShelvingLocation(Location oleLocation) {
884
885 LOG.debug("Inside getShelvingLocation");
886 String locationLevelName = "";
887 if (oleLocation != null) {
888 LocationLevel locationLevel =
889 oleLocation.getLocationLevel();
890 if (locationLevel != null) {
891 while (locationLevel.getLocationLevel() != null && !locationLevel.getLevel().equalsIgnoreCase(OLEConstants.OleDeliverRequest.SHELVING)) {
892 locationLevel = locationLevel.getLocationLevel();
893 }
894 locationLevelName = locationLevel.getName();
895 }
896 }
897 return locationLevelName;
898 }
899
900
901
902
903
904
905
906
907 public boolean canRaiseRequest(OleDeliverRequestBo oleDeliverRequestBo) {
908 LOG.debug("Inside canRaiseRequest");
909 boolean canRaiseRequest = true;
910
911 if (isItemAvailable(oleDeliverRequestBo)) {
912 canRaiseRequest = false;
913
914
915 }
916 return canRaiseRequest;
917 }
918
919
920
921
922
923
924
925
926 public OleDeliverRequestBo updateLoanDocument(OleDeliverRequestBo oleDeliverRequestBo) {
927 LOG.debug("Inside updateLoanDocument");
928 Map<String, String> loanMap = new HashMap<String, String>();
929 loanMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
930 List<OleLoanDocument> oleLoanDocumentList = (List<OleLoanDocument>) getBusinessObjectService().findMatching(OleLoanDocument.class, loanMap);
931 if (oleLoanDocumentList != null && oleLoanDocumentList.size() > 0 && oleLoanDocumentList.get(0) != null && oleLoanDocumentList.get(0).getOleRequestId() == null) {
932 if (oleLoanDocumentList.get(0).getLoanId() != null) {
933 oleLoanDocumentList.get(0).setOleRequestId(oleDeliverRequestBo.getRequestId());
934 oleDeliverRequestBo.setLoanTransactionRecordNumber(oleLoanDocumentList.get(0).getLoanId());
935 }
936 businessObjectService.save(oleLoanDocumentList.get(0));
937
938 }
939 return oleDeliverRequestBo;
940 }
941
942
943
944
945
946
947
948 public void deleteRequest(String requestId, String itemUUID, String operatorId, String loanTransactionNumber, String reuestOutCome) {
949 LOG.debug("Inside deleteRequest");
950 Map<String, String> requestMap = new HashMap<String, String>();
951 Map<String, String> titleLevelRequestMap = new HashMap<String, String>();
952 List<OleDeliverRequestBo> titleLevelRequestBoList = null;
953 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_ID, requestId);
954 OleDeliverRequestBo oleDeliverRequestBo = createRequestHistoryRecord(requestId, operatorId, loanTransactionNumber, reuestOutCome);
955 if (oleDeliverRequestBo != null) {
956 if (oleDeliverRequestBo.getRequestLevel().equalsIgnoreCase("Item Level")) {
957 Map<String, String> itemMap = new HashMap<String, String>();
958 itemMap.put(OLEConstants.ITEM_UUID, itemUUID);
959 List<OleDeliverRequestBo> oleDeliverRequestDocumentsList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class, itemMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
960 getBusinessObjectService().delete(oleDeliverRequestDocumentsList);
961 int queuePosition = 1;
962 for (int i = 0; i < oleDeliverRequestDocumentsList.size(); i++) {
963 oleDeliverRequestDocumentsList.get(i).setBorrowerQueuePosition(queuePosition);
964 queuePosition = queuePosition + 1;
965 }
966 getBusinessObjectService().save(oleDeliverRequestDocumentsList);
967 } else if (oleDeliverRequestBo.getRequestLevel().equalsIgnoreCase("Title Level")) {
968 requestMap = new HashMap<String, String>();
969 requestMap.put("bibId", oleDeliverRequestBo.getBibId());
970 requestMap.put("borrowerBarcode", oleDeliverRequestBo.getBorrowerBarcode());
971 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
972 if (oleDeliverRequestBoList.size() > 0) {
973 for (OleDeliverRequestBo oleDeliverRequestBo1 : oleDeliverRequestBoList) {
974 titleLevelRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo1.getItemUuid());
975 getBusinessObjectService().delete(oleDeliverRequestBo1);
976 titleLevelRequestBoList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, titleLevelRequestMap);
977 int queuePosition = 1;
978 for (int i = 0; i < titleLevelRequestBoList.size(); i++) {
979 titleLevelRequestBoList.get(i).setBorrowerQueuePosition(queuePosition);
980 queuePosition = queuePosition + 1;
981 }
982 getBusinessObjectService().save(titleLevelRequestBoList);
983 }
984 }
985 }
986 }
987
988 }
989
990
991 public void deleteTitleLevelIndividualRequests(OleDeliverRequestBo oleDeliverRequestBo) {
992 Map<String, String> requestMap = new HashMap<String, String>();
993 Map<String, String> titleLevelRequestMap = new HashMap<String, String>();
994 List<OleDeliverRequestBo> titleLevelRequestBoList = null;
995 requestMap = new HashMap<String, String>();
996 requestMap.put("bibId", oleDeliverRequestBo.getBibId());
997 requestMap.put("borrowerBarcode", oleDeliverRequestBo.getBorrowerBarcode());
998 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
999 if (oleDeliverRequestBoList.size() > 0) {
1000 for (OleDeliverRequestBo oleDeliverRequestBo1 : oleDeliverRequestBoList) {
1001 titleLevelRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo1.getItemUuid());
1002 getBusinessObjectService().delete(oleDeliverRequestBo1);
1003 titleLevelRequestBoList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, titleLevelRequestMap);
1004 int queuePosition = 1;
1005 for (int i = 0; i < titleLevelRequestBoList.size(); i++) {
1006 titleLevelRequestBoList.get(i).setBorrowerQueuePosition(queuePosition);
1007 queuePosition = queuePosition + 1;
1008 }
1009 getBusinessObjectService().save(titleLevelRequestBoList);
1010 }
1011 }
1012 }
1013
1014
1015
1016
1017
1018
1019
1020 public OleItemSearch getItemDetails(String itemUUID) {
1021 LOG.debug("Inside getItemDetails");
1022 OleItemSearch oleItemSearch = getItemDetailsForPatron(itemUUID);
1023 try {
1024
1025 String itemXml = getLoanProcessor().getItemXML(itemUUID);
1026 Item oleItem = getLoanProcessor().getItemPojo(itemXml);
1027 if (oleItem != null && oleItem.getItemType() != null) {
1028 oleItemSearch.setItemType(processItemType(oleItem.getItemType().getCodeValue()));
1029 }
1030 oleItemSearch.setCopyNumber(oleItem.getCopyNumber());
1031 if (oleItem.getItemStatus() != null) {
1032 oleItemSearch.setItemStatus(oleItem.getItemStatus().getCodeValue());
1033 }
1034 oleItemSearch.setShelvingLocation(getShelvingLocation(oleItem.getLocation()));
1035 oleItemSearch.setVolumeNumber(oleItem.getVolumeNumber());
1036 } catch (Exception e) {
1037 LOG.error("Not able to retrieve information from the docstore for the Item Barcode : " + itemUUID, e);
1038 }
1039 return oleItemSearch;
1040 }
1041
1042
1043
1044
1045
1046
1047
1048 public OleItemSearch getItemDetailsForPatron(String itemUUID) {
1049 LOG.debug("Inside getItemDetailsForPatron");
1050 OleItemSearch oleItemSearch;
1051 try {
1052
1053 Map<String, String> itemMap = new HashMap<String, String>();
1054
1055 OleItemSearch itemSearchList = getDocstoreUtil().getOleItemSearchList(itemUUID);
1056 if (itemSearchList != null) {
1057 return oleItemSearch = itemSearchList;
1058 }
1059 } catch (NullPointerException e) {
1060 LOG.error("No item details available for the Item Barcode : " + itemUUID, e);
1061 }
1062
1063 return new OleItemSearch();
1064
1065 }
1066
1067
1068
1069
1070
1071
1072
1073 public OleDeliverRequestBo reOrderQueuePosition(OleDeliverRequestBo oleDeliverRequestBo) {
1074 LOG.debug("Inside reOrderQueuePosition");
1075 List<OleDeliverRequestBo> existingRequest = new ArrayList<OleDeliverRequestBo>();
1076 String queue = getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.REQUEST_QUEUE);
1077 List<String> orderQueue = new ArrayList<String>();
1078 String[] queueArray = queue.split(";");
1079 for (int i = 0; i < queueArray.length; i++) {
1080 orderQueue.add(queueArray[i]);
1081 }
1082 List<OleDeliverRequestBo> finalList = new ArrayList<OleDeliverRequestBo>();
1083 Map<String, String> recallRequestMap = new HashMap<String, String>();
1084 recallRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
1085 recallRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "1");
1086 Map<String, String> recallHoldRequestMap = new HashMap<String, String>();
1087 recallHoldRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
1088 recallHoldRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "2");
1089 Map<String, String> holdRequestMap = new HashMap<String, String>();
1090 holdRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
1091 holdRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "3");
1092 Map<String, String> holdHoldRequestMap = new HashMap<String, String>();
1093 holdHoldRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
1094 holdHoldRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "4");
1095 Map<String, String> pageRequestMap = new HashMap<String, String>();
1096 pageRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
1097 pageRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "5");
1098 Map<String, String> pageHoldRequestMap = new HashMap<String, String>();
1099 pageHoldRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
1100 pageHoldRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "6");
1101 Map<String, String> copyRequestMap = new HashMap<String, String>();
1102 copyRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
1103 copyRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "7");
1104 Map<String, String> inTransitRequestMap = new HashMap<String, String>();
1105 inTransitRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
1106 inTransitRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "8");
1107 Map<String, String> asrRequestMap = new HashMap<String, String>();
1108 asrRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
1109 asrRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "9");
1110 List<OleDeliverRequestBo> recallList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class, recallRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
1111 List<OleDeliverRequestBo> recallHoldList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class, recallHoldRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
1112 List<OleDeliverRequestBo> holdList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class, holdRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
1113 List<OleDeliverRequestBo> holdHoldList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class, holdHoldRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
1114 List<OleDeliverRequestBo> pageList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class, pageRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
1115 List<OleDeliverRequestBo> pageHoldList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class, pageHoldRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
1116 List<OleDeliverRequestBo> copyList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class, copyRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
1117 List<OleDeliverRequestBo> inTransitList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class, inTransitRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
1118 List<OleDeliverRequestBo> asrList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class, asrRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
1119 if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.RECALL_DELIVERY)) {
1120 recallList.add(oleDeliverRequestBo);
1121 } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.HOLD_DELIVERY)) {
1122 holdList.add(oleDeliverRequestBo);
1123 } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.PAGE_DELIVERY)) {
1124 pageList.add(oleDeliverRequestBo);
1125 } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.COPY)) {
1126 copyList.add(oleDeliverRequestBo);
1127 } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.INTRANSIT)) {
1128 inTransitList.add(oleDeliverRequestBo);
1129 } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.RECALL_HOLD)) {
1130 recallHoldList.add(oleDeliverRequestBo);
1131 } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.HOLD_HOLD)) {
1132 holdHoldList.add(oleDeliverRequestBo);
1133 } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.PAGE_HOLD)) {
1134 pageHoldList.add(oleDeliverRequestBo);
1135 } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.ASR_REQUEST)) {
1136 asrList.add(oleDeliverRequestBo);
1137 }
1138 OleDeliverRequestBo oleDeliverRequestBo1;
1139 for (int i = 0; i < orderQueue.size(); i++) {
1140 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.RECALL) && recallList.size() > 0) {
1141 for (int x = 0; x < recallList.size(); x++) {
1142 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(recallList.get(x));
1143 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
1144 this.queuePosition = this.queuePosition + 1;
1145 finalList.add(oleDeliverRequestBo1);
1146
1147 }
1148 }
1149 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.HOLD) && holdList.size() > 0) {
1150 for (int x = 0; x < holdList.size(); x++) {
1151 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(holdList.get(x));
1152 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
1153 this.queuePosition = this.queuePosition + 1;
1154 finalList.add(oleDeliverRequestBo1);
1155
1156 }
1157 }
1158 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.PAGE) && pageList.size() > 0) {
1159 for (int x = 0; x < pageList.size(); x++) {
1160 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(pageList.get(x));
1161 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
1162 this.queuePosition = this.queuePosition + 1;
1163 finalList.add(oleDeliverRequestBo1);
1164 }
1165 }
1166 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.RECALL) && recallHoldList.size() > 0) {
1167 for (int x = 0; x < recallHoldList.size(); x++) {
1168 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(recallHoldList.get(x));
1169 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
1170 this.queuePosition = this.queuePosition + 1;
1171 finalList.add(oleDeliverRequestBo1);
1172
1173 }
1174 }
1175 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.HOLD) && holdHoldList.size() > 0) {
1176 for (int x = 0; x < holdHoldList.size(); x++) {
1177 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(holdHoldList.get(x));
1178 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
1179 this.queuePosition = this.queuePosition + 1;
1180 finalList.add(oleDeliverRequestBo1);
1181
1182 }
1183 }
1184 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.PAGE) && pageHoldList.size() > 0) {
1185 for (int x = 0; x < pageHoldList.size(); x++) {
1186 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(pageHoldList.get(x));
1187 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
1188 this.queuePosition = this.queuePosition + 1;
1189 finalList.add(oleDeliverRequestBo1);
1190 }
1191 }
1192 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.COPY) && copyList.size() > 0) {
1193 for (int x = 0; x < copyList.size(); x++) {
1194 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(copyList.get(x));
1195 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
1196 this.queuePosition = this.queuePosition + 1;
1197 finalList.add(oleDeliverRequestBo1);
1198
1199 }
1200 }
1201 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.INTRANSIT) && inTransitList.size() > 0) {
1202 for (int x = 0; x < inTransitList.size(); x++) {
1203 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(inTransitList.get(x));
1204 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
1205 this.queuePosition = this.queuePosition + 1;
1206 finalList.add(oleDeliverRequestBo1);
1207
1208 }
1209 }
1210 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.ASR_REQUEST) && asrList.size() > 0) {
1211 for (int x = 0; x < asrList.size(); x++) {
1212 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(asrList.get(x));
1213 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
1214 this.queuePosition = this.queuePosition + 1;
1215 finalList.add(oleDeliverRequestBo1);
1216
1217 }
1218 }
1219 }
1220 for (int i = 0; i < finalList.size(); i++) {
1221 if (finalList.get(i).getRequestId() == null) {
1222 oleDeliverRequestBo.setBorrowerQueuePosition(finalList.get(i).getBorrowerQueuePosition());
1223 finalList.remove(finalList.get(i));
1224 }
1225 }
1226 getBusinessObjectService().save(finalList);
1227 this.queuePosition = 0;
1228 oleDeliverRequestBo.setRequestId(KRADServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber("OLE_DLVR_RQST_S").toString());
1229 return oleDeliverRequestBo;
1230 }
1231
1232
1233
1234
1235
1236
1237
1238 public boolean isItemAvailbleInDocstore(OleDeliverRequestBo oleDeliverRequestBo) {
1239 LOG.debug("Inside isItemAvailbleInDocstore");
1240 boolean available = false;
1241 Map<String, String> itemMap = new HashMap<String, String>();
1242 try {
1243 String itemUUID = "";
1244 org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
1245 org.kuali.ole.docstore.common.search.SearchParams search_Params = new org.kuali.ole.docstore.common.search.SearchParams();
1246 SearchResponse searchResponse = null;
1247 search_Params.getSearchConditions().add(search_Params.buildSearchCondition("phrase", search_Params.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), item.ITEM_BARCODE, oleDeliverRequestBo.getItemId()), ""));
1248
1249
1250 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), "id"));
1251 ;
1252
1253
1254
1255
1256
1257 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(search_Params);
1258 for (SearchResult searchResult : searchResponse.getSearchResults()) {
1259 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
1260 String fieldName = searchResultField.getFieldName();
1261 String fieldValue = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
1262
1263 if (fieldName.equalsIgnoreCase("id") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
1264 itemUUID = fieldValue;
1265 }
1266
1267 }
1268 }
1269
1270
1271 oleDeliverRequestBo.setItemUuid(itemUUID);
1272 } catch (Exception e) {
1273 LOG.error("Exception", e);
1274
1275 }
1276
1277 OleItemSearch itemSearchList = getDocstoreUtil().getOleItemSearchList(oleDeliverRequestBo.getItemUuid());
1278 if (itemSearchList != null) {
1279 oleDeliverRequestBo.setTitle(itemSearchList.getTitle());
1280 oleDeliverRequestBo.setAuthor(itemSearchList.getAuthor());
1281 oleDeliverRequestBo.setCallNumber(itemSearchList.getCallNumber());
1282 oleDeliverRequestBo.setItemType(itemSearchList.getItemType());
1283 }
1284 try {
1285
1286 String itemXml = getLoanProcessor().getItemXML(oleDeliverRequestBo.getItemUuid());
1287 Item oleItem = getLoanProcessor().getItemPojo(itemXml);
1288
1289 oleDeliverRequestBo.setCopyNumber(oleItem.getCopyNumber());
1290 if (oleItem.getItemStatus() != null) {
1291 oleDeliverRequestBo.setItemStatus(oleItem.getItemStatus().getCodeValue());
1292 }
1293 oleDeliverRequestBo.setShelvingLocation(getShelvingLocation(oleItem.getLocation()));
1294 available = true;
1295 } catch (Exception e) {
1296 LOG.error(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVAL_LOC), e);
1297 }
1298 return available;
1299 }
1300
1301 public OleDeliverRequestBo populateItemDetailsToRequest(OleDeliverRequestBo oleDeliverRequestBo, OleItemSearch oleItemSearch) {
1302 LOG.debug("Inside populateItemDetailsToRequest");
1303 if (oleDeliverRequestBo != null && oleItemSearch != null) {
1304 oleDeliverRequestBo.setAuthor(oleItemSearch.getAuthor());
1305 oleDeliverRequestBo.setTitle(oleItemSearch.getTitle());
1306 oleDeliverRequestBo.setCallNumber(oleItemSearch.getCallNumber());
1307 oleDeliverRequestBo.setCopyNumber(oleItemSearch.getCopyNumber());
1308 oleDeliverRequestBo.setItemType(oleItemSearch.getItemType());
1309 oleDeliverRequestBo.setItemStatus(oleItemSearch.getItemStatus());
1310 oleItemSearch.setShelvingLocation(oleDeliverRequestBo.getShelvingLocation());
1311 }
1312 return oleDeliverRequestBo;
1313 }
1314
1315
1316 public OleDeliverRequestBo generateRecallNotice(OleDeliverRequestBo oleDeliverRequestBo) throws Exception {
1317 Map<String, String> loanMap = new HashMap<String, String>();
1318 loanMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
1319 List<OleLoanDocument> loanDocuments = (List<OleLoanDocument>) getBusinessObjectService().findMatching(OleLoanDocument.class, loanMap);
1320 OleLoanDocument oleLoanDocument = loanDocuments.get(0);
1321 Map<String, String> patronMap = new HashMap<String, String>();
1322 patronMap.put(OLEConstants.OleDeliverRequest.PATRON_ID, oleLoanDocument.getPatronId());
1323 List<OlePatronDocument> patronDocumentList = (List<OlePatronDocument>) getBusinessObjectService().findMatching(OlePatronDocument.class, patronMap);
1324 OleNoticeBo oleNoticeBo = new OleNoticeBo();
1325 Item item;
1326 if (patronDocumentList.size() > 0) {
1327 OlePatronDocument olePatronDocument = patronDocumentList.get(0);
1328 EntityTypeContactInfoBo entityTypeContactInfoBo = olePatronDocument.getEntity().getEntityTypeContactInfos().get(0);
1329 oleNoticeBo.setPatronName(olePatronDocument.getEntity().getNames().get(0).getFirstName() + " " + olePatronDocument.getEntity().getNames().get(0).getLastName());
1330 oleNoticeBo.setPatronAddress(getOlePatronHelperService().getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronPreferredAddress(entityTypeContactInfoBo) : "");
1331 oleNoticeBo.setPatronEmailAddress(getOlePatronHelperService().getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronHomeEmailId(entityTypeContactInfoBo) : "");
1332 oleNoticeBo.setPatronPhoneNumber(getOlePatronHelperService().getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
1333 }
1334 oleNoticeBo.setAuthor(oleDeliverRequestBo.getAuthor() != null ? oleDeliverRequestBo.getAuthor() : "");
1335 oleNoticeBo.setCirculationDeskAddress("");
1336 oleNoticeBo.setCirculationDeskName("");
1337 oleNoticeBo.setCirculationDeskEmailAddress("");
1338 oleNoticeBo.setCirculationDeskPhoneNumber("");
1339 oleNoticeBo.setItemCallNumber(oleDeliverRequestBo.getCallNumber() != null ? oleDeliverRequestBo.getCallNumber() : "");
1340 oleNoticeBo.setItemShelvingLocation(oleDeliverRequestBo.getShelvingLocation() != null ? oleDeliverRequestBo.getShelvingLocation() : "");
1341 oleNoticeBo.setItemId(oleDeliverRequestBo.getItemId() != null ? oleDeliverRequestBo.getItemId() : "");
1342 oleNoticeBo.setTitle(oleDeliverRequestBo.getTitle() != null ? oleDeliverRequestBo.getTitle() : "");
1343 oleNoticeBo.setOleItem(getItem(oleDeliverRequestBo.getItemUuid()));
1344 oleNoticeBo.setOlePatron(oleDeliverRequestBo.getOlePatron());
1345 oleNoticeBo.setVolumeNumber(oleDeliverRequestBo.getVolumeNumber() != null ? oleDeliverRequestBo.getVolumeNumber() : "");
1346 oleNoticeBo.setOriginalDueDate(oleDeliverRequestBo.getOriginalDueDate());
1347 oleNoticeBo.setNewDueDate(oleDeliverRequestBo.getNewDueDate());
1348 String volumeNumber = oleDeliverRequestBo.getEnumeration() != null ? oleDeliverRequestBo.getEnumeration() : "";
1349 String chronology = oleDeliverRequestBo.getChronology() != null ? oleDeliverRequestBo.getChronology() : "";
1350 String copyNumber = oleDeliverRequestBo.getCopyNumber() != null ? oleDeliverRequestBo.getCopyNumber() : "";
1351 oleNoticeBo.setEnumeration(oleDeliverRequestBo.getEnumeration());
1352 oleNoticeBo.setChronology(oleDeliverRequestBo.getChronology());
1353 oleNoticeBo.setCopyNumber(oleDeliverRequestBo.getCopyNumber());
1354 oleNoticeBo.setVolumeIssueCopyNumber(volumeNumber + "/" + chronology + "/" + copyNumber);
1355
1356
1357
1358
1359
1360 oleNoticeBo.setNoticeName(OLEConstants.NOTICE_RECALL);
1361 String noticeContent = getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.RECALL_BODY);
1362 oleNoticeBo.setNoticeSpecificContent(noticeContent);
1363
1364 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
1365 List<OleNoticeBo> oleNoticeBos = new ArrayList<OleNoticeBo>();
1366 String noticeType = getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.RECALL_NOTICE_TYPE);
1367 oleNoticeBos.add(oleNoticeBo);
1368 if (noticeType.equalsIgnoreCase(OLEConstants.EMAIL)) {
1369 if (oleNoticeBo.getPatronEmailAddress() != null && !oleNoticeBo.getPatronEmailAddress().isEmpty()) {
1370 List list = oleDeliverBatchService.getNoticeForPatron(oleNoticeBos);
1371 String content = list.toString();
1372 content = content.replace('[', ' ');
1373 content = content.replace(']', ' ');
1374 try{
1375 if (!content.trim().equals("")) {
1376 OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
1377 String replyToEmail = getCircDeskLocationResolver().getReplyToEmail(oleNoticeBo.getItemShelvingLocation());
1378 if (replyToEmail != null) {
1379 oleMailer.sendEmail(new EmailFrom(replyToEmail), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(content), true);
1380 oleDeliverRequestBo.setRecallNoticeSentDate(new java.sql.Date(System.currentTimeMillis()));
1381 } else {
1382 String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
1383 if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
1384 fromAddress = OLEConstants.KUALI_MAIL;
1385 }
1386 oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(content), true);
1387 oleDeliverRequestBo.setRecallNoticeSentDate(new java.sql.Date(System.currentTimeMillis()));
1388 }
1389 } else {
1390 for (OleNoticeBo oleNoticeBo1 : oleNoticeBos) {
1391 if (LOG.isDebugEnabled()) {
1392 LOG.debug("Notice Type :" + oleNoticeBo1.getNoticeName() + " " + "Item Barcode : " + oleNoticeBo1.getItemId() + " " + "Patron Name :" + oleNoticeBo1.getPatronName());
1393 }
1394 }
1395 }}catch(Exception e){
1396 LOG.info("Exception occured while sending Recall Notice to the patron : "+oleDeliverRequestBo.getPatronName() + "with barcode :"+oleDeliverRequestBo.getBorrowerId() +"for the loaned item having barcode : "+oleDeliverRequestBo.getItemId());
1397 LOG.error(e,e);
1398 }
1399
1400 if (LOG.isDebugEnabled()) {
1401 LOG.debug("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
1402 }
1403
1404
1405
1406
1407 }
1408 } else if (noticeType.equalsIgnoreCase(OLEConstants.SMS)) {
1409
1410 Map map = oleDeliverBatchService.getSMSForPatron(oleNoticeBos);
1411 HashMap sms = (HashMap) map.get(OLEConstants.OleDeliverRequest.RECALL);
1412 Iterator it = sms.entrySet().iterator();
1413 while (it.hasNext()) {
1414 Map.Entry pairs = (Map.Entry) it.next();
1415 String patronPhoneNumber = oleNoticeBo.getPatronPhoneNumber();
1416 OleSms oleSms = new OleSms();
1417 oleSms.sendSms("", patronPhoneNumber, (String) pairs.getValue());
1418 }
1419
1420 }
1421 if (noticeType.equalsIgnoreCase(OLEConstants.MAIL) || noticeType.equalsIgnoreCase(OLEConstants.EMAIL)) {
1422
1423 try{
1424 oleDeliverBatchService.getPdfNoticeForPatron(oleNoticeBos);
1425 oleDeliverRequestBo.setRecallNoticeSentDate(new java.sql.Date(System.currentTimeMillis()));
1426 }catch(Exception e){
1427 LOG.info("Exception occured while generating Recall Notice pdf to the patron : "+oleDeliverRequestBo.getPatronName() + "with barcode :"+oleDeliverRequestBo.getBorrowerId() +"for the loaned item having barcode : "+oleDeliverRequestBo.getItemId());
1428 }
1429 if (LOG.isDebugEnabled()) {
1430 LOG.debug("Recall Notice Pdf generated for item Id" + oleNoticeBo.getItemId());
1431 }
1432 }
1433
1434 return oleDeliverRequestBo;
1435 }
1436
1437
1438 public List<String> getList(String[] arrays) {
1439 List<String> resultList = new ArrayList<>();
1440 if (arrays != null && arrays.length > 0) {
1441 for (String arrayObj : arrays) {
1442 resultList.add(arrayObj);
1443 }
1444 }
1445 return resultList;
1446 }
1447
1448 public Map<String, String> getMap(String[] arrays) {
1449 Map<String, String> resultMap = new HashMap<String, String>();
1450 if (arrays != null && arrays.length > 0) {
1451 for (String arrayObj : arrays) {
1452 resultMap.put(arrayObj, arrayObj);
1453 }
1454 }
1455 return resultMap;
1456 }
1457
1458
1459 public void generateOnHoldNoticesBasedOnPickupLocation(String pickupLocationId) throws Exception {
1460
1461 List<OleDeliverRequestBo> finalDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>();
1462 OleLoanDocumentDaoOjb oleLoanDocumentDaoOjb = (OleLoanDocumentDaoOjb) SpringContext.getService("oleLoanDao");
1463 String requestTypeParameter = getLoanProcessor().getParameter(OLEConstants.ON_HOLD_NOTICE_REQUEST_TYPE);
1464 String onHoldItemStatusParameter = getLoanProcessor().getParameter(OLEConstants.ON_HOLD_NOTICE_ITEM_STATUS);
1465 List<String> requestTypeIds = new ArrayList<String>();
1466 List<String> requestTypeCodes = new ArrayList<String>();
1467 Map<String, String> itemStatuses = new HashMap<String, String>();
1468 if (requestTypeParameter != null && !requestTypeParameter.trim().isEmpty()) {
1469 String[] requestType = requestTypeParameter.split(";");
1470 requestTypeCodes = getList(requestType);
1471 requestTypeIds = oleLoanDocumentDaoOjb.getRequestTypeIdsForHoldNotice(requestTypeCodes);
1472 }
1473 if (onHoldItemStatusParameter != null && !onHoldItemStatusParameter.trim().isEmpty()) {
1474 String[] itemStatus = onHoldItemStatusParameter.split(";");
1475 itemStatuses = getMap(itemStatus);
1476 }
1477 Collection oleDeliverRequestBoList = oleLoanDocumentDaoOjb.getHoldRequestsByPickupLocation(requestTypeIds, pickupLocationId);
1478 OleDeliverRequestBo oleDeliverRequestBo;
1479 Set<String> circulationDeskIds = new HashSet<>();
1480 List<OleNoticeBo> noticesList = new ArrayList<OleNoticeBo>();
1481 EntityTypeContactInfoBo entityTypeContactInfoBo;
1482 OleNoticeBo oleNoticeBo;
1483 Item item;
1484 boolean firstTime = true;
1485 String patronId = "";
1486 String noticeTypeParam = getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.ONHOLD_NOTICE_TYPE);
1487 for (Object obj : oleDeliverRequestBoList) {
1488 OleDeliverRequestBo deliverRequestBo = (OleDeliverRequestBo) obj;
1489 if (firstTime) {
1490 patronId = deliverRequestBo.getBorrowerId();
1491 firstTime = false;
1492 }
1493 if (getDocstoreUtil().isItemAvailableInDocStore(deliverRequestBo)) {
1494 item = deliverRequestBo.getOleItem();
1495 OlePatronDocument olePatronDocument = deliverRequestBo.getOlePatron();
1496 if (item != null && item.getItemStatus() != null && item.getItemStatus().getCodeValue() != null && deliverRequestBo.getOnHoldNoticeSentDate() == null) {
1497 if (itemStatuses.containsKey(item.getItemStatus().getCodeValue())) {
1498 entityTypeContactInfoBo = deliverRequestBo.getOlePatron().getEntity().getEntityTypeContactInfos().get(0);
1499 oleNoticeBo = new OleNoticeBo();
1500 oleNoticeBo.setAuthor(deliverRequestBo.getAuthor());
1501 oleNoticeBo.setCirculationDeskAddress("");
1502 oleNoticeBo.setCirculationDeskName("");
1503 oleNoticeBo.setCirculationDeskEmailAddress("");
1504 oleNoticeBo.setCirculationDeskPhoneNumber("");
1505 oleNoticeBo.setPatronName(deliverRequestBo.getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + deliverRequestBo.getOlePatron().getEntity().getNames().get(0).getLastName());
1506 oleNoticeBo.setPatronAddress(getOlePatronHelperService().getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronPreferredAddress(entityTypeContactInfoBo) : "");
1507 oleNoticeBo.setPatronEmailAddress(getOlePatronHelperService().getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronHomeEmailId(entityTypeContactInfoBo) : "");
1508 oleNoticeBo.setPatronPhoneNumber(getOlePatronHelperService().getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
1509 oleNoticeBo.setItemCallNumber(deliverRequestBo.getCallNumber() != null ? deliverRequestBo.getCallNumber() : "");
1510 oleNoticeBo.setItemShelvingLocation(deliverRequestBo.getShelvingLocation() != null ? deliverRequestBo.getShelvingLocation() : "");
1511 oleNoticeBo.setItemId(deliverRequestBo.getItemId() != null ? deliverRequestBo.getItemId() : "");
1512 oleNoticeBo.setTitle(deliverRequestBo.getTitle() != null ? deliverRequestBo.getTitle() : "");
1513 oleNoticeBo.setOleItem(item);
1514 oleNoticeBo.setOlePatron(deliverRequestBo.getOlePatron());
1515 oleNoticeBo.setVolumeNumber(item.getVolumeNumber() != null ? item.getVolumeNumber() : "");
1516 oleNoticeBo.setEnumeration(deliverRequestBo.getEnumeration());
1517 oleNoticeBo.setChronology(deliverRequestBo.getChronology());
1518 oleNoticeBo.setCopyNumber(deliverRequestBo.getCopyNumber());
1519 oleNoticeBo.setNewDueDate(new Date());
1520 oleNoticeBo.setOriginalDueDate(new Date());
1521 oleNoticeBo.setNoticeName(OLEConstants.NOTICE_ONHOLD);
1522 oleNoticeBo.setCirculationDeskName(deliverRequestBo.getOlePickUpLocation().getCirculationDeskPublicName());
1523 oleNoticeBo.setCirculationDeskReplyToEmail(deliverRequestBo.getOlePickUpLocation().getReplyToEmail());
1524 String circulationDeskId = deliverRequestBo.getPickUpLocationId();
1525 int noDays = 0;
1526 Map<String, String> mapCirculationDesk = new HashMap<String, String>();
1527 mapCirculationDesk.put(OLEConstants.OleCirculationDesk.OLE_CIRCULATION_DESK_ID, circulationDeskId);
1528 List<OleCirculationDesk> oleCirculationDesks = (List<OleCirculationDesk>) KRADServiceLocator.getBusinessObjectService().findMatching(OleCirculationDesk.class, mapCirculationDesk);
1529 if (oleCirculationDesks.size() > 0) {
1530 OleCirculationDesk oleCirculationDesk = oleCirculationDesks.get(0);
1531 noDays = Integer.parseInt(oleCirculationDesk.getOnHoldDays());
1532 }
1533 Calendar calendar = Calendar.getInstance();
1534 calendar.add(Calendar.DATE, noDays);
1535 Date date = calendar.getTime();
1536 oleNoticeBo.setExpiredOnHoldDate(date);
1537 deliverRequestBo.setHoldExpirationDate(new java.sql.Date(date.getTime()));
1538
1539
1540
1541
1542
1543 String maxNumOfDays = deliverRequestBo.getOlePickUpLocation().getOnHoldDays() != null ? deliverRequestBo.getOlePickUpLocation().getOnHoldDays() : getLoanProcessor().getParameter(OLEConstants.MAX_NO_OF_DAYS_ON_HOLD);
1544 Integer maxNumberOfDaysOnHold = new Integer(maxNumOfDays);
1545 oleNoticeBo.setOnHoldDueDate(dateAdd(deliverRequestBo.getCreateDate(), maxNumberOfDaysOnHold));
1546 String noticeContent = getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.ONHOLD_BODY);
1547 oleNoticeBo.setNoticeSpecificContent(noticeContent);
1548 String agendaName = OLEConstants.BATCH_PROGRAM_AGENDA;
1549 HashMap<String, Object> termValues = new HashMap<String, Object>();
1550 OleCirculationDesk oleCirculationDesk = deliverRequestBo.getOlePickUpLocation();
1551 String deskLocation = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskCode() : "";
1552 String deskLocationName = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskPublicName() : "";
1553 termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode());
1554 termValues.put(OLEConstants.DESK_LOCATION, deskLocation);
1555 termValues.put(OLEConstants.NOTICE, OLEConstants.NOTICE_ONHOLD);
1556 if (LOG.isDebugEnabled()) {
1557 LOG.debug("termValues.toString()" + termValues.toString());
1558 }
1559 EngineResults engineResults = loanProcessor.getEngineResults(agendaName, termValues);
1560 String noticeType = (String) engineResults.getAttribute(OLEConstants.NOTICE_TYPE);
1561 if (LOG.isDebugEnabled()) {
1562 LOG.debug("**************" + noticeType);
1563 }
1564 noticeType = noticeType != null ? noticeType : noticeTypeParam;
1565 oleNoticeBo.setNoticeType(noticeType);
1566 if (!patronId.equalsIgnoreCase(deliverRequestBo.getBorrowerId()) && noticesList.size() > 0) {
1567 String replyToEmail = null;
1568 if (circulationDeskIds.size() == 1) {
1569 OleCirculationDesk circulationDesk = getCircDeskLocationResolver().getOleCirculationDesk(circulationDeskIds.iterator().next());
1570 if (circulationDesk != null && StringUtils.isNotBlank(circulationDesk.getReplyToEmail())) {
1571 replyToEmail = circulationDesk.getReplyToEmail();
1572 }
1573 }
1574 generateNoticesBasedOnNoticeType(noticesList, OLEConstants.NOTICE_ONHOLD, replyToEmail);
1575 patronId = deliverRequestBo.getBorrowerId();
1576 circulationDeskIds = new HashSet<>();
1577 noticesList = new ArrayList<>();
1578 }
1579 if (deliverRequestBo.getOlePickUpLocation() != null && StringUtils.isNotBlank(deliverRequestBo.getOlePickUpLocation().getCirculationDeskId())) {
1580 circulationDeskIds.add(deliverRequestBo.getOlePickUpLocation().getCirculationDeskId());
1581 }
1582 noticesList.add(oleNoticeBo);
1583
1584 deliverRequestBo.setOleItem(null);
1585 oleDeliverRequestBo = (OleDeliverRequestBo) ObjectUtils.deepCopy(deliverRequestBo);
1586 oleDeliverRequestBo.setOnHoldNoticeSentDate(new java.sql.Date(System.currentTimeMillis()));
1587 finalDeliverRequestBoList.add(oleDeliverRequestBo);
1588 }
1589 }
1590 }
1591 }
1592 if (noticesList.size() > 0) {
1593 String replyToEmail = null;
1594 if (circulationDeskIds.size() == 1) {
1595 OleCirculationDesk circulationDesk = getCircDeskLocationResolver().getOleCirculationDesk(circulationDeskIds.iterator().next());
1596 if (circulationDesk != null && StringUtils.isNotBlank(circulationDesk.getReplyToEmail())) {
1597 replyToEmail = circulationDesk.getReplyToEmail();
1598 }
1599 }
1600 generateNoticesBasedOnNoticeType(noticesList, OLEConstants.NOTICE_ONHOLD, replyToEmail);
1601 }
1602 getBusinessObjectService().save(finalDeliverRequestBoList);
1603 }
1604
1605
1606 public void generateOnHoldNotice() throws Exception {
1607
1608 List<OleDeliverRequestBo> finalDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>();
1609 OleLoanDocumentDaoOjb oleLoanDocumentDaoOjb = (OleLoanDocumentDaoOjb) SpringContext.getService("oleLoanDao");
1610 String requestTypeParameter = getLoanProcessor().getParameter(OLEConstants.ON_HOLD_NOTICE_REQUEST_TYPE);
1611 String onHoldItemStatusParameter = getLoanProcessor().getParameter(OLEConstants.ON_HOLD_NOTICE_ITEM_STATUS);
1612 List<String> requestTypeIds = new ArrayList<String>();
1613 List<String> requestTypeCodes = new ArrayList<String>();
1614 Map<String, String> itemStatuses = new HashMap<String, String>();
1615 if (requestTypeParameter != null && !requestTypeParameter.trim().isEmpty()) {
1616 String[] requestType = requestTypeParameter.split(";");
1617 requestTypeCodes = getList(requestType);
1618 requestTypeIds = oleLoanDocumentDaoOjb.getRequestTypeIdsForHoldNotice(requestTypeCodes);
1619 }
1620 if (onHoldItemStatusParameter != null && !onHoldItemStatusParameter.trim().isEmpty()) {
1621 String[] itemStatus = onHoldItemStatusParameter.split(";");
1622 itemStatuses = getMap(itemStatus);
1623 }
1624 Collection oleDeliverRequestBoList = oleLoanDocumentDaoOjb.getHoldRequests(requestTypeIds);
1625 OleDeliverRequestBo oleDeliverRequestBo;
1626 Set<String> circulationDeskIds = new HashSet<>();
1627 List<OleNoticeBo> noticesList = new ArrayList<OleNoticeBo>();
1628 EntityTypeContactInfoBo entityTypeContactInfoBo;
1629 OleNoticeBo oleNoticeBo;
1630 Item item;
1631 boolean firstTime = true;
1632 String patronId = "";
1633 String noticeTypeParam = getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.ONHOLD_NOTICE_TYPE);
1634 for (Object obj : oleDeliverRequestBoList) {
1635 OleDeliverRequestBo deliverRequestBo = (OleDeliverRequestBo) obj;
1636 if (firstTime) {
1637 patronId = deliverRequestBo.getBorrowerId();
1638 firstTime = false;
1639 }
1640 if (getDocstoreUtil().isItemAvailableInDocStore(deliverRequestBo)) {
1641 item = deliverRequestBo.getOleItem();
1642 OlePatronDocument olePatronDocument = deliverRequestBo.getOlePatron();
1643 if (item != null && item.getItemStatus() != null && item.getItemStatus().getCodeValue() != null && deliverRequestBo.getOnHoldNoticeSentDate() == null) {
1644 if (itemStatuses.containsKey(item.getItemStatus().getCodeValue())) {
1645 entityTypeContactInfoBo = deliverRequestBo.getOlePatron().getEntity().getEntityTypeContactInfos().get(0);
1646 oleNoticeBo = new OleNoticeBo();
1647 oleNoticeBo.setAuthor(deliverRequestBo.getAuthor());
1648 oleNoticeBo.setCirculationDeskAddress("");
1649 oleNoticeBo.setCirculationDeskName("");
1650 oleNoticeBo.setCirculationDeskEmailAddress("");
1651 oleNoticeBo.setCirculationDeskPhoneNumber("");
1652 oleNoticeBo.setPatronName(deliverRequestBo.getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + deliverRequestBo.getOlePatron().getEntity().getNames().get(0).getLastName());
1653 oleNoticeBo.setPatronAddress(getOlePatronHelperService().getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronPreferredAddress(entityTypeContactInfoBo) : "");
1654 oleNoticeBo.setPatronEmailAddress(getOlePatronHelperService().getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronHomeEmailId(entityTypeContactInfoBo) : "");
1655 oleNoticeBo.setPatronPhoneNumber(getOlePatronHelperService().getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
1656 oleNoticeBo.setItemCallNumber(deliverRequestBo.getCallNumber() != null ? deliverRequestBo.getCallNumber() : "");
1657 oleNoticeBo.setItemShelvingLocation(deliverRequestBo.getShelvingLocation() != null ? deliverRequestBo.getShelvingLocation() : "");
1658 oleNoticeBo.setItemId(deliverRequestBo.getItemId() != null ? deliverRequestBo.getItemId() : "");
1659 oleNoticeBo.setTitle(deliverRequestBo.getTitle() != null ? deliverRequestBo.getTitle() : "");
1660 oleNoticeBo.setChronology(deliverRequestBo.getChronology());
1661 oleNoticeBo.setOleItem(item);
1662 oleNoticeBo.setOlePatron(deliverRequestBo.getOlePatron());
1663 oleNoticeBo.setVolumeNumber(item.getVolumeNumber() != null ? item.getVolumeNumber() : "");
1664 oleNoticeBo.setNewDueDate(new Date());
1665 oleNoticeBo.setOriginalDueDate(new Date());
1666 oleNoticeBo.setCopyNumber(deliverRequestBo.getCopyNumber());
1667 oleNoticeBo.setEnumeration(deliverRequestBo.getEnumeration());
1668 oleNoticeBo.setChronology(deliverRequestBo.getChronology());
1669 oleNoticeBo.setNoticeName(OLEConstants.NOTICE_ONHOLD);
1670 oleNoticeBo.setCirculationDeskName(deliverRequestBo.getOlePickUpLocation().getCirculationDeskPublicName());
1671 oleNoticeBo.setCirculationDeskReplyToEmail(deliverRequestBo.getOlePickUpLocation().getReplyToEmail());
1672 String circulationDeskId = deliverRequestBo.getPickUpLocationId();
1673 int noDays = 0;
1674 Map<String, String> mapCirculationDesk = new HashMap<String, String>();
1675 mapCirculationDesk.put(OLEConstants.OleCirculationDesk.OLE_CIRCULATION_DESK_ID, circulationDeskId);
1676 List<OleCirculationDesk> oleCirculationDesks = (List<OleCirculationDesk>) KRADServiceLocator.getBusinessObjectService().findMatching(OleCirculationDesk.class, mapCirculationDesk);
1677 if (oleCirculationDesks.size() > 0) {
1678 OleCirculationDesk oleCirculationDesk = oleCirculationDesks.get(0);
1679 noDays = Integer.parseInt(oleCirculationDesk.getOnHoldDays());
1680 }
1681 Calendar calendar = Calendar.getInstance();
1682 calendar.add(Calendar.DATE, noDays);
1683 Date date = calendar.getTime();
1684 oleNoticeBo.setExpiredOnHoldDate(date);
1685 deliverRequestBo.setHoldExpirationDate(new java.sql.Date(date.getTime()));
1686 String maxNumOfDays = deliverRequestBo.getOlePickUpLocation().getOnHoldDays() != null ? deliverRequestBo.getOlePickUpLocation().getOnHoldDays() : getLoanProcessor().getParameter(OLEConstants.MAX_NO_OF_DAYS_ON_HOLD);
1687 Integer maxNumberOfDaysOnHold = new Integer(maxNumOfDays);
1688 oleNoticeBo.setOnHoldDueDate(dateAdd(deliverRequestBo.getCreateDate(), maxNumberOfDaysOnHold));
1689 String noticeContent = getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.ONHOLD_BODY);
1690 oleNoticeBo.setNoticeSpecificContent(noticeContent);
1691 String agendaName = OLEConstants.BATCH_PROGRAM_AGENDA;
1692 HashMap<String, Object> termValues = new HashMap<String, Object>();
1693 OleCirculationDesk oleCirculationDesk = deliverRequestBo.getOlePickUpLocation();
1694 String deskLocation = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskCode() : "";
1695 String deskLocationName = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskPublicName() : "";
1696 termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode());
1697 termValues.put(OLEConstants.DESK_LOCATION, deskLocation);
1698 termValues.put(OLEConstants.NOTICE, OLEConstants.NOTICE_ONHOLD);
1699 if (LOG.isDebugEnabled()) {
1700 LOG.debug("termValues.toString()" + termValues.toString());
1701 }
1702 EngineResults engineResults = loanProcessor.getEngineResults(agendaName, termValues);
1703 String noticeType = (String) engineResults.getAttribute(OLEConstants.NOTICE_TYPE);
1704 if (LOG.isDebugEnabled()) {
1705 LOG.debug("**************" + noticeType);
1706 }
1707 noticeType = noticeType != null ? noticeType : noticeTypeParam;
1708 oleNoticeBo.setNoticeType(noticeType);
1709 if (!patronId.equalsIgnoreCase(deliverRequestBo.getBorrowerId()) && noticesList.size() > 0) {
1710 String replyToEmail = null;
1711 if (circulationDeskIds.size() == 1) {
1712 OleCirculationDesk circulationDesk = getCircDeskLocationResolver().getOleCirculationDesk(circulationDeskIds.iterator().next());
1713 if (circulationDesk != null && StringUtils.isNotBlank(circulationDesk.getReplyToEmail())) {
1714 replyToEmail = circulationDesk.getReplyToEmail();
1715 }
1716 }
1717 generateNoticesBasedOnNoticeType(noticesList, OLEConstants.NOTICE_ONHOLD, replyToEmail);
1718 patronId = deliverRequestBo.getBorrowerId();
1719 circulationDeskIds = new HashSet<>();
1720 noticesList = new ArrayList<>();
1721 }
1722 if (deliverRequestBo.getOlePickUpLocation() != null && StringUtils.isNotBlank(deliverRequestBo.getOlePickUpLocation().getCirculationDeskId())) {
1723 circulationDeskIds.add(deliverRequestBo.getOlePickUpLocation().getCirculationDeskId());
1724 }
1725 noticesList.add(oleNoticeBo);
1726
1727 deliverRequestBo.setOleItem(null);
1728 oleDeliverRequestBo = (OleDeliverRequestBo) ObjectUtils.deepCopy(deliverRequestBo);
1729 oleDeliverRequestBo.setOnHoldNoticeSentDate(new java.sql.Date(System.currentTimeMillis()));
1730 finalDeliverRequestBoList.add(oleDeliverRequestBo);
1731 }
1732 }
1733 }
1734 }
1735 if (noticesList.size() > 0) {
1736 String replyToEmail = null;
1737 if (circulationDeskIds.size() == 1) {
1738 OleCirculationDesk circulationDesk = getCircDeskLocationResolver().getOleCirculationDesk(circulationDeskIds.iterator().next());
1739 if (circulationDesk != null && StringUtils.isNotBlank(circulationDesk.getReplyToEmail())) {
1740 replyToEmail = circulationDesk.getReplyToEmail();
1741 }
1742 }
1743 generateNoticesBasedOnNoticeType(noticesList, OLEConstants.NOTICE_ONHOLD, replyToEmail);
1744 }
1745 getBusinessObjectService().save(finalDeliverRequestBoList);
1746 }
1747
1748 private void generateNoticesBasedOnNoticeType(List<OleNoticeBo> noticesList, String noticeName, String replyToEmail) throws Exception {
1749 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
1750 OleNoticeBo oleNoticeBo = noticesList.get(0);
1751 String noticeType = oleNoticeBo.getNoticeType();
1752 if (noticeType != null && (noticeType.equalsIgnoreCase(OLEConstants.EMAIL) || noticeType.equalsIgnoreCase(OLEConstants.MAIL))) {
1753 if (LOG.isDebugEnabled()) {
1754 LOG.debug("noticesList.size()" + noticesList.size());
1755 }
1756 oleDeliverBatchService.getPdfNoticeForPatron(noticesList);
1757 }
1758 if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.EMAIL)) {
1759 if (oleNoticeBo.getPatronEmailAddress() != null && !oleNoticeBo.getPatronEmailAddress().isEmpty()) {
1760 List list = oleDeliverBatchService.getNoticeForPatron(noticesList);
1761 String content = list.toString();
1762 content = content.replace('[', ' ');
1763 content = content.replace(']', ' ');
1764 if (!content.trim().equals("")) {
1765 OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
1766 if (replyToEmail != null) {
1767 oleMailer.sendEmail(new EmailFrom(replyToEmail), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(content), true);
1768 } else {
1769 String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
1770 if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
1771 fromAddress = OLEConstants.KUALI_MAIL;
1772 }
1773 oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(content), true);
1774 }
1775 } else {
1776 if (LOG.isDebugEnabled()) {
1777 LOG.debug("Notice Details" + noticesList);
1778 }
1779 }
1780 if (LOG.isDebugEnabled()) {
1781 LOG.debug("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
1782 }
1783 }
1784 } else if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.SMS)) {
1785 Map map = oleDeliverBatchService.getSMSForPatron(noticesList);
1786 HashMap sms = (HashMap) map.get(noticeName);
1787 Iterator it = sms.entrySet().iterator();
1788 while (it.hasNext()) {
1789 Map.Entry pairs = (Map.Entry) it.next();
1790 String patronPhoneNumber = oleNoticeBo.getPatronPhoneNumber();
1791 OleSms oleSms = new OleSms();
1792 oleSms.sendSms("", patronPhoneNumber, (String) pairs.getValue());
1793 }
1794 }
1795 }
1796
1797 public void generateRequestExpirationNotice() throws Exception {
1798 OleLoanDocumentDaoOjb oleLoanDocumentDaoOjb = (OleLoanDocumentDaoOjb) SpringContext.getService("oleLoanDao");
1799 Collection oleDeliverRequestBoList = oleLoanDocumentDaoOjb.getExpiredRequests();
1800 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OleDeliverRequest.DATE_FORMAT);
1801 EntityTypeContactInfoBo entityTypeContactInfoBo;
1802 List<OleNoticeBo> noticesList = new ArrayList<OleNoticeBo>();
1803 Set<String> itemLocations = new HashSet<>();
1804 Item item;
1805 String noticeType = null;
1806 OleNoticeBo oleNoticeBo = new OleNoticeBo();
1807 boolean firstTime = true;
1808 String patronId = "";
1809 String noticeTypeParam = getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.RQST_EXPR_NOTICE_TYPE);
1810 if (oleDeliverRequestBoList.size() > 0) {
1811 for (Object obj : oleDeliverRequestBoList) {
1812 OleDeliverRequestBo deliverRequestBo = (OleDeliverRequestBo) obj;
1813 if (firstTime) {
1814 patronId = deliverRequestBo.getBorrowerId();
1815 firstTime = false;
1816 }
1817 if (getDocstoreUtil().isItemAvailableInDocStore(deliverRequestBo)) {
1818
1819 item = deliverRequestBo.getOleItem();
1820 if (LOG.isDebugEnabled()) {
1821 LOG.debug("Expiration Date :" + deliverRequestBo.getRequestExpiryDate());
1822 }
1823 if (deliverRequestBo.getOlePatron().isCourtesyNotice()) {
1824 if (LOG.isDebugEnabled()) {
1825 LOG.debug("Inside Expiration Date :" + deliverRequestBo.getRequestExpiryDate());
1826 }
1827 entityTypeContactInfoBo = deliverRequestBo.getOlePatron().getEntity().getEntityTypeContactInfos().get(0);
1828 oleNoticeBo = new OleNoticeBo();
1829 oleNoticeBo.setAuthor(deliverRequestBo.getAuthor());
1830 oleNoticeBo.setCirculationDeskAddress("");
1831 oleNoticeBo.setCirculationDeskName("");
1832 oleNoticeBo.setCirculationDeskEmailAddress("");
1833 oleNoticeBo.setCirculationDeskPhoneNumber("");
1834 oleNoticeBo.setPatronName(deliverRequestBo.getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + deliverRequestBo.getOlePatron().getEntity().getNames().get(0).getLastName());
1835 oleNoticeBo.setPatronAddress(getOlePatronHelperService().getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronPreferredAddress(entityTypeContactInfoBo) : "");
1836 oleNoticeBo.setPatronEmailAddress(getOlePatronHelperService().getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronHomeEmailId(entityTypeContactInfoBo) : "");
1837 oleNoticeBo.setPatronPhoneNumber(getOlePatronHelperService().getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
1838 oleNoticeBo.setItemCallNumber(deliverRequestBo.getCallNumber() != null ? deliverRequestBo.getCallNumber() : "");
1839 oleNoticeBo.setItemShelvingLocation(deliverRequestBo.getShelvingLocation() != null ? deliverRequestBo.getShelvingLocation() : "");
1840 oleNoticeBo.setItemId(deliverRequestBo.getItemId() != null ? deliverRequestBo.getItemId() : "");
1841 oleNoticeBo.setTitle(deliverRequestBo.getTitle() != null ? deliverRequestBo.getTitle() : "");
1842 oleNoticeBo.setOleItem(item);
1843 oleNoticeBo.setOlePatron(deliverRequestBo.getOlePatron());
1844 oleNoticeBo.setVolumeNumber(item.getVolumeNumber() != null ? item.getVolumeNumber() : "");
1845 oleNoticeBo.setNewDueDate(new Date());
1846 oleNoticeBo.setOriginalDueDate(new Date());
1847 oleNoticeBo.setCopyNumber(deliverRequestBo.getCopyNumber());
1848 oleNoticeBo.setEnumeration(deliverRequestBo.getEnumeration());
1849 oleNoticeBo.setChronology(deliverRequestBo.getChronology());
1850 oleNoticeBo.setNoticeName(OLEConstants.OleDeliverRequest.EXPIRED_REQUEST);
1851 String noticeContent = getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.EXP_HOLD_NOTICE_CONTENT);
1852 oleNoticeBo.setNoticeSpecificContent(noticeContent);
1853
1854 String agendaName = OLEConstants.BATCH_PROGRAM_AGENDA;
1855 HashMap<String, Object> termValues = new HashMap<String, Object>();
1856 OleCirculationDesk oleCirculationDesk = deliverRequestBo.getOlePickUpLocation();
1857 OlePatronDocument olePatronDocument = deliverRequestBo.getOlePatron();
1858 String deskLocation = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskCode() : "";
1859 String deskLocationName = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskPublicName() : "";
1860 termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode());
1861 termValues.put(OLEConstants.DESK_LOCATION, deskLocation);
1862 termValues.put(OLEConstants.NOTICE, OLEConstants.OleDeliverRequest.EXPIRED_REQUEST);
1863 if (LOG.isDebugEnabled()) {
1864 LOG.debug("termValues.toString()" + termValues.toString());
1865 }
1866 EngineResults engineResults = getLoanProcessor().getEngineResults(agendaName, termValues);
1867 noticeType = (String) engineResults.getAttribute(OLEConstants.NOTICE_TYPE);
1868 if (LOG.isDebugEnabled()) {
1869 LOG.debug("**************" + noticeType);
1870 }
1871 noticeType = noticeType != null ? noticeType : noticeTypeParam;
1872 oleNoticeBo.setNoticeType(noticeType);
1873 oleNoticeBo.setNoticeType(noticeType);
1874 if (!patronId.equalsIgnoreCase(deliverRequestBo.getBorrowerId()) && noticesList.size() > 0) {
1875 String replyToEmail = null;
1876 if (itemLocations.size() == 1) {
1877 replyToEmail = getCircDeskLocationResolver().getReplyToEmail(itemLocations.iterator().next());
1878 }
1879 generateNoticesBasedOnNoticeType(noticesList, OLEConstants.OleDeliverRequest.EXPIRED_REQUEST, replyToEmail);
1880 patronId = deliverRequestBo.getBorrowerId();
1881 noticesList = new ArrayList<>();
1882 itemLocations = new HashSet<>();
1883 }
1884 noticesList.add(oleNoticeBo);
1885 itemLocations.add(oleNoticeBo.getItemShelvingLocation());
1886 }
1887 }
1888 }
1889 if (noticesList.size() > 0) {
1890 String replyToEmail = null;
1891 if (itemLocations.size() == 1) {
1892 replyToEmail = getCircDeskLocationResolver().getReplyToEmail(itemLocations.iterator().next());
1893 }
1894 generateNoticesBasedOnNoticeType(noticesList, OLEConstants.OleDeliverRequest.EXPIRED_REQUEST, replyToEmail);
1895 }
1896 }
1897 }
1898
1899 private java.sql.Date dateAdd(java.sql.Date in, int daysToAdd) {
1900 if (in == null) {
1901 return null;
1902 }
1903 GregorianCalendar cal = new GregorianCalendar();
1904 cal.setTime(in);
1905 cal.add(Calendar.DAY_OF_MONTH, daysToAdd);
1906 return new java.sql.Date(cal.getTime().getTime());
1907 }
1908
1909 public void deletingExpiredRequests() {
1910 LOG.debug("Inside deletingExpiredRequests");
1911 List<OleDeliverRequestBo> oleDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>();
1912 List<OleDeliverRequestBo> newOleDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>();
1913 try {
1914 oleDeliverRequestBoList = (List<OleDeliverRequestBo>) getBusinessObjectService().findAll(OleDeliverRequestBo.class);
1915
1916 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OleDeliverRequest.DATE_FORMAT);
1917 for (int i = 0; i < oleDeliverRequestBoList.size(); i++) {
1918 try {
1919 if ((fmt.format(oleDeliverRequestBoList.get(i).getRequestExpiryDate())).compareTo(fmt.format(new Date(System.currentTimeMillis()))) < 0) {
1920
1921 deleteRequest(oleDeliverRequestBoList.get(i).getRequestId(), oleDeliverRequestBoList.get(i).getItemUuid(), oleDeliverRequestBoList.get(i).getOperatorCreateId(), oleDeliverRequestBoList.get(i).getLoanTransactionRecordNumber(), ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.REQUEST_EXPIRED));
1922 }
1923 } catch (Exception e) {
1924 LOG.info("Exception occured while deleting the request with request Id : " + oleDeliverRequestBoList.get(i).getRequestId());
1925 LOG.error(e, e);
1926 }
1927 }
1928
1929 } catch (Exception e) {
1930
1931 LOG.error("Exception while deleting expired requests", e);
1932 }
1933 }
1934
1935 private Item getItem(String itemUUID) {
1936 LOG.debug("Inside getItem");
1937 try {
1938
1939 String itemXml = getLoanProcessor().getItemXML(itemUUID);
1940 Item oleItem = getLoanProcessor().getItemPojo(itemXml);
1941 return oleItem;
1942 } catch (Exception e) {
1943 LOG.error("Item not available in doc store", e);
1944 }
1945 return null;
1946 }
1947
1948
1949 private OleNoticeBo setPatronDetailsForNotice(OleNoticeBo oleNoticeBo, OlePatronDocument olePatronDocument) {
1950 LOG.debug("Inside setPatronDetailsForNotice");
1951 if (oleNoticeBo.getAuthor() != null && olePatronDocument.getOlePatronId() != null) {
1952 oleNoticeBo.setPatronName(olePatronDocument.getName().getFirstName());
1953 if (olePatronDocument.getAddresses().size() > 0) {
1954 oleNoticeBo.setPatronAddress(olePatronDocument.getAddresses().get(0).getLine1() + "/n" + olePatronDocument.getAddresses().get(0).getLine2() + "/n" + olePatronDocument.getAddresses().get(0).getCity());
1955 }
1956 oleNoticeBo.setPatronEmailAddress(olePatronDocument.getEmailAddress());
1957 oleNoticeBo.setPatronPhoneNumber(olePatronDocument.getPhoneNumber());
1958 }
1959 return oleNoticeBo;
1960 }
1961
1962
1963 private OleDeliverRequestBo createRequestHistoryRecord(String requestId, String OperatorId, String loanTransactionNumber, String reuestOutCome) {
1964 LOG.debug("Inside createRequestHistoryRecord");
1965 Map<String, String> requestMap = new HashMap<String, String>();
1966 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_ID, requestId);
1967 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, requestMap);
1968 OleDeliverRequestBo oleDeliverRequestBo = null;
1969 if (oleDeliverRequestBoList.size() > 0) {
1970 oleDeliverRequestBo = oleDeliverRequestBoList.get(0);
1971 OleDeliverRequestHistoryRecord oleDeliverRequestHistoryRecord = new OleDeliverRequestHistoryRecord();
1972 oleDeliverRequestHistoryRecord.setRequestId(oleDeliverRequestBo.getRequestId());
1973 oleDeliverRequestHistoryRecord.setPatronId(oleDeliverRequestBo.getOlePatron() != null ? oleDeliverRequestBo.getOlePatron().getOlePatronId() : null);
1974 oleDeliverRequestHistoryRecord.setItemId(oleDeliverRequestBo.getItemId());
1975 oleDeliverRequestHistoryRecord.setArchiveDate(new java.sql.Date(System.currentTimeMillis()));
1976 oleDeliverRequestHistoryRecord.setPickUpLocationCode(oleDeliverRequestBo.getPickUpLocationCode());
1977 oleDeliverRequestHistoryRecord.setCreateDate(oleDeliverRequestBo.getCreateDate());
1978 if (StringUtils.isNotBlank(OperatorId)) {
1979 oleDeliverRequestHistoryRecord.setOperatorId(OperatorId);
1980 } else {
1981 oleDeliverRequestHistoryRecord.setOperatorId(" ");
1982 }
1983 oleDeliverRequestHistoryRecord.setDeliverRequestTypeCode(oleDeliverRequestBo.getRequestTypeCode());
1984 oleDeliverRequestHistoryRecord.setPoLineItemNumber("");
1985 oleDeliverRequestHistoryRecord.setLoanTransactionId(loanTransactionNumber);
1986 oleDeliverRequestHistoryRecord.setRequestOutComeStatus(reuestOutCome);
1987
1988 getBusinessObjectService().save(oleDeliverRequestHistoryRecord);
1989 getBusinessObjectService().delete(oleDeliverRequestBoList);
1990 }
1991 return oleDeliverRequestBo;
1992 }
1993
1994 public OleDeliverRequestBo getOleDeliverRequestBo(String itemUUID) {
1995
1996 LOG.debug("Inside getOleDeliverRequestBo method");
1997 Map<String, String> requestMap = new HashMap<String, String>();
1998 requestMap.put(OLEConstants.ITEM_UUID, itemUUID);
1999 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, requestMap);
2000 if (oleDeliverRequestBoList.size() > 0)
2001 return oleDeliverRequestBoList.get(0);
2002 return null;
2003 }
2004
2005 private static int determineDifferenceInDays(Date currentDate, Date dueDate) {
2006 Calendar calendar1 = Calendar.getInstance();
2007 calendar1.setTime(dueDate);
2008 Calendar calendar2 = Calendar.getInstance();
2009 calendar2.setTime(currentDate);
2010 long diffInMillis = calendar2.getTimeInMillis() - calendar1.getTimeInMillis();
2011 return (int) (diffInMillis / (24 * 1000 * 60 * 60));
2012 }
2013
2014 public void generateNotices() throws Exception {
2015
2016 generateCourtesyNotice();
2017
2018 }
2019
2020 public void generateLostNotice() throws Exception {
2021 OleLoanDocumentDaoOjb oleLoanDocumentDaoOjb = (OleLoanDocumentDaoOjb) SpringContext.getService(OLEConstants.OLE_LOAN_DAO);
2022 LoanWithNoticesDAO loanWithNoticesDAO = (LoanWithNoticesDAO) SpringContext.getService(OLEConstants.LOAN_WITH_NOTICES_DAO);
2023 String lostNoticeToDate = ParameterValueResolver.getInstance().getParameter(OLEConstants.APPL_ID_OLE, OLEConstants
2024 .DLVR_NMSPC, OLEConstants.DLVR_CMPNT,OLEConstants.LOST_NOTICE_TO_DATE);
2025 List<String> loanIds = loanWithNoticesDAO.getLoanIdsForOverudeNotices(lostNoticeToDate, OLEConstants.NOTICE_LOST);
2026 if (loanIds.size() > 0) {
2027 List<OleLoanDocument> loanDocuments = oleLoanDocumentDaoOjb.getLaonDocumentsFromLaondId(loanIds);
2028 List<OleLoanDocument> loanDocumentsWithItemInfo = getLoanDocumentWithItemInfo(loanDocuments);
2029 int threadPoolSize = OLEConstants.DEFAULT_NOTICE_THREAD_POOL_SIZE;
2030 String threadPoolSizeValue =ParameterValueResolver.getInstance().getParameter(OLEConstants.APPL_ID_OLE, OLEConstants
2031 .DLVR_NMSPC, OLEConstants.DLVR_CMPNT,OLEConstants.NOTICE_THREAD_POOL_SIZE);
2032 if (StringUtils.isNotBlank(threadPoolSizeValue)) {
2033 try {
2034 threadPoolSize = Integer.parseInt(threadPoolSizeValue);
2035 } catch (Exception e) {
2036 LOG.error("Invalid thread pool size from SystemParameter. So assigned default thread pool size" + threadPoolSize);
2037 threadPoolSize = OLEConstants.DEFAULT_NOTICE_THREAD_POOL_SIZE;
2038 }
2039 }
2040
2041 Map<String, List<OleLoanDocument>> mapofNoticesForEachPatron = buildMapofNoticesForEachPatron(loanDocumentsWithItemInfo);
2042
2043 ExecutorService lostNoticesExecutorService = Executors.newFixedThreadPool(threadPoolSize);
2044
2045 for (Iterator<String> iterator = mapofNoticesForEachPatron.keySet().iterator(); iterator.hasNext(); ) {
2046 String patronId = iterator.next();
2047 List<OleLoanDocument> oleLoanDocuments = mapofNoticesForEachPatron.get
2048 (patronId);
2049 Runnable deliverOverDueNoticesExecutor = new LostNoticesExecutor(oleLoanDocuments);
2050 lostNoticesExecutorService.execute(deliverOverDueNoticesExecutor);
2051 }
2052 }
2053 }
2054
2055
2056 public void generateCourtesyNotice() throws Exception {
2057 OleLoanDocumentDaoOjb oleLoanDocumentDaoOjb = (OleLoanDocumentDaoOjb) SpringContext.getService(OLEConstants.OLE_LOAN_DAO);
2058 LoanWithNoticesDAO loanWithNoticesDAO = (LoanWithNoticesDAO) SpringContext.getService(OLEConstants.LOAN_WITH_NOTICES_DAO);
2059 String courtesyNoticeToDate = ParameterValueResolver.getInstance().getParameter(OLEConstants.APPL_ID_OLE, OLEConstants
2060 .DLVR_NMSPC, OLEConstants.DLVR_CMPNT,OLEConstants.COURTESY_NOTICE_TO_DATE);
2061 List<String> loanIds = loanWithNoticesDAO.getLoanIdsForOverudeNotices(courtesyNoticeToDate, OLEConstants.NOTICE_COURTESY);
2062 if (loanIds.size() > 0) {
2063 List<OleLoanDocument> loanDocuments = oleLoanDocumentDaoOjb.getLaonDocumentsFromLaondId(loanIds);
2064 List<OleLoanDocument> loanDocumentsWithItemInfo = getLoanDocumentWithItemInfo(loanDocuments);
2065 int threadPoolSize = OLEConstants.DEFAULT_NOTICE_THREAD_POOL_SIZE;
2066 String threadPoolSizeValue = ParameterValueResolver.getInstance().getParameter(OLEConstants.APPL_ID_OLE, OLEConstants
2067 .DLVR_NMSPC, OLEConstants.DLVR_CMPNT,OLEConstants.NOTICE_THREAD_POOL_SIZE);
2068 if (StringUtils.isNotBlank(threadPoolSizeValue)) {
2069 try {
2070 threadPoolSize = Integer.parseInt(threadPoolSizeValue);
2071 } catch (Exception e) {
2072 LOG.error("Invalid thread pool size from SystemParameter. So assigned default thread pool size" + threadPoolSize);
2073 threadPoolSize = OLEConstants.DEFAULT_NOTICE_THREAD_POOL_SIZE;
2074 }
2075 }
2076
2077 Map<String, List<OleLoanDocument>> mapofNoticesForEachPatron = buildMapofNoticesForEachPatron(loanDocumentsWithItemInfo);
2078
2079 ExecutorService courtesyNoticesExecutorService = Executors.newFixedThreadPool(threadPoolSize);
2080
2081 for (Iterator<String> iterator = mapofNoticesForEachPatron.keySet().iterator(); iterator.hasNext(); ) {
2082 String patronId = iterator.next();
2083 List<OleLoanDocument> oleLoanDocuments = mapofNoticesForEachPatron.get
2084 (patronId);
2085 Runnable deliverCourtesyNoticesExecutor = new CourtesyNoticesExecutor(oleLoanDocuments);
2086 courtesyNoticesExecutorService.execute(deliverCourtesyNoticesExecutor);
2087 }
2088 }
2089 }
2090
2091 public void generateOverdueNotice() throws Exception {
2092 OleLoanDocumentDaoOjb oleLoanDocumentDaoOjb = (OleLoanDocumentDaoOjb) SpringContext.getService(OLEConstants.OLE_LOAN_DAO);
2093 LoanWithNoticesDAO loanWithNoticesDAO = (LoanWithNoticesDAO) SpringContext.getService(OLEConstants.LOAN_WITH_NOTICES_DAO);
2094 String overdueNoticeToDate = ParameterValueResolver.getInstance().getParameter(OLEConstants.APPL_ID_OLE, OLEConstants
2095 .DLVR_NMSPC, OLEConstants.DLVR_CMPNT,OLEConstants.OVERDUE_NOTICE_TO_DATE);
2096 List<String> loanIds = loanWithNoticesDAO.getLoanIdsForOverudeNotices(overdueNoticeToDate, OLEConstants.NOTICE_OVERDUE);
2097 if (loanIds.size() > 0) {
2098 List<OleLoanDocument> loanDocuments = oleLoanDocumentDaoOjb.getLaonDocumentsFromLaondId(loanIds);
2099 List<OleLoanDocument> loanDocumentsWithItemInfo = getLoanDocumentWithItemInfo(loanDocuments);
2100 int threadPoolSize = OLEConstants.DEFAULT_NOTICE_THREAD_POOL_SIZE;
2101 String threadPoolSizeValue = ParameterValueResolver.getInstance().getParameter(OLEConstants.APPL_ID_OLE, OLEConstants
2102 .DLVR_NMSPC, OLEConstants.DLVR_CMPNT,OLEConstants.NOTICE_THREAD_POOL_SIZE);
2103 if (StringUtils.isNotBlank(threadPoolSizeValue)) {
2104 try {
2105 threadPoolSize = Integer.parseInt(threadPoolSizeValue);
2106 } catch (Exception e) {
2107 LOG.error("Invalid thread pool size from SystemParameter. So assigned default thread pool size" + threadPoolSize);
2108 threadPoolSize = OLEConstants.DEFAULT_NOTICE_THREAD_POOL_SIZE;
2109 }
2110 }
2111
2112 Map<String, List<OleLoanDocument>> mapofNoticesForEachPatron = buildMapofNoticesForEachPatron(loanDocumentsWithItemInfo);
2113
2114 ExecutorService overDueNoticesExecutorService = Executors.newFixedThreadPool(threadPoolSize);
2115
2116 for (Iterator<String> iterator = mapofNoticesForEachPatron.keySet().iterator(); iterator.hasNext(); ) {
2117 String patronId = iterator.next();
2118 List<OleLoanDocument> oleLoanDocuments = mapofNoticesForEachPatron.get
2119 (patronId);
2120 Runnable deliverOverDueNoticesExecutor = new OverdueNoticesExecutor(oleLoanDocuments);
2121 overDueNoticesExecutorService.execute(deliverOverDueNoticesExecutor);
2122 }
2123 }
2124 }
2125
2126 private Map<String, List<OleLoanDocument>> buildMapofNoticesForEachPatron(List<OleLoanDocument> loanDocuments) {
2127 Map<String, List<OleLoanDocument>> map = new HashMap<>();
2128 String patronId;
2129 for (Iterator<OleLoanDocument> iterator = loanDocuments.iterator(); iterator.hasNext(); ) {
2130 OleLoanDocument oleLoanDocument = iterator.next();
2131 patronId = oleLoanDocument.getPatronId();
2132 if (map.containsKey(patronId)) {
2133 map.get(patronId).add(oleLoanDocument);
2134 } else {
2135 List<OleLoanDocument> oleLoanDocumentList = new ArrayList<>();
2136 oleLoanDocumentList.add(oleLoanDocument);
2137 map.put(patronId, oleLoanDocumentList);
2138 }
2139 }
2140
2141 return map;
2142 }
2143
2144 private void iterateNotices(List<OleLoanDocument> notices, List<String> itemUUIDS) {
2145 List<OleLoanDocument> documents = new ArrayList<>();
2146 List<String> itemIds = new ArrayList<>();
2147 if (notices != null && notices.size() > 0) {
2148 boolean firstTime = true;
2149 String patronId = "";
2150 for (Object obj : notices) {
2151 OleLoanDocument loanDocument = (OleLoanDocument) obj;
2152 if (firstTime) {
2153 patronId = loanDocument.getPatronId();
2154 }
2155 if (patronId != null && patronId.equals(loanDocument.getPatronId())) {
2156 documents.add(loanDocument);
2157 itemIds.add(loanDocument.getItemUuid());
2158 } else {
2159 generateNoticeForOverdueAndCourtesy(patronId, documents, true, itemUUIDS);
2160 documents = new ArrayList<>();
2161 itemIds = new ArrayList<>();
2162 documents.add(loanDocument);
2163 itemIds.add(loanDocument.getItemUuid());
2164 patronId = loanDocument.getPatronId();
2165 }
2166 firstTime = false;
2167 }
2168 generateNoticeForOverdueAndCourtesy(patronId, documents, true, itemUUIDS);
2169 }
2170 }
2171
2172 public void generateNoticeForOverdueAndCourtesy(String patronId, List<OleLoanDocument> oleLoanDocuments, boolean overdue, List<String> itemUUIDS) {
2173 Map<String, String> patronMap = new HashMap<String, String>();
2174 patronMap.put("olePatronId", patronId);
2175 List<OlePatronDocument> olePatronDocuments = (List<OlePatronDocument>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePatronDocument.class, patronMap);
2176 if (olePatronDocuments != null && olePatronDocuments.size() > 0) {
2177 OlePatronDocument olePatronDocument = olePatronDocuments.get(0);
2178 if (oleLoanDocuments != null && oleLoanDocuments.size() > 0) {
2179 getNoticeList(oleLoanDocuments, olePatronDocument, overdue, itemUUIDS);
2180 }
2181 }
2182 }
2183
2184 public void generateHoldCourtesyNotice() throws Exception {
2185 List<OleDeliverRequestBo> oleDeliverRequestBos = (List<OleDeliverRequestBo>) KRADServiceLocator.getBusinessObjectService().findAll(OleDeliverRequestBo.class);
2186 List<OleDeliverRequestBo> expiredOnHoldNoticeBos = new ArrayList<>();
2187 for (OleDeliverRequestBo oleDeliverRequestBo : oleDeliverRequestBos) {
2188 List<OleNoticeBo> oleNoticeBos = new ArrayList<OleNoticeBo>();
2189 DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
2190 if (getDocstoreUtil().isItemAvailableInDocStore(oleDeliverRequestBo) && oleDeliverRequestBo.getHoldExpirationDate() != null && !isExpiredOnHoldNotice(oleDeliverRequestBo)) {
2191 Item oleItem = oleDeliverRequestBo.getOleItem();
2192 OleNoticeBo oleNoticeBo = new OleNoticeBo();
2193 Date currentDate = new Date();
2194 DateFormat formatter = new SimpleDateFormat(OLEConstants.DAT_FORMAT_EFFECTIVE_NOTICE);
2195 Date itemStatusEffectiveDate = (Date) formatter.parse(oleItem.getItemStatusEffectiveDate());
2196 Integer numberOfDaysOnHold = determineDifferenceInDays(currentDate, itemStatusEffectiveDate);
2197 Integer maxNumberOfDaysOnHold = determineDifferenceInDays(itemStatusEffectiveDate, oleDeliverRequestBo.getHoldExpirationDate());
2198 OleCirculationDesk oleCirculationDesk = null;
2199 if (oleDeliverRequestBo.getPickUpLocationId() != null) {
2200 oleCirculationDesk = getCircDeskLocationResolver().getOleCirculationDesk(oleDeliverRequestBo.getPickUpLocationId());
2201
2202
2203 }
2204 String itemTypeName = null;
2205 if (oleItem.getTemporaryItemType() != null && oleItem.getTemporaryItemType().getCodeValue() != "") {
2206 OleInstanceItemType oleInstanceItemType = getLoanProcessor().getItemTypeIdByItemType(oleItem.getTemporaryItemType().getCodeValue());
2207 itemTypeName = oleInstanceItemType.getInstanceItemTypeCode();
2208 } else if (oleItem.getItemType() != null && oleItem.getItemType().getCodeValue() != "") {
2209 OleInstanceItemType oleInstanceItemType = getLoanProcessor().getItemTypeIdByItemType(oleItem.getItemType().getCodeValue());
2210 itemTypeName = oleInstanceItemType.getInstanceItemTypeCode();
2211 }
2212 OlePatronDocument olePatronDocument = oleDeliverRequestBo.getOlePatron();
2213 String agendaName = OLEConstants.OleDeliverRequest.NOTICE_VALIDATION;
2214 String patronId = olePatronDocument.getOlePatronId() != null ? olePatronDocument.getOlePatronId() : "";
2215 String itemId = oleDeliverRequestBo.getItemId() != null ? oleDeliverRequestBo.getItemId() : "";
2216 dataCarrierService.removeData(patronId + itemId);
2217 HashMap<String, Object> termValues = new HashMap<String, Object>();
2218 Date expirationDate = olePatronDocument != null ? olePatronDocument.getExpirationDate() : null;
2219 termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode());
2220 termValues.put(OLEConstants.ITEM_TYPE, itemTypeName);
2221 termValues.put(OLEConstants.OVERLAY_ITEM_LOCATION, oleDeliverRequestBo.getShelvingLocation());
2222 termValues.put(OLEConstants.NO_OF_DAYS_ON_HOLD, numberOfDaysOnHold);
2223 termValues.put(OLEConstants.MAX_NO_OF_DAYS_ONHOLD, maxNumberOfDaysOnHold);
2224 termValues.put(OLEConstants.ITEM_SHELVING, oleDeliverRequestBo.getShelvingLocation());
2225 termValues.put(OLEConstants.ITEM_COLLECTION, oleDeliverRequestBo.getItemCollection());
2226 termValues.put(OLEConstants.ITEM_LIBRARY, oleDeliverRequestBo.getItemLibrary());
2227 termValues.put(OLEConstants.ITEM_CAMPUS, oleDeliverRequestBo.getItemCampus());
2228 termValues.put(OLEConstants.ITEM_INSTITUTION, oleDeliverRequestBo.getItemInstitution());
2229 termValues.put(OLEConstants.REQUEST_TYPE, oleDeliverRequestBo.getRequestTypeCode());
2230 termValues.put(OLEConstants.EXPIR_DATE, expirationDate);
2231 termValues.put(OLEConstants.PATRON_ID_POLICY, patronId);
2232 termValues.put(OLEConstants.ITEM_ID_POLICY, itemId);
2233 if (oleItem.getItemStatus() != null)
2234 termValues.put(OLEConstants.ITEM_STATUS, oleItem.getItemStatus().getCodeValue());
2235 if (LOG.isDebugEnabled()) {
2236 LOG.debug("termValues.toString()" + termValues.toString());
2237 }
2238 EngineResults engineResults = getLoanProcessor().getEngineResults(agendaName, termValues);
2239 String notice = (String) engineResults.getAttribute(OLEConstants.NOTICE);
2240 if (LOG.isDebugEnabled()) {
2241 LOG.debug("notice" + notice);
2242 }
2243 agendaName = OLEConstants.BATCH_PROGRAM_AGENDA;
2244 termValues = new HashMap<String, Object>();
2245 String deskLocation = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskCode() : "";
2246 String deskLocationName = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskPublicName() : "";
2247 termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode());
2248 termValues.put(OLEConstants.DESK_LOCATION, deskLocation);
2249 termValues.put(OLEConstants.NOTICE, notice);
2250 if (LOG.isDebugEnabled()) {
2251 LOG.debug("termValues.toString()" + termValues.toString());
2252 }
2253 engineResults = getLoanProcessor().getEngineResults(agendaName, termValues);
2254 dataCarrierService.removeData(patronId + itemId);
2255 String noticeType = (String) engineResults.getAttribute(OLEConstants.NOTICE_TYPE);
2256 if (LOG.isDebugEnabled()) {
2257 LOG.debug("**************" + noticeType);
2258 }
2259 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
2260 if (notice != null) {
2261 oleNoticeBo.setNoticeName(notice);
2262 if (notice.equalsIgnoreCase(OLEConstants.NOTICE_HOLD_COURTESY)) {
2263 oleNoticeBo = getExpiredHoldNotice(oleDeliverRequestBo);
2264 oleNoticeBo.setCirculationDeskName(deskLocationName);
2265 oleNoticeBos.add(oleNoticeBo);
2266 noticeType = noticeType == null ? getLoanProcessor().getParameter("HOLDCOURTESY_NOTICE_TYPE") : noticeType;
2267 }
2268 if (oleNoticeBos.size() > 0 && noticeType != null && (noticeType.equalsIgnoreCase(OLEConstants.EMAIL) || noticeType.equalsIgnoreCase(OLEConstants.MAIL))) {
2269 oleDeliverBatchService.getPdfNoticeForPatron(oleNoticeBos);
2270 }
2271
2272 }
2273 olePatronDocument = oleDeliverRequestBo.getOlePatron();
2274 if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.EMAIL)) {
2275 if (olePatronDocument.getEmailAddress() != null && !olePatronDocument.getEmailAddress().isEmpty()) {
2276 List list = oleDeliverBatchService.getNoticeForPatron(oleNoticeBos);
2277 String noticeContent = list.toString();
2278 noticeContent = noticeContent.replace('[', ' ');
2279 noticeContent = noticeContent.replace(']', ' ');
2280 if (!noticeContent.trim().equals("")) {
2281 OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
2282 if (oleDeliverRequestBo.getOlePickUpLocation() != null && StringUtils.isNotBlank(oleDeliverRequestBo.getOlePickUpLocation().getReplyToEmail())) {
2283 oleMailer.sendEmail(new EmailFrom(oleDeliverRequestBo.getOlePickUpLocation().getReplyToEmail()), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(noticeContent), true);
2284 } else {
2285 String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
2286 if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
2287 fromAddress = OLEConstants.KUALI_MAIL;
2288 }
2289 oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(noticeContent), true);
2290 }
2291 } else {
2292 for (OleNoticeBo oleNoticeBo1 : oleNoticeBos) {
2293 if (LOG.isDebugEnabled()) {
2294 LOG.debug("Notice Type :" + oleNoticeBo1.getNoticeName() + " " + "Item Barcode : " + oleNoticeBo1.getItemId() + " " + "Patron Name :" + oleNoticeBo1.getPatronName());
2295 }
2296 }
2297 }
2298
2299 if (LOG.isDebugEnabled()) {
2300 LOG.debug("olePatronDocument.getEmailAddress()" + olePatronDocument.getEmailAddress());
2301 }
2302 }
2303 } else if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.SMS)) {
2304
2305 }
2306 } else if (oleDeliverRequestBo.getHoldExpirationDate() != null && isExpiredOnHoldNotice(oleDeliverRequestBo)) {
2307 expiredOnHoldNoticeBos.add(oleDeliverRequestBo);
2308 }
2309 }
2310 if (CollectionUtils.isNotEmpty(expiredOnHoldNoticeBos)) {
2311 deleteExpiredOnHoldNotices(expiredOnHoldNoticeBos);
2312 }
2313 }
2314
2315 private void deleteExpiredOnHoldNotices(List<OleDeliverRequestBo> expiredOnHoldNoticeBos) {
2316 List<OleDeliverRequestHistoryRecord> oleDeliverRequestHistoryRecords = new ArrayList<>();
2317 for (OleDeliverRequestBo oleDeliverRequestBo : expiredOnHoldNoticeBos) {
2318 try {
2319 deleteRequest(oleDeliverRequestBo.getRequestId(), oleDeliverRequestBo.getItemUuid(), " ", oleDeliverRequestBo.getLoanTransactionRecordNumber(), ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.HOLD_REQUEST_EXPIRED));
2320 } catch (Exception e) {
2321
2322 }
2323 }
2324 }
2325
2326 private boolean isExpiredOnHoldNotice(OleDeliverRequestBo oleDeliverRequestBo) {
2327 boolean isExpired = false;
2328 if (oleDeliverRequestBo.getHoldExpirationDate() != null && oleDeliverRequestBo.getHoldExpirationDate().compareTo(getDateTimeService().getCurrentDate()) < 0) {
2329 isExpired = true;
2330 }
2331 return isExpired;
2332 }
2333
2334 public void deleteTemporaryHistoryRecord() throws Exception {
2335 List<OlePatronDocument> patronDocumentList = (List<OlePatronDocument>) KRADServiceLocator.getBusinessObjectService().findAll(OlePatronDocument.class);
2336 for (OlePatronDocument olePatronDocument : patronDocumentList) {
2337 Map<String, String> requestMap = new HashMap<String, String>();
2338 requestMap.put(OLEConstants.OlePatron.PATRON_ID, olePatronDocument.getOlePatronId());
2339 List<OleTemporaryCirculationHistory> oleTemporaryCirculationHistoryList = (List<OleTemporaryCirculationHistory>) KRADServiceLocator.getBusinessObjectService().findMatching(OleTemporaryCirculationHistory.class, requestMap);
2340 List<OleTemporaryCirculationHistory> deleteRecords = new ArrayList<OleTemporaryCirculationHistory>();
2341 for (OleTemporaryCirculationHistory oleTemporaryCirculationHistory : oleTemporaryCirculationHistoryList) {
2342 String agendaName = OLEConstants.BATCH_PROGRAM_AGENDA;
2343 HashMap<String, Object> termValues = new HashMap<String, Object>();
2344 termValues.put(OLEConstants.OleDeliverRequest.IS_TEMPORARY_HISTORY_RECORD, String.valueOf(Boolean.TRUE));
2345 DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
2346 dataCarrierService.addData(OLEConstants.DATE_CHECK_IN, oleTemporaryCirculationHistory.getCheckInDate());
2347 EngineResults engineResults = getLoanProcessor().getEngineResults(agendaName, termValues);
2348 Boolean deleteRecord = (Boolean) engineResults.getAttribute(OLEConstants.OVERLAY_OPTION_DELETE);
2349 if (deleteRecord != null && deleteRecord) {
2350 deleteRecords.add(oleTemporaryCirculationHistory);
2351 }
2352 }
2353 getBusinessObjectService().delete(deleteRecords);
2354 }
2355 }
2356
2357 private OleNoticeBo getExpiredHoldNotice(OleDeliverRequestBo oleDeliverRequestBo) throws Exception {
2358 LOG.debug("Expired Hold Notice");
2359 Item oleItem = oleDeliverRequestBo.getOleItem();
2360 EntityTypeContactInfoBo entityTypeContactInfoBo = oleDeliverRequestBo.getOlePatron().getEntity().getEntityTypeContactInfos().get(0);
2361 OleNoticeBo oleNoticeBo = new OleNoticeBo();
2362 org.kuali.ole.docstore.common.document.Item item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(oleDeliverRequestBo.getItemUuid());
2363 String shelvingLocation = oleDeliverRequestBo.getShelvingLocation();
2364 OleCirculationDesk oleCirculationDesk = getOleCirculationDesk(oleDeliverRequestBo.getPickUpLocationId());
2365 if (oleCirculationDesk != null)
2366 oleNoticeBo.setCirculationDeskName(oleCirculationDesk.getCirculationDeskPublicName());
2367 else
2368 oleNoticeBo.setCirculationDeskName("");
2369 oleNoticeBo.setCirculationDeskAddress("");
2370 oleNoticeBo.setCirculationDeskEmailAddress("");
2371 oleNoticeBo.setCirculationDeskPhoneNumber("");
2372 oleNoticeBo.setCirculationDeskPhoneNumber("");
2373 oleNoticeBo.setPatronName(oleDeliverRequestBo.getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + oleDeliverRequestBo.getOlePatron().getEntity().getNames().get(0).getLastName());
2374 oleNoticeBo.setPatronAddress(getOlePatronHelperService().getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronPreferredAddress(entityTypeContactInfoBo) : "");
2375 oleNoticeBo.setPatronEmailAddress(getOlePatronHelperService().getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronHomeEmailId(entityTypeContactInfoBo) : "");
2376 oleNoticeBo.setPatronPhoneNumber(getOlePatronHelperService().getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
2377 oleNoticeBo.setNoticeName(OLEConstants.NOTICE_HOLD_COURTESY);
2378 oleNoticeBo.setNoticeSpecificContent(getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.EXP_HOLD_NOTICE_CONTENT));
2379 oleNoticeBo.setTitle(item.getHolding().getBib().getTitle());
2380 oleNoticeBo.setAuthor(item.getHolding().getBib().getAuthor());
2381
2382
2383 oleNoticeBo.setVolumeNumber(item.getVolumeNumber());
2384 oleNoticeBo.setItemShelvingLocation(shelvingLocation != null ? shelvingLocation : "");
2385
2386 oleNoticeBo.setItemCallNumber((String) oleItem.getCallNumber().getNumber() != null && !oleItem.getCallNumber().getNumber().equals("") ? oleItem.getCallNumber().getNumber() : "");
2387 oleNoticeBo.setItemId(oleDeliverRequestBo.getItemId() != null ? oleDeliverRequestBo.getItemId() : "");
2388 oleNoticeBo.setCirculationDeskName(oleDeliverRequestBo.getOlePickUpLocation().getCirculationDeskPublicName());
2389 oleNoticeBo.setCirculationDeskReplyToEmail(oleDeliverRequestBo.getOlePickUpLocation().getReplyToEmail());
2390 oleNoticeBo.setOleItem(oleItem);
2391 oleNoticeBo.setOlePatron(oleDeliverRequestBo.getOlePatron());
2392 oleNoticeBo.setCopyNumber(oleDeliverRequestBo.getCopyNumber());
2393 oleNoticeBo.setEnumeration(oleDeliverRequestBo.getEnumeration());
2394 oleNoticeBo.setChronology(oleDeliverRequestBo.getChronology());
2395
2396
2397 oleDeliverRequestBo.getOlePatron().setEmailAddress(oleNoticeBo.getPatronEmailAddress());
2398 return oleNoticeBo;
2399 }
2400
2401 private OleNoticeBo getCourtesyNotice(OleLoanDocument oleLoanDocument) throws Exception {
2402 LOG.debug("Courtesy Notice");
2403 oleLoanDocument.setCourtesyNoticeFlag(true);
2404 Map<String, String> map = new HashMap<String, String>();
2405 map.put(OLEConstants.LOAN_ID, oleLoanDocument.getLoanId());
2406 KRADServiceLocator.getBusinessObjectService().save(oleLoanDocument);
2407 EntityTypeContactInfoBo entityTypeContactInfoBo = oleLoanDocument.getOlePatron().getEntity().getEntityTypeContactInfos().get(0);
2408 OleNoticeBo oleNoticeBo = new OleNoticeBo();
2409
2410 Item oleItem = oleLoanDocument.getOleItem();
2411 String shelvingLocation = oleLoanDocument.getItemLocation();
2412 OleCirculationDesk oleCirculationDesk = getOleCirculationDesk(oleLoanDocument.getCirculationLocationId());
2413 if (oleCirculationDesk != null)
2414 oleNoticeBo.setCirculationDeskName(oleCirculationDesk.getCirculationDeskPublicName());
2415 else
2416 oleNoticeBo.setCirculationDeskName("");
2417 oleNoticeBo.setCirculationDeskAddress("");
2418 oleNoticeBo.setCirculationDeskEmailAddress("");
2419 oleNoticeBo.setCirculationDeskPhoneNumber("");
2420 oleNoticeBo.setPatronName(oleLoanDocument.getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + oleLoanDocument.getOlePatron().getEntity().getNames().get(0).getLastName());
2421 oleNoticeBo.setPatronAddress(getOlePatronHelperService().getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronPreferredAddress(entityTypeContactInfoBo) : "");
2422 oleNoticeBo.setPatronEmailAddress(getOlePatronHelperService().getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronHomeEmailId(entityTypeContactInfoBo) : "");
2423 oleNoticeBo.setPatronPhoneNumber(getOlePatronHelperService().getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
2424 oleNoticeBo.setNoticeName(OLEConstants.NOTICE_COURTESY);
2425 oleNoticeBo.setNoticeSpecificContent(getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.COURTESY_NOTICE_CONTENT));
2426
2427
2428 oleNoticeBo.setTitle(oleLoanDocument.getTitle());
2429 oleNoticeBo.setAuthor(oleLoanDocument.getAuthor());
2430 oleNoticeBo.setVolumeNumber(oleLoanDocument.getItemVolumeNumber());
2431 oleNoticeBo.setItemShelvingLocation(shelvingLocation != null ? shelvingLocation : "");
2432
2433 oleNoticeBo.setItemCallNumber(oleLoanDocument.getItemCallNumber());
2434 oleNoticeBo.setItemId(oleLoanDocument.getItemId());
2435 oleLoanDocument.getOlePatron().setEmailAddress(oleNoticeBo.getPatronEmailAddress());
2436 if (LOG.isDebugEnabled()) {
2437 LOG.debug("oleNoticeBo.getPatronEmailAddress()" + oleNoticeBo.getPatronEmailAddress());
2438 }
2439 return oleNoticeBo;
2440 }
2441
2442 private OleNoticeBo getOverdueNotice(OleLoanDocument oleLoanDocument) throws Exception {
2443 LOG.debug("Overdue Notice");
2444 EntityTypeContactInfoBo entityTypeContactInfoBo = oleLoanDocument.getOlePatron().getEntity().getEntityTypeContactInfos().get(0);
2445 OleNoticeBo oleNoticeBo = new OleNoticeBo();
2446
2447 Item oleItem = oleLoanDocument.getOleItem();
2448
2449
2450 OleCirculationDesk oleCirculationDesk = getOleCirculationDesk(oleLoanDocument.getCirculationLocationId());
2451 if (oleCirculationDesk != null)
2452 oleNoticeBo.setCirculationDeskName(oleCirculationDesk.getCirculationDeskPublicName());
2453 else
2454 oleNoticeBo.setCirculationDeskName("");
2455 oleNoticeBo.setCirculationDeskAddress("");
2456 oleNoticeBo.setCirculationDeskEmailAddress("");
2457 oleNoticeBo.setCirculationDeskPhoneNumber("");
2458 oleNoticeBo.setPatronName(oleLoanDocument.getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + oleLoanDocument.getOlePatron().getEntity().getNames().get(0).getLastName());
2459 oleNoticeBo.setPatronAddress(getOlePatronHelperService().getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronPreferredAddress(entityTypeContactInfoBo) : "");
2460 oleNoticeBo.setPatronEmailAddress(getOlePatronHelperService().getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronHomeEmailId(entityTypeContactInfoBo) : "");
2461 oleNoticeBo.setPatronPhoneNumber(getOlePatronHelperService().getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
2462 oleNoticeBo.setNoticeName(OLEConstants.NOTICE_OVERDUE);
2463 oleNoticeBo.setNoticeSpecificContent(getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.OVERDUE_NOTICE_CONTENT));
2464 oleNoticeBo.setTitle(oleLoanDocument.getTitle());
2465 oleNoticeBo.setAuthor(oleLoanDocument.getAuthor());
2466
2467
2468
2469
2470 String volume = (String) oleItem.getEnumeration() != null && !oleItem.getEnumeration().equals("") ? oleItem.getEnumeration() : "";
2471 String issue = new String(" ");
2472 String copyNumber = (String) oleItem.getCopyNumber() != null && !oleItem.getCopyNumber().equals("") ? oleItem.getCopyNumber() : "";
2473 oleNoticeBo.setVolumeIssueCopyNumber(volume + "/" + issue + "/" + copyNumber);
2474 oleNoticeBo.setItemShelvingLocation(oleLoanDocument.getItemLocation());
2475
2476
2477
2478
2479
2480 oleNoticeBo.setItemCallNumber(getLoanProcessor().getItemCallNumber(oleItem, oleLoanDocument.getInstanceUuid()));
2481
2482 oleNoticeBo.setItemId(oleLoanDocument.getItemId());
2483
2484 oleNoticeBo.setDueDate(oleLoanDocument.getLoanDueDate() != null ? oleLoanDocument.getLoanDueDate() : null);
2485
2486 oleLoanDocument.getOlePatron().setEmailAddress(oleNoticeBo.getPatronEmailAddress());
2487 if (LOG.isDebugEnabled()) {
2488 LOG.debug("oleNoticeBo.getPatronEmailAddress()" + oleNoticeBo.getPatronEmailAddress());
2489 }
2490 int noOfOverdueNoticeSent = Integer.parseInt(oleLoanDocument.getNumberOfOverdueNoticesSent() != null ? oleLoanDocument.getNumberOfOverdueNoticesSent() : "0");
2491 noOfOverdueNoticeSent = noOfOverdueNoticeSent + 1;
2492 if (LOG.isDebugEnabled()) {
2493 LOG.debug("Updated Loan Record : " + oleLoanDocument);
2494 }
2495 oleLoanDocument.setNumberOfOverdueNoticesSent(Integer.toString(noOfOverdueNoticeSent));
2496 oleLoanDocument.setOverDueNoticeDate(new java.sql.Date(System.currentTimeMillis()));
2497 getBusinessObjectService().save(oleLoanDocument);
2498 return oleNoticeBo;
2499 }
2500
2501 public void updateItem(Item oleItem, String itemUuid) throws Exception {
2502 ItemStatus itemStatus = new ItemStatus();
2503 itemStatus.setCodeValue(OLEConstants.OleDeliverRequest.MISSING);
2504 itemStatus.setFullValue(OLEConstants.OleDeliverRequest.MISSING);
2505 oleItem.setItemStatus(itemStatus);
2506 oleItem.setStaffOnlyFlag(true);
2507 String itemContent = new ItemOlemlRecordProcessor().toXML(oleItem);
2508 org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
2509 item.setId(itemUuid);
2510 item.setContent(itemContent);
2511 item.setCategory(OLEConstants.WORK_CATEGORY);
2512 item.setType(DocType.ITEM.getCode());
2513 item.setFormat(OLEConstants.OLEML_FORMAT);
2514 getDocstoreClientLocator().getDocstoreClient().updateItem(item);
2515 }
2516
2517 public String getShelvingLocation(LocationLevel oleLocationLevel) {
2518 String location = null;
2519 if (oleLocationLevel != null) {
2520 if (OLEConstants.LOCATION_LEVEL_SHELVING.equalsIgnoreCase(oleLocationLevel.getLevel()))
2521 location = oleLocationLevel.getName();
2522 else
2523 location = getShelvingLocation(oleLocationLevel.getLocationLevel());
2524 }
2525 if ("".equals(location) || location == null)
2526 return null;
2527 return location;
2528 }
2529
2530
2531 public String getIntervalForCourtesyNotice() {
2532 BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
2533 Map<String, String> criteriaMap = new HashMap<String, String>();
2534 criteriaMap.put(OLEConstants.NAMESPACE_CODE, OLEConstants.DLVR_NMSPC);
2535 criteriaMap.put(OLEConstants.COMPONENT_CODE, OLEConstants.DLVR_CMPNT);
2536 criteriaMap.put(OLEConstants.NAME, OLEParameterConstants.COURTESY_NOTICE_INTER);
2537 List<ParameterBo> parametersList = (List<ParameterBo>) businessObjectService.findMatching(ParameterBo.class, criteriaMap);
2538 return parametersList.get(0).getValue();
2539 }
2540
2541 public String getIntervalForOverdueNotice() {
2542 BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
2543 Map<String, String> criteriaMap = new HashMap<String, String>();
2544 criteriaMap.put(OLEConstants.NAMESPACE_CODE, OLEConstants.DLVR_NMSPC);
2545 criteriaMap.put(OLEConstants.COMPONENT_CODE, OLEConstants.DLVR_CMPNT);
2546 criteriaMap.put(OLEConstants.NAME, OLEConstants.OVERDUE_NOTICE_INTER);
2547 List<ParameterBo> parametersList = (List<ParameterBo>) businessObjectService.findMatching(ParameterBo.class, criteriaMap);
2548 return parametersList.get(0).getValue();
2549 }
2550
2551
2552 private PatronBillPayment getPatronBillPayment(String patronId) {
2553 LOG.debug("Inside the getPatronBillPayment method");
2554 Map billMap = new HashMap();
2555 billMap.put(OLEConstants.OleDeliverRequest.LOAN_PATRON_ID, patronId);
2556 List<PatronBillPayment> patronBillPaymentList = (List<PatronBillPayment>) getBusinessObjectService().findMatching(PatronBillPayment.class, billMap);
2557 return patronBillPaymentList != null && patronBillPaymentList.size() > 0 ? patronBillPaymentList.get(0) : null;
2558 }
2559
2560 private OlePaymentStatus getPaymentStatus() {
2561 LOG.debug("Inside the getPaymentStatus method");
2562 Map statusMap = new HashMap();
2563 statusMap.put(OLEConstants.OleDeliverRequest.PAYMENT_STATUS_NAME, OLEConstants.PAYMENT_STATUS_OUTSTANDING);
2564 List<OlePaymentStatus> olePaymentStatusList = (List<OlePaymentStatus>) getBusinessObjectService().findMatching(OlePaymentStatus.class, statusMap);
2565 return olePaymentStatusList != null && olePaymentStatusList.size() > 0 ? olePaymentStatusList.get(0) : null;
2566 }
2567
2568 private String getFeeTypeId(String feeTypeName) {
2569 LOG.debug("Inside the getOverdueFeeTypeId method");
2570 Map feeMap = new HashMap();
2571 feeMap.put(OLEConstants.FEE_TYPE_NAME, feeTypeName);
2572 List<OleFeeType> oleFeeTypes = (List<OleFeeType>) getBusinessObjectService().findMatching(OleFeeType.class, feeMap);
2573 return oleFeeTypes != null && oleFeeTypes.size() > 0 ? oleFeeTypes.get(0).getFeeTypeId() : null;
2574 }
2575
2576 public String processItemType(String itemType) {
2577
2578 LOG.debug("Inside process Item Type");
2579 Map<String, String> itemMap = new HashMap<String, String>();
2580 itemMap.put(OLEConstants.OleDeliverRequest.ITEM_TYPE_CODE, itemType);
2581 List<OleInstanceItemType> oleInstanceItemTypeList = (List<OleInstanceItemType>) businessObjectService.findMatching(OleInstanceItemType.class, itemMap);
2582 if (oleInstanceItemTypeList != null && oleInstanceItemTypeList.size() > 0) {
2583 OleInstanceItemType oleInstanceItemType = oleInstanceItemTypeList.get(0);
2584 return oleInstanceItemType.getInstanceItemTypeName();
2585 }
2586 return null;
2587 }
2588
2589 public String placeRequest(String patronBarcode, String operatorId, String itemBarcode, String requestType, String pickUpLocation, String itemIdentifier, String itemLocation, String itemType, String title, String author, String callNumber, boolean externalItem, String bibId, String requestLevel, java.sql.Date requestExpiryDate) {
2590 OLEPlaceRequest olePlaceRequest = new OLEPlaceRequest();
2591 OLEPlaceRequestConverter olePlaceRequestConverter = new OLEPlaceRequestConverter();
2592 ASRHelperServiceImpl asrHelperService = new ASRHelperServiceImpl();
2593 MaintenanceDocument newDocument = null;
2594 try {
2595 try {
2596 if (null == GlobalVariables.getUserSession()) {
2597 Person person = personService.getPerson(operatorId);
2598 String principalName = person.getPrincipalName();
2599 UserSession userSession = new UserSession(principalName);
2600 GlobalVariables.setUserSession(userSession);
2601 }
2602 newDocument = (MaintenanceDocument) getDocumentService().getNewDocument(OLEConstants.REQUEST_DOC_TYPE);
2603 } catch (WorkflowException e) {
2604 e.printStackTrace();
2605 olePlaceRequest.setBlockOverride(true);
2606 olePlaceRequest.setMessage("Cannot create");
2607 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2608 }
2609 OleDeliverRequestBo oleDeliverRequestBo = null;
2610 oleDeliverRequestBo = (OleDeliverRequestBo) newDocument.getNewMaintainableObject().getDataObject();
2611 oleDeliverRequestBo.setCreateDate(new java.sql.Date(System.currentTimeMillis()));
2612 oleDeliverRequestBo.setRequestLevel(requestLevel);
2613 oleDeliverRequestBo.setBibId(bibId);
2614 if (requestExpiryDate != null) {
2615 oleDeliverRequestBo.setRequestExpiryDate(requestExpiryDate);
2616 }
2617 OlePatronDocument olePatronDocument = null;
2618 Map<String, String> patronMap = new HashMap<String, String>();
2619 patronMap.put(OLEConstants.BARCODE, patronBarcode);
2620 OleNoticeBo oleNoticeBo = new OleNoticeBo();
2621 List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) getBusinessObjectService().findMatching(OlePatronDocument.class, patronMap);
2622 if (olePatronDocumentList.size() > 0) {
2623 olePatronDocument = olePatronDocumentList.get(0);
2624 oleDeliverRequestBo.setBorrowerId(olePatronDocument.getOlePatronId());
2625 oleDeliverRequestBo.setBorrowerBarcode(olePatronDocument.getBarcode());
2626 oleDeliverRequestBo.setOlePatron(olePatronDocument);
2627 EntityTypeContactInfoBo entityTypeContactInfoBo = olePatronDocument.getEntity().getEntityTypeContactInfos().get(0);
2628 try {
2629 oleNoticeBo.setPatronName(olePatronDocument.getEntity().getNames().get(0).getFirstName() + " " + oleDeliverRequestBo.getOlePatron().getEntity().getNames().get(0).getLastName());
2630 oleNoticeBo.setPatronAddress(getOlePatronHelperService().getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronPreferredAddress(entityTypeContactInfoBo) : "");
2631 oleNoticeBo.setPatronEmailAddress(getOlePatronHelperService().getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronHomeEmailId(entityTypeContactInfoBo) : "");
2632 oleNoticeBo.setPatronPhoneNumber(getOlePatronHelperService().getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
2633 } catch (Exception e) {
2634 LOG.error("Exception", e);
2635 olePlaceRequest.setBlockOverride(true);
2636 if (LOG.isDebugEnabled()) {
2637 LOG.debug("Exception Occured while setting the patron information for the patron . Patron Barcode : " + oleDeliverRequestBo.getBorrowerBarcode());
2638 }
2639 }
2640 } else {
2641 olePlaceRequest.setBlockOverride(true);
2642 olePlaceRequest.setCode("002");
2643 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_PATRON_INFO));
2644 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2645 }
2646 if (requestType != null) {
2647 Map<String, String> requestTypeMap = new HashMap<String, String>();
2648 requestTypeMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_CD, requestType);
2649 List<OleDeliverRequestType> oleDeliverRequestTypeList = (List<OleDeliverRequestType>) getBusinessObjectService().findMatching(OleDeliverRequestType.class, requestTypeMap);
2650 if (oleDeliverRequestTypeList != null && (oleDeliverRequestTypeList.size() > 0)) {
2651 oleDeliverRequestBo.setRequestTypeId(oleDeliverRequestTypeList.get(0).getRequestTypeId());
2652 oleDeliverRequestBo.setOleDeliverRequestType(oleDeliverRequestTypeList.get(0));
2653 } else {
2654 olePlaceRequest.setBlockOverride(true);
2655 olePlaceRequest.setCode("012");
2656 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_RQST_TYP));
2657 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2658 }
2659 }
2660 if (pickUpLocation != null) {
2661 Map<String, String> circulationDeskMap = new HashMap<String, String>();
2662 circulationDeskMap.put(OLEConstants.OleCirculationDesk.OLE_CIRCULATION_DESK_CD, pickUpLocation);
2663 List<OleCirculationDesk> oleCirculationDeskList = (List<OleCirculationDesk>) getBusinessObjectService().findMatching(OleCirculationDesk.class, circulationDeskMap);
2664 if (oleCirculationDeskList != null && oleCirculationDeskList.size() > 0) {
2665 oleDeliverRequestBo.setPickUpLocationId(oleCirculationDeskList.get(0).getCirculationDeskId());
2666 oleDeliverRequestBo.setPickUpLocationCode(oleCirculationDeskList.get(0).getCirculationDeskCode());
2667 oleDeliverRequestBo.setOlePickUpLocation(oleCirculationDeskList.get(0));
2668 } else {
2669 olePlaceRequest.setBlockOverride(true);
2670 olePlaceRequest.setCode("013");
2671 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_PK_UP_LOCN));
2672 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2673 }
2674
2675 }
2676 try {
2677 if (itemBarcode == null || (itemBarcode != null && itemBarcode.isEmpty())) {
2678 olePlaceRequest.setBlockOverride(true);
2679 olePlaceRequest.setCode("014");
2680 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_BARCODE_DOESNOT_EXISTS));
2681 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2682
2683 }
2684 oleDeliverRequestBo.setItemId(itemBarcode);
2685 oleDeliverRequestBo.setItemUuid(itemIdentifier);
2686 oleDeliverRequestBo.setItemStatus(OLEConstants.AVAILABLE);
2687 oleDeliverRequestBo.setItemType(itemType);
2688 oleDeliverRequestBo.setItemLocation(itemLocation);
2689 if (itemIdentifier == null || itemLocation == null || itemType == null) {
2690 Thread.sleep(500);
2691 String itemUUID = null;
2692 String holdingsId = null;
2693 if (itemIdentifier == null) {
2694 try {
2695 org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
2696 org.kuali.ole.docstore.common.search.SearchParams search_Params = new org.kuali.ole.docstore.common.search.SearchParams();
2697 SearchResponse searchResponse = null;
2698 search_Params.getSearchConditions().add(search_Params.buildSearchCondition("phrase", search_Params.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), item.ITEM_BARCODE, oleDeliverRequestBo.getItemId()), ""));
2699 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), "id"));
2700 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.HOLDINGS.getCode(), "id"));
2701 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(search_Params);
2702 for (SearchResult searchResult : searchResponse.getSearchResults()) {
2703 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
2704 String fieldName = searchResultField.getFieldName();
2705 String fieldValue = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
2706 if (fieldName.equalsIgnoreCase("id") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("holdings")) {
2707 holdingsId = fieldValue;
2708 } else {
2709 oleDeliverRequestBo.setItemUuid(fieldValue);
2710 itemUUID = fieldValue;
2711 }
2712 }
2713 }
2714 } catch (Exception ex) {
2715 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_EXIST));
2716 LOG.error(OLEConstants.ITEM_EXIST + ex);
2717 }
2718 }
2719 if (itemUUID == null) {
2720 olePlaceRequest.setBlockOverride(true);
2721 olePlaceRequest.setCode("014");
2722 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_BARCODE_DOESNOT_EXISTS));
2723 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2724 }
2725 if (itemType == null || itemLocation == null) {
2726 Map<String, Object> detailMap = retrieveBIbItemHoldingData(itemUUID);
2727 Bib bib = (Bib) detailMap.get(OLEConstants.BIB);
2728 Item item = (Item) detailMap.get(OLEConstants.ITEM);
2729 OleHoldings oleHoldings = (OleHoldings) detailMap.get(OLEConstants.HOLDING);
2730 org.kuali.ole.docstore.common.document.Item item1 = (org.kuali.ole.docstore.common.document.Item) detailMap.get("documentItem");
2731 if (item != null) {
2732 oleDeliverRequestBo.setOleItem(item);
2733 if (item.getCallNumber() != null && StringUtils.isNotBlank(item.getCallNumber().getNumber())) {
2734 oleDeliverRequestBo.setCallNumber(item.getCallNumber().getNumber());
2735 }
2736 if (StringUtils.isNotBlank(item.getCopyNumber())) {
2737 oleDeliverRequestBo.setCopyNumber(item.getCopyNumber());
2738 }
2739 oleDeliverRequestBo.setVolumeNumber(item.getVolumeNumber() != null ? item.getVolumeNumber() : "");
2740 oleDeliverRequestBo.setEnumeration(item.getEnumeration() != null ? item.getEnumeration() : "");
2741 oleDeliverRequestBo.setChronology(item.getChronology() != null ? item.getChronology() : "");
2742 }
2743 if (oleHoldings != null) {
2744 if (StringUtils.isBlank(oleDeliverRequestBo.getCallNumber()) && oleHoldings.getCallNumber() != null && StringUtils.isNotBlank(oleHoldings.getCallNumber().getNumber())) {
2745 oleDeliverRequestBo.setCallNumber(oleHoldings.getCallNumber().getNumber());
2746 }
2747 if (StringUtils.isBlank(oleDeliverRequestBo.getCopyNumber()) && oleHoldings.getCopyNumber() != null) {
2748 oleDeliverRequestBo.setCopyNumber(oleHoldings.getCopyNumber());
2749 }
2750 }
2751 if (itemLocation == null) {
2752 if (item1.getLocation() == null || (item1.getLocation() != null && item1.getLocation().trim().isEmpty())) {
2753 itemLocation = getDocstoreUtil().getLocation(oleHoldings.getLocation(), new StringBuffer(""));
2754 } else {
2755 itemLocation = item1.getLocation();
2756 }
2757 oleDeliverRequestBo.setItemLocation(itemLocation);
2758 }
2759 if (item.getItemType() != null) {
2760 oleDeliverRequestBo.setItemType(item.getItemType().getCodeValue());
2761 }
2762 if (item.getItemStatus() != null) {
2763 oleDeliverRequestBo.setItemStatus(item.getItemStatus().getCodeValue());
2764 }
2765
2766 if (bib != null) {
2767 oleDeliverRequestBo.setTitle(bib.getTitle());
2768 oleDeliverRequestBo.setAuthor(bib.getAuthor());
2769 }
2770 }
2771 }
2772
2773 if (itemLocation != null) {
2774 if (asrHelperService.isAnASRItem(itemLocation) && isValidASRItemStatus(oleDeliverRequestBo.getItemStatus()) && !oleDeliverRequestBo.getRequestTypeCode().equals(getLoanProcessor().getParameter(ASRConstants.ASR_TYP_RQST))) {
2775 olePlaceRequest.setCode("700");
2776 olePlaceRequest.setBlockOverride(true);
2777 olePlaceRequest.setMessage("Cannot create " + oleDeliverRequestBo.getRequestTypeCode() + " for this item");
2778 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2779 } else if (asrHelperService.isAnASRItem(itemLocation) && !isValidASRItemStatus(oleDeliverRequestBo.getItemStatus()) && oleDeliverRequestBo.getRequestTypeCode().equals(getLoanProcessor().getParameter(ASRConstants.ASR_TYP_RQST))) {
2780 olePlaceRequest.setCode("701");
2781 olePlaceRequest.setBlockOverride(true);
2782 olePlaceRequest.setMessage("Cannot create " + oleDeliverRequestBo.getRequestTypeCode() + " for this item");
2783 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2784 }
2785 Map<String, String> locationMap = getCircDeskLocationResolver().getLocationMap(itemLocation);
2786 oleDeliverRequestBo.setItemLibrary(locationMap.get(OLEConstants.ITEM_LIBRARY));
2787 oleDeliverRequestBo.setItemInstitution(locationMap.get(OLEConstants.ITEM_INSTITUTION));
2788 oleDeliverRequestBo.setItemCampus(locationMap.get(OLEConstants.ITEM_CAMPUS));
2789 oleDeliverRequestBo.setItemCollection(locationMap.get(OLEConstants.ITEM_COLLECTION));
2790 oleDeliverRequestBo.setShelvingLocation(locationMap.get(OLEConstants.ITEM_SHELVING));
2791 }
2792 oleDeliverRequestBo.setRequestCreator(OLEConstants.OleDeliverRequest.REQUESTER_OPERATOR);
2793 oleDeliverRequestBo.setOperatorCreateId(operatorId);
2794 oleDeliverRequestBo.setItemId(itemBarcode);
2795
2796
2797
2798
2799
2800 processRequestTypeByPickUpLocation(oleDeliverRequestBo);
2801 String message = this.patronRecordExpired(oleDeliverRequestBo);
2802 if (message != null) {
2803 olePlaceRequest.setCode("015");
2804 olePlaceRequest.setMessage(message);
2805 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2806 }
2807 boolean requestRaised = this.isRequestAlreadyRaisedByPatron(oleDeliverRequestBo);
2808 if (requestRaised) {
2809 {
2810 olePlaceRequest.setBlockOverride(true);
2811 olePlaceRequest.setCode("016");
2812 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RQST_ALRDY_RAISD));
2813 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2814 }
2815 }
2816 boolean itemEligible = this.isItemEligible(oleDeliverRequestBo);
2817 if (!itemEligible) {
2818 {
2819 olePlaceRequest.setBlockOverride(true);
2820 olePlaceRequest.setCode("017");
2821 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITM_NOT_LOAN));
2822 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2823 }
2824 }
2825 boolean alreadyLoaned = this.isAlreadyLoaned(oleDeliverRequestBo);
2826 if (alreadyLoaned) {
2827 olePlaceRequest.setBlockOverride(true);
2828 olePlaceRequest.setCode("018");
2829 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITM_LOAN_BY_PTRN));
2830 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2831 }
2832 SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
2833 boolean valid = false;
2834 String errorMessage = fireRules(oleDeliverRequestBo,false,false);
2835
2836 if ((oleDeliverRequestBo.getMessage() != null && !oleDeliverRequestBo.getMessage().isEmpty())) {
2837 olePlaceRequest.setCode("500");
2838 olePlaceRequest.setMessage(oleDeliverRequestBo.getMessage().replaceAll("<br/>", ""));
2839 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2840 }
2841
2842
2843 OleDeliverRequestBo oleDeliverRequestBo1 = null;
2844 boolean asrItem = false;
2845 try {
2846 oleDeliverRequestBo1 = oleDeliverRequestBo;
2847 if (isItemAvailable(oleDeliverRequestBo1)) {
2848 olePlaceRequest.setBlockOverride(true);
2849 olePlaceRequest.setCode("019");
2850 olePlaceRequest.setMessage(oleDeliverRequestBo1.getRequestTypeCode() + OLEConstants.RQST_CONDITION + oleDeliverRequestBo1.getItemStatus());
2851 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2852 }
2853 oleDeliverRequestBo.setOleItem(null);
2854 asrItem = asrHelperService.isAnASRItem(oleDeliverRequestBo.getItemLocation());
2855 if (asrItem && isValidASRItemStatus(oleDeliverRequestBo.getItemInstitution())) {
2856 oleDeliverRequestBo.setAsrFlag(true);
2857 oleDeliverRequestBo.setRequestStatus("1");
2858 }
2859 newDocument.getDocumentHeader().setDocumentDescription(OLEConstants.NEW_REQUEST_DOC);
2860 newDocument.getNewMaintainableObject().setDataObject(oleDeliverRequestBo1);
2861
2862 newDocument = (MaintenanceDocument) getDocumentService().routeDocument(newDocument, null, null);
2863 oleDeliverRequestBo = (OleDeliverRequestBo) newDocument.getNewMaintainableObject().getDataObject();
2864 } catch (WorkflowException e) {
2865 e.printStackTrace();
2866 }
2867
2868
2869 String requestId = "";
2870
2871 try {
2872 requestId = ":" + OLEConstants.OleDeliverRequest.REQUEST_ID + ":" + oleDeliverRequestBo.getRequestId();
2873
2874 if (!oleDeliverRequestBo.getRequestTypeId().equals("8")) {
2875 oleDeliverRequestBo = updateLoanDocument(oleDeliverRequestBo);
2876 oleDeliverRequestBo.setOlePatron(null);
2877 oleDeliverRequestBo.setOleProxyPatron(null);
2878 }
2879 if (LOG.isDebugEnabled()) {
2880 LOG.debug("Request Raised Succesfully" + requestId);
2881 }
2882 if (externalItem) {
2883 String noticeSendParameter = getLoanProcessor().getParameter(OLEParameterConstants.NCIP_ACCEPT_ITEM_NOTICE_INDICATOR);
2884 if (noticeSendParameter != null && (noticeSendParameter.trim().isEmpty() || noticeSendParameter.equalsIgnoreCase("Y"))) {
2885 oleNoticeBo.setNoticeName(OLEConstants.PICKUP_NOTICE);
2886 Date pickupDate = new java.sql.Date(System.currentTimeMillis());
2887 if (oleDeliverRequestBo.getOlePickUpLocation() != null && oleDeliverRequestBo.getOlePickUpLocation().getOnHoldDays() != null) {
2888 pickupDate = addDate(new java.sql.Date(System.currentTimeMillis()), new Integer(oleDeliverRequestBo.getOlePickUpLocation().getOnHoldDays()));
2889 }
2890 oleNoticeBo.setNoticeSpecificContent(OLEConstants.PICKUP_NOTICE_START_CONTENT + oleDeliverRequestBo.getOlePickUpLocation().getCirculationDeskPublicName() + OLEConstants.PICKUP_NOTICE_MIDDLE_CONTENT + pickupDate + OLEConstants.PICKUP_NOTICE_FINAL_CONTENT);
2891 oleNoticeBo.setAuthor(author);
2892 oleNoticeBo.setItemCallNumber(callNumber);
2893 oleNoticeBo.setItemId(itemBarcode);
2894 oleNoticeBo.setTitle(title);
2895 oleNoticeBo.setCirculationDeskName(oleDeliverRequestBo.getOlePickUpLocation().getCirculationDeskPublicName());
2896 oleNoticeBo.setCirculationDeskReplyToEmail(oleDeliverRequestBo.getOlePickUpLocation().getReplyToEmail());
2897 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
2898 String content = oleDeliverBatchService.getEmailPickUpNotice(oleNoticeBo);
2899 try {
2900 if (!content.trim().equals("")) {
2901 OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
2902 if (oleDeliverRequestBo.getOlePickUpLocation() != null && StringUtils.isNotBlank(oleDeliverRequestBo.getOlePickUpLocation().getReplyToEmail())) {
2903 oleMailer.sendEmail(new EmailFrom(oleDeliverRequestBo.getOlePickUpLocation().getReplyToEmail()), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(content), true);
2904 } else {
2905 String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
2906 if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
2907 fromAddress = OLEConstants.KUALI_MAIL;
2908 }
2909 oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(content), true);
2910 }
2911 if (LOG.isDebugEnabled()) {
2912 LOG.debug("Mail send Successfully to " + oleNoticeBo.getPatronEmailAddress());
2913 }
2914 oleDeliverBatchService.getPdfPickUpNotice(oleNoticeBo);
2915 } else {
2916 if (LOG.isDebugEnabled()) {
2917 LOG.debug("Notice Type :" + oleNoticeBo.getNoticeName() + " " + "Item Barcode : " + oleNoticeBo.getItemId() + " " + "Patron Name :" + oleNoticeBo.getPatronName());
2918 }
2919 }
2920 } catch (Exception e) {
2921 LOG.error("Exception", e);
2922 olePlaceRequest.setCode("020");
2923 olePlaceRequest.setQueuePosition(String.valueOf(oleDeliverRequestBo.getBorrowerQueuePosition()));
2924 olePlaceRequest.setMessage(OLEConstants.RQST_SUCCESS + requestId + OLEConstants.NTCE_PRBLM);
2925 olePlaceRequest.setRequestId(oleDeliverRequestBo.getRequestId());
2926 olePlaceRequest.setAvailableDate(getAvailableDate(itemBarcode));
2927 if (oleDeliverRequestBo.getRequestExpiryDate() != null) {
2928 olePlaceRequest.setExpirationDate(fmt.format(oleDeliverRequestBo.getRequestExpiryDate()));
2929 }
2930 olePlaceRequest.setBlockOverride(true);
2931 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2932 }
2933 }
2934 }
2935
2936 } catch (Exception e) {
2937 LOG.error("Exception", e);
2938 olePlaceRequest.setCode("020");
2939 olePlaceRequest.setQueuePosition(String.valueOf(oleDeliverRequestBo.getBorrowerQueuePosition()));
2940 olePlaceRequest.setMessage(OLEConstants.RQST_SUCCESS + requestId + OLEConstants.RQST_PRBLM);
2941 olePlaceRequest.setRequestId(oleDeliverRequestBo.getRequestId());
2942 olePlaceRequest.setAvailableDate(getAvailableDate(itemBarcode));
2943 if (oleDeliverRequestBo.getRequestExpiryDate() != null) {
2944 olePlaceRequest.setExpirationDate(fmt.format(oleDeliverRequestBo.getRequestExpiryDate()));
2945 }
2946 olePlaceRequest.setBlockOverride(true);
2947 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2948
2949 }
2950 olePlaceRequest.setCode("021");
2951 olePlaceRequest.setRequestId(oleDeliverRequestBo.getRequestId());
2952 olePlaceRequest.setAvailableDate(getAvailableDate(itemBarcode));
2953 olePlaceRequest.setQueuePosition(String.valueOf(oleDeliverRequestBo.getBorrowerQueuePosition()));
2954 if (oleDeliverRequestBo.getRequestExpiryDate() != null) {
2955 olePlaceRequest.setExpirationDate(fmt.format(oleDeliverRequestBo.getRequestExpiryDate()));
2956 }
2957 olePlaceRequest.setMessage(OLEConstants.RQST_SUCCESS + requestId);
2958 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2959 } catch (Exception e) {
2960 LOG.error("Exception", e);
2961 olePlaceRequest.setBlockOverride(true);
2962 if (e.getMessage() != null && e.getMessage().equalsIgnoreCase("Item barcode does not exist.")) {
2963 olePlaceRequest.setCode("014");
2964 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_BARCODE_DOESNOT_EXISTS));
2965 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2966 }
2967 olePlaceRequest.setCode("023");
2968 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RQST_FAIL));
2969 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2970 }
2971 } catch (Exception e) {
2972 LOG.error("Exception", e);
2973 olePlaceRequest.setBlockOverride(true);
2974 olePlaceRequest.setCode("023");
2975 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RQST_FAIL));
2976 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2977 }
2978 }
2979
2980 private DocumentService getDocumentService() {
2981 if (null == documentService) {
2982 documentService = GlobalResourceLoader.getService(OLEConstants.DOCUMENT_HEADER_SERVICE);
2983 }
2984 return documentService;
2985 }
2986
2987 public void setDocumentService(DocumentService documentService) {
2988 this.documentService = documentService;
2989 }
2990
2991 public String overridePlaceRequest(String patronBarcode, String operatorId, String itemBarcode, String requestType, String pickUpLocation, String itemIdentifier, String itemLocation, String itemType, String title, String author, String callNumber, boolean externalItem, String bibId, String requestLevel, java.sql.Date requestExpiryDate) {
2992 OLEPlaceRequest olePlaceRequest = new OLEPlaceRequest();
2993 OLEPlaceRequestConverter olePlaceRequestConverter = new OLEPlaceRequestConverter();
2994 ASRHelperServiceImpl asrHelperService = new ASRHelperServiceImpl();
2995 MaintenanceDocument newDocument = null;
2996 try {
2997 try {
2998 if (null == GlobalVariables.getUserSession()) {
2999 Person person = personService.getPerson(operatorId);
3000 String principalName = person.getPrincipalName();
3001 UserSession userSession = new UserSession(principalName);
3002 GlobalVariables.setUserSession(userSession);
3003 }
3004 newDocument = (MaintenanceDocument) getDocumentService().getNewDocument(OLEConstants.REQUEST_DOC_TYPE);
3005 } catch (WorkflowException e) {
3006 e.printStackTrace();
3007 olePlaceRequest.setMessage("Cannot create");
3008 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
3009 }
3010 OleDeliverRequestBo oleDeliverRequestBo = null;
3011 oleDeliverRequestBo = (OleDeliverRequestBo) newDocument.getNewMaintainableObject().getDataObject();
3012 oleDeliverRequestBo.setCreateDate(new java.sql.Date(System.currentTimeMillis()));
3013 oleDeliverRequestBo.setRequestLevel(requestLevel);
3014 oleDeliverRequestBo.setBibId(bibId);
3015 if (requestExpiryDate != null) {
3016 oleDeliverRequestBo.setRequestExpiryDate(requestExpiryDate);
3017 }
3018 OlePatronDocument olePatronDocument = null;
3019 Map<String, String> patronMap = new HashMap<String, String>();
3020 patronMap.put(OLEConstants.BARCODE, patronBarcode);
3021 OleNoticeBo oleNoticeBo = new OleNoticeBo();
3022 List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) getBusinessObjectService().findMatching(OlePatronDocument.class, patronMap);
3023 if (olePatronDocumentList.size() > 0) {
3024 olePatronDocument = olePatronDocumentList.get(0);
3025 oleDeliverRequestBo.setBorrowerId(olePatronDocument.getOlePatronId());
3026 oleDeliverRequestBo.setBorrowerBarcode(olePatronDocument.getBarcode());
3027 oleDeliverRequestBo.setOlePatron(olePatronDocument);
3028 EntityTypeContactInfoBo entityTypeContactInfoBo = olePatronDocument.getEntity().getEntityTypeContactInfos().get(0);
3029 try {
3030 oleNoticeBo.setPatronName(olePatronDocument.getEntity().getNames().get(0).getFirstName() + " " + oleDeliverRequestBo.getOlePatron().getEntity().getNames().get(0).getLastName());
3031 oleNoticeBo.setPatronAddress(getOlePatronHelperService().getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronPreferredAddress(entityTypeContactInfoBo) : "");
3032 oleNoticeBo.setPatronEmailAddress(getOlePatronHelperService().getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronHomeEmailId(entityTypeContactInfoBo) : "");
3033 oleNoticeBo.setPatronPhoneNumber(getOlePatronHelperService().getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
3034 } catch (Exception e) {
3035 LOG.error("Exception", e);
3036 if (LOG.isDebugEnabled()) {
3037 LOG.debug("Exception Occured while setting the patron information for the patron . Patron Barcode : " + oleDeliverRequestBo.getBorrowerBarcode());
3038 }
3039 }
3040 }
3041 if (requestType != null) {
3042 Map<String, String> requestTypeMap = new HashMap<String, String>();
3043 requestTypeMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_CD, requestType);
3044 List<OleDeliverRequestType> oleDeliverRequestTypeList = (List<OleDeliverRequestType>) getBusinessObjectService().findMatching(OleDeliverRequestType.class, requestTypeMap);
3045 if (oleDeliverRequestTypeList != null && (oleDeliverRequestTypeList.size() > 0)) {
3046 oleDeliverRequestBo.setRequestTypeId(oleDeliverRequestTypeList.get(0).getRequestTypeId());
3047 oleDeliverRequestBo.setOleDeliverRequestType(oleDeliverRequestTypeList.get(0));
3048 }
3049 }
3050 if (pickUpLocation != null) {
3051 Map<String, String> circulationDeskMap = new HashMap<String, String>();
3052 circulationDeskMap.put(OLEConstants.OleCirculationDesk.OLE_CIRCULATION_DESK_CD, pickUpLocation);
3053 List<OleCirculationDesk> oleCirculationDeskList = (List<OleCirculationDesk>) getBusinessObjectService().findMatching(OleCirculationDesk.class, circulationDeskMap);
3054 if (oleCirculationDeskList != null && oleCirculationDeskList.size() > 0) {
3055 oleDeliverRequestBo.setPickUpLocationId(oleCirculationDeskList.get(0).getCirculationDeskId());
3056 oleDeliverRequestBo.setPickUpLocationCode(oleCirculationDeskList.get(0).getCirculationDeskCode());
3057 oleDeliverRequestBo.setOlePickUpLocation(oleCirculationDeskList.get(0));
3058 }
3059 }
3060 try {
3061 oleDeliverRequestBo.setItemId(itemBarcode);
3062 oleDeliverRequestBo.setItemUuid(itemIdentifier);
3063 oleDeliverRequestBo.setItemStatus(OLEConstants.AVAILABLE);
3064 oleDeliverRequestBo.setItemType(itemType);
3065 oleDeliverRequestBo.setItemLocation(itemLocation);
3066 if (itemIdentifier == null || itemLocation == null || itemType == null) {
3067 Thread.sleep(500);
3068 String itemUUID = null;
3069 String holdingsId = null;
3070 if (itemIdentifier == null) {
3071 try {
3072 org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
3073 org.kuali.ole.docstore.common.search.SearchParams search_Params = new org.kuali.ole.docstore.common.search.SearchParams();
3074 SearchResponse searchResponse = null;
3075 search_Params.getSearchConditions().add(search_Params.buildSearchCondition("phrase", search_Params.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), item.ITEM_BARCODE, oleDeliverRequestBo.getItemId()), ""));
3076 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), "id"));
3077 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.HOLDINGS.getCode(), "id"));
3078 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(search_Params);
3079 for (SearchResult searchResult : searchResponse.getSearchResults()) {
3080 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
3081 String fieldName = searchResultField.getFieldName();
3082 String fieldValue = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
3083 if (fieldName.equalsIgnoreCase("id") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("holdings")) {
3084 holdingsId = fieldValue;
3085 } else {
3086 oleDeliverRequestBo.setItemUuid(fieldValue);
3087 itemUUID = fieldValue;
3088 }
3089 }
3090 }
3091 } catch (Exception ex) {
3092 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_EXIST));
3093 LOG.error(OLEConstants.ITEM_EXIST + ex);
3094 }
3095 }
3096 if (itemType == null || itemLocation == null) {
3097 Map<String, Object> detailMap = retrieveBIbItemHoldingData(itemUUID);
3098 Bib bib = (Bib) detailMap.get(OLEConstants.BIB);
3099 Item item = (Item) detailMap.get(OLEConstants.ITEM);
3100 OleHoldings oleHoldings = (OleHoldings) detailMap.get(OLEConstants.HOLDING);
3101 org.kuali.ole.docstore.common.document.Item item1 = (org.kuali.ole.docstore.common.document.Item) detailMap.get("documentItem");
3102 if (item != null) {
3103 oleDeliverRequestBo.setOleItem(item);
3104 if (item.getCallNumber() != null && StringUtils.isNotBlank(item.getCallNumber().getNumber())) {
3105 oleDeliverRequestBo.setCallNumber(item.getCallNumber().getNumber());
3106 }
3107 if (StringUtils.isNotBlank(item.getCopyNumber())) {
3108 oleDeliverRequestBo.setCopyNumber(item.getCopyNumber());
3109 }
3110 oleDeliverRequestBo.setVolumeNumber(item.getVolumeNumber() != null ? item.getVolumeNumber() : "");
3111 oleDeliverRequestBo.setEnumeration(item.getEnumeration() != null ? item.getEnumeration() : "");
3112 oleDeliverRequestBo.setChronology(item.getChronology() != null ? item.getChronology() : "");
3113 }
3114 if (oleHoldings != null) {
3115 if (StringUtils.isBlank(oleDeliverRequestBo.getCallNumber()) && oleHoldings.getCallNumber() != null && StringUtils.isNotBlank(oleHoldings.getCallNumber().getNumber())) {
3116 oleDeliverRequestBo.setCallNumber(oleHoldings.getCallNumber().getNumber());
3117 }
3118 if (StringUtils.isBlank(oleDeliverRequestBo.getCopyNumber()) && StringUtils.isNotBlank(oleHoldings.getCopyNumber())) {
3119 oleDeliverRequestBo.setCopyNumber(oleHoldings.getCopyNumber());
3120 }
3121 }
3122 if (itemLocation == null) {
3123 if (item1.getLocation() == null || (item1.getLocation() != null && item1.getLocation().trim().isEmpty())) {
3124 itemLocation = getDocstoreUtil().getLocation(oleHoldings.getLocation(), new StringBuffer(""));
3125 } else {
3126 itemLocation = item1.getLocation();
3127 }
3128 oleDeliverRequestBo.setItemLocation(itemLocation);
3129 }
3130 if (item.getItemType() != null) {
3131 oleDeliverRequestBo.setItemType(item.getItemType().getCodeValue());
3132 }
3133 if (item.getItemStatus() != null) {
3134 oleDeliverRequestBo.setItemStatus(item.getItemStatus().getCodeValue());
3135 }
3136
3137 if (bib != null) {
3138 oleDeliverRequestBo.setTitle(bib.getTitle());
3139 oleDeliverRequestBo.setAuthor(bib.getAuthor());
3140 }
3141 }
3142 }
3143
3144 if (itemLocation != null) {
3145 if (asrHelperService.isAnASRItem(itemLocation) && isValidASRItemStatus(oleDeliverRequestBo.getItemStatus()) && !oleDeliverRequestBo.getRequestTypeCode().equals(getLoanProcessor().getParameter(ASRConstants.ASR_TYP_RQST))) {
3146 olePlaceRequest.setCode("700");
3147 olePlaceRequest.setMessage("Cannot create " + oleDeliverRequestBo.getRequestTypeCode() + " for this item");
3148 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
3149 } else if (asrHelperService.isAnASRItem(itemLocation) && !isValidASRItemStatus(oleDeliverRequestBo.getItemStatus()) && oleDeliverRequestBo.getRequestTypeCode().equals(getLoanProcessor().getParameter(ASRConstants.ASR_TYP_RQST))) {
3150 olePlaceRequest.setCode("701");
3151 olePlaceRequest.setMessage("Cannot create " + oleDeliverRequestBo.getRequestTypeCode() + " for this item");
3152 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
3153 }
3154 Map<String, String> locationMap = getCircDeskLocationResolver().getLocationMap(itemLocation);
3155 oleDeliverRequestBo.setItemLibrary(locationMap.get(OLEConstants.ITEM_LIBRARY));
3156 oleDeliverRequestBo.setItemInstitution(locationMap.get(OLEConstants.ITEM_INSTITUTION));
3157 oleDeliverRequestBo.setItemCampus(locationMap.get(OLEConstants.ITEM_CAMPUS));
3158 oleDeliverRequestBo.setItemCollection(locationMap.get(OLEConstants.ITEM_COLLECTION));
3159 oleDeliverRequestBo.setShelvingLocation(locationMap.get(OLEConstants.ITEM_SHELVING));
3160 }
3161 oleDeliverRequestBo.setRequestCreator(OLEConstants.OleDeliverRequest.REQUESTER_OPERATOR);
3162 oleDeliverRequestBo.setOperatorCreateId(operatorId);
3163 oleDeliverRequestBo.setItemId(itemBarcode);
3164 processRequestTypeByPickUpLocation(oleDeliverRequestBo);
3165 SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
3166 boolean valid = false;
3167 fireRules(oleDeliverRequestBo,false,true);
3168 if(oleDeliverRequestBo.getMessage()!=null&&oleDeliverRequestBo.getMessage().equals(OLEConstants.NO_RULE_FOUND)){
3169 olePlaceRequest.setCode("500");
3170 olePlaceRequest.setMessage(oleDeliverRequestBo.getMessage());
3171 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
3172 }
3173 OleDeliverRequestBo oleDeliverRequestBo1 = null;
3174 boolean asrItem = false;
3175 try {
3176 oleDeliverRequestBo1 = oleDeliverRequestBo;
3177 oleDeliverRequestBo.setOleItem(null);
3178 asrItem = asrHelperService.isAnASRItem(oleDeliverRequestBo.getItemLocation());
3179 if (asrItem && oleDeliverRequestBo.getItemStatus().equals(getLoanProcessor().getParameter(ASRConstants.ASR_REQUEST_ITEM_STATUS))) {
3180 oleDeliverRequestBo.setAsrFlag(true);
3181 oleDeliverRequestBo.setRequestStatus("1");
3182 }
3183 newDocument.getDocumentHeader().setDocumentDescription(OLEConstants.NEW_REQUEST_DOC);
3184 newDocument.getNewMaintainableObject().setDataObject(oleDeliverRequestBo1);
3185 newDocument = (MaintenanceDocument) getDocumentService().routeDocument(newDocument, null, null);
3186 oleDeliverRequestBo = (OleDeliverRequestBo) newDocument.getNewMaintainableObject().getDataObject();
3187 } catch (WorkflowException e) {
3188 e.printStackTrace();
3189 }
3190
3191
3192 String requestId = "";
3193
3194 try {
3195 requestId = ":" + OLEConstants.OleDeliverRequest.REQUEST_ID + ":" + oleDeliverRequestBo.getRequestId();
3196
3197 if (!oleDeliverRequestBo.getRequestTypeId().equals("8")) {
3198 oleDeliverRequestBo = updateLoanDocument(oleDeliverRequestBo);
3199 oleDeliverRequestBo.setOlePatron(null);
3200 oleDeliverRequestBo.setOleProxyPatron(null);
3201 }
3202 if (LOG.isDebugEnabled()) {
3203 LOG.debug("Request Raised Succesfully" + requestId);
3204 }
3205 if (externalItem) {
3206 String noticeSendParameter = getLoanProcessor().getParameter(OLEParameterConstants.NCIP_ACCEPT_ITEM_NOTICE_INDICATOR);
3207 if (noticeSendParameter != null && (noticeSendParameter.trim().isEmpty() || noticeSendParameter.equalsIgnoreCase("Y"))) {
3208 oleNoticeBo.setNoticeName(OLEConstants.PICKUP_NOTICE);
3209 Date pickupDate = new java.sql.Date(System.currentTimeMillis());
3210 if (oleDeliverRequestBo.getOlePickUpLocation().getOnHoldDays() != null) {
3211 pickupDate = addDate(new java.sql.Date(System.currentTimeMillis()), new Integer(oleDeliverRequestBo.getOlePickUpLocation().getOnHoldDays()));
3212 }
3213 oleNoticeBo.setNoticeSpecificContent(OLEConstants.PICKUP_NOTICE_START_CONTENT + oleDeliverRequestBo.getOlePickUpLocation().getCirculationDeskPublicName() + OLEConstants.PICKUP_NOTICE_MIDDLE_CONTENT + pickupDate + OLEConstants.PICKUP_NOTICE_FINAL_CONTENT);
3214 oleNoticeBo.setAuthor(author);
3215 oleNoticeBo.setItemCallNumber(callNumber);
3216 oleNoticeBo.setItemId(itemBarcode);
3217 oleNoticeBo.setTitle(title);
3218 oleNoticeBo.setCirculationDeskName(oleDeliverRequestBo.getOlePickUpLocation().getCirculationDeskPublicName());
3219 oleNoticeBo.setCirculationDeskReplyToEmail(oleDeliverRequestBo.getOlePickUpLocation().getReplyToEmail());
3220 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
3221 String content = oleDeliverBatchService.getEmailPickUpNotice(oleNoticeBo);
3222 try {
3223 if (!content.trim().equals("")) {
3224 OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
3225 if (oleDeliverRequestBo.getOlePickUpLocation() != null && StringUtils.isNotBlank(oleDeliverRequestBo.getOlePickUpLocation().getReplyToEmail())) {
3226 oleMailer.sendEmail(new EmailFrom(oleDeliverRequestBo.getOlePickUpLocation().getReplyToEmail()), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(content), true);
3227 } else {
3228 String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
3229 if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
3230 fromAddress = OLEConstants.KUALI_MAIL;
3231 }
3232 oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(content), true);
3233 }
3234 if (LOG.isDebugEnabled()) {
3235 LOG.debug("Mail send Successfully to " + oleNoticeBo.getPatronEmailAddress());
3236 }
3237 oleDeliverBatchService.getPdfPickUpNotice(oleNoticeBo);
3238 } else {
3239 if (LOG.isDebugEnabled()) {
3240 LOG.debug("Notice Type :" + oleNoticeBo.getNoticeName() + " " + "Item Barcode : " + oleNoticeBo.getItemId() + " " + "Patron Name :" + oleNoticeBo.getPatronName());
3241 }
3242 }
3243 } catch (Exception e) {
3244 LOG.error("Exception", e);
3245 olePlaceRequest.setCode("020");
3246 olePlaceRequest.setQueuePosition(String.valueOf(oleDeliverRequestBo.getBorrowerQueuePosition()));
3247 olePlaceRequest.setMessage(OLEConstants.RQST_SUCCESS + requestId + OLEConstants.NTCE_PRBLM);
3248 olePlaceRequest.setRequestId(oleDeliverRequestBo.getRequestId());
3249 olePlaceRequest.setAvailableDate(getAvailableDate(itemBarcode));
3250 if (oleDeliverRequestBo.getRequestExpiryDate() != null) {
3251 olePlaceRequest.setExpirationDate(fmt.format(oleDeliverRequestBo.getRequestExpiryDate()));
3252 }
3253 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
3254 }
3255 }
3256 }
3257
3258 } catch (Exception e) {
3259 LOG.error("Exception", e);
3260 olePlaceRequest.setCode("020");
3261 olePlaceRequest.setQueuePosition(String.valueOf(oleDeliverRequestBo.getBorrowerQueuePosition()));
3262 olePlaceRequest.setMessage(OLEConstants.RQST_SUCCESS + requestId + OLEConstants.RQST_PRBLM);
3263 olePlaceRequest.setRequestId(oleDeliverRequestBo.getRequestId());
3264 olePlaceRequest.setAvailableDate(getAvailableDate(itemBarcode));
3265 if (oleDeliverRequestBo.getRequestExpiryDate() != null) {
3266 olePlaceRequest.setExpirationDate(fmt.format(oleDeliverRequestBo.getRequestExpiryDate()));
3267 }
3268 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
3269
3270 }
3271 olePlaceRequest.setCode("021");
3272 olePlaceRequest.setRequestId(oleDeliverRequestBo.getRequestId());
3273 olePlaceRequest.setAvailableDate(getAvailableDate(itemBarcode));
3274 olePlaceRequest.setQueuePosition(String.valueOf(oleDeliverRequestBo.getBorrowerQueuePosition()));
3275 olePlaceRequest.setMessage(OLEConstants.RQST_SUCCESS + requestId);
3276 if (oleDeliverRequestBo.getRequestExpiryDate() != null) {
3277 olePlaceRequest.setExpirationDate(fmt.format(oleDeliverRequestBo.getRequestExpiryDate()));
3278 }
3279 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
3280 } catch (Exception e) {
3281 LOG.error("Exception", e);
3282 olePlaceRequest.setCode("023");
3283 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RQST_FAIL));
3284 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
3285 }
3286 } catch (Exception e) {
3287 LOG.error("Exception", e);
3288 olePlaceRequest.setCode("023");
3289 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RQST_FAIL));
3290 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
3291 }
3292 }
3293
3294 public String getAvailableDate(String itemBarcode) {
3295 Map<String, String> loanMap = new HashMap<>();
3296 SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
3297 simpleDateFormat.applyPattern(OLEConstants.GREGORIAN_PATTERN);
3298 loanMap.put(OLEConstants.OleDeliverRequest.ITEM_ID, itemBarcode);
3299 String date = null;
3300 List<OleLoanDocument> loanDocuments = (List<OleLoanDocument>) getBusinessObjectService().findMatching(OleLoanDocument.class, loanMap);
3301 if (loanDocuments.size() > 0) {
3302 if (loanDocuments.get(0).getLoanDueDate() != null) {
3303 date = loanDocuments.get(0).getLoanDueDate().toString();
3304 } else {
3305 date = simpleDateFormat.format(new Timestamp(2025, 1, 1, 1, 1, 1, 1));
3306 }
3307 } else {
3308 date = simpleDateFormat.format(new Timestamp(new java.sql.Date(System.currentTimeMillis()).getTime()));
3309 }
3310 return date;
3311 }
3312
3313
3314 public java.sql.Date addDate(java.sql.Date in, int daysToAdd) {
3315 if (in == null) {
3316 return null;
3317 }
3318 GregorianCalendar cal = new GregorianCalendar();
3319 cal.setTime(in);
3320 cal.add(Calendar.DAY_OF_MONTH, daysToAdd);
3321 return new java.sql.Date(cal.getTime().getTime());
3322 }
3323
3324
3325 private boolean isRecallRequestExist(String requestTypeId, String itemBarcode) {
3326 HashMap<String, String> map = new HashMap<String, String>();
3327 map.put("itemId", itemBarcode);
3328 map.put("requestTypeId", requestTypeId);
3329 List<OleDeliverRequestBo> matchBos = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, map);
3330 if (matchBos != null && matchBos.size() > 0) {
3331 return true;
3332 }else{
3333 return false;
3334 }
3335 }
3336
3337
3338
3339
3340
3341
3342 public OleDeliverRequestBo processRequestToExecuteDrools(OleDeliverRequestBo oleDeliverRequestBo){
3343 List<OleDeliverRequestBo> recallList = new ArrayList<OleDeliverRequestBo>();
3344 List<OleDeliverRequestBo> holdList = new ArrayList<OleDeliverRequestBo>();
3345 List<OleDeliverRequestBo> pageList = new ArrayList<OleDeliverRequestBo>();
3346 List<OleDeliverRequestBo> asrList = new ArrayList<OleDeliverRequestBo>();
3347 List<OleDeliverRequestBo> requestsByBorrower = new ArrayList<OleDeliverRequestBo>();
3348 List<FeeType> feeTypeList = getOleCirculationPolicyService().getPatronBillPayment(oleDeliverRequestBo.getBorrowerId());
3349 Integer overdueFineAmt = 0;
3350 Integer replacementFeeAmt = 0;
3351 Integer serviceFeeAmt = 0;
3352 for (FeeType feeType : feeTypeList) {
3353 Integer fineAmount = feeType.getFeeAmount().subtract(feeType.getPaidAmount()).intValue();
3354 overdueFineAmt += feeType.getOleFeeType().getFeeTypeName().equalsIgnoreCase(OLEConstants.OVERDUE_FINE) ? fineAmount : 0;
3355 replacementFeeAmt += feeType.getOleFeeType().getFeeTypeName().equalsIgnoreCase(OLEConstants.REPLACEMENT_FEE) ? fineAmount : 0;
3356 serviceFeeAmt += feeType.getOleFeeType().getFeeTypeName().equalsIgnoreCase(OLEConstants.SERVICE_FEE) ? fineAmount : 0;
3357 }
3358 Map<String, String> requestMap = new HashMap<String, String>();
3359 requestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
3360 if (oleDeliverRequestBo.getRequestTypeId()!= null && (oleDeliverRequestBo.getRequestTypeId().equals("1") || oleDeliverRequestBo.getRequestTypeId().equals("2"))) {
3361 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "1");
3362 recallList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
3363 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "2");
3364 recallList.addAll((List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap));
3365 } else if (oleDeliverRequestBo.getRequestTypeId() != null && (oleDeliverRequestBo.getRequestTypeId().equals("3") || oleDeliverRequestBo.getRequestTypeId().equals("4"))) {
3366
3367 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "3");
3368 holdList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
3369 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "4");
3370 holdList.addAll((List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap));
3371 } else if (oleDeliverRequestBo.getRequestTypeId() != null && (oleDeliverRequestBo.getRequestTypeId().equals("5") || oleDeliverRequestBo.getRequestTypeId().equals("6"))) {
3372
3373 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "5");
3374 pageList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
3375 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "6");
3376 pageList.addAll((List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap));
3377 } else if (oleDeliverRequestBo.getRequestTypeId() != null && (oleDeliverRequestBo.getRequestTypeId().equals("9"))) {
3378 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "9");
3379 asrList.addAll((List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap));
3380 }
3381 HashMap<String, Object> termValues = new HashMap<String, Object>();
3382 oleDeliverRequestBo.setRecallRequestCount(new Integer(recallList.size()));
3383 oleDeliverRequestBo.setHoldRequestCount(new Integer(holdList.size()));
3384 oleDeliverRequestBo.setPageRequestCount(new Integer(pageList.size()));
3385 oleDeliverRequestBo.setAsrRequestCount(new Integer(asrList.size()));
3386 oleDeliverRequestBo.setFineAmount( overdueFineAmt + replacementFeeAmt + serviceFeeAmt);
3387 termValues.put(OLEConstants.MAX_NO_OF_HOLD_REQUEST, new Integer(holdList.size()) + 1);
3388 termValues.put(OLEConstants.MAX_NO_OF_PAGE_REQUEST, new Integer(pageList.size()) + 1);
3389 termValues.put(OLEConstants.MAX_NO_OF_ASR_REQUEST, new Integer(asrList.size()) + 1);
3390 termValues.put(OLEConstants.FINE_AMOUNT, overdueFineAmt + replacementFeeAmt + serviceFeeAmt);
3391
3392 return oleDeliverRequestBo;
3393
3394 }
3395
3396
3397
3398
3399 public EngineResults executeEngineResults(OleDeliverRequestBo oleDeliverRequestBo,boolean backGroundLoan) {
3400 List<OleDeliverRequestBo> recallList = new ArrayList<OleDeliverRequestBo>();
3401 List<OleDeliverRequestBo> holdList = new ArrayList<OleDeliverRequestBo>();
3402 List<OleDeliverRequestBo> pageList = new ArrayList<OleDeliverRequestBo>();
3403 List<OleDeliverRequestBo> asrList = new ArrayList<OleDeliverRequestBo>();
3404 List<OleDeliverRequestBo> requestsByBorrower = new ArrayList<OleDeliverRequestBo>();
3405 Engine engine = KrmsApiServiceLocator.getEngine();
3406 ContextDefinition contextDefinition = KrmsRepositoryServiceLocator.getContextBoService().getContextByNameAndNamespace("OLE-CONTEXT", "OLE");
3407 AgendaDefinition agendaDefinition = KrmsRepositoryServiceLocator.getAgendaBoService().getAgendaByNameAndContextId(OLEConstants.REQUEST_AGENDA_NM, contextDefinition.getId());
3408 HashMap<String, String> map = new HashMap<String, String>();
3409 map.put(OLEConstants.AGENDA_NAME, agendaDefinition.getName());
3410 List<MatchBo> matchBos = (List<MatchBo>) getBusinessObjectService().findMatching(MatchBo.class, map);
3411
3412 SelectionCriteria selectionCriteria =
3413 SelectionCriteria.createCriteria(null, getSelectionContext(contextDefinition.getName()), getAgendaContext(OLEConstants.REQUEST_AGENDA_NM));
3414 EngineResults engineResult = null;
3415
3416 if (agendaDefinition != null) {
3417
3418 ExecutionOptions executionOptions = new ExecutionOptions();
3419 executionOptions.setFlag(ExecutionFlag.LOG_EXECUTION, true);
3420
3421 Facts.Builder factBuilder = Facts.Builder.create();
3422
3423 String borrowerType = "";
3424 if (oleDeliverRequestBo.getOlePatron() != null && oleDeliverRequestBo.getOlePatron().getOleBorrowerType() != null) {
3425 borrowerType = oleDeliverRequestBo.getOlePatron().getOleBorrowerType().getBorrowerTypeCode();
3426 }
3427 String itemType = oleDeliverRequestBo.getItemType();
3428
3429 String requestTypeId = oleDeliverRequestBo.getRequestTypeId();
3430
3431 String requestType = oleDeliverRequestBo.getRequestTypeCode();
3432
3433 String location = oleDeliverRequestBo.getShelvingLocation();
3434 OleLoanDocument oleLoanDocument = getLoanProcessor().getOleLoanDocumentUsingItemUUID(oleDeliverRequestBo.getItemUuid());
3435 DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
3436 dataCarrierService.addData(OLEConstants.LOANED_DATE, oleLoanDocument != null ? oleLoanDocument.getCreateDate() : null);
3437 dataCarrierService.addData(OLEConstants.DUE_DATE, oleLoanDocument != null ? oleLoanDocument.getLoanDueDate() : null);
3438 String patronId = oleDeliverRequestBo.getBorrowerId() != null ? oleDeliverRequestBo.getBorrowerId() : "";
3439 String itemId = oleDeliverRequestBo.getItemId() != null ? oleDeliverRequestBo.getItemId() : "";
3440 dataCarrierService.removeData(patronId + itemId);
3441 String borrowerId = oleDeliverRequestBo.getBorrowerId();
3442
3443 List<FeeType> feeTypeList = getOleCirculationPolicyService().getPatronBillPayment(oleDeliverRequestBo.getBorrowerId());
3444 Integer overdueFineAmt = 0;
3445 Integer replacementFeeAmt = 0;
3446 Integer serviceFeeAmt = 0;
3447 for (FeeType feeType : feeTypeList) {
3448 Integer fineAmount = feeType.getFeeAmount().subtract(feeType.getPaidAmount()).intValue();
3449 overdueFineAmt += feeType.getOleFeeType().getFeeTypeName().equalsIgnoreCase(OLEConstants.OVERDUE_FINE) ? fineAmount : 0;
3450 replacementFeeAmt += feeType.getOleFeeType().getFeeTypeName().equalsIgnoreCase(OLEConstants.REPLACEMENT_FEE) ? fineAmount : 0;
3451 serviceFeeAmt += feeType.getOleFeeType().getFeeTypeName().equalsIgnoreCase(OLEConstants.SERVICE_FEE) ? fineAmount : 0;
3452 }
3453 Map<String, String> requestMap = new HashMap<String, String>();
3454 requestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
3455 if (requestTypeId != null && (requestTypeId.equals("1") || requestTypeId.equals("2"))) {
3456 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "1");
3457 recallList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
3458 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "2");
3459 recallList.addAll((List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap));
3460 } else if (requestTypeId != null && (requestTypeId.equals("3") || requestTypeId.equals("4"))) {
3461
3462 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "3");
3463 holdList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
3464 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "4");
3465 holdList.addAll((List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap));
3466 } else if (requestTypeId != null && (requestTypeId.equals("5") || requestTypeId.equals("6"))) {
3467
3468 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "5");
3469 pageList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
3470 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "6");
3471 pageList.addAll((List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap));
3472 } else if (requestTypeId != null && (requestTypeId.equals("9"))) {
3473 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "9");
3474 asrList.addAll((List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap));
3475 }
3476 Map<String, String> requestByBorrower = new HashMap<String, String>();
3477 requestByBorrower.put(OLEConstants.OleDeliverRequest.BORROWER_ID, borrowerId);
3478 requestsByBorrower = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestByBorrower);
3479 HashMap<String, Object> termValues = new HashMap<String, Object>();
3480 termValues.put(OLEConstants.BORROWER_TYPE, borrowerType);
3481 termValues.put(OLEConstants.ITEM_TYPE, itemType);
3482 termValues.put(OLEConstants.LOCATION, location);
3483 termValues.put(OLEConstants.ITEM_SHELVING, oleDeliverRequestBo.getShelvingLocation());
3484 termValues.put(OLEConstants.ITEM_COLLECTION, oleDeliverRequestBo.getItemCollection());
3485 termValues.put(OLEConstants.ITEM_LIBRARY, oleDeliverRequestBo.getItemLibrary());
3486 termValues.put(OLEConstants.ITEM_CAMPUS, oleDeliverRequestBo.getItemCampus());
3487 termValues.put(OLEConstants.ITEM_INSTITUTION, oleDeliverRequestBo.getItemInstitution());
3488 termValues.put(OLEConstants.MAX_NO_OF_RECALL_REQUEST, new Integer(recallList.size()) + 1);
3489 termValues.put(OLEConstants.MAX_NO_OF_HOLD_REQUEST, new Integer(holdList.size()) + 1);
3490 termValues.put(OLEConstants.MAX_NO_OF_PAGE_REQUEST, new Integer(pageList.size()) + 1);
3491 termValues.put(OLEConstants.MAX_NO_OF_ASR_REQUEST, new Integer(asrList.size()) + 1);
3492 termValues.put(OLEConstants.FINE_AMOUNT, overdueFineAmt + replacementFeeAmt + serviceFeeAmt);
3493
3494
3495 termValues.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, requestTypeId);
3496 termValues.put(OLEConstants.REQUEST_TYPE, requestType);
3497 termValues.put(OLEConstants.PATRON_ID_POLICY, patronId);
3498 termValues.put(OLEConstants.ITEM_ID_POLICY, itemId);
3499
3500 for (Iterator<MatchBo> matchBoIterator = matchBos.iterator(); matchBoIterator.hasNext(); ) {
3501 MatchBo matchBo = matchBoIterator.next();
3502 factBuilder.addFact(matchBo.getTermName(), termValues.get((matchBo.getTermName())));
3503 }
3504 if (LOG.isDebugEnabled()) {
3505 LOG.debug("termValues.toString()" + termValues.toString());
3506 }
3507 engineResult = engine.execute(selectionCriteria, factBuilder.build(), executionOptions);
3508 dataCarrierService.removeData(patronId + itemId);
3509 List<String> errorMessage = (List<String>) engineResult.getAttribute(OLEConstants.ERROR_ACTION);
3510 java.sql.Date d = (java.sql.Date) engineResult.getAttribute(OLEConstants.REQ_EXPIRATION_DATE);
3511 Timestamp recallDueDate = (Timestamp) engineResult.getAttribute(OLEConstants.RECALL_DUE_DATE);
3512 String notice = (String) engineResult.getAttribute(OLEConstants.NOTICE);
3513 oleDeliverRequestBo.setNoticeType(notice);
3514 if (oleDeliverRequestBo.getRequestExpiryDate() == null) {
3515 oleDeliverRequestBo.setRequestExpiryDate(d);
3516 }
3517 StringBuffer failures = new StringBuffer();
3518 if (errorMessage != null && errorMessage.size() > 0) {
3519 int i = 1;
3520 for (String errMsg : errorMessage) {
3521 failures.append(i++ + ". " + errMsg + OLEConstants.BREAK);
3522 }
3523 }
3524 if (!failures.toString().isEmpty() && !backGroundLoan) {
3525 oleDeliverRequestBo.setMessage(failures.toString());
3526 } else if (failures.toString().trim().isEmpty() || backGroundLoan) {
3527 boolean overrideKRMS = true;
3528
3529 if (oleDeliverRequestBo.getRequestTypeId().equals("1") ) {
3530 overrideKRMS = isRecallRequestExist(oleDeliverRequestBo.getRequestTypeId(), oleDeliverRequestBo.getItemId());
3531 }else{
3532 overrideKRMS = false;
3533 }
3534 if(!overrideKRMS && oleDeliverRequestBo.getRequestTypeId().equals("2")){
3535 overrideKRMS = isRecallRequestExist(oleDeliverRequestBo.getRequestTypeId(), oleDeliverRequestBo.getItemId());
3536 }
3537 if (!overrideKRMS || backGroundLoan) {
3538 if (oleLoanDocument != null && (oleDeliverRequestBo.getRequestTypeId().equals("1") || oleDeliverRequestBo.getRequestTypeId().equals("2"))) {
3539 Timestamp itemDueDate = null;
3540 if (ObjectUtils.isNotNull(oleLoanDocument)) {
3541 itemDueDate = oleLoanDocument.getLoanDueDate();
3542 }
3543 Item oleItem = oleDeliverRequestBo.getOleItem();
3544 if (itemDueDate == null && recallDueDate != null) {
3545 oleDeliverRequestBo.setNewDueDate(new java.sql.Date(recallDueDate.getTime()));
3546 oleLoanDocument.setLoanDueDate(recallDueDate);
3547 oleDeliverRequestBo.setRecallDueDate(recallDueDate);
3548 oleItem.setDueDateTime(recallDueDate.toString());
3549 getBusinessObjectService().save(oleLoanDocument);
3550 OleCirculationDesk oleCirculationDesk = oleLoanDocument.getCirculationLocationId() != null ?
3551 getCircDeskLocationResolver().getOleCirculationDesk(oleLoanDocument.getCirculationLocationId()) : null;
3552 oleLoanDocument.setOleCirculationDesk(oleCirculationDesk);
3553 OLEDeliverNoticeHelperService oleDeliverNoticeHelperService = getOleDeliverNoticeHelperService();
3554 oleDeliverNoticeHelperService.deleteDeliverNotices(oleLoanDocument.getLoanId());
3555 try {
3556 List<OLEDeliverNotice> deliverNotices = (List<OLEDeliverNotice>) engineResult.getAttribute("deliverNotices");
3557 if (deliverNotices != null) {
3558 for (OLEDeliverNotice deliverNotice : deliverNotices) {
3559 deliverNotice.setLoanId(oleLoanDocument.getLoanId());
3560 deliverNotice.setPatronId(oleLoanDocument.getPatronId());
3561 }
3562 getBusinessObjectService().save(deliverNotices);
3563 }
3564 } catch (Exception e) {
3565 LOG.info("Exception occured while updating the date in notice table");
3566 LOG.error(e, e);
3567 }
3568 oleItem.setDueDateTime(getLoanProcessor().convertDateToString(recallDueDate, "MM/dd/yyyy HH:mm:ss"));
3569 try {
3570 updateItem(oleItem);
3571 } catch (Exception e) {
3572 if (LOG.isInfoEnabled()) {
3573 LOG.info("Exception occured while updating the item . " + e.getMessage());
3574 }
3575 LOG.error(e, e);
3576 }
3577 }
3578 if (recallDueDate != null && itemDueDate != null) {
3579
3580 oleDeliverRequestBo.setOriginalDueDate((new java.sql.Date(itemDueDate.getTime())));
3581 oleDeliverRequestBo.setNewDueDate(new java.sql.Date(recallDueDate.getTime()));
3582 oleLoanDocument.setLoanDueDate(recallDueDate);
3583 oleDeliverRequestBo.setRecallDueDate(recallDueDate);
3584 getBusinessObjectService().save(oleLoanDocument);
3585 OleCirculationDesk oleCirculationDesk = oleLoanDocument.getCirculationLocationId() != null ?
3586 getCircDeskLocationResolver().getOleCirculationDesk(oleLoanDocument.getCirculationLocationId()) : null;
3587 oleLoanDocument.setOleCirculationDesk(oleCirculationDesk);
3588 OLEDeliverNoticeHelperService oleDeliverNoticeHelperService = getOleDeliverNoticeHelperService();
3589 oleDeliverNoticeHelperService.deleteDeliverNotices(oleLoanDocument.getLoanId());
3590 try {
3591 List<OLEDeliverNotice> deliverNotices = (List<OLEDeliverNotice>) engineResult.getAttribute("deliverNotices");
3592 if (deliverNotices != null) {
3593 for (OLEDeliverNotice deliverNotice : deliverNotices) {
3594 deliverNotice.setLoanId(oleLoanDocument.getLoanId());
3595 deliverNotice.setPatronId(oleLoanDocument.getPatronId());
3596 }
3597 getBusinessObjectService().save(deliverNotices);
3598 }
3599 } catch (Exception e) {
3600 LOG.info("Exception occured while updating the date in notice table");
3601 LOG.error(e, e);
3602 }
3603 oleItem.setDueDateTime(getLoanProcessor().convertDateToString(recallDueDate, "MM/dd/yyyy HH:mm:ss"));
3604 try {
3605 updateItem(oleItem);
3606 } catch (Exception e) {
3607 if (LOG.isInfoEnabled()) {
3608 LOG.info("Exception occured while updating the item . " + e.getMessage());
3609 }
3610 LOG.error(e, e);
3611 }
3612
3613
3614
3615
3616 }
3617 }
3618 }
3619 }
3620 dataCarrierService.addData(OLEConstants.ERROR_ACTION, null);
3621 }
3622 return engineResult;
3623 }
3624
3625
3626 public EngineResults executeEngineResultsForOverride(OleDeliverRequestBo oleDeliverRequestBo) {
3627 List<OleDeliverRequestBo> recallList = new ArrayList<OleDeliverRequestBo>();
3628 List<OleDeliverRequestBo> holdList = new ArrayList<OleDeliverRequestBo>();
3629 List<OleDeliverRequestBo> pageList = new ArrayList<OleDeliverRequestBo>();
3630 List<OleDeliverRequestBo> asrList = new ArrayList<OleDeliverRequestBo>();
3631 List<OleDeliverRequestBo> requestsByBorrower = new ArrayList<OleDeliverRequestBo>();
3632 Engine engine = KrmsApiServiceLocator.getEngine();
3633 ContextDefinition contextDefinition = KrmsRepositoryServiceLocator.getContextBoService().getContextByNameAndNamespace("OLE-CONTEXT", "OLE");
3634 AgendaDefinition agendaDefinition = KrmsRepositoryServiceLocator.getAgendaBoService().getAgendaByNameAndContextId(OLEConstants.REQUEST_AGENDA_NM, contextDefinition.getId());
3635 HashMap<String, String> map = new HashMap<String, String>();
3636 map.put(OLEConstants.AGENDA_NAME, agendaDefinition.getName());
3637 List<MatchBo> matchBos = (List<MatchBo>) getBusinessObjectService().findMatching(MatchBo.class, map);
3638
3639 SelectionCriteria selectionCriteria =
3640 SelectionCriteria.createCriteria(null, getSelectionContext(contextDefinition.getName()), getAgendaContext(OLEConstants.REQUEST_AGENDA_NM));
3641 EngineResults engineResult = null;
3642
3643 if (agendaDefinition != null) {
3644
3645 ExecutionOptions executionOptions = new ExecutionOptions();
3646 executionOptions.setFlag(ExecutionFlag.LOG_EXECUTION, true);
3647
3648 Facts.Builder factBuilder = Facts.Builder.create();
3649
3650 String borrowerType = "";
3651 if (oleDeliverRequestBo.getOlePatron() != null && oleDeliverRequestBo.getOlePatron().getOleBorrowerType() != null) {
3652 borrowerType = oleDeliverRequestBo.getOlePatron().getOleBorrowerType().getBorrowerTypeCode();
3653 }
3654 String itemType = oleDeliverRequestBo.getItemType();
3655
3656 String requestTypeId = oleDeliverRequestBo.getRequestTypeId();
3657
3658 String requestType = oleDeliverRequestBo.getRequestTypeCode();
3659
3660 String location = oleDeliverRequestBo.getShelvingLocation();
3661 OleLoanDocument oleLoanDocument = getLoanProcessor().getOleLoanDocumentUsingItemUUID(oleDeliverRequestBo.getItemUuid());
3662 DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
3663 dataCarrierService.addData(OLEConstants.LOANED_DATE, oleLoanDocument != null ? oleLoanDocument.getCreateDate() : null);
3664 dataCarrierService.addData(OLEConstants.DUE_DATE, oleLoanDocument != null ? oleLoanDocument.getLoanDueDate() : null);
3665 String patronId = oleDeliverRequestBo.getBorrowerId() != null ? oleDeliverRequestBo.getBorrowerId() : "";
3666 String itemId = oleDeliverRequestBo.getItemId() != null ? oleDeliverRequestBo.getItemId() : "";
3667 dataCarrierService.removeData(patronId + itemId);
3668 String borrowerId = oleDeliverRequestBo.getBorrowerId();
3669
3670 List<FeeType> feeTypeList = getOleCirculationPolicyService().getPatronBillPayment(oleDeliverRequestBo.getBorrowerId());
3671 Integer overdueFineAmt = 0;
3672 Integer replacementFeeAmt = 0;
3673 Integer serviceFeeAmt = 0;
3674 for (FeeType feeType : feeTypeList) {
3675 Integer fineAmount = feeType.getFeeAmount().subtract(feeType.getPaidAmount()).intValue();
3676 overdueFineAmt += feeType.getOleFeeType().getFeeTypeName().equalsIgnoreCase(OLEConstants.OVERDUE_FINE) ? fineAmount : 0;
3677 replacementFeeAmt += feeType.getOleFeeType().getFeeTypeName().equalsIgnoreCase(OLEConstants.REPLACEMENT_FEE) ? fineAmount : 0;
3678 serviceFeeAmt += feeType.getOleFeeType().getFeeTypeName().equalsIgnoreCase(OLEConstants.SERVICE_FEE) ? fineAmount : 0;
3679 }
3680 Map<String, String> requestMap = new HashMap<String, String>();
3681 requestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
3682 if (requestTypeId != null && (requestTypeId.equals("1") || requestTypeId.equals("2"))) {
3683 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "1");
3684 recallList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
3685 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "2");
3686 recallList.addAll((List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap));
3687 } else if (requestTypeId != null && (requestTypeId.equals("3") || requestTypeId.equals("4"))) {
3688
3689 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "3");
3690 holdList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
3691 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "4");
3692 holdList.addAll((List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap));
3693 } else if (requestTypeId != null && (requestTypeId.equals("5") || requestTypeId.equals("6"))) {
3694
3695 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "5");
3696 pageList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
3697 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "6");
3698 pageList.addAll((List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap));
3699 } else if (requestTypeId != null && (requestTypeId.equals("9"))) {
3700 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "9");
3701 asrList.addAll((List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap));
3702 }
3703 Map<String, String> requestByBorrower = new HashMap<String, String>();
3704 requestByBorrower.put(OLEConstants.OleDeliverRequest.BORROWER_ID, borrowerId);
3705 requestsByBorrower = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestByBorrower);
3706 HashMap<String, Object> termValues = new HashMap<String, Object>();
3707 termValues.put(OLEConstants.BORROWER_TYPE, borrowerType);
3708 termValues.put(OLEConstants.ITEM_TYPE, itemType);
3709 termValues.put(OLEConstants.LOCATION, location);
3710 termValues.put(OLEConstants.ITEM_SHELVING, oleDeliverRequestBo.getShelvingLocation());
3711 termValues.put(OLEConstants.ITEM_COLLECTION, oleDeliverRequestBo.getItemCollection());
3712 termValues.put(OLEConstants.ITEM_LIBRARY, oleDeliverRequestBo.getItemLibrary());
3713 termValues.put(OLEConstants.ITEM_CAMPUS, oleDeliverRequestBo.getItemCampus());
3714 termValues.put(OLEConstants.ITEM_INSTITUTION, oleDeliverRequestBo.getItemInstitution());
3715 termValues.put(OLEConstants.MAX_NO_OF_RECALL_REQUEST, new Integer(recallList.size()) + 1);
3716 termValues.put(OLEConstants.MAX_NO_OF_HOLD_REQUEST, new Integer(holdList.size()) + 1);
3717 termValues.put(OLEConstants.MAX_NO_OF_PAGE_REQUEST, new Integer(pageList.size()) + 1);
3718 termValues.put(OLEConstants.MAX_NO_OF_ASR_REQUEST, new Integer(asrList.size()) + 1);
3719 termValues.put(OLEConstants.FINE_AMOUNT, overdueFineAmt + replacementFeeAmt + serviceFeeAmt);
3720
3721
3722 termValues.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, requestTypeId);
3723 termValues.put(OLEConstants.REQUEST_TYPE, requestType);
3724 termValues.put(OLEConstants.PATRON_ID_POLICY, patronId);
3725 termValues.put(OLEConstants.ITEM_ID_POLICY, itemId);
3726
3727 for (Iterator<MatchBo> matchBoIterator = matchBos.iterator(); matchBoIterator.hasNext(); ) {
3728 MatchBo matchBo = matchBoIterator.next();
3729 factBuilder.addFact(matchBo.getTermName(), termValues.get((matchBo.getTermName())));
3730 }
3731 if (LOG.isDebugEnabled()) {
3732 LOG.debug("termValues.toString()" + termValues.toString());
3733 }
3734 engineResult = engine.execute(selectionCriteria, factBuilder.build(), executionOptions);
3735 dataCarrierService.removeData(patronId + itemId);
3736 List<String> errorMessage = (List<String>) engineResult.getAttribute(OLEConstants.ERROR_ACTION);
3737 java.sql.Date d = (java.sql.Date) engineResult.getAttribute(OLEConstants.REQ_EXPIRATION_DATE);
3738 Timestamp recallDueDate = (Timestamp) engineResult.getAttribute(OLEConstants.RECALL_DUE_DATE);
3739 String notice = (String) engineResult.getAttribute(OLEConstants.NOTICE);
3740 oleDeliverRequestBo.setNoticeType(notice);
3741 if (oleDeliverRequestBo.getRequestExpiryDate() == null) {
3742 oleDeliverRequestBo.setRequestExpiryDate(d);
3743 }
3744 StringBuffer failures = new StringBuffer();
3745
3746
3747 boolean overrideKRMS = true;
3748 if (oleDeliverRequestBo.getRequestTypeId().equals("1") ) {
3749 overrideKRMS = isRecallRequestExist(oleDeliverRequestBo.getRequestTypeId(), oleDeliverRequestBo.getItemId());
3750 }else{
3751 overrideKRMS = false;
3752 }
3753 if(!overrideKRMS && oleDeliverRequestBo.getRequestTypeId().equals("2")){
3754 overrideKRMS = isRecallRequestExist(oleDeliverRequestBo.getRequestTypeId(), oleDeliverRequestBo.getItemId());
3755 }
3756 if (!overrideKRMS) {
3757 if (oleLoanDocument != null && (oleDeliverRequestBo.getRequestTypeId().equals("1") || oleDeliverRequestBo.getRequestTypeId().equals("2"))) {
3758 Timestamp itemDueDate = null;
3759 if (ObjectUtils.isNotNull(oleLoanDocument)) {
3760 itemDueDate = oleLoanDocument.getLoanDueDate();
3761 }
3762 Item oleItem = oleDeliverRequestBo.getOleItem();
3763 if (itemDueDate == null && recallDueDate != null) {
3764 oleDeliverRequestBo.setNewDueDate(new java.sql.Date(recallDueDate.getTime()));
3765 oleLoanDocument.setLoanDueDate(recallDueDate);
3766 oleDeliverRequestBo.setRecallDueDate(recallDueDate);
3767 oleItem.setDueDateTime(recallDueDate.toString());
3768 getBusinessObjectService().save(oleLoanDocument);
3769 OleCirculationDesk oleCirculationDesk = oleLoanDocument.getCirculationLocationId() != null ?
3770 getCircDeskLocationResolver().getOleCirculationDesk(oleLoanDocument.getCirculationLocationId()) : null;
3771 oleLoanDocument.setOleCirculationDesk(oleCirculationDesk);
3772 OLEDeliverNoticeHelperService oleDeliverNoticeHelperService = getOleDeliverNoticeHelperService();
3773 oleDeliverNoticeHelperService.deleteDeliverNotices(oleLoanDocument.getLoanId());
3774 try {
3775 List<OLEDeliverNotice> deliverNotices = (List<OLEDeliverNotice>) engineResult.getAttribute("deliverNotices");
3776 if (deliverNotices != null) {
3777 for (OLEDeliverNotice deliverNotice : deliverNotices) {
3778 deliverNotice.setLoanId(oleLoanDocument.getLoanId());
3779 deliverNotice.setPatronId(oleLoanDocument.getPatronId());
3780 }
3781 getBusinessObjectService().save(deliverNotices);
3782 }
3783 } catch (Exception e) {
3784 LOG.info("Exception occured while updating the date in notice table");
3785 LOG.error(e, e);
3786 }
3787 oleItem.setDueDateTime(getLoanProcessor().convertDateToString(recallDueDate, "MM/dd/yyyy HH:mm:ss"));
3788 try {
3789 updateItem(oleItem);
3790 } catch (Exception e) {
3791 if (LOG.isInfoEnabled()) {
3792 LOG.info("Exception occured while updating the item . " + e.getMessage());
3793 }
3794 LOG.error(e, e);
3795 }
3796 }
3797 if (recallDueDate != null && itemDueDate != null) {
3798
3799 oleDeliverRequestBo.setOriginalDueDate((new java.sql.Date(itemDueDate.getTime())));
3800 oleDeliverRequestBo.setNewDueDate(new java.sql.Date(recallDueDate.getTime()));
3801 oleLoanDocument.setLoanDueDate(recallDueDate);
3802 oleDeliverRequestBo.setRecallDueDate(recallDueDate);
3803 getBusinessObjectService().save(oleLoanDocument);
3804 OleCirculationDesk oleCirculationDesk = oleLoanDocument.getCirculationLocationId() != null ?
3805 getCircDeskLocationResolver().getOleCirculationDesk(oleLoanDocument.getCirculationLocationId()) : null;
3806 oleLoanDocument.setOleCirculationDesk(oleCirculationDesk);
3807 OLEDeliverNoticeHelperService oleDeliverNoticeHelperService = getOleDeliverNoticeHelperService();
3808 oleDeliverNoticeHelperService.deleteDeliverNotices(oleLoanDocument.getLoanId());
3809 try {
3810 List<OLEDeliverNotice> deliverNotices = (List<OLEDeliverNotice>) engineResult.getAttribute("deliverNotices");
3811 if (deliverNotices != null) {
3812 for (OLEDeliverNotice deliverNotice : deliverNotices) {
3813 deliverNotice.setLoanId(oleLoanDocument.getLoanId());
3814 deliverNotice.setPatronId(oleLoanDocument.getPatronId());
3815 }
3816 getBusinessObjectService().save(deliverNotices);
3817 }
3818 } catch (Exception e) {
3819 LOG.info("Exception occured while updating the date in notice table");
3820 LOG.error(e, e);
3821 }
3822 oleItem.setDueDateTime(getLoanProcessor().convertDateToString(recallDueDate, "MM/dd/yyyy HH:mm:ss"));
3823 try {
3824 updateItem(oleItem);
3825 } catch (Exception e) {
3826 if (LOG.isInfoEnabled()) {
3827 LOG.info("Exception occured while updating the item . " + e.getMessage());
3828 }
3829 LOG.error(e, e);
3830 }
3831
3832 }
3833 }
3834 }
3835
3836 dataCarrierService.addData(OLEConstants.ERROR_ACTION, null);
3837 }
3838 return engineResult;
3839 }
3840
3841
3842
3843
3844
3845
3846
3847 protected Map<String, String> getSelectionContext(String contextName) {
3848 Map<String, String> selector = new HashMap<String, String>();
3849 selector.put(NAMESPACE_CODE_SELECTOR, OLEConstants.OLE_NAMESPACE);
3850 selector.put(NAME_SELECTOR, contextName);
3851 return selector;
3852 }
3853
3854
3855
3856
3857
3858
3859
3860 protected Map<String, String> getAgendaContext(String agendaName) {
3861 Map<String, String> selector = new HashMap<String, String>();
3862 selector.put(NAME_SELECTOR, agendaName);
3863 return selector;
3864 }
3865
3866 public OleCirculationDesk getOleCirculationDesk(String circulationDeskId) {
3867 Map<String, String> circulationDeskMap = new HashMap<String, String>();
3868 circulationDeskMap.put(OLEConstants.CIRCULATION_DESK_ID, circulationDeskId);
3869 List<OleCirculationDesk> oleCirculationDeskList = (List<OleCirculationDesk>) getBusinessObjectService().findMatching(OleCirculationDesk.class, circulationDeskMap);
3870 if (oleCirculationDeskList != null && oleCirculationDeskList.size() > 0) {
3871 return oleCirculationDeskList.get(0);
3872 } else
3873 return null;
3874 }
3875
3876 private RoleService getRoleService() {
3877 RoleService service = KimApiServiceLocator.getRoleService();
3878 return service;
3879 }
3880
3881 public boolean checkForOverdueNotice(Date expDate) {
3882 Date curDat = new Date();
3883 if (expDate != null && curDat.compareTo(expDate) <= 0) {
3884 return false;
3885 }
3886 return true;
3887 }
3888
3889
3890
3891
3892
3893 public org.kuali.ole.docstore.common.document.Item retrieveItemWithBibAndHoldingData(String itemUUID) {
3894 org.kuali.ole.docstore.common.document.Item item = null;
3895 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
3896 HoldingOlemlRecordProcessor holdingsOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
3897 try {
3898
3899 item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(itemUUID);
3900
3901 Item item1 = itemOlemlRecordProcessor.fromXML(item.getContent());
3902 item = populateInfoFromInstanceItemToDocItem(item1, item);
3903 OleHoldings oleHoldings = holdingsOlemlRecordProcessor.fromXML(item.getHolding().getContent());
3904 Holdings holdings = populateInfoFromInstanceHoldingToDocHoldings(oleHoldings, item.getHolding());
3905 item.setHolding(holdings);
3906 } catch (Exception e) {
3907 LOG.error(e);
3908 }
3909 return item;
3910 }
3911
3912
3913 public org.kuali.ole.docstore.common.document.Item populateInfoFromInstanceItemToDocItem(Item instanceItem, org.kuali.ole.docstore.common.document.Item documentItem) {
3914
3915 documentItem.setBarcode(instanceItem.getAccessInformation().getBarcode());
3916 documentItem.setAnalytic(Boolean.valueOf(instanceItem.getAnalytic()));
3917 if (instanceItem.getCallNumber() != null) {
3918 documentItem.setCallNumber(instanceItem.getCallNumber().getNumber());
3919 documentItem.setCallNumberType(instanceItem.getCallNumber().getType());
3920 documentItem.setCallNumberPrefix(instanceItem.getCallNumber().getPrefix());
3921 }
3922 documentItem.setChronology(instanceItem.getChronology());
3923 documentItem.setCopyNumber(instanceItem.getCopyNumber());
3924 if (instanceItem.getItemStatus() != null) {
3925 documentItem.setItemStatus(instanceItem.getItemStatus().getCodeValue());
3926 }
3927 if (instanceItem.getItemType() != null) {
3928 documentItem.setItemType(instanceItem.getItemType().getCodeValue());
3929 }
3930 documentItem.setEnumeration(instanceItem.getEnumeration());
3931 documentItem.setVolumeNumber(instanceItem.getVolumeNumber());
3932
3933 return documentItem;
3934 }
3935
3936 public org.kuali.ole.docstore.common.document.Holdings populateInfoFromInstanceHoldingToDocHoldings(OleHoldings oleHoldings, Holdings holdings) {
3937 if (oleHoldings.getCallNumber() != null) {
3938 holdings.setCallNumber(oleHoldings.getCallNumber().getNumber());
3939 holdings.setCallNumberPrefix(oleHoldings.getCallNumber().getPrefix());
3940 holdings.setCallNumberType(oleHoldings.getCallNumber().getType());
3941 }
3942 holdings.setCopyNumber(oleHoldings.getCopyNumber());
3943 holdings.setHoldingsType(oleHoldings.getHoldingsType());
3944
3945 return holdings;
3946 }
3947
3948
3949 public Map retrieveBIbItemHoldingData(String itemUUID) {
3950 Map<String, Object> bibMap = new HashMap<String, Object>();
3951 org.kuali.ole.docstore.common.document.Item item = null;
3952 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
3953 HoldingOlemlRecordProcessor holdingsOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
3954 try {
3955 item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(itemUUID);
3956 bibMap.put(OLEConstants.DOCUMENT_ITEM, item);
3957 bibMap.put(OLEConstants.BIB, item.getHolding().getBib());
3958 Item item1 = itemOlemlRecordProcessor.fromXML(item.getContent());
3959 bibMap.put(OLEConstants.ITEM, item1);
3960 OleHoldings oleHoldings = holdingsOlemlRecordProcessor.fromXML(item.getHolding().getContent());
3961 bibMap.put(OLEConstants.HOLDING, oleHoldings);
3962 } catch (Exception e) {
3963 LOG.error(e);
3964 }
3965 return bibMap;
3966 }
3967
3968 private void getNoticeList(List<OleLoanDocument> oleLoanDocuments, OlePatronDocument olePatronDocument, boolean overdue, List<String> itemUUIDS) {
3969 Long b1 = System.currentTimeMillis();
3970 List<OleLoanDocument> oleOverDueNoticeBoList = new ArrayList<>();
3971 List<OleLoanDocument> oleCourtesyNoticeList = new ArrayList<>();
3972 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
3973 StringBuffer mailContent = new StringBuffer();
3974 Document document = null;
3975 OutputStream outputStream = null;
3976 Set<String> overdueItemLocations = new HashSet<>();
3977 Set<String> courtesyItemLocations = new HashSet<>();
3978 try {
3979 String overdueNoticeType = getLoanProcessor().getParameter(OLEParameterConstants.OVERDUE_NOTICE_TYPE);
3980 String courtesyNoticeType = getLoanProcessor().getParameter(OLEParameterConstants.COURTESY_NOTICE_TYPE);
3981 mailContent.append(oleDeliverBatchService.getHeaderAndPatronContent(olePatronDocument, overdue));
3982 oleDeliverBatchService.getHeaderAndPatronPDFContent(olePatronDocument, overdue);
3983 document = oleDeliverBatchService.getOverdueDocument();
3984 outputStream = oleDeliverBatchService.getOverdueOutPutStream();
3985 for (OleLoanDocument oleLoanDocument : oleLoanDocuments) {
3986 boolean overdueExists = false;
3987 oleLoanDocument.setOlePatron(olePatronDocument);
3988 if (LOG.isInfoEnabled()) {
3989 LOG.info("oleLoanDocument---->ItemID--" + oleLoanDocument.getItemId() + ": Patron Barcode--" + oleLoanDocument.getPatronBarcode());
3990 LOG.info("oleItem.getItemStatusEffectiveDate()" + oleLoanDocument.getItemStatusEffectiveDate());
3991 }
3992 if (oleLoanDocument.getItemTypeName() != null) {
3993 oleLoanDocument.setItemType(getItemTypeCodeByName(oleLoanDocument.getItemTypeName()));
3994 }
3995 for (OLEDeliverNotice oleDeliverNotice : oleLoanDocument.getDeliverNotices()) {
3996 String noticeType = oleDeliverNotice.getNoticeType();
3997 if (oleLoanDocument.getReplacementBill() != null && oleLoanDocument.getReplacementBill().intValue() > 0 && noticeType.equalsIgnoreCase(OLEConstants.NOTICE_LOST)) {
3998 int noOfOverdueNoticeSent = Integer.parseInt(oleLoanDocument.getNumberOfOverdueNoticesSent() != null ? oleLoanDocument.getNumberOfOverdueNoticesSent() : "0");
3999 noOfOverdueNoticeSent = noOfOverdueNoticeSent + 1;
4000 oleLoanDocument.setNumberOfOverdueNoticesSent(Integer.toString(noOfOverdueNoticeSent));
4001 oleLoanDocument.setOverDueNoticeDate(new java.sql.Date(System.currentTimeMillis()));
4002 String billNumber = getLoanProcessor().generatePatronBillPayment(oleLoanDocument, OLEConstants.REPLACEMENT_FEE, oleLoanDocument.getReplacementBill());
4003 oleLoanDocument.setRepaymentFeePatronBillId(billNumber);
4004 itemUUIDS.add(oleLoanDocument.getItemUuid());
4005 getBusinessObjectService().delete(oleDeliverNotice);
4006 }
4007 if (noticeType.equalsIgnoreCase(OLEConstants.NOTICE_OVERDUE)) {
4008 oleOverDueNoticeBoList.add(oleLoanDocument);
4009 if (!overdueExists) {
4010 mailContent.append(oleDeliverBatchService.getOverdueNoticeHTMLContent(oleLoanDocument));
4011 }
4012 overdueItemLocations.add(oleLoanDocument.getItemLocation());
4013 noticeType = noticeType == null ? overdueNoticeType : noticeType;
4014 if (!overdueExists) {
4015 oleDeliverBatchService.getOverdueNoticePDFContent(oleLoanDocument, overdue, document);
4016 }
4017 int noOfOverdueNoticeSent = Integer.parseInt(oleLoanDocument.getNumberOfOverdueNoticesSent() != null ? oleLoanDocument.getNumberOfOverdueNoticesSent() : "0");
4018 noOfOverdueNoticeSent = noOfOverdueNoticeSent + 1;
4019 if (LOG.isDebugEnabled()) {
4020 LOG.debug("Updated Loan Record : " + oleLoanDocument);
4021 }
4022 oleLoanDocument.setNumberOfOverdueNoticesSent(Integer.toString(noOfOverdueNoticeSent));
4023 oleLoanDocument.setOverDueNoticeDate(new java.sql.Date(System.currentTimeMillis()));
4024 overdueExists = true;
4025 getBusinessObjectService().delete(oleDeliverNotice);
4026 } else if (noticeType.equalsIgnoreCase(OLEConstants.NOTICE_COURTESY) && olePatronDocument.isCourtesyNotice() && !oleLoanDocument.isCourtesyNoticeFlag()) {
4027 oleCourtesyNoticeList.add(oleLoanDocument);
4028 mailContent.append(oleDeliverBatchService.getOverdueNoticeHTMLContent(oleLoanDocument));
4029 courtesyItemLocations.add(oleLoanDocument.getItemLocation());
4030 oleDeliverBatchService.getOverdueNoticePDFContent(oleLoanDocument, overdue, document);
4031 noticeType = noticeType == null ? courtesyNoticeType : noticeType;
4032 oleLoanDocument.setCourtesyNoticeFlag(!overdue);
4033 getBusinessObjectService().delete(oleDeliverNotice);
4034 }
4035
4036 olePatronDocument = oleLoanDocument.getOlePatron();
4037 if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.SMS)) {
4038
4039 }
4040 }
4041 getBusinessObjectService().save(oleLoanDocument);
4042 saveOLEDeliverNoticeHistory(oleLoanDocument);
4043 }
4044
4045 } catch (Exception e) {
4046 LOG.error("Exception in generateNotices()" + e.getMessage(), e);
4047 }
4048 Long b2 = System.currentTimeMillis();
4049 Long b3 = b2 - b1;
4050 LOG.info("Time taken to send the notices " + b3);
4051 boolean isFileNeedToDelete = true;
4052 if (overdue) {
4053 if (oleOverDueNoticeBoList != null && oleOverDueNoticeBoList.size() > 0) {
4054 String replyToEmail = null;
4055 if (overdueItemLocations.size() == 1) {
4056 replyToEmail = getCircDeskLocationResolver().getReplyToEmail(overdueItemLocations.iterator().next());
4057 }
4058 if (replyToEmail != null) {
4059 sendMailsToPatron(olePatronDocument, mailContent.toString(), replyToEmail);
4060 } else {
4061 String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
4062 sendMailsToPatron(olePatronDocument, mailContent.toString(), fromAddress);
4063 }
4064 try {
4065 if (document != null && outputStream != null) {
4066 oleDeliverBatchService.getPdfFooter(document, outputStream);
4067 isFileNeedToDelete = false;
4068 }
4069 } catch (Exception e) {
4070 LOG.error("PDF overdue notice error");
4071 }
4072
4073 }
4074 } else {
4075 if (oleCourtesyNoticeList != null && oleCourtesyNoticeList.size() > 0) {
4076 String replyToEmail = null;
4077 if (courtesyItemLocations.size() == 1) {
4078 replyToEmail = getCircDeskLocationResolver().getReplyToEmail(courtesyItemLocations.iterator().next());
4079 }
4080 if (replyToEmail != null) {
4081 sendMailsToPatron(olePatronDocument, mailContent.toString(), replyToEmail);
4082 } else {
4083 String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
4084 sendMailsToPatron(olePatronDocument, mailContent.toString(), fromAddress);
4085 }
4086 try {
4087 if (document != null && outputStream != null) {
4088 oleDeliverBatchService.getPdfFooter(document, outputStream);
4089 isFileNeedToDelete = false;
4090 }
4091 } catch (Exception e) {
4092 LOG.error("PDF courtesy notice error");
4093 }
4094 }
4095 }
4096 if (isFileNeedToDelete) {
4097 oleDeliverBatchService.cleanZeroByteFiles();
4098 }
4099 }
4100
4101 public void sendMailsToPatron(OlePatronDocument olePatronDocument, String noticeContent, String fromAddress) {
4102
4103 Long b1 = System.currentTimeMillis();
4104 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
4105 String emailAddress = "";
4106 try {
4107 EntityTypeContactInfoBo entityTypeContactInfoBo = olePatronDocument.getEntity().getEntityTypeContactInfos().get(0);
4108 emailAddress = getOlePatronHelperService().getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getOlePatronHelperService().getPatronHomeEmailId(entityTypeContactInfoBo) : "";
4109 } catch (Exception e) {
4110 LOG.error("Unable to get Patron Email Address --sendMailsToPatron--" + e.getMessage(), e);
4111 }
4112 try {
4113 if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
4114 fromAddress = OLEConstants.KUALI_MAIL;
4115 }
4116
4117 if (emailAddress != null && !emailAddress.isEmpty()) {
4118 noticeContent = noticeContent.replace('[', ' ');
4119 noticeContent = noticeContent.replace(']', ' ');
4120 if (!noticeContent.trim().equals("")) {
4121 OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
4122 oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(emailAddress), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(noticeContent), true);
4123 }
4124 } else {
4125 LOG.error("Patron Email Address --sendMailsToPatron-- is Empty or Null");
4126 }
4127 } catch (Exception e) {
4128 LOG.error("Exception in generateNotices()" + e.getMessage(), e);
4129 }
4130 Long b2 = System.currentTimeMillis();
4131 Long total = b2 - b1;
4132 LOG.info("The time taken sending mail :" + total);
4133 }
4134
4135
4136
4137
4138
4139
4140
4141 public List<OleLoanDocument> getLoanDocumentWithItemInfo(List<OleLoanDocument> oleLoanDocuments) throws Exception {
4142 Long startTime = System.currentTimeMillis();
4143 List<OleLoanDocument> loanDocumentsWithItemInfo = new ArrayList<OleLoanDocument>();
4144 if (oleLoanDocuments != null && oleLoanDocuments.size() > 0) {
4145 Map<String, OleLoanDocument> loanDocumentMap = new HashMap<String, OleLoanDocument>();
4146 SearchParams searchParams = new SearchParams();
4147 List<SearchCondition> searchConditions = new ArrayList<>();
4148 SearchResponse searchResponse = new SearchResponse();
4149 String numberOfRecords = getLoanProcessor().getParameter(OLEConstants.NUMBER_OF_ITEM_INFO);
4150 List<List<OleLoanDocument>> slicedList = (List<List<OleLoanDocument>>) splitListToSubList(oleLoanDocuments, Integer.valueOf(numberOfRecords).intValue());
4151 for (List<OleLoanDocument> oleLoanDocumentList : slicedList) {
4152 try {
4153 searchConditions = new ArrayList<>();
4154 searchResponse = new SearchResponse();
4155 searchParams = new SearchParams();
4156 for (OleLoanDocument oleLoanDocument : oleLoanDocumentList) {
4157 loanDocumentMap.put(oleLoanDocument.getItemUuid(), oleLoanDocument);
4158 searchConditions.add(searchParams.buildSearchCondition("phrase", searchParams.buildSearchField("item", "id", oleLoanDocument.getItemUuid()), "OR"));
4159 }
4160 searchParams.setPageSize(Integer.parseInt(OLEConstants.MAX_PAGE_SIZE_FOR_LOAN));
4161 buildSearchParams(searchParams);
4162 searchParams.getSearchConditions().addAll(searchConditions);
4163 try {
4164 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
4165 } catch (Exception e) {
4166 LOG.error(e, e);
4167 throw new Exception("Exception occured while fetching data from solr");
4168 }
4169 try {
4170 List<OleLoanDocument> processedLoanDocuments = buildSearchResultsFields(searchResponse, loanDocumentMap);
4171 loanDocumentsWithItemInfo.addAll(processedLoanDocuments);
4172 } catch (Exception e) {
4173 LOG.error(e, e);
4174 throw new Exception("Exception occured while setting the item information to loan documents");
4175 }
4176 } catch (Exception e) {
4177 LOG.info("Exception occured while setting the item information to the loan documents");
4178 LOG.error(e, e);
4179 }
4180 }
4181 }
4182 Long endTime = System.currentTimeMillis();
4183 Long timeDifference = endTime - startTime;
4184 LOG.info("Time Taken to set the item information in the loan records in milliseconds : " + timeDifference);
4185 return loanDocumentsWithItemInfo;
4186 }
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196 public List<OleLoanDocument> buildSearchResultsFields(SearchResponse searchResponse, Map<String, OleLoanDocument> loanDocumentMap) throws Exception {
4197 int count = 0;
4198 Map<String, String> itemTypeNameMap = new HashMap<String, String>();
4199 List<OleInstanceItemType> instanceItemTypeList = (List<OleInstanceItemType>) getBusinessObjectService().findAll(OleInstanceItemType.class);
4200 if (instanceItemTypeList != null && instanceItemTypeList.size() > 0) {
4201 for (OleInstanceItemType oleInstanceItemType : instanceItemTypeList) {
4202 itemTypeNameMap.put(oleInstanceItemType.getInstanceItemTypeName(), oleInstanceItemType.getInstanceItemTypeCode());
4203 }
4204 }
4205 DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
4206 List<OleLoanDocument> oleLoanDocuments = new ArrayList<>();
4207 if (searchResponse != null) {
4208 for (SearchResult searchResult : searchResponse.getSearchResults()) {
4209 try {
4210 OleLoanDocument oleLoanDocument = null;
4211 boolean found = false;
4212 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
4213 if (searchResultField.getFieldValue() != null) {
4214 if (searchResultField.getFieldName().equalsIgnoreCase("id")) {
4215 found = loanDocumentMap.containsKey(searchResultField.getFieldValue());
4216 }
4217 if (found) {
4218 if (searchResultField.getFieldName().equalsIgnoreCase("id")) {
4219 oleLoanDocument = loanDocumentMap.get(searchResultField.getFieldValue());
4220 oleLoanDocument.setItemUuid(searchResultField.getFieldValue());
4221 } else if (searchResultField.getFieldName().equalsIgnoreCase("ItemBarcode_display")) {
4222 oleLoanDocument.setItemId(searchResultField.getFieldValue());
4223 } else if (searchResultField.getFieldName().equalsIgnoreCase("bibIdentifier")) {
4224 oleLoanDocument.setBibUuid(searchResultField.getFieldValue());
4225 } else if (searchResultField.getFieldName().equalsIgnoreCase("Title_display")) {
4226 oleLoanDocument.setTitle(searchResultField.getFieldValue());
4227 } else if (searchResultField.getFieldName().equalsIgnoreCase("Author_display")) {
4228 oleLoanDocument.setAuthor(searchResultField.getFieldValue());
4229 } else if (searchResultField.getFieldName().equalsIgnoreCase("holdingsIdentifier")) {
4230 oleLoanDocument.setInstanceUuid(searchResultField.getFieldValue());
4231 } else if (searchResultField.getFieldName().equalsIgnoreCase("claimsReturnedNote")) {
4232 oleLoanDocument.setClaimsReturnNote(searchResultField.getFieldValue());
4233
4234 } else if (searchResultField.getFieldName().equalsIgnoreCase("ClaimsReturnedFlag_display") && searchResultField.getFieldValue().equalsIgnoreCase("true")) {
4235 oleLoanDocument.setClaimsReturnedIndicator(true);
4236 count++;
4237 } else if (searchResultField.getFieldName().equalsIgnoreCase("Location_display")) {
4238 String location= searchResultField.getFieldValue().split("/")[searchResultField.getFieldValue().split("/").length - 1];
4239 getOleLoanDocumentsFromSolrBuilder().getLocationBySolr(location, oleLoanDocument);
4240 oleLoanDocument.setItemFullLocation(searchResultField.getFieldValue());
4241 Map<String, String> locationMap = getCircDeskLocationResolver().getLocationMap(oleLoanDocument.getItemFullLocation());
4242 oleLoanDocument.setItemInstitution(locationMap.get(OLEConstants.ITEM_INSTITUTION));
4243 oleLoanDocument.setItemCampus(locationMap.get(OLEConstants.ITEM_CAMPUS));
4244 oleLoanDocument.setItemCollection(locationMap.get(OLEConstants.ITEM_COLLECTION));
4245 oleLoanDocument.setItemLibrary(locationMap.get(OLEConstants.ITEM_LIBRARY));
4246 oleLoanDocument.setItemLocation(locationMap.get(OLEConstants.ITEM_SHELVING));
4247
4248 } else if (searchResultField.getFieldName().equalsIgnoreCase("HoldingsLocation_display") &&
4249 (oleLoanDocument.getItemLocation() == null || oleLoanDocument.getItemLocation().isEmpty())) {
4250 String location= searchResultField.getFieldValue().split("/")[searchResultField.getFieldValue().split("/").length - 1];
4251 getOleLoanDocumentsFromSolrBuilder().getLocationBySolr(location, oleLoanDocument);
4252 oleLoanDocument.setItemFullLocation(searchResultField.getFieldValue());
4253 Map<String, String> locationMap = getCircDeskLocationResolver().getLocationMap(oleLoanDocument.getItemFullLocation());
4254 oleLoanDocument.setItemInstitution(locationMap.get(OLEConstants.ITEM_INSTITUTION));
4255 oleLoanDocument.setItemCampus(locationMap.get(OLEConstants.ITEM_CAMPUS));
4256 oleLoanDocument.setItemCollection(locationMap.get(OLEConstants.ITEM_COLLECTION));
4257 oleLoanDocument.setItemLibrary(locationMap.get(OLEConstants.ITEM_LIBRARY));
4258 oleLoanDocument.setItemLocation(locationMap.get(OLEConstants.ITEM_SHELVING));
4259
4260 } else if (searchResultField.getFieldName().equalsIgnoreCase("claimsReturnedFlagCreateDate")) {
4261 String[] formatStrings = new String[]{"MM/dd/yyyy hh:mm:ss", "MM/dd/yyyy", "yyyy-MM-dd hh:mm:ss"};
4262 Date date = getOleLoanDocumentsFromSolrBuilder().tryParse(formatStrings, searchResultField.getFieldValue());
4263 oleLoanDocument.setClaimsReturnedDate(new Timestamp(date.getTime()));
4264
4265 } else if (searchResultField.getFieldName().equalsIgnoreCase("CallNumber_display")) {
4266 oleLoanDocument.setItemCallNumber(searchResultField.getFieldValue());
4267 } else if (searchResultField.getFieldName().equalsIgnoreCase("TemporaryItemTypeFullValue_search")) {
4268 oleLoanDocument.setItemTypeName(searchResultField.getFieldValue());
4269 oleLoanDocument.setItemType(itemTypeNameMap.get(oleLoanDocument.getItemTypeName()));
4270 } else if (searchResultField.getFieldName().equalsIgnoreCase("ItemTypeFullValue_display") &&
4271 (oleLoanDocument.getItemTypeName() == null || oleLoanDocument.getItemTypeName().isEmpty())) {
4272 oleLoanDocument.setItemTypeName(searchResultField.getFieldValue());
4273 oleLoanDocument.setItemType(itemTypeNameMap.get(oleLoanDocument.getItemTypeName()));
4274 } else if (searchResultField.getFieldName().equalsIgnoreCase("Enumeration_display")) {
4275 oleLoanDocument.setEnumeration(searchResultField.getFieldValue());
4276 } else if (searchResultField.getFieldName().equalsIgnoreCase("Chronology_display")) {
4277 oleLoanDocument.setChronology(searchResultField.getFieldValue());
4278 } else if (searchResultField.getFieldName().equalsIgnoreCase("ItemStatus_display")) {
4279 oleLoanDocument.setItemStatus(searchResultField.getFieldValue());
4280 } else if (searchResultField.getFieldName().equalsIgnoreCase("ItemDamagedStatus_display")) {
4281 oleLoanDocument.setItemDamagedStatus(searchResultField.getFieldValue().equalsIgnoreCase("true"));
4282 } else if (searchResultField.getFieldName().equalsIgnoreCase("DamagedItemNote_search")) {
4283 oleLoanDocument.setItemDamagedNote(searchResultField.getFieldValue());
4284 } else if (searchResultField.getFieldName().equalsIgnoreCase("MissingPieceFlagNote_search")) {
4285 oleLoanDocument.setMissingPieceNote(searchResultField.getFieldValue());
4286 } else if (searchResultField.getFieldName().equalsIgnoreCase("MissingPieceFlag_display")) {
4287 oleLoanDocument.setMissingPieceFlag(searchResultField.getFieldValue().equalsIgnoreCase("true"));
4288 } else if (searchResultField.getFieldName().equalsIgnoreCase("CopyNumber_search")) {
4289 oleLoanDocument.setItemCopyNumber(searchResultField.getFieldValue());
4290 } else if (searchResultField.getFieldName().equalsIgnoreCase("HoldingsCopyNumber_search") &&
4291 (oleLoanDocument.getItemCopyNumber() == null || oleLoanDocument.getItemCopyNumber().isEmpty())) {
4292 oleLoanDocument.setItemCopyNumber(searchResultField.getFieldValue());
4293 } else if (searchResultField.getFieldName().equalsIgnoreCase("HoldingsCallNumber_search") &&
4294 (oleLoanDocument.getItemCallNumber() == null || oleLoanDocument.getItemCallNumber().isEmpty())) {
4295 oleLoanDocument.setItemCallNumber(searchResultField.getFieldValue());
4296 } else if (searchResultField.getFieldName().equalsIgnoreCase("MissingPieceCount_search")) {
4297 oleLoanDocument.setMissingPiecesCount(searchResultField.getFieldValue());
4298 } else if (searchResultField.getFieldName().equalsIgnoreCase("NumberOfPieces_search")) {
4299 oleLoanDocument.setItemNumberOfPieces(Integer.parseInt(searchResultField.getFieldValue()));
4300 oleLoanDocument.setBackUpNoOfPieces(searchResultField.getFieldValue());
4301 } else if (searchResultField.getFieldName().equalsIgnoreCase("ClaimsReturnedFlag_search")) {
4302 oleLoanDocument.setClaimsReturnedIndicator(Boolean.valueOf(searchResultField.getFieldValue()));
4303 } else if (searchResultField.getFieldName().equalsIgnoreCase("itemStatusEffectiveDate")) {
4304 oleLoanDocument.setItemStatusEffectiveDate(searchResultField.getFieldValue());
4305
4306 }
4307 }
4308 }
4309
4310 }
4311 found = false;
4312 if (oleLoanDocument.getOlePatron() != null) {
4313 oleLoanDocument.getOlePatron().setNumberOfClaimsReturned(count);
4314 }
4315 oleLoanDocuments.add(oleLoanDocument);
4316 } catch (Exception e) {
4317 LOG.info("Exception occured while setting the item info for the loan ");
4318 }
4319 }
4320 }
4321 return oleLoanDocuments;
4322 }
4323
4324 private OleLoanDocumentsFromSolrBuilder getOleLoanDocumentsFromSolrBuilder() {
4325 if (null == oleLoanDocumentsFromSolrBuilder) {
4326 oleLoanDocumentsFromSolrBuilder = new OleLoanDocumentsFromSolrBuilder();
4327 }
4328 return oleLoanDocumentsFromSolrBuilder;
4329 }
4330
4331 public void setOleLoanDocumentsFromSolrBuilder(OleLoanDocumentsFromSolrBuilder oleLoanDocumentsFromSolrBuilder) {
4332 this.oleLoanDocumentsFromSolrBuilder = oleLoanDocumentsFromSolrBuilder;
4333 }
4334
4335 public String getItemTypeCodeByName(String itemTypeName) {
4336 String itemTypeCode = "";
4337 List<OleInstanceItemType> instanceItemTypeList = null;
4338 Map<String, String> instanceItemTypeMap = new HashMap<String, String>();
4339 instanceItemTypeMap.put("instanceItemTypeName", itemTypeName);
4340 instanceItemTypeList = (List<OleInstanceItemType>) getBusinessObjectService().findMatching(OleInstanceItemType.class, instanceItemTypeMap);
4341 if (instanceItemTypeList != null && instanceItemTypeList.size() > 0) {
4342 itemTypeCode = instanceItemTypeList.get(0).getInstanceItemTypeCode();
4343 }
4344 return itemTypeCode;
4345 }
4346
4347
4348
4349
4350
4351
4352
4353 public void updateItem(Item oleItem) throws Exception {
4354 String itemUuid = oleItem.getItemIdentifier();
4355 String itemXmlContent = getItemOlemlRecordProcessor().toXML(oleItem);
4356 try {
4357 org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
4358 item.setId(itemUuid);
4359 item.setContent(itemXmlContent);
4360 item.setCategory(OLEConstants.WORK_CATEGORY);
4361 item.setType(DocType.ITEM.getCode());
4362 item.setFormat(OLEConstants.OLEML_FORMAT);
4363 getDocstoreClientLocator().getDocstoreClient().updateItem(item);
4364 } catch (Exception e) {
4365 LOG.error(OLEConstants.ITM_STS_TO_DOC_FAIL + e, e);
4366 throw new Exception(OLEConstants.ITM_STS_TO_DOC_FAIL);
4367 }
4368
4369 }
4370
4371
4372 public List splitListToSubList(List<OleLoanDocument> parentList, int childListSize) {
4373 List<List<OleLoanDocument>> childList = new ArrayList<List<OleLoanDocument>>();
4374 List<OleLoanDocument> tempList = new ArrayList<OleLoanDocument>();
4375 int count = 0;
4376 if (parentList != null) {
4377 for (OleLoanDocument obj : parentList) {
4378 if (count < childListSize) {
4379 count = count + 1;
4380 tempList.add(obj);
4381 } else {
4382 childList.add(tempList);
4383 tempList = new ArrayList<OleLoanDocument>();
4384 tempList.add(obj);
4385 count = 1;
4386 }
4387 }
4388 if (tempList.size() <= childListSize) {
4389 childList.add(tempList);
4390 }
4391 }
4392 return childList;
4393 }
4394
4395
4396 public void buildSearchParams(SearchParams searchParams) {
4397 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "id"));
4398 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "ItemBarcode_display"));
4399 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "bibIdentifier"));
4400 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "Title_display"));
4401 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "Author_display"));
4402 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "LocalId_display"));
4403 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "holdingsIdentifier"));
4404 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "ClaimsReturnedFlag_display"));
4405 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "claimsReturnedFlagCreateDate"));
4406 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "claimsReturnedNote"));
4407 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "CallNumber_display"));
4408 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "TemporaryItemTypeFullValue_search"));
4409 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "ItemTypeFullValue_display"));
4410 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "Enumeration_display"));
4411 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "Chronology_display"));
4412 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "ItemStatus_display"));
4413 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "ItemDamagedStatus_display"));
4414 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "DamagedItemNote_search"));
4415 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "MissingPieceFlagNote_search"));
4416 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "Location_display"));
4417 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "HoldingsCopyNumber_search"));
4418 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "HoldingsCallNumber_search"));
4419 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "HoldingsLocation_display"));
4420 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "MissingPieceCount_search"));
4421 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "NumberOfPieces_search"));
4422 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "CallNumberPrefix_display"));
4423 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "CopyNumber_search"));
4424 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "proxyBorrower"));
4425 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "VolumeNumberLabel_display"));
4426 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "dueDateTime"));
4427 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "NumberOfRenew_display"));
4428 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "checkOutDateTime"));
4429 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "ClaimsReturnedFlag_search"));
4430 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "itemStatusEffectiveDate"));
4431 }
4432
4433
4434 public void saveOLEDeliverNoticeHistory(OleLoanDocument oleLoanDocument) {
4435 for (OLEDeliverNotice oleDeliverNotice : oleLoanDocument.getDeliverNotices()) {
4436 OLEDeliverNoticeHistory oleDeliverNoticeHistory = new OLEDeliverNoticeHistory();
4437 oleDeliverNoticeHistory.setLoanId(oleLoanDocument.getLoanId());
4438 oleDeliverNoticeHistory.setNoticeType(oleDeliverNotice.getNoticeType());
4439 oleDeliverNoticeHistory.setNoticeSentDate(new Timestamp(new Date().getTime()));
4440 oleDeliverNoticeHistory.setPatronId(oleLoanDocument.getPatronId());
4441 oleDeliverNoticeHistory.setNoticeSendType(oleDeliverNotice.getNoticeSendType());
4442 getBusinessObjectService().save(oleDeliverNoticeHistory);
4443 }
4444 }
4445
4446
4447 private void itemStatusBulkUpdate(List<String> itemUUIDs) {
4448 List<org.kuali.ole.docstore.common.document.Item> items = null;
4449 DocstoreLocalClient docstoreLocalClient = new DocstoreLocalClient();
4450 try {
4451 items = docstoreLocalClient.retrieveItems(itemUUIDs);
4452
4453 } catch (Exception e) {
4454 StringBuffer itemUUIDsBuffer = new StringBuffer();
4455 for (String itemUUID : itemUUIDs) {
4456 itemUUIDsBuffer.append(itemUUID + ",");
4457 }
4458 LOG.info("Exception occured while retrieving the item for updating the item status to the following itemIds : " + itemUUIDsBuffer.toString());
4459 LOG.error(e, e);
4460 }
4461
4462 BibTrees bibTrees = new BibTrees();
4463 for (org.kuali.ole.docstore.common.document.Item item : items) {
4464 Item oleItem = (Item) item.getContentObject();
4465 String itemXml = null;
4466 try {
4467 itemXml = getLoanProcessor().buildItemContentWithItemStatus(oleItem, OLEConstants.ITEM_STATUS_LOST);
4468 } catch (Exception e) {
4469 LOG.info("Exception occured while updating the item status for the item id : " + item.getId() + "and barcode : " + item.getBarcode());
4470 LOG.error(e, e);
4471 }
4472 if (itemXml != null) {
4473 item.setContent(itemXml);
4474 item.setOperation(DocstoreDocument.OperationType.UPDATE);
4475 BibTree bibTree = new BibTree();
4476 bibTree.setBib(item.getHolding().getBib());
4477 HoldingsTree holdingsTree = new HoldingsTree();
4478 holdingsTree.setHoldings(item.getHolding());
4479 holdingsTree.getItems().add(item);
4480 bibTree.getHoldingsTrees().add(holdingsTree);
4481 bibTrees.getBibTrees().add(bibTree);
4482 }
4483 }
4484 try {
4485 docstoreLocalClient.processBibTrees(bibTrees);
4486 } catch (Exception e) {
4487 LOG.error(e, e);
4488 StringBuffer itemUUIDsBuffer = new StringBuffer();
4489 for (String itemUUID : itemUUIDs) {
4490 itemUUIDsBuffer.append(itemUUID + ",");
4491 }
4492 LOG.info("Exception occured while updating item status to the following itemIds : " + itemUUIDsBuffer.toString());
4493 }
4494
4495 }
4496
4497 public Map<String, List<String>> getItemStatusBasedOnRequestTypeMap() {
4498 String recallDeliveryRequestStatus = getLoanProcessor().getParameter(OLEConstants.RECALL_DELIVERY_ITEM_STATUS);
4499 String recallHoldRequestStatus = getLoanProcessor().getParameter(OLEConstants.RECALL_HOLD_ITEM_STATUS);
4500 String holdDeliveryRequestStatus = getLoanProcessor().getParameter(OLEConstants.HOLD_DELIVERY_ITEM_STATUS);
4501 String holdHoldRequestStatus = getLoanProcessor().getParameter(OLEConstants.HOLD_HOLD_ITEM_STATUS);
4502 String pageDeliveryRequestStatus = getLoanProcessor().getParameter(OLEConstants.PAGE_DELIVERY_ITEM_STATUS);
4503 String pageHoldRequestStatus = getLoanProcessor().getParameter(OLEConstants.PAGE_HOLD_ITEM_STATUS);
4504 String copyRequestStatus = getLoanProcessor().getParameter(OLEConstants.COPY_REQUEST_ITEM_STATUS);
4505
4506 String asrRequestStatus = getLoanProcessor().getParameter(OLEConstants.ASR_REQUEST_ITEM_STATUS);
4507
4508 Set<String> recallSet = new HashSet<>();
4509 recallSet.addAll(convertArrayToList(recallDeliveryRequestStatus.split(";")));
4510 recallSet.addAll(convertArrayToList(recallHoldRequestStatus.split(";")));
4511
4512 Set<String> holdSet = new HashSet<>();
4513 holdSet.addAll(convertArrayToList(holdDeliveryRequestStatus.split(";")));
4514 holdSet.addAll(convertArrayToList(holdHoldRequestStatus.split(";")));
4515
4516 Set<String> pageSet = new HashSet<>();
4517 pageSet.addAll(convertArrayToList(pageDeliveryRequestStatus.split(";")));
4518 pageSet.addAll(convertArrayToList(pageHoldRequestStatus.split(";")));
4519
4520 Map<String, List<String>> itemStatusByRequestTypeMap = new HashMap<String, List<String>>();
4521 itemStatusByRequestTypeMap.put("recall", new ArrayList<>(recallSet));
4522 itemStatusByRequestTypeMap.put("hold", new ArrayList<>(holdSet));
4523 itemStatusByRequestTypeMap.put("page", new ArrayList<>(pageSet));
4524 itemStatusByRequestTypeMap.put("copy", convertArrayToList(copyRequestStatus.split(";")));
4525 itemStatusByRequestTypeMap.put("asr",convertArrayToList(asrRequestStatus.split(";")));
4526 return itemStatusByRequestTypeMap;
4527 }
4528
4529
4530 public boolean deliverAddressExist(String patronId) throws Exception {
4531 boolean found = false;
4532 Map<String, String> criteria = new HashMap<String, String>();
4533 Map<String, String> addressCriteria = new HashMap<String, String>();
4534 criteria.put("olePatronId", patronId);
4535 List<OlePatronDocument> olePatronDocument = (List<OlePatronDocument>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePatronDocument.class, criteria);
4536 if (olePatronDocument != null && olePatronDocument.size() > 0) {
4537 List<OleAddressBo> oleAddressBos = olePatronDocument.get(0).getOleAddresses();
4538 if (oleAddressBos != null && oleAddressBos.size() > 0) {
4539 for (int address = 0; address < oleAddressBos.size(); address++) {
4540 if (oleAddressBos != null && oleAddressBos.size() > 0 && oleAddressBos.get(address).isDeliverAddress()) {
4541 found = true;
4542 }
4543 }
4544 }
4545
4546 }
4547 return found;
4548 }
4549
4550
4551 public List getPatronDocumentByPatronBarcode(String patronBarcode) throws Exception {
4552 Map barMap = new HashMap();
4553 barMap.put(OLEConstants.OlePatron.BARCODE, patronBarcode);
4554 List<OlePatronDocument> matching = (List<OlePatronDocument>) getBusinessObjectService().findMatching(OlePatronDocument.class, barMap);
4555 return matching;
4556 }
4557
4558
4559
4560 public String getParameter(String name) {
4561 ParameterKey parameterKey = ParameterKey.create(OLEConstants.APPL_ID, OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, name);
4562 Parameter parameter = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameter(parameterKey);
4563 if (parameter == null) {
4564 parameterKey = ParameterKey.create(OLEConstants.APPL_ID_OLE, OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, name);
4565 parameter = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameter(parameterKey);
4566 }
4567 return parameter != null ? parameter.getValue() : null;
4568 }
4569
4570 private DataCarrierService dataCarrierService;
4571
4572 public DataCarrierService getDataCarrierService() {
4573 if (dataCarrierService == null) {
4574 dataCarrierService = (DataCarrierService)SpringContext.getService("dataCarrierService");
4575 }
4576 return dataCarrierService;
4577 }
4578
4579 public OlePatronDocument validateGeneralChecks(OlePatronDocument olePatronDocument) throws Exception {
4580
4581 boolean isAddressVerified = false;
4582 try {
4583 isAddressVerified = (boolean) getOleCirculationPolicyService().isAddressVerified(olePatronDocument, olePatronDocument.getOlePatronId());
4584
4585 } catch (Exception e) {
4586
4587 throw e;
4588 }
4589 OlePatronRecordUtil olePatronRecordUtil = new OlePatronRecordUtil();
4590 DroolsResponse droolsResponse= olePatronRecordUtil.fireRules(olePatronDocument,null);
4591
4592 if (droolsResponse!=null && droolsResponse.getErrorMessage()!=null && droolsResponse.getErrorMessage().getErrorMessage()!=null && !droolsResponse.getErrorMessage().getErrorMessage().trim().isEmpty()) {
4593 olePatronDocument.setErrorMessage(droolsResponse.getErrorMessage().getErrorMessage());
4594 }
4595 getDataCarrierService().addData(OLEConstants.ERROR_ACTION, null);
4596 getDataCarrierService().addData(OLEConstants.ERRORS_AND_PERMISSION, null);
4597 return olePatronDocument;
4598 }
4599
4600 public EngineResults getEngineResults(String agendaName, HashMap<String, Object> termValues) throws Exception {
4601 LOG.debug("Inside the getEngineResults method");
4602 EngineResults engineResult = null;
4603 try {
4604 Engine engine = KrmsApiServiceLocator.getEngine();
4605 ContextDefinition contextDefinition = KrmsRepositoryServiceLocator.getContextBoService().getContextByNameAndNamespace("OLE-CONTEXT", "OLE");
4606 AgendaDefinition agendaDefinition = KrmsRepositoryServiceLocator.getAgendaBoService().getAgendaByNameAndContextId(agendaName, contextDefinition.getId());
4607 HashMap<String, String> map = new HashMap<String, String>();
4608 map.put(OLEConstants.AGENDA_NAME, agendaDefinition.getName());
4609 List<MatchBo> matchBos = (List<MatchBo>) getBusinessObjectService().findMatching(MatchBo.class, map);
4610
4611 SelectionCriteria selectionCriteria =
4612 SelectionCriteria.createCriteria(null, getSelectionContext(contextDefinition.getName()), getAgendaContext(agendaName));
4613 ExecutionOptions executionOptions = new ExecutionOptions();
4614 executionOptions.setFlag(ExecutionFlag.LOG_EXECUTION, true);
4615
4616 Facts.Builder factBuilder = Facts.Builder.create();
4617
4618 for (Iterator<MatchBo> matchBoIterator = matchBos.iterator(); matchBoIterator.hasNext(); ) {
4619 MatchBo matchBo = matchBoIterator.next();
4620 factBuilder.addFact(matchBo.getTermName(), termValues.get((matchBo.getTermName())));
4621 }
4622 engineResult = engine.execute(selectionCriteria, factBuilder.build(), executionOptions);
4623 } catch (Exception krmsException) {
4624 LOG.error("-----------KRMS EXCEPTION------------------", krmsException);
4625
4626 throw new RuntimeException(krmsException);
4627 }
4628 return engineResult;
4629 }
4630
4631
4632 public List<OleDeliverRequestBo> getRequestByItem(String itemBarcode) {
4633 List<OleDeliverRequestBo> oleDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>();
4634 Map<String, String> requestMap = new HashMap<String, String>();
4635 requestMap.put("itemId", itemBarcode);
4636 oleDeliverRequestBoList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
4637 return oleDeliverRequestBoList;
4638 }
4639
4640 public List<String> convertArrayToList(String[] array) {
4641 List<String> returnArrayList = new ArrayList<>();
4642 if (array != null && array.length > 0) {
4643 for (String value : array) {
4644 if (StringUtils.isNotBlank(value))
4645 returnArrayList.add(value.trim());
4646 }
4647 }
4648 return returnArrayList;
4649 }
4650
4651 protected SimpleDateFormat getSimpleDateFormat() {
4652 return new SimpleDateFormat(RiceConstants.SIMPLE_DATE_FORMAT_FOR_DATE + " " + RiceConstants.SIMPLE_DATE_FORMAT_FOR_TIME);
4653 }
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663 public String fireRules(OleDeliverRequestBo oleDeliverRequestBo, boolean backGroundLoan, boolean override) {
4664 processRequestToExecuteDrools(oleDeliverRequestBo);
4665 DroolsResponse droolsResponse = new DroolsResponse();
4666 NoticeInfo noticeInfo = new NoticeInfo();
4667 buildFactsAndExecuteRules(droolsResponse,noticeInfo,oleDeliverRequestBo);
4668 processRequestAfterRuleEvaluation(oleDeliverRequestBo, droolsResponse, noticeInfo,backGroundLoan, override);
4669 return oleDeliverRequestBo.getMessage();
4670 }
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682 private OleDeliverRequestBo processRequestAfterRuleEvaluation(OleDeliverRequestBo oleDeliverRequestBo,DroolsResponse droolsResponse,NoticeInfo noticeInfo,boolean backGroundLoan,boolean override){
4683 if (droolsResponse.isRuleMatched() ) {
4684 droolsResponse.setErrorMessage(null);
4685 OleDroolsHoldResponseBo oleDroolsHoldResponseBo = generateOleDroolsHoldResponseBo(droolsResponse, null);
4686 oleDeliverRequestBo.setOleDroolsHoldResponseBo(oleDroolsHoldResponseBo);
4687 if (oleDeliverRequestBo.getRequestExpiryDate() == null) {
4688 Timestamp requestExpirationDate = calculateXDatesBasedOnCalendar(getCalendarGroup(oleDeliverRequestBo.getItemLocation()), String.valueOf(oleDroolsHoldResponseBo.getRequestExpirationDay()), null, true);
4689 oleDeliverRequestBo.setRequestExpiryDate(new java.sql.Date(requestExpirationDate.getTime()));
4690 }
4691 if (oleDeliverRequestBo.getRequestTypeId() != null && ((oleDeliverRequestBo.getRequestTypeId().equals("1") || oleDeliverRequestBo.getRequestTypeId().equals("2")) && (!isRecallRequestExist("1", oleDeliverRequestBo.getItemId()) && !isRecallRequestExist("2", oleDeliverRequestBo.getItemId())) || backGroundLoan)) {
4692 updateLoanDocument(oleDeliverRequestBo,noticeInfo,oleDroolsHoldResponseBo.getMinimumLoanPeriod(), oleDroolsHoldResponseBo.getRecallLoanPeriod());
4693 }
4694 oleDeliverRequestBo.setOleDroolsHoldResponseBo(null);
4695 oleDeliverRequestBo.setMessage(droolsResponse.getErrorMessage().getErrorMessage());
4696 }else{
4697 oleDeliverRequestBo.setMessage(OLEConstants.NO_RULE_FOUND);
4698 }
4699 return oleDeliverRequestBo;
4700 }
4701
4702 private void buildFactsAndExecuteRules(DroolsResponse droolsResponse,NoticeInfo noticeInfo,OleDeliverRequestBo oleDeliverRequestBo){
4703 ArrayList<Object> facts = new ArrayList<Object>();
4704 facts.add(noticeInfo);
4705 facts.add(droolsResponse);
4706 facts.add(oleDeliverRequestBo);
4707 facts.add(oleDeliverRequestBo.getOlePatron());
4708 new CircUtilController().fireRules(facts, null, "place-request");
4709 }
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720 public Timestamp calculateXDatesBasedOnCalendar(String groupId, String days, Timestamp timeToCalculateFrom, boolean daysAlone) {
4721 OleCalendarService oleCalendarService = new OleCalendarServiceImpl();
4722 if (timeToCalculateFrom == null) {
4723 timeToCalculateFrom = new Timestamp(System.currentTimeMillis());
4724 }
4725 if (daysAlone) {
4726 return oleCalendarService.calculateDueDate(groupId, String.valueOf(days), timeToCalculateFrom);
4727 } else {
4728 return oleCalendarService.calculateDueDateHrs(groupId, String.valueOf(days), new Timestamp(System.currentTimeMillis()));
4729 }
4730 }
4731
4732
4733
4734
4735
4736
4737
4738 public String getCalendarGroup(String itemLocation) {
4739 String groupId = null;
4740 if (StringUtils.isNotBlank(itemLocation)) {
4741 OleCirculationDesk oleCirculationDesk = getCirculationDesk(itemLocation);
4742 if (oleCirculationDesk != null) {
4743 groupId = oleCirculationDesk.getCalendarGroupId();
4744 }
4745 }
4746 return groupId;
4747 }
4748
4749
4750
4751
4752
4753
4754
4755 private OleCirculationDesk getCirculationDesk(String itemLocation) {
4756 Map circulationDeskMap = new HashMap();
4757 OleCirculationDesk oleCirculationDesk = null;
4758 String[] locations = itemLocation.split("/");
4759 circulationDeskMap.put("location.locationCode", locations[locations.length - 1]);
4760 List<OleCirculationDeskLocation> oleCirculationDeskLocations = (List<OleCirculationDeskLocation>) getBusinessObjectService().findMatching(OleCirculationDeskLocation.class, circulationDeskMap);
4761 for (OleCirculationDeskLocation oleCirculationDeskLocation : oleCirculationDeskLocations) {
4762 if (oleCirculationDeskLocation.getCirculationFullLocationCode().equals(itemLocation)) {
4763 oleCirculationDesk = oleCirculationDeskLocation.getOleCirculationDesk();
4764 }
4765 }
4766 return oleCirculationDesk;
4767 }
4768
4769
4770
4771
4772
4773
4774
4775
4776 private OleDroolsHoldResponseBo generateOleDroolsHoldResponseBo(DroolsResponse droolsResponse, OleDroolsHoldResponseBo oleDroolsHoldResponseBo) {
4777 if (oleDroolsHoldResponseBo == null) {
4778 oleDroolsHoldResponseBo = new OleDroolsHoldResponseBo();
4779 }
4780 oleDroolsHoldResponseBo.setRuleMatched(droolsResponse.isRuleMatched());
4781 if (droolsResponse.getDroolsExchange().getFromContext("minimumLoanPeriod") != null) {
4782 oleDroolsHoldResponseBo.setMinimumLoanPeriod((String) droolsResponse.getDroolsExchange().getFromContext("minimumLoanPeriod"));
4783 }
4784 if (droolsResponse.getDroolsExchange().getFromContext("recallLoanPeriod") != null) {
4785 oleDroolsHoldResponseBo.setRecallLoanPeriod((String) droolsResponse.getDroolsExchange().getFromContext("recallLoanPeriod"));
4786 }
4787 if (droolsResponse.getDroolsExchange().getFromContext("requestExpirationDays") != null) {
4788 oleDroolsHoldResponseBo.setRequestExpirationDay((Integer) droolsResponse.getDroolsExchange().getFromContext("requestExpirationDays"));
4789 }
4790 return oleDroolsHoldResponseBo;
4791 }
4792
4793
4794
4795
4796
4797
4798 private OleLoanDocument getLoanDocument(String itemId) {
4799 Timestamp dueDate = null;
4800 OleLoanDocument oleLoanDocument = null;
4801 Map<String, String> loanMap = new HashMap<String, String>();
4802 loanMap.put("itemId", itemId);
4803 List<OleLoanDocument> oleLoanDocumentList = (List<OleLoanDocument>) getBusinessObjectService().findMatching(OleLoanDocument.class, loanMap);
4804 if (oleLoanDocumentList.size() > 0) {
4805 oleLoanDocument = oleLoanDocumentList.get(0);
4806 }
4807 return oleLoanDocument;
4808 }
4809
4810
4811
4812
4813
4814
4815
4816
4817 private void updateLoanDocument(OleDeliverRequestBo oleDeliverRequestBo, NoticeInfo noticeInfo,String minimumLoanPeriod, String recallLoanPeriod) {
4818 Timestamp dueDate = null;
4819 if (oleDeliverRequestBo.getRequestTypeId().equals("1") || oleDeliverRequestBo.getRequestTypeId().equals("2")) {
4820 OleLoanDocument oleLoanDocument = getLoanDocument(oleDeliverRequestBo.getItemId());
4821 if (oleLoanDocument != null ) {
4822 if (oleLoanDocument.getCirculationLocationId() != null) {
4823 Map<String, String> circDeskCriteriaMap = new HashMap<String, String>();
4824 circDeskCriteriaMap.put("circulationDeskId", oleLoanDocument.getCirculationLocationId());
4825 List<OleCirculationDesk> oleCirculationDesks = (List<OleCirculationDesk>) getBusinessObjectService().findMatching(OleCirculationDesk.class, circDeskCriteriaMap);
4826 OleCirculationDesk oleCirculationDesk = null;
4827 if (oleCirculationDesks.size() > 0) {
4828 oleCirculationDesk = oleCirculationDesks.get(0);
4829 }
4830 if (oleCirculationDesk != null && oleCirculationDesk.getCalendarGroupId() != null) {
4831 Timestamp minimumLoanPeriodDate = calculateXDatesBasedOnCalendar(oleCirculationDesk.getCalendarGroupId(), minimumLoanPeriod, null, false);
4832 Timestamp recallLoanPeriodDate = calculateXDatesBasedOnCalendar(oleCirculationDesk.getCalendarGroupId(), recallLoanPeriod, null, false);
4833 Timestamp createdDate = new Timestamp(oleLoanDocument.getCreateDate().getTime());
4834 dueDate = getDueDate(minimumLoanPeriodDate, recallLoanPeriodDate, createdDate, minimumLoanPeriod, recallLoanPeriod, oleCirculationDesk.getCalendarGroupId());
4835 oleLoanDocument.setPastDueDate(oleLoanDocument.getLoanDueDate());
4836 oleLoanDocument.setLoanDueDate(dueDate);
4837 if(oleLoanDocument.getPastDueDate()!=null){
4838 oleDeliverRequestBo.setOriginalDueDate(new java.sql.Date(oleLoanDocument.getPastDueDate().getTime()));
4839 }
4840 oleDeliverRequestBo.setRecallDueDate(new Timestamp(oleLoanDocument.getLoanDueDate().getTime()));
4841 oleDeliverRequestBo.setNewDueDate(new java.sql.Date(oleLoanDocument.getLoanDueDate().getTime()));
4842 oleDeliverRequestBo.setNoticeType(noticeInfo.getNoticeType());
4843 List<OLEDeliverNotice> deliverNotices = getDeliverNotices(oleDeliverRequestBo, oleLoanDocument,noticeInfo);
4844
4845 oleLoanDocument.setDeliverNotices(deliverNotices);
4846 persistDeliverNotices(deliverNotices,oleLoanDocument.getLoanId());
4847 Item oleItem = oleDeliverRequestBo.getOleItem();
4848 oleItem.setDueDateTime(getLoanProcessor().convertDateToString(oleLoanDocument.getLoanDueDate(), "MM/dd/yyyy HH:mm:ss"));
4849 try {
4850 updateItem(oleItem);
4851 } catch (Exception e) {
4852 if (LOG.isInfoEnabled()) {
4853 LOG.info("Exception occured while updating the item . " + e.getMessage());
4854 }
4855 }
4856 getBusinessObjectService().save(oleLoanDocument);
4857 }
4858 }
4859
4860 }
4861
4862 }
4863 }
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876 private Timestamp getDueDate(Timestamp minimumLoanPeriodDate, Timestamp recallLoanPeriodDate, Timestamp createdDate, String minimumLoanDays, String recallLoanDays, String groupId) {
4877 Timestamp dueDate = null;
4878 Timestamp minimumLoanDateByLoanedDate = null;
4879 if (minimumLoanPeriodDate.compareTo(recallLoanPeriodDate) <= 0) {
4880 dueDate = recallLoanPeriodDate;
4881 } else {
4882 minimumLoanDateByLoanedDate = calculateXDatesBasedOnCalendar(groupId, minimumLoanDays, createdDate, false);
4883 if (recallLoanPeriodDate.compareTo(minimumLoanDateByLoanedDate) >= 0) {
4884 dueDate = recallLoanPeriodDate;
4885 } else {
4886 dueDate = minimumLoanPeriodDate;
4887 }
4888
4889 }
4890 String defaultCloseTime = getLoanProcessor().getParameter(OLEParameterConstants.DEF_CLOSE_TIME);
4891 dueDate = Timestamp.valueOf(new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT).
4892 format(dueDate).concat(" ").concat(defaultCloseTime));
4893 return dueDate;
4894
4895 }
4896
4897
4898
4899
4900
4901
4902 public ItemRecord getItemRecordByBarcode(String itemBarcode) {
4903 ItemRecord itemRecord = null;
4904 HashMap<String, String> criteriaMap = new HashMap<>();
4905 criteriaMap.put("barCode", itemBarcode);
4906 List<ItemRecord> itemRecords = (List<ItemRecord>) getBusinessObjectService().findMatching(ItemRecord.class,
4907 criteriaMap);
4908 if (null != itemRecords && !itemRecords.isEmpty()) {
4909 itemRecord = itemRecords.get(0);
4910 }
4911
4912 return itemRecord;
4913 }
4914
4915
4916
4917
4918
4919
4920
4921 public List<OLEDeliverNotice> getDeliverNotices(OleDeliverRequestBo oleDeliverRequestBo,OleLoanDocument oleLoanDocument,NoticeInfo noticeInfo){
4922 ItemRecord itemRecord = getItemRecordByBarcode(oleDeliverRequestBo.getItemId());
4923 itemRecord.setDueDateTime(oleDeliverRequestBo.getRecallDueDate());
4924 List<OLEDeliverNotice> oleDeliverNotices = new CircUtilController().processNotices(oleLoanDocument,itemRecord);
4925 return oleDeliverNotices;
4926 }
4927
4928 public void persistDeliverNotices(List<OLEDeliverNotice> oleDeliverNotices,String loanId){
4929 Map<String,String> noticeMap = new HashMap<String,String>();
4930 noticeMap.put("loanId",loanId);
4931 getBusinessObjectService().deleteMatching(OLEDeliverNotice.class,noticeMap);
4932 getBusinessObjectService().save(oleDeliverNotices);
4933 }
4934
4935 public boolean isValidASRItemStatus(String itemStatus){
4936 boolean valid = false;
4937 String parameterValue = getLoanProcessor().getParameter(ASRConstants.ASR_REQUEST_ITEM_STATUS);
4938 String[] itemStatuses ;
4939 if(itemStatus!=null){
4940 itemStatuses = parameterValue.split("[';']");
4941 if(itemStatuses!=null && itemStatuses.length>0){
4942 for(String itemStats: itemStatuses){
4943 if(itemStatus.equals(itemStats)){
4944 valid =true;
4945 break;
4946 }
4947 }
4948 }
4949
4950 }
4951
4952 return valid;
4953 }
4954 }
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966