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;
}
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;
}
Aggregations