I am looking at Spring Batch (2.1.9) for processing CSV files uploaded by users. The flow I need to support includes two major job-templates for many file formats.
- validation of the uploaded file that includes:
- Parsing and validating the format of all provided fields for each record (using regexp)
- Business validation of the mapped object
- Generating a detailed report that provides the total record count, invalid record count, and a detail of the errors (line number and all the errors found in it)
Only files that have no errors can be fully processed in a second job triggered by the user that uploaded it:
- Processing the file:
- Parsing the file
- storing the records to the DB (using a service call)
- commit all the records in the uploaded file or rollback if there are errors
- provide feedback on the processing (success or failure)
I have looked at various examples but couldn't find good examples for:
- defining regexp for the fields in an ItemReader
- collecting errors and generating file-processing report.
- commit or rollback the entire job (no commit-interval)
- using a single job definition and passing (reference?) to the CSV fields, regexp expressions, business validation service, and processing service at runtime (based on the file type)
I would appreciate any pointers to sample code that addresses these issues