1 package org.kuali.ole.deliver.service;
2
3
4 import com.lowagie.text.Document;
5 import org.apache.log4j.Logger;
6 import org.kuali.asr.ASRConstants;
7 import org.kuali.asr.service.ASRHelperServiceImpl;
8 import org.kuali.ole.DataCarrierService;
9 import org.kuali.ole.LoanUtil;
10 import org.kuali.ole.OLEConstants;
11 import org.kuali.ole.OLEParameterConstants;
12 import org.kuali.ole.deliver.batch.OleDeliverBatchServiceImpl;
13 import org.kuali.ole.deliver.batch.OleMailer;
14 import org.kuali.ole.deliver.batch.OleNoticeBo;
15 import org.kuali.ole.deliver.batch.OleSms;
16 import org.kuali.ole.deliver.bo.*;
17 import org.kuali.ole.deliver.processor.LoanProcessor;
18 import org.kuali.ole.describe.bo.OleInstanceItemType;
19 import org.kuali.ole.describe.bo.OleLocation;
20 import org.kuali.ole.describe.bo.OleLocationLevel;
21 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
22 import org.kuali.ole.docstore.common.document.Bib;
23 import org.kuali.ole.docstore.common.document.Holdings;
24 import org.kuali.ole.docstore.common.document.ItemOleml;
25 import org.kuali.ole.docstore.common.document.content.enums.DocType;
26 import org.kuali.ole.docstore.common.document.content.instance.*;
27 import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
28 import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
29 import org.kuali.ole.docstore.common.search.SearchResponse;
30 import org.kuali.ole.docstore.common.search.SearchResult;
31 import org.kuali.ole.docstore.common.search.SearchResultField;
32 import org.kuali.ole.docstore.common.document.content.instance.Item;
33 import org.kuali.ole.docstore.common.document.content.instance.LocationLevel;
34 import org.kuali.ole.ingest.pojo.MatchBo;
35 import org.kuali.ole.ncip.bo.OLENCIPConstants;
36 import org.kuali.ole.ncip.bo.OLEPlaceRequest;
37 import org.kuali.ole.ncip.converter.OLEPlaceRequestConverter;
38 import org.kuali.ole.sys.context.SpringContext;
39 import org.kuali.ole.util.DocstoreUtil;
40 import org.kuali.rice.core.api.config.property.ConfigContext;
41 import org.kuali.rice.core.api.mail.EmailBody;
42 import org.kuali.rice.core.api.mail.EmailFrom;
43 import org.kuali.rice.core.api.mail.EmailSubject;
44 import org.kuali.rice.core.api.mail.EmailTo;
45 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
46 import org.kuali.rice.coreservice.impl.parameter.ParameterBo;
47 import org.kuali.rice.kim.api.permission.PermissionService;
48 import org.kuali.rice.kim.api.role.RoleService;
49 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
50 import org.kuali.rice.kim.impl.identity.type.EntityTypeContactInfoBo;
51 import org.kuali.rice.krad.service.BusinessObjectService;
52 import org.kuali.rice.krad.service.KRADServiceLocator;
53 import org.kuali.rice.krad.util.GlobalVariables;
54 import org.kuali.rice.krad.util.KRADConstants;
55 import org.kuali.rice.krad.util.ObjectUtils;
56 import org.kuali.rice.krms.api.KrmsApiServiceLocator;
57 import org.kuali.rice.krms.api.engine.*;
58 import org.kuali.rice.krms.impl.repository.AgendaBo;
59
60 import java.io.OutputStream;
61 import java.math.BigDecimal;
62 import java.sql.*;
63 import java.text.DateFormat;
64 import java.text.SimpleDateFormat;
65 import java.util.*;
66 import java.util.Date;
67
68 import org.apache.ojb.broker.PersistenceBroker;
69 import org.apache.ojb.broker.PersistenceBrokerException;
70
71
72
73
74
75
76
77
78 public class OleDeliverRequestDocumentHelperServiceImpl {
79 private static final Logger LOG = Logger.getLogger(OleDeliverRequestDocumentHelperServiceImpl.class);
80 private static final String NAMESPACE_CODE_SELECTOR = "namespaceCode";
81 private static final String NAME_SELECTOR = "name";
82 private final static String RULE_EVALUATED = "Rule Evaluated";
83 private final static String ROUTED_EXTERNAL = "Routed External";
84 private BusinessObjectService businessObjectService;
85 private int queuePosition = 0;
86 private LoanProcessor loanProcessor;
87 private DocstoreUtil docstoreUtil;
88
89
90 private PermissionService getPermissionService() {
91 PermissionService service = KimApiServiceLocator.getPermissionService();
92 return service;
93 }
94
95 private DocstoreClientLocator docstoreClientLocator;
96
97 public DocstoreClientLocator getDocstoreClientLocator() {
98
99 if (docstoreClientLocator == null) {
100 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
101
102 }
103 return docstoreClientLocator;
104 }
105
106 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
107 this.businessObjectService = businessObjectService;
108 }
109
110
111 public void setLoanProcessor(LoanProcessor loanProcessor) {
112 this.loanProcessor = loanProcessor;
113 }
114
115 public void setDocstoreUtil(DocstoreUtil docstoreUtil) {
116 this.docstoreUtil = docstoreUtil;
117 }
118
119 public void setDocstoreClientLocator(DocstoreClientLocator docstoreClientLocator) {
120 this.docstoreClientLocator = docstoreClientLocator;
121 }
122
123 public DocstoreUtil getDocstoreUtil() {
124 if(docstoreUtil == null){
125 docstoreUtil = SpringContext.getBean(DocstoreUtil.class);
126 }
127 return docstoreUtil;
128 }
129
130
131
132
133
134
135
136 private BusinessObjectService getBusinessObjectService() {
137 if (null == businessObjectService) {
138 businessObjectService = KRADServiceLocator.getBusinessObjectService();
139 }
140 return businessObjectService;
141 }
142
143 public LoanProcessor getLoanProcessor() {
144 if(loanProcessor == null){
145 loanProcessor = SpringContext.getBean(LoanProcessor.class);
146 }
147 return loanProcessor;
148 }
149
150
151
152
153
154
155
156 public OleDeliverRequestBo processRequestType(OleDeliverRequestBo oleDeliverRequestBo) {
157 if (LOG.isDebugEnabled()) {
158 LOG.debug("Inside processRequestType for the Request id :" + oleDeliverRequestBo.getRequestId());
159 }
160 oleDeliverRequestBo = processPatron(oleDeliverRequestBo);
161 oleDeliverRequestBo = processItem(oleDeliverRequestBo);
162 oleDeliverRequestBo = processRequestTypeByPickUpLocation(oleDeliverRequestBo);
163 return oleDeliverRequestBo;
164 }
165
166 private OleDeliverRequestBo processRequestTypeByPickUpLocation(OleDeliverRequestBo oleDeliverRequestBo){
167 if (oleDeliverRequestBo.getRequestTypeId() != null) {
168 if (oleDeliverRequestBo.getRequestTypeId().equals("3") && oleDeliverRequestBo.getPickUpLocationId() != null && !oleDeliverRequestBo.getPickUpLocationId().isEmpty()) {
169 oleDeliverRequestBo.setRequestTypeId("4");
170 } else if (oleDeliverRequestBo.getRequestTypeId().equals("5") && oleDeliverRequestBo.getPickUpLocationId() != null && !oleDeliverRequestBo.getPickUpLocationId().isEmpty()) {
171 oleDeliverRequestBo.setRequestTypeId("6");
172 } else if (oleDeliverRequestBo.getRequestTypeId().equals("1") && oleDeliverRequestBo.getPickUpLocationId() != null && !oleDeliverRequestBo.getPickUpLocationId().isEmpty()) {
173 oleDeliverRequestBo.setRequestTypeId("2");
174 }
175 }
176 return oleDeliverRequestBo;
177 }
178
179
180
181
182
183
184
185
186 public OleDeliverRequestBo processPatron(OleDeliverRequestBo oleDeliverRequestBo) {
187 LOG.debug("Inside processPatron");
188 OleDeliverRequestBo deliver = oleDeliverRequestBo;
189
190 if (oleDeliverRequestBo.getBorrowerBarcode() != null || oleDeliverRequestBo.getProxyBorrowerBarcode() != null) {
191 Map<String, String> patronMap = new HashMap<String, String>();
192 patronMap.put(OLEConstants.OleDeliverRequest.PATRON_BARCODE, oleDeliverRequestBo.getBorrowerBarcode());
193 List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) getBusinessObjectService().findMatching(OlePatronDocument.class, patronMap);
194 if (olePatronDocumentList != null && olePatronDocumentList.size() > 0) {
195 deliver.setOlePatron(olePatronDocumentList.get(0));
196 deliver.setBorrowerName(olePatronDocumentList.get(0).getPatronName());
197 deliver.setBorrowerId(olePatronDocumentList.get(0).getOlePatronId());
198 } else if (olePatronDocumentList != null && olePatronDocumentList.size() == 0) {
199 deliver.setBorrowerId(null);
200 deliver.setFirstName(null);
201 deliver.setLastName(null);
202 deliver.setOlePatron(null);
203 deliver.setBorrowerName(null);
204 deliver.setBorrowerBarcode(null);
205 }
206 if (oleDeliverRequestBo.getRequestCreator().equals(OLEConstants.OleDeliverRequest.REQUESTER_PROXY_PATRON)) {
207 Map<String, String> proxyPatronMap = new HashMap<String, String>();
208 proxyPatronMap.put(OLEConstants.OleDeliverRequest.PATRON_BARCODE, oleDeliverRequestBo.getProxyBorrowerBarcode());
209 List<OlePatronDocument> oleProxyPatronDocumentList = (List<OlePatronDocument>) getBusinessObjectService().findMatching(OlePatronDocument.class, proxyPatronMap);
210 if (oleProxyPatronDocumentList != null && oleProxyPatronDocumentList.size() > 0) {
211 deliver.setOleProxyPatron(oleProxyPatronDocumentList.get(0));
212 deliver.setProxyBorrowerName(oleProxyPatronDocumentList.get(0).getPatronName());
213 deliver.setProxyBorrowerId(oleProxyPatronDocumentList.get(0).getOlePatronId());
214 } else if (oleProxyPatronDocumentList != null && oleProxyPatronDocumentList.size() == 0) {
215 deliver.setProxyBorrowerId(null);
216 deliver.setProxyBorrowerName(null);
217 deliver.setOleProxyPatron(null);
218 }
219 }
220
221 }
222
223 return deliver;
224 }
225
226 public boolean processOperator(String principalId) {
227
228
229
230
231 boolean isOperator = true;
232 Collection<String> roles = getRoleService().getRoleMemberPrincipalIds(OLEConstants.OlePatron.PATRON_NAMESPACE, OLEConstants.OleDeliverRequest.REQUESTER_OPERATOR, null);
233 if (roles != null) {
234 isOperator = roles.contains(principalId);
235 }
236 return isOperator;
237 }
238
239
240
241
242
243
244
245 public boolean validateRequestType(OleDeliverRequestBo oleDeliverRequestBo) {
246 LOG.debug("Inside validateRequestType");
247 boolean validRequest = true;
248 if ((oleDeliverRequestBo.getRequestTypeId().equals("2") || oleDeliverRequestBo.getRequestTypeId().equals("4") || oleDeliverRequestBo.getRequestTypeId().equals("6")) && (oleDeliverRequestBo.getPickUpLocationId() == null) || (oleDeliverRequestBo.getPickUpLocationId() != null && oleDeliverRequestBo.getPickUpLocationId().isEmpty())) {
249 validRequest = false;
250 }
251 return validRequest;
252 }
253
254
255
256
257
258
259
260
261 public boolean validateDeliveryPrivilege(OleDeliverRequestBo oleDeliverRequestBo) {
262 LOG.debug("Inside validateDeliveryPrivilege");
263 boolean hasDeliveryPrivilege = true;
264 if (oleDeliverRequestBo.getRequestTypeId().equals("1") || oleDeliverRequestBo.getRequestTypeId().equals("3") || oleDeliverRequestBo.getRequestTypeId().equals("5")) {
265 if (oleDeliverRequestBo.getOlePatron() != null && !oleDeliverRequestBo.getOlePatron().isDeliveryPrivilege()) {
266 hasDeliveryPrivilege = false;
267 }
268 } else if (oleDeliverRequestBo.getRequestTypeId().equals("2") || oleDeliverRequestBo.getRequestTypeId().equals("4") || oleDeliverRequestBo.getRequestTypeId().equals("6")) {
269 if (oleDeliverRequestBo.getOlePatron() != null && !oleDeliverRequestBo.getOlePatron().isDeliveryPrivilege() && oleDeliverRequestBo.getPickUpLocationId() == null) {
270 hasDeliveryPrivilege = false;
271 }
272 }
273 return hasDeliveryPrivilege;
274 }
275
276
277
278
279
280
281
282
283 public boolean validatePagingPrivilege(OleDeliverRequestBo oleDeliverRequestBo) {
284 LOG.debug("Inside validatePagingPrivilege");
285 boolean hasPagePrivilege = true;
286 if (oleDeliverRequestBo.getRequestTypeId().equals("5") || oleDeliverRequestBo.getRequestTypeId().equals("6")) {
287 if (!oleDeliverRequestBo.getOlePatron().isPagingPrivilege()) {
288 hasPagePrivilege = false;
289 }
290 }
291 return hasPagePrivilege;
292 }
293
294
295
296
297
298
299
300
301 public OleDeliverRequestBo processRequester(OleDeliverRequestBo oleDeliverRequestBo) {
302 LOG.debug("Inside processRequester");
303 if (oleDeliverRequestBo.getRequestCreator().equals(OLEConstants.OleDeliverRequest.REQUESTER_PATRON)) {
304 oleDeliverRequestBo.setProxyBorrowerId(null);
305 oleDeliverRequestBo.setOleProxyPatron(null);
306 oleDeliverRequestBo.setOperatorCreateId(null);
307 oleDeliverRequestBo.setOperatorCreator(null);
308 } else if (oleDeliverRequestBo.getRequestCreator().equals(OLEConstants.OleDeliverRequest.REQUESTER_PROXY_PATRON)) {
309 oleDeliverRequestBo.setOperatorCreateId(null);
310 oleDeliverRequestBo.setOperatorCreator(null);
311 } else if (oleDeliverRequestBo.getRequestCreator().equals(OLEConstants.OleDeliverRequest.REQUESTER_OPERATOR)) {
312 oleDeliverRequestBo.setProxyBorrowerId(null);
313 oleDeliverRequestBo.setOleProxyPatron(null);
314 }
315 return oleDeliverRequestBo;
316 }
317
318
319
320
321
322
323
324
325 public boolean isValidProxyPatron(OleDeliverRequestBo oleDeliverRequestBo) {
326 LOG.debug("Inside isValidProxyPatron");
327 boolean validProxy = true;
328 Map<String, String> proxyMap = new HashMap<String, String>();
329 proxyMap.put(OLEConstants.OleDeliverRequest.PATRON_ID, oleDeliverRequestBo.getBorrowerId());
330 proxyMap.put(OLEConstants.OleDeliverRequest.PROXY_PATRON_ID, oleDeliverRequestBo.getProxyBorrowerId());
331 if (oleDeliverRequestBo.getProxyBorrowerId() != null && !oleDeliverRequestBo.getProxyBorrowerId().isEmpty()) {
332 List<OleProxyPatronDocument> proxyPatronDocuments = (List<OleProxyPatronDocument>) getBusinessObjectService().findMatching(OleProxyPatronDocument.class, proxyMap);
333 if (proxyPatronDocuments.size() == 0) {
334 validProxy = false;
335 }
336 }
337 return validProxy;
338 }
339
340
341
342
343
344
345
346
347 public boolean isRequestAlreadyRaisedByPatron(OleDeliverRequestBo oleDeliverRequestBo) {
348 LOG.debug("Inside isRequestAlreadyRaised");
349 boolean alreadyExist = false;
350 Map<String, String> requestMap = new HashMap<String, String>();
351 requestMap.put(OLEConstants.OleDeliverRequest.BORROWER_ID, oleDeliverRequestBo.getBorrowerId());
352 requestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
353 List<OleDeliverRequestBo> deliverRequestBos = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
354 if (deliverRequestBos != null && deliverRequestBos.size() > 0) {
355 alreadyExist = true;
356 }
357 return alreadyExist;
358 }
359
360
361
362
363
364
365
366
367 public boolean isAlreadyLoaned(OleDeliverRequestBo oleDeliverRequestBo) {
368 LOG.debug("Inside isAlreadyLoaned");
369 boolean alreadyLoaned = false;
370 Map<String, String> loanMap = new HashMap<String, String>();
371 loanMap.put(OLEConstants.OleDeliverRequest.LOAN_PATRON_ID, oleDeliverRequestBo.getBorrowerId());
372 loanMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
373 List<OleLoanDocument> loanDocuments = (List<OleLoanDocument>) getBusinessObjectService().findMatching(OleLoanDocument.class, loanMap);
374 if (loanDocuments != null && loanDocuments.size() > 0) {
375 alreadyLoaned = true;
376 }
377 return alreadyLoaned;
378 }
379
380
381
382
383
384
385
386
387 public boolean isItemAvailable(OleDeliverRequestBo oleDeliverRequestBo) {
388 LOG.debug("Inside isItemAvailable");
389 boolean itemAvailable = true;
390
391 String itemStatuslist = null;
392 String requestTypeCode = oleDeliverRequestBo.getRequestTypeCode();
393 if (requestTypeCode.equals("Recall/Delivery Request")) {
394 itemStatuslist = getLoanProcessor().getParameter(OLEConstants.RECALL_DELIVERY_ITEM_STATUS);
395 } else if (requestTypeCode.equals("Recall/Hold Request")) {
396 itemStatuslist = getLoanProcessor().getParameter(OLEConstants.RECALL_HOLD_ITEM_STATUS);
397 } else if (requestTypeCode.equals("Hold/Delivery Request")) {
398 itemStatuslist = getLoanProcessor().getParameter(OLEConstants.HOLD_DELIVERY_ITEM_STATUS);
399 } else if (requestTypeCode.equals("Hold/Hold Request")) {
400 itemStatuslist = getLoanProcessor().getParameter(OLEConstants.HOLD_HOLD_ITEM_STATUS);
401 } else if (requestTypeCode.equals("Page/Delivery Request")) {
402 itemStatuslist = getLoanProcessor().getParameter(OLEConstants.PAGE_DELIVERY_ITEM_STATUS);
403 } else if (requestTypeCode.equals("Page/Hold Request")) {
404 itemStatuslist = getLoanProcessor().getParameter(OLEConstants.PAGE_HOLD_ITEM_STATUS);
405 } else if (requestTypeCode.equals("Copy Request")) {
406 itemStatuslist = getLoanProcessor().getParameter(OLEConstants.COPY_REQUEST_ITEM_STATUS);
407 } else if (requestTypeCode.equals("ASR Request")) {
408 itemStatuslist = getLoanProcessor().getParameter(OLEConstants.ASR_REQUEST_ITEM_STATUS);
409 }else {
410 GlobalVariables.getMessageMap().putError(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, OLEConstants.OleDeliverRequest.REQUEST_ID_INVALID);
411 }
412 String[] str = itemStatuslist.split(";");
413 for (String itemStatus : str) {
414 if ((itemStatus != null) && (!itemStatus.isEmpty()) && (itemStatus.equals(oleDeliverRequestBo.getItemStatus()))) {
415 itemAvailable = false;
416 }
417 }
418 return itemAvailable;
419 }
420
421
422
423
424
425
426
427
428 public boolean isItemAvailableForLoan(OleDeliverRequestBo oleDeliverRequestBo) {
429 LOG.debug("Inside isItemAvailable");
430 boolean itemAvailable = false;
431 Map<String, String> loanItemMap = new HashMap<String, String>();
432 loanItemMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
433 List<OleLoanDocument> loanItemDocuments = (List<OleLoanDocument>) getBusinessObjectService().findMatching(OleLoanDocument.class, loanItemMap);
434 if (loanItemDocuments.size() == 0) {
435 itemAvailable = true;
436 }
437 return itemAvailable;
438 }
439
440
441
442
443
444
445
446
447 public boolean isItemEligible(OleDeliverRequestBo oleDeliverRequestBo) {
448 LOG.debug("Inside isItemEligible");
449 boolean itemEligible = true;
450 Map<String, String> statusMap = new HashMap<String, String>();
451 statusMap.put(OLEConstants.OleDeliverRequest.LOSTBILLREPLACEMENT, OLEConstants.OleDeliverRequest.LOSTBILLREPLACEMENT);
452 statusMap.put(OLEConstants.OleDeliverRequest.MISSINGFINALOVERDUE, OLEConstants.OleDeliverRequest.MISSINGFINALOVERDUE);
453 statusMap.put(OLEConstants.OleDeliverRequest.WITHDRAWNCLIAMSRETURN, OLEConstants.OleDeliverRequest.WITHDRAWNCLIAMSRETURN);
454
455 if (statusMap.containsKey(oleDeliverRequestBo.getItemStatus())) {
456 itemEligible = false;
457 }
458 return itemEligible;
459 }
460
461
462
463
464
465
466
467 public String patronRecordExpired(OleDeliverRequestBo oleDeliverRequestBo) {
468 LOG.debug("Inside patronRecordExpired");
469 String expired = null;
470 Map<String, String> patronMap = new HashMap<String, String>();
471 patronMap.put(OLEConstants.OleDeliverRequest.PATRON_ID, oleDeliverRequestBo.getBorrowerId());
472 List<OlePatronDocument> olePatronDocuments = (List<OlePatronDocument>) getBusinessObjectService().findMatching(OlePatronDocument.class, patronMap);
473 if (olePatronDocuments != null && olePatronDocuments.size() > 0) {
474 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OleDeliverRequest.DATE_FORMAT);
475 Date expirationDate = olePatronDocuments.get(0).getExpirationDate();
476 Date activationDate = olePatronDocuments.get(0).getActivationDate();
477 if ((fmt.format(activationDate)).compareTo(fmt.format(new Date(System.currentTimeMillis()))) <= 0) {
478 if (expirationDate != null) {
479 if ((fmt.format(expirationDate)).compareTo(fmt.format(new Date(System.currentTimeMillis()))) < 0) {
480 expired = OLEConstants.OleDeliverRequest.PATRON_RECORD_EXPIRE;
481 }
482 }
483 } else {
484 expired = OLEConstants.OleDeliverRequest.PATRON_RECORD_FUTURE;
485 }
486 }
487 return expired;
488 }
489
490
491
492
493
494
495
496
497 public List<OleDeliverRequestBo> getRequestedItems(String olePatronId) {
498 LOG.debug("Inside getRequestedItems");
499 Map<String, String> requestMap = new HashMap<String, String>();
500 requestMap.put(OLEConstants.OleDeliverRequest.BORROWER_ID, olePatronId);
501 List<OleDeliverRequestBo> deliverRequestBos = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
502 for (int i = 0; i < deliverRequestBos.size(); i++) {
503 processItem(deliverRequestBos.get(i));
504 }
505 return deliverRequestBos;
506
507 }
508
509
510
511
512
513
514
515
516 public String validateQueuePosition(List<OleDeliverRequestBo> itemList) {
517 LOG.debug("Inside validateQueuePosition");
518 String message = OLEConstants.OleDeliverRequest.REORDER_SUCCESS;
519 List<Integer> queuePositionList = new ArrayList<Integer>();
520 if (itemList.get(0).getBorrowerQueuePosition() < 1) {
521 return OLEConstants.OleDeliverRequest.POSITIVE_QUEUE_POSITION;
522 }
523 queuePositionList.add(itemList.get(0).getBorrowerQueuePosition());
524
525 for (int i = 1; i < itemList.size(); i++) {
526 for (int j = 0; j < queuePositionList.size(); j++) {
527 if (itemList.get(i).getBorrowerQueuePosition() != null) {
528 if ((itemList.get(i).getBorrowerQueuePosition() >= 1) && (itemList.get(i).getBorrowerQueuePosition() == queuePositionList.get(j))) {
529 return OLEConstants.OleDeliverRequest.QUEUE_DUPLICATE;
530 } else if ((itemList.get(i).getBorrowerQueuePosition() <= 0)) {
531 return OLEConstants.OleDeliverRequest.POSITIVE_QUEUE_POSITION;
532 }
533 }
534 }
535 queuePositionList.add(itemList.get(i).getBorrowerQueuePosition());
536 }
537 return message;
538 }
539
540
541
542
543
544
545
546
547
548 public boolean isRequestRaised(OleDeliverRequestBo oleDeliverRequestBo) {
549 LOG.debug("Inside isRequestRaised");
550 boolean exist = false;
551 Map<String, String> requestMap = new HashMap<String, String>();
552 requestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
553 List<OleDeliverRequestBo> deliverRequestBos = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
554 if (deliverRequestBos.size() > 0) {
555 exist = true;
556 }
557 return exist;
558 }
559
560
561
562
563
564
565
566 public void cancelDocument(OleDeliverRequestBo oleDeliverRequestBo) {
567 ASRHelperServiceImpl asrHelperService = new ASRHelperServiceImpl();
568 LOG.debug("Inside cancelDocument");
569 Map<String, String> itemMap = new HashMap<String, String>();
570 itemMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
571 Map<String, String> requestMap = new HashMap<String, String>();
572 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_ID, oleDeliverRequestBo.getRequestId());
573 getBusinessObjectService().deleteMatching(OleDeliverRequestBo.class, requestMap);
574 List<OleDeliverRequestBo> oleDeliverRequestDocumentsList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class, itemMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
575 getBusinessObjectService().delete(oleDeliverRequestDocumentsList);
576 int queuePosition = 1;
577 for (int i = 0; i < oleDeliverRequestDocumentsList.size(); i++) {
578 oleDeliverRequestDocumentsList.get(i).setBorrowerQueuePosition(queuePosition);
579 queuePosition = queuePosition + 1;
580 }
581 getBusinessObjectService().save(oleDeliverRequestDocumentsList);
582 asrHelperService.deleteASRTypeRequest(oleDeliverRequestBo.getRequestId());
583
584 }
585
586 public void cancelPendingRequestForClaimsReturnedItem(String itemUuid) throws Exception {
587 Map<String, String> requestMap = new HashMap<String, String>();
588 requestMap.put(OLEConstants.ITEM_UUID, itemUuid);
589 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
590 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
591 for (OleDeliverRequestBo oleDeliverRequestBo : oleDeliverRequestBoList) {
592 cancelDocument(oleDeliverRequestBo);
593 OleItemSearch itemSearch = getDocstoreUtil().getOleItemSearchList(itemUuid);
594 EntityTypeContactInfoBo entityTypeContactInfoBo = oleDeliverRequestBo.getOlePatron().getEntity().getEntityTypeContactInfos().get(0);
595 List<OleNoticeBo> oleNoticeBos = new ArrayList<OleNoticeBo>();
596 OleNoticeBo oleNoticeBo = new OleNoticeBo();
597 oleNoticeBo.setNoticeName(OLEConstants.CANCELLATION_NOTICE);
598 oleNoticeBo.setPatronName(oleDeliverRequestBo.getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + oleDeliverRequestBo.getOlePatron().getEntity().getNames().get(0).getLastName());
599 oleNoticeBo.setPatronAddress(getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getPatronPreferredAddress(entityTypeContactInfoBo) : "");
600 oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : "");
601 oleNoticeBo.setPatronPhoneNumber(getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
602 oleNoticeBo.setAuthor(itemSearch.getAuthor() != null ? itemSearch.getAuthor() : "");
603 oleNoticeBo.setItemCallNumber(itemSearch.getCallNumber() != null ? itemSearch.getCallNumber() : "");
604 if(itemSearch.getShelvingLocation()!=null && itemSearch.getShelvingLocation().toString().contains("/")){
605 String [] location=itemSearch.getShelvingLocation().split("/");
606 if(location!=null && location.length>0)
607 oleNoticeBo.setItemShelvingLocation(location[1]!=null ? location[1] : "");
608 } else {
609 oleNoticeBo.setItemShelvingLocation("");
610 }
611 oleNoticeBo.setItemId(itemSearch.getItemBarCode() != null ? itemSearch.getItemBarCode() : "");
612 oleNoticeBo.setTitle(itemSearch.getTitle() != null ? itemSearch.getTitle() : "");
613 oleNoticeBo.setOleItem(getItem(oleDeliverRequestBo.getItemUuid()));
614 String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
615 if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
616 fromAddress = OLEConstants.KUALI_MAIL;
617 }
618 if (oleNoticeBo.getPatronEmailAddress() != null && !oleNoticeBo.getPatronEmailAddress().isEmpty()) {
619 oleNoticeBos.add(oleNoticeBo);
620 List list = oleDeliverBatchService.getNoticeForPatron(oleNoticeBos);
621 String content = list.toString();
622 content = content.replace('[', ' ');
623 content = content.replace(']', ' ');
624 if (!content.trim().equals("")) {
625 OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
626 oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.CANCELLATION_NOTICE), new EmailBody(content), true);
627 }
628 }
629 }
630 }
631
632
633
634
635
636
637
638 public OleDeliverRequestBo processItem(OleDeliverRequestBo oleDeliverRequestBo) {
639 LOG.debug("Inside processItem");
640 OleItemSearch oleItemSearch = null;
641 if (oleDeliverRequestBo.getItemType() == null) {
642
643
644 OleItemSearch itemSearchList = getDocstoreUtil().getOleItemSearchList(oleDeliverRequestBo.getItemUuid());
645 try {
646
647
648
649 if (itemSearchList != null) {
650 oleItemSearch = itemSearchList;
651 oleDeliverRequestBo.setTitle(itemSearchList.getTitle());
652 oleDeliverRequestBo.setAuthor(itemSearchList.getAuthor());
653 oleDeliverRequestBo.setCallNumber(itemSearchList.getCallNumber());
654 oleDeliverRequestBo.setItemType(itemSearchList.getItemType());
655 oleDeliverRequestBo.setItemLocation(itemSearchList.getShelvingLocation());
656 oleDeliverRequestBo.setShelvingLocation(itemSearchList.getShelvingLocation());
657 oleDeliverRequestBo.setCopyNumber(itemSearchList.getCopyNumber());
658 oleDeliverRequestBo.setItemStatus(itemSearchList.getItemStatus());
659 }
660 } catch (Exception ex) {
661 ex.printStackTrace();
662 }
663 try {
664 String itemXml = getLoanProcessor().getItemXML(oleDeliverRequestBo.getItemUuid());
665 Item oleItem = getLoanProcessor().getItemPojo(itemXml);
666 if (oleItemSearch == null) {
667 oleItemSearch = new OleItemSearch();
668 oleItemSearch.setCopyNumber(oleItem.getCopyNumber());
669 if (oleItem.getItemStatus() != null) {
670 oleItemSearch.setItemStatus(oleItem.getItemStatus().getCodeValue());
671 }
672 oleItemSearch.setShelvingLocation(getShelvingLocation(oleItem.getLocation()));
673 oleDeliverRequestBo.setCopyNumber(oleItem.getCopyNumber());
674
675 if (oleItem.getItemStatus() != null) {
676 oleDeliverRequestBo.setItemStatus(oleItem.getItemStatus().getCodeValue());
677 }
678 oleDeliverRequestBo.setShelvingLocation(oleItemSearch.getShelvingLocation());
679 }
680
681 if (oleDeliverRequestBo.getRequestTypeId().equals("8")) {
682 oleDeliverRequestBo.setInTransitCheckInNote(oleItem.getCheckinNote());
683 }
684 } catch (Exception e) {
685 LOG.error(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVAL_LOC), e);
686 }
687 }
688 oleDeliverRequestBo.setOleItemSearch(oleItemSearch);
689 oleDeliverRequestBo = processItemType(oleDeliverRequestBo);
690 return oleDeliverRequestBo;
691 }
692
693
694
695
696
697
698
699 public OleDeliverRequestBo processItemType(OleDeliverRequestBo oleDeliverRequestBo) {
700 LOG.debug("Inside process Item Type");
701 Map<String, String> itemMap = new HashMap<String, String>();
702 itemMap = new HashMap<String, String>();
703 itemMap.put(OLEConstants.OleDeliverRequest.ITEM_TYPE_CODE, oleDeliverRequestBo.getItemType());
704 List<OleInstanceItemType> oleInstanceItemTypeList = (List<OleInstanceItemType>) getBusinessObjectService().findMatching(OleInstanceItemType.class, itemMap);
705 if (oleInstanceItemTypeList != null && oleInstanceItemTypeList.size() > 0) {
706 OleInstanceItemType oleInstanceItemType = oleInstanceItemTypeList.get(0);
707 oleDeliverRequestBo.setItemTypeName(oleInstanceItemType.getInstanceItemTypeName());
708 }
709
710 return oleDeliverRequestBo;
711 }
712
713
714
715
716
717
718
719 private String getShelvingLocation(Location oleLocation) {
720
721 LOG.debug("Inside getShelvingLocation");
722 String locationLevelName = "";
723 if (oleLocation != null) {
724 LocationLevel locationLevel =
725 oleLocation.getLocationLevel();
726 if (locationLevel != null) {
727 while (locationLevel.getLocationLevel() != null && !locationLevel.getLevel().equalsIgnoreCase(OLEConstants.OleDeliverRequest.SHELVING)) {
728 locationLevel = locationLevel.getLocationLevel();
729 }
730 locationLevelName = locationLevel.getName();
731 }
732 }
733 return locationLevelName;
734 }
735
736
737
738
739
740
741
742
743 public boolean canRaiseRequest(OleDeliverRequestBo oleDeliverRequestBo) {
744 LOG.debug("Inside canRaiseRequest");
745 boolean canRaiseRequest = true;
746
747 if (isItemAvailable(oleDeliverRequestBo)) {
748 canRaiseRequest = false;
749
750
751 }
752 return canRaiseRequest;
753 }
754
755
756
757
758
759
760
761
762 public OleDeliverRequestBo updateLoanDocument(OleDeliverRequestBo oleDeliverRequestBo) {
763 LOG.debug("Inside updateLoanDocument");
764 Map<String, String> loanMap = new HashMap<String, String>();
765 loanMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
766 List<OleLoanDocument> oleLoanDocumentList = (List<OleLoanDocument>) getBusinessObjectService().findMatching(OleLoanDocument.class, loanMap);
767 if (oleLoanDocumentList != null && oleLoanDocumentList.size() > 0 && oleLoanDocumentList.get(0) != null && oleLoanDocumentList.get(0).getOleRequestId() == null) {
768 if (oleLoanDocumentList.get(0).getLoanId() != null) {
769 oleLoanDocumentList.get(0).setOleRequestId(oleDeliverRequestBo.getRequestId());
770 oleDeliverRequestBo.setLoanTransactionRecordNumber(oleLoanDocumentList.get(0).getLoanId());
771 }
772 businessObjectService.save(oleLoanDocumentList.get(0));
773
774 }
775 return oleDeliverRequestBo;
776 }
777
778
779
780
781
782
783
784 public void deleteRequest(String requestId, String itemUUID, String operatorId, String loanTransactionNumber) {
785 LOG.debug("Inside deleteRequest");
786 Map<String, String> requestMap = new HashMap<String, String>();
787 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_ID, requestId);
788 createRequestHistoryRecord(requestId, operatorId, loanTransactionNumber);
789 Map<String, String> itemMap = new HashMap<String, String>();
790 itemMap.put(OLEConstants.ITEM_UUID, itemUUID);
791 List<OleDeliverRequestBo> oleDeliverRequestDocumentsList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class, itemMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
792 getBusinessObjectService().delete(oleDeliverRequestDocumentsList);
793 int queuePosition = 1;
794 for (int i = 0; i < oleDeliverRequestDocumentsList.size(); i++) {
795 oleDeliverRequestDocumentsList.get(i).setBorrowerQueuePosition(queuePosition);
796 queuePosition = queuePosition + 1;
797 }
798 getBusinessObjectService().save(oleDeliverRequestDocumentsList);
799
800 }
801
802
803
804
805
806
807
808 public OleItemSearch getItemDetails(String itemUUID) {
809 LOG.debug("Inside getItemDetails");
810 OleItemSearch oleItemSearch = getItemDetailsForPatron(itemUUID);
811 try {
812
813 String itemXml = getLoanProcessor().getItemXML(itemUUID);
814 Item oleItem = getLoanProcessor().getItemPojo(itemXml);
815 if (oleItem != null && oleItem.getItemType() != null) {
816 oleItemSearch.setItemType(processItemType(oleItem.getItemType().getCodeValue()));
817 }
818 oleItemSearch.setCopyNumber(oleItem.getCopyNumber());
819 if (oleItem.getItemStatus() != null) {
820 oleItemSearch.setItemStatus(oleItem.getItemStatus().getCodeValue());
821 }
822 oleItemSearch.setShelvingLocation(getShelvingLocation(oleItem.getLocation()));
823 oleItemSearch.setVolumeNumber(oleItem.getVolumeNumber());
824 } catch (Exception e) {
825 LOG.error("Not able to retrieve information from the docstore for the Item Barcode : " + itemUUID, e);
826 }
827 return oleItemSearch;
828 }
829
830
831
832
833
834
835
836 public OleItemSearch getItemDetailsForPatron(String itemUUID) {
837 LOG.debug("Inside getItemDetailsForPatron");
838 OleItemSearch oleItemSearch;
839 try {
840
841 Map<String, String> itemMap = new HashMap<String, String>();
842
843 OleItemSearch itemSearchList = getDocstoreUtil().getOleItemSearchList(itemUUID);
844 if (itemSearchList != null) {
845 return oleItemSearch = itemSearchList;
846 }
847 } catch (NullPointerException e) {
848 LOG.error("No item details available for the Item Barcode : " + itemUUID, e);
849 }
850
851 return new OleItemSearch();
852
853 }
854
855
856
857
858
859
860
861 public OleDeliverRequestBo reOrderQueuePosition(OleDeliverRequestBo oleDeliverRequestBo) {
862 LOG.debug("Inside reOrderQueuePosition");
863 List<OleDeliverRequestBo> existingRequest = new ArrayList<OleDeliverRequestBo>();
864 String queue = getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.REQUEST_QUEUE);
865 List<String> orderQueue = new ArrayList<String>();
866 String[] queueArray = queue.split(";");
867 for (int i = 0; i < queueArray.length; i++) {
868 orderQueue.add(queueArray[i]);
869 }
870 List<OleDeliverRequestBo> finalList = new ArrayList<OleDeliverRequestBo>();
871 Map<String, String> recallRequestMap = new HashMap<String, String>();
872 recallRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
873 recallRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "1");
874 Map<String, String> recallHoldRequestMap = new HashMap<String, String>();
875 recallHoldRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
876 recallHoldRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "2");
877 Map<String, String> holdRequestMap = new HashMap<String, String>();
878 holdRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
879 holdRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "3");
880 Map<String, String> holdHoldRequestMap = new HashMap<String, String>();
881 holdHoldRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
882 holdHoldRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "4");
883 Map<String, String> pageRequestMap = new HashMap<String, String>();
884 pageRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
885 pageRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "5");
886 Map<String, String> pageHoldRequestMap = new HashMap<String, String>();
887 pageHoldRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
888 pageHoldRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "6");
889 Map<String, String> copyRequestMap = new HashMap<String, String>();
890 copyRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
891 copyRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "7");
892 Map<String, String> inTransitRequestMap = new HashMap<String, String>();
893 inTransitRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
894 inTransitRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "8");
895 Map<String, String> asrRequestMap = new HashMap<String, String>();
896 asrRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
897 asrRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "9");
898 List<OleDeliverRequestBo> recallList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class, recallRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
899 List<OleDeliverRequestBo> recallHoldList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class, recallHoldRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
900 List<OleDeliverRequestBo> holdList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class, holdRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
901 List<OleDeliverRequestBo> holdHoldList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class, holdHoldRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
902 List<OleDeliverRequestBo> pageList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class, pageRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
903 List<OleDeliverRequestBo> pageHoldList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class, pageHoldRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
904 List<OleDeliverRequestBo> copyList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class, copyRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
905 List<OleDeliverRequestBo> inTransitList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class, inTransitRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
906 List<OleDeliverRequestBo> asrList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatchingOrderBy(OleDeliverRequestBo.class, asrRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
907 if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.RECALL_DELIVERY)) {
908 recallList.add(oleDeliverRequestBo);
909 } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.HOLD_DELIVERY)) {
910 holdList.add(oleDeliverRequestBo);
911 } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.PAGE_DELIVERY)) {
912 pageList.add(oleDeliverRequestBo);
913 } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.COPY)) {
914 copyList.add(oleDeliverRequestBo);
915 } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.INTRANSIT)) {
916 inTransitList.add(oleDeliverRequestBo);
917 } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.RECALL_HOLD)) {
918 recallHoldList.add(oleDeliverRequestBo);
919 } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.HOLD_HOLD)) {
920 holdHoldList.add(oleDeliverRequestBo);
921 } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.PAGE_HOLD)) {
922 pageHoldList.add(oleDeliverRequestBo);
923 }else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.ASR_REQUEST)) {
924 asrList.add(oleDeliverRequestBo);
925 }
926 OleDeliverRequestBo oleDeliverRequestBo1;
927 for (int i = 0; i < orderQueue.size(); i++) {
928 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.RECALL) && recallList.size() > 0) {
929 for (int x = 0; x < recallList.size(); x++) {
930 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(recallList.get(x));
931 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
932 this.queuePosition = this.queuePosition + 1;
933 finalList.add(oleDeliverRequestBo1);
934
935 }
936 }
937 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.HOLD) && holdList.size() > 0) {
938 for (int x = 0; x < holdList.size(); x++) {
939 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(holdList.get(x));
940 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
941 this.queuePosition = this.queuePosition + 1;
942 finalList.add(oleDeliverRequestBo1);
943
944 }
945 }
946 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.PAGE) && pageList.size() > 0) {
947 for (int x = 0; x < pageList.size(); x++) {
948 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(pageList.get(x));
949 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
950 this.queuePosition = this.queuePosition + 1;
951 finalList.add(oleDeliverRequestBo1);
952 }
953 }
954 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.RECALL) && recallHoldList.size() > 0) {
955 for (int x = 0; x < recallHoldList.size(); x++) {
956 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(recallHoldList.get(x));
957 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
958 this.queuePosition = this.queuePosition + 1;
959 finalList.add(oleDeliverRequestBo1);
960
961 }
962 }
963 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.HOLD) && holdHoldList.size() > 0) {
964 for (int x = 0; x < holdHoldList.size(); x++) {
965 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(holdHoldList.get(x));
966 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
967 this.queuePosition = this.queuePosition + 1;
968 finalList.add(oleDeliverRequestBo1);
969
970 }
971 }
972 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.PAGE) && pageHoldList.size() > 0) {
973 for (int x = 0; x < pageHoldList.size(); x++) {
974 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(pageHoldList.get(x));
975 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
976 this.queuePosition = this.queuePosition + 1;
977 finalList.add(oleDeliverRequestBo1);
978 }
979 }
980 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.COPY) && copyList.size() > 0) {
981 for (int x = 0; x < copyList.size(); x++) {
982 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(copyList.get(x));
983 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
984 this.queuePosition = this.queuePosition + 1;
985 finalList.add(oleDeliverRequestBo1);
986
987 }
988 }
989 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.INTRANSIT) && inTransitList.size() > 0) {
990 for (int x = 0; x < inTransitList.size(); x++) {
991 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(inTransitList.get(x));
992 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
993 this.queuePosition = this.queuePosition + 1;
994 finalList.add(oleDeliverRequestBo1);
995
996 }
997 }
998 if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.ASR_REQUEST) && asrList.size() > 0) {
999 for (int x = 0; x < asrList.size(); x++) {
1000 oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(asrList.get(x));
1001 oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
1002 this.queuePosition = this.queuePosition + 1;
1003 finalList.add(oleDeliverRequestBo1);
1004
1005 }
1006 }
1007 }
1008 for (int i = 0; i < finalList.size(); i++) {
1009 if (finalList.get(i).getRequestId() == null) {
1010 oleDeliverRequestBo.setBorrowerQueuePosition(finalList.get(i).getBorrowerQueuePosition());
1011 finalList.remove(finalList.get(i));
1012 }
1013 }
1014 getBusinessObjectService().save(finalList);
1015 this.queuePosition = 0;
1016 oleDeliverRequestBo.setRequestId(KRADServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber("OLE_DLVR_RQST_S").toString());
1017 return oleDeliverRequestBo;
1018 }
1019
1020
1021
1022
1023
1024
1025
1026 public boolean isItemAvailbleInDocstore(OleDeliverRequestBo oleDeliverRequestBo) {
1027 LOG.debug("Inside isItemAvailbleInDocstore");
1028 boolean available = false;
1029 Map<String, String> itemMap = new HashMap<String, String>();
1030 try {
1031 String itemUUID = "";
1032 org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
1033 org.kuali.ole.docstore.common.search.SearchParams search_Params = new org.kuali.ole.docstore.common.search.SearchParams();
1034 SearchResponse searchResponse = null;
1035 search_Params.getSearchConditions().add(search_Params.buildSearchCondition("", search_Params.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), item.ITEM_BARCODE, oleDeliverRequestBo.getItemId()), ""));
1036
1037
1038 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), "id"));
1039 ;
1040
1041
1042
1043
1044
1045 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(search_Params);
1046 for (SearchResult searchResult : searchResponse.getSearchResults()) {
1047 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
1048 String fieldName = searchResultField.getFieldName();
1049 String fieldValue = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
1050
1051 if (fieldName.equalsIgnoreCase("id") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
1052 itemUUID = fieldValue;
1053 }
1054
1055 }
1056 }
1057
1058
1059 oleDeliverRequestBo.setItemUuid(itemUUID);
1060 } catch (Exception e) {
1061 LOG.error("Exception", e);
1062
1063 }
1064
1065 OleItemSearch itemSearchList = getDocstoreUtil().getOleItemSearchList(oleDeliverRequestBo.getItemUuid());
1066 if (itemSearchList != null) {
1067 oleDeliverRequestBo.setTitle(itemSearchList.getTitle());
1068 oleDeliverRequestBo.setAuthor(itemSearchList.getAuthor());
1069 oleDeliverRequestBo.setCallNumber(itemSearchList.getCallNumber());
1070 oleDeliverRequestBo.setItemType(itemSearchList.getItemType());
1071 }
1072 try {
1073
1074 String itemXml = getLoanProcessor().getItemXML(oleDeliverRequestBo.getItemUuid());
1075 Item oleItem = getLoanProcessor().getItemPojo(itemXml);
1076
1077 oleDeliverRequestBo.setCopyNumber(oleItem.getCopyNumber());
1078 if (oleItem.getItemStatus() != null) {
1079 oleDeliverRequestBo.setItemStatus(oleItem.getItemStatus().getCodeValue());
1080 }
1081 oleDeliverRequestBo.setShelvingLocation(getShelvingLocation(oleItem.getLocation()));
1082 available = true;
1083 } catch (Exception e) {
1084 LOG.error(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVAL_LOC), e);
1085 }
1086 return available;
1087 }
1088
1089 public OleDeliverRequestBo populateItemDetailsToRequest(OleDeliverRequestBo oleDeliverRequestBo, OleItemSearch oleItemSearch) {
1090 LOG.debug("Inside populateItemDetailsToRequest");
1091 if (oleDeliverRequestBo != null && oleItemSearch != null) {
1092 oleDeliverRequestBo.setAuthor(oleItemSearch.getAuthor());
1093 oleDeliverRequestBo.setTitle(oleItemSearch.getTitle());
1094 oleDeliverRequestBo.setCallNumber(oleItemSearch.getCallNumber());
1095 oleDeliverRequestBo.setCopyNumber(oleItemSearch.getCopyNumber());
1096 oleDeliverRequestBo.setItemType(oleItemSearch.getItemType());
1097 oleDeliverRequestBo.setItemStatus(oleItemSearch.getItemStatus());
1098 oleItemSearch.setShelvingLocation(oleDeliverRequestBo.getShelvingLocation());
1099 }
1100 return oleDeliverRequestBo;
1101 }
1102
1103
1104 public OleDeliverRequestBo generateRecallNotice(OleDeliverRequestBo oleDeliverRequestBo) throws Exception {
1105 Map<String, String> loanMap = new HashMap<String, String>();
1106 loanMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
1107 List<OleLoanDocument> loanDocuments = (List<OleLoanDocument>) getBusinessObjectService().findMatching(OleLoanDocument.class, loanMap);
1108 OleLoanDocument oleLoanDocument = loanDocuments.get(0);
1109 Map<String, String> patronMap = new HashMap<String, String>();
1110 patronMap.put(OLEConstants.OleDeliverRequest.PATRON_ID, oleLoanDocument.getPatronId());
1111 List<OlePatronDocument> patronDocumentList = (List<OlePatronDocument>) getBusinessObjectService().findMatching(OlePatronDocument.class, patronMap);
1112 OleNoticeBo oleNoticeBo = new OleNoticeBo();
1113 Item item;
1114 if (patronDocumentList.size() > 0) {
1115 OlePatronDocument olePatronDocument = patronDocumentList.get(0);
1116 EntityTypeContactInfoBo entityTypeContactInfoBo = olePatronDocument.getEntity().getEntityTypeContactInfos().get(0);
1117 oleNoticeBo.setPatronName(olePatronDocument.getEntity().getNames().get(0).getFirstName() + " " +olePatronDocument.getEntity().getNames().get(0).getLastName());
1118 oleNoticeBo.setPatronAddress(getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getPatronPreferredAddress(entityTypeContactInfoBo) : "");
1119 oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : "");
1120 oleNoticeBo.setPatronPhoneNumber(getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
1121 }
1122 oleNoticeBo.setAuthor(oleDeliverRequestBo.getAuthor() != null ? oleDeliverRequestBo.getAuthor() : "");
1123 oleNoticeBo.setCirculationDeskAddress("");
1124 oleNoticeBo.setCirculationDeskName("");
1125 oleNoticeBo.setCirculationDeskEmailAddress("");
1126 oleNoticeBo.setCirculationDeskPhoneNumber("");
1127 oleNoticeBo.setItemCallNumber(oleDeliverRequestBo.getCallNumber() != null ? oleDeliverRequestBo.getCallNumber() : "");
1128 oleNoticeBo.setItemShelvingLocation(oleDeliverRequestBo.getShelvingLocation() != null ? oleDeliverRequestBo.getShelvingLocation() : "");
1129 oleNoticeBo.setItemId(oleDeliverRequestBo.getItemId() != null ? oleDeliverRequestBo.getItemId() : "");
1130 oleNoticeBo.setTitle(oleDeliverRequestBo.getTitle() != null ? oleDeliverRequestBo.getTitle() : "");
1131 oleNoticeBo.setOleItem(getItem(oleDeliverRequestBo.getItemUuid()));
1132 oleNoticeBo.setOlePatron(oleDeliverRequestBo.getOlePatron());
1133 oleNoticeBo.setVolumeNumber(oleNoticeBo.getOleItem().getVolumeNumber() != null ? oleNoticeBo.getOleItem().getVolumeNumber() : "");
1134 oleNoticeBo.setOriginalDueDate(oleLoanDocument.getLoanDueDate());
1135 oleNoticeBo.setNewDueDate(oleDeliverRequestBo.getNewDueDate());
1136 oleNoticeBo.setOriginalDueDate(oleDeliverRequestBo.getOriginalDueDate());
1137
1138
1139
1140
1141
1142 oleNoticeBo.setNoticeName(OLEConstants.NOTICE_RECALL);
1143 String noticeContent = getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.RECALL_BODY);
1144 oleNoticeBo.setNoticeSpecificContent(noticeContent);
1145
1146 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
1147 List<OleNoticeBo> oleNoticeBos = new ArrayList<OleNoticeBo>();
1148 String noticeType = getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.RECALL_NOTICE_TYPE);
1149 oleNoticeBos.add(oleNoticeBo);
1150 if (noticeType.equalsIgnoreCase(OLEConstants.EMAIL)) {
1151 String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
1152 if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
1153 fromAddress = OLEConstants.KUALI_MAIL;
1154 }
1155 if (oleNoticeBo.getPatronEmailAddress() != null && !oleNoticeBo.getPatronEmailAddress().isEmpty()) {
1156 List list = oleDeliverBatchService.getNoticeForPatron(oleNoticeBos);
1157 String content = list.toString();
1158 content = content.replace('[', ' ');
1159 content = content.replace(']', ' ');
1160 if (!content.trim().equals("")) {
1161 OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
1162 oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(content), true);
1163 } else {
1164 for (OleNoticeBo oleNoticeBo1 : oleNoticeBos) {
1165 if (LOG.isDebugEnabled()) {
1166 LOG.debug("Notice Type :" + oleNoticeBo1.getNoticeName() + " " + "Item Barcode : " + oleNoticeBo1.getItemId() + " " + "Patron Name :" + oleNoticeBo1.getPatronName());
1167 }
1168 }
1169 }
1170 if (LOG.isDebugEnabled()) {
1171 LOG.debug("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
1172 }
1173
1174
1175
1176
1177 }
1178 } else if (noticeType.equalsIgnoreCase(OLEConstants.SMS)) {
1179
1180 Map map = oleDeliverBatchService.getSMSForPatron(oleNoticeBos);
1181 HashMap sms = (HashMap) map.get(OLEConstants.OleDeliverRequest.RECALL);
1182 Iterator it = sms.entrySet().iterator();
1183 while (it.hasNext()) {
1184 Map.Entry pairs = (Map.Entry) it.next();
1185 String patronPhoneNumber = oleNoticeBo.getPatronPhoneNumber();
1186 OleSms oleSms = new OleSms();
1187 oleSms.sendSms("", patronPhoneNumber, (String) pairs.getValue());
1188 }
1189
1190 }
1191 if (noticeType.equalsIgnoreCase(OLEConstants.MAIL) || noticeType.equalsIgnoreCase(OLEConstants.EMAIL)) {
1192
1193 oleDeliverBatchService.getPdfNoticeForPatron(oleNoticeBos);
1194 if (LOG.isDebugEnabled()) {
1195 LOG.debug("Recall Notice Pdf generated for item Id" + oleNoticeBo.getItemId());
1196 }
1197 }
1198 oleDeliverRequestBo = (OleDeliverRequestBo) ObjectUtils.deepCopy(oleDeliverRequestBo);
1199 oleDeliverRequestBo.setRecallNoticeSentDate(new java.sql.Date(System.currentTimeMillis()));
1200 return oleDeliverRequestBo;
1201 }
1202
1203
1204 public void generateOnHoldNotice() throws Exception {
1205
1206 List<OleDeliverRequestBo> finalDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>();
1207 Map<String, String> onHoldNoticeMap = new HashMap<String, String>();
1208 onHoldNoticeMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "2");
1209 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, onHoldNoticeMap);
1210 Map<String, String> onHoldHoldNoticeMap = new HashMap<String, String>();
1211 onHoldHoldNoticeMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "4");
1212 List<OleDeliverRequestBo> oleDeliverRequestBoList1 = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, onHoldHoldNoticeMap);
1213 oleDeliverRequestBoList.addAll(oleDeliverRequestBoList1);
1214 OleDeliverRequestBo oleDeliverRequestBo;
1215 List<OleNoticeBo> noticesList = new ArrayList<OleNoticeBo>();
1216 EntityTypeContactInfoBo entityTypeContactInfoBo;
1217 OleNoticeBo oleNoticeBo;
1218 Item item;
1219 for (int i = 0; i < oleDeliverRequestBoList.size(); i++) {
1220 if (getDocstoreUtil().isItemAvailableInDocStore(oleDeliverRequestBoList.get(i))) {
1221 item = oleDeliverRequestBoList.get(i).getOleItem();
1222 OlePatronDocument olePatronDocument = oleDeliverRequestBoList.get(i).getOlePatron();
1223 if (item != null && item.getItemStatus() != null && item.getItemStatus().getCodeValue() != null && item.getItemStatus().getCodeValue().equals(OLEConstants.ITEM_STATUS_ON_HOLD) && oleDeliverRequestBoList.get(i).getOnHoldNoticeSentDate() == null) {
1224 entityTypeContactInfoBo = oleDeliverRequestBoList.get(i).getOlePatron().getEntity().getEntityTypeContactInfos().get(0);
1225 oleNoticeBo = new OleNoticeBo();
1226 oleNoticeBo.setAuthor(oleDeliverRequestBoList.get(i).getAuthor());
1227 oleNoticeBo.setCirculationDeskAddress("");
1228 oleNoticeBo.setCirculationDeskName("");
1229 oleNoticeBo.setCirculationDeskEmailAddress("");
1230 oleNoticeBo.setCirculationDeskPhoneNumber("");
1231 oleNoticeBo.setPatronName(oleDeliverRequestBoList.get(i).getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + oleDeliverRequestBoList.get(i).getOlePatron().getEntity().getNames().get(0).getLastName());
1232 oleNoticeBo.setPatronAddress(getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getPatronPreferredAddress(entityTypeContactInfoBo) : "");
1233 oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : "");
1234 oleNoticeBo.setPatronPhoneNumber(getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
1235 oleNoticeBo.setItemCallNumber(oleDeliverRequestBoList.get(i).getCallNumber() != null ? oleDeliverRequestBoList.get(i).getCallNumber() : "");
1236 oleNoticeBo.setItemShelvingLocation(oleDeliverRequestBoList.get(i).getShelvingLocation() != null ? oleDeliverRequestBoList.get(i).getShelvingLocation() : "");
1237 oleNoticeBo.setItemId(oleDeliverRequestBoList.get(i).getItemId() != null ? oleDeliverRequestBoList.get(i).getItemId() : "");
1238 oleNoticeBo.setTitle(oleDeliverRequestBoList.get(i).getTitle() != null ? oleDeliverRequestBoList.get(i).getTitle() : "");
1239 oleNoticeBo.setOleItem(item);
1240 oleNoticeBo.setOlePatron(oleDeliverRequestBoList.get(i).getOlePatron());
1241 oleNoticeBo.setVolumeNumber(item.getVolumeNumber() != null ? item.getVolumeNumber() : "");
1242 oleNoticeBo.setNewDueDate(new Date());
1243 oleNoticeBo.setOriginalDueDate(new Date());
1244 oleNoticeBo.setNoticeName(OLEConstants.NOTICE_ONHOLD);
1245 oleNoticeBo.setCirculationDeskName(oleDeliverRequestBoList.get(i).getOlePickUpLocation().getCirculationDeskPublicName());
1246 String circulationDeskId = oleDeliverRequestBoList.get(i).getPickUpLocationId();
1247 int noDays = 0;
1248 Map<String, String> mapCirculationDesk = new HashMap<String, String>();
1249 mapCirculationDesk.put(OLEConstants.OleCirculationDesk.OLE_CIRCULATION_DESK_ID, circulationDeskId);
1250 List<OleCirculationDesk> oleCirculationDesks = (List<OleCirculationDesk>) KRADServiceLocator.getBusinessObjectService().findMatching(OleCirculationDesk.class, mapCirculationDesk);
1251 if (oleCirculationDesks.size() > 0) {
1252 OleCirculationDesk oleCirculationDesk = oleCirculationDesks.get(0);
1253 noDays = Integer.parseInt(oleCirculationDesk.getOnHoldDays());
1254 }
1255 Calendar calendar = Calendar.getInstance();
1256 calendar.add(Calendar.DATE, noDays);
1257 Date date = calendar.getTime();
1258 oleNoticeBo.setExpiredOnHoldDate(date);
1259 String maxNumOfDays = oleDeliverRequestBoList.get(i).getOlePickUpLocation().getOnHoldDays() != null ? oleDeliverRequestBoList.get(i).getOlePickUpLocation().getOnHoldDays() : getLoanProcessor().getParameter(OLEConstants.MAX_NO_OF_DAYS_ON_HOLD);
1260 Integer maxNumberOfDaysOnHold = new Integer(maxNumOfDays);
1261 oleNoticeBo.setOnHoldDueDate(dateAdd(oleDeliverRequestBoList.get(i).getCreateDate(), maxNumberOfDaysOnHold));
1262 String noticeContent = getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.ONHOLD_BODY);
1263 oleNoticeBo.setNoticeSpecificContent(noticeContent);
1264 noticesList.add(oleNoticeBo);
1265 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
1266 String agendaName = OLEConstants.BATCH_PROGRAM_AGENDA;
1267 HashMap<String, Object> termValues = new HashMap<String, Object>();
1268 OleCirculationDesk oleCirculationDesk = oleDeliverRequestBoList.get(i).getOlePickUpLocation();
1269 String deskLocation = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskCode() : "";
1270 String deskLocationName = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskPublicName() : "";
1271 termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode());
1272 termValues.put(OLEConstants.DESK_LOCATION, deskLocation);
1273 termValues.put(OLEConstants.NOTICE, OLEConstants.NOTICE_ONHOLD);
1274 if (LOG.isDebugEnabled()) {
1275 LOG.debug("termValues.toString()" + termValues.toString());
1276 }
1277 EngineResults engineResults = loanProcessor.getEngineResults(agendaName, termValues);
1278 String noticeType = (String) engineResults.getAttribute(OLEConstants.NOTICE_TYPE);
1279 if (LOG.isDebugEnabled()) {
1280 LOG.debug("**************" + noticeType);
1281 }
1282 noticeType = noticeType != null ? noticeType : getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.ONHOLD_NOTICE_TYPE);
1283 if (noticeType != null && (noticeType.equalsIgnoreCase(OLEConstants.EMAIL) || noticeType.equalsIgnoreCase(OLEConstants.MAIL))) {
1284 if (LOG.isDebugEnabled()) {
1285 LOG.debug("noticesList.size()" + noticesList.size());
1286 }
1287 oleDeliverBatchService.getPdfNoticeForPatron(noticesList);
1288 if (LOG.isDebugEnabled()) {
1289 LOG.debug("OnHold Notice Pdf generated for item Id" + oleNoticeBo.getItemId());
1290 }
1291 }
1292 if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.EMAIL)) {
1293 String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
1294 if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
1295 fromAddress = OLEConstants.KUALI_MAIL;
1296 }
1297 if (oleNoticeBo.getPatronEmailAddress() != null && !oleNoticeBo.getPatronEmailAddress().isEmpty()) {
1298 List list = oleDeliverBatchService.getNoticeForPatron(noticesList);
1299 String content = list.toString();
1300 content = content.replace('[', ' ');
1301 content = content.replace(']', ' ');
1302 if (!content.trim().equals("")) {
1303 OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
1304 oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(content), true);
1305 } else {
1306 for (OleNoticeBo oleNoticeBo1 : noticesList) {
1307 if (LOG.isDebugEnabled()) {
1308 LOG.debug("Notice Type :" + oleNoticeBo1.getNoticeName() + " " + "Item Barcode : " + oleNoticeBo1.getItemId() + " " + "Patron Name :" + oleNoticeBo1.getPatronName());
1309 }
1310 }
1311 }
1312 if (LOG.isDebugEnabled()) {
1313 LOG.debug("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
1314 }
1315
1316
1317
1318 }
1319 } else if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.SMS)) {
1320 Map map = oleDeliverBatchService.getSMSForPatron(noticesList);
1321 HashMap sms = (HashMap) map.get(OLEConstants.NOTICE_ONHOLD);
1322 Iterator it = sms.entrySet().iterator();
1323 while (it.hasNext()) {
1324 Map.Entry pairs = (Map.Entry) it.next();
1325 String patronPhoneNumber = oleNoticeBo.getPatronPhoneNumber();
1326 OleSms oleSms = new OleSms();
1327 oleSms.sendSms("", patronPhoneNumber, (String) pairs.getValue());
1328 }
1329 }
1330
1331 oleDeliverRequestBoList.get(i).setOleItem(null);
1332 oleDeliverRequestBo = (OleDeliverRequestBo) ObjectUtils.deepCopy(oleDeliverRequestBoList.get(i));
1333 oleDeliverRequestBo.setOnHoldNoticeSentDate(new java.sql.Date(System.currentTimeMillis()));
1334 finalDeliverRequestBoList.add(oleDeliverRequestBo);
1335 }
1336 }
1337 getBusinessObjectService().save(finalDeliverRequestBoList);
1338 }
1339 }
1340
1341 public void generateRequestExpirationNotice() throws Exception {
1342 List<OleDeliverRequestBo> oleDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>();
1343 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
1344 oleDeliverRequestBoList = (List<OleDeliverRequestBo>) getBusinessObjectService().findAll(OleDeliverRequestBo.class);
1345 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OleDeliverRequest.DATE_FORMAT);
1346 EntityTypeContactInfoBo entityTypeContactInfoBo;
1347 List<OleNoticeBo> noticesList = new ArrayList<OleNoticeBo>();
1348 Item item;
1349 String noticeType = null;
1350 OleNoticeBo oleNoticeBo = new OleNoticeBo();
1351 if (oleDeliverRequestBoList.size() > 0) {
1352 for (int i = 0; i < oleDeliverRequestBoList.size(); i++) {
1353 if (getDocstoreUtil().isItemAvailableInDocStore(oleDeliverRequestBoList.get(i))) {
1354
1355 item = oleDeliverRequestBoList.get(i).getOleItem();
1356 if (LOG.isDebugEnabled()) {
1357 LOG.debug("Expiration Date :" + oleDeliverRequestBoList.get(i).getRequestExpiryDate());
1358 }
1359 if (oleDeliverRequestBoList.get(i).getOlePatron().isCourtesyNotice() && (fmt.format(oleDeliverRequestBoList.get(i).getRequestExpiryDate())).compareTo(fmt.format(new Date(System.currentTimeMillis()))) <= 0) {
1360 if (LOG.isDebugEnabled()) {
1361 LOG.debug("Inside Expiration Date :" + oleDeliverRequestBoList.get(i).getRequestExpiryDate());
1362 }
1363 entityTypeContactInfoBo = oleDeliverRequestBoList.get(i).getOlePatron().getEntity().getEntityTypeContactInfos().get(0);
1364 oleNoticeBo = new OleNoticeBo();
1365 oleNoticeBo.setAuthor(oleDeliverRequestBoList.get(i).getAuthor());
1366 oleNoticeBo.setCirculationDeskAddress("");
1367 oleNoticeBo.setCirculationDeskName("");
1368 oleNoticeBo.setCirculationDeskEmailAddress("");
1369 oleNoticeBo.setCirculationDeskPhoneNumber("");
1370 oleNoticeBo.setPatronName(oleDeliverRequestBoList.get(i).getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + oleDeliverRequestBoList.get(i).getOlePatron().getEntity().getNames().get(0).getLastName());
1371 oleNoticeBo.setPatronAddress(getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getPatronPreferredAddress(entityTypeContactInfoBo) : "");
1372 oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : "");
1373 oleNoticeBo.setPatronPhoneNumber(getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
1374 oleNoticeBo.setItemCallNumber(oleDeliverRequestBoList.get(i).getCallNumber() != null ? oleDeliverRequestBoList.get(i).getCallNumber() : "");
1375 oleNoticeBo.setItemShelvingLocation(oleDeliverRequestBoList.get(i).getShelvingLocation() != null ? oleDeliverRequestBoList.get(i).getShelvingLocation() : "");
1376 oleNoticeBo.setItemId(oleDeliverRequestBoList.get(i).getItemId() != null ? oleDeliverRequestBoList.get(i).getItemId() : "");
1377 oleNoticeBo.setTitle(oleDeliverRequestBoList.get(i).getTitle() != null ? oleDeliverRequestBoList.get(i).getTitle() : "");
1378 oleNoticeBo.setOleItem(item);
1379 oleNoticeBo.setOlePatron(oleDeliverRequestBoList.get(i).getOlePatron());
1380 oleNoticeBo.setVolumeNumber(item.getVolumeNumber() != null ? item.getVolumeNumber() : "");
1381 oleNoticeBo.setNewDueDate(new Date());
1382 oleNoticeBo.setOriginalDueDate(new Date());
1383 oleNoticeBo.setNoticeName(OLEConstants.OleDeliverRequest.EXPIRED_REQUEST);
1384 String noticeContent = getLoanProcessor().getParameter(OLEParameterConstants.EXPIRED_BODY);
1385 oleNoticeBo.setNoticeSpecificContent(noticeContent);
1386 noticesList.add(oleNoticeBo);
1387 String agendaName = OLEConstants.BATCH_PROGRAM_AGENDA;
1388 HashMap<String, Object> termValues = new HashMap<String, Object>();
1389 OleCirculationDesk oleCirculationDesk = oleDeliverRequestBoList.get(i).getOlePickUpLocation();
1390 OlePatronDocument olePatronDocument = oleDeliverRequestBoList.get(i).getOlePatron();
1391 String deskLocation = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskCode() : "";
1392 String deskLocationName = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskPublicName() : "";
1393 termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode());
1394 termValues.put(OLEConstants.DESK_LOCATION, deskLocation);
1395 termValues.put(OLEConstants.NOTICE, OLEConstants.OleDeliverRequest.EXPIRED_REQUEST);
1396 if (LOG.isDebugEnabled()) {
1397 LOG.debug("termValues.toString()" + termValues.toString());
1398 }
1399 EngineResults engineResults = getLoanProcessor().getEngineResults(agendaName, termValues);
1400 noticeType = (String) engineResults.getAttribute(OLEConstants.NOTICE_TYPE);
1401 if (LOG.isDebugEnabled()) {
1402 LOG.debug("**************" + noticeType);
1403 }
1404 noticeType = noticeType != null ? noticeType : getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.RQST_EXPR_NOTICE_TYPE);
1405 if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.SMS)) {
1406
1407 Map map = oleDeliverBatchService.getSMSForPatron(noticesList);
1408 HashMap sms = (HashMap) map.get(OLEConstants.OleDeliverRequest.EXPIRED_REQUEST);
1409 Iterator it = sms.entrySet().iterator();
1410 while (it.hasNext()) {
1411 Map.Entry pairs = (Map.Entry) it.next();
1412
1413 String patronPhoneNumber = oleNoticeBo.getPatronPhoneNumber();
1414 OleSms oleSms = new OleSms();
1415 oleSms.sendSms("", patronPhoneNumber, (String) pairs.getValue());
1416 }
1417 }
1418 }
1419 }
1420 if (noticeType != null && (noticeType.equalsIgnoreCase(OLEConstants.EMAIL) || noticeType.equalsIgnoreCase(OLEConstants.MAIL))) {
1421 oleDeliverBatchService.getPdfNoticeForPatron(noticesList);
1422 LOG.debug("Request Expiration Notice Pdf generated for item Id");
1423 }
1424 if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.EMAIL)) {
1425 String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
1426 if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
1427 fromAddress = OLEConstants.KUALI_MAIL;
1428 }
1429
1430 List list = (List) oleDeliverBatchService.getNoticeForPatron(noticesList);
1431 String noticeContent = list.toString();
1432 noticeContent = noticeContent.replace('[', ' ');
1433 noticeContent = noticeContent.replace(']', ' ');
1434 if (!noticeContent.trim().equals("")) {
1435 OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
1436 oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(noticeContent), true);
1437 } else {
1438 for (OleNoticeBo oleNoticeBo1 : noticesList) {
1439 if (LOG.isDebugEnabled()) {
1440 LOG.debug("Notice Type :" + oleNoticeBo1.getNoticeName() + " " + "Item Barcode : " + oleNoticeBo1.getItemId() + " " + "Patron Name :" + oleNoticeBo1.getPatronName());
1441 }
1442 }
1443 }
1444 if (LOG.isDebugEnabled()) {
1445 LOG.debug("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
1446 }
1447
1448 }
1449 }
1450 }
1451 }
1452
1453 private java.sql.Date dateAdd(java.sql.Date in, int daysToAdd) {
1454 if (in == null) {
1455 return null;
1456 }
1457 GregorianCalendar cal = new GregorianCalendar();
1458 cal.setTime(in);
1459 cal.add(Calendar.DAY_OF_MONTH, daysToAdd);
1460 return new java.sql.Date(cal.getTime().getTime());
1461 }
1462
1463 public void deletingExpiredRequests() {
1464 LOG.debug("Inside deletingExpiredRequests");
1465 List<OleDeliverRequestBo> oleDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>();
1466 List<OleDeliverRequestBo> newOleDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>();
1467 try {
1468 oleDeliverRequestBoList = (List<OleDeliverRequestBo>) getBusinessObjectService().findAll(OleDeliverRequestBo.class);
1469 getBusinessObjectService().delete(oleDeliverRequestBoList);
1470 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OleDeliverRequest.DATE_FORMAT);
1471 for (int i = 0; i < oleDeliverRequestBoList.size(); i++) {
1472 if ((fmt.format(oleDeliverRequestBoList.get(i).getRequestExpiryDate())).compareTo(fmt.format(new Date(System.currentTimeMillis()))) > 0) {
1473 newOleDeliverRequestBoList.add(oleDeliverRequestBoList.get(i));
1474 }
1475 }
1476 getBusinessObjectService().save(newOleDeliverRequestBoList);
1477 } catch (Exception e) {
1478 getBusinessObjectService().save(oleDeliverRequestBoList);
1479 LOG.error("Exception while deleting expired requests", e);
1480 }
1481 }
1482
1483 private Item getItem(String itemUUID) {
1484 LOG.debug("Inside getItem");
1485 try {
1486
1487 String itemXml = getLoanProcessor().getItemXML(itemUUID);
1488 Item oleItem = getLoanProcessor().getItemPojo(itemXml);
1489 return oleItem;
1490 } catch (Exception e) {
1491 LOG.error("Item not available in doc store", e);
1492 }
1493 return null;
1494 }
1495
1496
1497 private OleNoticeBo setPatronDetailsForNotice(OleNoticeBo oleNoticeBo, OlePatronDocument olePatronDocument) {
1498 LOG.debug("Inside setPatronDetailsForNotice");
1499 if (oleNoticeBo.getAuthor() != null && olePatronDocument.getOlePatronId() != null) {
1500 oleNoticeBo.setPatronName(olePatronDocument.getName().getFirstName());
1501 if (olePatronDocument.getAddresses().size() > 0) {
1502 oleNoticeBo.setPatronAddress(olePatronDocument.getAddresses().get(0).getLine1() + "/n" + olePatronDocument.getAddresses().get(0).getLine2() + "/n" + olePatronDocument.getAddresses().get(0).getCity());
1503 }
1504 oleNoticeBo.setPatronEmailAddress(olePatronDocument.getEmailAddress());
1505 oleNoticeBo.setPatronPhoneNumber(olePatronDocument.getPhoneNumber());
1506 }
1507 return oleNoticeBo;
1508 }
1509
1510
1511 private void createRequestHistoryRecord(String requestId, String OperatorId, String loanTransactionNumber) {
1512 LOG.debug("Inside createRequestHistoryRecord");
1513 Map<String, String> requestMap = new HashMap<String, String>();
1514 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_ID, requestId);
1515 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, requestMap);
1516 if (oleDeliverRequestBoList.size() > 0) {
1517 OleDeliverRequestBo oleDeliverRequestBo = oleDeliverRequestBoList.get(0);
1518 OleDeliverRequestHistoryRecord oleDeliverRequestHistoryRecord = new OleDeliverRequestHistoryRecord();
1519 oleDeliverRequestHistoryRecord.setRequestId(oleDeliverRequestBo.getRequestId());
1520 oleDeliverRequestHistoryRecord.setItemId(oleDeliverRequestBo.getItemId());
1521 oleDeliverRequestHistoryRecord.setArchiveDate(new java.sql.Date(System.currentTimeMillis()));
1522 oleDeliverRequestHistoryRecord.setPickUpLocationCode(oleDeliverRequestBo.getPickUpLocationCode());
1523 oleDeliverRequestHistoryRecord.setOperatorId(OperatorId);
1524 oleDeliverRequestHistoryRecord.setDeliverRequestTypeCode(oleDeliverRequestBo.getRequestTypeCode());
1525 oleDeliverRequestHistoryRecord.setPoLineItemNumber("");
1526 oleDeliverRequestHistoryRecord.setLoanTransactionId(loanTransactionNumber);
1527
1528 getBusinessObjectService().save(oleDeliverRequestHistoryRecord);
1529 }
1530 getBusinessObjectService().delete(oleDeliverRequestBoList);
1531 }
1532
1533 public OleDeliverRequestBo getOleDeliverRequestBo(String itemUUID) {
1534
1535 LOG.debug("Inside getOleDeliverRequestBo method");
1536 Map<String, String> requestMap = new HashMap<String, String>();
1537 requestMap.put(OLEConstants.ITEM_UUID, itemUUID);
1538 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, requestMap);
1539 if (oleDeliverRequestBoList.size() > 0)
1540 return oleDeliverRequestBoList.get(0);
1541 return null;
1542 }
1543
1544 public String getPatronPreferredAddress(EntityTypeContactInfoBo entityTypeContactInfoBo) throws Exception {
1545 LOG.debug("Inside the getPatronPreferredAddress method");
1546 String address = "";
1547 if (entityTypeContactInfoBo.getAddresses() != null) {
1548 for (int i = 0; i < entityTypeContactInfoBo.getAddresses().size(); i++) {
1549 if (entityTypeContactInfoBo.getAddresses().get(i).isDefaultValue()) {
1550 if (entityTypeContactInfoBo.getAddresses().get(i).getLine1() != null)
1551 if (!entityTypeContactInfoBo.getAddresses().get(i).getLine1().isEmpty())
1552 address += entityTypeContactInfoBo.getAddresses().get(i).getLine1() + ",";
1553
1554 if (entityTypeContactInfoBo.getAddresses().get(i).getLine2() != null)
1555 if (!entityTypeContactInfoBo.getAddresses().get(i).getLine2().isEmpty())
1556 address += entityTypeContactInfoBo.getAddresses().get(i).getLine2() + ",";
1557
1558 if (entityTypeContactInfoBo.getAddresses().get(i).getLine3() != null)
1559 if (!entityTypeContactInfoBo.getAddresses().get(i).getLine3().isEmpty())
1560 address += entityTypeContactInfoBo.getAddresses().get(i).getLine3() + ",";
1561
1562 if (entityTypeContactInfoBo.getAddresses().get(i).getCity() != null)
1563 if (!entityTypeContactInfoBo.getAddresses().get(i).getCity().isEmpty())
1564 address += entityTypeContactInfoBo.getAddresses().get(i).getCity() + ",";
1565
1566 if (entityTypeContactInfoBo.getAddresses().get(i).getStateProvinceCode() != null)
1567 if (!entityTypeContactInfoBo.getAddresses().get(i).getStateProvinceCode().isEmpty())
1568 address += entityTypeContactInfoBo.getAddresses().get(i).getStateProvinceCode() + ",";
1569
1570 if (entityTypeContactInfoBo.getAddresses().get(i).getCountryCode() != null)
1571 if (!entityTypeContactInfoBo.getAddresses().get(i).getCountryCode().isEmpty())
1572 address += entityTypeContactInfoBo.getAddresses().get(i).getCountryCode() + ",";
1573
1574 if (entityTypeContactInfoBo.getAddresses().get(i).getPostalCode() != null)
1575 if (!entityTypeContactInfoBo.getAddresses().get(i).getPostalCode().isEmpty())
1576 address += entityTypeContactInfoBo.getAddresses().get(i).getPostalCode();
1577 }
1578 }
1579 }
1580
1581 return address;
1582 }
1583
1584 public String getPatronHomePhoneNumber(EntityTypeContactInfoBo entityTypeContactInfoBo) throws Exception {
1585 LOG.debug("Inside the getPatronHomePhoneNumber method");
1586 String phoneNumber = "";
1587 if (entityTypeContactInfoBo.getPhoneNumbers() != null) {
1588 for (int j = 0; j < entityTypeContactInfoBo.getPhoneNumbers().size(); j++) {
1589 if (entityTypeContactInfoBo.getPhoneNumbers().get(j).getPhoneTypeCode().equalsIgnoreCase("HM")) {
1590 phoneNumber = (entityTypeContactInfoBo.getPhoneNumbers().get(j).getPhoneNumber());
1591 }
1592 }
1593 }
1594 return phoneNumber;
1595 }
1596
1597 public String getPatronHomeEmailId(EntityTypeContactInfoBo entityTypeContactInfoBo) throws Exception {
1598 LOG.debug("Inside the getPatronHomeEmailId method");
1599 String emailId = "";
1600 if (entityTypeContactInfoBo.getEmailAddresses() != null) {
1601 for (int j = 0; j < entityTypeContactInfoBo.getEmailAddresses().size(); j++) {
1602 if (entityTypeContactInfoBo.getEmailAddresses().get(j).getDefaultValue()) {
1603 emailId = (entityTypeContactInfoBo.getEmailAddresses().get(j).getEmailAddress());
1604 break;
1605 }
1606 }
1607 }
1608 return emailId;
1609 }
1610
1611 private static int determineDifferenceInDays(Date currentDate, Date dueDate) {
1612 Calendar calendar1 = Calendar.getInstance();
1613 calendar1.setTime(dueDate);
1614 Calendar calendar2 = Calendar.getInstance();
1615 calendar2.setTime(currentDate);
1616 long diffInMillis = calendar2.getTimeInMillis() - calendar1.getTimeInMillis();
1617 return (int) (diffInMillis / (24 * 1000 * 60 * 60));
1618 }
1619
1620
1621 public void generateNotices() throws Exception {
1622 Long b1 = System.currentTimeMillis();
1623 if (LOG.isDebugEnabled()) {
1624 LOG.debug("************---------START TIME OF GENERATE NOTICE SERVICE------" + System.currentTimeMillis());
1625 }
1626 DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
1627 String courtesyInterval = getIntervalForCourtesyNotice();
1628 OleLoanDocumentDaoOjb oleLoanDocumentDaoOjb = (OleLoanDocumentDaoOjb)SpringContext.getBean("oleLoanDao");
1629 Collection courtesyNotice = new ArrayList<>();
1630 Collection overdueNotice = new ArrayList<>();
1631 try {
1632 overdueNotice=oleLoanDocumentDaoOjb.getOverdueLoanDocument();
1633 List<OleLoanDocument> documents = new ArrayList<>();
1634 List<String> itemIds = new ArrayList<>();
1635 if (overdueNotice != null && overdueNotice.size()>0) {
1636 boolean isOnlyOnePatronRecordExist=true;
1637 boolean firstTime = true;
1638 String patronId="";
1639 for (Object obj : overdueNotice) {
1640 OleLoanDocument loanDocument = (OleLoanDocument) obj;
1641 if(firstTime){
1642 patronId=loanDocument.getPatronId();
1643 }
1644 if(patronId!=null && patronId.equals(loanDocument.getPatronId()) ){
1645 documents.add(loanDocument);
1646 itemIds.add(loanDocument.getItemUuid());
1647 } else {
1648 generateNoticeForOverdueAndCourtesy(patronId,documents,courtesyInterval,true,itemIds);
1649 documents = new ArrayList<>();
1650 itemIds = new ArrayList<>();
1651 patronId=loanDocument.getPatronId();
1652 isOnlyOnePatronRecordExist=false;
1653 }
1654 firstTime=false;
1655 }
1656 if(isOnlyOnePatronRecordExist){
1657 generateNoticeForOverdueAndCourtesy(patronId,documents,courtesyInterval,true,itemIds);
1658 }
1659 }
1660 courtesyNotice=oleLoanDocumentDaoOjb.getCourtesyLoanDocument(Integer.parseInt(courtesyInterval));
1661 documents = new ArrayList<>();
1662 itemIds = new ArrayList<>();
1663 if (courtesyNotice != null && courtesyNotice.size()>0) {
1664 boolean firstTime = true;
1665 String patronId="";
1666 boolean isOnlyOnePatronRecordExist=true;
1667 for (Object obj : courtesyNotice) {
1668 OleLoanDocument loanDocument = (OleLoanDocument) obj;
1669 if(firstTime){
1670 patronId=loanDocument.getPatronId();
1671 }
1672 if(patronId!=null && patronId.equals(loanDocument.getPatronId())){
1673 documents.add(loanDocument);
1674 itemIds.add(loanDocument.getItemUuid());
1675 } else {
1676 generateNoticeForOverdueAndCourtesy(patronId,documents,courtesyInterval,false,itemIds);
1677 documents = new ArrayList<>();
1678 itemIds = new ArrayList<>();
1679 patronId=loanDocument.getPatronId();
1680 isOnlyOnePatronRecordExist=false;
1681 }
1682 firstTime=false;
1683 }
1684 if(isOnlyOnePatronRecordExist){
1685 generateNoticeForOverdueAndCourtesy(patronId,documents,courtesyInterval,false,itemIds);
1686 }
1687 }
1688 } catch (Exception e){
1689 LOG.error("Error while preparing Patron Map using PersistenceBroker ----> generateOverDueNotice()"+e.getMessage() +e);
1690 }
1691 Long b2 = System.currentTimeMillis();
1692 Long total = b2 - b1;
1693 LOG.info("The time generating overdue/courtesy notice time:"+total);
1694
1695 }
1696
1697 public void generateNoticeForOverdueAndCourtesy(String patronId, List<OleLoanDocument> oleLoanDocuments,String courtesyInterval,boolean overdue,List<String> itemIds){
1698 Map<String, String> patronMap = new HashMap<String, String>();
1699 patronMap.put("olePatronId",patronId);
1700 List<OlePatronDocument> olePatronDocuments=(List<OlePatronDocument>)KRADServiceLocator.getBusinessObjectService().findMatching(OlePatronDocument.class,patronMap);
1701 if(olePatronDocuments!=null && olePatronDocuments.size()>0){
1702 OlePatronDocument olePatronDocument=olePatronDocuments.get(0);
1703 if(oleLoanDocuments!=null && oleLoanDocuments.size()>0){
1704 getNoticeList(oleLoanDocuments,olePatronDocument,overdue,courtesyInterval,itemIds);
1705 }
1706 }
1707 }
1708
1709 public void generateHoldCourtesyNotice() throws Exception {
1710 List<OleDeliverRequestBo> oleDeliverRequestBos = (List<OleDeliverRequestBo>) KRADServiceLocator.getBusinessObjectService().findAll(OleDeliverRequestBo.class);
1711 for (OleDeliverRequestBo oleDeliverRequestBo : oleDeliverRequestBos) {
1712 List<OleNoticeBo> oleNoticeBos = new ArrayList<OleNoticeBo>();
1713 DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
1714 if (getDocstoreUtil().isItemAvailableInDocStore(oleDeliverRequestBo)) {
1715 Item oleItem = oleDeliverRequestBo.getOleItem();
1716 OleNoticeBo oleNoticeBo = new OleNoticeBo();
1717 Date currentDate = new Date();
1718 DateFormat formatter = new SimpleDateFormat(OLEConstants.DAT_FORMAT_EFFECTIVE_NOTICE);
1719 Date itemStatusEffectiveDate = (Date) formatter.parse(oleItem.getItemStatusEffectiveDate());
1720 Integer numberOfDaysOnHold = determineDifferenceInDays(currentDate, itemStatusEffectiveDate);
1721 Integer maxNumberOfDaysOnHold = 0;
1722 OleCirculationDesk oleCirculationDesk = null;
1723 if (oleDeliverRequestBo.getPickUpLocationId() != null) {
1724 oleCirculationDesk = getLoanProcessor().getOleCirculationDesk(oleDeliverRequestBo.getPickUpLocationId());
1725 String maxNumOfDays = oleCirculationDesk.getOnHoldDays() != null ? oleCirculationDesk.getOnHoldDays() : getLoanProcessor().getParameter(OLEConstants.MAX_NO_OF_DAYS_ON_HOLD);
1726 maxNumberOfDaysOnHold = new Integer(maxNumOfDays);
1727 }
1728 String itemTypeName = null;
1729 if (oleItem.getTemporaryItemType() != null && oleItem.getTemporaryItemType().getCodeValue() != "") {
1730 OleInstanceItemType oleInstanceItemType = getLoanProcessor().getItemTypeIdByItemType(oleItem.getTemporaryItemType().getCodeValue());
1731 itemTypeName = oleInstanceItemType.getInstanceItemTypeCode();
1732 }
1733 else if (oleItem.getItemType() != null && oleItem.getItemType().getCodeValue() != "") {
1734 OleInstanceItemType oleInstanceItemType = getLoanProcessor().getItemTypeIdByItemType(oleItem.getItemType().getCodeValue());
1735 itemTypeName = oleInstanceItemType.getInstanceItemTypeCode();
1736 }
1737 OlePatronDocument olePatronDocument = oleDeliverRequestBo.getOlePatron();
1738 String agendaName = OLEConstants.OleDeliverRequest.NOTICE_VALIDATION;
1739 dataCarrierService.addData(OLEConstants.CIRC_POLICY_FOUND, null);
1740 HashMap<String, Object> termValues = new HashMap<String, Object>();
1741 Date expirationDate = olePatronDocument!=null ? olePatronDocument.getExpirationDate():null;
1742 termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode());
1743 termValues.put(OLEConstants.ITEM_TYPE, itemTypeName);
1744 termValues.put(OLEConstants.OVERLAY_ITEM_LOCATION, oleDeliverRequestBo.getShelvingLocation());
1745 termValues.put(OLEConstants.NO_OF_DAYS_ON_HOLD, numberOfDaysOnHold);
1746 termValues.put(OLEConstants.MAX_NO_OF_DAYS_ONHOLD, maxNumberOfDaysOnHold);
1747 termValues.put(OLEConstants.ITEM_SHELVING, oleDeliverRequestBo.getShelvingLocation());
1748 termValues.put(OLEConstants.ITEM_COLLECTION, oleDeliverRequestBo.getItemCollection());
1749 termValues.put(OLEConstants.ITEM_LIBRARY, oleDeliverRequestBo.getItemLibrary());
1750 termValues.put(OLEConstants.ITEM_CAMPUS, oleDeliverRequestBo.getItemCampus());
1751 termValues.put(OLEConstants.ITEM_INSTITUTION, oleDeliverRequestBo.getItemInstitution());
1752 termValues.put(OLEConstants.REQUEST_TYPE,oleDeliverRequestBo.getRequestTypeCode());
1753 termValues.put(OLEConstants.EXPIR_DATE,expirationDate);
1754 if (oleItem.getItemStatus() != null)
1755 termValues.put(OLEConstants.ITEM_STATUS, oleItem.getItemStatus().getCodeValue());
1756 if (LOG.isDebugEnabled()) {
1757 LOG.debug("termValues.toString()" + termValues.toString());
1758 }
1759 EngineResults engineResults = getLoanProcessor().getEngineResults(agendaName, termValues);
1760 String notice = (String) engineResults.getAttribute(OLEConstants.NOTICE);
1761 if (LOG.isDebugEnabled()) {
1762 LOG.debug("notice" + notice);
1763 }
1764 agendaName = OLEConstants.BATCH_PROGRAM_AGENDA;
1765 termValues = new HashMap<String, Object>();
1766 String deskLocation = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskCode() : "";
1767 String deskLocationName = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskPublicName() : "";
1768 termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode());
1769 termValues.put(OLEConstants.DESK_LOCATION, deskLocation);
1770 termValues.put(OLEConstants.NOTICE, notice);
1771 if (LOG.isDebugEnabled()) {
1772 LOG.debug("termValues.toString()" + termValues.toString());
1773 }
1774 engineResults = getLoanProcessor().getEngineResults(agendaName, termValues);
1775 String noticeType = (String) engineResults.getAttribute(OLEConstants.NOTICE_TYPE);
1776 if (LOG.isDebugEnabled()) {
1777 LOG.debug("**************" + noticeType);
1778 }
1779 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
1780 if (notice != null) {
1781 oleNoticeBo.setNoticeName(notice);
1782 if (notice.equalsIgnoreCase(OLEConstants.NOTICE_HOLD_COURTESY)) {
1783 oleNoticeBo = getExpiredHoldNotice(oleDeliverRequestBo);
1784 oleNoticeBo.setCirculationDeskName(deskLocationName);
1785 oleNoticeBos.add(oleNoticeBo);
1786 noticeType = noticeType == null ? getLoanProcessor().getParameter("HOLDCOURTESY_NOTICE_TYPE") : noticeType;
1787 }
1788 if (oleNoticeBos.size() > 0 && noticeType != null && (noticeType.equalsIgnoreCase(OLEConstants.EMAIL) || noticeType.equalsIgnoreCase(OLEConstants.MAIL))) {
1789 oleDeliverBatchService.getPdfNoticeForPatron(oleNoticeBos);
1790 }
1791
1792 }
1793 olePatronDocument = oleDeliverRequestBo.getOlePatron();
1794 if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.EMAIL)) {
1795 String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
1796 if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
1797 fromAddress = OLEConstants.KUALI_MAIL;
1798 }
1799 if (olePatronDocument.getEmailAddress() != null && !olePatronDocument.getEmailAddress().isEmpty()) {
1800 List list = oleDeliverBatchService.getNoticeForPatron(oleNoticeBos);
1801 String noticeContent = list.toString();
1802 noticeContent = noticeContent.replace('[', ' ');
1803 noticeContent = noticeContent.replace(']', ' ');
1804 if (!noticeContent.trim().equals("")) {
1805 OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
1806 oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(noticeContent), true);
1807 } else {
1808 for (OleNoticeBo oleNoticeBo1 : oleNoticeBos) {
1809 if (LOG.isDebugEnabled()) {
1810 LOG.debug("Notice Type :" + oleNoticeBo1.getNoticeName() + " " + "Item Barcode : " + oleNoticeBo1.getItemId() + " " + "Patron Name :" + oleNoticeBo1.getPatronName());
1811 }
1812 }
1813 }
1814
1815 if (LOG.isDebugEnabled()) {
1816 LOG.debug("olePatronDocument.getEmailAddress()" + olePatronDocument.getEmailAddress());
1817 }
1818 }
1819 } else if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.SMS)) {
1820
1821 }
1822 }
1823 }
1824 }
1825
1826 public void deleteTemporaryHistoryRecord() throws Exception {
1827 List<OlePatronDocument> patronDocumentList = (List<OlePatronDocument>) KRADServiceLocator.getBusinessObjectService().findAll(OlePatronDocument.class);
1828 for (OlePatronDocument olePatronDocument : patronDocumentList) {
1829 Map<String, String> requestMap = new HashMap<String, String>();
1830 requestMap.put(OLEConstants.OlePatron.PATRON_ID, olePatronDocument.getOlePatronId());
1831 List<OleTemporaryCirculationHistory> oleTemporaryCirculationHistoryList = (List<OleTemporaryCirculationHistory>) KRADServiceLocator.getBusinessObjectService().findMatching(OleTemporaryCirculationHistory.class, requestMap);
1832 List<OleTemporaryCirculationHistory> deleteRecords = new ArrayList<OleTemporaryCirculationHistory>();
1833 for (OleTemporaryCirculationHistory oleTemporaryCirculationHistory : oleTemporaryCirculationHistoryList) {
1834 String agendaName = OLEConstants.BATCH_PROGRAM_AGENDA;
1835 HashMap<String, Object> termValues = new HashMap<String, Object>();
1836 termValues.put(OLEConstants.OleDeliverRequest.IS_TEMPORARY_HISTORY_RECORD, String.valueOf(Boolean.TRUE));
1837 DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
1838 dataCarrierService.addData(OLEConstants.DATE_CHECK_IN, oleTemporaryCirculationHistory.getCheckInDate());
1839 EngineResults engineResults = getLoanProcessor().getEngineResults(agendaName, termValues);
1840 Boolean deleteRecord = (Boolean) engineResults.getAttribute(OLEConstants.OVERLAY_OPTION_DELETE);
1841 if (deleteRecord != null && deleteRecord) {
1842 deleteRecords.add(oleTemporaryCirculationHistory);
1843 }
1844 }
1845 getBusinessObjectService().delete(deleteRecords);
1846 }
1847 }
1848
1849 private OleNoticeBo getExpiredHoldNotice(OleDeliverRequestBo oleDeliverRequestBo) throws Exception {
1850 LOG.debug("Expired Hold Notice");
1851 Item oleItem = oleDeliverRequestBo.getOleItem();
1852 EntityTypeContactInfoBo entityTypeContactInfoBo = oleDeliverRequestBo.getOlePatron().getEntity().getEntityTypeContactInfos().get(0);
1853 OleNoticeBo oleNoticeBo = new OleNoticeBo();
1854 org.kuali.ole.docstore.common.document.Item item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(oleDeliverRequestBo.getItemUuid());
1855 String shelvingLocation = oleDeliverRequestBo.getShelvingLocation();
1856 OleCirculationDesk oleCirculationDesk = getOleCirculationDesk(oleDeliverRequestBo.getPickUpLocationId());
1857 if (oleCirculationDesk != null)
1858 oleNoticeBo.setCirculationDeskName(oleCirculationDesk.getCirculationDeskPublicName());
1859 else
1860 oleNoticeBo.setCirculationDeskName("");
1861 oleNoticeBo.setCirculationDeskAddress("");
1862 oleNoticeBo.setCirculationDeskEmailAddress("");
1863 oleNoticeBo.setCirculationDeskPhoneNumber("");
1864 oleNoticeBo.setCirculationDeskPhoneNumber("");
1865 oleNoticeBo.setPatronName(oleDeliverRequestBo.getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + oleDeliverRequestBo.getOlePatron().getEntity().getNames().get(0).getLastName());
1866 oleNoticeBo.setPatronAddress(getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getPatronPreferredAddress(entityTypeContactInfoBo) : "");
1867 oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : "");
1868 oleNoticeBo.setPatronPhoneNumber(getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
1869 oleNoticeBo.setNoticeName(OLEConstants.NOTICE_HOLD_COURTESY);
1870 oleNoticeBo.setNoticeSpecificContent(LoanUtil.getLoanUtil().getProperty(OLEConstants.OleDeliverRequest.EXP_HOLD_NOTICE_CONTENT));
1871 oleNoticeBo.setTitle(item.getHolding().getBib().getTitle());
1872 oleNoticeBo.setAuthor(item.getHolding().getBib().getAuthor());
1873
1874
1875 oleNoticeBo.setVolumeNumber(item.getVolumeNumber());
1876 oleNoticeBo.setItemShelvingLocation(shelvingLocation != null ? shelvingLocation : "");
1877
1878 oleNoticeBo.setItemCallNumber((String) oleItem.getCallNumber().getNumber() != null && !oleItem.getCallNumber().getNumber().equals("") ? oleItem.getCallNumber().getNumber() : "");
1879 oleNoticeBo.setItemId(oleDeliverRequestBo.getItemId() != null ? oleDeliverRequestBo.getItemId() : "");
1880 oleNoticeBo.setOleItem(oleItem);
1881 oleNoticeBo.setOlePatron(oleDeliverRequestBo.getOlePatron());
1882
1883 oleDeliverRequestBo.getOlePatron().setEmailAddress(oleNoticeBo.getPatronEmailAddress());
1884 return oleNoticeBo;
1885 }
1886
1887 private OleNoticeBo getCourtesyNotice(OleLoanDocument oleLoanDocument) throws Exception {
1888 LOG.debug("Courtesy Notice");
1889 oleLoanDocument.setCourtesyNoticeFlag(true);
1890 Map<String, String> map = new HashMap<String, String>();
1891 map.put(OLEConstants.LOAN_ID, oleLoanDocument.getLoanId());
1892 KRADServiceLocator.getBusinessObjectService().save(oleLoanDocument);
1893 EntityTypeContactInfoBo entityTypeContactInfoBo = oleLoanDocument.getOlePatron().getEntity().getEntityTypeContactInfos().get(0);
1894 OleNoticeBo oleNoticeBo = new OleNoticeBo();
1895
1896 Item oleItem = oleLoanDocument.getOleItem();
1897 String shelvingLocation = oleLoanDocument.getItemLocation();
1898 OleCirculationDesk oleCirculationDesk = getOleCirculationDesk(oleLoanDocument.getCirculationLocationId());
1899 if (oleCirculationDesk != null)
1900 oleNoticeBo.setCirculationDeskName(oleCirculationDesk.getCirculationDeskPublicName());
1901 else
1902 oleNoticeBo.setCirculationDeskName("");
1903 oleNoticeBo.setCirculationDeskAddress("");
1904 oleNoticeBo.setCirculationDeskEmailAddress("");
1905 oleNoticeBo.setCirculationDeskPhoneNumber("");
1906 oleNoticeBo.setPatronName(oleLoanDocument.getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + oleLoanDocument.getOlePatron().getEntity().getNames().get(0).getLastName());
1907 oleNoticeBo.setPatronAddress(getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getPatronPreferredAddress(entityTypeContactInfoBo) : "");
1908 oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : "");
1909 oleNoticeBo.setPatronPhoneNumber(getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
1910 oleNoticeBo.setNoticeName(OLEConstants.NOTICE_COURTESY);
1911 oleNoticeBo.setNoticeSpecificContent(LoanUtil.getLoanUtil().getProperty(OLEConstants.OleDeliverRequest.COURTESY_NOTICE_CONTENT));
1912
1913
1914 oleNoticeBo.setTitle(oleLoanDocument.getTitle());
1915 oleNoticeBo.setAuthor(oleLoanDocument.getAuthor());
1916 oleNoticeBo.setVolumeNumber(oleLoanDocument.getItemVolumeNumber());
1917 oleNoticeBo.setItemShelvingLocation(shelvingLocation != null ? shelvingLocation : "");
1918
1919 oleNoticeBo.setItemCallNumber(oleLoanDocument.getItemCallNumber());
1920 oleNoticeBo.setItemId(oleLoanDocument.getItemId());
1921 oleLoanDocument.getOlePatron().setEmailAddress(oleNoticeBo.getPatronEmailAddress());
1922 if (LOG.isDebugEnabled()) {
1923 LOG.debug("oleNoticeBo.getPatronEmailAddress()" + oleNoticeBo.getPatronEmailAddress());
1924 }
1925 return oleNoticeBo;
1926 }
1927
1928 private OleNoticeBo getOverdueNotice(OleLoanDocument oleLoanDocument) throws Exception {
1929 LOG.debug("Overdue Notice");
1930 EntityTypeContactInfoBo entityTypeContactInfoBo = oleLoanDocument.getOlePatron().getEntity().getEntityTypeContactInfos().get(0);
1931 OleNoticeBo oleNoticeBo = new OleNoticeBo();
1932
1933 Item oleItem = oleLoanDocument.getOleItem();
1934
1935
1936 OleCirculationDesk oleCirculationDesk = getOleCirculationDesk(oleLoanDocument.getCirculationLocationId());
1937 if (oleCirculationDesk != null)
1938 oleNoticeBo.setCirculationDeskName(oleCirculationDesk.getCirculationDeskPublicName());
1939 else
1940 oleNoticeBo.setCirculationDeskName("");
1941 oleNoticeBo.setCirculationDeskAddress("");
1942 oleNoticeBo.setCirculationDeskEmailAddress("");
1943 oleNoticeBo.setCirculationDeskPhoneNumber("");
1944 oleNoticeBo.setPatronName(oleLoanDocument.getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + oleLoanDocument.getOlePatron().getEntity().getNames().get(0).getLastName());
1945 oleNoticeBo.setPatronAddress(getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getPatronPreferredAddress(entityTypeContactInfoBo) : "");
1946 oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : "");
1947 oleNoticeBo.setPatronPhoneNumber(getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
1948 oleNoticeBo.setNoticeName(OLEConstants.NOTICE_OVERDUE);
1949 oleNoticeBo.setNoticeSpecificContent(LoanUtil.getLoanUtil().getProperty(OLEConstants.OleDeliverRequest.OVERDUE_NOTICE_CONTENT));
1950 oleNoticeBo.setTitle(oleLoanDocument.getTitle());
1951 oleNoticeBo.setAuthor(oleLoanDocument.getAuthor());
1952
1953
1954
1955
1956 String volume = (String) oleItem.getEnumeration() != null && !oleItem.getEnumeration().equals("") ? oleItem.getEnumeration() : "";
1957 String issue = new String(" ");
1958 String copyNumber = (String) oleItem.getCopyNumber() != null && !oleItem.getCopyNumber().equals("") ? oleItem.getCopyNumber() : "";
1959 oleNoticeBo.setVolumeIssueCopyNumber(volume + "/" + issue + "/" + copyNumber);
1960 oleNoticeBo.setItemShelvingLocation(oleLoanDocument.getItemLocation());
1961 if (oleItem.getCallNumber().getNumber() != null && !oleItem.getCallNumber().getNumber().equals("")) {
1962 oleNoticeBo.setItemCallNumber((String) oleItem.getCallNumber().getNumber() != null && !oleItem.getCallNumber().getNumber().equals("") ? oleItem.getCallNumber().getNumber() : "");
1963 } else {
1964 oleNoticeBo.setItemCallNumber(getLoanProcessor().getItemCallNumber(oleItem, oleLoanDocument.getInstanceUuid()));
1965 }
1966
1967 oleNoticeBo.setItemId(oleLoanDocument.getItemId());
1968
1969 oleNoticeBo.setDueDate(oleLoanDocument.getLoanDueDate()!=null ? oleLoanDocument.getLoanDueDate():null);
1970
1971 oleLoanDocument.getOlePatron().setEmailAddress(oleNoticeBo.getPatronEmailAddress());
1972 if (LOG.isDebugEnabled()) {
1973 LOG.debug("oleNoticeBo.getPatronEmailAddress()" + oleNoticeBo.getPatronEmailAddress());
1974 }
1975 int noOfOverdueNoticeSent = Integer.parseInt(oleLoanDocument.getNumberOfOverdueNoticesSent() != null ? oleLoanDocument.getNumberOfOverdueNoticesSent() : "0");
1976 noOfOverdueNoticeSent = noOfOverdueNoticeSent + 1;
1977 if (LOG.isDebugEnabled()) {
1978 LOG.debug("Updated Loan Record : " + oleLoanDocument);
1979 }
1980 oleLoanDocument.setNumberOfOverdueNoticesSent(Integer.toString(noOfOverdueNoticeSent));
1981 oleLoanDocument.setOverDueNoticeDate(new java.sql.Date(System.currentTimeMillis()));
1982 getBusinessObjectService().save(oleLoanDocument);
1983 return oleNoticeBo;
1984 }
1985
1986 public void updateItem(Item oleItem, String itemUuid) throws Exception {
1987 ItemStatus itemStatus = new ItemStatus();
1988 itemStatus.setCodeValue(OLEConstants.OleDeliverRequest.MISSING);
1989 itemStatus.setFullValue(OLEConstants.OleDeliverRequest.MISSING);
1990 oleItem.setItemStatus(itemStatus);
1991 oleItem.setStaffOnlyFlag(true);
1992 String itemContent = new ItemOlemlRecordProcessor().toXML(oleItem);
1993 org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
1994 item.setId(itemUuid);
1995 item.setContent(itemContent);
1996 item.setCategory(OLEConstants.WORK_CATEGORY);
1997 item.setType(DocType.ITEM.getCode());
1998 item.setFormat(OLEConstants.OLEML_FORMAT);
1999 getDocstoreClientLocator().getDocstoreClient().updateItem(item);
2000 }
2001
2002 public String getShelvingLocation(LocationLevel oleLocationLevel) {
2003 String location = null;
2004 if (oleLocationLevel != null) {
2005 if (OLEConstants.LOCATION_LEVEL_SHELVING.equalsIgnoreCase(oleLocationLevel.getLevel()))
2006 location = oleLocationLevel.getName();
2007 else
2008 location = getShelvingLocation(oleLocationLevel.getLocationLevel());
2009 }
2010 if ("".equals(location) || location == null)
2011 return null;
2012 return location;
2013 }
2014
2015
2016 public String getIntervalForCourtesyNotice() {
2017 BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
2018 Map<String, String> criteriaMap = new HashMap<String, String>();
2019 criteriaMap.put(OLEConstants.NAMESPACE_CODE, OLEConstants.DLVR_NMSPC);
2020 criteriaMap.put(OLEConstants.COMPONENT_CODE, OLEConstants.DLVR_CMPNT);
2021 criteriaMap.put(OLEConstants.NAME, OLEParameterConstants.COURTESY_NOTICE_INTER);
2022 List<ParameterBo> parametersList = (List<ParameterBo>) businessObjectService.findMatching(ParameterBo.class, criteriaMap);
2023 return parametersList.get(0).getValue();
2024 }
2025
2026 public String getIntervalForOverdueNotice() {
2027 BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
2028 Map<String, String> criteriaMap = new HashMap<String, String>();
2029 criteriaMap.put(OLEConstants.NAMESPACE_CODE, OLEConstants.DLVR_NMSPC);
2030 criteriaMap.put(OLEConstants.COMPONENT_CODE, OLEConstants.DLVR_CMPNT);
2031 criteriaMap.put(OLEConstants.NAME, OLEConstants.OVERDUE_NOTICE_INTER);
2032 List<ParameterBo> parametersList = (List<ParameterBo>) businessObjectService.findMatching(ParameterBo.class, criteriaMap);
2033 return parametersList.get(0).getValue();
2034 }
2035
2036
2037 private PatronBillPayment getPatronBillPayment(String patronId) {
2038 LOG.debug("Inside the getPatronBillPayment method");
2039 Map billMap = new HashMap();
2040 billMap.put(OLEConstants.OleDeliverRequest.LOAN_PATRON_ID, patronId);
2041 List<PatronBillPayment> patronBillPaymentList = (List<PatronBillPayment>) getBusinessObjectService().findMatching(PatronBillPayment.class, billMap);
2042 return patronBillPaymentList != null && patronBillPaymentList.size() > 0 ? patronBillPaymentList.get(0) : null;
2043 }
2044
2045 private OlePaymentStatus getPaymentStatus() {
2046 LOG.debug("Inside the getPaymentStatus method");
2047 Map statusMap = new HashMap();
2048 statusMap.put(OLEConstants.OleDeliverRequest.PAYMENT_STATUS_NAME, OLEConstants.PAYMENT_STATUS_OUTSTANDING);
2049 List<OlePaymentStatus> olePaymentStatusList = (List<OlePaymentStatus>) getBusinessObjectService().findMatching(OlePaymentStatus.class, statusMap);
2050 return olePaymentStatusList != null && olePaymentStatusList.size() > 0 ? olePaymentStatusList.get(0) : null;
2051 }
2052
2053 private String getFeeTypeId(String feeTypeName) {
2054 LOG.debug("Inside the getOverdueFeeTypeId method");
2055 Map feeMap = new HashMap();
2056 feeMap.put(OLEConstants.FEE_TYPE_NAME, feeTypeName);
2057 List<OleFeeType> oleFeeTypes = (List<OleFeeType>) getBusinessObjectService().findMatching(OleFeeType.class, feeMap);
2058 return oleFeeTypes != null && oleFeeTypes.size() > 0 ? oleFeeTypes.get(0).getFeeTypeId() : null;
2059 }
2060
2061 public String processItemType(String itemType) {
2062
2063 LOG.debug("Inside process Item Type");
2064 Map<String, String> itemMap = new HashMap<String, String>();
2065 itemMap.put(OLEConstants.OleDeliverRequest.ITEM_TYPE_CODE, itemType);
2066 List<OleInstanceItemType> oleInstanceItemTypeList = (List<OleInstanceItemType>) businessObjectService.findMatching(OleInstanceItemType.class, itemMap);
2067 if (oleInstanceItemTypeList != null && oleInstanceItemTypeList.size() > 0) {
2068 OleInstanceItemType oleInstanceItemType = oleInstanceItemTypeList.get(0);
2069 return oleInstanceItemType.getInstanceItemTypeName();
2070 }
2071 return null;
2072 }
2073
2074 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) {
2075 OLEPlaceRequest olePlaceRequest = new OLEPlaceRequest();
2076 OLEPlaceRequestConverter olePlaceRequestConverter = new OLEPlaceRequestConverter();
2077 ASRHelperServiceImpl asrHelperService = new ASRHelperServiceImpl();
2078 OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
2079 oleDeliverRequestBo.setCreateDate(new java.sql.Date(System.currentTimeMillis()));
2080 OlePatronDocument olePatronDocument = null;
2081 Map<String, String> patronMap = new HashMap<String, String>();
2082 patronMap.put(OLEConstants.BARCODE, patronBarcode);
2083 OleNoticeBo oleNoticeBo = new OleNoticeBo();
2084 List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) getBusinessObjectService().findMatching(OlePatronDocument.class, patronMap);
2085 if (olePatronDocumentList.size() > 0) {
2086 olePatronDocument = olePatronDocumentList.get(0);
2087 oleDeliverRequestBo.setBorrowerId(olePatronDocument.getOlePatronId());
2088 oleDeliverRequestBo.setBorrowerBarcode(olePatronDocument.getBarcode());
2089 oleDeliverRequestBo.setOlePatron(olePatronDocument);
2090 EntityTypeContactInfoBo entityTypeContactInfoBo = olePatronDocument.getEntity().getEntityTypeContactInfos().get(0);
2091 try {
2092 oleNoticeBo.setPatronName(olePatronDocument.getEntity().getNames().get(0).getFirstName() + " " + oleDeliverRequestBo.getOlePatron().getEntity().getNames().get(0).getLastName());
2093 oleNoticeBo.setPatronAddress(getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getPatronPreferredAddress(entityTypeContactInfoBo) : "");
2094 oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : "");
2095 oleNoticeBo.setPatronPhoneNumber(getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
2096 } catch (Exception e) {
2097 LOG.error("Exception", e);
2098 if (LOG.isDebugEnabled()) {
2099 LOG.debug("Exception Occured while setting the patron information for the patron . Patron Barcode : " + oleDeliverRequestBo.getBorrowerBarcode());
2100 }
2101 }
2102 } else {
2103 olePlaceRequest.setCode("002");
2104 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_PATRON_INFO));
2105 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2106 }
2107 if (requestType != null) {
2108 Map<String, String> requestTypeMap = new HashMap<String, String>();
2109 requestTypeMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_CD, requestType);
2110 List<OleDeliverRequestType> oleDeliverRequestTypeList = (List<OleDeliverRequestType>) getBusinessObjectService().findMatching(OleDeliverRequestType.class, requestTypeMap);
2111 if (oleDeliverRequestTypeList != null && (oleDeliverRequestTypeList.size() > 0)) {
2112 oleDeliverRequestBo.setRequestTypeId(oleDeliverRequestTypeList.get(0).getRequestTypeId());
2113 oleDeliverRequestBo.setOleDeliverRequestType(oleDeliverRequestTypeList.get(0));
2114 } else{
2115 olePlaceRequest.setCode("012");
2116 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_RQST_TYP));
2117 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2118 }
2119 }
2120 if (pickUpLocation != null) {
2121 Map<String, String> circulationDeskMap = new HashMap<String, String>();
2122 circulationDeskMap.put(OLEConstants.OleCirculationDesk.OLE_CIRCULATION_DESK_CD, pickUpLocation);
2123 List<OleCirculationDesk> oleCirculationDeskList = (List<OleCirculationDesk>) getBusinessObjectService().findMatching(OleCirculationDesk.class, circulationDeskMap);
2124 if (oleCirculationDeskList != null && oleCirculationDeskList.size() > 0) {
2125 oleDeliverRequestBo.setPickUpLocationId(oleCirculationDeskList.get(0).getCirculationDeskId());
2126 oleDeliverRequestBo.setPickUpLocationCode(oleCirculationDeskList.get(0).getCirculationDeskCode());
2127 oleDeliverRequestBo.setOlePickUpLocation(oleCirculationDeskList.get(0));
2128 } else {
2129 olePlaceRequest.setCode("013");
2130 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_PK_UP_LOCN));
2131 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2132 }
2133
2134 }
2135 try {
2136 if (itemBarcode == null || (itemBarcode != null && itemBarcode.isEmpty())) {
2137 olePlaceRequest.setCode("014");
2138 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_BARCODE_DOESNOT_EXISTS));
2139 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2140
2141 }
2142 oleDeliverRequestBo.setItemId(itemBarcode);
2143 oleDeliverRequestBo.setItemUuid(itemIdentifier);
2144 oleDeliverRequestBo.setItemStatus(OLEConstants.AVAILABLE);
2145 oleDeliverRequestBo.setItemType(itemType);
2146 oleDeliverRequestBo.setItemLocation(itemLocation);
2147 if(itemIdentifier == null || itemLocation == null || itemType == null){
2148 Thread.sleep(500);
2149 String itemUUID=null;
2150 String holdingsId =null;
2151 if(itemIdentifier==null){
2152 try {
2153 org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
2154 org.kuali.ole.docstore.common.search.SearchParams search_Params = new org.kuali.ole.docstore.common.search.SearchParams();
2155 SearchResponse searchResponse = null;
2156 search_Params.getSearchConditions().add(search_Params.buildSearchCondition("", search_Params.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), item.ITEM_BARCODE, oleDeliverRequestBo.getItemId()), ""));
2157 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), "id"));
2158 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.HOLDINGS.getCode(), "id"));
2159 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(search_Params);
2160 for (SearchResult searchResult : searchResponse.getSearchResults()) {
2161 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
2162 String fieldName = searchResultField.getFieldName();
2163 String fieldValue = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
2164 if (fieldName.equalsIgnoreCase("id") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("holdings")) {
2165 holdingsId = fieldValue;
2166 } else {
2167 oleDeliverRequestBo.setItemUuid(fieldValue);
2168 itemUUID = fieldValue;
2169 }
2170 }
2171 }
2172 } catch (Exception ex) {
2173 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_EXIST));
2174 LOG.error(OLEConstants.ITEM_EXIST + ex);
2175 }
2176 }
2177 if(itemUUID==null){
2178 olePlaceRequest.setCode("014");
2179 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_BARCODE_DOESNOT_EXISTS));
2180 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2181 }
2182 if(itemType==null || itemLocation ==null){
2183 Map<String,Object> detailMap =retrieveBIbItemHoldingData(itemUUID);
2184 Bib bib = (Bib)detailMap.get(OLEConstants.BIB);
2185 Item item = (Item)detailMap.get(OLEConstants.ITEM);
2186 OleHoldings oleHoldings = (OleHoldings)detailMap.get(OLEConstants.HOLDING);
2187 org.kuali.ole.docstore.common.document.Item item1 = (org.kuali.ole.docstore.common.document.Item)detailMap.get("documentItem");
2188 if(itemLocation == null){
2189 if(item1.getLocation()== null || (item1.getLocation()!=null && item1.getLocation().trim().isEmpty())){
2190 itemLocation =getDocstoreUtil().getLocation(oleHoldings.getLocation(),new StringBuffer(""));
2191 }else{
2192 itemLocation = item1.getLocation();
2193 }
2194 oleDeliverRequestBo.setItemLocation(itemLocation);
2195 }
2196 if(item.getItemType()!=null){
2197 oleDeliverRequestBo.setItemType(item.getItemType().getCodeValue());
2198 }
2199 if (item.getItemStatus() != null) {
2200 oleDeliverRequestBo.setItemStatus(item.getItemStatus().getCodeValue());
2201 }
2202 }
2203 }
2204
2205 if(itemLocation!=null){
2206 if (asrHelperService.isAnASRItem(itemLocation) && oleDeliverRequestBo.getItemStatus().equals(getLoanProcessor().getParameter(ASRConstants.ASR_REQUEST_ITEM_STATUS)) && !oleDeliverRequestBo.getRequestTypeCode().equals(getLoanProcessor().getParameter(ASRConstants.ASR_TYP_RQST))){
2207 olePlaceRequest.setCode("700");
2208 olePlaceRequest.setMessage("Cannot create "+oleDeliverRequestBo.getRequestTypeCode()+" for this item");
2209 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2210 }else if(asrHelperService.isAnASRItem(itemLocation) && !oleDeliverRequestBo.getItemStatus().equals(getLoanProcessor().getParameter(ASRConstants.ASR_REQUEST_ITEM_STATUS)) && oleDeliverRequestBo.getRequestTypeCode().equals(getLoanProcessor().getParameter(ASRConstants.ASR_TYP_RQST))){
2211 olePlaceRequest.setCode("701");
2212 olePlaceRequest.setMessage("Cannot create "+oleDeliverRequestBo.getRequestTypeCode()+" for this item");
2213 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2214 }
2215 Map<String,String> locationMap = getLocationMap(itemLocation);
2216 oleDeliverRequestBo.setItemLibrary(locationMap.get(OLEConstants.ITEM_LIBRARY));
2217 oleDeliverRequestBo.setItemInstitution(locationMap.get(OLEConstants.ITEM_INSTITUTION));
2218 oleDeliverRequestBo.setItemCampus(locationMap.get(OLEConstants.ITEM_CAMPUS));
2219 oleDeliverRequestBo.setItemCollection(locationMap.get(OLEConstants.ITEM_COLLECTION));
2220 oleDeliverRequestBo.setShelvingLocation(locationMap.get(OLEConstants.ITEM_SHELVING));
2221 }
2222 oleDeliverRequestBo.setRequestCreator(OLENCIPConstants.OPERATOR);
2223 oleDeliverRequestBo.setOperatorCreateId(operatorId);
2224 oleDeliverRequestBo.setItemId(itemBarcode);
2225 if (!processOperator(operatorId)) {
2226 olePlaceRequest.setCode("001");
2227 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_OPRTR_ID));
2228 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2229 }
2230 processRequestTypeByPickUpLocation(oleDeliverRequestBo);
2231 String message = this.patronRecordExpired(oleDeliverRequestBo);
2232 if (message != null) {
2233 olePlaceRequest.setCode("015");
2234 olePlaceRequest.setMessage(message);
2235 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2236 }
2237 boolean requestRaised = this.isRequestAlreadyRaisedByPatron(oleDeliverRequestBo);
2238 if (requestRaised){
2239 {
2240 olePlaceRequest.setCode("016");
2241 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RQST_ALRDY_RAISD));
2242 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2243 }
2244 }
2245 boolean itemEligible = this.isItemEligible(oleDeliverRequestBo);
2246 if (!itemEligible){
2247 {
2248 olePlaceRequest.setCode("017");
2249 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITM_NOT_LOAN));
2250 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2251 }
2252 }
2253 boolean alreadyLoaned = this.isAlreadyLoaned(oleDeliverRequestBo);
2254 if (alreadyLoaned){
2255 olePlaceRequest.setCode("018");
2256 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITM_LOAN_BY_PTRN));
2257 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2258 }
2259 boolean valid = false;
2260 EngineResults engineResult = this.executeEngineResults(oleDeliverRequestBo);
2261 if (engineResult != null) {
2262 List<ResultEvent> allResults = engineResult.getAllResults();
2263 if (allResults.size() > 0) {
2264 for (Iterator<ResultEvent> resultEventIterator = allResults.iterator(); resultEventIterator.hasNext(); ) {
2265 ResultEvent resultEvent = resultEventIterator.next();
2266 if (resultEvent.getType().equals(RULE_EVALUATED))
2267 valid |= resultEvent.getResult();
2268 }
2269 if ((oleDeliverRequestBo.getMessage() != null && !oleDeliverRequestBo.getMessage().isEmpty())) {
2270 olePlaceRequest.setCode("500");
2271 olePlaceRequest.setMessage(oleDeliverRequestBo.getMessage().replaceAll("<br/>",""));
2272 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2273 }
2274
2275 }
2276 }
2277 OleDeliverRequestBo oleDeliverRequestBo1 = oleDeliverRequestBo;
2278
2279 if (oleDeliverRequestBo.getRequestTypeId().equals("1") || oleDeliverRequestBo.getRequestTypeId().equals("2")) {
2280 oleDeliverRequestBo1 = this.updateLoanDocument(oleDeliverRequestBo);
2281 }
2282 if (isItemAvailable(oleDeliverRequestBo1)) {
2283 olePlaceRequest.setCode("019");
2284 olePlaceRequest.setMessage(oleDeliverRequestBo1.getRequestTypeCode()+ OLEConstants.RQST_CONDITION +oleDeliverRequestBo1.getItemStatus());
2285 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2286 }
2287 oleDeliverRequestBo.setOleItem(null);
2288 this.reOrderQueuePosition(oleDeliverRequestBo1);
2289 boolean asrItem = asrHelperService.isAnASRItem(oleDeliverRequestBo.getItemLocation());
2290 if(asrItem && oleDeliverRequestBo.getItemStatus().equals(getLoanProcessor().getParameter(ASRConstants.ASR_REQUEST_ITEM_STATUS))) {
2291 oleDeliverRequestBo.setAsrFlag(true);
2292 oleDeliverRequestBo.setRequestStatus("1");
2293 }
2294 getBusinessObjectService().save(oleDeliverRequestBo1);
2295 List<OleDeliverRequestBo> oleDeliverRequestBoList=null;
2296 String requestId = "";
2297 try {
2298 Map<String, String> requestMap = new HashMap<String, String>();
2299 requestMap.put(OLEConstants.OleDeliverRequest.BORROWER_ID, olePatronDocument.getOlePatronId());
2300 requestMap.put(OLEConstants.OleDeliverRequest.ITEM_ID, itemBarcode);
2301 oleDeliverRequestBoList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
2302 if (oleDeliverRequestBoList.size() > 0) {
2303 requestId = ":"+OLEConstants.OleDeliverRequest.REQUEST_ID+":" + oleDeliverRequestBoList.get(0).getRequestId();
2304 }
2305 if (LOG.isDebugEnabled()) {
2306 LOG.debug("Request Raised Succesfully" + requestId);
2307 }
2308 if(asrItem && oleDeliverRequestBo.getItemStatus().equals(getLoanProcessor().getParameter(ASRConstants.ASR_REQUEST_ITEM_STATUS))){
2309
2310 ASRTypeRequest asrTypeRequest = new ASRTypeRequest();
2311 asrTypeRequest.setRequestId(oleDeliverRequestBoList.get(0).getRequestId());
2312 asrTypeRequest.setRequestStatus("1");
2313 asrTypeRequest.setPickUpLocation(oleDeliverRequestBo.getPickUpLocationCode());
2314 asrTypeRequest.setItemId(oleDeliverRequestBo.getItemId());
2315 asrTypeRequest.setPatronId(oleDeliverRequestBo.getBorrowerId());
2316 getBusinessObjectService().save(asrTypeRequest);
2317 } else if(externalItem){
2318 String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
2319 if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
2320 fromAddress = OLEConstants.KUALI_MAIL;
2321 }
2322 oleNoticeBo.setNoticeName(OLEConstants.PICKUP_NOTICE);
2323 Date pickupDate = new java.sql.Date(System.currentTimeMillis());
2324 if(oleDeliverRequestBo.getOlePickUpLocation().getOnHoldDays()!=null){
2325 pickupDate = addDate(new java.sql.Date(System.currentTimeMillis()), new Integer(oleDeliverRequestBo.getOlePickUpLocation().getOnHoldDays()));
2326 }
2327 oleNoticeBo.setNoticeSpecificContent(OLEConstants.PICKUP_NOTICE_START_CONTENT + oleDeliverRequestBo.getOlePickUpLocation().getCirculationDeskPublicName() + OLEConstants.PICKUP_NOTICE_MIDDLE_CONTENT + pickupDate + OLEConstants.PICKUP_NOTICE_FINAL_CONTENT);
2328 oleNoticeBo.setAuthor(author);
2329 oleNoticeBo.setItemCallNumber(callNumber);
2330 oleNoticeBo.setItemId(itemBarcode);
2331 oleNoticeBo.setTitle(title);
2332 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
2333 String content = oleDeliverBatchService.getEmailPickUpNotice(oleNoticeBo);
2334 try {
2335 if (!content.trim().equals("")) {
2336 OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
2337 oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(content), true);
2338 if (LOG.isDebugEnabled()) {
2339 LOG.debug("Mail send Successfully to " + oleNoticeBo.getPatronEmailAddress());
2340 }
2341 oleDeliverBatchService.getPdfPickUpNotice(oleNoticeBo);
2342 } else {
2343 if (LOG.isDebugEnabled()) {
2344 LOG.debug("Notice Type :" + oleNoticeBo.getNoticeName() + " " + "Item Barcode : " + oleNoticeBo.getItemId() + " " + "Patron Name :" + oleNoticeBo.getPatronName());
2345 }
2346 }
2347 }catch(Exception e){
2348 LOG.error("Exception", e);
2349 olePlaceRequest.setCode("020");
2350 olePlaceRequest.setQueuePosition(String.valueOf(oleDeliverRequestBo.getBorrowerQueuePosition()));
2351 olePlaceRequest.setMessage(OLEConstants.RQST_SUCCESS + requestId + OLEConstants.NTCE_PRBLM);
2352 olePlaceRequest.setRequestId(oleDeliverRequestBoList.get(0).getRequestId());
2353 olePlaceRequest.setAvailableDate(getAvailableDate(itemBarcode));
2354 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2355 }
2356 } }
2357 catch (Exception e) {
2358 LOG.error("Exception", e);
2359 olePlaceRequest.setCode("020");
2360 olePlaceRequest.setQueuePosition(String.valueOf(oleDeliverRequestBo.getBorrowerQueuePosition()));
2361 olePlaceRequest.setMessage(OLEConstants.RQST_SUCCESS + requestId + OLEConstants.RQST_PRBLM);
2362 olePlaceRequest.setRequestId(oleDeliverRequestBoList.get(0).getRequestId());
2363 olePlaceRequest.setAvailableDate(getAvailableDate(itemBarcode));
2364 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2365
2366 }
2367 olePlaceRequest.setCode("021");
2368 olePlaceRequest.setRequestId(oleDeliverRequestBoList.get(0).getRequestId());
2369 olePlaceRequest.setAvailableDate(getAvailableDate(itemBarcode));
2370 olePlaceRequest.setQueuePosition(String.valueOf(oleDeliverRequestBo.getBorrowerQueuePosition()));
2371 olePlaceRequest.setMessage(OLEConstants.RQST_SUCCESS + requestId);
2372 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2373 } catch (Exception e) {
2374 LOG.error("Exception", e);
2375 if (e.getMessage()!=null && e.getMessage().equalsIgnoreCase("Item barcode does not exist.")) {
2376 olePlaceRequest.setCode("014");
2377 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_BARCODE_DOESNOT_EXISTS));
2378 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2379 }
2380 olePlaceRequest.setCode("023");
2381 olePlaceRequest.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RQST_FAIL));
2382 return olePlaceRequestConverter.generatePlaceRequestXml(olePlaceRequest);
2383 }
2384 }
2385
2386 public String getAvailableDate(String itemBarcode){
2387 Map<String,String> loanMap =new HashMap<>();
2388 loanMap.put(OLEConstants.OleDeliverRequest.ITEM_ID,itemBarcode);
2389 String date = null;
2390 List<OleLoanDocument> loanDocuments = (List<OleLoanDocument>)getBusinessObjectService().findMatching(OleLoanDocument.class, loanMap);
2391 if(loanDocuments.size()>0){
2392 date = loanDocuments.get(0).getLoanDueDate().toString();
2393 }else {
2394 SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
2395 simpleDateFormat.applyPattern(OLEConstants.GREGORIAN_PATTERN);
2396 date = simpleDateFormat.format(new Timestamp(new java.sql.Date(System.currentTimeMillis()).getTime()));
2397 }
2398 return date;
2399 }
2400
2401
2402 public java.sql.Date addDate(java.sql.Date in, int daysToAdd) {
2403 if (in == null) {
2404 return null;
2405 }
2406 GregorianCalendar cal = new GregorianCalendar();
2407 cal.setTime(in);
2408 cal.add(Calendar.DAY_OF_MONTH, daysToAdd);
2409 return new java.sql.Date(cal.getTime().getTime());
2410 }
2411
2412 public EngineResults executeEngineResults(OleDeliverRequestBo oleDeliverRequestBo) {
2413 List<OleDeliverRequestBo> recallList = new ArrayList<OleDeliverRequestBo>();
2414 List<OleDeliverRequestBo> holdList = new ArrayList<OleDeliverRequestBo>();
2415 List<OleDeliverRequestBo> pageList = new ArrayList<OleDeliverRequestBo>();
2416 List<OleDeliverRequestBo> asrList = new ArrayList<OleDeliverRequestBo>();
2417 List<OleDeliverRequestBo> requestsByBorrower = new ArrayList<OleDeliverRequestBo>();
2418 Engine engine = KrmsApiServiceLocator.getEngine();
2419 EngineResults engineResult = null;
2420 HashMap<String, Object> agendaValue = new HashMap<String, Object>();
2421 agendaValue.put(OLEConstants.NAME_NM, OLEConstants.REQUEST_AGENDA_NM);
2422 List<AgendaBo> agendaBos = (List<AgendaBo>) KRADServiceLocator.getBusinessObjectService().findMatching(AgendaBo.class, agendaValue);
2423 if (agendaBos != null && agendaBos.size() > 0) {
2424 AgendaBo agendaBo = agendaBos.get(0);
2425 HashMap<String, String> map = new HashMap<String, String>();
2426 map.put(OLEConstants.AGENDA_NAME, agendaBo.getName());
2427 List<MatchBo> matchBos = (List<MatchBo>) KRADServiceLocator.getBusinessObjectService().findMatching(MatchBo.class, map);
2428
2429 SelectionCriteria selectionCriteria =
2430 SelectionCriteria.createCriteria(null, getSelectionContext(agendaBo.getContext().getName()),
2431 getAgendaContext(OLEConstants.REQUEST_AGENDA_NM));
2432
2433 ExecutionOptions executionOptions = new ExecutionOptions();
2434 executionOptions.setFlag(ExecutionFlag.LOG_EXECUTION, true);
2435
2436 Facts.Builder factBuilder = Facts.Builder.create();
2437
2438 String borrowerType = "";
2439 if (oleDeliverRequestBo.getOlePatron() != null && oleDeliverRequestBo.getOlePatron().getOleBorrowerType() != null) {
2440 borrowerType = oleDeliverRequestBo.getOlePatron().getOleBorrowerType().getBorrowerTypeCode();
2441 }
2442 String itemType = oleDeliverRequestBo.getItemType();
2443
2444 String requestTypeId = oleDeliverRequestBo.getRequestTypeId();
2445
2446 String requestType = oleDeliverRequestBo.getRequestTypeCode();
2447
2448 String location = oleDeliverRequestBo.getShelvingLocation();
2449 OleLoanDocument oleLoanDocument = getLoanProcessor().getOleLoanDocumentUsingItemUUID(oleDeliverRequestBo.getItemUuid());
2450 DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
2451 dataCarrierService.addData(OLEConstants.LOANED_DATE, oleLoanDocument != null ? oleLoanDocument.getCreateDate() : null);
2452 dataCarrierService.addData(OLEConstants.DUE_DATE,oleLoanDocument!=null?oleLoanDocument.getLoanDueDate():null);
2453 dataCarrierService.addData(OLEConstants.CIRC_POLICY_FOUND, null);
2454 String borrowerId = oleDeliverRequestBo.getBorrowerId();
2455 Map<String, String> requestMap = new HashMap<String, String>();
2456 requestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
2457 if (requestTypeId != null && (requestTypeId.equals("1") || requestTypeId.equals("2"))) {
2458 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "1");
2459 recallList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
2460 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "2");
2461 recallList.addAll((List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap));
2462 } else if (requestTypeId != null && (requestTypeId.equals("3") || requestTypeId.equals("4"))) {
2463
2464 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "3");
2465 holdList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
2466 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "4");
2467 holdList.addAll((List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap));
2468 } else if (requestTypeId != null && (requestTypeId.equals("5") || requestTypeId.equals("6"))) {
2469
2470 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "5");
2471 pageList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
2472 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "6");
2473 pageList.addAll((List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap));
2474 }else if (requestTypeId != null && (requestTypeId.equals("9"))) {
2475 requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "9");
2476 asrList.addAll((List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap));
2477 }
2478 Map<String, String> requestByBorrower = new HashMap<String, String>();
2479 requestByBorrower.put(OLEConstants.OleDeliverRequest.BORROWER_ID, borrowerId);
2480 requestsByBorrower = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestByBorrower);
2481 HashMap<String, Object> termValues = new HashMap<String, Object>();
2482 termValues.put(OLEConstants.BORROWER_TYPE, borrowerType);
2483 termValues.put(OLEConstants.ITEM_TYPE, itemType);
2484 termValues.put(OLEConstants.LOCATION, location);
2485 termValues.put(OLEConstants.ITEM_SHELVING, oleDeliverRequestBo.getShelvingLocation());
2486 termValues.put(OLEConstants.ITEM_COLLECTION, oleDeliverRequestBo.getItemCollection());
2487 termValues.put(OLEConstants.ITEM_LIBRARY, oleDeliverRequestBo.getItemLibrary());
2488 termValues.put(OLEConstants.ITEM_CAMPUS, oleDeliverRequestBo.getItemCampus());
2489 termValues.put(OLEConstants.ITEM_INSTITUTION, oleDeliverRequestBo.getItemInstitution());
2490 termValues.put(OLEConstants.MAX_NO_OF_RECALL_REQUEST, new Integer(recallList.size()) + 1);
2491 termValues.put(OLEConstants.MAX_NO_OF_HOLD_REQUEST, new Integer(holdList.size()) + 1);
2492 termValues.put(OLEConstants.MAX_NO_OF_PAGE_REQUEST, new Integer(pageList.size()) + 1);
2493 termValues.put(OLEConstants.MAX_NO_OF_ASR_REQUEST, new Integer(asrList.size()) + 1);
2494
2495 termValues.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, requestTypeId);
2496 termValues.put(OLEConstants.REQUEST_TYPE, requestType);
2497
2498
2499 for (Iterator<MatchBo> matchBoIterator = matchBos.iterator(); matchBoIterator.hasNext(); ) {
2500 MatchBo matchBo = matchBoIterator.next();
2501 factBuilder.addFact(matchBo.getTermName(), termValues.get((matchBo.getTermName())));
2502 }
2503 if (LOG.isDebugEnabled()) {
2504 LOG.debug("termValues.toString()" + termValues.toString());
2505 }
2506 engineResult = engine.execute(selectionCriteria, factBuilder.build(), executionOptions);
2507 List<String> errorMessage = (List<String>) engineResult.getAttribute(OLEConstants.ERROR_ACTION);
2508 java.sql.Date d = (java.sql.Date) engineResult.getAttribute(OLEConstants.REQ_EXPIRATION_DATE);
2509 Timestamp recallDueDate = (Timestamp) engineResult.getAttribute(OLEConstants.RECALL_DUE_DATE);
2510 String notice = (String) engineResult.getAttribute(OLEConstants.NOTICE);
2511 oleDeliverRequestBo.setNoticeType(notice);
2512 if (recallDueDate != null && oleLoanDocument.getLoanDueDate()!=null && oleLoanDocument.getLoanDueDate().compareTo(recallDueDate) > 0) {
2513 oleLoanDocument.setLoanDueDate(recallDueDate);
2514 oleDeliverRequestBo.setRecallDueDate(recallDueDate);
2515 getBusinessObjectService().save(oleLoanDocument);
2516 }
2517 oleDeliverRequestBo.setRequestExpiryDate(d);
2518 StringBuffer failures = new StringBuffer();
2519 if (errorMessage != null && errorMessage.size() > 0) {
2520 int i = 1;
2521 for (String errMsg : errorMessage) {
2522 failures.append(i++ + ". " + errMsg + OLEConstants.BREAK);
2523 }
2524 }
2525 if (!failures.toString().isEmpty()) {
2526 oleDeliverRequestBo.setMessage(failures.toString());
2527 }
2528 dataCarrierService.addData(OLEConstants.ERROR_ACTION, null);
2529 }
2530 return engineResult;
2531 }
2532
2533
2534
2535
2536
2537
2538
2539 protected Map<String, String> getSelectionContext(String contextName) {
2540 Map<String, String> selector = new HashMap<String, String>();
2541 selector.put(NAMESPACE_CODE_SELECTOR, OLEConstants.OLE_NAMESPACE);
2542 selector.put(NAME_SELECTOR, contextName);
2543 return selector;
2544 }
2545
2546
2547
2548
2549
2550
2551
2552 protected Map<String, String> getAgendaContext(String agendaName) {
2553 Map<String, String> selector = new HashMap<String, String>();
2554 selector.put(NAME_SELECTOR, agendaName);
2555 return selector;
2556 }
2557
2558 public OleCirculationDesk getOleCirculationDesk(String circulationDeskId) {
2559 Map<String, String> circulationDeskMap = new HashMap<String, String>();
2560 circulationDeskMap.put(OLEConstants.CIRCULATION_DESK_ID, circulationDeskId);
2561 List<OleCirculationDesk> oleCirculationDeskList = (List<OleCirculationDesk>) getBusinessObjectService().findMatching(OleCirculationDesk.class, circulationDeskMap);
2562 if (oleCirculationDeskList != null && oleCirculationDeskList.size() > 0) {
2563 return oleCirculationDeskList.get(0);
2564 } else
2565 return null;
2566 }
2567
2568 private RoleService getRoleService() {
2569 RoleService service = KimApiServiceLocator.getRoleService();
2570 return service;
2571 }
2572 public boolean checkForOverdueNotice(Date expDate){
2573 Date curDat = new Date();
2574 if(expDate!=null && curDat.compareTo(expDate)<=0){
2575 return false;
2576 }
2577 return true;
2578 }
2579
2580
2581 public Map<String,String> getLocationMap(String itemLocation){
2582 Map<String,String> locationMap = new HashMap<String,String>();
2583 String[] locationArray = itemLocation.split("['/']");
2584 List<String> locationList = Arrays.asList(locationArray);
2585 for(String value : locationList){
2586 Map<String,String> requestMap = new HashMap<>();
2587 requestMap.put(OLEConstants.LOCATION_CODE,value);
2588 List<OleLocation> oleLocations = (List<OleLocation>)getBusinessObjectService().findMatching(OleLocation.class,requestMap);
2589 if(oleLocations!=null && oleLocations.size()>0){
2590 String locationLevelId = oleLocations.get(0).getLevelId();
2591 requestMap.clear();
2592 requestMap.put(OLEConstants.LEVEL_ID,locationLevelId);
2593 List<OleLocationLevel> oleLocationLevels = (List<OleLocationLevel>)getBusinessObjectService().findMatching(OleLocationLevel.class,requestMap);
2594 if(oleLocationLevels!=null && oleLocationLevels.size()>0){
2595 OleLocationLevel oleLocationLevel = new OleLocationLevel();
2596 oleLocationLevel = oleLocationLevels.get(0);
2597 if(oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_CAMPUS)){
2598 locationMap.put(OLEConstants.ITEM_CAMPUS, value);
2599 }else if(oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_INSTITUTION)){
2600 locationMap.put(OLEConstants.ITEM_INSTITUTION,value);
2601 }else if(oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_COLLECTION)){
2602 locationMap.put(OLEConstants.ITEM_COLLECTION,value);
2603 }else if(oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_LIBRARY)){
2604 locationMap.put(OLEConstants.ITEM_LIBRARY,value);
2605 }else if(oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_SHELVING)){
2606 locationMap.put(OLEConstants.ITEM_SHELVING,value);
2607 }
2608 }
2609 }
2610 }
2611 return locationMap;
2612 }
2613
2614
2615
2616 public org.kuali.ole.docstore.common.document.Item retrieveItemWithBibAndHoldingData(String itemUUID){
2617 org.kuali.ole.docstore.common.document.Item item = null;
2618 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
2619 HoldingOlemlRecordProcessor holdingsOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
2620 try{
2621
2622 item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(itemUUID);
2623
2624 Item item1 = itemOlemlRecordProcessor.fromXML(item.getContent());
2625 item = populateInfoFromInstanceItemToDocItem(item1,item);
2626 OleHoldings oleHoldings = holdingsOlemlRecordProcessor.fromXML(item.getHolding().getContent());
2627 Holdings holdings = populateInfoFromInstanceHoldingToDocHoldings(oleHoldings,item.getHolding());
2628 item.setHolding(holdings);
2629 }catch (Exception e){
2630 LOG.error(e);
2631 }
2632 return item;
2633 }
2634
2635
2636
2637 public org.kuali.ole.docstore.common.document.Item populateInfoFromInstanceItemToDocItem(Item instanceItem,org.kuali.ole.docstore.common.document.Item documentItem){
2638
2639 documentItem.setBarcode(instanceItem.getAccessInformation().getBarcode());
2640 documentItem.setAnalytic(Boolean.valueOf(instanceItem.getAnalytic()));
2641 if(instanceItem.getCallNumber()!=null){
2642 documentItem.setCallNumber(instanceItem.getCallNumber().getNumber());
2643 documentItem.setCallNumberType(instanceItem.getCallNumber().getType());
2644 documentItem.setCallNumberPrefix(instanceItem.getCallNumber().getPrefix());
2645 }
2646 documentItem.setChronology(instanceItem.getChronology());
2647 documentItem.setCopyNumber(instanceItem.getCopyNumber());
2648 if(instanceItem.getItemStatus()!=null){
2649 documentItem.setItemStatus(instanceItem.getItemStatus().getCodeValue());
2650 }
2651 if(instanceItem.getItemType()!=null){
2652 documentItem.setItemType(instanceItem.getItemType().getCodeValue());
2653 }
2654 documentItem.setEnumeration(instanceItem.getEnumeration());
2655 documentItem.setVolumeNumber(instanceItem.getVolumeNumber());
2656
2657 return documentItem;
2658 }
2659
2660 public org.kuali.ole.docstore.common.document.Holdings populateInfoFromInstanceHoldingToDocHoldings(OleHoldings oleHoldings ,Holdings holdings) {
2661 if(oleHoldings.getCallNumber()!=null) {
2662 holdings.setCallNumber(oleHoldings.getCallNumber().getNumber());
2663 holdings.setCallNumberPrefix(oleHoldings.getCallNumber().getPrefix());
2664 holdings.setCallNumberType(oleHoldings.getCallNumber().getType());
2665 }
2666 holdings.setCopyNumber(oleHoldings.getCopyNumber());
2667 holdings.setHoldingsType(oleHoldings.getHoldingsType());
2668
2669 return holdings;
2670 }
2671
2672
2673
2674 public Map retrieveBIbItemHoldingData(String itemUUID){
2675 Map<String,Object> bibMap = new HashMap<String,Object>();
2676 org.kuali.ole.docstore.common.document.Item item = null;
2677 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
2678 HoldingOlemlRecordProcessor holdingsOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
2679 try{
2680 item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(itemUUID);
2681 bibMap.put(OLEConstants.DOCUMENT_ITEM,item);
2682 bibMap.put(OLEConstants.BIB,item.getHolding().getBib());
2683 Item item1 = itemOlemlRecordProcessor.fromXML(item.getContent());
2684 bibMap.put(OLEConstants.ITEM,item1);
2685 OleHoldings oleHoldings = holdingsOlemlRecordProcessor.fromXML(item.getHolding().getContent());
2686 bibMap.put(OLEConstants.HOLDING,oleHoldings);
2687 }catch (Exception e){
2688 LOG.error(e);
2689 }
2690 return bibMap;
2691
2692 }
2693
2694 private void getNoticeList(List<OleLoanDocument> oleLoanDocuments, OlePatronDocument olePatronDocument, boolean overdue, String courtesyInterval, List<String> itemIds) {
2695 Long b1 = System.currentTimeMillis();
2696 List<OleLoanDocument> oleOverDueNoticeBoList = new ArrayList<>();
2697 List<OleLoanDocument> oleCourtesyNoticeList = new ArrayList<>();
2698 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
2699 StringBuffer mailContent = new StringBuffer();
2700 Document document=null;
2701 OutputStream outputStream = null;
2702 try {
2703 String overdueNoticeType = getLoanProcessor().getParameter(OLEParameterConstants.OVERDUE_NOTICE_TYPE);
2704 String courtesyNoticeType = getLoanProcessor().getParameter(OLEParameterConstants.COURTESY_NOTICE_TYPE);
2705 DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
2706 HashMap<String, org.kuali.ole.docstore.common.document.Item> itemMap = getDocstoreClientLocator().getDocstoreClient().retrieveItemMap(itemIds);
2707 mailContent.append(oleDeliverBatchService.getHeaderAndPatronContent(olePatronDocument, overdue));
2708 oleDeliverBatchService.getHeaderAndPatronPDFContent(olePatronDocument,overdue);
2709 document=oleDeliverBatchService.getOverdueDocument();
2710 outputStream=oleDeliverBatchService.getOverdueOutPutStream();
2711 for (OleLoanDocument oleLoanDocument : oleLoanDocuments) {
2712 org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
2713 item = itemMap.get(oleLoanDocument.getItemUuid());
2714 oleLoanDocument.setInstanceUuid(item.getHolding().getId());
2715 String itemXml = item.getContent();
2716 oleLoanDocument.setTitle(item.getHolding().getBib().getTitle());
2717 oleLoanDocument.setAuthor(item.getHolding().getBib().getAuthor());
2718 oleLoanDocument.setItemVolumeNumber(item.getVolumeNumber());
2719 Item oleItem = getLoanProcessor().getItemPojo(itemXml);
2720 if (oleItem != null && oleItem.getCallNumber() != null) {
2721 oleLoanDocument.setItemCallNumber(oleItem.getCallNumber().getNumber());
2722 }
2723 oleLoanDocument.setOleItem(oleItem);
2724 oleLoanDocument.setOlePatron(olePatronDocument);
2725 Date dueDate = oleLoanDocument.getLoanDueDate();
2726 Date currentDate = new Date();
2727 Integer dueDateDiffInterval = determineDifferenceInDays(dueDate, currentDate);
2728 DateFormat formatter = new SimpleDateFormat(OLEConstants.DAT_FORMAT_EFFECTIVE_NOTICE);
2729 if (LOG.isDebugEnabled()) {
2730 LOG.debug("oleItem.getItemStatusEffectiveDate()" + oleItem.getItemStatusEffectiveDate());
2731 }
2732 Date itemStatusEffectiveDate = (Date) formatter.parse(oleItem.getItemStatusEffectiveDate());
2733 Integer numberOfDaysOnHold = determineDifferenceInDays(itemStatusEffectiveDate, currentDate);
2734 Integer dueDateSumInterval = determineDifferenceInDays(currentDate, dueDate);
2735 Integer overdueNoticeInterval = Integer.parseInt(getIntervalForOverdueNotice());
2736 Integer intervalWithNoticeCount = 0;
2737 Integer loanNoOfOverdueNoticeSent = oleLoanDocument.getNumberOfOverdueNoticesSent() != null ? Integer.parseInt(oleLoanDocument.getNumberOfOverdueNoticesSent()) : 0;
2738 if (oleLoanDocument.getNumberOfOverdueNoticesSent() != null) {
2739 intervalWithNoticeCount = Integer.parseInt(oleLoanDocument.getNumberOfOverdueNoticesSent()) + 1;
2740 } else {
2741 intervalWithNoticeCount = intervalWithNoticeCount + 1;
2742 }
2743 dueDateSumInterval = dueDateSumInterval / intervalWithNoticeCount;
2744 if (dueDateSumInterval < 0) {
2745 dueDateSumInterval = 0;
2746 }
2747 if (dueDateDiffInterval < 0) {
2748 dueDateDiffInterval = 0;
2749 }
2750 Integer maxNumberOfDaysOnHold = 0;
2751 OleCirculationDesk oleCirculationDesk = null;
2752 if (oleLoanDocument.getCirculationLocationId() != null) {
2753 oleCirculationDesk = getLoanProcessor().getOleCirculationDesk(oleLoanDocument.getCirculationLocationId());
2754 String maxNumOfDays = oleCirculationDesk.getOnHoldDays() != null ? oleCirculationDesk.getOnHoldDays() : getLoanProcessor().getParameter(OLEConstants.MAX_NO_OF_DAYS_ON_HOLD);
2755 maxNumberOfDaysOnHold = new Integer(maxNumOfDays);
2756 }
2757 if (oleItem.getTemporaryItemType() != null && oleItem.getTemporaryItemType().getCodeValue() != "") {
2758 OleInstanceItemType oleInstanceItemType = getLoanProcessor().getItemTypeIdByItemType(oleItem.getTemporaryItemType().getCodeValue());
2759 oleLoanDocument.setItemTypeName(oleInstanceItemType.getInstanceItemTypeCode());
2760 } else if (oleItem.getItemType() != null && oleItem.getItemType().getCodeValue() != "") {
2761 OleInstanceItemType oleInstanceItemType = getLoanProcessor().getItemTypeIdByItemType(oleItem.getItemType().getCodeValue());
2762 oleLoanDocument.setItemTypeName(oleInstanceItemType.getInstanceItemTypeCode());
2763 }
2764 OleDeliverRequestBo oleDeliverRequestBo = getLoanProcessor().getPrioritizedRequest(oleLoanDocument.getItemUuid());
2765 getLoanProcessor().getLocation(oleItem, oleLoanDocument);
2766 String agendaName = OLEConstants.NOTICE_AGENDA_NM;
2767 dataCarrierService.addData(OLEConstants.CIRC_POLICY_FOUND, null);
2768 HashMap<String, Object> termValues = new HashMap<String, Object>();
2769 Date expirationDate = olePatronDocument != null ? olePatronDocument.getExpirationDate() : null;
2770 termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode());
2771 termValues.put(OLEConstants.ITEM_TYPE, oleLoanDocument.getItemTypeName());
2772 termValues.put(OLEConstants.OVERLAY_ITEM_LOCATION, oleLoanDocument.getItemLocation());
2773 termValues.put(OLEConstants.DUE_DATE_DIFF_INTERVAL, dueDateDiffInterval);
2774 if (oleItem.getItemStatus() != null)
2775 termValues.put(OLEConstants.ITEM_STATUS, oleItem.getItemStatus().getCodeValue());
2776 termValues.put(OLEConstants.NO_OF_DAYS_ON_HOLD, numberOfDaysOnHold);
2777 termValues.put(OLEConstants.MAX_NO_OF_DAYS_ONHOLD, maxNumberOfDaysOnHold);
2778 termValues.put(OLEConstants.OleDeliverRequest.CLAIM_RETURNED, oleItem.isClaimsReturnedFlag() ? "true" : "false");
2779 termValues.put(OLEConstants.OleDeliverRequest.REPLACEMENT_FEE_PATRON_BILL, oleLoanDocument.getRepaymentFeePatronBillId() != null ? "true" : "false");
2780 termValues.put(OLEConstants.OleDeliverRequest.NUBER_OF_OVER_DUE_SENT, loanNoOfOverdueNoticeSent);
2781 termValues.put(OLEConstants.OleDeliverRequest.DUE_DATE_SUM_INTERVAL, dueDateSumInterval);
2782 termValues.put(OLEConstants.OleDeliverRequest.CONFIGURABLE_INTERVAL, Integer.parseInt(courtesyInterval));
2783 termValues.put(OLEConstants.OleDeliverRequest.INTERVAL_WITH_NOTICE_COUNT, intervalWithNoticeCount);
2784 termValues.put(OLEConstants.ITEM_SHELVING, oleLoanDocument.getItemLocation());
2785 termValues.put(OLEConstants.ITEM_COLLECTION, oleLoanDocument.getItemCollection());
2786 termValues.put(OLEConstants.ITEM_LIBRARY, oleLoanDocument.getItemLibrary());
2787 termValues.put(OLEConstants.ITEM_CAMPUS, oleLoanDocument.getItemCampus());
2788 termValues.put(OLEConstants.ITEM_INSTITUTION, oleLoanDocument.getItemInstitution());
2789 termValues.put(OLEConstants.REQUEST_TYPE, oleDeliverRequestBo != null ? oleDeliverRequestBo.getRequestTypeCode() : null);
2790 termValues.put(OLEConstants.EXPIR_DATE, expirationDate);
2791 if (LOG.isDebugEnabled()) {
2792 LOG.debug("termValues.toString()" + termValues.toString());
2793 }
2794 EngineResults engineResults = getLoanProcessor().getEngineResults(agendaName, termValues);
2795 String notice = (String) engineResults.getAttribute(OLEConstants.NOTICE);
2796 String itemStatus = (String) engineResults.getAttribute(OLEConstants.ITEM_STATUS);
2797 BigDecimal replacementBill = (BigDecimal) engineResults.getAttribute(OLEConstants.REPLACEMENT_BILL);
2798 List<String> errorMessage = (List<String>) engineResults.getAttribute(OLEConstants.ERROR_ACTION);
2799 if (errorMessage != null && LOG.isDebugEnabled()) {
2800 LOG.debug("errorMessage" + errorMessage.toString());
2801 }
2802 if (LOG.isDebugEnabled()) {
2803 LOG.debug("notice" + notice);
2804 }
2805 agendaName = OLEConstants.BATCH_PROGRAM_AGENDA;
2806 termValues = new HashMap<String, Object>();
2807 String deskLocation = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskCode() : "";
2808 String deskLocationName = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskPublicName() : "";
2809 termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode());
2810 termValues.put(OLEConstants.DESK_LOCATION, deskLocation);
2811 termValues.put(OLEConstants.NOTICE, notice);
2812 engineResults = getLoanProcessor().getEngineResults(agendaName, termValues);
2813 String noticeType = (String) engineResults.getAttribute(OLEConstants.NOTICE_TYPE);
2814 errorMessage = (List<String>) engineResults.getAttribute(OLEConstants.ERROR_ACTION);
2815 if (errorMessage != null && LOG.isDebugEnabled()) {
2816 LOG.debug("errorMessage" + errorMessage);
2817 }
2818 if (LOG.isDebugEnabled()) {
2819 LOG.debug("noticeType" + noticeType);
2820 }
2821 if (itemStatus != null) {
2822 int noOfOverdueNoticeSent = Integer.parseInt(oleLoanDocument.getNumberOfOverdueNoticesSent() != null ? oleLoanDocument.getNumberOfOverdueNoticesSent() : "0");
2823 noOfOverdueNoticeSent = noOfOverdueNoticeSent + 1;
2824 oleLoanDocument.setNumberOfOverdueNoticesSent(Integer.toString(noOfOverdueNoticeSent));
2825 oleLoanDocument.setOverDueNoticeDate(new java.sql.Date(System.currentTimeMillis()));
2826 String billNumber = getLoanProcessor().generatePatronBillPayment(oleLoanDocument, OLEConstants.REPLACEMENT_FEE, replacementBill);
2827 oleLoanDocument.setRepaymentFeePatronBillId(billNumber);
2828 getBusinessObjectService().save(oleLoanDocument);
2829 getLoanProcessor().updateItemStatus(oleItem, itemStatus);
2830 }
2831 if (notice != null) {
2832 if (notice.equalsIgnoreCase(OLEConstants.NOTICE_OVERDUE)) {
2833 oleOverDueNoticeBoList.add(oleLoanDocument);
2834 mailContent.append(oleDeliverBatchService.getOverdueNoticeHTMLContent(oleLoanDocument));
2835 noticeType = noticeType == null ? overdueNoticeType : noticeType;
2836 oleDeliverBatchService.getOverdueNoticePDFContent(oleLoanDocument,overdue,document);
2837 } else if (notice.equalsIgnoreCase(OLEConstants.NOTICE_COURTESY) && olePatronDocument.isCourtesyNotice() && !oleLoanDocument.isCourtesyNoticeFlag()) {
2838 oleCourtesyNoticeList.add(oleLoanDocument);
2839 mailContent.append(oleDeliverBatchService.getOverdueNoticeHTMLContent(oleLoanDocument));
2840 oleDeliverBatchService.getOverdueNoticePDFContent(oleLoanDocument,overdue,document);
2841 noticeType = noticeType == null ? courtesyNoticeType : noticeType;
2842 }
2843 }
2844 olePatronDocument = oleLoanDocument.getOlePatron();
2845 if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.SMS)) {
2846
2847 }
2848 }
2849 } catch (Exception e) {
2850 LOG.error("Exception in generateNotices()" + e.getMessage(), e);
2851 }
2852 Long b2 = System.currentTimeMillis();
2853 Long b3 = b2 - b1;
2854 LOG.info("" + b3);
2855 boolean isFileNeedToDelete=true;
2856 if (overdue) {
2857 if (oleOverDueNoticeBoList != null && oleOverDueNoticeBoList.size() > 0) {
2858 sendMailsToPatron(olePatronDocument, mailContent.toString());
2859 try {
2860 if (document != null && outputStream!=null) {
2861 oleDeliverBatchService.getPdfFooter(document,outputStream);
2862 isFileNeedToDelete=false;
2863 }
2864 } catch (Exception e){
2865 LOG.error("PDF overdue notice error");
2866 }
2867
2868 }
2869 } else {
2870 if (oleCourtesyNoticeList != null && oleCourtesyNoticeList.size() > 0) {
2871 sendMailsToPatron(olePatronDocument, mailContent.toString());
2872 try {
2873 if (document != null && outputStream!=null) {
2874 oleDeliverBatchService.getPdfFooter(document,outputStream);
2875 isFileNeedToDelete=false;
2876 }
2877 } catch (Exception e){
2878 LOG.error("PDF overdue notice error");
2879 }
2880 }
2881 }
2882 if(isFileNeedToDelete){
2883 oleDeliverBatchService.cleanZeroByteFiles();
2884 }
2885
2886 }
2887
2888 private void sendMailsToPatron(OlePatronDocument olePatronDocument, String noticeContent) {
2889
2890 Long b1 = System.currentTimeMillis();
2891 OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
2892 String emailAddress = "";
2893 try {
2894 EntityTypeContactInfoBo entityTypeContactInfoBo = olePatronDocument.getEntity().getEntityTypeContactInfos().get(0);
2895 emailAddress = getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : "";
2896 } catch (Exception e) {
2897 LOG.error("Unable to get Patron Email Address --sendMailsToPatron--" + e.getMessage(), e);
2898 }
2899 try {
2900 String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
2901 if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
2902 fromAddress = OLEConstants.KUALI_MAIL;
2903 }
2904
2905 if (emailAddress != null && !emailAddress.isEmpty()) {
2906 noticeContent = noticeContent.replace('[', ' ');
2907 noticeContent = noticeContent.replace(']', ' ');
2908 if (!noticeContent.trim().equals("")) {
2909 OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
2910 oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(emailAddress), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(noticeContent), true);
2911 }
2912 } else {
2913 LOG.error("Patron Email Address --sendMailsToPatron-- is Empty or Null");
2914 }
2915 } catch (Exception e) {
2916 LOG.error("Exception in generateNotices()" + e.getMessage(), e);
2917 }
2918 Long b2 = System.currentTimeMillis();
2919 Long total = b2 - b1;
2920 LOG.info("The time taken sending mail :" + total);
2921 }
2922
2923
2924 }
2925
2926
2927
2928
2929
2930