Github user jvwing commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2012#discussion_r127880492
  
    --- Diff: 
nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/main/java/org/apache/nifi/processors/rethinkdb/GetRethinkDB.java
 ---
    @@ -0,0 +1,197 @@
    +/*
    + * 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.processors.rethinkdb;
    +
    +import org.apache.commons.lang3.StringUtils;
    +import org.apache.nifi.annotation.behavior.EventDriven;
    +import org.apache.nifi.annotation.behavior.InputRequirement;
    +import org.apache.nifi.annotation.behavior.WritesAttribute;
    +import org.apache.nifi.annotation.behavior.WritesAttributes;
    +import org.apache.nifi.annotation.documentation.CapabilityDescription;
    +import org.apache.nifi.annotation.documentation.SeeAlso;
    +import org.apache.nifi.annotation.documentation.Tags;
    +import org.apache.nifi.annotation.lifecycle.OnScheduled;
    +import org.apache.nifi.annotation.lifecycle.OnStopped;
    +import org.apache.nifi.components.AllowableValue;
    +import org.apache.nifi.components.PropertyDescriptor;
    +import org.apache.nifi.expression.AttributeExpression.ResultType;
    +import org.apache.nifi.flowfile.FlowFile;
    +import org.apache.nifi.processor.ProcessContext;
    +import org.apache.nifi.processor.ProcessSession;
    +import org.apache.nifi.processor.Relationship;
    +import org.apache.nifi.processor.exception.ProcessException;
    +import org.apache.nifi.processor.util.StandardValidators;
    +
    +import com.google.gson.Gson;
    +
    +import java.io.ByteArrayInputStream;
    +import java.nio.charset.Charset;
    +import java.util.ArrayList;
    +import java.util.Collections;
    +import java.util.HashSet;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Set;
    +
    +@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
    +@EventDriven
    +@Tags({"rethinkdb", "get", "read"})
    +@CapabilityDescription("Processor to get a JSON document from RethinkDB 
(https://www.rethinkdb.com/) using the document id. The FlowFile will contain 
the retrieved document")
    +@WritesAttributes({
    +    @WritesAttribute(attribute = GetRethinkDB.RETHINKDB_ERROR_MESSAGE, 
description = "RethinkDB error message"),
    +    })
    +@SeeAlso({PutRethinkDB.class})
    +public class GetRethinkDB extends AbstractRethinkDBProcessor {
    +
    +    public static AllowableValue READ_MODE_SINGLE = new 
AllowableValue("single", "Single", "Read values from memory from primary 
replica (Default)");
    +    public static AllowableValue READ_MODE_MAJORITY = new 
AllowableValue("majority", "Majority", "Read values commited to disk on 
majority of replicas");
    +    public static AllowableValue READ_MODE_OUTDATED = new 
AllowableValue("outdated", "Outdated", "Read values from memory from an 
arbitrary replica ");
    +
    +    protected static final PropertyDescriptor READ_MODE = new 
PropertyDescriptor.Builder()
    +            .name("rethinkdb-read-mode")
    +            .displayName("Read Mode")
    +            .description("Read mode used for consistency")
    +            .required(true)
    +            .defaultValue(READ_MODE_SINGLE.getValue())
    +            .allowableValues(READ_MODE_SINGLE, READ_MODE_MAJORITY, 
READ_MODE_OUTDATED)
    +            .expressionLanguageSupported(true)
    +            .build();
    +
    +    public static final PropertyDescriptor RETHINKDB_DOCUMENT_ID = new 
PropertyDescriptor.Builder()
    +            .displayName("Document Identifier")
    +            .name("rethinkdb-document-identifier")
    +            .description("A FlowFile attribute, or attribute expression 
used " +
    +                "for determining RethinkDB key for the Flow File content")
    +            .required(true)
    +            
.addValidator(StandardValidators.createAttributeExpressionLanguageValidator(ResultType.STRING,
 true))
    +            .expressionLanguageSupported(true)
    +            .build();
    +
    +    protected String READ_MODE_KEY = "read_mode";
    +
    +    private static final Set<Relationship> relationships;
    +    private static final List<PropertyDescriptor> propertyDescriptors;
    +
    +    public static final String RETHINKDB_ERROR_MESSAGE = 
"rethinkdb.error.message";
    +
    +    protected Gson gson = new Gson();
    +
    +    static {
    +        final Set<Relationship> tempRelationships = new HashSet<>();
    +        tempRelationships.add(REL_SUCCESS);
    +        tempRelationships.add(REL_FAILURE);
    +        tempRelationships.add(REL_NOT_FOUND);
    +        relationships = Collections.unmodifiableSet(tempRelationships);
    +
    +        final List<PropertyDescriptor> tempDescriptors = new ArrayList<>();
    +        tempDescriptors.add(DB_NAME);
    +        tempDescriptors.add(DB_HOST);
    +        tempDescriptors.add(DB_PORT);
    +        tempDescriptors.add(USERNAME);
    +        tempDescriptors.add(PASSWORD);
    +        tempDescriptors.add(TABLE_NAME);
    +        tempDescriptors.add(CHARSET);
    +        tempDescriptors.add(RETHINKDB_DOCUMENT_ID);
    +        tempDescriptors.add(READ_MODE);
    +        tempDescriptors.add(MAX_DOCUMENTS_SIZE);
    +        propertyDescriptors = 
Collections.unmodifiableList(tempDescriptors);
    +    }
    +
    +    @Override
    +    public Set<Relationship> getRelationships() {
    +        return relationships;
    +    }
    +
    +    @Override
    +    public final List<PropertyDescriptor> 
getSupportedPropertyDescriptors() {
    +        return propertyDescriptors;
    +    }
    +
    +    @OnScheduled
    +    public void onScheduled(final ProcessContext context) {
    +        super.onScheduled(context);
    +    }
    +
    +    @Override
    +    public void onTrigger(final ProcessContext context, final 
ProcessSession session) throws ProcessException {
    +        FlowFile flowFile = session.get();
    +        if (flowFile == null) {
    +            return;
    +        }
    +
    +        Charset charset = 
Charset.forName(context.getProperty(CHARSET).evaluateAttributeExpressions(flowFile).getValue());
    +        String id = 
context.getProperty(RETHINKDB_DOCUMENT_ID).evaluateAttributeExpressions(flowFile).getValue();
    +        String readMode = 
context.getProperty(READ_MODE).evaluateAttributeExpressions(flowFile).getValue();
    +
    +        if ( StringUtils.isEmpty(id) ) {
    +            getLogger().error("Empty id '" + id + "'");
    +            flowFile = session.putAttribute(flowFile, 
RETHINKDB_ERROR_MESSAGE, "Empty id '" + id + "'");
    --- End diff --
    
    Do we need to interpolate `id` here after we know it is an empty string?  
Your unit test testBlankId() suggests that the result will just be single 
quotes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to