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


##########
extensions/windows-event-log/ConsumeWindowsEventLog.cpp:
##########
@@ -696,32 +696,30 @@ void 
ConsumeWindowsEventLog::putEventRenderFlowFileToSession(const EventRender&
   };
 
   if (output_.xml) {
-    auto flowFile = session.create();
     logger_->log_trace("Writing rendered XML to a flow file");
-
-    for (const auto &fieldMapping : eventRender.matched_fields) {
-      if (!fieldMapping.second.empty()) {
-        session.putAttribute(flowFile, fieldMapping.first, 
fieldMapping.second);
-      }
-    }
-
-    commitFlowFile(flowFile, eventRender.xml, "application/xml");
+    auto flow_file = session.create();
+    addMatchedFieldsAsAttributes(eventRender, session, flow_file);
+    commitFlowFile(flow_file, eventRender.xml, "application/xml");
   }
 
   if (output_.plaintext) {
     logger_->log_trace("Writing rendered plain text to a flow file");
     commitFlowFile(session.create(), eventRender.plaintext, "text/plain");
   }
 
-  if (output_.json.type == JSONType::Raw) {
-    logger_->log_trace("Writing rendered raw JSON to a flow file");
-    commitFlowFile(session.create(), eventRender.json, "application/json");
-  } else if (output_.json.type == JSONType::Simple) {
-    logger_->log_trace("Writing rendered simple JSON to a flow file");
-    commitFlowFile(session.create(), eventRender.json, "application/json");
-  } else if (output_.json.type == JSONType::Flattened) {
-    logger_->log_trace("Writing rendered flattened JSON to a flow file");
-    commitFlowFile(session.create(), eventRender.json, "application/json");
+  if (output_.json.type != JSONType::None) {
+    logger_->log_trace("Writing rendered %s JSON to a flow file", 
output_.json.type.toString());
+    auto flow_file = session.create();
+    addMatchedFieldsAsAttributes(eventRender, session, flow_file);

Review Comment:
   Sry for the late reply.
   I've added this for all cases(and a test for plaintext aswell) in 
https://github.com/apache/nifi-minifi-cpp/pull/1482/commits/76db15357c1f2efd8cf2fa1cec2a7ed370eb0bf7



##########
extensions/windows-event-log/tests/ConsumeWindowsEventLogTests.cpp:
##########
@@ -236,6 +236,14 @@ TEST_CASE("ConsumeWindowsEventLog extracts some attributes 
by default", "[onTrig
   auto logger_processor = test_plan->addProcessor("LogAttribute", "logger", 
Success, true);
   test_plan->setProperty(logger_processor, 
LogAttribute::FlowFilesToLog.getName(), "0");
 
+  SECTION("XML output") {
+    CHECK(test_plan->setProperty(cwel_processor, ConsumeWindowsEventLog 
::OutputFormat.getName(), "XML"));
+  }
+
+  SECTION("Json output") {
+    CHECK(test_plan->setProperty(cwel_processor, ConsumeWindowsEventLog 
::OutputFormat.getName(), "JSON"));
+  }

Review Comment:
   Sorry for the late reply.
   Yes there are some tests that cover those cases in 
[MetadataWalkerTests](https://github.com/apache/nifi-minifi-cpp/blob/main/extensions/windows-event-log/tests/MetadataWalkerTests.cpp)



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