private JRDataSource processInput(@Nonnull final Input input)
throws JSONException, JRException {
//CSON:RedundantThrows
List<Values> dataSourceValues = Lists.newArrayList();
for (Map<String, Object> o : input.datasource.attributesValues) {
Values rowValues = new Values(input.values);
for (Map.Entry<String, Object> entry : o.entrySet()) {
rowValues.put(entry.getKey(), entry.getValue());
}
dataSourceValues.add(rowValues);
}
List<ForkJoinTask<Values>> futures = Lists.newArrayList();
if (!dataSourceValues.isEmpty()) {
for (Values dataSourceValue : dataSourceValues) {
addAttributes(input.template, dataSourceValue);
final ForkJoinTask<Values> taskFuture = this.processorGraph.createTask(dataSourceValue).fork();
futures.add(taskFuture);
}
final File reportFile;
if (this.reportTemplate != null) {
final Configuration configuration = input.template.getConfiguration();
final File file = new File(configuration.getDirectory(), this.reportTemplate);
reportFile = this.jasperReportBuilder.compileJasperReport(configuration, file);
} else {
reportFile = null;
}
List<Map<String, ?>> rows = new ArrayList<Map<String, ?>>();
for (ForkJoinTask<Values> future : futures) {
final Values rowData = future.join();
if (reportFile != null) {
rowData.put(this.reportKey, reportFile.getAbsolutePath());
}
rows.add(rowData.asMap());
}
return new JRMapCollectionDataSource(rows);
}
return null;