use of org.springframework.batch.core.configuration.annotation.StepScope in project tutorials by eugenp.
the class SpringbatchPartitionConfig method itemReader.
@Bean
@StepScope
public FlatFileItemReader<Transaction> itemReader(@Value("#{stepExecutionContext[fileName]}") String filename) throws UnexpectedInputException, ParseException {
FlatFileItemReader<Transaction> reader = new FlatFileItemReader<>();
DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
String[] tokens = { "username", "userid", "transactiondate", "amount" };
tokenizer.setNames(tokens);
reader.setResource(new ClassPathResource("input/partitioner/" + filename));
DefaultLineMapper<Transaction> lineMapper = new DefaultLineMapper<>();
lineMapper.setLineTokenizer(tokenizer);
lineMapper.setFieldSetMapper(new RecordFieldSetMapper());
reader.setLinesToSkip(1);
reader.setLineMapper(lineMapper);
return reader;
}
use of org.springframework.batch.core.configuration.annotation.StepScope in project RecordManager2 by moravianlibrary.
the class ZakonyProLidiHarvestJobConfig method zakonyProLidiFulltextReader.
@Bean(name = Constants.JOB_ID_FULLTEXT_ZAKONYPROLIDI + ":reader")
@StepScope
public ItemReader<HarvestedRecordUniqueId> zakonyProLidiFulltextReader(@Value("#{jobParameters[" + Constants.JOB_PARAM_CONF_ID + "]}") Long configId) throws Exception {
JdbcPagingItemReader<HarvestedRecordUniqueId> reader = new JdbcPagingItemReader<HarvestedRecordUniqueId>();
SqlPagingQueryProviderFactoryBean pqpf = new SqlPagingQueryProviderFactoryBean();
pqpf.setDataSource(dataSource);
pqpf.setSelectClause("SELECT import_conf_id, record_id");
pqpf.setFromClause("FROM harvested_record");
pqpf.setWhereClause("WHERE import_conf_id = :conf_id and deleted is null");
pqpf.setSortKeys(ImmutableMap.of("record_id", Order.DESCENDING));
Map<String, Object> parameterValues = new HashMap<String, Object>();
parameterValues.put("conf_id", configId);
reader.setParameterValues(parameterValues);
reader.setRowMapper(new HarvestedRecordIdRowMapper());
reader.setPageSize(1);
reader.setQueryProvider(pqpf.getObject());
reader.setDataSource(dataSource);
reader.afterPropertiesSet();
return reader;
}
use of org.springframework.batch.core.configuration.annotation.StepScope in project RecordManager2 by moravianlibrary.
the class ExportRecordsJobConfig method exportRecordsWriter.
@Bean(name = "exportRecordsJob:exportRecordsWriter")
@StepScope
public FlatFileItemWriter<String> exportRecordsWriter(@Value("#{jobParameters[" + Constants.JOB_PARAM_OUT_FILE + "]}") String filename) throws Exception {
FlatFileItemWriter<String> fileWritter = new FlatFileItemWriter<String>();
fileWritter.setAppendAllowed(false);
fileWritter.setShouldDeleteIfExists(true);
fileWritter.setEncoding("UTF-8");
fileWritter.setLineAggregator(new PassThroughLineAggregator<String>());
fileWritter.setResource(new FileSystemResource(filename));
fileWritter.afterPropertiesSet();
return fileWritter;
}
use of org.springframework.batch.core.configuration.annotation.StepScope in project RecordManager2 by moravianlibrary.
the class ExportRecordsJobConfig method exportCosmotron996Reader.
@Bean(name = Constants.JOB_ID_EXPORT_COSMOTRON_996 + ":exportCosmotron996Reader")
@StepScope
public ItemReader<Cosmotron996> exportCosmotron996Reader(@Value("#{jobParameters[" + Constants.JOB_PARAM_CONF_ID + "]}") Long configId) throws Exception {
JdbcPagingItemReader<Cosmotron996> reader = new JdbcPagingItemReader<Cosmotron996>();
SqlPagingQueryProviderFactoryBean pqpf = new SqlPagingQueryProviderFactoryBean();
pqpf.setDataSource(dataSource);
pqpf.setSelectClause("SELECT *");
pqpf.setFromClause("FROM cosmotron_996");
pqpf.setWhereClause("WHERE import_conf_id = :conf_id");
pqpf.setSortKey("record_id");
Map<String, Object> parameterValues = new HashMap<String, Object>();
parameterValues.put("conf_id", configId);
reader.setParameterValues(parameterValues);
reader.setRowMapper(new Cosmotron996RowMapper());
reader.setPageSize(20);
reader.setQueryProvider(pqpf.getObject());
reader.setDataSource(dataSource);
reader.afterPropertiesSet();
return reader;
}
use of org.springframework.batch.core.configuration.annotation.StepScope in project RecordManager2 by moravianlibrary.
the class ExportRecordsJobConfig method exportRecordsForClassifierReader.
@Bean(name = "exportRecordsForClassifierJob:exportRecordsForClassifierReader")
@StepScope
public ItemReader<HarvestedRecordUniqueId> exportRecordsForClassifierReader(@Value("#{jobParameters[" + Constants.JOB_PARAM_CONF_ID + "]}") Long configId) throws Exception {
JdbcPagingItemReader<HarvestedRecordUniqueId> reader = new JdbcPagingItemReader<HarvestedRecordUniqueId>();
SqlPagingQueryProviderFactoryBean pqpf = new SqlPagingQueryProviderFactoryBean();
pqpf.setDataSource(dataSource);
pqpf.setSelectClause("SELECT import_conf_id, record_id");
pqpf.setFromClause("FROM harvested_record");
pqpf.setWhereClause("WHERE import_conf_id = :conf_id AND dedup_record_id IN ( " + " SELECT dedup_record_id " + " FROM harvested_record " + " WHERE EXISTS( " + " SELECT 1 " + " FROM fulltext_kramerius " + " WHERE harvested_record.id = fulltext_kramerius.harvested_record_id " + " ))");
pqpf.setSortKey("record_id");
Map<String, Object> parameterValues = new HashMap<String, Object>();
parameterValues.put("conf_id", configId);
reader.setParameterValues(parameterValues);
reader.setRowMapper(new HarvestedRecordIdRowMapper());
reader.setPageSize(20);
reader.setQueryProvider(pqpf.getObject());
reader.setDataSource(dataSource);
reader.afterPropertiesSet();
return reader;
}
Aggregations