ModeleVerreIteStepConfig.java
package com.sintia.ffl.admin.optique.services.batch.refpromoteur.export.ite;
import com.sintia.ffl.admin.optique.dal.entities.ModeleVerreIte;
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.Date;
import java.sql.Timestamp;
@Configuration
public class ModeleVerreIteStepConfig extends AbstractSinglePromoteurJDBCExportStepConfig<ModeleVerreIte> {
private static final String QUERY = "select id_modele_verre_ite, id_classe, id_distributeur_ite, id_fabricant_ite, " +
"id_type_materiau_ite, id_type_verre_ite, c_modele, l_modele, n_indice, b_saisie, d_creation, d_maj, " +
"c_opto_code_verre, d_demande_supp " +
"from modele_verre_ite";
public ModeleVerreIteStepConfig(){
super(
TypeStaging.REF_PROMOTEUR,
(rs, rowNum) -> {
Timestamp dCreation = rs.getTimestamp("d_creation");
Timestamp dMaj = rs.getTimestamp("d_maj");
Date dDemandeSupp = rs.getDate("d_demande_supp");
return new ModeleVerreIte(
rs.getInt("id_modele_verre_ite"),
rs.getInt("id_classe"),
rs.getInt("id_distributeur_ite"),
rs.getInt("id_fabricant_ite"),
rs.getInt("id_type_materiau_ite"),
rs.getInt("id_type_verre_ite"),
rs.getString("c_modele"),
rs.getString("l_modele"),
rs.getShort("n_indice"),
rs.getString("b_saisie"),
dCreation == null ? null : dCreation.toLocalDateTime(),
dMaj == null ? null : dMaj.toLocalDateTime(),
rs.getString("c_opto_code_verre"),
dDemandeSupp == null ? null : dDemandeSupp.toLocalDate(),
null
);
},
CodePromoteur.ITE
);
}
@Bean
public Step modeleVerreIteStep(StepBuilderFactory stepBuilderFactory, FileUtils fileUtils,
DataSource dataSource) throws IOException {
return super.buildStep(stepBuilderFactory, fileUtils, dataSource);
}
@Bean("modeleVerreIteReader")
@StepScope
@Override
protected GenerericJDBCItemReadFromDB<ModeleVerreIte> reader(
DataSource dataSource,
@Value("#{jobParameters['idPromoteur']}") Integer idPromoteur,
@Value("#{jobParameters['codePromoteur']}") String codePromoteur) throws IOException {
return super.buildReader(dataSource, QUERY, codePromoteur);
}
@Bean("modeleVerreIteWriter")
@StepScope
@Override
public AsyncItemWriter<ModeleVerreIte> 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);
}
}