entity-manager: addObjectRuntimeValidateJson

extract function addObjectRuntimeValidateJson from addObject function.

Since the runtime configuration validation feature for "AddObject" API
looks to be broken since some time, extract it into it's own function to
separate the `AddObject` feature from schema handling and enhance
readability of the default code path.

Tested: next patches in series

Change-Id: Ief9a1c90598221450b5bceffd6e85ee7e1feca68
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/src/entity_manager/dbus_interface.cpp b/src/entity_manager/dbus_interface.cpp
index c6b00f0..c8f55a6 100644
--- a/src/entity_manager/dbus_interface.cpp
+++ b/src/entity_manager/dbus_interface.cpp
@@ -233,6 +233,38 @@
     tryIfaceInitialize(iface);
 }
 
+// @brief: throws on error
+static void addObjectRuntimeValidateJson(const nlohmann::json& newData,
+                                         const std::string* type)
+{
+    if constexpr (!ENABLE_RUNTIME_VALIDATE_JSON)
+    {
+        return;
+    }
+
+    const std::filesystem::path schemaPath =
+        std::filesystem::path(schemaDirectory) / "exposes_record.json";
+
+    std::ifstream schemaFile{schemaPath};
+
+    if (!schemaFile.good())
+    {
+        throw std::invalid_argument("No schema avaliable, cannot validate.");
+    }
+    nlohmann::json schema =
+        nlohmann::json::parse(schemaFile, nullptr, false, true);
+    if (schema.is_discarded())
+    {
+        lg2::error("Schema not legal: {TYPE}.json", "TYPE", *type);
+        throw DBusInternalError();
+    }
+
+    if (!validateJson(schema, newData))
+    {
+        throw std::invalid_argument("Data does not match schema");
+    }
+}
+
 void EMDBusInterface::addObject(
     const std::flat_map<std::string, JsonVariantType, std::less<>>& data,
     nlohmann::json& systemConfiguration, const std::string& jsonPointerPath,
@@ -296,31 +328,7 @@
         lastIndex++;
     }
 
-    if constexpr (ENABLE_RUNTIME_VALIDATE_JSON)
-    {
-        const std::filesystem::path schemaPath =
-            std::filesystem::path(schemaDirectory) / "exposes_record.json";
-
-        std::ifstream schemaFile{schemaPath};
-
-        if (!schemaFile.good())
-        {
-            throw std::invalid_argument(
-                "No schema avaliable, cannot validate.");
-        }
-        nlohmann::json schema =
-            nlohmann::json::parse(schemaFile, nullptr, false, true);
-        if (schema.is_discarded())
-        {
-            lg2::error("Schema not legal: {TYPE}.json", "TYPE", *type);
-            throw DBusInternalError();
-        }
-
-        if (!validateJson(schema, newData))
-        {
-            throw std::invalid_argument("Data does not match schema");
-        }
-    }
+    addObjectRuntimeValidateJson(newData, type);
 
     if (foundNull)
     {