Writing multiple CSV files using MultiResourceItemWriter in a Step. After writing the various files in the Step, I want to be able to email these files to the appropriate receiver using the StepExecutionListener.
The problem, though, is how do I know which of the files should be sent to which email ? The filename or the suffix (I have a custom ResourceSuffixCreator but it only gets an index which can't help identify 1 file from the other usefully.)
Using spring boot 2.2.7.
Thanks for any help.
UPDATE I have, say, steps in this job. The success step outputs success related files for each email target using MultiResourceItemWriter.
return this.stepBuilderFactory.get("generateSuccessRecords")
.<SuccessReport, SuccessReport>chunk(1)
.reader(successReportItemReader(null, null))
.processor(itemProcessor)
.writer(successReportItemWriter(null))
.build();
successReportItemWriter is a MultiResourceItemWriter that delegates to a
return new MultiResourceItemWriterBuilder<SuccessReport>()
.name("successReportItemWriter")
.itemCountLimitPerResource(1)
.delegate(individualSuccessReportItemWriter())
.resource(new FileSystemResource(jobReportDirectory + "/successReport"))
.resourceSuffixCreator(suffixCreator)
.build();
individualSuccessReportItemWriter() is as below.
FlatFileItemWriter<SuccessReport> itemWriter = new FlatFileItemWriter<>();
itemWriter.setName("individualSuccessReportItemWriter");
itemWriter.setHeaderCallback(new SuccesssReportHeaderCallback());
itemWriter.setLineAggregator(new SuccessReportLineAggregator());
After the Success step generates the SuccessReport , the Fallout step will query from the DB and repeat the above to create the FalloutReport .csv files for each Email Target, again using MultiResourceItemWriter.
The goal is to be able to email each Email target the Success Report and the Fallout Report .csv files as attachment. Suppose, there are 25 Email Targets. There will be 25 Success .CSV files and 25 Failure .CSV files generated as a result of running the 2 Steps (Success and Fallout). Each Email target will get 1 success and 1 fallout .csv file as attachment.
The class SuccessReport and FalloutReport has the email Target while it generates the .csv file -- however unable to name the files as such because the suffix Creator does not allow for naming them accordingly.