I have a spring boot project which reads a textfile from an input folder and generates a pdf report.
public void generateReport(String inputTextFileWIthPath, String compiledJasperFile, String outFilePath) {
try {
String[] columnNames = ["column1","column2","column3"] ;
File jasperFile = new File(compiledJasperFile);
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(jasperFile);
// Map<String, Object> parameters = new HashMap<String, Object>();
JRCsvDataSource dataSource = new JRCsvDataSource(inputTextFileWIthPath);
dataSource.setFieldDelimiter('|');
dataSource.setColumnNames(columnNames);
//Map data with fields
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, dataSource);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("_dd-MM-yyyy_HH-mm-ss");
LocalDateTime now = LocalDateTime.now();
String reportFileName = "report" + dtf.format(now) + ".pdf";
JasperExportManager.exportReportToPdfFile(jasperPrint, outFilePath + reportFileName);
} catch (Exception e) {
e.printStackTrace();
}
}
- I am able to generate the report with the above code.
But the scenario is
Read all the text files from the input folder and generate the
report files for each input text file and store them in the output folder.If any report generate fails, store the failure message in db table.
Also, The application should run as a stand alone jar. How to define entry point so that program starts reading the files from input
folder when we run the jar(using scheduler).Trying to figure out what is the better approach to implement this. Can use Executor service to read all the files from input folder or is there a better approach to achieve this.