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

pvillard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new 761571a6fb NIFI-14357 Write path and owner attributes in 
FetchBoxFileInfo
761571a6fb is described below

commit 761571a6fb51b2841e5a7eb1daa98bc4a536a6d3
Author: Alaksiej Ščarbaty <[email protected]>
AuthorDate: Wed Mar 12 13:24:57 2025 +0100

    NIFI-14357 Write path and owner attributes in FetchBoxFileInfo
    
    Signed-off-by: Pierre Villard <[email protected]>
    
    This closes #9798.
---
 .../org/apache/nifi/processors/box/BoxFileUtils.java     | 16 +++++++++++-----
 .../org/apache/nifi/processors/box/FetchBoxFileInfo.java | 14 +++++++++++---
 .../apache/nifi/processors/box/FetchBoxFileInfoTest.java |  9 +++++++++
 3 files changed, 31 insertions(+), 8 deletions(-)

diff --git 
a/nifi-extension-bundles/nifi-box-bundle/nifi-box-processors/src/main/java/org/apache/nifi/processors/box/BoxFileUtils.java
 
b/nifi-extension-bundles/nifi-box-bundle/nifi-box-processors/src/main/java/org/apache/nifi/processors/box/BoxFileUtils.java
index 81d72172f9..a0f7fea030 100644
--- 
a/nifi-extension-bundles/nifi-box-bundle/nifi-box-processors/src/main/java/org/apache/nifi/processors/box/BoxFileUtils.java
+++ 
b/nifi-extension-bundles/nifi-box-bundle/nifi-box-processors/src/main/java/org/apache/nifi/processors/box/BoxFileUtils.java
@@ -16,25 +16,31 @@
  */
 package org.apache.nifi.processors.box;
 
-import static java.lang.String.valueOf;
-
 import com.box.sdk.BoxFile;
 import com.box.sdk.BoxFolder;
 import com.box.sdk.BoxItem;
+import org.apache.nifi.flowfile.attributes.CoreAttributes;
+
 import java.util.LinkedHashMap;
 import java.util.Map;
