I have a requirement to read one of our module related transaction table using Spring default FlatFileReader to fetch record and use Spring FlatFileWriter to write so I don't have control on these reader and writer as they are not custom one. Then the second step is tasklet to transmit the same flat file to the remote location using SFTP.
But some times when Spring FlatFile reader don't get record then it will generate empty File with header.
So I am checking the content of the file in the second step tasklet and checking if it contains header and record then transmit the same in that step otherwise I'm inserting some default records which is holding some logic into the transaction table. Once insertion is completed then I would like to call previous step that is step 1 Spring flat file reader from the current tasklet step.
Please let me know on the same to call previous step from the current step which is tasklet.
Please find the below sample job config
<batch:step id="FlatFileStep3" next="TransmissionFlatFileStep4">
<batch:tasklet>
<batch:chunk reader="FlatFileReader" writer="FlatFileWriter" commit-interval="50"/>
</batch:tasklet>
</batch:step>
<batch:step id="TransmissionFlatFileStep4">
<batch:tasklet>
<batch:chunk ref="TransmissionFlatFileTasklet"/>
<batch:next on="NOT_COMPLETED" to="FlatFileStep3"/>
<batch:next on="COMPLETED" to="UpdateTxnTableStep5"/>
</batch:tasklet>
</batch:step>
<batch:step id="UpdateTxnTableStep5">
<batch:tasklet>
<batch:chunk ref="UpdateTxnTableTasklet"/>
</batch:tasklet>
</batch:step>
when the spring batch comes to the TransmissionFlatFileStep4 then in the TransmissionFlatFileTasklet I have logic to check the file content. if the file is empty then I have insertion logic to insert some default data to our transaction table. Then in the same tasklet (TransmissionFlatFileTasklet) I override the public ExitStatus afterStep(StepExecution stepExecution) method by implementing StepExecutionListener interface and set the custom exit status NOT_COMPLETED & COMPLETED so its calling UpdateTxnTableStep5 when the status is COMPLETED as well as it call FlatFileCreationStep3 on NOT_COMPLETED so this time the flat file will be generated with those default records but once the flat file completes then it should again call TransmissionFlatFileStep4 which is not happening the batch is throwing error : unable to find the next state