Search in sources :

Example 1 with FieldSetMapper

use of org.powo.job.dwc.taxon.FieldSetMapper in project powop by RBGKew.

the class TaxonParsingTest method setUp.

@Before
public final void setUp() throws Exception {
    String[] names = new String[] { "http://rs.tdwg.org/dwc/terms/taxonID", "http://rs.tdwg.org/dwc/terms/scientificName", "http://rs.tdwg.org/dwc/terms/scientificNameID", "http://rs.tdwg.org/dwc/terms/scientificNameAuthorship", "http://rs.tdwg.org/dwc/terms/taxonRank", "http://rs.tdwg.org/dwc/terms/taxonomicStatus", "http://rs.tdwg.org/dwc/terms/parentNameUsageID", "http://rs.tdwg.org/dwc/terms/acceptedNameUsageID", "http://rs.tdwg.org/dwc/terms/genus", "http://rs.tdwg.org/dwc/terms/subgenus", "http://rs.tdwg.org/dwc/terms/specificEpithet", "http://rs.tdwg.org/dwc/terms/infraspecificEpithet", "http://purl.org/dc/elements/1.1/identifier", "http://purl.org/dc/elements/1.1/modified", "http://purl.org/dc/elements/1.1/source" };
    DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
    tokenizer.setDelimiter(DelimitedLineTokenizer.DELIMITER_TAB);
    tokenizer.setNames(names);
    taxonService = EasyMock.createMock(TaxonService.class);
    @SuppressWarnings("rawtypes") Set<Converter> converters = new HashSet<>();
    converters.add(new StringToIsoDateTimeConverter());
    converters.add(new TaxonomicStatusConverter());
    converters.add(new RankConverter());
    converters.add(new NomenclaturalStatusConverter());
    ConversionServiceFactoryBean factoryBean = new ConversionServiceFactoryBean();
    factoryBean.setConverters(converters);
    factoryBean.afterPropertiesSet();
    ConversionService conversionService = factoryBean.getObject();
    FieldSetMapper fieldSetMapper = new FieldSetMapper();
    fieldSetMapper.setFieldNames(names);
    fieldSetMapper.setDefaultValues(new HashMap<String, String>());
    fieldSetMapper.setConversionService(conversionService);
    DefaultLineMapper<Taxon> lineMapper = new DefaultLineMapper<Taxon>();
    lineMapper.setFieldSetMapper(fieldSetMapper);
    lineMapper.setLineTokenizer(tokenizer);
    flatFileItemReader.setEncoding("UTF-8");
    flatFileItemReader.setLinesToSkip(0);
    flatFileItemReader.setResource(content);
    flatFileItemReader.setLineMapper(lineMapper);
    flatFileItemReader.afterPropertiesSet();
}
Also used : DelimitedLineTokenizer(org.springframework.batch.item.file.transform.DelimitedLineTokenizer) TaxonService(org.powo.api.TaxonService) FieldSetMapper(org.powo.job.dwc.taxon.FieldSetMapper) Taxon(org.powo.model.Taxon) NomenclaturalStatusConverter(org.powo.model.convert.NomenclaturalStatusConverter) DefaultLineMapper(org.springframework.batch.item.file.mapping.DefaultLineMapper) RankConverter(org.powo.model.convert.RankConverter) ConversionServiceFactoryBean(org.springframework.context.support.ConversionServiceFactoryBean) ConversionService(org.springframework.core.convert.ConversionService) StringToIsoDateTimeConverter(org.powo.model.convert.StringToIsoDateTimeConverter) Converter(org.springframework.core.convert.converter.Converter) TaxonomicStatusConverter(org.powo.model.convert.TaxonomicStatusConverter) RankConverter(org.powo.model.convert.RankConverter) StringToIsoDateTimeConverter(org.powo.model.convert.StringToIsoDateTimeConverter) NomenclaturalStatusConverter(org.powo.model.convert.NomenclaturalStatusConverter) TaxonomicStatusConverter(org.powo.model.convert.TaxonomicStatusConverter) HashSet(java.util.HashSet) Before(org.junit.Before)

Aggregations

HashSet (java.util.HashSet)1 Before (org.junit.Before)1 TaxonService (org.powo.api.TaxonService)1 FieldSetMapper (org.powo.job.dwc.taxon.FieldSetMapper)1 Taxon (org.powo.model.Taxon)1 NomenclaturalStatusConverter (org.powo.model.convert.NomenclaturalStatusConverter)1 RankConverter (org.powo.model.convert.RankConverter)1 StringToIsoDateTimeConverter (org.powo.model.convert.StringToIsoDateTimeConverter)1 TaxonomicStatusConverter (org.powo.model.convert.TaxonomicStatusConverter)1 DefaultLineMapper (org.springframework.batch.item.file.mapping.DefaultLineMapper)1 DelimitedLineTokenizer (org.springframework.batch.item.file.transform.DelimitedLineTokenizer)1 ConversionServiceFactoryBean (org.springframework.context.support.ConversionServiceFactoryBean)1 ConversionService (org.springframework.core.convert.ConversionService)1 Converter (org.springframework.core.convert.converter.Converter)1