You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by lo...@apache.org on 2022/02/14 11:43:55 UTC

[nifi] branch NIFI-9058 created (now ff81c1c)

This is an automated email from the ASF dual-hosted git repository.

lordgamez pushed a change to branch NIFI-9058
in repository https://gitbox.apache.org/repos/asf/nifi.git.


      at ff81c1c  Remove unused parameter from buildAtrs

This branch includes the following new commits:

     new 0cc4fa4  NIFI-9058 Core attributes shall not be filtered from Attributes List
     new ff81c1c  Remove unused parameter from buildAtrs

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[nifi] 02/02: Remove unused parameter from buildAtrs

Posted by lo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lordgamez pushed a commit to branch NIFI-9058
in repository https://gitbox.apache.org/repos/asf/nifi.git

commit ff81c1c810bb972ebe7de9d9915fc024a76ec0f2
Author: Gabor Gyimesi <ga...@gmail.com>
AuthorDate: Mon Feb 14 12:42:54 2022 +0100

    Remove unused parameter from buildAtrs
---
 .../java/org/apache/nifi/processors/standard/AttributesToJSON.java    | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AttributesToJSON.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AttributesToJSON.java
index 3e9fd61..b9af5c1 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AttributesToJSON.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AttributesToJSON.java
@@ -205,7 +205,7 @@ public class AttributesToJSON extends AbstractProcessor {
         return result;
     }
 
-    private Set<String> buildAtrs(String atrList, Set<String> atrsToExclude) {
+    private Set<String> buildAtrs(String atrList) {
         //If list of attributes specified get only those attributes. Otherwise write them all
         if (StringUtils.isNotBlank(atrList)) {
             String[] ats = StringUtils.split(atrList, AT_LIST_SEPARATOR);
@@ -225,7 +225,7 @@ public class AttributesToJSON extends AbstractProcessor {
         attributesToRemove = context.getProperty(INCLUDE_CORE_ATTRIBUTES).asBoolean() ? Collections.EMPTY_SET : Arrays.stream(CoreAttributes.values())
                 .map(CoreAttributes::key)
                 .collect(Collectors.toSet());
-        attributes = buildAtrs(context.getProperty(ATTRIBUTES_LIST).getValue(), attributesToRemove);
+        attributes = buildAtrs(context.getProperty(ATTRIBUTES_LIST).getValue());
         nullValueForEmptyString = context.getProperty(NULL_VALUE_FOR_EMPTY_STRING).asBoolean();
         destinationContent = DESTINATION_CONTENT.equals(context.getProperty(DESTINATION).getValue());
         if(context.getProperty(ATTRIBUTES_REGEX).isSet()) {

[nifi] 01/02: NIFI-9058 Core attributes shall not be filtered from Attributes List

Posted by lo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lordgamez pushed a commit to branch NIFI-9058
in repository https://gitbox.apache.org/repos/asf/nifi.git

commit 0cc4fa4628d5de5425afe71990a8b632c0762062
Author: Gabor Gyimesi <ga...@gmail.com>
AuthorDate: Wed Aug 18 15:51:54 2021 +0200

    NIFI-9058 Core attributes shall not be filtered from Attributes List
---
 .../nifi/processors/standard/AttributesToJSON.java |  5 +---
 .../processors/standard/TestAttributesToJSON.java  | 29 ++++++++++++++++++++++
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AttributesToJSON.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AttributesToJSON.java
index eb1b52a..3e9fd61 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AttributesToJSON.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AttributesToJSON.java
@@ -212,10 +212,7 @@ public class AttributesToJSON extends AbstractProcessor {
             if (ats != null) {
                 Set<String> result = new HashSet<>(ats.length);
                 for (String str : ats) {
-                    String trim = str.trim();
-                    if (!atrsToExclude.contains(trim)) {
-                        result.add(trim);
-                    }
+                    result.add(str.trim());
                 }
                 return result;
             }
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToJSON.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToJSON.java
index 84f5c7d..40352fe 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToJSON.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToJSON.java
@@ -310,6 +310,35 @@ public class TestAttributesToJSON {
         ObjectMapper mapper = new ObjectMapper();
         Map<String, String> val = mapper.readValue(json, HashMap.class);
         assertEquals(TEST_ATTRIBUTE_VALUE, val.get(TEST_ATTRIBUTE_KEY));
+        assertEquals(TEST_ATTRIBUTE_VALUE, val.get(CoreAttributes.PATH.key()));
+        assertEquals(2, val.size());
+    }
+
+    @Test
+    public void testAttribute_noIncludeCoreAttributesRegex() throws IOException {
+        final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToJSON());
+        testRunner.setProperty(AttributesToJSON.ATTRIBUTES_REGEX, CoreAttributes.PATH.key() + ".*");
+        testRunner.setProperty(AttributesToJSON.INCLUDE_CORE_ATTRIBUTES, "false");
+
+        ProcessSession session = testRunner.getProcessSessionFactory().createSession();
+        FlowFile ff = session.create();
+        ff = session.putAttribute(ff, TEST_ATTRIBUTE_KEY, TEST_ATTRIBUTE_VALUE);
+        ff = session.putAttribute(ff, CoreAttributes.PATH.key(), TEST_ATTRIBUTE_VALUE);
+
+        testRunner.enqueue(ff);
+        testRunner.run();
+
+        testRunner.getFlowFilesForRelationship(AttributesToJSON.REL_SUCCESS).get(0)
+                .assertAttributeExists(AttributesToJSON.JSON_ATTRIBUTE_NAME);
+        testRunner.assertTransferCount(AttributesToJSON.REL_SUCCESS, 1);
+        testRunner.assertTransferCount(AttributesToJSON.REL_FAILURE, 0);
+
+        String json = testRunner.getFlowFilesForRelationship(AttributesToJSON.REL_SUCCESS)
+                .get(0).getAttribute(AttributesToJSON.JSON_ATTRIBUTE_NAME);
+
+        ObjectMapper mapper = new ObjectMapper();
+        Map<String, String> val = mapper.readValue(json, HashMap.class);
+        assertEquals(TEST_ATTRIBUTE_VALUE, val.get(CoreAttributes.PATH.key()));
         assertEquals(1, val.size());
     }