IncompatibiliteSupplementTrtIntegreLoadStepConfig.java

package com.sintia.ffl.admin.optique.services.batch.refcatalogue.load;

import com.sintia.ffl.admin.optique.dal.entities.IncompatibiliteSupplementTrtIntegre;
import com.sintia.ffl.admin.optique.dal.repositories.IncompatibiliteSupplementTrtIntegreRepository;
import com.sintia.ffl.admin.staging.FileUtils;
import com.sintia.ffl.admin.staging.GenerericItemReadFromFile;
import com.sintia.ffl.admin.staging.StagingStepListener;
import com.sintia.ffl.admin.staging.step.imports.AbstractCommunImportStepConfig;
import com.sintia.ffl.adminui.commons.enums.TypeStaging;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.JobScope;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;

import java.io.IOException;

@Slf4j
@Configuration
public class IncompatibiliteSupplementTrtIntegreLoadStepConfig
        extends AbstractCommunImportStepConfig<IncompatibiliteSupplementTrtIntegre, Integer, IncompatibiliteSupplementTrtIntegreRepository> {

    public IncompatibiliteSupplementTrtIntegreLoadStepConfig() {
        super(IncompatibiliteSupplementTrtIntegre.class, TypeStaging.REF_CATALOGUE);
    }

    @Bean
    @JobScope
    public Step incompatibiliteSupplementTrtIntegreLoadStep(JobRepository jobRepository,
                                                            PlatformTransactionManager transactionManager,
                                                            FileUtils fileUtils,
                                                            IncompatibiliteSupplementTrtIntegreRepository repository,
                                                            StagingStepListener<IncompatibiliteSupplementTrtIntegre, Integer> stepListener)
            throws IOException {

        // Appelle la nouvelle version de buildStep avec JobRepository et TransactionManager
        return super.buildStep(jobRepository, transactionManager, repository, fileUtils , stepListener);
    }

    @Bean("incompatibiliteSupplementTrtIntegreItemReader")
    @StepScope
    @Override
    public GenerericItemReadFromFile<IncompatibiliteSupplementTrtIntegre> reader(
            FileUtils fileUtils,
            @Value("#{jobParameters['envSource'] ?: 'pprod'}") String envSource,
            @Value("#{jobParameters['envCible']  ?: 'pprod'}") String envCible)
            throws IOException {

        return super.buildReader(fileUtils, envSource, envCible);
    }
}