From 589e631ec4f038b0cd4919305671a25b0ba436c0 Mon Sep 17 00:00:00 2001 From: Pierre Villard Date: Mon, 11 Jun 2018 21:39:19 +0200 Subject: [PATCH] NIFI-5297 - EL support in ScanAttribute --- .../org/apache/nifi/processors/standard/ScanAttribute.java | 6 ++++-- .../apache/nifi/processors/standard/TestScanAttribute.java | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ScanAttribute.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ScanAttribute.java index c3dd2143ebe5..8e6afd0f7ffa 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ScanAttribute.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ScanAttribute.java @@ -41,6 +41,7 @@ import org.apache.nifi.annotation.documentation.Tags; import org.apache.nifi.annotation.lifecycle.OnScheduled; import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.expression.ExpressionLanguageScope; import org.apache.nifi.flowfile.FlowFile; import org.apache.nifi.logging.ComponentLog; import org.apache.nifi.processor.AbstractProcessor; @@ -87,6 +88,7 @@ public class ScanAttribute extends AbstractProcessor { + "the text file are loaded into memory when the processor is scheduled and reloaded when the contents are modified.") .required(true) .addValidator(StandardValidators.FILE_EXISTS_VALIDATOR) + .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY) .build(); public static final PropertyDescriptor DICTIONARY_FILTER = new PropertyDescriptor.Builder() .name("Dictionary Filter Pattern") @@ -150,13 +152,13 @@ public void onScheduled(final ProcessContext context) throws IOException { this.attributePattern = (attributeRegex.equals(".*")) ? null : Pattern.compile(attributeRegex); this.dictionaryTerms = createDictionary(context); - this.fileWatcher = new SynchronousFileWatcher(Paths.get(context.getProperty(DICTIONARY_FILE).getValue()), new LastModifiedMonitor(), 1000L); + this.fileWatcher = new SynchronousFileWatcher(Paths.get(context.getProperty(DICTIONARY_FILE).evaluateAttributeExpressions().getValue()), new LastModifiedMonitor(), 1000L); } private Set createDictionary(final ProcessContext context) throws IOException { final Set terms = new HashSet<>(); - final File file = new File(context.getProperty(DICTIONARY_FILE).getValue()); + final File file = new File(context.getProperty(DICTIONARY_FILE).evaluateAttributeExpressions().getValue()); try (final InputStream fis = new FileInputStream(file); final BufferedReader reader = new BufferedReader(new InputStreamReader(fis))) { diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanAttribute.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanAttribute.java index b4a41369f2b9..07677a97b60c 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanAttribute.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanAttribute.java @@ -21,7 +21,6 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; - import org.junit.Test; public class TestScanAttribute { @@ -29,7 +28,8 @@ public class TestScanAttribute { @Test public void testSingleMatch() { final TestRunner runner = TestRunners.newTestRunner(new ScanAttribute()); - runner.setProperty(ScanAttribute.DICTIONARY_FILE, "src/test/resources/ScanAttribute/dictionary1"); + runner.setVariable("dictionary", "src/test/resources/ScanAttribute/dictionary1"); + runner.setProperty(ScanAttribute.DICTIONARY_FILE, "${dictionary}"); final Map attributes = new HashMap<>(); attributes.put("abc", "world");