This is an automated email from the ASF dual-hosted git repository. joewitt pushed a commit to branch support/nifi-1.16 in repository https://gitbox.apache.org/repos/asf/nifi.git
commit d6176fea41c3b703443c5d77ca19b20aac7ef04a Author: ravinarayansingh <[email protected]> AuthorDate: Thu Apr 14 10:05:48 2022 -0500 NIFI-9899 Corrected MongoDBLookupService attribute handling - Corrected collection and database name properties to handle FlowFile attributes This closes #5966 Signed-off-by: David Handermann <[email protected]> --- .../java/org/apache/nifi/mongodb/MongoDBLookupService.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/main/java/org/apache/nifi/mongodb/MongoDBLookupService.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/main/java/org/apache/nifi/mongodb/MongoDBLookupService.java index d97c5decf8..ecf1db1659 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/main/java/org/apache/nifi/mongodb/MongoDBLookupService.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/main/java/org/apache/nifi/mongodb/MongoDBLookupService.java @@ -70,8 +70,6 @@ public class MongoDBLookupService extends JsonInferenceSchemaRegistryService imp .fromPropertyDescriptor(SCHEMA_NAME) .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY) .build(); - private volatile String databaseName; - private volatile String collection; public static final PropertyDescriptor CONTROLLER_SERVICE = new PropertyDescriptor.Builder() .name("mongo-lookup-client-service") @@ -138,7 +136,7 @@ public class MongoDBLookupService extends JsonInferenceSchemaRegistryService imp } try { - Document result = findOne(query, projection); + Document result = findOne(query, projection,context); if(result == null) { return Optional.empty(); @@ -173,17 +171,12 @@ public class MongoDBLookupService extends JsonInferenceSchemaRegistryService imp this.controllerService = context.getProperty(CONTROLLER_SERVICE).asControllerService(MongoDBClientService.class); this.schemaNameProperty = context.getProperty(LOCAL_SCHEMA_NAME).evaluateAttributeExpressions().getValue(); - - this.databaseName = context.getProperty(DATABASE_NAME).evaluateAttributeExpressions().getValue(); - this.collection = context.getProperty(COLLECTION_NAME).evaluateAttributeExpressions().getValue(); - String configuredProjection = context.getProperty(PROJECTION).isSet() ? context.getProperty(PROJECTION).getValue() : null; if (!StringUtils.isBlank(configuredProjection)) { projection = Document.parse(configuredProjection); } - super.onEnabled(context); } @@ -223,7 +216,9 @@ public class MongoDBLookupService extends JsonInferenceSchemaRegistryService imp return Collections.unmodifiableList(_temp); } - private Document findOne(Document query, Document projection) { + private Document findOne(Document query, Document projection,Map<String, String> context) { + final String databaseName = getProperty(DATABASE_NAME).evaluateAttributeExpressions(context).getValue(); + final String collection = getProperty(COLLECTION_NAME).evaluateAttributeExpressions(context).getValue(); MongoCollection col = controllerService.getDatabase(databaseName).getCollection(collection); MongoCursor<Document> it = (projection != null ? col.find(query).projection(projection) : col.find(query)).iterator(); Document retVal = it.hasNext() ? it.next() : null;
