martinzink commented on a change in pull request #1188: URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r727100066
########## File path: extensions/standard-processors/processors/DefragTextFlowFiles.h ########## @@ -0,0 +1,121 @@ +/** + * 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. + */ + +#pragma once + +#include <regex> +#include <memory> +#include <string> +#include <set> + +#include "core/Processor.h" +#include "utils/FlowFileStore.h" +#include "utils/Enum.h" +#include "serialization/PayloadSerializer.h" + + +namespace org::apache::nifi::minifi::processors { + +class DefragTextFlowFiles : public core::Processor { + public: + explicit DefragTextFlowFiles(const std::string& name, const utils::Identifier& uuid = {}) + : Processor(name, uuid) { + logger_ = logging::LoggerFactory<DefragTextFlowFiles>::getLogger(); + } + EXTENSIONAPI static core::Relationship Self; + EXTENSIONAPI static core::Relationship Success; + EXTENSIONAPI static core::Relationship Original; + EXTENSIONAPI static core::Relationship Failure; + + EXTENSIONAPI static core::Property Pattern; + EXTENSIONAPI static core::Property PatternLoc; + EXTENSIONAPI static core::Property MaxBufferAge; + EXTENSIONAPI static core::Property MaxBufferSize; + + void initialize() override; + void onSchedule(core::ProcessContext* context, core::ProcessSessionFactory* sessionFactory) override; + void onTrigger(core::ProcessContext* context, core::ProcessSession* session) override; + void restore(const std::shared_ptr<core::FlowFile>& flowFile) override; + std::set<std::shared_ptr<core::Connectable>> getOutGoingConnections(const std::string &relationship) const override; + + SMART_ENUM(PatternLocation, + (END_OF_MESSAGE, "End of Message"), + (START_OF_MESSAGE, "Start of Message") + ) + + class LastPatternFinder : public InputStreamCallback { + public: + LastPatternFinder(const std::regex& pattern, PatternLocation pattern_location) : pattern_(pattern), pattern_location_(pattern_location) {} + ~LastPatternFinder() override = default; + int64_t process(const std::shared_ptr<io::BaseStream>& stream) override; + + bool foundPattern() const { return last_pattern_location.has_value(); } + const std::optional<size_t>& getLastPatternPosition() const { return last_pattern_location; } + + protected: + void searchContent(const std::string& content); + const std::regex& pattern_; + PatternLocation pattern_location_; + std::optional<size_t> last_pattern_location; + }; Review comment: Valid point :+1: , moved it to cpp for testing splitFlowFileAtLastPattern we would need flowfiles, processsession and other bells and whistles so it wouldnt be that different than the other tests using the TestController so I just deleted these two. (The others should provide enough coverage imho) https://github.com/apache/nifi-minifi-cpp/pull/1188/commits/2c5fc511148d193c40c0ed9aa6ba3ec51d8ac667 -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
