@EventDriven @SideEffectFree @SupportsBatching @Tags(value={"JSON","evaluate","JsonPath"}) @InputRequirement(value=INPUT_REQUIRED) @CapabilityDescription(value="Evaluates one or more JsonPath expressions against the content of a FlowFile. The results of those expressions are assigned to FlowFile Attributes or are written to the content of the FlowFile itself, depending on configuration of the Processor. JsonPaths are entered by adding user-defined properties; the name of the property maps to the Attribute Name into which the result will be placed (if the Destination is flowfile-attribute; otherwise, the property name is ignored). The value of the property must be a valid JsonPath expression. A Return Type of \'auto-detect\' will make a determination based off the configured destination. When \'Destination\' is set to \'flowfile-attribute,\' a return type of \'scalar\' will be used. When \'Destination\' is set to \'flowfile-content,\' a return type of \'JSON\' will be used.If the JsonPath evaluates to a JSON array or JSON object and the Return Type is set to \'scalar\' the FlowFile will be unmodified and will be routed to failure. A Return Type of JSON can return scalar values if the provided JsonPath evaluates to the specified value and will be routed as a match.If Destination is \'flowfile-content\' and the JsonPath does not evaluate to a defined path, the FlowFile will be routed to \'unmatched\' without having its contents modified. If Destination is flowfile-attribute and the expression matches nothing, attributes will be created with empty strings as the value, and the FlowFile will always be routed to \'matched.\'") @DynamicProperty(name="A FlowFile attribute(if <Destination> is set to \'flowfile-attribute\')", value="A JsonPath expression", description="If <Destination>=\'flowfile-attribute\' then that FlowFile attribute will be set to any JSON objects that match the JsonPath. If <Destination>=\'flowfile-content\' then the FlowFile content will be updated to any JSON objects that match the JsonPath.") public class EvaluateJsonPath extends AbstractJsonPathProcessor
Modifier and Type | Field and Description |
---|---|
static PropertyDescriptor |
DESTINATION |
static java.lang.String |
DESTINATION_ATTRIBUTE |
static java.lang.String |
DESTINATION_CONTENT |
static PropertyDescriptor |
PATH_NOT_FOUND |
static java.lang.String |
PATH_NOT_FOUND_IGNORE |
static java.lang.String |
PATH_NOT_FOUND_WARN |
static Relationship |
REL_FAILURE |
static Relationship |
REL_MATCH |
static Relationship |
REL_NO_MATCH |
static PropertyDescriptor |
RETURN_TYPE |
static java.lang.String |
RETURN_TYPE_AUTO |
static java.lang.String |
RETURN_TYPE_JSON |
static java.lang.String |
RETURN_TYPE_SCALAR |
NULL_VALUE_DEFAULT_REPRESENTATION
Constructor and Description |
---|
EvaluateJsonPath() |
Modifier and Type | Method and Description |
---|---|
protected java.util.Collection<ValidationResult> |
customValidate(ValidationContext context)
Allows subclasses to perform their own validation on the already set
properties.
|
java.util.Set<Relationship> |
getRelationships() |
protected PropertyDescriptor |
getSupportedDynamicPropertyDescriptor(java.lang.String propertyDescriptorName)
Used to allow subclasses to determine what PropertyDescriptor if any to
use when a property is requested for which a descriptor is not already
registered.
|
protected java.util.List<PropertyDescriptor> |
getSupportedPropertyDescriptors()
Allows subclasses to register which property descriptor objects are
supported.
|
protected void |
init(ProcessorInitializationContext context)
Provides subclasses the ability to perform initialization logic
|
void |
onPropertyModified(PropertyDescriptor descriptor,
java.lang.String oldValue,
java.lang.String newValue)
Hook method allowing subclasses to eagerly react to a configuration
change for the given property descriptor.
|
void |
onRemoved(ProcessContext processContext)
Provides cleanup of the map for any JsonPath values that may have been created.
|
void |
onScheduled(ProcessContext processContext) |
void |
onTrigger(ProcessContext processContext,
ProcessSession processSession) |
void |
onUnscheduled() |
onTrigger
getControllerServiceLookup, getIdentifier, getLogger, getNodeTypeProvider, initialize, isConfigurationRestored, isScheduled, toString, updateConfiguredRestoredTrue, updateScheduledFalse, updateScheduledTrue
equals, getPropertyDescriptor, getPropertyDescriptors, hashCode, validate
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getPropertyDescriptor, getPropertyDescriptors, validate
public static final java.lang.String DESTINATION_ATTRIBUTE
public static final java.lang.String DESTINATION_CONTENT
public static final java.lang.String RETURN_TYPE_AUTO
public static final java.lang.String RETURN_TYPE_JSON
public static final java.lang.String RETURN_TYPE_SCALAR
public static final java.lang.String PATH_NOT_FOUND_IGNORE
public static final java.lang.String PATH_NOT_FOUND_WARN
public static final PropertyDescriptor DESTINATION
public static final PropertyDescriptor RETURN_TYPE
public static final PropertyDescriptor PATH_NOT_FOUND
public static final Relationship REL_MATCH
public static final Relationship REL_NO_MATCH
public static final Relationship REL_FAILURE
protected void init(ProcessorInitializationContext context)
AbstractSessionFactoryProcessor
init
in class AbstractSessionFactoryProcessor
context
- in which to perform initializationprotected java.util.Collection<ValidationResult> customValidate(ValidationContext context)
AbstractConfigurableComponent
customValidate
in class AbstractConfigurableComponent
context
- provides a mechanism for obtaining externally
managed values, such as property values and supplies convenience methods
for operating on those valuespublic java.util.Set<Relationship> getRelationships()
getRelationships
in interface Processor
getRelationships
in class AbstractSessionFactoryProcessor
protected java.util.List<PropertyDescriptor> getSupportedPropertyDescriptors()
AbstractConfigurableComponent
getSupportedPropertyDescriptors
in class AbstractConfigurableComponent
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(java.lang.String propertyDescriptorName)
AbstractConfigurableComponent
Used to allow subclasses to determine what PropertyDescriptor if any to use when a property is requested for which a descriptor is not already registered. By default this method simply returns a null descriptor. By overriding this method processor implementations can support dynamic properties since this allows them to register properties on demand. It is acceptable for a dynamically generated property to indicate it is required so long as it is understood it is only required once set. Dynamic properties by definition cannot be required until used.
This method should be side effect free in the subclasses in terms of how often it is called for a given property name because there is guarantees how often it will be called for a given property name.
Default is null.
getSupportedDynamicPropertyDescriptor
in class AbstractConfigurableComponent
propertyDescriptorName
- used to lookup if any property descriptors exist for that namepublic void onPropertyModified(PropertyDescriptor descriptor, java.lang.String oldValue, java.lang.String newValue)
AbstractConfigurableComponent
onPropertyModified
in interface ConfigurableComponent
onPropertyModified
in class AbstractConfigurableComponent
descriptor
- of the modified propertyoldValue
- non-null property value (previous)newValue
- the new property value or if null indicates the property
was removed@OnRemoved public void onRemoved(ProcessContext processContext)
processContext
- context@OnScheduled public void onScheduled(ProcessContext processContext)
@OnUnscheduled public void onUnscheduled()
public void onTrigger(ProcessContext processContext, ProcessSession processSession) throws ProcessException
onTrigger
in class AbstractProcessor
ProcessException