exceptionfactory commented on code in PR #7458:
URL: https://github.com/apache/nifi/pull/7458#discussion_r1254447282


##########
nifi-nar-bundles/nifi-extension-utils/nifi-data-upload/src/main/java/org/apache/nifi/processors/dataupload/DataUploadProperties.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.dataupload;
+
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.fileresource.service.api.FileResourceService;
+
+import static 
org.apache.nifi.processors.dataupload.DataUploadSource.FLOWFILE_CONTENT;
+
+public class DataUploadProperties {
+
+    public static final PropertyDescriptor DATA_TO_UPLOAD = new 
PropertyDescriptor.Builder()
+            .name("data-to-upload")
+            .displayName("Data to Upload")

Review Comment:
   This property name seems a bit too generic to be clear. Aligning with the 
name of the allowable values enumeration, it seems like `Data Upload Source` or 
just `Data Source` would be clearer.



##########
nifi-nar-bundles/nifi-extension-utils/nifi-data-upload/pom.xml:
##########
@@ -0,0 +1,44 @@
+<?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 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.nifi</groupId>
+        <artifactId>nifi-extension-utils</artifactId>
+        <version>2.0.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>nifi-data-upload</artifactId>

Review Comment:
   Thinking about the name of this module and related elements, this seems like 
it should be named for more for the source than the intended destination. What 
do you think about `nifi-data-input` or `nifi-data-transfer`. Both of those 
also seem a bit generic, perhaps `nifi-resource-transfer` and then naming the 
`enum` as `ResourceTransferSource`?



##########
nifi-nar-bundles/nifi-standard-services/nifi-file-resource-service-bundle/nifi-file-resource-service/src/main/java/org/apache/nifi/fileresource/service/StandardFileResourceService.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.fileresource.service;
+
+import org.apache.nifi.annotation.behavior.Restricted;
+import org.apache.nifi.annotation.behavior.Restriction;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnDisabled;
+import org.apache.nifi.annotation.lifecycle.OnEnabled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.RequiredPermission;
+import org.apache.nifi.components.resource.ResourceCardinality;
+import org.apache.nifi.components.resource.ResourceReference;
+import org.apache.nifi.components.resource.ResourceType;
+import org.apache.nifi.context.PropertyContext;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.fileresource.service.api.FileResource;
+import org.apache.nifi.fileresource.service.api.FileResourceService;
+import org.apache.nifi.controller.AbstractControllerService;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+@Tags({"file", "resource"})
+@CapabilityDescription("Provides a file resource for other components. The 
file needs to be available locally by Nifi (e.g. local disk or mounted 
storage). " +
+        "NiFi needs to have read permission to the file.")
+@Restricted(
+        restrictions = {
+                @Restriction(
+                        requiredPermission = 
RequiredPermission.READ_FILESYSTEM,
+                        explanation = "Provides operator the ability to read 
from any file that NiFi has access to.")
+        }
+)
+public class StandardFileResourceService extends AbstractControllerService 
implements FileResourceService {
+
+    public static final PropertyDescriptor FILE_PATH = new 
PropertyDescriptor.Builder()
+            .name("file-path")
+            .displayName("File Path")

Review Comment:
   Although this property value can be resolved from attributes, it otherwise 
seems limiting and potentially confusing to have a service that only returns a 
single FileResource. One option could be to make this property something like 
`Base Directory` and then change the signature of the `FileResourceService` to 
take a `URI` or `Path`. In other words, making the Service contract explicitly 
support return different files depending on input parameters, as opposed 
scoping to the bounds of the an attributes Map, which could be empty.



##########
nifi-nar-bundles/nifi-extension-utils/nifi-data-upload/src/main/java/org/apache/nifi/processors/dataupload/DataUploadUtil.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.dataupload;
+
+import org.apache.nifi.components.PropertyValue;
+import org.apache.nifi.fileresource.service.api.FileResource;
+import org.apache.nifi.fileresource.service.api.FileResourceService;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.exception.ProcessException;
+
+import java.io.InputStream;
+
+import static 
org.apache.nifi.processors.dataupload.DataUploadProperties.FILE_RESOURCE_SERVICE;
+
+public final class DataUploadUtil {
+
+    private DataUploadUtil() {}
+
+    /**
+     * If DataUploadSource is LOCAL_FILE, looks up FILE_RESOURCE_SERVICE 
property from the process context, retrieves FileResource from the service and 
returns it.
+     * If DataUploadSource is not LOCAL_FILE, it returns null.
+     *
+     * @param dataUploadSource type of the data upload
+     * @param context process context with properties
+     * @param flowFile FlowFile with attributes to use in expression language
+     * @return FileResource retrieved from FileResourceService if 
DataUploadSource is LOCAL_FILE, otherwise null
+     * @throws ProcessException if DataUploadSource is LOCAL_FILE but 
FileResourceService is not provided in the context
+     */
+    public static FileResource getFileResource(final DataUploadSource 
dataUploadSource, final ProcessContext context, final FlowFile flowFile) {
+        if (dataUploadSource == DataUploadSource.LOCAL_FILE) {
+            final PropertyValue property = 
context.getProperty(FILE_RESOURCE_SERVICE);
+            if (property == null || !property.isSet()) {
+                throw new ProcessException("DataUploadSource is LOCAL_FILE but 
no FileResourceService found");
+            }
+            final FileResourceService fileResourceService = 
property.asControllerService(FileResourceService.class);
+            return 
fileResourceService.getFileResource(flowFile.getAttributes());
+        }
+        return null;
+    }
+
+    /**
+     * Returns the input stream of the FileResource if it is provided (not 
null). Otherwise, returns the input stream of the FlowFile.
+     *
+     * @param session the session to read the FlowFile
+     * @param flowFile the FlowFile which is read when no FileResource is 
provided
+     * @param fileResource the FileResource
+     * @return input stream of the FileResource or the FlowFile
+     */
+    public static InputStream getUploadInputStream(final ProcessSession 
session, final FlowFile flowFile, final FileResource fileResource) {
+        return fileResource == null ? session.read(flowFile) : 
fileResource.getInputStream();
+    }
+
+    /**
+     * Returns the size of the FileResource if it is provided (not null). 
Otherwise, returns the size of the FlowFile.
+     *
+     * @param flowFile the FlowFile which is used when no FileResource is 
provided
+     * @param fileResource the FileResource
+     * @return size of the FileResource or the FlowFile
+     */
+    public static long getUploadSize(final FlowFile flowFile, final 
FileResource fileResource) {

Review Comment:
   As mentioned elsewhere, this has more to do with the source. Recommend 
naming this method something like `getResourceSize()` or `getTransferSize()`.



-- 
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