**I am working on the Spring Batch that will read all CSV files from the folder and need to do different process based on file bame. The below code is working fine with one file(name) type. but the issue is I need to decide the step execution based on "File Name". Anyone, please help with this logic?
My File Name format:
EMP.CRE.3434234.3.6.csv
EMP.UPT.3434234.3.7.csv
STD.CRE.3434234.3.8.csv
STD.UPT.3434234.3.9.csv
based on EMP or STD, I need to execute different processing logic. If it's CRE then create logic(step) and UPT means to update the data.
Below is my current code structure:
@Bean
public Job employeeJob() throws Exception{
return jobs.get("employeeJob")
.start(masterStep())
.build();
}
@Bean
public step masterStep() throws Exception{
return steps.get("masterStep").partitioner(slavestep()
.partitioner("partition",partitioner())
.taskExecutor(taskExecutor()).build();
}
@Bean
public step slaveStep() throws Exception{
return steps.get("slaveStep").<EmployeeData, EmployeeData>chunk(10)
.reader(reader(null))
.processor(processor(null,null)
.writer(writer()).build();
}
@Bean
@JobScope
public Partitioner partitioner() throws Exception{
MultiResourcePartitioner partitioner = new MultiResourcePartitioner();
PathMatchingResourcePatternResolver resolver= new PathMatchingResourcePatternResolver();
partitioner.SetResources(resolver.getResources("file:"+Resourcepath+ filetype));
partitioner.partition(20);
return partitioner;
}
@Bean
@StepScope
public FlatFileItemReader<EmployeeData> reader(@value("#stepExecutionContext['fileName] String file){
return new FlatFileItemReaderBuilder<EmployeeData>()
...
...
.build();
}