List<Object> results = new ArrayList<Object>();
List<String> datasources = new ArrayList<String>();
//calculate aggregate results
EasyBatchReport easyBatchFinalReport = new EasyBatchReport();
for (EasyBatchReport easyBatchReport : easyBatchReports) {
startTimes.add(easyBatchReport.getStartTime());
endTimes.add(easyBatchReport.getEndTime());
totalRecords += easyBatchReport.getTotalRecords();
filteredRecords.addAll(easyBatchReport.getFilteredRecords());
ignoredRecords.addAll(easyBatchReport.getIgnoredRecords());
rejectedRecords.addAll(easyBatchReport.getRejectedRecords());
errorRecords.addAll(easyBatchReport.getErrorRecords());
successRecords.addAll(easyBatchReport.getSuccessRecords());
results.add(easyBatchReport.getEasyBatchResult());
datasources.add(easyBatchReport.getDataSource());
}
//merge results
easyBatchFinalReport.setStartTime(Collections.min(startTimes));
easyBatchFinalReport.setEndTime(Collections.max(endTimes));
easyBatchFinalReport.setTotalRecords(totalRecords);
for (Integer filteredRecord : filteredRecords) {
easyBatchFinalReport.addFilteredRecord(filteredRecord);
}
for (Integer ignoredRecord : ignoredRecords) {
easyBatchFinalReport.addIgnoredRecord(ignoredRecord);
}
for (Integer rejectedRecord : rejectedRecords) {
easyBatchFinalReport.addRejectedRecord(rejectedRecord);
}
for (Integer errorRecord : errorRecords) {
easyBatchFinalReport.addErrorRecord(errorRecord);
}
for (Integer successRecord : successRecords) {
easyBatchFinalReport.addSuccessRecord(successRecord);
}
easyBatchFinalReport.setEasyBatchResult(results);
//data sources
StringBuilder stringBuilder = new StringBuilder();
for (String dataSource : datasources) {
stringBuilder.append(dataSource).append("\n");
}
easyBatchFinalReport.setDataSource(stringBuilder.toString());
//return merged report
return easyBatchFinalReport;
}