turcsanyip commented on code in PR #6355:
URL: https://github.com/apache/nifi/pull/6355#discussion_r972431295


##########
nifi-nar-bundles/nifi-box-bundle/nifi-box-services-api/pom.xml:
##########
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements. See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License. You may obtain a copy of the License at
+  http://www.apache.org/licenses/LICENSE-2.0
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
https://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <artifactId>nifi-box-bundle</artifactId>
+        <groupId>org.apache.nifi</groupId>
+        <version>1.18.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>nifi-box-services-api</artifactId>
+    <packaging>jar</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.box</groupId>
+            <artifactId>box-java-sdk</artifactId>
+            <version>3.4.0</version>
+        </dependency>

Review Comment:
   `3.6.0` has been released in the meantime. Please use the latest version.



##########
nifi-nar-bundles/nifi-box-bundle/nifi-box-services/pom.xml:
##########
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements. See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License. You may obtain a copy of the License at
+  http://www.apache.org/licenses/LICENSE-2.0
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
https://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <artifactId>nifi-box-bundle</artifactId>
+        <groupId>org.apache.nifi</groupId>
+        <version>1.18.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>nifi-box-services</artifactId>
+    <packaging>jar</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.nifi</groupId>
+            <artifactId>nifi-box-services-api</artifactId>
+            <version>1.18.0-SNAPSHOT</version>
+        </dependency>

Review Comment:
   It should be `provided` because it comes from the parent NAR.



