You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2021/10/06 15:31:51 UTC

[GitHub] [nifi-minifi-cpp] martinzink commented on a change in pull request #1188: MINIFICPP-1651: Added DefragTextFlowFiles processor

martinzink commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r723399621



##########
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:
       I exposed it so it can be unit tested (extensions/standard-processors/tests/unit/DefragTextFlowFilesTests.cpp) TEST_CASE("FindLastRegexTest1", "[findlastregextest]")
   TEST_CASE("FindLastRegexTest2", "[findlastregextest2]")




-- 
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-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org