martinzink commented on code in PR #2221:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2221#discussion_r3801534131


##########
extensions/standard-processors/processors/JoinEnrichmentAttributes.cpp:
##########
@@ -0,0 +1,160 @@
+/**
+ * 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 "JoinEnrichmentAttributes.h"
+
+#include "core/Resource.h"
+#include "minifi-cpp/core/ProcessSession.h"
+#include "utils/AttributeErrors.h"
+#include "utils/EnrichmentUtils.h"
+#include "utils/ProcessorConfigUtils.h"
+
+namespace org::apache::nifi::minifi::standard {
+const core::Relationship JoinEnrichmentAttributes::Self("__self__", "Marks the 
FlowFile to be owned by this processor");
+
+void JoinEnrichmentAttributes::initialize() {
+  setSupportedProperties(Properties);
+  setSupportedRelationships(Relationships);
+  ProcessorImpl::initialize();
+}
+
+void JoinEnrichmentAttributes::onSchedule(core::ProcessContext& context, 
core::ProcessSessionFactory& session_factory) {
+  using namespace std::literals::chrono_literals;
+  if (const auto timeout = utils::parseOptionalDurationProperty(context, 
TimeoutProperty); timeout && *timeout > 0ms) {
+    time_out_tracker_.emplace(*timeout);
+  }
+  max_batch_size_ = utils::parseOptionalU64Property(context, MaxBatchSize);
+  if (max_batch_size_ && *max_batch_size_ == 0) {
+    throw Exception(PROCESSOR_EXCEPTION, "Max Batch Size property is invalid");
+  }
+  ProcessorImpl::onSchedule(context, session_factory);
+}
+
+namespace {
+bool checkRequiredAttributes(const core::FlowFile& flow_file) {
+  return flow_file.getAttribute(ENRICHMENT_ROLE).has_value() && 
flow_file.getAttribute(ENRICHMENT_GROUP_ID).has_value();
+}
+}  // namespace
+
+void JoinEnrichmentAttributes::join(const std::shared_ptr<core::FlowFile>& 
original, const std::shared_ptr<core::FlowFile>& enrichment,
+    core::ProcessSession& session) const {
+  const auto cloned = session.clone(*original);
+  for (const auto& [k, v] : enrichment->getAttributes()) {
+    if (k != ENRICHMENT_ROLE) {
+      cloned->setAttribute(k, v);
+    }
+  }
+  cloned->setAttribute(ENRICHMENT_ROLE, "JOINED");
+  if (!std::ranges::contains(session_flow_files_, original->getUUID())) {
+    session.add(original);

Review Comment:
   We only want to add these to the session if they are not from this session. 
(ProcessSession asserts that a flowfile is only in one category (added, 
deleted, modified/updaetd) and every transferred flowfile is in session



-- 
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]

Reply via email to