##########
nifi-nar-bundles/nifi-box-bundle/nifi-box-processors/src/main/java/org/apache/nifi/processors/box/ListBoxFiles.java:
##########
@@ -0,0 +1,262 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.box;
+
+import com.box.sdk.BoxAPIConnection;
+import com.box.sdk.BoxFile;
+import com.box.sdk.BoxFolder;
+import com.box.sdk.BoxItem;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.InputRequirement.Requirement;
+import org.apache.nifi.annotation.behavior.PrimaryNodeOnly;
+import org.apache.nifi.annotation.behavior.Stateful;
+import org.apache.nifi.annotation.behavior.TriggerSerially;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.box.controllerservices.BoxClientService;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.state.Scope;
+import org.apache.nifi.context.PropertyContext;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processor.util.list.AbstractListProcessor;
+import org.apache.nifi.processor.util.list.ListedEntityTracker;
+import org.apache.nifi.serialization.record.RecordSchema;
+
+import java.io.IOException;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+@PrimaryNodeOnly
+@TriggerSerially
+@Tags({"box", "storage"})
+@CapabilityDescription("Lists files in a Box folder. " +
+    "Each listed file may result in one FlowFile, the metadata being written 
as FlowFile attributes. " +
+    "Or - in case the 'Record Writer' property is set - the entire result is 
written as records to a single FlowFile. " +
+    "This Processor is designed to run on Primary Node only in a cluster. If 
the primary node changes, the new Primary Node will pick up where the " +
+    "previous node left off without duplicating all of the data.")
+@SeeAlso({FetchBoxFiles.class})
+@InputRequirement(Requirement.INPUT_FORBIDDEN)
+@WritesAttributes({@WritesAttribute(attribute = BoxFileInfo.ID, description = 
"The id of the file"),
+    @WritesAttribute(attribute = BoxFileInfo.FILENAME, description = "The name 
of the file"),
+    @WritesAttribute(attribute = BoxFileInfo.PATH, description = "The path of 
the file on Box"),
+    @WritesAttribute(attribute = BoxFileInfo.SIZE, description = "The size of 
the file (in bytes)"),
+    @WritesAttribute(attribute = BoxFileInfo.TIMESTAMP, description = "The 
last modified time of the file.")})
+@Stateful(scopes = {Scope.CLUSTER}, description = "The processor stores 
necessary data to be able to keep track what files have been listed already." +
+    " What exactly needs to be stored depends on the 'Listing Strategy'.")
+public class ListBoxFiles extends AbstractListProcessor<BoxFileInfo> {
+    public static final PropertyDescriptor FOLDER_ID = new 
PropertyDescriptor.Builder()
+        .name("box-folder-id")
+        .displayName("Folder ID")
+        .description("The ID of the folder from which to pull list of files.")
+        .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+        .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+        .required(true)
+        .build();
+
+    public static final PropertyDescriptor RECURSIVE_SEARCH = new 
PropertyDescriptor.Builder()
+        .name("recursive-search")
+        .displayName("Search Recursively")
+        .description("When 'true', will include list of files from 
sub-folders." +
+            " Otherwise, will return only files that are within the folder 
defined by the 'Folder ID' property.")
+        .required(true)
+        .defaultValue("true")
+        .allowableValues("true", "false")
+        .build();
+
+    public static final PropertyDescriptor MIN_AGE = new 
PropertyDescriptor.Builder()
+        .name("min-age")
+        .displayName("Minimum File Age")
+        .description("The minimum age a file must be in order to be 
considered; any files younger than this will be ignored.")
+        .required(true)
+        .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+        .defaultValue("0 sec")
+        .build();
+
+    public static final PropertyDescriptor LISTING_STRATEGY = new 
PropertyDescriptor.Builder()
+        .fromPropertyDescriptor(AbstractListProcessor.LISTING_STRATEGY)
+        .allowableValues(BY_TIMESTAMPS, BY_ENTITIES, BY_TIME_WINDOW, 
NO_TRACKING)
+        .build();
+
+    public static final PropertyDescriptor TRACKING_STATE_CACHE = new 
PropertyDescriptor.Builder()
+        .fromPropertyDescriptor(ListedEntityTracker.TRACKING_STATE_CACHE)
+        .dependsOn(LISTING_STRATEGY, BY_ENTITIES)
+        .build();
+
+    public static final PropertyDescriptor TRACKING_TIME_WINDOW = new 
PropertyDescriptor.Builder()
+        .fromPropertyDescriptor(ListedEntityTracker.TRACKING_TIME_WINDOW)
+        .dependsOn(LISTING_STRATEGY, BY_ENTITIES)
+        .build();
+
+    public static final PropertyDescriptor INITIAL_LISTING_TARGET = new 
PropertyDescriptor.Builder()
+        .fromPropertyDescriptor(ListedEntityTracker.INITIAL_LISTING_TARGET)
+        .dependsOn(LISTING_STRATEGY, BY_ENTITIES)
+        .build();
+
+    private static final List<PropertyDescriptor> PROPERTIES = 
Collections.unmodifiableList(Arrays.asList(
+        FOLDER_ID,
+        BoxClientService.BOX_CLIENT_SERVICE,
+        RECURSIVE_SEARCH,

Review Comment:
   Please move the `Box Client Service` to the first position (similar to 
GoogleDrive and Dropbox processors).
   ```suggestion
           BoxClientService.BOX_CLIENT_SERVICE,
           FOLDER_ID,
           RECURSIVE_SEARCH,
   ```



##########
nifi-nar-bundles/nifi-box-bundle/nifi-box-nar/src/main/resources/META-INF/NOTICE:
##########
@@ -0,0 +1,16 @@
+nifi-box-nar
+Copyright 2015-2020 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+******************
+Apache Software License v2
+******************
+
+The following binary components are provided under the Apache Software License 
v2
+
+  (ASLv2) The Box SDK for Java
+    The following NOTICE information applies:
+      The Box SDK for Java
+      Copyright 2019 Box, Inc. All rights reserved.

Review Comment:
   Box SDK should not be packaged in the `nifi-box-services-nar`, this entry 
will be not needed in that case.
   
   However, Jackson jars are present in the NAR (coming with nifi-json-utils) 
and it needs to be mentioned in the NOTICE file.



##########
nifi-nar-bundles/nifi-box-bundle/nifi-box-processors/pom.xml:
##########
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements. See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License. You may obtain a copy of the License at
+  http://www.apache.org/licenses/LICENSE-2.0
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
https://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.nifi</groupId>
+        <artifactId>nifi-box-bundle</artifactId>
+        <version>1.18.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>nifi-box-processors</artifactId>
+    <packaging>jar</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.box</groupId>
+            <artifactId>box-java-sdk</artifactId>
+            <version>3.4.0</version>
+        </dependency>

Review Comment:
   It comes with `nifi-box-services-api` transitively and it should not be 
declared here (otherwise it will be packaged into the processors NAR 
unnecessarily).



##########
nifi-nar-bundles/nifi-box-bundle/nifi-box-processors/src/main/java/org/apache/nifi/processors/box/BoxFileInfo.java:
##########
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.box;
+
+import org.apache.nifi.processor.util.list.ListableEntity;
+import org.apache.nifi.serialization.SimpleRecordSchema;
+import org.apache.nifi.serialization.record.MapRecord;
+import org.apache.nifi.serialization.record.Record;
+import org.apache.nifi.serialization.record.RecordField;
+import org.apache.nifi.serialization.record.RecordFieldType;
+import org.apache.nifi.serialization.record.RecordSchema;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class BoxFileInfo implements ListableEntity {
+    public static final String ID = "box.id";
+    public static final String FILENAME = "filename";
+    public static final String PATH = "box.path";

Review Comment:
   Please use `path` instead (the usual `path` + `filename` attribute pair).



##########
nifi-nar-bundles/nifi-box-bundle/nifi-box-services-api-nar/src/main/resources/META-INF/NOTICE:
##########
@@ -0,0 +1,16 @@
+nifi-box-nar
+Copyright 2015-2020 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+******************
+Apache Software License v2
+******************
+
+The following binary components are provided under the Apache Software License 
v2
+
+  (ASLv2) The Box SDK for Java
+    The following NOTICE information applies:
+      The Box SDK for Java
+      Copyright 2019 Box, Inc. All rights reserved.

Review Comment:
   Box SDK has some transitive dependencies that are packaged in the NAR and 
therefore they should be mentioned in the NOTICE file(s).
   ```
   [INFO] +- com.box:box-java-sdk:jar:3.4.0:compile
   [INFO] |  +- com.eclipsesource.minimal-json:minimal-json:jar:0.9.5:runtime
   [INFO] |  +- org.bitbucket.b_c:jose4j:jar:0.7.9:runtime
   [INFO] |  +- org.bouncycastle:bcprov-jdk15on:jar:1.70:runtime
   [INFO] |  \- org.bouncycastle:bcpkix-jdk15on:jar:1.70:runtime
   [INFO] |     \- org.bouncycastle:bcutil-jdk15on:jar:1.70:runtime
   ```
   



##########
nifi-nar-bundles/nifi-box-bundle/nifi-box-services-nar/src/main/resources/META-INF/NOTICE:
##########
@@ -0,0 +1,16 @@
+nifi-box-nar
+Copyright 2015-2020 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+******************
+Apache Software License v2
+******************
+
+The following binary components are provided under the Apache Software License 
v2
+
+  (ASLv2) The Box SDK for Java
+    The following NOTICE information applies:
+      The Box SDK for Java
+      Copyright 2019 Box, Inc. All rights reserved.

Review Comment:
   Box SDK is not packaged in the `nifi-box-services-nar` so this entry is not 
needed.
   
   However, Jackson jars are present in the NAR (coming with `nifi-json-utils`) 
and it needs to be mentioned in the NOTICE file. 



##########
nifi-nar-bundles/nifi-box-bundle/nifi-box-processors/pom.xml:
##########
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements. See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License. You may obtain a copy of the License at
+  http://www.apache.org/licenses/LICENSE-2.0
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
https://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.nifi</groupId>
+        <artifactId>nifi-box-bundle</artifactId>
+        <version>1.18.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>nifi-box-processors</artifactId>
+    <packaging>jar</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.box</groupId>
+            <artifactId>box-java-sdk</artifactId>
+            <version>3.4.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.nifi</groupId>
+            <artifactId>nifi-box-services-api</artifactId>
+            <version>1.18.0-SNAPSHOT</version>
+        </dependency>

Review Comment:
   It should be `provided` because it comes from the parent NAR.



##########
nifi-nar-bundles/nifi-box-bundle/nifi-box-processors/src/main/java/org/apache/nifi/processors/box/ListBoxFiles.java:
##########
@@ -0,0 +1,262 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.box;
+
+import com.box.sdk.BoxAPIConnection;
+import com.box.sdk.BoxFile;
+import com.box.sdk.BoxFolder;
+import com.box.sdk.BoxItem;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.InputRequirement.Requirement;
+import org.apache.nifi.annotation.behavior.PrimaryNodeOnly;
+import org.apache.nifi.annotation.behavior.Stateful;
+import org.apache.nifi.annotation.behavior.TriggerSerially;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.box.controllerservices.BoxClientService;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.state.Scope;
+import org.apache.nifi.context.PropertyContext;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processor.util.list.AbstractListProcessor;
+import org.apache.nifi.processor.util.list.ListedEntityTracker;
+import org.apache.nifi.serialization.record.RecordSchema;
+
+import java.io.IOException;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+@PrimaryNodeOnly
+@TriggerSerially
+@Tags({"box", "storage"})
+@CapabilityDescription("Lists files in a Box folder. " +
+    "Each listed file may result in one FlowFile, the metadata being written 
as FlowFile attributes. " +
+    "Or - in case the 'Record Writer' property is set - the entire result is 
written as records to a single FlowFile. " +
+    "This Processor is designed to run on Primary Node only in a cluster. If 
the primary node changes, the new Primary Node will pick up where the " +
+    "previous node left off without duplicating all of the data.")
+@SeeAlso({FetchBoxFiles.class})
+@InputRequirement(Requirement.INPUT_FORBIDDEN)
+@WritesAttributes({@WritesAttribute(attribute = BoxFileInfo.ID, description = 
"The id of the file"),
+    @WritesAttribute(attribute = BoxFileInfo.FILENAME, description = "The name 
of the file"),
+    @WritesAttribute(attribute = BoxFileInfo.PATH, description = "The path of 
the file on Box"),
+    @WritesAttribute(attribute = BoxFileInfo.SIZE, description = "The size of 
the file (in bytes)"),
+    @WritesAttribute(attribute = BoxFileInfo.TIMESTAMP, description = "The 
last modified time of the file.")})
+@Stateful(scopes = {Scope.CLUSTER}, description = "The processor stores 
necessary data to be able to keep track what files have been listed already." +
+    " What exactly needs to be stored depends on the 'Listing Strategy'.")
+public class ListBoxFiles extends AbstractListProcessor<BoxFileInfo> {
+    public static final PropertyDescriptor FOLDER_ID = new 
PropertyDescriptor.Builder()
+        .name("box-folder-id")
+        .displayName("Folder ID")
+        .description("The ID of the folder from which to pull list of files.")
+        .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+        .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+        .required(true)
+        .build();
+
+    public static final PropertyDescriptor RECURSIVE_SEARCH = new 
PropertyDescriptor.Builder()
+        .name("recursive-search")
+        .displayName("Search Recursively")
+        .description("When 'true', will include list of files from 
sub-folders." +
+            " Otherwise, will return only files that are within the folder 
defined by the 'Folder ID' property.")
+        .required(true)
+        .defaultValue("true")
+        .allowableValues("true", "false")
+        .build();
+
+    public static final PropertyDescriptor MIN_AGE = new 
PropertyDescriptor.Builder()
+        .name("min-age")
+        .displayName("Minimum File Age")
+        .description("The minimum age a file must be in order to be 
considered; any files younger than this will be ignored.")
+        .required(true)
+        .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+        .defaultValue("0 sec")
+        .build();
+
+    public static final PropertyDescriptor LISTING_STRATEGY = new 
PropertyDescriptor.Builder()
+        .fromPropertyDescriptor(AbstractListProcessor.LISTING_STRATEGY)
+        .allowableValues(BY_TIMESTAMPS, BY_ENTITIES, BY_TIME_WINDOW, 
NO_TRACKING)
+        .build();
+
+    public static final PropertyDescriptor TRACKING_STATE_CACHE = new 
PropertyDescriptor.Builder()
+        .fromPropertyDescriptor(ListedEntityTracker.TRACKING_STATE_CACHE)
+        .dependsOn(LISTING_STRATEGY, BY_ENTITIES)
+        .build();
+
+    public static final PropertyDescriptor TRACKING_TIME_WINDOW = new 
PropertyDescriptor.Builder()
+        .fromPropertyDescriptor(ListedEntityTracker.TRACKING_TIME_WINDOW)
+        .dependsOn(LISTING_STRATEGY, BY_ENTITIES)
+        .build();
+
+    public static final PropertyDescriptor INITIAL_LISTING_TARGET = new 
PropertyDescriptor.Builder()
+        .fromPropertyDescriptor(ListedEntityTracker.INITIAL_LISTING_TARGET)
+        .dependsOn(LISTING_STRATEGY, BY_ENTITIES)
+        .build();
+
+    private static final List<PropertyDescriptor> PROPERTIES = 
Collections.unmodifiableList(Arrays.asList(
+        FOLDER_ID,
+        BoxClientService.BOX_CLIENT_SERVICE,
+        RECURSIVE_SEARCH,
+        MIN_AGE,
+        LISTING_STRATEGY,
+        TRACKING_STATE_CACHE,
+        TRACKING_TIME_WINDOW,
+        INITIAL_LISTING_TARGET,
+        RECORD_WRITER
+    ));
+
+    private volatile BoxAPIConnection boxAPIConnection;
+
+    @Override
+    protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+        return PROPERTIES;
+    }
+
+    @Override
+    protected Map<String, String> createAttributes(
+        final BoxFileInfo entity,
+        final ProcessContext context
+    ) {
+        final Map<String, String> attributes = new HashMap<>();
+
+        for (BoxFlowFileAttribute attribute : BoxFlowFileAttribute.values()) {
+            Optional.ofNullable(attribute.getValue(entity))
+                .ifPresent(value -> attributes.put(attribute.getName(), 
value));
+        }
+
+        return attributes;
+    }
+
+    @OnScheduled
+    public void onScheduled(final ProcessContext context) throws IOException {
+        BoxClientService boxClientService = 
context.getProperty(BoxClientService.BOX_CLIENT_SERVICE).asControllerService(BoxClientService.class);
+
+        boxAPIConnection = boxClientService.getBoxApiConnection();
+    }
+
+    @Override
+    protected String getListingContainerName(final ProcessContext context) {
+        return String.format("Box Folder [%s]", getPath(context));
+    }
+
+    @Override
+    protected String getPath(final ProcessContext context) {
+        return 
context.getProperty(FOLDER_ID).evaluateAttributeExpressions().getValue();
+    }
+
+    @Override
+    protected boolean isListingResetNecessary(final PropertyDescriptor 
property) {
+        return LISTING_STRATEGY.equals(property)
+            || FOLDER_ID.equals(property)
+            || RECURSIVE_SEARCH.equals(property);
+    }
+
+    @Override
+    protected Scope getStateScope(final PropertyContext context) {
+        return Scope.CLUSTER;
+    }
+
+    @Override
+    protected RecordSchema getRecordSchema() {
+        return BoxFileInfo.getRecordSchema();
+    }
+
+    @Override
+    protected String getDefaultTimePrecision() {
+        return PRECISION_SECONDS.getValue();
+    }
+
+    @Override
+    protected List<BoxFileInfo> performListing(
+        final ProcessContext context,
+        final Long minTimestamp,
+        final ListingMode listingMode
+    ) throws IOException {
+        final List<BoxFileInfo> listing = new ArrayList<>();
+
+        final String folderId = 
context.getProperty(FOLDER_ID).evaluateAttributeExpressions().getValue();
+        final Boolean recursive = 
context.getProperty(RECURSIVE_SEARCH).asBoolean();
+        final Long minAge = 
context.getProperty(MIN_AGE).asTimePeriod(TimeUnit.MILLISECONDS);
+
+
+        listFolder(listing, folderId, recursive, minAge);
+
+        return listing;
+    }
+
+    private void listFolder(List<BoxFileInfo> listing, String folderId, 
Boolean recursive, Long minAge) {
+        BoxFolder folder = getFolder(folderId);
+        for (BoxItem.Info itemInfo : folder.getChildren(
+            "id",
+            "name",
+            "item_status",
+            "size",
+            "created_at",
+            "modified_at",
+            "content_created_at",
+            "content_modified_at",
+            "path_collection"
+        )) {
+            if (itemInfo instanceof BoxFile.Info) {
+                BoxFile.Info info = (BoxFile.Info) itemInfo;
+
+                long createdAt = itemInfo.getCreatedAt().getTime();
+
+                if (Instant.now().toEpochMilli() - createdAt >= minAge) {
+                    BoxFileInfo boxFileInfo = new BoxFileInfo.Builder()
+                        .id(info.getID())
+                        .fileName(info.getName())
+                        .path("/" + info.getPathCollection().stream()
+                            .filter(pathItemInfo -> 
!pathItemInfo.getID().equals("0"))
+                            .map(BoxItem.Info::getName)
+                            .collect(Collectors.joining("/")))
+                        .size(info.getSize())
+                        .createdTime(info.getCreatedAt().getTime())
+                        .modifiedTime(info.getModifiedAt().getTime())
+                        .build();
+
+                    listing.add(boxFileInfo);
+                }
+            } else if (recursive && itemInfo instanceof BoxFolder.Info) {
+                BoxFolder.Info info = (BoxFolder.Info) itemInfo;
+                listFolder(listing, info.getID(), recursive, minAge);
+            }
+        }
+    }

Review Comment:
   `Instant.now()` should be calculated once and before all network 
communications. Otherwise newer and newer files can be listed breaking the 
purpose of `minAge`.
   As the method is recursive, the value should come from outside as a 
parameter. I'd suggest passing in `createdAtMax` instead of `minAge` which can 
be calculated as `Instant.now() - minAge`.
   ```suggestion
           long createdAtMax = Instant.now().toEpochMilli() - minAge;
           listFolder(listing, folderId, recursive, createdAtMax);
   
           return listing;
       }
   
       private void listFolder(List<BoxFileInfo> listing, String folderId, 
Boolean recursive, long createdAtMax) {
           BoxFolder folder = getFolder(folderId);
           for (BoxItem.Info itemInfo : folder.getChildren(
               "id",
               "name",
               "item_status",
               "size",
               "created_at",
               "modified_at",
               "content_created_at",
               "content_modified_at",
               "path_collection"
           )) {
               if (itemInfo instanceof BoxFile.Info) {
                   BoxFile.Info info = (BoxFile.Info) itemInfo;
   
                   long createdAt = itemInfo.getCreatedAt().getTime();
   
                   if (createdAt <= createdAtMax) {
                       BoxFileInfo boxFileInfo = new BoxFileInfo.Builder()
                           .id(info.getID())
                           .fileName(info.getName())
                           .path("/" + info.getPathCollection().stream()
                               .filter(pathItemInfo -> 
!pathItemInfo.getID().equals("0"))
                               .map(BoxItem.Info::getName)
                               .collect(Collectors.joining("/")))
                           .size(info.getSize())
                           .createdTime(info.getCreatedAt().getTime())
                           .modifiedTime(info.getModifiedAt().getTime())
                           .build();
   
                       listing.add(boxFileInfo);
                   }
               } else if (recursive && itemInfo instanceof BoxFolder.Info) {
                   BoxFolder.Info info = (BoxFolder.Info) itemInfo;
                   listFolder(listing, info.getID(), recursive, createdAtMax);
               }
           }
       }
   ```



##########
nifi-nar-bundles/nifi-box-bundle/nifi-box-processors/src/main/java/org/apache/nifi/processors/box/FetchBoxFiles.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.box;
+
+import com.box.sdk.BoxAPIConnection;
+import com.box.sdk.BoxAPIResponseException;
+import com.box.sdk.BoxFile;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.box.controllerservices.BoxClientService;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"box", "storage", "fetch"})
+@CapabilityDescription("Fetches files from a Box Folder. Designed to be used 
in tandem with ListBoxFiles.")
+@SeeAlso({ListBoxFiles.class})
+@WritesAttributes({
+    @WritesAttribute(attribute = FetchBoxFiles.ERROR_CODE_ATTRIBUTE, 
description = "The error code returned by Box when the fetch of a file fails"),
+    @WritesAttribute(attribute = FetchBoxFiles.ERROR_MESSAGE_ATTRIBUTE, 
description = "The error message returned by Box when the fetch of a file 
fails")
+})
+public class FetchBoxFiles extends AbstractProcessor {
+    public static final String ERROR_CODE_ATTRIBUTE = "error.code";
+    public static final String ERROR_MESSAGE_ATTRIBUTE = "error.message";
+
+    public static final PropertyDescriptor FILE_ID = new PropertyDescriptor
+        .Builder().name("box-file-id")
+        .displayName("File ID")
+        .description("The ID of the File to fetch")
+        .required(true)
+        .defaultValue("${box.id}")
+        
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+        .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+        .build();
+
+    public static final Relationship REL_SUCCESS =
+        new Relationship.Builder()
+            .name("success")
+            .description("A FlowFile will be routed here for each successfully 
fetched File.")
+            .build();
+
+    public static final Relationship REL_FAILURE =
+        new Relationship.Builder().name("failure")
+            .description("A FlowFile will be routed here for each File for 
which fetch was attempted but failed.")
+            .build();
+
+    private static final List<PropertyDescriptor> PROPERTIES = 
Collections.unmodifiableList(Arrays.asList(
+        FILE_ID,
+        BoxClientService.BOX_CLIENT_SERVICE

Review Comment:
   Please move the Box Client Service to the first position (similar to 
GoogleDrive and Dropbox processors).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to