-import java.util.stream.Collectors;
-import org.apache.nifi.flowfile.attributes.CoreAttributes;
+
+import static java.lang.String.valueOf;
+import static java.util.stream.Collectors.joining;
 
 public final class BoxFileUtils {
 
     public static final String BOX_URL = "https://app.box.com/file/";;
 
+    public static String getParentIds(final BoxItem.Info info) {
+        return info.getPathCollection().stream()
+                .map(BoxItem.Info::getID)
+                .collect(joining(","));
+    }
     public static String getParentPath(BoxItem.Info info) {
         return "/" + info.getPathCollection().stream()
                 .filter(pathItemInfo -> !pathItemInfo.getID().equals("0"))
                 .map(BoxItem.Info::getName)
-                .collect(Collectors.joining("/"));
+                .collect(joining("/"));
     }
 
     public static String getFolderPath(BoxFolder.Info folderInfo) {
diff --git 
a/nifi-extension-bundles/nifi-box-bundle/nifi-box-processors/src/main/java/org/apache/nifi/processors/box/FetchBoxFileInfo.java
 
b/nifi-extension-bundles/nifi-box-bundle/nifi-box-processors/src/main/java/org/apache/nifi/processors/box/FetchBoxFileInfo.java
index fb0663ba82..dcf90f6f70 100644
--- 
a/nifi-extension-bundles/nifi-box-bundle/nifi-box-processors/src/main/java/org/apache/nifi/processors/box/FetchBoxFileInfo.java
+++ 
b/nifi-extension-bundles/nifi-box-bundle/nifi-box-processors/src/main/java/org/apache/nifi/processors/box/FetchBoxFileInfo.java
@@ -20,6 +20,7 @@ import com.box.sdk.BoxAPIConnection;
 import com.box.sdk.BoxAPIException;
 import com.box.sdk.BoxAPIResponseException;
 import com.box.sdk.BoxFile;
+import com.box.sdk.BoxUser;
 import org.apache.nifi.annotation.behavior.InputRequirement;
 import org.apache.nifi.annotation.behavior.WritesAttribute;
 import org.apache.nifi.annotation.behavior.WritesAttributes;
@@ -64,10 +65,13 @@ import static 
org.apache.nifi.processors.box.BoxFileAttributes.TIMESTAMP_DESC;
         @WritesAttribute(attribute = ID, description = ID_DESC),
         @WritesAttribute(attribute = "filename", description = FILENAME_DESC),
         @WritesAttribute(attribute = "path", description = PATH_DESC),
+        @WritesAttribute(attribute = "box.path.folder.ids", description = "A 
comma separated list of file path_collection IDs"),
         @WritesAttribute(attribute = SIZE, description = SIZE_DESC),
         @WritesAttribute(attribute = TIMESTAMP, description = TIMESTAMP_DESC),
         @WritesAttribute(attribute = "box.created.at", description = "The 
creation date of the file"),
-        @WritesAttribute(attribute = "box.owner", description = "The owner of 
the file"),
+        @WritesAttribute(attribute = "box.owner", description = "The name of 
the file owner"),
+        @WritesAttribute(attribute = "box.owner.id", description = "The ID of 
the file owner"),
+        @WritesAttribute(attribute = "box.owner.login", description = "The 
login of the file owner"),
         @WritesAttribute(attribute = "box.description", description = "The 
description of the file"),
         @WritesAttribute(attribute = "box.etag", description = "The etag of 
the file"),
         @WritesAttribute(attribute = "box.sha1", description = "The SHA-1 hash 
of the file"),
@@ -197,10 +201,14 @@ public class FetchBoxFileInfo extends AbstractProcessor {
         addAttributeIfNotNull(attributes, "box.created.at", 
fileInfo.getCreatedAt());
         addAttributeIfNotNull(attributes, "box.trashed.at", 
fileInfo.getTrashedAt());
         addAttributeIfNotNull(attributes, "box.purged.at", 
fileInfo.getPurgedAt());
+        addAttributeIfNotNull(attributes, "box.path.folder.ids", 
BoxFileUtils.getParentIds(fileInfo));
 
         // Handle special cases
-        if (fileInfo.getOwnedBy() != null && fileInfo.getOwnedBy().getName() 
!= null) {
-            attributes.put("box.owner", fileInfo.getOwnedBy().getName());
+        final BoxUser.Info owner = fileInfo.getOwnedBy();
+        if (owner != null) {
+            addAttributeIfNotNull(attributes, "box.owner", owner.getName());
+            addAttributeIfNotNull(attributes, "box.owner.id", owner.getID());
+            addAttributeIfNotNull(attributes, "box.owner.login", 
owner.getLogin());
         }
 
         if (fileInfo.getParent() != null) {
diff --git 
a/nifi-extension-bundles/nifi-box-bundle/nifi-box-processors/src/test/java/org/apache/nifi/processors/box/FetchBoxFileInfoTest.java
 
b/nifi-extension-bundles/nifi-box-bundle/nifi-box-processors/src/test/java/org/apache/nifi/processors/box/FetchBoxFileInfoTest.java
index ebdb4e20a0..3d442f3d62 100644
--- 
a/nifi-extension-bundles/nifi-box-bundle/nifi-box-processors/src/test/java/org/apache/nifi/processors/box/FetchBoxFileInfoTest.java
+++ 
b/nifi-extension-bundles/nifi-box-bundle/nifi-box-processors/src/test/java/org/apache/nifi/processors/box/FetchBoxFileInfoTest.java
@@ -47,6 +47,8 @@ public class FetchBoxFileInfoTest extends AbstractBoxFileTest 
{
     private static final String TEST_ITEM_STATUS = "active";
     private static final String TEST_SEQUENCE_ID = "1";
     private static final String TEST_OWNER_NAME = "Test User";
+    private static final String TEST_OWNER_ID = "123456";
+    private static final String TEST_OWNER_LOGIN = "[email protected]";
     private static final String TEST_SHARED_LINK_URL = 
"https://app.box.com/s/abcdef123456";;
     private static final Date TEST_CREATED_AT = new Date(12345678L);
     private static final Date TEST_CONTENT_CREATED_AT = new Date(12345600L);
@@ -173,7 +175,10 @@ public class FetchBoxFileInfoTest extends 
AbstractBoxFileTest {
         when(mockFileInfo.getPurgedAt()).thenReturn(TEST_PURGED_AT);
 
         when(mockBoxUser.getName()).thenReturn(TEST_OWNER_NAME);
+        when(mockBoxUser.getID()).thenReturn(TEST_OWNER_ID);
+        when(mockBoxUser.getLogin()).thenReturn(TEST_OWNER_LOGIN);
         when(mockFileInfo.getOwnedBy()).thenReturn(mockBoxUser);
+
         when(mockSharedLink.getURL()).thenReturn(TEST_SHARED_LINK_URL);
         when(mockFileInfo.getSharedLink()).thenReturn(mockSharedLink);
 
@@ -193,6 +198,10 @@ public class FetchBoxFileInfoTest extends 
AbstractBoxFileTest {
         flowFile.assertAttributeEquals("box.content.created.at", 
TEST_CONTENT_CREATED_AT.toString());
         flowFile.assertAttributeEquals("box.content.modified.at", 
TEST_CONTENT_MODIFIED_AT.toString());
         flowFile.assertAttributeEquals("box.owner", TEST_OWNER_NAME);
+        flowFile.assertAttributeEquals("box.owner.id", TEST_OWNER_ID);
+        flowFile.assertAttributeEquals("box.owner.login", TEST_OWNER_LOGIN);
         flowFile.assertAttributeEquals("box.shared.link", 
TEST_SHARED_LINK_URL);
+        flowFile.assertAttributeEquals("box.path.folder.ids", 
mockBoxFolderInfo.getID());
+        flowFile.assertAttributeEquals("path", "/" + 
mockBoxFolderInfo.getName());
     }
 }
\ No newline at end of file

Reply via email to