Repository: nifi Updated Branches: refs/heads/master 946c2fe6b -> ee18ead16
NIFI-5297 - EL support in ScanAttribute This closes #2786 Signed-off-by: Mike Thomsen <mikerthom...@gmail.com> Project: http://git-wip-us.apache.org/repos/asf/nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/ee18ead1 Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/ee18ead1 Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/ee18ead1 Branch: refs/heads/master Commit: ee18ead16c7b0697560e27c63cf1dd06b1c38c4f Parents: 946c2fe Author: Pierre Villard <pierre.villard...@gmail.com> Authored: Mon Jun 11 21:39:19 2018 +0200 Committer: Mike Thomsen <mikerthom...@gmail.com> Committed: Mon Jun 11 18:48:38 2018 -0400 ---------------------------------------------------------------------- .../org/apache/nifi/processors/standard/ScanAttribute.java | 6 ++++-- .../org/apache/nifi/processors/standard/TestScanAttribute.java | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi/blob/ee18ead1/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ScanAttribute.java ---------------------------------------------------------------------- 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 c3dd214..8e6afd0 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.CapabilityDescription; 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 class ScanAttribute extends AbstractProcessor { 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<String> createDictionary(final ProcessContext context) throws IOException { final Set<String> 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))) { http://git-wip-us.apache.org/repos/asf/nifi/blob/ee18ead1/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanAttribute.java ---------------------------------------------------------------------- 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 b4a4136..07677a9 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 java.util.Map; 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<String, String> attributes = new HashMap<>(); attributes.put("abc", "world");