PurgeVerreJobConfiguration.java

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

import com.sintia.ffl.admin.optique.specifique.isea.listener.PurgeVerreJobListener;
import com.sintia.ffl.admin.optique.specifique.isea.processor.PurgeVerreProcessor;
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;

@Configuration
@EnableBatchProcessing
public class PurgeVerreJobConfiguration {
	
	@Autowired
	public JobBuilderFactory jobBuilderFactory;
	
	@Autowired
	public StepBuilderFactory stepBuilderFactory;
	
	@Autowired
	private PurgeVerreProcessor purgeVerreProcessor;
	
	@Bean
	public Job purgeVerres(PurgeVerreJobListener listener) {
		FlowBuilder<Flow> flowBuilder = new FlowBuilder<>("purgeVerres");
		Flow flow = flowBuilder
				.start(dataProcessor())
				.build();
		
		return jobBuilderFactory.get("purgeVerres")
				.incrementer(new RunIdIncrementer())
				.listener(listener)
				.start(flow)
				.end()
				.build();
	}
	
	private Step dataProcessor() {
		return stepBuilderFactory.get("dataProcessor")
				.tasklet(purgeVerreProcessor)
				.build();
	}
	
	
}