Search in sources :

Example 26 with DefaultLineMapper

use of org.springframework.batch.item.file.mapping.DefaultLineMapper in project spring-batch by roytuts.

the class SpringBatchConfig method fileItemReader.

@Bean
public FlatFileItemReader<Person> fileItemReader(BeanWrapperFieldSetMapper<Person> beanWrapperFieldSetMapper) {
    FlatFileItemReader<Person> fileItemReader = new FlatFileItemReader<>();
    fileItemReader.setResource(new ClassPathResource("person.csv"));
    DelimitedLineTokenizer delimitedLineTokenizer = new DelimitedLineTokenizer();
    delimitedLineTokenizer.setNames("id", "firstName", "lastName");
    DefaultLineMapper<Person> defaultLineMapper = new DefaultLineMapper<>();
    defaultLineMapper.setLineTokenizer(delimitedLineTokenizer);
    defaultLineMapper.setFieldSetMapper(beanWrapperFieldSetMapper);
    fileItemReader.setLineMapper(defaultLineMapper);
    return fileItemReader;
}
Also used : FlatFileItemReader(org.springframework.batch.item.file.FlatFileItemReader) DelimitedLineTokenizer(org.springframework.batch.item.file.transform.DelimitedLineTokenizer) DefaultLineMapper(org.springframework.batch.item.file.mapping.DefaultLineMapper) Person(com.roytuts.spring.batch.csvtomysql.vo.Person) ClassPathResource(org.springframework.core.io.ClassPathResource) JobRepositoryFactoryBean(org.springframework.batch.core.repository.support.JobRepositoryFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 27 with DefaultLineMapper

use of org.springframework.batch.item.file.mapping.DefaultLineMapper in project spring-batch by roytuts.

the class SpringBatchConfig method fileItemReader.

@Bean
public FlatFileItemReader<Person> fileItemReader() {
    FlatFileItemReader<Person> fileItemReader = new FlatFileItemReader<>();
    fileItemReader.setResource(new ClassPathResource("person.csv"));
    DelimitedLineTokenizer delimitedLineTokenizer = new DelimitedLineTokenizer();
    delimitedLineTokenizer.setNames("id", "firstName", "lastName");
    DefaultLineMapper<Person> defaultLineMapper = new DefaultLineMapper<>();
    defaultLineMapper.setLineTokenizer(delimitedLineTokenizer);
    defaultLineMapper.setFieldSetMapper(new PersonFieldSetMapper());
    fileItemReader.setLineMapper(defaultLineMapper);
    return fileItemReader;
}
Also used : FlatFileItemReader(org.springframework.batch.item.file.FlatFileItemReader) DelimitedLineTokenizer(org.springframework.batch.item.file.transform.DelimitedLineTokenizer) PersonFieldSetMapper(com.roytuts.spring.batch.csvtoxml.fieldset.mapper.PersonFieldSetMapper) DefaultLineMapper(org.springframework.batch.item.file.mapping.DefaultLineMapper) Person(com.roytuts.spring.batch.csvtoxml.vo.Person) ClassPathResource(org.springframework.core.io.ClassPathResource) JobRepositoryFactoryBean(org.springframework.batch.core.repository.support.JobRepositoryFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 28 with DefaultLineMapper

use of org.springframework.batch.item.file.mapping.DefaultLineMapper in project spring-batch by roytuts.

the class SpringBatchConfig method fileItemReader.

@Bean
public FlatFileItemReader<Person> fileItemReader(BeanWrapperFieldSetMapper<Person> beanWrapperFieldSetMapper) {
    FlatFileItemReader<Person> fileItemReader = new FlatFileItemReader<>();
    fileItemReader.setResource(new ClassPathResource("person.csv"));
    DelimitedLineTokenizer delimitedLineTokenizer = new DelimitedLineTokenizer();
    delimitedLineTokenizer.setNames("id", "firstName", "lastName");
    DefaultLineMapper<Person> defaultLineMapper = new DefaultLineMapper<>();
    defaultLineMapper.setLineTokenizer(delimitedLineTokenizer);
    defaultLineMapper.setFieldSetMapper(beanWrapperFieldSetMapper);
    fileItemReader.setLineMapper(defaultLineMapper);
    return fileItemReader;
}
Also used : FlatFileItemReader(org.springframework.batch.item.file.FlatFileItemReader) DelimitedLineTokenizer(org.springframework.batch.item.file.transform.DelimitedLineTokenizer) DefaultLineMapper(org.springframework.batch.item.file.mapping.DefaultLineMapper) Person(com.roytuts.spring.batch.task.scheduler.vo.Person) ClassPathResource(org.springframework.core.io.ClassPathResource) JobRepositoryFactoryBean(org.springframework.batch.core.repository.support.JobRepositoryFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 29 with DefaultLineMapper

use of org.springframework.batch.item.file.mapping.DefaultLineMapper in project spring-batch by roytuts.

the class SpringBatchConfig method reader.

@Bean
public // creates an item reader
ItemReader<User> reader() {
    FlatFileItemReader<User> reader = new FlatFileItemReader<User>();
    // look for file user.csv
    reader.setResource(new ClassPathResource("user.csv"));
    // line mapper
    DefaultLineMapper<User> lineMapper = new DefaultLineMapper<User>();
    // each line with comma separated
    lineMapper.setLineTokenizer(new DelimitedLineTokenizer());
    // map file's field with object
    lineMapper.setFieldSetMapper(new UserFieldSetMapper());
    reader.setLineMapper(lineMapper);
    return reader;
}
Also used : FlatFileItemReader(org.springframework.batch.item.file.FlatFileItemReader) DelimitedLineTokenizer(org.springframework.batch.item.file.transform.DelimitedLineTokenizer) User(com.roytuts.spring.batch.vo.User) DefaultLineMapper(org.springframework.batch.item.file.mapping.DefaultLineMapper) UserFieldSetMapper(com.roytuts.spring.batch.fieldset.mapper.UserFieldSetMapper) ClassPathResource(org.springframework.core.io.ClassPathResource) Bean(org.springframework.context.annotation.Bean)

Aggregations

DefaultLineMapper (org.springframework.batch.item.file.mapping.DefaultLineMapper)29 DelimitedLineTokenizer (org.springframework.batch.item.file.transform.DelimitedLineTokenizer)29 FlatFileItemReader (org.springframework.batch.item.file.FlatFileItemReader)18 FileSystemResource (org.springframework.core.io.FileSystemResource)13 Bean (org.springframework.context.annotation.Bean)10 ClassPathResource (org.springframework.core.io.ClassPathResource)7 JobRepositoryFactoryBean (org.springframework.batch.core.repository.support.JobRepositoryFactoryBean)5 CVRClinicalRecord (org.cbioportal.cmo.pipelines.cvr.model.staging.CVRClinicalRecord)3 Before (org.junit.Before)3 TaxonService (org.powo.api.TaxonService)3 ConversionService (org.springframework.core.convert.ConversionService)3 HashSet (java.util.HashSet)2 Transaction (org.baeldung.batch.model.Transaction)2 RecordFieldSetMapper (org.baeldung.batch.service.RecordFieldSetMapper)2 CVRFusionRecord (org.cbioportal.cmo.pipelines.cvr.model.staging.CVRFusionRecord)2 MskimpactSeqDate (org.cbioportal.cmo.pipelines.cvr.model.staging.MskimpactSeqDate)2 StringToIsoDateTimeConverter (org.powo.model.convert.StringToIsoDateTimeConverter)2 StepScope (org.springframework.batch.core.configuration.annotation.StepScope)2 BeanWrapperFieldSetMapper (org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper)2 ConversionServiceFactoryBean (org.springframework.context.support.ConversionServiceFactoryBean)2