I got it working as it should in order to meet our requirements.
Here's some stuff that I hope it will help!
The two problems that I needed nail down were:
A- the job has to iterate thru a set of files from the input directory
B- valid and rejected records must be written to separate output files in order to get handled by their respective business process
Here are pertinent parts of my main SB config file (removed some details for clarity).
FilePartitioner:
MultiInputFilesPartitioner implements Partitioner, customized to load the partitions based on available files (ex: sorted by date).Code:<beans:bean id="filePartitioner" class="com.MultiInputFilesPartitioner"> <beans:property name="resources" value="file:${data.root}/input/${collected.file.name}"/> </beans:bean>
NormalizerStepMaster:
PartitionStep extends AbstractStep in order to customize the doExecute.Code:<beans:bean id="normalizerStepMaster" name="normalizerStep:master" class="com.PartitionStep"> <beans:property name="partitionHandler"> <beans:bean class="org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler"> <beans:property name="taskExecutor"> <beans:bean class="org.springframework.core.task.SyncTaskExecutor" /> </beans:property> <beans:property name="step" ref="normalizerStep" /> <beans:property name="gridSize" value="3" /> </beans:bean> </beans:property> <beans:property name="stepExecutionSplitter"> <beans:bean class="org.springframework.batch.core.partition.support.SimpleStepExecutionSplitter"> <beans:constructor-arg ref="jobRepository" /> <beans:constructor-arg ref="normalizerStep" /> <beans:constructor-arg ref="filePartitioner" /> </beans:bean> </beans:property> <beans:property name="jobRepository" ref="jobRepository" /> </beans:bean>
And finally, the NormalizerStep, which is executed once for each input file:
The normalizerCompositeItemWriter is implemented as DHGarrette suggested.Code:<beans:bean id="normalizerStep" parent="simpleStep"> <beans:property name="itemReader" ref="normalizerItemReader"/> <beans:property name="itemProcessor"> <beans:bean id="compositeItemProcessor" class="org.springframework.batch.item.support.CompositeItemProcessor"> <beans:property name="itemProcessors"> <beans:list> <beans:ref bean="normalizerValidatingItemProcessor" /> <beans:ref bean="recordCounterItemProcessor" /> </beans:list> </beans:property> </beans:bean> </beans:property> <beans:property name="itemWriter" ref="normalizerCompositeItemWriter"/> <beans:property name="streams"> <beans:list> <beans:ref bean="validRecordItemWriter"/> <beans:ref bean="rejectedRecordItemWriter"/> </beans:list> </beans:property> </beans:bean>
The normalizerValidatingItemProcessor is the one that decides if a record is valid or rejected.
The recordCounterItemProcessor is a custom processor that checks if the record count match with the input file footer.
I really hope the it will help you get out of the Dead-end.
Good luck!
Gino


Reply With Quote
