1 package org.kuali.ole.deliver.service;
2
3 import org.apache.commons.lang3.StringUtils;
4 import org.apache.log4j.Logger;
5 import org.jfree.util.Log;
6 import org.kuali.ole.OLEConstants;
7 import org.kuali.ole.OLEParameterConstants;
8 import org.kuali.ole.deliver.bo.OLEDeliverNotice;
9 import org.kuali.ole.deliver.bo.OleLoanDocument;
10
11 import java.sql.Timestamp;
12 import java.util.ArrayList;
13 import java.util.Date;
14 import java.util.List;
15
16
17
18
19 public class CourtesyNoticesExecutor extends NoticesExecutor {
20 private static final Logger LOG = Logger.getLogger(CourtesyNoticesExecutor.class);
21 private NoticeMailContentFormatter noticeMailContentFormatter;
22 public CourtesyNoticesExecutor(List<OleLoanDocument> loanDocuments) {
23 super(loanDocuments);
24 }
25
26 @Override
27 protected void postProcess(List<OleLoanDocument> loanDocuments) {
28
29 }
30
31 @Override
32 protected void preProcess(List<OleLoanDocument> loanDocuments) {
33
34 }
35
36 @Override
37 public List<OLEDeliverNotice> buildNoticesForDeletion() {
38 List<OLEDeliverNotice> oleDeliverNotices = new ArrayList<>();
39 for (OleLoanDocument loanDocument:loanDocuments) {
40
41 if (loanDocument.getItemTypeName() != null) {
42 loanDocument.setItemType(getItemTypeCodeByName(loanDocument.getItemTypeName()));
43 }
44
45 for (OLEDeliverNotice oleDeliverNotice : loanDocument.getDeliverNotices()) {
46 LOG.info("CourtesyNoticesExecutor thread id---->"+Thread.currentThread().getId()+"current thread---->"+Thread.currentThread()+"Loan id-->"+loanDocument.getLoanId()+"notice id--->"+oleDeliverNotice.getId());
47 Timestamp toBeSendDate = oleDeliverNotice.getNoticeToBeSendDate();
48 if (oleDeliverNotice.getNoticeType().equals(OLEConstants.NOTICE_COURTESY) && toBeSendDate.compareTo
49 (getSendToDate(OLEConstants.COURTESY_NOTICE_TO_DATE)) < 0) {
50 try {
51 oleDeliverNotices.add(oleDeliverNotice);
52 } catch (Exception e) {
53 Log.info(e.getStackTrace());
54 }
55 }
56 }
57 }
58
59 return oleDeliverNotices;
60 }
61
62 @Override
63 public String generateMailContent(List<OleLoanDocument> oleLoanDocuments) {
64 String title = getParameterResolverInstance().getParameter(OLEConstants.APPL_ID, OLEConstants
65 .DLVR_NMSPC, OLEConstants.DLVR_CMPNT,
66 OLEParameterConstants
67 .COURTESY_TITLE);
68 String body = getParameterResolverInstance().getParameter(OLEConstants.APPL_ID_OLE, OLEConstants
69 .DLVR_NMSPC, OLEConstants.DLVR_CMPNT, OLEConstants.OleDeliverRequest.COURTESY_NOTICE_CONTENT);
70 String mailContent = getNoticeMailContentFormatter().generateMailContentForPatron(oleLoanDocuments,title,body);
71
72 return mailContent;
73 }
74
75 private NoticeMailContentFormatter getNoticeMailContentFormatter() {
76 if (null == noticeMailContentFormatter) {
77 noticeMailContentFormatter = new CourtesyNoticeEmailContentFormatter();
78 }
79 return noticeMailContentFormatter;
80 }
81
82 public void setNoticeMailContentFormatter(NoticeMailContentFormatter noticeMailContentFormatter) {
83 this.noticeMailContentFormatter = noticeMailContentFormatter;
84 }
85 }