I am using only one step that used chunk oriented processing (ItemReader, ItemProcessor, ItemWriter), to read the data from a file, process the data (there is many business logic behind with conditions) and the last step which is to write the data into the database.
The part that I found little bit tricky is the processor part, I cannot really add conditional flow since I use chunk processing neither the composite processor since there are conditions that needs to be met to process certain flow (after doing many checks on the data - which leads sometimes on a direct data return).
Is there a better way to implement all this business logic with many conditions and checks or a way to call an ItemProcessor in another ItemProcessor under a certain condition using chunk processing in spring batch?
Thank you
There is no best way for that. It depends on the use case. So I will try to give some guidance.
The chunk-oriented processing model is designed to have a single item processor with the following contract: given an input item, the item processor can have one of the following outcomes:
null
: in this case, the item will be filtered (ie not passed to the writer)Now how you implement the logic inside an item processor is up to you. You can for example:
CompositeItemProcessor
provided by Spring Batch)ItemProcessorAdapter
or the FunctionItemProcessor
provided by Spring Batch)There are several use cases that can be implemented with an item processor, like data transformation, filtering, validation, etc. You can find more details in the Item processing section of the reference documentation.
What you really need to clearly define is what is the outcome of the entire validation process (as a black box), no matter how complex it is and only then choose the best pattern to implement it in your case (note how I said "the best in your case", because there is no absolute best way).