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