Updated 3.1 updates in sample apps

Simplified usage of Ranges in single-step-batch-job for filereader
This commit is contained in:
Glenn Renfro
2023-07-07 13:44:16 -04:00
parent 05b553dbde
commit 10dee0be5e
5 changed files with 12 additions and 10 deletions

View File

@@ -17,9 +17,7 @@
package org.springframework.cloud.task.batch.autoconfigure;
import org.springframework.batch.item.file.transform.Range;
import org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
/**
* Converter for taking properties of format {@code start-end} or {@code start} (where
@@ -29,8 +27,6 @@ import org.springframework.stereotype.Component;
* @author Michael Minella
* @since 2.3
*/
@Component
@ConfigurationPropertiesBinding
public class RangeConverter implements Converter<String, Range> {
@Override

View File

@@ -16,7 +16,9 @@
package org.springframework.cloud.task.batch.autoconfigure.flatfile;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.batch.item.file.FlatFileItemReader;
@@ -35,6 +37,7 @@ import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.task.batch.autoconfigure.RangeConverter;
import org.springframework.context.annotation.Bean;
/**
@@ -86,7 +89,10 @@ public class FlatFileItemReaderAutoConfiguration {
.fieldSetMapper(new MapFieldSetMapper());
}
else if (this.properties.isFixedLength()) {
mapFlatFileItemReaderBuilder.fixedLength().columns(this.properties.getRanges().toArray(new Range[0]))
RangeConverter rangeConverter = new RangeConverter();
List<Range> ranges = new ArrayList<>();
this.properties.getRanges().forEach(range -> ranges.add(rangeConverter.convert(range)));
mapFlatFileItemReaderBuilder.fixedLength().columns(ranges.toArray(new Range[0]))
.names(this.properties.getNames()).fieldSetMapper(new MapFieldSetMapper())
.beanMapperStrict(this.properties.isParsingStrict());
}

View File

@@ -113,7 +113,7 @@ public class FlatFileItemReaderProperties {
/**
* The column ranges to be used to parse a fixed width file.
*/
private List<Range> ranges = new ArrayList<>();
private List<String> ranges = new ArrayList<>();
/**
* The names of the fields to be parsed from the file.
@@ -373,7 +373,7 @@ public class FlatFileItemReaderProperties {
* The column ranges to be used to parsed a fixed width file.
* @return a list of {@link Range} instances
*/
public List<Range> getRanges() {
public List<String> getRanges() {
return this.ranges;
}
@@ -381,7 +381,7 @@ public class FlatFileItemReaderProperties {
* Column ranges for each field.
* @param ranges list of ranges in start-end format (end is optional)
*/
public void setRanges(List<Range> ranges) {
public void setRanges(List<String> ranges) {
this.ranges = ranges;
}

View File

@@ -78,7 +78,7 @@
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-single-step-batch-job</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.batch</groupId>

View File

@@ -7,7 +7,7 @@
<artifactId>timestamp-task</artifactId>
<packaging>jar</packaging>
<name>Timestamp Task</name>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<description>Spring Cloud Timestamp Task</description>
<parent>