Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 4AE97200D0E for ; Mon, 11 Sep 2017 16:17:08 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 49D871609C3; Mon, 11 Sep 2017 14:17:08 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 3FBE51609C4 for ; Mon, 11 Sep 2017 16:17:07 +0200 (CEST) Received: (qmail 1744 invoked by uid 500); 11 Sep 2017 14:17:05 -0000 Mailing-List: contact issues-help@nifi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@nifi.apache.org Delivered-To: mailing list issues@nifi.apache.org Received: (qmail 1733 invoked by uid 99); 11 Sep 2017 14:17:05 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Sep 2017 14:17:05 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id E7B86C170A for ; Mon, 11 Sep 2017 14:17:04 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -100.002 X-Spam-Level: X-Spam-Status: No, score=-100.002 tagged_above=-999 required=6.31 tests=[RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id ZJk5rjWriP-y for ; Mon, 11 Sep 2017 14:17:03 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id C7BCF6102F for ; Mon, 11 Sep 2017 14:17:02 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 61DF9E0EDB for ; Mon, 11 Sep 2017 14:17:01 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 91FFE24157 for ; Mon, 11 Sep 2017 14:17:00 +0000 (UTC) Date: Mon, 11 Sep 2017 14:17:00 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@nifi.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (NIFI-4345) Add a controller service and a lookup service for MongoDB MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Mon, 11 Sep 2017 14:17:08 -0000 [ https://issues.apache.org/jira/browse/NIFI-4345?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16161323#comment-16161323 ] ASF GitHub Bot commented on NIFI-4345: -------------------------------------- Github user markap14 commented on a diff in the pull request: https://github.com/apache/nifi/pull/2123#discussion_r138080737 --- Diff: nifi-nar-bundles/nifi-standard-services/nifi-mongodb-services-bundle/nifi-mongodb-services/src/main/java/org/apache/nifi/mongodb/MongoDBLookupService.java --- @@ -0,0 +1,116 @@ +/* + * 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.mongodb; + +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.annotation.lifecycle.OnEnabled; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.controller.ConfigurationContext; +import org.apache.nifi.controller.ControllerServiceInitializationContext; +import org.apache.nifi.lookup.LookupFailureException; +import org.apache.nifi.lookup.LookupService; +import org.apache.nifi.processor.util.StandardValidators; +import org.apache.nifi.reporting.InitializationException; +import org.bson.Document; +import org.codehaus.jackson.map.ObjectMapper; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; + + +@Tags({"mongo", "mongodb", "lookup", "record"}) +@CapabilityDescription( + "Provides lookup service functionality through a configured connection to MongoDB. " + + "One or more keys must defined in LookupRecord in order for it to run. Each value " + + "must correspond to a full field value in the Mongo collection, as this does not support " + + "regular expressions and other features." +) +public class MongoDBLookupService extends MongoDBControllerService implements LookupService { + + public static final PropertyDescriptor LOOKUP_KEY = new PropertyDescriptor.Builder() + .name("mongo-lookup-key") + .displayName("The key from the result to return") + .addValidator(StandardValidators.NON_BLANK_VALIDATOR) + .required(true) + .defaultValue("somevalue") + .build(); + + private ObjectMapper mapper; + private String lookupKey; + + private static final List lookupDescriptors; + + static { + lookupDescriptors = new ArrayList<>(); + lookupDescriptors.addAll(descriptors); + lookupDescriptors.add(LOOKUP_KEY); + } + + @Override + public Optional lookup(Map coordinates) throws LookupFailureException { + Document query = new Document(coordinates); + + if (coordinates.size() == 0) { + throw new LookupFailureException("No keys were configured. Mongo query would return random documents."); + } + + try { + Document result = this.findOne(query); + + Object val = result.get(lookupKey); + + return Optional.ofNullable(val); + } catch (Exception ex) { + getLogger().error("Error during lookup {}", new Object[]{ query.toJson() }, ex); + throw new LookupFailureException(ex); + } + } + + @OnEnabled + public void onEnabled(final ConfigurationContext context) throws InitializationException, IOException, InterruptedException { + this.lookupKey = context.getProperty(LOOKUP_KEY).getValue(); + super.onEnabled(context); + } + + @Override + public Class getValueType() { + return null; --- End diff -- This should return Record.class > Add a controller service and a lookup service for MongoDB > --------------------------------------------------------- > > Key: NIFI-4345 > URL: https://issues.apache.org/jira/browse/NIFI-4345 > Project: Apache NiFi > Issue Type: Improvement > Reporter: Mike Thomsen > > - Create a Controller Service that wraps the functionality of the Mongo driver. > - Create a lookup service that can return elements based on a query. -- This message was sent by Atlassian JIRA (v6.4.14#64029)