VerreTraitIntegresAssoIteStepConfig.java

package com.sintia.ffl.admin.optique.services.batch.refpromoteur.export.ite;

import com.sintia.ffl.admin.optique.dal.entities.VerreTraitIntegresAssoIte;
import com.sintia.ffl.admin.staging.FileUtils;
import com.sintia.ffl.admin.staging.GenerericJDBCItemReadFromDB;
import com.sintia.ffl.admin.staging.step.export.jdbc.AbstractSinglePromoteurJDBCExportStepConfig;
import com.sintia.ffl.adminui.commons.enums.TypeStaging;
import com.sintia.ffl.core.commons.enums.CodePromoteur;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.integration.async.AsyncItemWriter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.io.IOException;
import java.sql.Timestamp;

@Configuration
public class VerreTraitIntegresAssoIteStepConfig extends AbstractSinglePromoteurJDBCExportStepConfig<VerreTraitIntegresAssoIte> {

    private static final String QUERY = "select id_verre_trait_integres_asso_ite, id_trait_integre_ite, c_modele, " +
            "d_creation, d_maj " +
            "from verre_trait_integres_asso_ite";

    public VerreTraitIntegresAssoIteStepConfig(){
        super(
                TypeStaging.REF_PROMOTEUR,
                (rs, rowNum) -> {
                    Timestamp dCreation = rs.getTimestamp("d_creation");
                    Timestamp dMaj = rs.getTimestamp("d_maj");
                    return new VerreTraitIntegresAssoIte(
                            rs.getInt("id_verre_trait_integres_asso_ite"),
                            rs.getInt("id_trait_integre_ite"),
                            rs.getString("c_modele"),
                            dCreation == null ? null : dCreation.toLocalDateTime(),
                            dMaj == null ? null : dMaj.toLocalDateTime()
                    );
                },
                CodePromoteur.ITE);
    }
    
    @Bean
    public Step verreTraitIntegresAssoIteStep(StepBuilderFactory stepBuilderFactory, FileUtils fileUtils,
                                              DataSource dataSource) throws IOException {
        return super.buildStep(stepBuilderFactory, fileUtils, dataSource);
    }

    @Bean("verreTraitIntegresAssoIteReader")
    @StepScope
    @Override
    protected GenerericJDBCItemReadFromDB<VerreTraitIntegresAssoIte> reader(
            DataSource dataSource,
            @Value("#{jobParameters['idPromoteur']}") Integer idPromoteur,
            @Value("#{jobParameters['codePromoteur']}") String codePromoteur) throws IOException {
        return super.buildReader(dataSource, QUERY, codePromoteur);
    }
    
    @Bean("verreTraitIntegresAssoIteWriter")
    @StepScope
    @Override
    public AsyncItemWriter<VerreTraitIntegresAssoIte> writer(
            FileUtils fileUtils,
            @Value("#{jobParameters['envSource'] ?: 'pprod'}") String envSource,
            @Value("#{jobParameters['envCible'] ?: 'pprod'}") String envCible,
            @Value("#{jobParameters['codePromoteur']}") String codePromoteur
    ) throws IOException {
        return super.buildWriter(fileUtils, envSource, envCible, codePromoteur);
    }
}