exceptionfactory commented on code in PR #6899:
URL: https://github.com/apache/nifi/pull/6899#discussion_r1093752013
##########
nifi-nar-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/vision/AbstractStartGcpVisionOperation.java:
##########
@@ -70,7 +92,15 @@ public void onStopped() throws IOException {
}
private InputStream getInputStreamFromProperty(ProcessContext context,
FlowFile flowFile) {
- return new
ByteArrayInputStream(context.getProperty(getJsonPayloadPropertyDescriptor()).evaluateAttributeExpressions(flowFile).getValue().getBytes(StandardCharsets.UTF_8));
+ Map<String, String> attributes = new HashMap<>();
+ attributes.put(OUTPUT_BUCKET.getName(), getAttributeValue(context,
flowFile, OUTPUT_BUCKET.getName()));
+ attributes.put(FEATURE_TYPE.getName(), getAttributeValue(context,
flowFile, FEATURE_TYPE.getName()));
+ return new
ByteArrayInputStream(context.getProperty(getJsonPayloadPropertyDescriptor())
+ .evaluateAttributeExpressions(flowFile,
attributes).getValue().getBytes(StandardCharsets.UTF_8));
+ }
+
+ private String getAttributeValue(ProcessContext context, FlowFile
flowFile, String name) {
+ return flowFile.getAttribute(name) != null ?
flowFile.getAttribute(name) :
context.getProperty(name).evaluateAttributeExpressions().getValue();
Review Comment:
It would be helpful to split this into multiple lines for improved
readability, and adjust the logical operator. The
`evaluateAttributeExpressions()` invocation does not add much value in this
case, so it seems unnecessary.
```suggestion
final String flowFileAttribute = flowFile.getAttribute(name);
final PropertyValue propertyValue = context.getProperty(name);
return flowFileAttribute == null ? propertyValue.getValue() :
flowFileAttribute;
```
##########
nifi-nar-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/vision/AbstractStartGcpVisionOperation.java:
##########
@@ -24,14 +24,36 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.nifi.annotation.lifecycle.OnStopped;
import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
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 org.apache.nifi.processor.util.StandardValidators;
public abstract class AbstractStartGcpVisionOperation<B extends
com.google.protobuf.GeneratedMessageV3.Builder<B>> extends
AbstractGcpVisionProcessor {
+ public static final PropertyDescriptor FEATURE_TYPE = new
PropertyDescriptor.Builder()
+ .name("feature-type")
+ .displayName("Vision Feature Type")
+ .description("Type of GCP Vision Feature")
+
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .defaultValue("TEXT_DETECTION")
+ .build();
+ public static final PropertyDescriptor OUTPUT_BUCKET = new
PropertyDescriptor.Builder()
+ .name("output-bucket")
+ .displayName("Output Bucket")
+ .description("Name of the GCS bucket where the output of the
Vision job will be persisted.")
Review Comment:
As with the Vision Feature Type property, recommend describing when this
property applies.
```suggestion
.description("Name of the GCS bucket where the output of the
Vision job will be persisted. The value of this property applies when the JSON
Payload property is configured. The JSON Payload property value can use
Expression Language to reference the value of ${output-bucket}")
```
##########
nifi-nar-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/vision/AbstractStartGcpVisionOperation.java:
##########
@@ -24,14 +24,36 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.nifi.annotation.lifecycle.OnStopped;
import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
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 org.apache.nifi.processor.util.StandardValidators;
public abstract class AbstractStartGcpVisionOperation<B extends
com.google.protobuf.GeneratedMessageV3.Builder<B>> extends
AbstractGcpVisionProcessor {
+ public static final PropertyDescriptor FEATURE_TYPE = new
PropertyDescriptor.Builder()
+ .name("feature-type")
+ .displayName("Vision Feature Type")
+ .description("Type of GCP Vision Feature")
Review Comment:
The description should be updated to indicate that this is only used in
evaluation of the JSON Payload.
```suggestion
.description("Type of GCP Vision Feature. The value of this
property applies when the JSON Payload property is configured. The JSON Payload
property value can use Expression Language to reference the value of
${vision-feature-type}")
```
##########
nifi-nar-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/vision/AbstractStartGcpVisionOperation.java:
##########
@@ -70,7 +92,15 @@ public void onStopped() throws IOException {
}
private InputStream getInputStreamFromProperty(ProcessContext context,
FlowFile flowFile) {
- return new
ByteArrayInputStream(context.getProperty(getJsonPayloadPropertyDescriptor()).evaluateAttributeExpressions(flowFile).getValue().getBytes(StandardCharsets.UTF_8));
+ Map<String, String> attributes = new HashMap<>();
+ attributes.put(OUTPUT_BUCKET.getName(), getAttributeValue(context,
flowFile, OUTPUT_BUCKET.getName()));
+ attributes.put(FEATURE_TYPE.getName(), getAttributeValue(context,
flowFile, FEATURE_TYPE.getName()));
+ return new
ByteArrayInputStream(context.getProperty(getJsonPayloadPropertyDescriptor())
+ .evaluateAttributeExpressions(flowFile,
attributes).getValue().getBytes(StandardCharsets.UTF_8));
Review Comment:
Splitting this declaration into multiple lines would make it easier to
follow.
```suggestion
final PropertyValue jsonPropertyValue =
context.getProperty(getJsonPayloadPropertyDescriptor());
final String jsonPayload =
jsonPropertyValue.evaluateAttributeExpressions(flowFile, attributes).getValue();
return new
ByteArrayInputStream(jsonPayload.getBytes(StandardCharsets.UTF_8));
```
##########
nifi-nar-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/vision/AbstractStartGcpVisionOperation.java:
##########
@@ -24,14 +24,36 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.nifi.annotation.lifecycle.OnStopped;
import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
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 org.apache.nifi.processor.util.StandardValidators;
public abstract class AbstractStartGcpVisionOperation<B extends
com.google.protobuf.GeneratedMessageV3.Builder<B>> extends
AbstractGcpVisionProcessor {
+ public static final PropertyDescriptor FEATURE_TYPE = new
PropertyDescriptor.Builder()
+ .name("feature-type")
Review Comment:
Recommend aligning the name and display name:
```suggestion
.name("vision-feature-type")
```
--
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]