NIFI-12410 Support EL for Starting Row in ExcelReader

This closes #8119

Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
dan-s1 2023-12-04 17:07:10 +00:00 committed by exceptionfactory
parent 8645088e1d
commit ab8a82b997
No known key found for this signature in database
GPG Key ID: 29B6A52D2AAE8DBA
1 changed files with 5 additions and 6 deletions

View File

@ -79,12 +79,11 @@ public class ExcelReader extends SchemaRegistryService implements RecordReaderFa
+ " Use this to skip over rows of data at the top of a worksheet that are not part of the dataset.") + " Use this to skip over rows of data at the top of a worksheet that are not part of the dataset.")
.required(true) .required(true)
.defaultValue("1") .defaultValue("1")
.expressionLanguageSupported(ExpressionLanguageScope.NONE) .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
.addValidator(StandardValidators.NON_NEGATIVE_INTEGER_VALIDATOR) .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
.build(); .build();
private volatile ConfigurationContext configurationContext; private volatile ConfigurationContext configurationContext;
private volatile int firstRow;
private volatile String dateFormat; private volatile String dateFormat;
private volatile String timeFormat; private volatile String timeFormat;
private volatile String timestampFormat; private volatile String timestampFormat;
@ -92,7 +91,6 @@ public class ExcelReader extends SchemaRegistryService implements RecordReaderFa
@OnEnabled @OnEnabled
public void onEnabled(final ConfigurationContext context) { public void onEnabled(final ConfigurationContext context) {
this.configurationContext = context; this.configurationContext = context;
this.firstRow = getStartingRow(context);
this.dateFormat = context.getProperty(DateTimeUtils.DATE_FORMAT).getValue(); this.dateFormat = context.getProperty(DateTimeUtils.DATE_FORMAT).getValue();
this.timeFormat = context.getProperty(DateTimeUtils.TIME_FORMAT).getValue(); this.timeFormat = context.getProperty(DateTimeUtils.TIME_FORMAT).getValue();
this.timestampFormat = context.getProperty(DateTimeUtils.TIMESTAMP_FORMAT).getValue(); this.timestampFormat = context.getProperty(DateTimeUtils.TIMESTAMP_FORMAT).getValue();
@ -107,6 +105,7 @@ public class ExcelReader extends SchemaRegistryService implements RecordReaderFa
in.reset(); in.reset();
final List<String> requiredSheets = getRequiredSheets(variables); final List<String> requiredSheets = getRequiredSheets(variables);
final int firstRow = getStartingRow(variables);
final ExcelRecordReaderConfiguration configuration = new ExcelRecordReaderConfiguration.Builder() final ExcelRecordReaderConfiguration configuration = new ExcelRecordReaderConfiguration.Builder()
.withDateFormat(dateFormat) .withDateFormat(dateFormat)
.withRequiredSheets(requiredSheets) .withRequiredSheets(requiredSheets)
@ -154,8 +153,8 @@ public class ExcelReader extends SchemaRegistryService implements RecordReaderFa
return SchemaInferenceUtil.INFER_SCHEMA; return SchemaInferenceUtil.INFER_SCHEMA;
} }
private int getStartingRow(final PropertyContext context) { private int getStartingRow(final Map<String, String> variables) {
int rawStartingRow = context.getProperty(STARTING_ROW).asInteger(); int rawStartingRow = configurationContext.getProperty(STARTING_ROW).evaluateAttributeExpressions(variables).asInteger();
return getZeroBasedIndex(rawStartingRow); return getZeroBasedIndex(rawStartingRow);
} }