adamdebreceni commented on a change in pull request #1057:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1057#discussion_r634552401



##########
File path: libminifi/src/c2/protocols/RESTProtocol.cpp
##########
@@ -318,133 +178,7 @@ bool RESTProtocol::containsPayload(const C2Payload &o) {
   return false;
 }
 
-rapidjson::Value RESTProtocol::serializeConnectionQueues(const C2Payload 
&payload, std::string &label, rapidjson::Document::AllocatorType &alloc) {
-  rapidjson::Value json_payload(payload.isContainer() ? rapidjson::kArrayType 
: rapidjson::kObjectType);
-
-  C2Payload adjusted(payload.getOperation(), payload.getIdentifier(), 
payload.isRaw());
-
-  auto name = payload.getLabel();
-  std::string uuid;
-  C2ContentResponse updatedContent(payload.getOperation());
-  for (const C2ContentResponse &content : payload.getContent()) {
-    for (const auto& op_arg : content.operation_arguments) {
-      if (op_arg.first == "uuid") {
-        uuid = op_arg.second.to_string();
-      }
-      updatedContent.operation_arguments.insert(op_arg);
-    }
-  }
-  updatedContent.name = uuid;
-  adjusted.setLabel(uuid);
-  adjusted.setIdentifier(uuid);
-  c2::AnnotatedValue nd;
-  // name should be what was previously the TLN ( top level node )
-  nd = name;
-  updatedContent.operation_arguments.insert(std::make_pair("name", nd));
-  // the rvalue reference is an unfortunate side effect of the underlying API 
decision.
-  adjusted.addContent(std::move(updatedContent), true);
-  mergePayloadContent(json_payload, adjusted, alloc);
-  label = uuid;
-  return json_payload;
-}
-
-rapidjson::Value RESTProtocol::serializeJsonPayload(const C2Payload &payload, 
rapidjson::Document::AllocatorType &alloc) {
-  // get the name from the content
-  rapidjson::Value json_payload(payload.isContainer() ? rapidjson::kArrayType 
: rapidjson::kObjectType);
-
-  std::vector<ValueObject> children;
-
-  bool isQueue = payload.getLabel() == "queues";
-
-  for (const auto &nested_payload : payload.getNestedPayloads()) {
-    std::string label = nested_payload.getLabel();
-    rapidjson::Value* child_payload = new rapidjson::Value(isQueue ? 
serializeConnectionQueues(nested_payload, label, alloc) : 
serializeJsonPayload(nested_payload, alloc));
-
-    if (nested_payload.isCollapsible()) {
-      bool combine = false;
-      for (auto &subordinate : children) {
-        if (subordinate.name == label) {
-          subordinate.values.push_back(child_payload);
-          combine = true;
-          break;
-        }
-      }
-      if (!combine) {
-        ValueObject obj;
-        obj.name = label;
-        obj.values.push_back(child_payload);
-        children.push_back(obj);
-      }
-    } else {
-      ValueObject obj;
-      obj.name = label;
-      obj.values.push_back(child_payload);
-      children.push_back(obj);
-    }
-  }
-
-  for (auto child_vector : children) {
-    rapidjson::Value children_json;
-    rapidjson::Value newMemberKey = getStringValue(child_vector.name, alloc);
-    if (child_vector.values.size() > 1) {
-      children_json.SetArray();
-      for (auto child : child_vector.values) {
-        if (json_payload.IsArray())
-          json_payload.PushBack(child->Move(), alloc);
-        else
-          children_json.PushBack(child->Move(), alloc);
-      }
-      if (!json_payload.IsArray())
-        json_payload.AddMember(newMemberKey, children_json, alloc);
-    } else if (child_vector.values.size() == 1) {
-      rapidjson::Value* first = child_vector.values.front();
-      if (first->IsObject() && first->HasMember(newMemberKey)) {
-        if (json_payload.IsArray())
-          json_payload.PushBack((*first)[newMemberKey].Move(), alloc);
-        else
-          json_payload.AddMember(newMemberKey, (*first)[newMemberKey].Move(), 
alloc);
-      } else {
-        if (json_payload.IsArray()) {
-          json_payload.PushBack(first->Move(), alloc);
-        } else {
-          json_payload.AddMember(newMemberKey, first->Move(), alloc);
-        }
-      }
-    }
-    for (rapidjson::Value* child : child_vector.values)
-      delete child;
-  }
-
-  mergePayloadContent(json_payload, payload, alloc);
-  return json_payload;
-}
-
-std::string RESTProtocol::getOperation(const C2Payload &payload) {
-  switch (payload.getOperation()) {
-    case Operation::ACKNOWLEDGE:
-      return "acknowledge";
-    case Operation::HEARTBEAT:
-      return "heartbeat";
-    case Operation::RESTART:
-      return "restart";
-    case Operation::DESCRIBE:
-      return "describe";
-    case Operation::STOP:
-      return "stop";
-    case Operation::START:
-      return "start";
-    case Operation::UPDATE:
-      return "update";
-    case Operation::PAUSE:
-      return "pause";
-    case Operation::RESUME:
-      return "resume";
-    default:
-      return "heartbeat";
-  }
-}
-
-Operation RESTProtocol::stringToOperation(const std::string str) {
+Operation RESTProtocol::stringToOperation(const std::string& str) {

Review comment:
       made Operation enum into a smart enum, so that string <-> enum 
conversions are centralized 




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

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


Reply via email to