View Javadoc
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.executors.LoanNoticesExecutor;
11  import org.kuali.ole.describe.bo.OleInstanceItemType;
12  
13  import java.sql.Timestamp;
14  import java.util.*;
15  
16  /**
17   * Created by premkb on 3/30/15.
18   */
19  public class OverdueNoticesExecutor extends LoanNoticesExecutor {
20      private static final Logger LOG = Logger.getLogger(OverdueNoticesExecutor.class);
21      private NoticeMailContentFormatter noticeMailContentFormatter;
22  
23      public OverdueNoticesExecutor(List<OleLoanDocument> loanDocuments) {
24          super(loanDocuments);
25      }
26  
27      @Override
28      protected void postProcess(List<OleLoanDocument> loanDocuments) {
29  
30      }
31  
32      @Override
33      protected void preProcess(List<OleLoanDocument> loanDocuments) {
34  
35      }
36  
37      public List<OLEDeliverNotice> buildNoticesForDeletion() {
38          List<OLEDeliverNotice> oleDeliverNotices = new ArrayList<>();
39          for (OleLoanDocument loanDocument:loanDocuments) {
40              if (loanDocument.getItemTypeName() != null) {
41                  loanDocument.setItemType(getItemTypeCodeByName(loanDocument.getItemTypeName()));
42              }
43              String overdueNoticeToDate = getParameterResolverInstance().getParameter(OLEConstants
44                      .APPL_ID_OLE, OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, OLEConstants.OVERDUE_NOTICE_TO_DATE);
45              Timestamp overdueNoticetoSendDate = new Timestamp(System.currentTimeMillis());
46              if (!StringUtils.isEmpty(overdueNoticeToDate)) {
47                  overdueNoticetoSendDate = new Timestamp(new Date(overdueNoticeToDate).getTime());
48              }
49              for (OLEDeliverNotice oleDeliverNotice : loanDocument.getDeliverNotices()) {
50                  LOG.info("OverdueNoticesExecutor thread id---->"+Thread.currentThread().getId()+"current thread---->"+Thread.currentThread()+"Loan id-->"+loanDocument.getLoanId()+"notice id--->"+oleDeliverNotice.getId());
51                  Timestamp toBeSendDate = oleDeliverNotice.getNoticeToBeSendDate();
52                  if (oleDeliverNotice.getNoticeType().equals(OLEConstants.NOTICE_OVERDUE) && toBeSendDate.compareTo(overdueNoticetoSendDate) < 0) {
53                      try {
54                          int noOfOverdueNoticeSent = Integer.parseInt(loanDocument.getNumberOfOverdueNoticesSent() != null ? loanDocument.getNumberOfOverdueNoticesSent() : "0");
55                          noOfOverdueNoticeSent = noOfOverdueNoticeSent + 1;
56                          loanDocument.setNumberOfOverdueNoticesSent(Integer.toString(noOfOverdueNoticeSent));
57                          loanDocument.setOverDueNoticeDate(new java.sql.Date(System.currentTimeMillis()));
58                          //getBusinessObjectService().save(loanDocument);
59                          oleDeliverNotices.add(oleDeliverNotice);
60                      } catch (Exception e) {
61                          Log.info(e.getStackTrace());
62                      }
63  
64                  }
65              }
66          }
67          return oleDeliverNotices;
68      }
69  
70  
71  
72      public String generateMailContent(List<OleLoanDocument> oleLoanDocuments) {
73          String title = getParameterResolverInstance().getParameter(OLEConstants.APPL_ID, OLEConstants
74                  .DLVR_NMSPC, OLEConstants.DLVR_CMPNT,
75                  OLEParameterConstants
76                          .OVERDUE_TITLE);
77          String body = getParameterResolverInstance().getParameter(OLEConstants.APPL_ID_OLE, OLEConstants
78                  .DLVR_NMSPC, OLEConstants.DLVR_CMPNT, OLEConstants.OleDeliverRequest.OVERDUE_NOTICE_CONTENT);
79          String mailContent = getNoticeMailContentFormatter().generateMailContentForPatron(oleLoanDocuments,title,body);
80  
81          return mailContent;
82      }
83  
84      private NoticeMailContentFormatter getNoticeMailContentFormatter() {
85          if (null == noticeMailContentFormatter) {
86              noticeMailContentFormatter = new OverdueNoticeEmailContentFormatter();
87          }
88          return noticeMailContentFormatter;
89      }
90  
91      public void setNoticeMailContentFormatter(NoticeMailContentFormatter noticeMailContentFormatter) {
92          this.noticeMailContentFormatter = noticeMailContentFormatter;
93      }
94  }