Search in sources :

Example 1 with IWantDocumentBatchFeed

use of edu.cornell.kfs.module.purap.businessobject.IWantDocumentBatchFeed in project cu-kfs by CU-CommunityApps.

the class IWantDocumentFeedServiceImpl method parseInputFile.

/**
 * Parses the input file.
 *
 * @param incomingFileName
 * @return an IWantDocumentBatchFeed containing input data
 */
protected IWantDocumentBatchFeed parseInputFile(String incomingFileName) {
    LOG.info("Parsing file: " + incomingFileName);
    FileInputStream fileContents;
    try {
        fileContents = new FileInputStream(incomingFileName);
    } catch (FileNotFoundException e1) {
        LOG.error("file to load not found " + incomingFileName, e1);
        throw new RuntimeException("Cannot find the file requested to be loaded " + incomingFileName, e1);
    }
    // do the parse
    Object parsed = null;
    try {
        byte[] fileByteContent = IOUtils.toByteArray(fileContents);
        parsed = batchInputFileService.parse(iWantDocumentInputFileType, fileByteContent);
    } catch (IOException e) {
        LOG.error("error while getting file bytes:  " + e.getMessage(), e);
        throw new RuntimeException("Error encountered while attempting to get file bytes: " + e.getMessage(), e);
    } catch (ParseException e1) {
        LOG.error("Error parsing xml " + e1.getMessage());
        throw new RuntimeException("Error parsing xml " + e1.getMessage(), e1);
    } finally {
        IOUtils.closeQuietly(fileContents);
    }
    return (IWantDocumentBatchFeed) parsed;
}
Also used : IWantDocumentBatchFeed(edu.cornell.kfs.module.purap.businessobject.IWantDocumentBatchFeed) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ParseException(org.kuali.kfs.sys.exception.ParseException) FileInputStream(java.io.FileInputStream)

Example 2 with IWantDocumentBatchFeed

use of edu.cornell.kfs.module.purap.businessobject.IWantDocumentBatchFeed in project cu-kfs by CU-CommunityApps.

the class IWantDocumentFeedServiceImpl method processIWantDocumentFiles.

/**
 * @see edu.cornell.kfs.module.purap.batch.service.IWantDocumentFeedService#processIWantDocumentFiles()
 */
@Override
public boolean processIWantDocumentFiles() {
    List<String> fileNamesToLoad = batchInputFileService.listInputFileNamesWithDoneFile(iWantDocumentInputFileType);
    List<String> processedFiles = new ArrayList<String>();
    for (String incomingFileName : fileNamesToLoad) {
        try {
            LOG.debug("processIWantDocumentFiles  () Processing " + incomingFileName);
            IWantDocumentBatchFeed batchFeed = parseInputFile(incomingFileName);
            if (batchFeed != null && !batchFeed.getBatchIWantDocuments().isEmpty()) {
                loadIWantDocuments(batchFeed, incomingFileName, GlobalVariables.getMessageMap());
                processedFiles.add(incomingFileName);
            }
        } catch (RuntimeException e) {
            LOG.error("Caught exception trying to load i want document file: " + incomingFileName, e);
            // remove done files
            List<String> badFiles = new ArrayList<String>();
            badFiles.add(incomingFileName);
            removeDoneFiles(badFiles);
            throw new RuntimeException("Caught exception trying to load i want document file: " + incomingFileName, e);
        }
    }
    // remove done files
    removeDoneFiles(processedFiles);
    return true;
}
Also used : IWantDocumentBatchFeed(edu.cornell.kfs.module.purap.businessobject.IWantDocumentBatchFeed) ArrayList(java.util.ArrayList) AutoPopulatingList(org.springframework.util.AutoPopulatingList) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

IWantDocumentBatchFeed (edu.cornell.kfs.module.purap.businessobject.IWantDocumentBatchFeed)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ParseException (org.kuali.kfs.sys.exception.ParseException)1 AutoPopulatingList (org.springframework.util.AutoPopulatingList)1