Update most resources to use urlFromPieces

Only id in event_service and account_service have not been updated due
to the risk of it breaking the username/id. It will require further
testing to verify.

Use urlFromPieces wherever that is needed to insert a variable in the
URI. Don't use urlFromPieces when it is hardcoded values. This allow us
to control all resource URIs that is dynamically added and to sync with
the current recommanded method for `@odata.id`. The goal is to have a
common place to manage the url created from dbus-paths in order to
manage/update it easily when needed.

Tested:
RedfishValidtor Passed for all resource including the sensors with the
fragments.

Change-Id: I95cdfaaee58fc7f21c95f5944e1e5c813b3215f2
Signed-off-by: Willy Tu <wltu@google.com>
Signed-off-by: Ed Tanous <edtanous@google.com>
diff --git a/redfish-core/lib/pcie.hpp b/redfish-core/lib/pcie.hpp
index 77afd0a..5332a39 100644
--- a/redfish-core/lib/pcie.hpp
+++ b/redfish-core/lib/pcie.hpp
@@ -67,8 +67,8 @@
                 continue;
             }
             nlohmann::json::object_t pcieDevice;
-            pcieDevice["@odata.id"] =
-                "/redfish/v1/Systems/system/PCIeDevices/" + devName;
+            pcieDevice["@odata.id"] = crow::utility::urlFromPieces(
+                "redfish", "v1", "Systems", "system", "PCIeDevices", devName);
             pcieDeviceList.push_back(std::move(pcieDevice));
         }
         asyncResp->res.jsonValue[name + "@odata.count"] = pcieDeviceList.size();
@@ -242,13 +242,15 @@
             asyncResp->res.jsonValue["@odata.type"] =
                 "#PCIeDevice.v1_4_0.PCIeDevice";
             asyncResp->res.jsonValue["@odata.id"] =
-                "/redfish/v1/Systems/system/PCIeDevices/" + device;
+                crow::utility::urlFromPieces("redfish", "v1", "Systems",
+                                             "system", "PCIeDevices", device);
             asyncResp->res.jsonValue["Name"] = "PCIe Device";
             asyncResp->res.jsonValue["Id"] = device;
 
             asyncResp->res.jsonValue["PCIeFunctions"]["@odata.id"] =
-                "/redfish/v1/Systems/system/PCIeDevices/" + device +
-                "/PCIeFunctions";
+                crow::utility::urlFromPieces("redfish", "v1", "Systems",
+                                             "system", "PCIeDevices", device,
+                                             "PCIeFunctions");
         };
         std::string escapedPath = std::string(pciePath) + "/" + device;
         dbus::utility::escapePathForDbus(escapedPath);
@@ -277,9 +279,9 @@
 
         asyncResp->res.jsonValue["@odata.type"] =
             "#PCIeFunctionCollection.PCIeFunctionCollection";
-        asyncResp->res.jsonValue["@odata.id"] =
-            "/redfish/v1/Systems/system/PCIeDevices/" + device +
-            "/PCIeFunctions";
+        asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces(
+            "redfish", "v1", "Systems", "system", "PCIeDevices", device,
+            "PCIeFunctions");
         asyncResp->res.jsonValue["Name"] = "PCIe Function Collection";
         asyncResp->res.jsonValue["Description"] =
             "Collection of PCIe Functions for PCIe Device " + device;
@@ -330,9 +332,9 @@
                     continue;
                 }
                 nlohmann::json::object_t pcieFunction;
-                pcieFunction["@odata.id"] =
-                    "/redfish/v1/Systems/system/PCIeDevices/" + device +
-                    "/PCIeFunctions/" + std::to_string(functionNum);
+                pcieFunction["@odata.id"] = crow::utility::urlFromPieces(
+                    "redfish", "v1", "Systems", "system", "PCIeDevices", device,
+                    "PCIeFunctions", std::to_string(functionNum));
                 pcieFunctionList.push_back(std::move(pcieFunction));
             }
             asyncResp->res.jsonValue["Members@odata.count"] =
@@ -406,13 +408,15 @@
             asyncResp->res.jsonValue["@odata.type"] =
                 "#PCIeFunction.v1_2_0.PCIeFunction";
             asyncResp->res.jsonValue["@odata.id"] =
-                "/redfish/v1/Systems/system/PCIeDevices/" + device +
-                "/PCIeFunctions/" + function;
+                crow::utility::urlFromPieces("redfish", "v1", "Systems",
+                                             "system", "PCIeDevices", device,
+                                             "PCIeFunctions", function);
             asyncResp->res.jsonValue["Name"] = "PCIe Function";
             asyncResp->res.jsonValue["Id"] = function;
             asyncResp->res.jsonValue["FunctionId"] = std::stoi(function);
             asyncResp->res.jsonValue["Links"]["PCIeDevice"]["@odata.id"] =
-                "/redfish/v1/Systems/system/PCIeDevices/" + device;
+                crow::utility::urlFromPieces("redfish", "v1", "Systems",
+                                             "system", "PCIeDevices", device);
 
             for (const auto& property : pcieDevProperties)
             {