Add Json Config support for entity to DBus string

The entity map comprises both entity types and their corresponding
names, essential for generating unique D-Bus paths for each entity.
However, challenges arise due to variations in path generation across
companies, often dictated by differing entity types. To address this,
enabling configurability of EntityID becomes imperative, empowering
communities to tailor configurations to their specific use cases.

Testing:
Unit tests passed

Change-Id: I3981fde64bd00940caa5067a9472fd948e74cbf0
Signed-off-by: Kamalkumar Patel <kamalkumar.patel@ibm.com>
diff --git a/host-bmc/utils.cpp b/host-bmc/utils.cpp
index f025ada..a178d48 100644
--- a/host-bmc/utils.cpp
+++ b/host-bmc/utils.cpp
@@ -4,6 +4,7 @@
 
 #include "utils.hpp"
 
+#include <cstdlib>
 #include <iostream>
 
 namespace pldm
@@ -58,7 +59,8 @@
 void addObjectPathEntityAssociations(const EntityAssociations& entityAssoc,
                                      pldm_entity_node* entity,
                                      const fs::path& path,
-                                     ObjectPathMaps& objPathMap)
+                                     ObjectPathMaps& objPathMap,
+                                     EntityMaps entityMaps)
 {
     if (entity == nullptr)
     {
@@ -120,7 +122,7 @@
             for (size_t i = 1; i < ev.size(); i++)
             {
                 addObjectPathEntityAssociations(entityAssoc, ev[i], p,
-                                                objPathMap);
+                                                objPathMap, entityMaps);
             }
             found = true;
         }
@@ -131,7 +133,6 @@
         std::string dbusPath =
             path / fs::path{entityName +
                             std::to_string(node_entity.entity_instance_num)};
-
         try
         {
             pldm::utils::DBusHandler().getService(dbusPath.c_str(), nullptr);
@@ -145,7 +146,7 @@
 
 void updateEntityAssociation(const EntityAssociations& entityAssoc,
                              pldm_entity_association_tree* entityTree,
-                             ObjectPathMaps& objPathMap)
+                             ObjectPathMaps& objPathMap, EntityMaps entityMaps)
 {
     std::vector<pldm_entity_node*> parentsEntity =
         getParentEntites(entityAssoc);
@@ -200,9 +201,45 @@
             paths.pop_back();
         }
 
-        addObjectPathEntityAssociations(entityAssoc, entity, path, objPathMap);
+        addObjectPathEntityAssociations(entityAssoc, entity, path, objPathMap,
+                                        entityMaps);
     }
 }
+
+EntityMaps parseEntityMap(const fs::path& filePath)
+{
+    const Json emptyJson{};
+    EntityMaps entityMaps{};
+    std::ifstream jsonFile(filePath);
+    auto data = Json::parse(jsonFile);
+    if (data.is_discarded())
+    {
+        error("Failed parsing of EntityMap data from json file: '{JSON_PATH}'",
+              "JSON_PATH", filePath);
+        return entityMaps;
+    }
+    auto entities = data.value("EntityTypeToDbusStringMap", emptyJson);
+    char* err;
+    try
+    {
+        std::ranges::transform(entities.items(),
+                               std::inserter(entityMaps, entityMaps.begin()),
+                               [&err](const auto& element) {
+            std::string key = static_cast<EntityName>(element.key());
+            return std::make_pair(strtol(key.c_str(), &err, 10),
+                                  static_cast<EntityName>(element.value()));
+        });
+    }
+    catch (const std::exception& e)
+    {
+        error(
+            "Failed to create entity to DBus string mapping {ERROR} and Conversion failure is '{ERR}'",
+            "ERROR", e, "ERR", err);
+    }
+
+    return entityMaps;
+}
+
 } // namespace utils
 } // namespace hostbmc
 } // namespace pldm