http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/54818893/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 7f92213..042e4a6 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 @@ -45,7 +45,14 @@ 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.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; @@ -64,8 +71,10 @@ import java.util.concurrent.ConcurrentMap; + "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.") +@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 { public static final String DESTINATION_ATTRIBUTE = "flowfile-attribute"; @@ -77,34 +86,47 @@ public class EvaluateJsonPath extends AbstractJsonPathProcessor { 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.") + .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.") .required(true) .allowableValues(DESTINATION_CONTENT, DESTINATION_ATTRIBUTE) .defaultValue(DESTINATION_CONTENT) .build(); public static final PropertyDescriptor RETURN_TYPE = new PropertyDescriptor.Builder() - .name("Return Type") - .description("Indicates the desired return type of the JSON Path expressions. Selecting 'auto-detect' will set the return type to 'json' for a Destination of 'flowfile-content', and 'string' for a Destination of 'flowfile-attribute'.") + .name("Return Type").description("Indicates the desired return type of the JSON Path expressions. Selecting 'auto-detect' will set the return type to 'json' " + + "for a Destination of 'flowfile-content', and 'string' for a Destination of 'flowfile-attribute'.") .required(true) .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.") + .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(); - public static final Relationship REL_FAILURE = new Relationship.Builder().name("failure").description("FlowFiles are routed to this relationship when the JsonPath cannot be evaluated against the content of the FlowFile; for instance, if the FlowFile is not valid JSON").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(); + public static final Relationship REL_FAILURE = new Relationship.Builder() + .name("failure") + .description("FlowFiles are routed to this relationship when the JsonPath cannot be evaluated against the content of the " + + "FlowFile; for instance, if the FlowFile is not valid JSON") + .build(); private Set<Relationship> relationships; private List<PropertyDescriptor> properties; @@ -129,7 +151,8 @@ public class EvaluateJsonPath extends AbstractJsonPathProcessor { @Override protected Collection<ValidationResult> customValidate(final ValidationContext context) { - final List<ValidationResult> results = new ArrayList<>(super.customValidate(context)); + final List<ValidationResult> results = new ArrayList<>(super. + customValidate(context)); final String destination = context.getProperty(DESTINATION).getValue(); if (DESTINATION_CONTENT.equals(destination)) { @@ -142,7 +165,8 @@ public class EvaluateJsonPath extends AbstractJsonPathProcessor { } if (jsonPathCount != 1) { - results.add(new ValidationResult.Builder().subject("JsonPaths").valid(false).explanation("Exactly one JsonPath must be set if using destination of " + DESTINATION_CONTENT).build()); + results.add(new ValidationResult.Builder().subject("JsonPaths").valid(false). + explanation("Exactly one JsonPath must be set if using destination of " + DESTINATION_CONTENT).build()); } } @@ -159,13 +183,10 @@ public class EvaluateJsonPath extends AbstractJsonPathProcessor { return properties; } - @Override protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) { - return new PropertyDescriptor.Builder() - .name(propertyDescriptorName) - .expressionLanguageSupported(false) - .addValidator(new JsonPathValidator() { + return new PropertyDescriptor.Builder().name(propertyDescriptorName).expressionLanguageSupported(false). + addValidator(new JsonPathValidator() { @Override public void cacheComputedValue(String subject, String input, JsonPath computedJsonPath) { cachedJsonPathMap.put(input, computedJsonPath); @@ -175,10 +196,7 @@ public class EvaluateJsonPath extends AbstractJsonPathProcessor { public boolean isStale(String subject, String input) { return cachedJsonPathMap.get(input) == null; } - }) - .required(false) - .dynamic(true) - .build(); + }).required(false).dynamic(true).build(); } @Override @@ -193,9 +211,10 @@ public class EvaluateJsonPath extends AbstractJsonPathProcessor { } /** - * Provides cleanup of the map for any JsonPath values that may have been created. This will remove common values - * shared between multiple instances, but will be regenerated when the next validation cycle occurs as a result of - * isStale() + * Provides cleanup of the map for any JsonPath values that may have been created. This will remove common values shared between multiple instances, but will be regenerated when the next + * validation cycle occurs as a result of isStale() + * + * @param processContext context */ @OnRemoved public void onRemoved(ProcessContext processContext) { @@ -216,7 +235,8 @@ public class EvaluateJsonPath extends AbstractJsonPathProcessor { final ProcessorLog logger = getLogger(); - String representationOption = processContext.getProperty(NULL_VALUE_DEFAULT_REPRESENTATION).getValue(); + String representationOption = processContext. + getProperty(NULL_VALUE_DEFAULT_REPRESENTATION).getValue(); final String nullDefaultValue = NULL_REPRESENTATION_MAP.get(representationOption); /* Build the JsonPath expressions from attributes */ @@ -264,11 +284,12 @@ public class EvaluateJsonPath extends AbstractJsonPathProcessor { } resultHolder.set(result); } catch (PathNotFoundException 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 (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; @@ -288,12 +309,12 @@ public class EvaluateJsonPath extends AbstractJsonPathProcessor { @Override public void process(final OutputStream out) throws IOException { try (OutputStream outputStream = new BufferedOutputStream(out)) { - outputStream.write(resultRepresentation.getBytes(StandardCharsets.UTF_8)); + outputStream.write(resultRepresentation. + getBytes(StandardCharsets.UTF_8)); } } }); - processSession.getProvenanceReporter().modifyContent(flowFile, - "Replaced content with result of expression " + jsonPathExp.getPath()); + processSession.getProvenanceReporter().modifyContent(flowFile, "Replaced content with result of expression " + jsonPathExp.getPath()); break; } }
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/54818893/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateRegularExpression.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateRegularExpression.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateRegularExpression.java index 5d8af9f..50f10f3 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateRegularExpression.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateRegularExpression.java @@ -54,12 +54,11 @@ import org.apache.nifi.annotation.documentation.SeeAlso; @SideEffectFree @SupportsBatching @Tags({"deprecated"}) -@CapabilityDescription( - "WARNING: This has been deprecated and will be removed in 0.2.0. \n\n" - + "Use ExtractText instead.") +@CapabilityDescription("WARNING: This has been deprecated and will be removed in 0.2.0. \n\n Use ExtractText instead.") @SeeAlso(ExtractText.class) @Deprecated -@DynamicProperty(name = "A FlowFile attribute", value = "A regular expression with exactly one capturing group", description = "Will update the specified FlowFile attribute with the group captured by the regular expression") +@DynamicProperty(name = "A FlowFile attribute", value = "A regular expression with exactly one capturing group", + description = "Will update the specified FlowFile attribute with the group captured by the regular expression") public class EvaluateRegularExpression extends AbstractProcessor { public static final PropertyDescriptor CHARACTER_SET = new PropertyDescriptor.Builder() @@ -120,7 +119,8 @@ public class EvaluateRegularExpression extends AbstractProcessor { public static final PropertyDescriptor MULTILINE = new PropertyDescriptor.Builder() .name("Enable Multiline Mode") - .description("Indicates that '^' and '$' should match just after and just before a line terminator or end of sequence, instead of only the begining or end of the entire input. Can also be specified via the embeded flag (?m).") + .description("Indicates that '^' and '$' should match just after and just before a line terminator or end of sequence, instead " + + "of only the begining or end of the entire input. Can also be specified via the embeded flag (?m).") .required(true) .allowableValues("true", "false") .defaultValue("false") @@ -128,7 +128,8 @@ public class EvaluateRegularExpression extends AbstractProcessor { public static final PropertyDescriptor UNICODE_CASE = new PropertyDescriptor.Builder() .name("Enable Unicode-aware Case Folding") - .description("When used with 'Enable Case-insensitive Matching', matches in a manner consistent with the Unicode Standard. Can also be specified via the embeded flag (?u).") + .description("When used with 'Enable Case-insensitive Matching', matches in a manner consistent with the Unicode Standard. " + + "Can also be specified via the embeded flag (?u).") .required(true) .allowableValues("true", "false") .defaultValue("false") @@ -136,7 +137,8 @@ public class EvaluateRegularExpression extends AbstractProcessor { public static final PropertyDescriptor UNICODE_CHARACTER_CLASS = new PropertyDescriptor.Builder() .name("Enable Unicode Predefined Character Classes") - .description("Specifies conformance with the Unicode Technical Standard #18: Unicode Regular Expression Annex C: Compatibility Properties. Can also be specified via the embeded flag (?U).") + .description("Specifies conformance with the Unicode Technical Standard #18: Unicode Regular Expression Annex C: Compatibility " + + "Properties. Can also be specified via the embeded flag (?U).") .required(true) .allowableValues("true", "false") .defaultValue("false") @@ -152,15 +154,12 @@ public class EvaluateRegularExpression extends AbstractProcessor { public static final Relationship REL_MATCH = new Relationship.Builder() .name("matched") - .description( - "FlowFiles are routed to this relationship when the Regular Expression is successfully evaluated and the FlowFile " - + "is modified as a result") + .description("FlowFiles are routed to this relationship when the Regular Expression 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 no provided Regular Expression matches the content of the FlowFile") + .description("FlowFiles are routed to this relationship when no provided Regular Expression matches the content of the FlowFile") .build(); private Set<Relationship> relationships; @@ -201,12 +200,8 @@ public class EvaluateRegularExpression extends AbstractProcessor { @Override protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) { return new PropertyDescriptor.Builder() - .name(propertyDescriptorName) - .expressionLanguageSupported(false) - .addValidator(StandardValidators.createRegexValidator(1, 1, true)) - .required(false) - .dynamic(true) - .build(); + .name(propertyDescriptorName).expressionLanguageSupported(false) + .addValidator(StandardValidators.createRegexValidator(1, 1, true)).required(false).dynamic(true).build(); } @Override http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/54818893/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateXPath.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateXPath.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateXPath.java index 55f55ff..1ea0748 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateXPath.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateXPath.java @@ -93,9 +93,9 @@ import org.xml.sax.InputSource; + "evaluate to a Node, 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'") -@WritesAttribute(attribute="user-defined", description="This processor adds user-defined attributes if the <Destination> property is set to flowfile-attribute.") -@DynamicProperty(name="A FlowFile attribute(if <Destination> is set to 'flowfile-attribute'", value="An XPath expression", description="If <Destination>='flowfile-attribute' " + -"then the FlowFile attribute is set to the result of the XPath Expression. If <Destination>='flowfile-content' then the FlowFile content is set to the result of the XPath Expression.") +@WritesAttribute(attribute = "user-defined", description = "This processor adds user-defined attributes if the <Destination> property is set to flowfile-attribute.") +@DynamicProperty(name = "A FlowFile attribute(if <Destination> is set to 'flowfile-attribute'", value = "An XPath expression", description = "If <Destination>='flowfile-attribute' " + + "then the FlowFile attribute is set to the result of the XPath Expression. If <Destination>='flowfile-content' then the FlowFile content is set to the result of the XPath Expression.") public class EvaluateXPath extends AbstractProcessor { public static final String DESTINATION_ATTRIBUTE = "flowfile-attribute"; @@ -106,7 +106,9 @@ public class EvaluateXPath extends AbstractProcessor { public static final PropertyDescriptor DESTINATION = new PropertyDescriptor.Builder() .name("Destination") - .description("Indicates whether the results of the XPath 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 XPath may be specified, and the property name is ignored.") + .description("Indicates whether the results of the XPath 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 XPath may be specified, " + + "and the property name is ignored.") .required(true) .allowableValues(DESTINATION_CONTENT, DESTINATION_ATTRIBUTE) .defaultValue(DESTINATION_CONTENT) @@ -114,15 +116,29 @@ public class EvaluateXPath extends AbstractProcessor { public static final PropertyDescriptor RETURN_TYPE = new PropertyDescriptor.Builder() .name("Return Type") - .description("Indicates the desired return type of the Xpath expressions. Selecting 'auto-detect' will set the return type to 'nodeset' for a Destination of 'flowfile-content', and 'string' for a Destination of 'flowfile-attribute'.") + .description("Indicates the desired return type of the Xpath expressions. Selecting 'auto-detect' will set the return type to 'nodeset' " + + "for a Destination of 'flowfile-content', and 'string' for a Destination of 'flowfile-attribute'.") .required(true) .allowableValues(RETURN_TYPE_AUTO, RETURN_TYPE_NODESET, RETURN_TYPE_STRING) .defaultValue(RETURN_TYPE_AUTO) .build(); - public static final Relationship REL_MATCH = new Relationship.Builder().name("matched").description("FlowFiles are routed to this relationship when the XPath 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 XPath does not match the content of the FlowFile and the Destination is set to flowfile-content").build(); - public static final Relationship REL_FAILURE = new Relationship.Builder().name("failure").description("FlowFiles are routed to this relationship when the XPath cannot be evaluated against the content of the FlowFile; for instance, if the FlowFile is not valid XML, or if the Return Type is 'nodeset' and the XPath evaluates to multiple nodes").build(); + public static final Relationship REL_MATCH = new Relationship.Builder() + .name("matched") + .description("FlowFiles are routed to this relationship " + + "when the XPath 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 XPath does not match the content of the FlowFile and the Destination is set to flowfile-content") + .build(); + public static final Relationship REL_FAILURE = new Relationship.Builder() + .name("failure") + .description("FlowFiles are routed to this relationship " + + "when the XPath cannot be evaluated against the content of the FlowFile; for instance, if the FlowFile is not valid XML, or if the Return " + + "Type is 'nodeset' and the XPath evaluates to multiple nodes") + .build(); private Set<Relationship> relationships; private List<PropertyDescriptor> properties; @@ -130,8 +146,7 @@ public class EvaluateXPath extends AbstractProcessor { private final AtomicReference<XPathFactory> factoryRef = new AtomicReference<>(); static { - System.setProperty("javax.xml.xpath.XPathFactory:" + NamespaceConstant.OBJECT_MODEL_SAXON, - "net.sf.saxon.xpath.XPathFactoryImpl"); + System.setProperty("javax.xml.xpath.XPathFactory:" + NamespaceConstant.OBJECT_MODEL_SAXON, "net.sf.saxon.xpath.XPathFactoryImpl"); } @Override @@ -150,9 +165,11 @@ public class EvaluateXPath extends AbstractProcessor { @Override protected Collection<ValidationResult> customValidate(final ValidationContext context) { - final List<ValidationResult> results = new ArrayList<>(super.customValidate(context)); + final List<ValidationResult> results = new ArrayList<>(super. + customValidate(context)); - final String destination = context.getProperty(DESTINATION).getValue(); + final String destination = context.getProperty(DESTINATION). + getValue(); if (DESTINATION_CONTENT.equals(destination)) { int xpathCount = 0; @@ -163,7 +180,8 @@ public class EvaluateXPath extends AbstractProcessor { } if (xpathCount != 1) { - results.add(new ValidationResult.Builder().subject("XPaths").valid(false).explanation("Exactly one XPath must be set if using destination of " + DESTINATION_CONTENT).build()); + results.add(new ValidationResult.Builder().subject("XPaths").valid(false) + .explanation("Exactly one XPath must be set if using destination of " + DESTINATION_CONTENT).build()); } } @@ -188,12 +206,8 @@ public class EvaluateXPath extends AbstractProcessor { @Override protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) { return new PropertyDescriptor.Builder() - .name(propertyDescriptorName) - .expressionLanguageSupported(false) - .addValidator(new XPathValidator()) - .required(false) - .dynamic(true) - .build(); + .name(propertyDescriptorName).expressionLanguageSupported(false) + .addValidator(new XPathValidator()).required(false).dynamic(true).build(); } @Override @@ -272,7 +286,8 @@ public class EvaluateXPath extends AbstractProcessor { }); if (error.get() != null) { - logger.error("unable to evaluate XPath against {} due to {}; routing to 'failure'", new Object[]{flowFile, error.get()}); + logger.error("unable to evaluate XPath against {} due to {}; routing to 'failure'", + new Object[]{flowFile, error.get()}); session.transfer(flowFile, REL_FAILURE); continue; } @@ -287,7 +302,8 @@ public class EvaluateXPath extends AbstractProcessor { continue; } } catch (final XPathExpressionException e) { - logger.error("failed to evaluate XPath for {} for Property {} due to {}; routing to failure", new Object[]{flowFile, entry.getKey(), e}); + logger.error("failed to evaluate XPath for {} for Property {} due to {}; routing to failure", + new Object[]{flowFile, entry.getKey(), e}); session.transfer(flowFile, REL_FAILURE); continue flowFileLoop; } @@ -299,8 +315,8 @@ public class EvaluateXPath extends AbstractProcessor { session.transfer(flowFile, REL_NO_MATCH); continue flowFileLoop; } else if (nodeList.size() > 1) { - logger.error("Routing {} to 'failure' because the XPath evaluated to {} XML nodes", new Object[]{ - flowFile, nodeList.size()}); + logger.error("Routing {} to 'failure' because the XPath evaluated to {} XML nodes", + new Object[]{flowFile, nodeList.size()}); session.transfer(flowFile, REL_FAILURE); continue flowFileLoop; } @@ -312,7 +328,7 @@ public class EvaluateXPath extends AbstractProcessor { doTransform(sourceNode, baos); xpathResults.put(entry.getKey(), baos.toString("UTF-8")); } catch (UnsupportedEncodingException e) { - throw new ProcessException(e); // this REALLY shouldn't happen + throw new ProcessException(e); } catch (TransformerException e) { error.set(e); } @@ -340,7 +356,8 @@ public class EvaluateXPath extends AbstractProcessor { @Override public void process(final OutputStream rawOut) throws IOException { try (final OutputStream out = new BufferedOutputStream(rawOut)) { - out.write(resultString.getBytes("UTF-8")); + out.write(resultString. + getBytes("UTF-8")); } } }); @@ -352,8 +369,8 @@ public class EvaluateXPath extends AbstractProcessor { if (DESTINATION_ATTRIBUTE.equals(destination)) { flowFile = session.putAllAttributes(flowFile, xpathResults); final Relationship destRel = xpathResults.isEmpty() ? REL_NO_MATCH : REL_MATCH; - logger.info("Successfully evaluated XPaths against {} and found {} matches; routing to {}", new Object[]{flowFile, - xpathResults.size(), destRel.getName()}); + logger.info("Successfully evaluated XPaths against {} and found {} matches; routing to {}", + new Object[]{flowFile, xpathResults.size(), destRel.getName()}); session.transfer(flowFile, destRel); session.getProvenanceReporter().modifyAttributes(flowFile); } else if (DESTINATION_CONTENT.equals(destination)) { @@ -362,7 +379,8 @@ public class EvaluateXPath extends AbstractProcessor { session.getProvenanceReporter().modifyContent(flowFile); } } else { - logger.error("Failed to write XPath result for {} due to {}; routing original to 'failure'", new Object[]{flowFile, error.get()}); + logger.error("Failed to write XPath result for {} due to {}; routing original to 'failure'", + new Object[]{flowFile, error.get()}); session.transfer(flowFile, REL_FAILURE); } } @@ -383,29 +401,29 @@ public class EvaluateXPath extends AbstractProcessor { transformer.setOutputProperties(props); final ProcessorLog logger = getLogger(); - + final ObjectHolder<TransformerException> error = new ObjectHolder<>(null); transformer.setErrorListener(new ErrorListener() { @Override public void warning(final TransformerException exception) throws TransformerException { - logger.warn("Encountered warning from XPath Engine: ", new Object[] {exception.toString(), exception}); + logger.warn("Encountered warning from XPath Engine: ", new Object[]{exception.toString(), exception}); } @Override public void error(final TransformerException exception) throws TransformerException { - logger.error("Encountered error from XPath Engine: ", new Object[] {exception.toString(), exception}); + logger.error("Encountered error from XPath Engine: ", new Object[]{exception.toString(), exception}); error.set(exception); } @Override public void fatalError(final TransformerException exception) throws TransformerException { - logger.error("Encountered warning from XPath Engine: ", new Object[] {exception.toString(), exception}); + logger.error("Encountered warning from XPath Engine: ", new Object[]{exception.toString(), exception}); error.set(exception); } }); - + transformer.transform(sourceNode, new StreamResult(out)); - if ( error.get() != null ) { + if (error.get() != null) { throw error.get(); } } @@ -427,7 +445,8 @@ public class EvaluateXPath extends AbstractProcessor { return new ValidationResult.Builder().input(input).subject(subject).valid(error == null).explanation(error).build(); } catch (final Exception e) { - return new ValidationResult.Builder().input(input).subject(subject).valid(false).explanation("Unable to initialize XPath engine due to " + e.toString()).build(); + return new ValidationResult.Builder().input(input).subject(subject).valid(false) + .explanation("Unable to initialize XPath engine due to " + e.toString()).build(); } } } http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/54818893/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateXQuery.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateXQuery.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateXQuery.java index ad1a2e4..c6321ad 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateXQuery.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateXQuery.java @@ -94,9 +94,9 @@ import org.xml.sax.InputSource; + "'matched'. If no provided XQuery returns a result, the FlowFile will be routed to 'unmatched'. If the " + "Destination is 'flowfile-attribute' and the XQueries matche nothing, no attributes will be applied to the " + "FlowFile.") -@WritesAttribute(attribute="user-defined", description="This processor adds user-defined attributes if the <Destination> property is set to flowfile-attribute .") -@DynamicProperty(name="A FlowFile attribute(if <Destination> is set to 'flowfile-attribute'", value="An XQuery", description="If <Destination>='flowfile-attribute' " + - "then the FlowFile attribute is set to the result of the XQuery. If <Destination>='flowfile-content' then the FlowFile content is set to the result of the XQuery.") +@WritesAttribute(attribute = "user-defined", description = "This processor adds user-defined attributes if the <Destination> property is set to flowfile-attribute .") +@DynamicProperty(name = "A FlowFile attribute(if <Destination> is set to 'flowfile-attribute'", value = "An XQuery", description = "If <Destination>='flowfile-attribute' " + + "then the FlowFile attribute is set to the result of the XQuery. If <Destination>='flowfile-content' then the FlowFile content is set to the result of the XQuery.") public class EvaluateXQuery extends AbstractProcessor { public static final String DESTINATION_ATTRIBUTE = "flowfile-attribute"; @@ -147,22 +147,19 @@ public class EvaluateXQuery extends AbstractProcessor { public static final Relationship REL_MATCH = new Relationship.Builder() .name("matched") - .description( - "FlowFiles are routed to this relationship when the XQuery is successfully evaluated and the FlowFile " + .description("FlowFiles are routed to this relationship when the XQuery 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 XQuery does not match the content of the FlowFile " + .description("FlowFiles are routed to this relationship when the XQuery does not match the content of the FlowFile " + "and the Destination is set to flowfile-content") .build(); public static final Relationship REL_FAILURE = new Relationship.Builder() .name("failure") - .description( - "FlowFiles are routed to this relationship when the XQuery cannot be evaluated against the content of " + .description("FlowFiles are routed to this relationship when the XQuery cannot be evaluated against the content of " + "the FlowFile.") .build(); @@ -187,7 +184,8 @@ public class EvaluateXQuery extends AbstractProcessor { @Override protected Collection<ValidationResult> customValidate(final ValidationContext context) { - final List<ValidationResult> results = new ArrayList<>(super.customValidate(context)); + final List<ValidationResult> results = new ArrayList<>(super. + customValidate(context)); final String destination = context.getProperty(DESTINATION).getValue(); if (DESTINATION_CONTENT.equals(destination)) { @@ -198,11 +196,8 @@ public class EvaluateXQuery extends AbstractProcessor { } } if (xQueryCount != 1) { - results.add(new ValidationResult.Builder() - .subject("XQueries") - .valid(false) - .explanation("Exactly one XQuery must be set if using destination of " + DESTINATION_CONTENT) - .build()); + results.add(new ValidationResult.Builder().subject("XQueries").valid(false) + .explanation("Exactly one XQuery must be set if using destination of " + DESTINATION_CONTENT).build()); } } return results; @@ -220,13 +215,8 @@ public class EvaluateXQuery extends AbstractProcessor { @Override protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) { - return new PropertyDescriptor.Builder() - .name(propertyDescriptorName) - .expressionLanguageSupported(false) - .addValidator(new XQueryValidator()) - .required(false) - .dynamic(true) - .build(); + return new PropertyDescriptor.Builder().name(propertyDescriptorName).expressionLanguageSupported(false) + .addValidator(new XQueryValidator()).required(false).dynamic(true).build(); } @Override @@ -321,7 +311,8 @@ public class EvaluateXQuery extends AbstractProcessor { } } else { // if (DESTINATION_CONTENT.equals(destination)){ if (result.size() == 0) { - logger.info("Routing {} to 'unmatched'", new Object[]{flowFile}); + logger. + info("Routing {} to 'unmatched'", new Object[]{flowFile}); session.transfer(flowFile, REL_NO_MATCH); continue flowFileLoop; } else if (result.size() == 1) { @@ -362,8 +353,8 @@ public class EvaluateXQuery extends AbstractProcessor { session.remove(childrenFlowFiles); continue flowFileLoop; } catch (TransformerFactoryConfigurationError | TransformerException | IOException e) { - logger.error("Failed to write XQuery result for {} due to {}; routing original to 'failure'", new Object[]{ - flowFile, error.get()}); + logger.error("Failed to write XQuery result for {} due to {}; routing original to 'failure'", + new Object[]{flowFile, error.get()}); session.transfer(flowFile, REL_FAILURE); session.remove(childrenFlowFiles); continue flowFileLoop; @@ -392,15 +383,14 @@ public class EvaluateXQuery extends AbstractProcessor { } // end flowFileLoop } - private String formatItem(XdmItem item, ProcessContext context) throws TransformerConfigurationException, - TransformerFactoryConfigurationError, TransformerException, IOException { + private String formatItem(XdmItem item, ProcessContext context) throws TransformerConfigurationException, TransformerFactoryConfigurationError, TransformerException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); writeformattedItem(item, context, baos); return baos.toString(); } - void writeformattedItem(XdmItem item, ProcessContext context, OutputStream out) throws TransformerConfigurationException, - TransformerFactoryConfigurationError, TransformerException, IOException { + void writeformattedItem(XdmItem item, ProcessContext context, OutputStream out) + throws TransformerConfigurationException, TransformerFactoryConfigurationError, TransformerException, IOException { if (item.isAtomicValue()) { out.write(item.getStringValue().getBytes(UTF8)); @@ -448,19 +438,10 @@ public class EvaluateXQuery extends AbstractProcessor { } catch (final Exception e) { error = e.toString(); } - return new ValidationResult.Builder() - .input(input) - .subject(subject) - .valid(error == null) - .explanation(error) - .build(); + return new ValidationResult.Builder().input(input).subject(subject).valid(error == null).explanation(error).build(); } catch (final Exception e) { - return new ValidationResult.Builder() - .input(input) - .subject(subject) - .valid(false) - .explanation("Unable to initialize XQuery engine due to " + e.toString()) - .build(); + return new ValidationResult.Builder().input(input).subject(subject).valid(false) + .explanation("Unable to initialize XQuery engine due to " + e.toString()).build(); } } } http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/54818893/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteProcess.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteProcess.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteProcess.java index 61cf317..7950c9c 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteProcess.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteProcess.java @@ -62,7 +62,7 @@ import org.apache.nifi.processor.util.StandardValidators; @CapabilityDescription("Runs an operating system command specified by the user and writes the output of that command to a FlowFile. If the command is expected " + "to be long-running, the Processor can output the partial data on a specified interval. When this option is used, the output is expected to be in textual " + "format, as it typically does not make sense to split binary data on arbitrary time-based intervals.") -@DynamicProperty(name="An environment variable name", value="An environment variable value", description="These environment variables are passed to the process spawned by this Processor") +@DynamicProperty(name = "An environment variable name", value = "An environment variable value", description = "These environment variables are passed to the process spawned by this Processor") public class ExecuteProcess extends AbstractProcessor { public static final PropertyDescriptor COMMAND = new PropertyDescriptor.Builder() @@ -163,7 +163,8 @@ public class ExecuteProcess extends AbstractProcessor { if (inQuotes) { sb.append(c); } else { - final String arg = sb.toString().trim(); + final String arg = sb.toString(). + trim(); if (!arg.isEmpty()) { args.add(arg); } @@ -313,7 +314,7 @@ public class ExecuteProcess extends AbstractProcessor { }); // continue to do this loop until both the process has finished and we have finished copying - // the output from the process to the FlowFile. Unfortunately, even after calling Process.exitValue(), + // the output from the process to the FlowFile. Unfortunately, even after calling Process.exitValue(), // there can be data buffered on the InputStream; so we will wait until the stream is empty as well. int flowFileCount = 0; while (!finishedCopying.get() || isAlive(process)) { @@ -376,11 +377,13 @@ public class ExecuteProcess extends AbstractProcessor { } final int exitCode; - final long millis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos); + final long millis = TimeUnit.NANOSECONDS. + toMillis(System.nanoTime() - startNanos); try { exitCode = process.waitFor(); } catch (final InterruptedException ie) { - getLogger().warn("Process was interrupted before finishing"); + getLogger(). + warn("Process was interrupted before finishing"); return; } @@ -409,9 +412,7 @@ public class ExecuteProcess extends AbstractProcessor { } /** - * Output stream that is used to wrap another output stream in a way that - * the underlying output stream can be swapped out for a different one when - * needed + * Output stream that is used to wrap another output stream in a way that the underlying output stream can be swapped out for a different one when needed */ private static class ProxyOutputStream extends OutputStream { @@ -428,7 +429,6 @@ public class ExecuteProcess extends AbstractProcessor { lock.lock(); try { logger.trace("Switching delegate from {} to {}", new Object[]{this.delegate, delegate}); - this.delegate = delegate; } finally { lock.unlock(); @@ -470,7 +470,6 @@ public class ExecuteProcess extends AbstractProcessor { while (true) { if (delegate != null) { logger.trace("Writing to {}", new Object[]{delegate}); - delegate.write(b, off, len); return; } else { http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/54818893/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteStreamCommand.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteStreamCommand.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteStreamCommand.java index 4e6fd1b..ddeb51a 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteStreamCommand.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteStreamCommand.java @@ -61,8 +61,7 @@ import org.apache.nifi.stream.io.StreamUtils; /** * <p> - * This processor executes an external command on the contents of a flow file, - * and creates a new flow file with the results of the command. + * This processor executes an external command on the contents of a flow file, and creates a new flow file with the results of the command. * </p> * <p> * <strong>Properties:</strong> @@ -70,26 +69,22 @@ import org.apache.nifi.stream.io.StreamUtils; * <ul> * <li><strong>Command Path</strong> * <ul> - * <li>Specifies the command to be executed; if just the name of an executable - * is provided, it must be in the user's environment PATH.</li> + * <li>Specifies the command to be executed; if just the name of an executable is provided, it must be in the user's environment PATH.</li> * <li>Default value: none</li> * <li>Supports expression language: true</li> * </ul> * </li> * <li>Command Arguments * <ul> - * <li>The arguments to supply to the executable delimited by the ';' character. - * Each argument may be an Expression Language statement.</li> + * <li>The arguments to supply to the executable delimited by the ';' character. Each argument may be an Expression Language statement.</li> * <li>Default value: none</li> * <li>Supports expression language: true</li> * </ul> * </li> * <li>Working Directory * <ul> - * <li>The directory to use as the current working directory when executing the - * command</li> - * <li>Default value: none (which means whatever NiFi's current working - * directory is...probably the root of the NiFi installation directory.)</li> + * <li>The directory to use as the current working directory when executing the command</li> + * <li>Default value: none (which means whatever NiFi's current working directory is...probably the root of the NiFi installation directory.)</li> * <li>Supports expression language: true</li> * </ul> * </li> @@ -107,8 +102,7 @@ import org.apache.nifi.stream.io.StreamUtils; * </li> * <li>output-stream * <ul> - * <li>The destination path for the flow file created from the command's - * output</li> + * <li>The destination path for the flow file created from the command's output</li> * </ul> * </li> * </ul> @@ -120,16 +114,17 @@ import org.apache.nifi.stream.io.StreamUtils; @SupportsBatching @Tags({"command execution", "command", "stream", "execute"}) @CapabilityDescription("Executes an external command on the contents of a flow file, and creates a new flow file with the results of the command.") -@WritesAttributes({ @WritesAttribute(attribute = "execution.command", description = "The name of the command executed to create the new FlowFile"), - @WritesAttribute(attribute = "execution.command.args", description = "The semi-colon delimited list of arguments"), - @WritesAttribute(attribute = "execution.status", description = "The exit status code returned from executing the command"), - @WritesAttribute(attribute = "execution.error", description = "Any error messages returned from executing the command") }) +@WritesAttributes({ + @WritesAttribute(attribute = "execution.command", description = "The name of the command executed to create the new FlowFile"), + @WritesAttribute(attribute = "execution.command.args", description = "The semi-colon delimited list of arguments"), + @WritesAttribute(attribute = "execution.status", description = "The exit status code returned from executing the command"), + @WritesAttribute(attribute = "execution.error", description = "Any error messages returned from executing the command")}) public class ExecuteStreamCommand extends AbstractProcessor { - public static final Relationship ORIGINAL_RELATIONSHIP = new Relationship.Builder() - .name("original") - .description("FlowFiles that were successfully processed") - .build(); + public static final Relationship ORIGINAL_RELATIONSHIP = new Relationship.Builder(). + name("original"). + description("FlowFiles that were successfully processed"). + build(); public static final Relationship OUTPUT_STREAM_RELATIONSHIP = new Relationship.Builder() .name("output stream") .description("The destination path for the flow file created from the command's output") @@ -143,12 +138,10 @@ public class ExecuteStreamCommand extends AbstractProcessor { RELATIONSHIPS = Collections.unmodifiableSet(rels); } - private static final Validator ATTRIBUTE_EXPRESSION_LANGUAGE_VALIDATOR = StandardValidators.createAttributeExpressionLanguageValidator( - ResultType.STRING, true); - static final PropertyDescriptor EXECUTION_COMMAND = new PropertyDescriptor.Builder() - .name("Command Path") - .description( - "Specifies the command to be executed; if just the name of an executable is provided, it must be in the user's environment PATH.") + private static final Validator ATTRIBUTE_EXPRESSION_LANGUAGE_VALIDATOR = StandardValidators.createAttributeExpressionLanguageValidator(ResultType.STRING, true); + static final PropertyDescriptor EXECUTION_COMMAND = new PropertyDescriptor.Builder(). + name("Command Path") + .description("Specifies the command to be executed; if just the name of an executable is provided, it must be in the user's environment PATH.") .expressionLanguageSupported(true) .addValidator(ATTRIBUTE_EXPRESSION_LANGUAGE_VALIDATOR) .required(true) @@ -157,19 +150,16 @@ public class ExecuteStreamCommand extends AbstractProcessor { static final PropertyDescriptor EXECUTION_ARGUMENTS = new PropertyDescriptor.Builder() .name("Command Arguments") .description("The arguments to supply to the executable delimited by the ';' character.") - .expressionLanguageSupported(true) - .addValidator(new Validator() { + .expressionLanguageSupported(true).addValidator(new Validator() { @Override public ValidationResult validate(String subject, String input, ValidationContext context) { ValidationResult result = new ValidationResult.Builder() - .subject(subject) - .valid(true) - .input(input) - .build(); + .subject(subject).valid(true).input(input).build(); String[] args = input.split(";"); for (String arg : args) { - ValidationResult valResult = ATTRIBUTE_EXPRESSION_LANGUAGE_VALIDATOR.validate(subject, arg, context); + ValidationResult valResult = ATTRIBUTE_EXPRESSION_LANGUAGE_VALIDATOR. + validate(subject, arg, context); if (!valResult.isValid()) { result = valResult; break; @@ -177,8 +167,7 @@ public class ExecuteStreamCommand extends AbstractProcessor { } return result; } - }) - .build(); + }).build(); static final PropertyDescriptor WORKING_DIR = new PropertyDescriptor.Builder() .name("Working Directory") @@ -240,8 +229,7 @@ public class ExecuteStreamCommand extends AbstractProcessor { if (!StringUtils.isBlank(workingDir)) { dir = new File(workingDir); if (!dir.exists() && !dir.mkdirs()) { - logger.warn("Failed to create working directory {}, using current working directory {}", - new Object[]{workingDir, System.getProperty("user.dir")}); + logger.warn("Failed to create working directory {}, using current working directory {}", new Object[]{workingDir, System.getProperty("user.dir")}); } } builder.command(args); @@ -267,7 +255,8 @@ public class ExecuteStreamCommand extends AbstractProcessor { session.read(flowFile, callback); outputStreamFlowFile = callback.outputStreamFlowFile; exitCode = callback.exitCode; - logger.debug("Execution complete for command: {}. Exited with code: {}", new Object[]{executeCommand, exitCode}); + logger. + debug("Execution complete for command: {}. Exited with code: {}", new Object[]{executeCommand, exitCode}); Map<String, String> attributes = new HashMap<>(); @@ -317,8 +306,7 @@ public class ExecuteStreamCommand extends AbstractProcessor { FlowFile outputStreamFlowFile; int exitCode; - public StdInWriterCallback(OutputStream stdInWritable, InputStream stdOutReadable, ProcessorLog logger, ProcessSession session, - FlowFile outputStreamFlowFile, Process process) { + public StdInWriterCallback(OutputStream stdInWritable, InputStream stdOutReadable, ProcessorLog logger, ProcessSession session, FlowFile outputStreamFlowFile, Process process) { this.stdInWritable = stdInWritable; this.stdOutReadable = stdOutReadable; this.logger = logger; @@ -340,7 +328,8 @@ public class ExecuteStreamCommand extends AbstractProcessor { try { StreamUtils.copy(incomingFlowFileIS, stdInWritable); } catch (IOException e) { - logger.error("Failed to write flow file to stdIn due to {}", new Object[]{e}, e); + logger. + error("Failed to write flow file to stdIn due to {}", new Object[]{e}, e); } // MUST close the output stream to the stdIn so that whatever is reading knows // there is no more data http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/54818893/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExtractText.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExtractText.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExtractText.java index caf1cda..d413b1a 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExtractText.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExtractText.java @@ -67,8 +67,8 @@ import org.apache.nifi.annotation.lifecycle.OnScheduled; + "If any provided Regular Expression matches, the FlowFile(s) will be routed to 'matched'. " + "If no provided Regular Expression matches, the FlowFile will be routed to 'unmatched' " + "and no attributes will be applied to the FlowFile.") -@DynamicProperty(name="A FlowFile attribute", value="A Regular Expression with one or more capturing group", - description="The first capture group, if any found, will be placed into that attribute name." +@DynamicProperty(name = "A FlowFile attribute", value = "A Regular Expression with one or more capturing group", + description = "The first capture group, if any found, will be placed into that attribute name." + "But all catpure groups, including the matching string sequence itself will also be " + "provided at that attribute name with an index value provided.") public class ExtractText extends AbstractProcessor { @@ -140,7 +140,8 @@ public class ExtractText extends AbstractProcessor { public static final PropertyDescriptor MULTILINE = new PropertyDescriptor.Builder() .name("Enable Multiline Mode") - .description("Indicates that '^' and '$' should match just after and just before a line terminator or end of sequence, instead of only the begining or end of the entire input. Can also be specified via the embeded flag (?m).") + .description("Indicates that '^' and '$' should match just after and just before a line terminator or end of sequence, instead of " + + "only the begining or end of the entire input. Can also be specified via the embeded flag (?m).") .required(true) .allowableValues("true", "false") .defaultValue("false") @@ -148,7 +149,8 @@ public class ExtractText extends AbstractProcessor { public static final PropertyDescriptor UNICODE_CASE = new PropertyDescriptor.Builder() .name("Enable Unicode-aware Case Folding") - .description("When used with 'Enable Case-insensitive Matching', matches in a manner consistent with the Unicode Standard. Can also be specified via the embeded flag (?u).") + .description("When used with 'Enable Case-insensitive Matching', matches in a manner consistent with the Unicode Standard. Can also " + + "be specified via the embeded flag (?u).") .required(true) .allowableValues("true", "false") .defaultValue("false") @@ -156,7 +158,8 @@ public class ExtractText extends AbstractProcessor { public static final PropertyDescriptor UNICODE_CHARACTER_CLASS = new PropertyDescriptor.Builder() .name("Enable Unicode Predefined Character Classes") - .description("Specifies conformance with the Unicode Technical Standard #18: Unicode Regular Expression Annex C: Compatibility Properties. Can also be specified via the embeded flag (?U).") + .description("Specifies conformance with the Unicode Technical Standard #18: Unicode Regular Expression Annex C: Compatibility " + + "Properties. Can also be specified via the embeded flag (?U).") .required(true) .allowableValues("true", "false") .defaultValue("false") @@ -164,7 +167,8 @@ public class ExtractText extends AbstractProcessor { public static final PropertyDescriptor UNIX_LINES = new PropertyDescriptor.Builder() .name("Enable Unix Lines Mode") - .description("Indicates that only the '\n' line terminator is recognized int the behavior of '.', '^', and '$'. Can also be specified via the embeded flag (?d).") + .description("Indicates that only the '\n' line terminator is recognized int the behavior of '.', '^', and '$'. Can also be specified " + + "via the embeded flag (?d).") .required(true) .allowableValues("true", "false") .defaultValue("false") @@ -172,15 +176,12 @@ public class ExtractText extends AbstractProcessor { public static final Relationship REL_MATCH = new Relationship.Builder() .name("matched") - .description( - "FlowFiles are routed to this relationship when the Regular Expression is successfully evaluated and the FlowFile " - + "is modified as a result") + .description("FlowFiles are routed to this relationship when the Regular Expression 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 no provided Regular Expression matches the content of the FlowFile") + .description("FlowFiles are routed to this relationship when no provided Regular Expression matches the content of the FlowFile") .build(); private Set<Relationship> relationships; @@ -271,7 +272,8 @@ public class ExtractText extends AbstractProcessor { final Map<String, Pattern> patternMap = compiledPattersMapRef.get(); for (final Map.Entry<String, Pattern> entry : patternMap.entrySet()) { - final Matcher matcher = entry.getValue().matcher(contentString); + final Matcher matcher = entry.getValue(). + matcher(contentString); if (matcher.find()) { final String baseKey = entry.getKey(); http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/54818893/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GenerateFlowFile.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GenerateFlowFile.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GenerateFlowFile.java index 0ae4747..ebcca86 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GenerateFlowFile.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GenerateFlowFile.java @@ -73,13 +73,16 @@ public class GenerateFlowFile extends AbstractProcessor { .build(); public static final PropertyDescriptor UNIQUE_FLOWFILES = new PropertyDescriptor.Builder() .name("Unique FlowFiles") - .description("If true, each FlowFile that is generated will be unique. If false, a random value will be generated and all FlowFiles will get the same content but this offers much higher throughput") + .description("If true, each FlowFile that is generated will be unique. If false, a random value will be generated and all FlowFiles " + + "will get the same content but this offers much higher throughput") .required(true) .allowableValues("true", "false") .defaultValue("false") .build(); - public static final Relationship SUCCESS = new Relationship.Builder().name("success").build(); + public static final Relationship SUCCESS = new Relationship.Builder() + .name("success") + .build(); private List<PropertyDescriptor> descriptors; private Set<Relationship> relationships; @@ -146,7 +149,8 @@ public class GenerateFlowFile extends AbstractProcessor { data = this.data.get(); } - for (int i = 0; i < context.getProperty(BATCH_SIZE).asInteger(); i++) { + for (int i = 0; i < context.getProperty(BATCH_SIZE). + asInteger(); i++) { FlowFile flowFile = session.create(); if (data.length > 0) { flowFile = session.write(flowFile, new OutputStreamCallback() { http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/54818893/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFTP.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFTP.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFTP.java index efce8fd..ac02b9e 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFTP.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFTP.java @@ -35,14 +35,20 @@ import org.apache.nifi.processors.standard.util.FileTransfer; @SideEffectFree @Tags({"FTP", "get", "retrieve", "files", "fetch", "remote", "ingest", "source", "input"}) @CapabilityDescription("Fetches files from an FTP Server and creates FlowFiles from them") -@WritesAttributes({ @WritesAttribute(attribute = "filename", description = "The filename is set to the name of the file on the remote server"), - @WritesAttribute(attribute = "path", description = "The path is set to the path of the file's directory on the remote server. For example, if the <Remote Path> property is set to /tmp, files picked up from /tmp will have the path attribute set to /tmp. If the <Search Recursively> property is set to true and a file is picked up from /tmp/abc/1/2/3, then the path attribute will be set to /tmp/abc/1/2/3"), +@WritesAttributes({ + @WritesAttribute(attribute = "filename", description = "The filename is set to the name of the file on the remote server"), + @WritesAttribute(attribute = "path", description = "The path is set to the path of the file's directory on the remote server. " + + "For example, if the <Remote Path> property is set to /tmp, files picked up from /tmp will have the path attribute set " + + "to /tmp. If the <Search Recursively> property is set to true and a file is picked up from /tmp/abc/1/2/3, then the path " + + "attribute will be set to /tmp/abc/1/2/3"), @WritesAttribute(attribute = "file.lastModifiedTime", description = "The date and time that the source file was last modified"), - @WritesAttribute(attribute = "file.lastAccessTime", description = "The date and time that the file was last accessed. May not work on all file systems"), + @WritesAttribute(attribute = "file.lastAccessTime", description = "The date and time that the file was last accessed. May not work on " + + "all file systems"), @WritesAttribute(attribute = "file.owner", description = "The numeric owner id of the source file"), @WritesAttribute(attribute = "file.group", description = "The numeric group id of the source file"), @WritesAttribute(attribute = "file.permissions", description = "The read/write/execute permissions of the source file"), - @WritesAttribute(attribute = "absolute.path", description = "The full/absolute path from where a file was picked up. The current 'path' attribute is still populated, but may be a relative path")}) + @WritesAttribute(attribute = "absolute.path", description = "The full/absolute path from where a file was picked up. The current 'path' " + + "attribute is still populated, but may be a relative path")}) @SeeAlso(PutFTP.class) public class GetFTP extends GetFileTransfer { http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/54818893/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFile.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFile.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFile.java index f794095..bc2fac2 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFile.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFile.java @@ -72,15 +72,22 @@ import org.apache.nifi.processor.util.StandardValidators; @TriggerWhenEmpty @Tags({"local", "files", "filesystem", "ingest", "ingress", "get", "source", "input"}) @CapabilityDescription("Creates FlowFiles from files in a directory. NiFi will ignore files it doesn't have at least read permissions for.") -@WritesAttributes({ @WritesAttribute(attribute = "filename", description = "The filename is set to the name of the file on disk"), - @WritesAttribute(attribute = "path", description = "The path is set to the relative path of the file's directory on disk. For example, if the <Input Directory> property is set to /tmp, files picked up from /tmp will have the path attribute set to ./. If the <Recurse Subdirectories> property is set to true and a file is picked up from /tmp/abc/1/2/3, then the path attribute will be set to abc/1/2/3"), +@WritesAttributes({ + @WritesAttribute(attribute = "filename", description = "The filename is set to the name of the file on disk"), + @WritesAttribute(attribute = "path", description = "The path is set to the relative path of the file's directory on disk. For example, " + + "if the <Input Directory> property is set to /tmp, files picked up from /tmp will have the path attribute set to ./. If " + + "the <Recurse Subdirectories> property is set to true and a file is picked up from /tmp/abc/1/2/3, then the path attribute will " + + "be set to abc/1/2/3"), @WritesAttribute(attribute = "file.creationTime", description = "The date and time that the file was created. May not work on all file systems"), - @WritesAttribute(attribute = "file.lastModifiedTime", description = "The date and time that the file was last modified. May not work on all file systems"), - @WritesAttribute(attribute = "file.lastAccessTime", description = "The date and time that the file was last accessed. May not work on all file systems"), + @WritesAttribute(attribute = "file.lastModifiedTime", description = "The date and time that the file was last modified. May not work on all " + + "file systems"), + @WritesAttribute(attribute = "file.lastAccessTime", description = "The date and time that the file was last accessed. May not work on all " + + "file systems"), @WritesAttribute(attribute = "file.owner", description = "The owner of the file. May not work on all file systems"), @WritesAttribute(attribute = "file.group", description = "The group owner of the file. May not work on all file systems"), @WritesAttribute(attribute = "file.permissions", description = "The read/write/execute permissions of the file. May not work on all file systems"), - @WritesAttribute(attribute = "absolute.path", description = "The full/absolute path from where a file was picked up. The current 'path' attribute is still populated, but may be a relative path")}) + @WritesAttribute(attribute = "absolute.path", description = "The full/absolute path from where a file was picked up. The current 'path' " + + "attribute is still populated, but may be a relative path")}) @SeeAlso(PutFile.class) public class GetFile extends AbstractProcessor { @@ -271,12 +278,12 @@ public class GetFile extends AbstractProcessor { } } //Verify that we have at least read permissions on the file we're considering grabbing - if(!Files.isReadable(file.toPath())){ + if (!Files.isReadable(file.toPath())) { return false; } - + //Verify that if we're not keeping original that we have write permissions on the directory the file is in - if(keepOriginal == false && !Files.isWritable(file.toPath().getParent())){ + if (keepOriginal == false && !Files.isWritable(file.toPath().getParent())) { return false; } return filePattern.matcher(file.getName()).matches(); @@ -337,7 +344,8 @@ public class GetFile extends AbstractProcessor { if (store.supportsFileAttributeView("posix")) { try { PosixFileAttributeView view = Files.getFileAttributeView(file, PosixFileAttributeView.class); - attributes.put(FILE_PERMISSIONS_ATTRIBUTE, PosixFilePermissions.toString(view.readAttributes().permissions())); + attributes. + put(FILE_PERMISSIONS_ATTRIBUTE, PosixFilePermissions.toString(view.readAttributes().permissions())); attributes.put(FILE_GROUP_ATTRIBUTE, view.readAttributes().group().getName()); } catch (Exception ignore) { } // allow other attributes if these fail @@ -359,8 +367,7 @@ public class GetFile extends AbstractProcessor { final long pollingMillis = context.getProperty(POLLING_INTERVAL).asTimePeriod(TimeUnit.MILLISECONDS); if ((queueLastUpdated.get() < System.currentTimeMillis() - pollingMillis) && listingLock.tryLock()) { try { - final Set<File> listing = performListing(directory, fileFilterRef.get(), - context.getProperty(RECURSE).asBoolean().booleanValue()); + final Set<File> listing = performListing(directory, fileFilterRef.get(), context.getProperty(RECURSE).asBoolean().booleanValue()); queueLock.lock(); try { @@ -418,7 +425,8 @@ public class GetFile extends AbstractProcessor { flowFile = session.create(); final long importStart = System.nanoTime(); - flowFile = session.importFrom(filePath, keepingSourceFile, flowFile); + flowFile = session. + importFrom(filePath, keepingSourceFile, flowFile); final long importNanos = System.nanoTime() - importStart; final long importMillis = TimeUnit.MILLISECONDS.convert(importNanos, TimeUnit.NANOSECONDS); http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/54818893/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFileTransfer.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFileTransfer.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFileTransfer.java index 1b2be26..0b06244 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFileTransfer.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFileTransfer.java @@ -59,8 +59,10 @@ import org.apache.nifi.util.StopWatch; */ public abstract class GetFileTransfer extends AbstractProcessor { - public static final Relationship REL_SUCCESS = new Relationship.Builder().name("success") - .description("All FlowFiles that are received are routed to success").build(); + public static final Relationship REL_SUCCESS = new Relationship.Builder() + .name("success") + .description("All FlowFiles that are received are routed to success") + .build(); private final Set<Relationship> relationships; public static final String FILE_LAST_MODIFY_TIME_ATTRIBUTE = "file.lastModifiedTime"; @@ -207,7 +209,8 @@ public abstract class GetFileTransfer extends AbstractProcessor { try { transfer.deleteFile(null, file.getFullPathFileName()); } catch (final IOException e) { - logger.error("Failed to remove remote file {} due to {}; deleting local copy", new Object[]{file.getFullPathFileName(), e}); + logger.error("Failed to remove remote file {} due to {}; deleting local copy", + new Object[]{file.getFullPathFileName(), e}); session.remove(flowFile); return; }
