You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by jo...@apache.org on 2015/04/20 05:13:26 UTC
[49/50] [abbrv] incubator-nifi git commit: NIFI-485: Allow user to
choose how to handle missing JsonPath by ignoring or with a warning
NIFI-485: Allow user to choose how to handle missing JsonPath by ignoring or with a warning
Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/53b6ac33
Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/53b6ac33
Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/53b6ac33
Branch: refs/heads/NIFI-271
Commit: 53b6ac3333d19aff0cc68341fe944da9b0e445f9
Parents: 13cd2a6
Author: Aldrin Piri <al...@gmail.com>
Authored: Sun Apr 19 09:24:45 2015 -0400
Committer: Aldrin Piri <al...@gmail.com>
Committed: Sun Apr 19 09:24:45 2015 -0400
----------------------------------------------------------------------
.../processors/standard/EvaluateJsonPath.java | 21 ++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/53b6ac33/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateJsonPath.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateJsonPath.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateJsonPath.java
index f214178..7f92213 100644
--- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateJsonPath.java
+++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateJsonPath.java
@@ -75,6 +75,9 @@ public class EvaluateJsonPath extends AbstractJsonPathProcessor {
public static final String RETURN_TYPE_JSON = "json";
public static final String RETURN_TYPE_SCALAR = "scalar";
+ public static final String PATH_NOT_FOUND_IGNORE = "ignore";
+ public static final String PATH_NOT_FOUND_WARN = "warn";
+
public static final PropertyDescriptor DESTINATION = new PropertyDescriptor.Builder()
.name("Destination")
.description("Indicates whether the results of the JsonPath evaluation are written to the FlowFile content or a FlowFile attribute; if using attribute, must specify the Attribute Name property. If set to flowfile-content, only one JsonPath may be specified, and the property name is ignored.")
@@ -90,6 +93,14 @@ public class EvaluateJsonPath extends AbstractJsonPathProcessor {
.allowableValues(RETURN_TYPE_AUTO, RETURN_TYPE_JSON, RETURN_TYPE_SCALAR)
.defaultValue(RETURN_TYPE_AUTO)
.build();
+
+ public static final PropertyDescriptor PATH_NOT_FOUND = new PropertyDescriptor.Builder()
+ .name("Path Not Found Behavior")
+ .description("Indicates how to handle missing JSON path expressions when destination is set to 'flowfile-attribute'. Selecting 'warn' will generate a warning when a JSON path expression is not found.")
+ .required(true)
+ .allowableValues(PATH_NOT_FOUND_WARN, PATH_NOT_FOUND_IGNORE)
+ .defaultValue(PATH_NOT_FOUND_IGNORE)
+ .build();
public static final Relationship REL_MATCH = new Relationship.Builder().name("matched").description("FlowFiles are routed to this relationship when the JsonPath is successfully evaluated and the FlowFile is modified as a result").build();
public static final Relationship REL_NO_MATCH = new Relationship.Builder().name("unmatched").description("FlowFiles are routed to this relationship when the JsonPath does not match the content of the FlowFile and the Destination is set to flowfile-content").build();
@@ -111,6 +122,7 @@ public class EvaluateJsonPath extends AbstractJsonPathProcessor {
final List<PropertyDescriptor> properties = new ArrayList<>();
properties.add(DESTINATION);
properties.add(RETURN_TYPE);
+ properties.add(PATH_NOT_FOUND);
properties.add(NULL_VALUE_DEFAULT_REPRESENTATION);
this.properties = Collections.unmodifiableList(properties);
}
@@ -239,6 +251,7 @@ public class EvaluateJsonPath extends AbstractJsonPathProcessor {
String jsonPathAttrKey = attributeJsonPathEntry.getKey();
JsonPath jsonPathExp = attributeJsonPathEntry.getValue();
+ final String pathNotFound = processContext.getProperty(PATH_NOT_FOUND).getValue();
final ObjectHolder<Object> resultHolder = new ObjectHolder<>(null);
try {
@@ -251,7 +264,11 @@ public class EvaluateJsonPath extends AbstractJsonPathProcessor {
}
resultHolder.set(result);
} catch (PathNotFoundException e) {
- logger.warn("FlowFile {} could not find path {} for attribute key {}.", new Object[]{flowFile.getId(), jsonPathExp.getPath(), jsonPathAttrKey}, e);
+
+ if (pathNotFound.equals(PATH_NOT_FOUND_WARN)) {
+ logger.warn("FlowFile {} could not find path {} for attribute key {}.", new Object[]{flowFile.getId(), jsonPathExp.getPath(), jsonPathAttrKey}, e);
+ }
+
if (destination.equals(DESTINATION_ATTRIBUTE)) {
jsonPathResults.put(jsonPathAttrKey, StringUtils.EMPTY);
continue;
@@ -283,4 +300,4 @@ public class EvaluateJsonPath extends AbstractJsonPathProcessor {
flowFile = processSession.putAllAttributes(flowFile, jsonPathResults);
processSession.transfer(flowFile, REL_MATCH);
}
-}
\ No newline at end of file
+}