adamdebreceni commented on a change in pull request #1168: URL: https://github.com/apache/nifi-minifi-cpp/pull/1168#discussion_r714653120
########## File path: extensions/standard-processors/processors/RouteText.cpp ########## @@ -0,0 +1,476 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "RouteText.h" + +#include <map> +#include <vector> +#include <utility> +#include <algorithm> +#include <set> + +#ifdef __APPLE__ +#include <experimental/functional> +template<typename It, typename Hash, typename Eq> +using boyer_moore_searcher = std::experimental::boyer_moore_searcher<It, Hash, Eq>; +#else +#include <functional> +template<typename It, typename Hash, typename Eq> +using boyer_moore_searcher = std::boyer_moore_searcher<It, Hash, Eq>; +#endif + +#include "logging/LoggerConfiguration.h" +#include "utils/ProcessorConfigUtils.h" +#include "utils/OptionalUtils.h" +#include "range/v3/view/transform.hpp" +#include "range/v3/range/conversion.hpp" +#include "range/v3/view/tail.hpp" +#include "range/v3/view/join.hpp" +#include "range/v3/view/cache1.hpp" +#include "core/Resource.h" + +namespace org::apache::nifi::minifi::processors { + +const core::Property RouteText::RoutingStrategy( + core::PropertyBuilder::createProperty("Routing Strategy") + ->withDescription("Specifies how to determine which Relationship(s) to use when evaluating the segments " + "of incoming text against the 'Matching Strategy' and user-defined properties. " + "'Dynamic Routing' routes to all the matching dynamic relationships (or 'unmatched' if none matches). " + "'Route On All' routes to 'matched' iff all dynamic relationships match. " + "'Route On Any' routes to 'matched' iff any of the dynamic relationships match. ") + ->isRequired(true) + ->withDefaultValue<std::string>(toString(Routing::DYNAMIC)) + ->withAllowableValues<std::string>(Routing::values()) + ->build()); + +const core::Property RouteText::MatchingStrategy( + core::PropertyBuilder::createProperty("Matching Strategy") + ->withDescription("Specifies how to evaluate each segment of incoming text against the user-defined properties.") + ->isRequired(true) + ->withAllowableValues<std::string>(Matching::values()) + ->build()); + +const core::Property RouteText::TrimWhitespace( + core::PropertyBuilder::createProperty("Ignore Leading/Trailing Whitespace") + ->withDescription("Indicates whether or not the whitespace at the beginning and end should be ignored when evaluating a segment.") + ->isRequired(true) + ->withDefaultValue<bool>(true) + ->build()); + +const core::Property RouteText::IgnoreCase( + core::PropertyBuilder::createProperty("Ignore Case") + ->withDescription("If true, capitalization will not be taken into account when comparing values. E.g., matching against 'HELLO' or 'hello' will have the same result. " + "This property is ignored if the 'Matching Strategy' is set to 'Satisfies Expression'.") + ->isRequired(true) + ->withDefaultValue<bool>(false) + ->build()); + +const core::Property RouteText::GroupingRegex( + core::PropertyBuilder::createProperty("Grouping Regular Expression") + ->withDescription("Specifies a Regular Expression to evaluate against each segment to determine which Group it should be placed in. " + "The Regular Expression must have at least one Capturing Group that defines the segment's Group. If multiple Capturing Groups " + "exist in the Regular Expression, the values from all Capturing Groups will be joined together with \", \". Two segments will not be " + "placed into the same FlowFile unless they both have the same value for the Group (or neither matches the Regular Expression). " + "For example, to group together all lines in a CSV File by the first column, we can set this value to \"(.*?),.*\" (and use \"Per Line\" segmentation). " + "Two segments that have the same Group but different Relationships will never be placed into the same FlowFile.") + ->build()); + +const core::Property RouteText::GroupingFallbackValue( + core::PropertyBuilder::createProperty("Grouping Fallback Value") + ->withDescription("If the 'Grouping Regular Expression' is specified and the matching fails, this value will be considered the group of the segment.") + ->withDefaultValue<std::string>("") + ->build()); + +const core::Property RouteText::SegmentationStrategy( + core::PropertyBuilder::createProperty("Segmentation Strategy") + ->withDescription("Specifies what portions of the FlowFile content constitutes a single segment to be processed.") + ->isRequired(true) + ->withDefaultValue<std::string>(toString(Segmentation::PER_LINE)) + ->withAllowableValues<std::string>(Segmentation::values()) + ->build()); + +const core::Relationship RouteText::Original("original", "The original input file will be routed to this destination"); + +const core::Relationship RouteText::Unmatched("unmatched", "Segments that do not satisfy the required user-defined rules will be routed to this Relationship"); + +const core::Relationship RouteText::Matched("matched", "Segments that satisfy the required user-defined rules will be routed to this Relationship"); + +RouteText::RouteText(const std::string& name, const utils::Identifier& uuid) + : core::Processor(name, uuid), logger_(logging::LoggerFactory<RouteText>::getLogger()) {} + +void RouteText::initialize() { + setSupportedProperties({ + RoutingStrategy, + MatchingStrategy, + TrimWhitespace, + IgnoreCase, + GroupingRegex, + GroupingFallbackValue, + SegmentationStrategy + }); + setSupportedRelationships({Original, Unmatched, Matched}); +} + +static std::regex to_regex(const std::string& str) { Review comment: done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org