mirror of
https://github.com/apache/nifi.git
synced 2025-02-09 03:25:04 +00:00
NIFI-9899 Corrected MongoDBLookupService attribute handling
- Corrected collection and database name properties to handle FlowFile attributes This closes #5966 Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
parent
84340962d4
commit
ce95097aee
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user