View Javadoc

1   package org.kuali.ole.batch.service;
2   
3   import org.apache.log4j.Logger;
4   import org.kuali.ole.OLEConstants;
5   import org.kuali.ole.OLEParameterConstants;
6   import org.kuali.ole.batch.bo.*;
7   import org.kuali.ole.batch.form.OLEDeliverNoticeForm;
8   import org.kuali.ole.deliver.processor.LoanProcessor;
9   import org.kuali.rice.core.api.config.property.ConfigContext;
10  
11  import java.io.File;
12  import java.util.ArrayList;
13  import java.util.List;
14  
15  /**
16   * Created with IntelliJ IDEA.
17   * User: maheswarang
18   * Date: 8/7/13
19   * Time: 8:09 PM
20   * To change this template use File | Settings | File Templates.
21   */
22  public class OLEDeliverNoticeService {
23      private static final Logger LOG = Logger.getLogger(OLEDeliverNoticeService.class);
24      private LoanProcessor loanProcessor = new LoanProcessor();
25  
26      public OLEDeliverNoticeForm populateOLEDeliverNoticeForm(OLEDeliverNoticeForm oleDeliverNoticeForm){
27  
28          List<File> expiredRequestList= new ArrayList<File>();
29          List<File> courtesyNoticeList = new ArrayList<File>();
30          List<File> overDueNoticeList = new ArrayList<File>();
31          List<File> onHoldNoticeList = new ArrayList<File>();
32          List<File> recallNoticeList=new ArrayList<File>();
33          List<File> pickupNoticeList=new ArrayList<File>();
34          List<File> onHoldCourtesyNoticeList = new ArrayList<File>();
35          String pdfLocationSystemParam = loanProcessor.getParameter(OLEParameterConstants.PDF_LOCATION);
36          if (pdfLocationSystemParam == null || pdfLocationSystemParam.trim().isEmpty()) {
37              pdfLocationSystemParam = ConfigContext.getCurrentContextConfig().getProperty("staging.directory") + "/";
38          } else{
39              pdfLocationSystemParam = ConfigContext.getCurrentContextConfig().getProperty("homeDirectory")+ "/" + pdfLocationSystemParam +"/";
40          }
41          LOG.info("PDF LOCATION : " + pdfLocationSystemParam);
42          File directory = new File(pdfLocationSystemParam);
43          File[] fList = directory.listFiles();
44          for (File file : fList) {
45              if (file.isFile()) {
46                  if(file.getName().contains(loanProcessor.getParameter(OLEParameterConstants.EXP_REQ_TITLE).replaceAll(" ", "_"))){
47                      expiredRequestList.add(file);
48                  } else if(file.getName().contains(loanProcessor.getParameter(OLEParameterConstants.COURTESY_TITLE).replaceAll(" ", "_"))){
49                      courtesyNoticeList.add(file);
50                  }else if(file.getName().contains(loanProcessor.getParameter(OLEParameterConstants.OVERDUE_TITLE).replaceAll(" ", "_"))){
51                      overDueNoticeList.add(file);
52                  }else if(file.getName().contains(loanProcessor.getParameter(OLEParameterConstants.EXPIRED_TITLE).replaceAll(" ", "_"))){
53                      onHoldCourtesyNoticeList.add(file);
54                  }else if(file.getName().contains(loanProcessor.getParameter(OLEParameterConstants.ONHOLD_TITLE).replaceAll(" ", "_"))){
55                      onHoldNoticeList.add(file);
56                  }else if(file.getName().contains(loanProcessor.getParameter(OLEParameterConstants.RECALL_TITLE).replaceAll(" ", "_"))){
57                      recallNoticeList.add(file);
58                  }
59                  else if(file.getName().contains(loanProcessor.getParameter(OLEConstants.PICKUP_NOTICE).replaceAll(" ", "_"))){
60                      pickupNoticeList.add(file);
61                  }
62              } /*else if (file.isDirectory()) {
63                  listf(file.getAbsolutePath());
64              }*/
65          }
66          oleDeliverNoticeForm.setOleRecallNoticeList(generateRecallNoticeList(recallNoticeList));
67          oleDeliverNoticeForm.setOleCourtesyNoticeList(generateCourtesyNoticeList(courtesyNoticeList));
68          oleDeliverNoticeForm.setOleExpiredRequestNoticeList(generateExpiredRequestNoticeList(expiredRequestList));
69          oleDeliverNoticeForm.setOleOnHoldCourtesyNoticeList(generateOnHoldCourtesyNoticeList(onHoldCourtesyNoticeList));
70          oleDeliverNoticeForm.setOleOnHoldNoticeList(generateOnHoldNoticeList(onHoldNoticeList));
71          oleDeliverNoticeForm.setOleOverDueNoticeList(generateOverDueNoticeList(overDueNoticeList));
72          oleDeliverNoticeForm.setOlePickupNoticeList(generatePickupNoticeList(pickupNoticeList));
73          return oleDeliverNoticeForm;
74      }
75  
76      public List<OLERecallNotice> generateRecallNoticeList(List<File> recallNoticeList) {
77          List<OLERecallNotice> oleRecallNotices = new ArrayList<OLERecallNotice>();
78          OLERecallNotice oleRecallNotice ;
79          for(File file :recallNoticeList){
80              oleRecallNotice= new OLERecallNotice();
81              oleRecallNotice.setFileName(file.getName());
82              oleRecallNotice.setFileLocation(file.getAbsolutePath());
83              oleRecallNotices.add(oleRecallNotice);
84          }
85          LOG.info("No of Recall Notices : " +oleRecallNotices.size());
86          return oleRecallNotices;
87  
88      }
89  
90  
91      public List<OLEOnHoldNotice> generateOnHoldNoticeList(List<File> onHoldNoticeList) {
92          List<OLEOnHoldNotice> oleOnHoldNoticeList = new ArrayList<OLEOnHoldNotice>();
93          OLEOnHoldNotice oleOnHoldNotice ;
94          for(File file :onHoldNoticeList){
95              oleOnHoldNotice= new OLEOnHoldNotice();
96              oleOnHoldNotice.setFileName(file.getName());
97              oleOnHoldNotice.setFileLocation(file.getAbsolutePath());
98              oleOnHoldNoticeList.add(oleOnHoldNotice);
99          }
100         LOG.info("No of OnHold Notices : " +oleOnHoldNoticeList.size());
101         return oleOnHoldNoticeList;
102     }
103 
104 
105     public List<OLEOnHoldCourtesyNotice> generateOnHoldCourtesyNoticeList(List<File> onHoldCourtesyNoticeList) {
106         List<OLEOnHoldCourtesyNotice> oleOnHoldCourtesyNoticeList = new ArrayList<OLEOnHoldCourtesyNotice>();
107         OLEOnHoldCourtesyNotice oleOnHoldCourtesyNotice ;
108         for(File file :onHoldCourtesyNoticeList){
109             oleOnHoldCourtesyNotice= new OLEOnHoldCourtesyNotice();
110             oleOnHoldCourtesyNotice.setFileName(file.getName());
111             oleOnHoldCourtesyNotice.setFileLocation(file.getAbsolutePath());
112             oleOnHoldCourtesyNoticeList.add(oleOnHoldCourtesyNotice);
113         }
114         LOG.info("No of OnHold Courtesy  Notices : " +oleOnHoldCourtesyNoticeList.size());
115         return oleOnHoldCourtesyNoticeList;
116     }
117 
118     public List<OLEOverDueNotice> generateOverDueNoticeList(List<File> overDueNoticeList) {
119         List<OLEOverDueNotice> oleOverDueNoticeList = new ArrayList<OLEOverDueNotice>();
120         OLEOverDueNotice oleOverDueNotice ;
121         for(File file :overDueNoticeList){
122             oleOverDueNotice= new OLEOverDueNotice();
123             oleOverDueNotice.setFileName(file.getName());
124             oleOverDueNotice.setFileLocation(file.getAbsolutePath());
125             oleOverDueNoticeList.add(oleOverDueNotice);
126         }
127         LOG.info("No of OverDue Notices : " +oleOverDueNoticeList.size());
128         return oleOverDueNoticeList;
129     }
130 
131     public List<OLECourtesyNotice> generateCourtesyNoticeList(List<File> courtesyNoticeList) {
132         List<OLECourtesyNotice> oleCourtesyNoticeList = new ArrayList<OLECourtesyNotice>();
133         OLECourtesyNotice oleCourtesyNotice ;
134         for(File file :courtesyNoticeList){
135             oleCourtesyNotice= new OLECourtesyNotice();
136             oleCourtesyNotice.setFileName(file.getName());
137             oleCourtesyNotice.setFileLocation(file.getAbsolutePath());
138             oleCourtesyNoticeList.add(oleCourtesyNotice);
139         }
140         LOG.info("No of Courtesy Notices : " +oleCourtesyNoticeList.size());
141         return oleCourtesyNoticeList;
142     }
143 
144     public List<OLEExpiredRequestNotice> generateExpiredRequestNoticeList(List<File> expiredRequestNoticeList) {
145         List<OLEExpiredRequestNotice> oleExpiredRequestNoticeList = new ArrayList<OLEExpiredRequestNotice>();
146         OLEExpiredRequestNotice oleExpiredRequestNotice ;
147         for(File file :expiredRequestNoticeList){
148             oleExpiredRequestNotice= new OLEExpiredRequestNotice();
149             oleExpiredRequestNotice.setFileName(file.getName());
150             oleExpiredRequestNotice.setFileLocation(file.getAbsolutePath());
151             oleExpiredRequestNoticeList.add(oleExpiredRequestNotice);
152         }
153         LOG.info("No of Expired Request  Notices : " +oleExpiredRequestNoticeList.size());
154         return oleExpiredRequestNoticeList;
155     }
156     public List<OLEPickupNotice> generatePickupNoticeList(List<File> pickupNoticeList) {
157         List<OLEPickupNotice>  olePickupNotices = new ArrayList<OLEPickupNotice>();
158         OLEPickupNotice olePickupNotice ;
159         for(File file :pickupNoticeList){
160             olePickupNotice= new OLEPickupNotice();
161             olePickupNotice.setFileName(file.getName());
162             olePickupNotice.setFileLocation(file.getAbsolutePath());
163             olePickupNotices.add(olePickupNotice);
164         }
165         LOG.info("No of Expired Request  Notices : " +olePickupNotices.size());
166         return olePickupNotices;
167     }
168 
169 }
170 
171