use of org.kuali.kfs.module.ld.report.EnterpriseFeederReportData in project cu-kfs by CU-CommunityApps.
the class CuFileEnterpriseFeederServiceImpl method feed.
@Override
public void feed(String processName, boolean performNotifications) {
// to consider: maybe use java NIO classes to perform done file locking?
synchronized (this) {
if (StringUtils.isBlank(directoryName)) {
throw new IllegalArgumentException("directoryName not set for FileEnterpriseFeederServiceImpl.");
}
FileFilter doneFileFilter = new SuffixFileFilter(DONE_FILE_SUFFIX);
File enterpriseFeedFile = null;
String enterpriseFeedFileName = LaborConstants.BatchFileSystem.LABOR_ENTERPRISE_FEED + LaborConstants.BatchFileSystem.EXTENSION;
enterpriseFeedFile = new File(laborOriginEntryDirectoryName + File.separator + enterpriseFeedFileName);
PrintStream enterpriseFeedPs = null;
try {
enterpriseFeedPs = new PrintStream(enterpriseFeedFile);
} catch (FileNotFoundException e) {
LOG.error("enterpriseFeedFile doesn't exist " + enterpriseFeedFileName);
throw new RuntimeException("enterpriseFeedFile doesn't exist " + enterpriseFeedFileName);
}
if (LOG.isInfoEnabled()) {
LOG.info("New File created for enterprise feeder service run: " + enterpriseFeedFileName);
}
File directory = new File(directoryName);
if (!directory.exists() || !directory.isDirectory()) {
LOG.error("Directory doesn't exist and or it's not really a directory " + directoryName);
throw new RuntimeException("Directory doesn't exist and or it's not really a directory " + directoryName);
}
File[] doneFiles = directory.listFiles(doneFileFilter);
reorderDoneFiles(doneFiles);
boolean fatal = false;
LedgerSummaryReport ledgerSummaryReport = new LedgerSummaryReport();
// keeps track of statistics for reporting
EnterpriseFeederReportData feederReportData = new EnterpriseFeederReportData();
List<EnterpriseFeederStatusAndErrorMessagesWrapper> statusAndErrorsList = new ArrayList<EnterpriseFeederStatusAndErrorMessagesWrapper>();
for (File doneFile : doneFiles) {
File dataFile = null;
File reconFile = null;
EnterpriseFeederStatusAndErrorMessagesWrapper statusAndErrors = new EnterpriseFeederStatusAndErrorMessagesWrapper();
statusAndErrors.setErrorMessages(new ArrayList<Message>());
dataFile = getDataFile(doneFile);
reconFile = getReconFile(doneFile);
statusAndErrors.setFileNames(dataFile, reconFile, doneFile);
if (dataFile == null) {
LOG.error("Unable to find data file for done file: " + doneFile.getAbsolutePath());
statusAndErrors.getErrorMessages().add(new Message("Unable to find data file for done file: " + doneFile.getAbsolutePath(), Message.TYPE_FATAL));
statusAndErrors.setStatus(new RequiredFilesMissingStatus());
}
if (reconFile == null) {
LOG.error("Unable to find recon file for done file: " + doneFile.getAbsolutePath());
statusAndErrors.getErrorMessages().add(new Message("Unable to find recon file for done file: " + doneFile.getAbsolutePath(), Message.TYPE_FATAL));
statusAndErrors.setStatus(new RequiredFilesMissingStatus());
}
try {
if (dataFile != null && reconFile != null) {
if (LOG.isInfoEnabled()) {
LOG.info("Data file: " + dataFile.getAbsolutePath());
LOG.info("Reconciliation File: " + reconFile.getAbsolutePath());
}
fileEnterpriseFeederHelperService.feedOnFile(doneFile, dataFile, reconFile, enterpriseFeedPs, processName, reconciliationTableId, statusAndErrors, ledgerSummaryReport, errorStatisticsReport, feederReportData);
}
} catch (RuntimeException e) {
// we need to be extremely resistant to a file load failing so that it doesn't prevent other files from loading
LOG.error("Caught exception when feeding done file: " + doneFile.getAbsolutePath());
fatal = true;
} finally {
statusAndErrorsList.add(statusAndErrors);
boolean doneFileDeleted = doneFile.delete();
if (!doneFileDeleted) {
statusAndErrors.getErrorMessages().add(new Message("Unable to delete done file: " + doneFile.getAbsolutePath(), Message.TYPE_FATAL));
}
if (performNotifications) {
enterpriseFeederNotificationService.notifyFileFeedStatus(processName, statusAndErrors.getStatus(), doneFile, dataFile, reconFile, statusAndErrors.getErrorMessages());
}
}
}
enterpriseFeedPs.close();
// if errors encountered is greater than max allowed the enterprise feed file should not be sent
boolean enterpriseFeedFileCreated = false;
if (feederReportData.getNumberOfErrorEncountered() > getMaximumNumberOfErrorsAllowed() || fatal) {
enterpriseFeedFile.delete();
} else {
// generate done file
String enterpriseFeedDoneFileName = enterpriseFeedFileName.replace(LaborConstants.BatchFileSystem.EXTENSION, LaborConstants.BatchFileSystem.DONE_FILE_EXTENSION);
File enterpriseFeedDoneFile = new File(laborOriginEntryDirectoryName + File.separator + enterpriseFeedDoneFileName);
if (!enterpriseFeedDoneFile.exists()) {
try {
enterpriseFeedDoneFile.createNewFile();
} catch (IOException e) {
LOG.error("Unable to create done file for enterprise feed output group.", e);
throw new RuntimeException("Unable to create done file for enterprise feed output group.", e);
}
}
enterpriseFeedFileCreated = true;
}
// write out totals to log file
if (LOG.isInfoEnabled()) {
LOG.info("Total records read: " + feederReportData.getNumberOfRecordsRead());
LOG.info("Total amount read: " + feederReportData.getTotalAmountRead());
LOG.info("Total records written: " + feederReportData.getNumberOfRecordsRead());
LOG.info("Total amount written: " + feederReportData.getTotalAmountWritten());
}
generateReport(enterpriseFeedFileCreated, feederReportData, statusAndErrorsList, ledgerSummaryReport, laborOriginEntryDirectoryName + File.separator + enterpriseFeedFileName);
}
}
use of org.kuali.kfs.module.ld.report.EnterpriseFeederReportData in project cu-kfs by CU-CommunityApps.
the class CuFileEnterpriseFeederHelperServiceImplTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
fileEnterpriseFeederHelperService = SpringContext.getBean(FileEnterpriseFeederHelperService.class);
// make sure we have a batch directory
String batchDirectory = SpringContext.getBean(EnterpriseFeederService.class).getDirectoryName();
File batchDirectoryFile = new File(batchDirectory);
batchDirectoryFile.mkdir();
// copy the data file into place
File dataFileSrc = new File(DATA_FILE_PATH);
dataFileDest = new File(batchDirectory + "/SMGROS.data");
FileUtils.copyFile(dataFileSrc, dataFileDest);
// copy the recon file into place
File rerconileSrc = new File(RECON_FILE_PATH);
reconFileDest = new File(batchDirectory + "/SMGROS.recon");
FileUtils.copyFile(rerconileSrc, reconFileDest);
// create .done file
String doneFileName = batchDirectory + "/SMGROS.done";
doneFile = new File(doneFileName);
if (!doneFile.exists()) {
LOG.info("Creating done file: " + doneFile.getAbsolutePath());
doneFile.createNewFile();
}
statusAndErrors = new EnterpriseFeederStatusAndErrorMessagesWrapper();
statusAndErrors.setErrorMessages(new ArrayList<Message>());
statusAndErrors.setFileNames(dataFileDest, reconFileDest, doneFile);
File enterpriseFeedFile = null;
String enterpriseFeedFileName = LaborConstants.BatchFileSystem.LABOR_ENTERPRISE_FEED + LaborConstants.BatchFileSystem.EXTENSION;
enterpriseFeedFile = new File(batchDirectory + File.separator + enterpriseFeedFileName);
enterpriseFeedPs = null;
try {
enterpriseFeedPs = new PrintStream(enterpriseFeedFile);
} catch (FileNotFoundException e) {
LOG.error("enterpriseFeedFile doesn't exist " + enterpriseFeedFileName);
throw new RuntimeException("enterpriseFeedFile doesn't exist " + enterpriseFeedFileName);
}
ledgerSummaryReport = new LedgerSummaryReport();
feederReportData = new EnterpriseFeederReportData();
errorStatisticsReport = new ReportWriterTextServiceImpl();
}
Aggregations