View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.select.service.impl;
17  
18  import org.apache.struts.upload.FormFile;
19  import org.kuali.ole.select.businessobject.*;
20  import org.kuali.ole.select.constants.OleSelectPropertyConstants;
21  import org.kuali.ole.select.document.OlePurchaseOrderDocument;
22  import org.kuali.ole.select.document.OleRequisitionDocument;
23  import org.kuali.ole.select.service.BatchLoadService;
24  import org.kuali.ole.select.service.BibInfoService;
25  import org.kuali.ole.sys.OLEConstants;
26  import org.kuali.ole.sys.OLEKeyConstants;
27  import org.kuali.ole.sys.context.SpringContext;
28  import org.kuali.rice.core.api.config.property.ConfigurationService;
29  import org.kuali.rice.coreservice.api.CoreServiceApiServiceLocator;
30  import org.kuali.rice.coreservice.api.parameter.Parameter;
31  import org.kuali.rice.coreservice.api.parameter.ParameterKey;
32  import org.kuali.rice.kew.api.WorkflowDocument;
33  import org.kuali.rice.kim.api.identity.Person;
34  import org.kuali.rice.kim.api.identity.PersonService;
35  import org.kuali.rice.krad.service.BusinessObjectService;
36  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
37  import org.kuali.rice.krad.util.GlobalVariables;
38  
39  import java.io.*;
40  import java.math.BigDecimal;
41  import java.util.*;
42  
43  
44  public class BatchLoadServiceImpl implements BatchLoadService {
45  
46      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BatchLoadServiceImpl.class);
47      /**
48       *
49       * This method Loading the properties file
50       * @param classPath
51       * @return
52       */
53     /* public Properties loadPropertiesFromClassPath(String classPath) {
54  
55          ClassPathResource classPathResource = new ClassPathResource(classPath);
56          Properties properties = new Properties();
57          try {
58              properties.load(classPathResource.getInputStream());
59          }
60          catch (IOException e) {
61              throw new RuntimeException("Invalid class path: " + classPath + e);
62          }
63          return properties;
64      }*/
65  
66      /**
67       * This method... retrieve the BibInfoBean values as a list based on parameter
68       *
69       * @param filePath
70       * @return BibInfoBean as List
71       */
72      @Override
73      public List<BibInfoBean> getBibInfoBeanList(String xmlString) {
74          List<BibInfoBean> bibInfoBeanList = new ArrayList<BibInfoBean>();
75          BuildVendorBibInfoBean buildVendorBibInfoBean = new BuildVendorBibInfoBean();
76          bibInfoBeanList = buildVendorBibInfoBean.getBibInfoList(xmlString);
77          return bibInfoBeanList;
78      }
79  
80      /**
81       * This method saving the OleLoadFailureRecords
82       *
83       * @param bibFailureRecordsList
84       * @param loadSumId
85       * @param errorId
86       */
87      @Override
88      public void saveFailureRecord(List<BibInfoBean> bibFailureRecordsList, Integer loadSumId, BigDecimal errorId) {
89          for (int i = 0; i < bibFailureRecordsList.size(); i++) {
90              BibInfoBean bibInfoBean = bibFailureRecordsList.get(i);
91              OleLoadFailureRecords oleLoadFailureRecords = new OleLoadFailureRecords();
92              oleLoadFailureRecords.setAcqLoadSumId(loadSumId);
93              oleLoadFailureRecords.setErrorId(errorId);
94              oleLoadFailureRecords.setIsbn(bibInfoBean.getIsbn());
95              oleLoadFailureRecords.setVendorId(bibInfoBean.getYbp());
96              oleLoadFailureRecords.setTitle(bibInfoBean.getTitle());
97              SpringContext.getBean(BusinessObjectService.class).save(oleLoadFailureRecords);
98          }
99      }
100 
101     /**
102      * This method. saving the oleLoadSumRecords
103      *
104      * @param oleLoadSumRecords
105      * @param dupRecords
106      * @param sucRecords
107      */
108     @Override
109     public void saveSuccessRecord(OleLoadSumRecords oleLoadSumRecords, int dupRecords, int poSucRecords, int sucRecords, String batchDiscription, BigDecimal batchLoadProfile, String fileName) {
110         if (LOG.isDebugEnabled()) {
111             LOG.debug("dupRecords =====================" + dupRecords);
112             LOG.debug("sucRecords =====================" + sucRecords);
113             LOG.debug("poSucRecords =====================" + poSucRecords);
114         }
115         oleLoadSumRecords.setAcqLoadDescription(batchDiscription);
116         oleLoadSumRecords.setProfileId(batchLoadProfile);
117         oleLoadSumRecords.setFileName(fileName);
118         oleLoadSumRecords.setAcqLoadFailCount(dupRecords);
119         oleLoadSumRecords.setAcqLoadSuccCount(sucRecords);
120         oleLoadSumRecords.setAcqLoadTotCount(dupRecords + sucRecords);
121         oleLoadSumRecords.setAcqLoadPoTotCount(poSucRecords);
122         oleLoadSumRecords.setPrincipalId(GlobalVariables.getUserSession().getPrincipalId());
123         SpringContext.getBean(BusinessObjectService.class).save(oleLoadSumRecords);
124 
125     }
126 
127     /**
128      * This method for fileSize validation
129      *
130      * @param fileSize
131      * @return boolean
132      */
133     @Override
134     public boolean fileSizeValidation(Long fileSize) {
135         ConfigurationService kualiConfigurationService = SpringContext.getBean(ConfigurationService.class);
136 
137         String maxFileSizeString = getParameter(OleSelectPropertyConstants.STAFF_UPLOAD_MAXFILESIZE);
138         Long maxFileSize = Long.parseLong(maxFileSizeString);
139 
140         if (LOG.isDebugEnabled()) {
141             LOG.debug("defaultFileSize =====================" + maxFileSize);
142             LOG.debug("filesize =====================" + fileSize);
143             //LOG.debug("filesizeInMB ====================="+filesizeInMB);
144         }
145 
146         if (fileSize > maxFileSize && fileSize != 0) {
147             GlobalVariables.getMessageMap().putError(OLEConstants.GLOBAL_ERRORS, OLEKeyConstants.ERROR_BATCH_UPLOAD_FILE_SIZE, new Long(maxFileSize).toString() + "KB");
148             return true;
149         }
150 
151         return false;
152     }
153 
154     /**
155      * This method... retrieving the docstore info list based on bibinfo IsbnList
156      *
157      * @param bibIsbnList
158      * @return
159      */
160 
161     @Override
162     public List getDocIsbnList(List bibIsbnList) {
163         List docIsbnList = new ArrayList(0);
164         List<DocInfoBean> docInfoBeanList = new ArrayList<DocInfoBean>(0);
165         try {
166             BibInfoService bibInfoService = SpringContext.getBean(BibInfoServiceImpl.class);
167             docInfoBeanList = bibInfoService.getResult(bibIsbnList);
168             for (int j = 0; j < docInfoBeanList.size(); j++) {
169                 if (docInfoBeanList.get(j).getIsbn_display() != null) {
170                     docIsbnList.add(docInfoBeanList.get(j).getIsbn_display());
171                 }
172             }
173         } catch (Exception ex) {
174         }
175 
176         return docIsbnList;
177     }
178 
179     /**
180      * This method... check the no..of duplicate records based on isbn and VendorPO
181      *
182      * @param testList
183      * @param bibList
184      * @return No..of duplicate recodrs
185      */
186 
187     @Override
188     public int getNoOfDupIsbnRecords(List testIsbnList, List bibIsbnList) {
189         HashSet temp = new HashSet();
190         temp.addAll(testIsbnList);
191         testIsbnList.clear();
192         testIsbnList.addAll(temp);
193         int dupRecords = 0;
194         for (int i = 0; i < testIsbnList.size(); i++) {
195             for (int j = 0; j < bibIsbnList.size(); j++) {
196                 if (testIsbnList.get(i).equals(bibIsbnList.get(j))) {
197                     dupRecords++;
198                 }
199             }
200         }
201         if (LOG.isDebugEnabled()) {
202             LOG.debug("NO..OF duplicate records -------- >  " + dupRecords);
203         }
204         return dupRecords;
205     }
206 
207     /**
208      * This method for find out the duplicate records based on isbn
209      *
210      * @param isbnList
211      * @param bibInfoBeanList
212      * @return bibinfoBean list
213      */
214     @Override
215     public List<BibInfoBean> getIsbnFailureRecordsList(List isbnList, List<BibInfoBean> bibInfoBeanList) {
216         List<BibInfoBean> bibFailureRecordsList = new ArrayList<BibInfoBean>(0);
217         for (int i = 0; i < isbnList.size(); i++) {
218             for (int j = 0; j < bibInfoBeanList.size(); j++) {
219                 String isbn = bibInfoBeanList.get(j).getIsbn();
220                 if (isbn != null && !("".equals(isbn))) {
221                     if (isbn.equals(isbnList.get(i).toString())) {
222                         bibInfoBeanList.get(j).setFailure(bibInfoBeanList.get(j).getIsbn() + " is Duplicate ISBN value");
223                         bibFailureRecordsList.add(bibInfoBeanList.get(j));
224                         bibInfoBeanList.remove(j);
225                         j--;
226                     }
227                 }
228             }
229         }
230 
231         return bibFailureRecordsList;
232     }
233 
234     /**
235      * This method for find out the duplicate records based on VendorPO
236      *
237      * @param VendorPOList
238      * @param bibInfoBeanList
239      * @return bibInfoBean list
240      */
241     @Override
242     public List<BibInfoBean> getVendorPoNumberFailureRecordsList(List vendorNumberList, List<BibInfoBean> bibInfoBeanList) {
243         List<BibInfoBean> bibFailureRecordsList = new ArrayList<BibInfoBean>(0);
244         for (int i = 0; i < vendorNumberList.size(); i++) {
245             for (int j = 0; j < bibInfoBeanList.size(); j++) {
246                 String vendorPoValue = bibInfoBeanList.get(j).getYbp();
247                 if (vendorPoValue.equals(vendorNumberList.get(i).toString())) {
248                     bibInfoBeanList.get(j).setFailure(vendorPoValue + " is Duplicate Vendor Purchase Order value");
249                     bibFailureRecordsList.add(bibInfoBeanList.get(j));
250                     bibInfoBeanList.remove(j);
251                     j--;
252                 }
253             }
254         }
255 
256         return bibFailureRecordsList;
257     }
258 
259     /**
260      * This method...retrieve the OleLoadSumRecords based on id
261      *
262      * @param loadRecordsMap
263      * @return OleLoadSumRecords
264      */
265     @Override
266     public OleLoadSumRecords getOleLoadSumRecords(Map loadRecordsMap) {
267         OleLoadSumRecords oleLoadSumRecords = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(OleLoadSumRecords.class, loadRecordsMap);
268 
269         Map findProfileMap = new HashMap();
270         findProfileMap.put("profileId", oleLoadSumRecords.getProfileId());
271         OleLoadProfile oleLoadProfile = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(OleLoadProfile.class, findProfileMap);
272 
273         oleLoadSumRecords.setProfileFile(oleLoadProfile);
274 
275         return oleLoadSumRecords;
276     }
277 
278     /**
279      * This method... retrieve the OleLoadFailureRecords based on id
280      *
281      * @param loadRecordsMap
282      * @return List of OleLoadFailureRecords
283      */
284     @Override
285     public List<OleLoadFailureRecords> getOleFailureRecordsList(Map loadRecordsMap) {
286         Collection<OleLoadFailureRecords> oleLoadFailureRecordsList = SpringContext.getBean(BusinessObjectService.class).findMatching(OleLoadFailureRecords.class, loadRecordsMap);
287         for (OleLoadFailureRecords record : oleLoadFailureRecordsList) {
288             if (record.getErrorId().equals(new BigDecimal(5))) {
289                 record.setError(OLEConstants.BATCH_ISBN_DUPLICATE_FOUND);
290             } else if (record.getErrorId().equals(new BigDecimal(1))) {
291                 record.setError(OLEConstants.BATCH_VNO_DUPLICATE_FOUND);
292             } else if (record.getErrorId().equals(new BigDecimal(3))) {
293                 record.setError(OLEConstants.BATCH_LOAD_FAILD_FOUND);
294             } else if (record.getErrorId().equals(new BigDecimal(6))) {
295                 record.setError(OLEConstants.BATCH_VNO_NOT_FOUND);
296             } else if (record.getErrorId().equals(new BigDecimal(7))) {
297                 record.setError(OLEConstants.BAD_BFN_NO_FOUND);
298             } else if (record.getErrorId().equals(new BigDecimal(8))) {
299                 record.setError(OLEConstants.BAD_CONTROLL_LINE_FOUND);
300             } else if (record.getErrorId().equals(new BigDecimal(9))) {
301                 record.setError(OLEConstants.APO_RULE_FAILED);
302             } else {
303                 record.setError(OLEConstants.BATCH_TITLE_FAILD_FOUND);
304             }
305         }
306         return new ArrayList<OleLoadFailureRecords>(oleLoadFailureRecordsList);
307     }
308 
309     /**
310      * This method... retrieve the OleRequisitionDocument
311      *
312      * @return List of OleRequisitionDocument
313      */
314     @Override
315     public List getVendorPoNumberList(List<BibInfoBean> bibInfoBeanList) {
316         List bibVendorNumberList = new ArrayList(0);
317         for (int i = 0; i < bibInfoBeanList.size(); i++) {
318             bibVendorNumberList.add(bibInfoBeanList.get(i).getYbp());
319         }
320         List vendorNumberList = new ArrayList(0);
321         //List<OleRequisitionDocument> oleRequisitionDocumentList=new ArrayList<OleRequisitionDocument>(0);
322         clearSystemCache();
323         Map map = new HashMap();
324         for (int i = 0; i < bibVendorNumberList.size(); i++) {
325             if (bibVendorNumberList.get(i) != null && !("".equals(bibVendorNumberList.get(i)))) {
326                 map.put("vendorPoNumber", bibVendorNumberList.get(i));
327             }
328             int count = SpringContext.getBean(BusinessObjectService.class).countMatching(OleRequisitionDocument.class, map);
329             if (count != 0) {
330                 vendorNumberList.add(bibVendorNumberList.get(i));
331             }
332         }
333 
334        /*Collection docList = SpringContext.getBean(KeyValuesService.class).findAll(OleRequisitionDocument.class);*/
335 
336       /* for(int i=0;i<oleRequisitionDocumentList.size();i++)
337             if(oleRequisitionDocumentList.get(i).getVendorPoNumber()!=null)
338                 vendorNumberList.add(oleRequisitionDocumentList.get(i).getVendorPoNumber());*/
339 
340 
341         return vendorNumberList;
342     }
343 
344     /**
345      * This method... retrieve the failure Requisition List
346      *
347      * @return List of OleRequisitionDocument
348      */
349     @Override
350     public List<BibInfoBean> getRequisitionFailureRecords(List reqList, List<BibInfoBean> bibInfoBeanList) {
351         List<BibInfoBean> reqFailureList = new ArrayList<BibInfoBean>(0);
352 
353         for (int i = 0; i < reqList.size(); i++) {
354             if (reqList.get(i) == null) {
355                 bibInfoBeanList.get(i).setFailure("Requisition Creation Load Error Problem");
356                 reqFailureList.add(bibInfoBeanList.get(i));
357                 bibInfoBeanList.remove(i);
358                 i--;
359             }
360         }
361 
362         return reqFailureList;
363     }
364     /**
365      *
366      * This method... retrieve the failure Requisition List
367      * @return List of OleRequisitionDocument
368      */
369    /*public List<BibInfoBean> getPoFailureRecords(List reqList,List<BibInfoBean> bibInfoBeanList)
370    {
371        List<BibInfoBean> poFailureList=new ArrayList<BibInfoBean>(0);
372        Collection docList = SpringContext.getBean(KeyValuesService.class).findAll(OlePurchaseOrderDocument.class);
373        List<OlePurchaseOrderDocument> olePurchaseOrderDocumentList=new ArrayList<OlePurchaseOrderDocument>(docList);
374        for(int i=0;i<reqList.size();i++)
375        {    for(int j=0;j<olePurchaseOrderDocumentList.size()&&i<bibInfoBeanList.size();j++)
376              if((reqList.get(i).toString()).equals((olePurchaseOrderDocumentList.get(j).getRequisitionIdentifier().toString())))
377              {
378                  bibInfoBeanList.get(i).setFailure("PO Creation Load Error Problem");
379                  poFailureList.add(bibInfoBeanList.get(i));
380                  bibInfoBeanList.remove(i);
381                  i--;
382              }
383 
384        }
385 
386        return poFailureList;
387    }*/
388 
389     /**
390      * This method for destination path
391      * * @return boolean
392      */
393     @Override
394     public String getDestinationPath() {
395         ConfigurationService kualiConfigurationService = SpringContext.getBean(ConfigurationService.class);
396         //Properties properties = loadPropertiesFromClassPath(OLEConstants.LOAD_FILE_PROPERTIES);
397         String destinationPath = kualiConfigurationService.getPropertyValueAsString(OLEConstants.STAGING_DIRECTORY_KEY) + getParameter(OleSelectPropertyConstants.STAFF_UPLOAD_DESTINATIONPATH);
398         File dirCheck = (new File(destinationPath));
399         boolean isDir = dirCheck.exists();
400         if (LOG.isDebugEnabled()) {
401             LOG.debug("dirCheck =====================" + dirCheck);
402         }
403         if (!isDir) {
404             dirCheck.mkdir();
405         }
406         return destinationPath;
407     }
408 
409     public Integer getPoCount(String reqIds) {
410         int count = 0;
411         List reqList = Arrays.asList(reqIds.split(","));
412         clearSystemCache();
413         Map map = new HashMap();
414 
415         for (int i = 0; i < reqList.size(); i++) {
416             try {
417                 map.put(OLEConstants.REQ_IDENTIFIER, reqList.get(i));
418 
419                 /*
420                  * Collection poDocList = SpringContext.getBean(BusinessObjectService.class).findMatching(
421                  * OlePurchaseOrderDocument.class, map); if (0 < poDocList.size()) { OlePurchaseOrderDocument po =
422                  * ((List<OlePurchaseOrderDocument>) poDocList).get(0); if
423                  * (reqList.get(i).toString().equals(po.getRequisitionIdentifier().toString())) { String status =
424                  * getDocumentStatus(po.getDocumentNumber()); if ("FINAL".equals(status)) { count++; } if
425                  * (!OLEConstants.EXCEPTION.equals(status) && !OLEConstants.FINAL.equals(status)) { return -1; } } }
426                  */
427 
428                 int poCount = SpringContext.getBean(BusinessObjectService.class).countMatching(
429                         OlePurchaseOrderDocument.class, map);
430                 if (poCount != 0) {
431                     count++;
432                 } else {
433                     map.clear();
434                     map.put(OLEConstants.PUR_DOC_IDENTIFIER, reqList.get(i));
435                     Collection reqDocList = SpringContext.getBean(BusinessObjectService.class).findMatching(
436                             OleRequisitionDocument.class, map);
437                     if (0 < reqDocList.size()) {
438                         OleRequisitionDocument req = ((List<OleRequisitionDocument>) reqDocList).get(0);
439                         if (reqList.get(i).toString().equals(req.getPurapDocumentIdentifier().toString())) {
440                             String status = getDocumentStatus(req.getDocumentNumber());
441                             if (!OLEConstants.EXCEPTION.equals(status) && !OLEConstants.FINAL.equals(status)) {
442                                 return -1;
443                             }
444                         }
445 
446                     }
447                 }
448             } catch (Exception e) {
449                 LOG.error("Exception while processing PO Count ====" + e);
450             }
451         }
452         if (LOG.isDebugEnabled()) {
453             LOG.debug("NO..Of PO Created Count --- >  " + count);
454         }
455         return count;
456     }
457 
458     public void clearSystemCache() {
459 //       SpringContext.getBean(CacheService.class).clearSystemCaches();
460     }
461 
462     @Override
463     public void foundAllDuplicateRecords(List<BibInfoBean> bibInfoBeanList, List<BibInfoBean> reqFailureList, List<BibInfoBean> titleFailureList, List<BibInfoBean> isbnDupFailureList, List<BibInfoBean> vendorPoNumberDupFailureList, List bibIsbnList) {
464         for (int i = 0; i < bibInfoBeanList.size(); i++) {
465             if ("".equals(bibInfoBeanList.get(i).getAccountNumber()) || bibInfoBeanList.get(i).getAccountNumber() == null
466                     || "".equals(bibInfoBeanList.get(i).getObjectCode()) || bibInfoBeanList.get(i).getObjectCode() == null) {
467                 if (LOG.isDebugEnabled()) {
468                     LOG.debug(" Account No ---------->>> " + bibInfoBeanList.get(i).getAccountNumber() + "\n Object code ------->> " + bibInfoBeanList.get(i).getObjectCode());
469                 }
470                 bibInfoBeanList.get(i).setFailure(OLEConstants.BATCH_LOAD_FAILD_FOUND);
471                 reqFailureList.add(bibInfoBeanList.get(i));
472                 bibInfoBeanList.remove(i);
473                 i--;
474             } else if ("".equals(bibInfoBeanList.get(i).getTitle()) || bibInfoBeanList.get(i).getTitle() == null) {
475                 bibInfoBeanList.get(i).setFailure(OLEConstants.BATCH_TITLE_FAILD_FOUND);
476                 titleFailureList.add(bibInfoBeanList.get(i));
477                 bibInfoBeanList.remove(i);
478                 i--;
479             } else if ("".equals(bibInfoBeanList.get(i).getYbp()) || bibInfoBeanList.get(i).getYbp() == null) {
480                 bibInfoBeanList.get(i).setFailure("Vendor Purchase Order value is Null");
481                 vendorPoNumberDupFailureList.add(bibInfoBeanList.get(i));
482                 bibInfoBeanList.remove(i);
483                 i--;
484             } else {
485                 if (bibIsbnList.contains(bibInfoBeanList.get(i).getIsbn())) {
486                     bibInfoBeanList.get(i).setFailure(bibInfoBeanList.get(i).getIsbn() + " is Duplicate ISBN value");
487                     isbnDupFailureList.add(bibInfoBeanList.get(i));
488                     bibInfoBeanList.remove(i);
489                     i--;
490                 } else {
491                     bibIsbnList.add(bibInfoBeanList.get(i).getIsbn());
492                 }
493             }
494         }
495     }
496 
497     @Override
498     public Long getFileSize(FormFile upLoadedFile) {
499         Long filesize = new Long(0);
500         if (!"".equals(upLoadedFile.getFileName())) {
501             String fileName = upLoadedFile.getFileName();
502             int fileExtensionCount = fileName.indexOf(".");
503             String extension = fileName.substring(fileExtensionCount + 1);
504             fileName = fileName.substring(0, fileExtensionCount);
505             filesize = new Long(upLoadedFile.getFileSize());
506         }
507 
508         return filesize;
509     }
510 
511     @Override
512     public int getDupRecordsCount(List<BibInfoBean> reqFailureList, List<BibInfoBean> titleFailureList, List<BibInfoBean> isbnDupFailureList, List<BibInfoBean> vendorPoNumberDupFailureList) {
513         int dupRecords = 0;
514         dupRecords += reqFailureList.size();
515         dupRecords += titleFailureList.size();
516         dupRecords += isbnDupFailureList.size();
517         dupRecords += vendorPoNumberDupFailureList.size();
518         return dupRecords;
519     }
520 
521     @Override
522     public void saveAllFailureRecords(List<BibInfoBean> isbnFailureList, List<BibInfoBean> vendorPoNumberFailureList, List<BibInfoBean> reqFailureList, List<BibInfoBean> titleFailureList, List<BibInfoBean> vendorPoNumberDupFailureList, int acqLoadSumId) {
523         saveFailureRecord(isbnFailureList, acqLoadSumId, new BigDecimal(5));
524         saveFailureRecord(vendorPoNumberFailureList, acqLoadSumId, new BigDecimal(1));
525         saveFailureRecord(reqFailureList, acqLoadSumId, new BigDecimal(3));
526         saveFailureRecord(titleFailureList, acqLoadSumId, new BigDecimal(4));
527         saveFailureRecord(vendorPoNumberDupFailureList, acqLoadSumId, new BigDecimal(6));
528     }
529 
530     @Override
531     public List<BibInfoBean> getBibFailureRecordsList(List<BibInfoBean> isbnFailureList, List<BibInfoBean> vendorPoNumberFailureList, List<BibInfoBean> reqFailureList, List<BibInfoBean> titleFailureList, List<BibInfoBean> vendorPoNumberDupFailureList) {
532         List<BibInfoBean> bibFailureRecordsList = new ArrayList<BibInfoBean>(0);
533         //if(!isbnFailureList.isEmpty())
534         bibFailureRecordsList.addAll(isbnFailureList);
535         // if(!ybpFailureList.isEmpty())
536         bibFailureRecordsList.addAll(vendorPoNumberFailureList);
537         // if(!reqFailureList.isEmpty())
538         bibFailureRecordsList.addAll(reqFailureList);
539         // if(!poFailureList.isEmpty())
540         // bibFailureRecordsList.addAll(poFailureList);
541         bibFailureRecordsList.addAll(titleFailureList);
542         bibFailureRecordsList.addAll(vendorPoNumberDupFailureList);
543         return bibFailureRecordsList;
544     }
545 
546     @Override
547     public void createReqIdTextFile(List reqList, Integer acqSumId) {
548         try {
549             BufferedWriter out = new BufferedWriter(new FileWriter(getDestinationPath() + acqSumId + OLEConstants.BATCH_REQ_ID_FILE));
550             StringBuffer reqIds = new StringBuffer();
551             for (int i = 0; i < reqList.size(); i++) {
552                 reqIds.append(reqList.get(i).toString() + ",");
553             }
554             out.write(reqIds.toString());
555             out.close();
556         } catch (Exception ex) {
557         }
558 
559     }
560 
561     @Override
562     public void createErrorMrkFile(String failureRawData, Integer acqSumId) {
563         try {
564             BufferedWriter out = new BufferedWriter(new FileWriter(getDestinationPath() + acqSumId + OLEConstants.BATCH_FAILURE_FILE_MRK));
565             out.write(failureRawData);
566             out.close();
567         } catch (Exception ex) {
568         }
569 
570     }
571 
572 
573     @Override
574     public List getPOList(String loadSumId) {
575 
576         String directoryPath = getDestinationPath() + loadSumId + OLEConstants.BATCH_REQ_ID_FILE;
577         File file = new File(directoryPath);
578         List poList = new ArrayList();
579         try {
580             if (file.exists()) {
581                 InputStream fis = new FileInputStream(file);
582                 BufferedInputStream bis = new BufferedInputStream(fis);
583                 DataInputStream dis = new DataInputStream(bis);
584                 String reqIds = dis.readLine();
585                 List reqList = Arrays.asList(reqIds.split(","));
586                 clearSystemCache();
587                 Map map = new HashMap();
588                 for (int i = 0; i < reqList.size(); i++) {
589                     map.put("requisitionIdentifier", reqList.get(i));
590                     Collection<OlePurchaseOrderDocument> olePurchaseOrderDocumentList = SpringContext.getBean(BusinessObjectService.class).findMatching(OlePurchaseOrderDocument.class, map);
591                     if (!olePurchaseOrderDocumentList.isEmpty() && olePurchaseOrderDocumentList.iterator().next() != null) {
592                         poList.add(olePurchaseOrderDocumentList.iterator().next().getDocumentNumber());
593                     }
594                 }
595             }
596         } catch (Exception ex) {
597             LOG.error("Exception while getting POList----> " + ex);
598         }
599         return poList;
600     }
601 
602 
603     @Override
604     public List getBibIDList(String loadSumId) {
605 
606         String directoryPath = getDestinationPath() + loadSumId + OLEConstants.BATCH_REQ_ID_FILE;
607         File file = new File(directoryPath);
608         List bibIDList = new ArrayList();
609         try {
610             if (file.exists()) {
611                 InputStream fis = new FileInputStream(file);
612                 BufferedInputStream bis = new BufferedInputStream(fis);
613                 DataInputStream dis = new DataInputStream(bis);
614                 String reqIds = dis.readLine();
615                 List reqList = Arrays.asList(reqIds.split(","));
616                 clearSystemCache();
617                 Map map = new HashMap();
618                 for (int i = 0; i < reqList.size(); i++) {
619                     map.put("purapDocumentIdentifier", reqList.get(i));
620                     Collection<OleRequisitionDocument> oleRequisitionDocumentList = SpringContext.getBean(BusinessObjectService.class).findMatching(OleRequisitionDocument.class, map);
621                     if (!oleRequisitionDocumentList.isEmpty() && oleRequisitionDocumentList.iterator().next() != null) {
622                         List<OleRequisitionItem> oleRequisitionItemList = oleRequisitionDocumentList.iterator().next().getItems();
623                         for (int j = 0; j < oleRequisitionItemList.size(); j++) {
624                             OleRequisitionItem oleRequisitionItem = oleRequisitionItemList.get(j);
625                             bibIDList.add(oleRequisitionItem.getItemTitleId());
626                         }
627                     }
628                 }
629             }
630         } catch (Exception ex) {
631             LOG.error("Exception while getting BibIDList----> ", ex);
632         }
633         return bibIDList;
634     }
635 
636     private String getDocumentStatus(String docNumber) {
637         try {
638             Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(
639                     GlobalVariables.getUserSession().getPerson().getPrincipalId());
640             WorkflowDocument workFlowDocument = KRADServiceLocatorWeb.getWorkflowDocumentService()
641                     .loadWorkflowDocument(docNumber, principalPerson);
642             return workFlowDocument.getStatus().toString();
643         } catch (Exception e) {
644             LOG.error("Exception while getting document status---->" + e);
645         }
646         return null;
647     }
648 
649     public String getParameter(String name){
650         ParameterKey parameterKey = ParameterKey.create(org.kuali.ole.OLEConstants.APPL_ID, org.kuali.ole.OLEConstants.SELECT_NMSPC, org.kuali.ole.OLEConstants.SELECT_CMPNT,name);
651         Parameter parameter = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameter(parameterKey);
652         return parameter!=null?parameter.getValue():null;
653     }
654 }