ChargementCatalogueBatchConfiguration.java

package com.sintia.ffl.admin.optique.specifique.isea.config;

import com.sintia.ffl.admin.optique.specifique.isea.listener.ChargementJobListener;
import com.sintia.ffl.admin.optique.specifique.isea.processor.ChargementItemProcessor;
import com.sintia.ffl.admin.optique.specifique.isea.reader.ChargementItemReader;
import com.sintia.ffl.admin.optique.specifique.isea.writer.ChargementItemWriter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.job.builder.FlowBuilder;
import org.springframework.batch.core.job.flow.Flow;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
@EnableBatchProcessing
public class ChargementCatalogueBatchConfiguration {
	
	@Autowired
	public JobBuilderFactory jobBuilderFactory;
	
	@Autowired
	public StepBuilderFactory stepBuilderFactory;
	
	@Autowired
	private ChargementItemReader chargementItemReader;
	
	@Autowired
	private ChargementItemProcessor chargementItemProcessor;
	
	@Autowired
	private ChargementItemWriter chargementItemWriter;
	
	
	@Bean
	public Job chargementCatalogue(ChargementJobListener listener) {

		log.info("*****************************************************");
		log.info("ChargementCatalogueBatchConfiguration - chargementCatalogue()");

		FlowBuilder<Flow> flowBuilder = new FlowBuilder<>("chargementCatalogue");
		Flow flow = flowBuilder
				.start(dataReader())
				.next(dataProcessor())
				.next(dataWriter())
				.build();
		
		return jobBuilderFactory.get("chargementCatalogue")
				.incrementer(new RunIdIncrementer())
				.listener(listener)
				.start(flow)
				.end()
				.build();
	}
	
	private Step dataWriter() {
		log.info("*** writer ***** writer ***** writer ***** writer ***** writer ***** writer ***");
		return stepBuilderFactory.get("dataWriter")
				.tasklet(chargementItemWriter)
				.build();
	}
	
	private Step dataProcessor() {
		log.info("*** processor ***** processor ***** processor ***** processor ***** processor ***");
		return stepBuilderFactory.get("dataProcessor")
				.tasklet(chargementItemProcessor)
				.build();
	}
	
	private Step dataReader() {
		log.info("*** reader ***** reader ***** reader ***** reader ***** reader ***");
		return stepBuilderFactory.get("dataReader")
				.tasklet(chargementItemReader)
				.build();
	}
	
	
}