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
17
18
19
20
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 if (fList != null && fList.length > 0) {
45 for (File file : fList) {
46 if (file.isFile()) {
47 if (file.getName().contains(loanProcessor.getParameter(OLEParameterConstants.EXP_REQ_TITLE).replaceAll(" ", "_"))) {
48 expiredRequestList.add(file);
49 } else if (file.getName().contains(loanProcessor.getParameter(OLEParameterConstants.COURTESY_TITLE).replaceAll(" ", "_"))) {
50 courtesyNoticeList.add(file);
51 } else if (file.getName().contains(loanProcessor.getParameter(OLEParameterConstants.OVERDUE_TITLE).replaceAll(" ", "_"))) {
52 overDueNoticeList.add(file);
53 } else if (file.getName().contains(loanProcessor.getParameter(OLEParameterConstants.EXPIRED_TITLE).replaceAll(" ", "_"))) {
54 onHoldCourtesyNoticeList.add(file);
55 } else if (file.getName().contains(loanProcessor.getParameter(OLEParameterConstants.ONHOLD_TITLE).replaceAll(" ", "_"))) {
56 onHoldNoticeList.add(file);
57 } else if (file.getName().contains(loanProcessor.getParameter(OLEParameterConstants.RECALL_TITLE).replaceAll(" ", "_"))) {
58 recallNoticeList.add(file);
59 }else if (file.getName().contains(loanProcessor.getParameter(OLEParameterConstants.PICKUP_TITLE).replaceAll(" ", "_"))) {
60 pickupNoticeList.add(file);
61 }
62 }
63
64
65 }
66 }
67 oleDeliverNoticeForm.setOleRecallNoticeList(generateRecallNoticeList(recallNoticeList));
68 oleDeliverNoticeForm.setOleCourtesyNoticeList(generateCourtesyNoticeList(courtesyNoticeList));
69 oleDeliverNoticeForm.setOleExpiredRequestNoticeList(generateExpiredRequestNoticeList(expiredRequestList));
70 oleDeliverNoticeForm.setOleOnHoldCourtesyNoticeList(generateOnHoldCourtesyNoticeList(onHoldCourtesyNoticeList));
71 oleDeliverNoticeForm.setOleOnHoldNoticeList(generateOnHoldNoticeList(onHoldNoticeList));
72 oleDeliverNoticeForm.setOleOverDueNoticeList(generateOverDueNoticeList(overDueNoticeList));
73 oleDeliverNoticeForm.setOlePickupNoticeList(generatePickupNoticeList(pickupNoticeList));
74 return oleDeliverNoticeForm;
75 }
76
77 public List<OLERecallNotice> generateRecallNoticeList(List<File> recallNoticeList) {
78 List<OLERecallNotice> oleRecallNotices = new ArrayList<OLERecallNotice>();
79 OLERecallNotice oleRecallNotice ;
80 for(File file :recallNoticeList){
81 oleRecallNotice= new OLERecallNotice();
82 oleRecallNotice.setFileName(file.getName());
83 oleRecallNotice.setFileLocation(file.getAbsolutePath());
84 oleRecallNotices.add(oleRecallNotice);
85 }
86 LOG.info("No of Recall Notices : " +oleRecallNotices.size());
87 return oleRecallNotices;
88
89 }
90
91
92 public List<OLEOnHoldNotice> generateOnHoldNoticeList(List<File> onHoldNoticeList) {
93 List<OLEOnHoldNotice> oleOnHoldNoticeList = new ArrayList<OLEOnHoldNotice>();
94 OLEOnHoldNotice oleOnHoldNotice ;
95 for(File file :onHoldNoticeList){
96 oleOnHoldNotice= new OLEOnHoldNotice();
97 oleOnHoldNotice.setFileName(file.getName());
98 oleOnHoldNotice.setFileLocation(file.getAbsolutePath());
99 oleOnHoldNoticeList.add(oleOnHoldNotice);
100 }
101 LOG.info("No of OnHold Notices : " +oleOnHoldNoticeList.size());
102 return oleOnHoldNoticeList;
103 }
104
105
106 public List<OLEOnHoldCourtesyNotice> generateOnHoldCourtesyNoticeList(List<File> onHoldCourtesyNoticeList) {
107 List<OLEOnHoldCourtesyNotice> oleOnHoldCourtesyNoticeList = new ArrayList<OLEOnHoldCourtesyNotice>();
108 OLEOnHoldCourtesyNotice oleOnHoldCourtesyNotice ;
109 for(File file :onHoldCourtesyNoticeList){
110 oleOnHoldCourtesyNotice= new OLEOnHoldCourtesyNotice();
111 oleOnHoldCourtesyNotice.setFileName(file.getName());
112 oleOnHoldCourtesyNotice.setFileLocation(file.getAbsolutePath());
113 oleOnHoldCourtesyNoticeList.add(oleOnHoldCourtesyNotice);
114 }
115 LOG.info("No of OnHold Courtesy Notices : " +oleOnHoldCourtesyNoticeList.size());
116 return oleOnHoldCourtesyNoticeList;
117 }
118
119 public List<OLEOverDueNotice> generateOverDueNoticeList(List<File> overDueNoticeList) {
120 List<OLEOverDueNotice> oleOverDueNoticeList = new ArrayList<OLEOverDueNotice>();
121 OLEOverDueNotice oleOverDueNotice ;
122 for(File file :overDueNoticeList){
123 oleOverDueNotice= new OLEOverDueNotice();
124 oleOverDueNotice.setFileName(file.getName());
125 oleOverDueNotice.setFileLocation(file.getAbsolutePath());
126 oleOverDueNoticeList.add(oleOverDueNotice);
127 }
128 LOG.info("No of OverDue Notices : " +oleOverDueNoticeList.size());
129 return oleOverDueNoticeList;
130 }
131
132 public List<OLECourtesyNotice> generateCourtesyNoticeList(List<File> courtesyNoticeList) {
133 List<OLECourtesyNotice> oleCourtesyNoticeList = new ArrayList<OLECourtesyNotice>();
134 OLECourtesyNotice oleCourtesyNotice ;
135 for(File file :courtesyNoticeList){
136 oleCourtesyNotice= new OLECourtesyNotice();
137 oleCourtesyNotice.setFileName(file.getName());
138 oleCourtesyNotice.setFileLocation(file.getAbsolutePath());
139 oleCourtesyNoticeList.add(oleCourtesyNotice);
140 }
141 LOG.info("No of Courtesy Notices : " +oleCourtesyNoticeList.size());
142 return oleCourtesyNoticeList;
143 }
144
145 public List<OLEExpiredRequestNotice> generateExpiredRequestNoticeList(List<File> expiredRequestNoticeList) {
146 List<OLEExpiredRequestNotice> oleExpiredRequestNoticeList = new ArrayList<OLEExpiredRequestNotice>();
147 OLEExpiredRequestNotice oleExpiredRequestNotice ;
148 for(File file :expiredRequestNoticeList){
149 oleExpiredRequestNotice= new OLEExpiredRequestNotice();
150 oleExpiredRequestNotice.setFileName(file.getName());
151 oleExpiredRequestNotice.setFileLocation(file.getAbsolutePath());
152 oleExpiredRequestNoticeList.add(oleExpiredRequestNotice);
153 }
154 LOG.info("No of Expired Request Notices : " +oleExpiredRequestNoticeList.size());
155 return oleExpiredRequestNoticeList;
156 }
157 public List<OLEPickupNotice> generatePickupNoticeList(List<File> pickupNoticeList) {
158 List<OLEPickupNotice> olePickupNotices = new ArrayList<OLEPickupNotice>();
159 OLEPickupNotice olePickupNotice ;
160 for(File file :pickupNoticeList){
161 olePickupNotice= new OLEPickupNotice();
162 olePickupNotice.setFileName(file.getName());
163 olePickupNotice.setFileLocation(file.getAbsolutePath());
164 olePickupNotices.add(olePickupNotice);
165 }
166 LOG.info("No of Expired Request Notices : " +olePickupNotices.size());
167 return olePickupNotices;
168 }
169
170
171
172 }
173
174