From ea41b41ede3cc9832cf0b95c3f51ca29fda67fc3 Mon Sep 17 00:00:00 2001 From: Mike Thomsen Date: Thu, 3 May 2018 06:28:45 -0400 Subject: [PATCH] NIFI-5145 Made MockPropertyValue.evaluateExpressionLanguage(FlowFile able to accommodate null flowfiles the way live NiFi does. NIFI-5145 Fixed a mistake with evaluateAttributeExpressions found in a code review. NIFI-5145 Removed a property descriptor from GetHBase that was a duplication of the one in VisibilityFetchSupport. NIFI-5145 Added comments in the code that were requested in the review. NIFI-5145 Fixed check style issue. NIFI-5145 Fixed a few improperly scoped items in ListFileTransfer that impacted the FTP processor(s). NIFI-5145 Changed which override gets called based on code review feedback. NIFI-5145: Reverted changes to ListFileTransfer re ExpressionLanguageScope NIFI-5145: Removed TODO from MockPropertyValue javadoc Signed-off-by: Matthew Burgess This closes #2672 --- .../java/org/apache/nifi/util/MockPropertyValue.java | 9 +++++++++ .../src/main/java/org/apache/nifi/hbase/GetHBase.java | 9 --------- .../nifi/processors/mongodb/AbstractMongoProcessor.java | 3 +-- .../org/apache/nifi/processors/mongodb/GetMongo.java | 5 +++-- .../org/apache/nifi/processors/mongodb/PutMongo.java | 5 +++-- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/nifi-mock/src/main/java/org/apache/nifi/util/MockPropertyValue.java b/nifi-mock/src/main/java/org/apache/nifi/util/MockPropertyValue.java index 9b825d9063..cdabc6bf5c 100644 --- a/nifi-mock/src/main/java/org/apache/nifi/util/MockPropertyValue.java +++ b/nifi-mock/src/main/java/org/apache/nifi/util/MockPropertyValue.java @@ -202,6 +202,15 @@ public class MockPropertyValue implements PropertyValue { @Override public PropertyValue evaluateAttributeExpressions(final FlowFile flowFile) throws ProcessException { + /* + * The reason for this null check is that somewhere in the test API, it automatically assumes that a null FlowFile + * should be treated as though it were evaluated with the VARIABLE_REGISTRY scope instead of the flowfile scope. When NiFi + * is running, it doesn't care when it's evaluating EL against a null flowfile. However, the testing framework currently + * raises an error which makes it not mimick real world behavior. + */ + if (flowFile == null) { + return evaluateAttributeExpressions(); + } return evaluateAttributeExpressions(flowFile, null, null); } diff --git a/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/src/main/java/org/apache/nifi/hbase/GetHBase.java b/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/src/main/java/org/apache/nifi/hbase/GetHBase.java index 582814ea7a..59f325db3d 100644 --- a/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/src/main/java/org/apache/nifi/hbase/GetHBase.java +++ b/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/src/main/java/org/apache/nifi/hbase/GetHBase.java @@ -54,7 +54,6 @@ import org.apache.nifi.components.AllowableValue; import org.apache.nifi.components.PropertyDescriptor; import org.apache.nifi.components.ValidationContext; import org.apache.nifi.components.ValidationResult; -import org.apache.nifi.components.Validator; import org.apache.nifi.components.state.Scope; import org.apache.nifi.components.state.StateManager; import org.apache.nifi.components.state.StateMap; @@ -147,14 +146,6 @@ public class GetHBase extends AbstractProcessor implements VisibilityFetchSuppor .allowableValues(NONE, CURRENT_TIME) .defaultValue(NONE.getValue()) .build(); - static final PropertyDescriptor AUTHORIZATIONS = new PropertyDescriptor.Builder() - .name("hbase-fetch-row-authorizations") - .displayName("Authorizations") - .description("The list of authorizations to pass to the scanner. This will be ignored if cell visibility labels are not in use.") - .required(false) - .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY) - .addValidator(Validator.VALID) - .build(); static final Relationship REL_SUCCESS = new Relationship.Builder() .name("success") diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/AbstractMongoProcessor.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/AbstractMongoProcessor.java index 5bef4a8334..339bee70e5 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/AbstractMongoProcessor.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/AbstractMongoProcessor.java @@ -267,8 +267,7 @@ public abstract class AbstractMongoProcessor extends AbstractProcessor { protected void writeBatch(String payload, FlowFile parent, ProcessContext context, ProcessSession session, Map extraAttributes, Relationship rel) throws UnsupportedEncodingException { - String charset = parent != null ? context.getProperty(CHARSET).evaluateAttributeExpressions(parent).getValue() - : context.getProperty(CHARSET).evaluateAttributeExpressions().getValue(); + String charset = context.getProperty(CHARSET).evaluateAttributeExpressions(parent).getValue(); FlowFile flowFile = parent != null ? session.create(parent) : session.create(); flowFile = session.importFrom(new ByteArrayInputStream(payload.getBytes(charset)), flowFile); diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/GetMongo.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/GetMongo.java index fbd50b6918..d7a4d0bf43 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/GetMongo.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/GetMongo.java @@ -96,7 +96,7 @@ public class GetMongo extends AbstractMongoProcessor { "the flowfile's body. If this field is left blank and a timer is enabled instead of an incoming connection, " + "that will result in a full collection fetch using a \"{}\" query.") .required(false) - .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY) + .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES) .addValidator(DOCUMENT_VALIDATOR) .build(); @@ -346,6 +346,7 @@ public class GetMongo extends AbstractMongoProcessor { } } else { while (cursor.hasNext()) { + final FlowFile ffPtr = input; flowFile = session.create(); flowFile = session.write(flowFile, out -> { String json; @@ -354,7 +355,7 @@ public class GetMongo extends AbstractMongoProcessor { } else { json = cursor.next().toJson(); } - out.write(json.getBytes(context.getProperty(CHARSET).evaluateAttributeExpressions().getValue())); + out.write(json.getBytes(context.getProperty(CHARSET).evaluateAttributeExpressions(ffPtr).getValue())); }); flowFile = session.putAllAttributes(flowFile, attributes); diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java index e52fd36ec3..f9a0b2b0de 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java @@ -32,6 +32,7 @@ import org.apache.nifi.components.AllowableValue; import org.apache.nifi.components.PropertyDescriptor; import org.apache.nifi.components.ValidationContext; import org.apache.nifi.components.ValidationResult; +import org.apache.nifi.expression.ExpressionLanguageScope; import org.apache.nifi.flowfile.FlowFile; import org.apache.nifi.logging.ComponentLog; import org.apache.nifi.processor.ProcessContext; @@ -92,7 +93,7 @@ public class PutMongo extends AbstractMongoProcessor { + "otherwise it is ignored. Example: _id") .required(false) .addValidator(StandardValidators.NON_BLANK_VALIDATOR) - .expressionLanguageSupported(true) + .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES) .build(); static final PropertyDescriptor UPDATE_QUERY = new PropertyDescriptor.Builder() .name("putmongo-update-query") @@ -100,7 +101,7 @@ public class PutMongo extends AbstractMongoProcessor { .description("Specify a full MongoDB query to be used for the lookup query to do an update/upsert.") .required(false) .addValidator(StandardValidators.NON_BLANK_VALIDATOR) - .expressionLanguageSupported(true) + .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES) .build(); static final PropertyDescriptor UPDATE_MODE = new PropertyDescriptor.Builder()