1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.vnd.batch.service.impl;
17
18 import java.io.File;
19 import java.io.FileInputStream;
20 import java.io.FileNotFoundException;
21 import java.io.IOException;
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
25
26 import org.apache.commons.io.IOUtils;
27 import org.apache.commons.lang.StringUtils;
28 import org.kuali.ole.sys.batch.BatchInputFileType;
29 import org.kuali.ole.sys.batch.service.BatchInputFileService;
30 import org.kuali.ole.vnd.batch.dataaccess.DebarredVendorDao;
31 import org.kuali.ole.vnd.batch.dataaccess.DebarredVendorMatchDao;
32 import org.kuali.ole.vnd.batch.service.VendorExcludeService;
33 import org.kuali.ole.vnd.businessobject.DebarredVendorDetail;
34 import org.kuali.ole.vnd.businessobject.DebarredVendorMatch;
35 import org.kuali.ole.vnd.businessobject.VendorDetail;
36 import org.kuali.rice.core.api.datetime.DateTimeService;
37 import org.kuali.rice.krad.service.BusinessObjectService;
38 import org.kuali.rice.krad.util.GlobalVariables;
39 import org.springframework.transaction.annotation.Transactional;
40 @Transactional
41 public class VendorExcludeServiceImpl implements VendorExcludeService {
42 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(VendorExcludeServiceImpl.class);
43
44 private BatchInputFileService batchInputFileService;
45 private BusinessObjectService businessObjectService;
46 private DateTimeService dateTimeService;
47 private BatchInputFileType batchInputFileType;
48 private DebarredVendorDao debarredVendorDao;
49 private DebarredVendorMatchDao debarredVendorMatchDao;
50
51
52
53
54 @Override
55 public boolean loadEplsFile() {
56
57 List<String> fileNames = batchInputFileService.listInputFileNamesWithDoneFile(batchInputFileType);
58 String fileName = null;
59 long lastModified = 0;
60 if(fileNames.size() == 0) {
61 return true;
62 }
63 File tempFile;
64
65 for (String name : fileNames) {
66 tempFile = new File (name);
67 if(tempFile.lastModified() > lastModified) {
68 lastModified = tempFile.lastModified();
69 fileName = name;
70 }
71 }
72 if (fileName == null) {
73 LOG.error("BatchInputFileService.listInputFileNamesWithDoneFile(" +
74 batchInputFileType.getFileTypeIdentifer() + ") returned NULL which should never happen.");
75 throw new RuntimeException("BatchInputFileService.listInputFileNamesWithDoneFile(" +
76 batchInputFileType.getFileTypeIdentifer() + ") returned NULL which should never happen.");
77 }
78 byte[] fileByteContent;
79 List debarredVendorList = new ArrayList<DebarredVendorDetail> ();
80 try {
81 fileByteContent = IOUtils.toByteArray(new FileInputStream(fileName));
82 }
83 catch (FileNotFoundException ex) {
84 LOG.error("File not found [" + fileName + "]. " + ex.getMessage());
85 throw new RuntimeException("File not found [" + fileName + "]. " + ex.getMessage());
86 }
87 catch (IOException ex) {
88 LOG.error("IO Exception loading: [" + fileName + "]. " + ex.getMessage());
89 throw new RuntimeException("IO Exception loading: [" + fileName + "]. " + ex.getMessage());
90 }
91 Object parsedObject = batchInputFileService.parse(batchInputFileType, fileByteContent);
92 debarredVendorList = (List<DebarredVendorDetail>) parsedObject;
93
94 purgeOldVendorRecords();
95 businessObjectService.save(debarredVendorList);
96
97 removeDoneFiles(fileNames);
98 return true;
99 }
100
101
102
103
104 protected void removeDoneFiles(List<String> dataFileNames) {
105 for (String dataFileName : dataFileNames) {
106 File doneFile = new File(StringUtils.substringBeforeLast(dataFileName, ".") + ".done");
107 if (doneFile.exists()) {
108 doneFile.delete();
109 }
110 }
111 }
112
113
114
115
116 @Override
117 public boolean matchVendors() {
118 List<DebarredVendorMatch> matches = debarredVendorDao.match();
119 businessObjectService.save(matches);
120 return true;
121 }
122
123
124
125
126 @Override
127 public void purgeOldVendorRecords() {
128 businessObjectService.deleteMatching(DebarredVendorDetail.class, new HashMap());
129 }
130
131
132
133
134 @Override
135 public List<VendorDetail> getDebarredVendorsUnmatched() {
136 return debarredVendorMatchDao.getDebarredVendorsUnmatched();
137 }
138
139
140
141
142 @Override
143 public void confirmDebarredVendor(int debarredVendorId) {
144 DebarredVendorMatch match = debarredVendorMatchDao.getDebarredVendor(debarredVendorId);
145 match.setConfirmStatusCode("C");
146 match.setLastUpdatedPrincipalName(GlobalVariables.getUserSession().getPerson().getPrincipalName());
147 match.setLastUpdatedTimeStamp(dateTimeService.getCurrentTimestamp());
148 businessObjectService.save(match);
149 }
150
151
152
153
154 @Override
155 public void denyDebarredVendor(int debarredVendorId) {
156 DebarredVendorMatch match = debarredVendorMatchDao.getDebarredVendor(debarredVendorId);
157 match.setConfirmStatusCode("D");
158 match.setLastUpdatedPrincipalName(GlobalVariables.getUserSession().getPerson().getPrincipalName());
159 match.setLastUpdatedTimeStamp(dateTimeService.getCurrentTimestamp());
160 businessObjectService.save(match);
161 }
162
163
164
165
166
167 public BatchInputFileService getBatchInputFileService() {
168 return batchInputFileService;
169 }
170
171
172
173
174
175 public void setBatchInputFileService(BatchInputFileService batchInputFileService) {
176 this.batchInputFileService = batchInputFileService;
177 }
178
179
180
181
182
183 public BusinessObjectService getBusinessObjectService() {
184 return businessObjectService;
185 }
186
187
188
189
190
191 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
192 this.businessObjectService = businessObjectService;
193 }
194
195
196
197
198
199 public DateTimeService getDateTimeService() {
200 return dateTimeService;
201 }
202
203
204
205
206
207 public void setDateTimeService(DateTimeService dateTimeService) {
208 this.dateTimeService = dateTimeService;
209 }
210
211
212
213
214
215 public BatchInputFileType getBatchInputFileType() {
216 return batchInputFileType;
217 }
218
219
220
221
222
223 public void setBatchInputFileType(BatchInputFileType batchInputFileType) {
224 this.batchInputFileType = batchInputFileType;
225 }
226
227
228
229
230
231 public DebarredVendorDao getDebarredVendorDao() {
232 return debarredVendorDao;
233 }
234
235
236
237
238
239 public void setDebarredVendorDao(DebarredVendorDao debarredVendorDao) {
240 this.debarredVendorDao = debarredVendorDao;
241 }
242
243
244
245
246
247 public DebarredVendorMatchDao getDebarredVendorMatchDao() {
248 return debarredVendorMatchDao;
249 }
250
251
252
253
254
255 public void setDebarredVendorMatchDao(DebarredVendorMatchDao debarredVendorMatchDao) {
256 this.debarredVendorMatchDao = debarredVendorMatchDao;
257 }
258 }