NIFI-431: Updated validators to use new isExpressionLanguagePresent and isExpressionLanguageSupported methods of ValidationContext

This commit is contained in:
Mark Payne 2015-03-23 15:02:42 -04:00
parent 2429e0540f
commit 12fa9e79f7
9 changed files with 47 additions and 41 deletions

View File

@ -78,20 +78,24 @@ abstract class AbstractKiteProcessor extends AbstractProcessor {
protected static final Validator RECOGNIZED_URI = new Validator() {
@Override
public ValidationResult validate(String subject, String uri,
ValidationContext context) {
public ValidationResult validate(String subject, String uri, ValidationContext context) {
String message = "not set";
boolean isValid = true;
if (uri == null || uri.isEmpty()) {
if (uri.trim().isEmpty()) {
isValid = false;
} else if (!uri.contains("$")) {
try {
new URIBuilder(URI.create(uri)).build();
} catch (RuntimeException e) {
message = e.getMessage();
isValid = false;
} else {
final boolean elPresent = context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(uri);
if (!elPresent) {
try {
new URIBuilder(URI.create(uri)).build();
} catch (RuntimeException e) {
message = e.getMessage();
isValid = false;
}
}
}
return new ValidationResult.Builder()
.subject(subject)
.input(uri)
@ -157,16 +161,16 @@ abstract class AbstractKiteProcessor extends AbstractProcessor {
protected static final Validator SCHEMA_VALIDATOR = new Validator() {
@Override
public ValidationResult validate(String subject, String uri, ValidationContext context) {
Configuration conf = getConfiguration(
context.getProperty(CONF_XML_FILES).getValue());
Configuration conf = getConfiguration(context.getProperty(CONF_XML_FILES).getValue());
String error = null;
if (!uri.contains("$")) {
try {
getSchema(uri, conf);
} catch (SchemaNotFoundException e) {
error = e.getMessage();
}
final boolean elPresent = context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(uri);
if (!elPresent) {
try {
getSchema(uri, conf);
} catch (SchemaNotFoundException e) {
error = e.getMessage();
}
}
return new ValidationResult.Builder()
.subject(subject)
@ -177,8 +181,7 @@ abstract class AbstractKiteProcessor extends AbstractProcessor {
}
};
protected static final List<PropertyDescriptor> ABSTRACT_KITE_PROPS
= ImmutableList.<PropertyDescriptor>builder()
protected static final List<PropertyDescriptor> ABSTRACT_KITE_PROPS = ImmutableList.<PropertyDescriptor>builder()
.add(CONF_XML_FILES)
.build();

View File

@ -88,8 +88,7 @@ public class ConvertCSVToAvro extends AbstractKiteProcessor {
static final PropertyDescriptor SCHEMA =
new PropertyDescriptor.Builder()
.name("Record schema")
.description(
"Outgoing Avro schema for each record created from a CSV row")
.description("Outgoing Avro schema for each record created from a CSV row")
.addValidator(SCHEMA_VALIDATOR)
.expressionLanguageSupported(true)
.required(true)
@ -253,7 +252,6 @@ public class ConvertCSVToAvro extends AbstractKiteProcessor {
} catch (ProcessException | DatasetIOException e) {
getLogger().error("Failed reading or writing", e);
session.transfer(flowFile, FAILURE);
} catch (DatasetException e) {
getLogger().error("Failed to read FlowFile", e);
session.transfer(flowFile, FAILURE);

View File

@ -65,8 +65,7 @@ public class ConvertJSONToAvro extends AbstractKiteProcessor {
static final PropertyDescriptor SCHEMA
= new PropertyDescriptor.Builder()
.name("Record schema")
.description(
"Outgoing Avro schema for each record created from a JSON object")
.description("Outgoing Avro schema for each record created from a JSON object")
.addValidator(SCHEMA_VALIDATOR)
.expressionLanguageSupported(true)
.required(true)

View File

@ -68,8 +68,7 @@ public class StoreInKiteDataset extends AbstractKiteProcessor {
public static final PropertyDescriptor KITE_DATASET_URI =
new PropertyDescriptor.Builder()
.name("Target dataset URI")
.description(
"URI that identifies a Kite dataset where data will be stored")
.description("URI that identifies a Kite dataset where data will be stored")
.addValidator(RECOGNIZED_URI)
.expressionLanguageSupported(true)
.required(true)

View File

@ -155,7 +155,7 @@ public class ControlRate extends AbstractProcessor {
break;
}
final ValidationResult rateResult = rateValidator.validate("Maximum Rate", context.getProperty(MAX_RATE).getValue(), null);
final ValidationResult rateResult = rateValidator.validate("Maximum Rate", context.getProperty(MAX_RATE).getValue(), context);
if (!rateResult.isValid()) {
validationResults.add(rateResult);
}

View File

@ -16,10 +16,19 @@
*/
package org.apache.nifi.processors.standard;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.InvalidJsonException;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.PathNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.nifi.annotation.behavior.DynamicProperty;
@ -27,7 +36,6 @@ import org.apache.nifi.annotation.behavior.EventDriven;
import org.apache.nifi.annotation.behavior.SideEffectFree;
import org.apache.nifi.annotation.behavior.SupportsBatching;
import org.apache.nifi.annotation.documentation.CapabilityDescription;
import org.apache.nifi.annotation.behavior.DynamicRelationship;
import org.apache.nifi.annotation.documentation.Tags;
import org.apache.nifi.annotation.lifecycle.OnRemoved;
import org.apache.nifi.components.PropertyDescriptor;
@ -44,12 +52,10 @@ import org.apache.nifi.processor.io.OutputStreamCallback;
import org.apache.nifi.stream.io.BufferedOutputStream;
import org.apache.nifi.util.ObjectHolder;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.InvalidJsonException;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.PathNotFoundException;
@EventDriven
@SideEffectFree

View File

@ -54,7 +54,7 @@ public class HandleHttpResponse extends AbstractProcessor {
.name("HTTP Status Code")
.description("The HTTP Status Code to use when responding to the HTTP Request. See Section 10 of RFC 2616 for more information.")
.required(true)
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
.addValidator(StandardValidators.NON_NEGATIVE_INTEGER_VALIDATOR)
.expressionLanguageSupported(true)
.build();
public static final PropertyDescriptor HTTP_CONTEXT_MAP = new PropertyDescriptor.Builder()

View File

@ -203,7 +203,7 @@ public final class InvokeHTTP extends AbstractProcessor {
.description("Remote URL which will be connected to, including scheme, host, port, path.")
.required(true)
.expressionLanguageSupported(true)
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
.addValidator(StandardValidators.URL_VALIDATOR)
.build();
PropertyDescriptor PROP_CONNECT_TIMEOUT = new PropertyDescriptor.Builder()

View File

@ -146,6 +146,7 @@ public class PostHTTP extends AbstractProcessor {
.description("The URL to POST to. The first part of the URL must be static. However, the path of the URL may be defined using the Attribute Expression Language. For example, https://${hostname} is not valid, but https://1.1.1.1:8080/files/${nf.file.name} is valid.")
.required(true)
.addValidator(StandardValidators.createRegexMatchingValidator(Pattern.compile("https?\\://.*")))
.addValidator(StandardValidators.URL_VALIDATOR)
.expressionLanguageSupported(true)
.build();
public static final PropertyDescriptor SEND_AS_FLOWFILE = new PropertyDescriptor.Builder()