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 import org.kuali.ole.deliver.notice.bo.OleNoticeContentConfigurationBo;
11 import org.kuali.ole.deliver.notice.bo.OleNoticeFieldLabelMapping;
12 import org.kuali.ole.deliver.notice.executors.LoanNoticesExecutor;
13 import org.kuali.ole.describe.bo.OleInstanceItemType;
14
15 import java.sql.Timestamp;
16 import java.util.*;
17
18
19
20
21 public class OverdueNoticesExecutor extends LoanNoticesExecutor {
22 private static final Logger LOG = Logger.getLogger(OverdueNoticesExecutor.class);
23 private NoticeMailContentFormatter noticeMailContentFormatter;
24
25 public OverdueNoticesExecutor(List<OleLoanDocument> loanDocuments) {
26 super(loanDocuments);
27 }
28
29 @Override
30 protected String getNoticeType() {
31 return OLEConstants.NOTICE_OVERDUE;
32 }
33
34 @Override
35 protected void postProcess(List<OleLoanDocument> loanDocuments) {
36
37 }
38
39 @Override
40 protected void preProcess(List<OleLoanDocument> loanDocuments) {
41
42 }
43
44 public List<OLEDeliverNotice> buildNoticesForDeletion() {
45 List<OLEDeliverNotice> oleDeliverNotices = new ArrayList<>();
46 for (OleLoanDocument loanDocument:loanDocuments) {
47 if (loanDocument.getItemTypeName() != null) {
48 loanDocument.setItemType(getItemTypeCodeByName(loanDocument.getItemTypeName()));
49 }
50 String overdueNoticeToDate = getParameterResolverInstance().getParameter(OLEConstants
51 .APPL_ID_OLE, OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, OLEConstants.OVERDUE_NOTICE_TO_DATE);
52 Timestamp overdueNoticetoSendDate = new Timestamp(System.currentTimeMillis());
53 if (!StringUtils.isEmpty(overdueNoticeToDate)) {
54 overdueNoticetoSendDate = new Timestamp(new Date(overdueNoticeToDate).getTime());
55 }
56 for (OLEDeliverNotice oleDeliverNotice : loanDocument.getDeliverNotices()) {
57 LOG.info("OverdueNoticesExecutor thread id---->"+Thread.currentThread().getId()+"current thread---->"+Thread.currentThread()+"Loan id-->"+loanDocument.getLoanId()+"notice id--->"+oleDeliverNotice.getId());
58 Timestamp toBeSendDate = oleDeliverNotice.getNoticeToBeSendDate();
59 if (oleDeliverNotice.getNoticeType().equals(OLEConstants.OVERDUE_NOTICE) && toBeSendDate.compareTo(overdueNoticetoSendDate) < 0) {
60 try {
61 int noOfOverdueNoticeSent = Integer.parseInt(loanDocument.getNumberOfOverdueNoticesSent() != null ? loanDocument.getNumberOfOverdueNoticesSent() : "0");
62 noOfOverdueNoticeSent = noOfOverdueNoticeSent + 1;
63 loanDocument.setNumberOfOverdueNoticesSent(Integer.toString(noOfOverdueNoticeSent));
64 loanDocument.setOverDueNoticeDate(new java.sql.Date(System.currentTimeMillis()));
65
66 oleDeliverNotices.add(oleDeliverNotice);
67 } catch (Exception e) {
68 Log.info(e.getStackTrace());
69 }
70
71 }
72 }
73 }
74 return oleDeliverNotices;
75 }
76
77 @Override
78 public void setOleNoticeContentConfigurationBo() {
79 List<OleNoticeContentConfigurationBo> oleNoticeContentConfigurationBoList = null;
80 Map<String,String> noticeConfigurationMap = new HashMap<String,String>();
81 noticeConfigurationMap.put("noticeType",OLEConstants.OVERDUE_NOTICE);
82 oleNoticeContentConfigurationBoList= (List<OleNoticeContentConfigurationBo>)getBusinessObjectService().findMatching(OleNoticeContentConfigurationBo.class,noticeConfigurationMap);
83 if(oleNoticeContentConfigurationBoList!=null && oleNoticeContentConfigurationBoList.size()>0){
84 oleNoticeContentConfigurationBo = oleNoticeContentConfigurationBoList.get(0);
85 }else{
86 oleNoticeContentConfigurationBo = new OleNoticeContentConfigurationBo();
87 oleNoticeContentConfigurationBo.setNoticeTitle(getTitle());
88 oleNoticeContentConfigurationBo.setNoticeBody(getBody());
89 oleNoticeContentConfigurationBo.setNoticeFooterBody("");
90 }
91 }
92
93
94
95
96 public String getTitle() {
97 String title = getParameterResolverInstance().getParameter(OLEConstants.APPL_ID, OLEConstants
98 .DLVR_NMSPC, OLEConstants.DLVR_CMPNT,
99 OLEParameterConstants
100 .OVERDUE_TITLE);
101 return title;
102 }
103
104
105 public String getBody() {
106 String body = getParameterResolverInstance().getParameter(OLEConstants.APPL_ID_OLE, OLEConstants
107 .DLVR_NMSPC, OLEConstants.DLVR_CMPNT, OLEConstants.OleDeliverRequest.OVERDUE_NOTICE_CONTENT);
108 return body;
109 }
110
111
112 public String generateMailContent(List<OleLoanDocument> oleLoanDocuments) {
113 String mailContent = getNoticeMailContentFormatter().generateMailContentForPatron(oleLoanDocuments,oleNoticeContentConfigurationBo);
114 return mailContent;
115 }
116
117 private NoticeMailContentFormatter getNoticeMailContentFormatter() {
118 if (null == noticeMailContentFormatter) {
119 noticeMailContentFormatter = new OverdueNoticeEmailContentFormatter();
120 }
121 return noticeMailContentFormatter;
122 }
123
124 public void setNoticeMailContentFormatter(NoticeMailContentFormatter noticeMailContentFormatter) {
125 this.noticeMailContentFormatter = noticeMailContentFormatter;
126 }
127 }