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