chassis: refactor chassis property to prepare for future support

Move `LocationCode` and `UUID` to a method to cleanup the the main
Chassis handler.

Tested:
RedfishValidator Passed

```
*** /redfish/v1/Chassis/chassis0
INFO - 	 Type (#Chassis.v1_14_0.Chassis), GET SUCCESS (time: 0.405691)
WARNING - Thermal: The given property is deprecated by revision: This link has been deprecated in favor of the ThermalSubsystem link property.
WARNING - Power: The given property is deprecated by revision: This link has been deprecated in favor of the PowerSubsystem link property.
INFO - 	 PASS
INFO -
...

*** /redfish/v1/Chassis/chassis1
INFO - 	 Type (#Chassis.v1_14_0.Chassis), GET SUCCESS (time: 0.406565)
WARNING - Thermal: The given property is deprecated by revision: This link has been deprecated in favor of the ThermalSubsystem link property.
WARNING - Power: The given property is deprecated by revision: This link has been deprecated in favor of the PowerSubsystem link property.
INFO - 	 PASS
INFO -
*** /redfish/v1/Chassis/chassis1/Sensors
INFO - 	 Type (#SensorCollection.SensorCollection), GET SUCCESS (time: 0.358176)
INFO - 	 PASS
INFO -
*** /redfish/v1/Chassis/chassis1/ResetActionInfo
INFO - 	 Type (#ActionInfo.v1_1_2.ActionInfo), GET SUCCESS (time: 0.369962)
INFO - 	 PASS
...
```

Example,
```
$ curl  -u root:0penBmc -X GET http://localhost:3967/redfish/v1/Chassis/chassis1
{
  "@odata.id": "/redfish/v1/Chassis/chassis1",
  "@odata.type": "#Chassis.v1_14_0.Chassis",
  "Actions": {
    "#Chassis.Reset": {
      "@Redfish.ActionInfo": "/redfish/v1/Chassis/chassis1/ResetActionInfo",
      "target": "/redfish/v1/Chassis/chassis1/Actions/Chassis.Reset"
    }
  },
  "ChassisType": "RackMount",
  "Id": "chassis1",
  "Links": {
    "ComputerSystems": [
      {
        "@odata.id": "/redfish/v1/Systems/system"
      }
    ],
    "ManagedBy": [
      {
        "@odata.id": "/redfish/v1/Managers/bmc"
      }
    ]
  },
  "Location": {
    "PartLocation": {
      "ServiceLabel": "PE0"
    }
  },
  "Manufacturer": "manufacturer1",
  "Model": "model1",
  "Name": "chassis1",
  "PCIeDevices": {
    "@odata.id": "/redfish/v1/Systems/system/PCIeDevices"
  },
  "Power": {
    "@odata.id": "/redfish/v1/Chassis/chassis1/Power"
  },
...
}
```

Change-Id: I7a26530d3d718ce8fbf4182ee565f9fe9d94c5b5
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp
index b0c6291..c625b4b 100644
--- a/redfish-core/lib/chassis.hpp
+++ b/redfish-core/lib/chassis.hpp
@@ -179,6 +179,65 @@
             });
 }
 
+inline void
+    getChassisLocationCode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+                           const std::string& connectionName,
+                           const std::string& path)
+{
+    crow::connections::systemBus->async_method_call(
+        [asyncResp](const boost::system::error_code ec,
+                    const std::variant<std::string>& property) {
+            if (ec)
+            {
+                BMCWEB_LOG_DEBUG << "DBUS response error for "
+                                    "Location";
+                messages::internalError(asyncResp->res);
+                return;
+            }
+
+            const std::string* value = std::get_if<std::string>(&property);
+            if (value == nullptr)
+            {
+                BMCWEB_LOG_DEBUG << "Null value returned "
+                                    "for locaton code";
+                messages::internalError(asyncResp->res);
+                return;
+            }
+            asyncResp->res
+                .jsonValue["Location"]["PartLocation"]["ServiceLabel"] = *value;
+        },
+        connectionName, path, "org.freedesktop.DBus.Properties", "Get",
+        "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode");
+}
+
+inline void getChassisUUID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+                           const std::string& connectionName,
+                           const std::string& path)
+{
+    crow::connections::systemBus->async_method_call(
+        [asyncResp](const boost::system::error_code ec,
+                    const std::variant<std::string>& chassisUUID) {
+            if (ec)
+            {
+                BMCWEB_LOG_DEBUG << "DBUS response error for "
+                                    "UUID";
+                messages::internalError(asyncResp->res);
+                return;
+            }
+            const std::string* value = std::get_if<std::string>(&chassisUUID);
+            if (value == nullptr)
+            {
+                BMCWEB_LOG_DEBUG << "Null value returned "
+                                    "for UUID";
+                messages::internalError(asyncResp->res);
+                return;
+            }
+            asyncResp->res.jsonValue["UUID"] = *value;
+        },
+        connectionName, path, "org.freedesktop.DBus.Properties", "Get",
+        "xyz.openbmc_project.Common.UUID", "UUID");
+}
+
 /**
  * Chassis override class for delivering Chassis Schema
  * Functions triggers appropriate requests on DBus
@@ -330,44 +389,6 @@
                             }
                         }
 
-                        const std::string locationInterface =
-                            "xyz.openbmc_project.Inventory.Decorator."
-                            "LocationCode";
-                        if (std::find(interfaces2.begin(), interfaces2.end(),
-                                      locationInterface) != interfaces2.end())
-                        {
-                            crow::connections::systemBus->async_method_call(
-                                [asyncResp, chassisId(std::string(chassisId))](
-                                    const boost::system::error_code ec,
-                                    const std::variant<std::string>& property) {
-                                    if (ec)
-                                    {
-                                        BMCWEB_LOG_DEBUG
-                                            << "DBUS response error for "
-                                               "Location";
-                                        messages::internalError(asyncResp->res);
-                                        return;
-                                    }
-
-                                    const std::string* value =
-                                        std::get_if<std::string>(&property);
-                                    if (value == nullptr)
-                                    {
-                                        BMCWEB_LOG_DEBUG
-                                            << "Null value returned "
-                                               "for locaton code";
-                                        messages::internalError(asyncResp->res);
-                                        return;
-                                    }
-                                    asyncResp->res
-                                        .jsonValue["Location"]["PartLocation"]
-                                                  ["ServiceLabel"] = *value;
-                                },
-                                connectionName, path,
-                                "org.freedesktop.DBus.Properties", "Get",
-                                locationInterface, "LocationCode");
-                        }
-
                         crow::connections::systemBus->async_method_call(
                             [asyncResp, chassisId(std::string(chassisId))](
                                 const boost::system::error_code /*ec2*/,
@@ -430,39 +451,19 @@
                             "org.freedesktop.DBus.Properties", "GetAll",
                             "xyz.openbmc_project.Inventory.Decorator.Asset");
 
-                        // Chassis UUID
-                        const std::string uuidInterface =
-                            "xyz.openbmc_project.Common.UUID";
-                        if (std::find(interfaces2.begin(), interfaces2.end(),
-                                      uuidInterface) != interfaces2.end())
+                        for (const auto& interface : interfaces2)
                         {
-                            crow::connections::systemBus->async_method_call(
-                                [asyncResp](const boost::system::error_code ec,
-                                            const std::variant<std::string>&
-                                                chassisUUID) {
-                                    if (ec)
-                                    {
-                                        BMCWEB_LOG_DEBUG
-                                            << "DBUS response error for "
-                                               "UUID";
-                                        messages::internalError(asyncResp->res);
-                                        return;
-                                    }
-                                    const std::string* value =
-                                        std::get_if<std::string>(&chassisUUID);
-                                    if (value == nullptr)
-                                    {
-                                        BMCWEB_LOG_DEBUG
-                                            << "Null value returned "
-                                               "for UUID";
-                                        messages::internalError(asyncResp->res);
-                                        return;
-                                    }
-                                    asyncResp->res.jsonValue["UUID"] = *value;
-                                },
-                                connectionName, path,
-                                "org.freedesktop.DBus.Properties", "Get",
-                                uuidInterface, "UUID");
+                            if (interface == "xyz.openbmc_project.Common.UUID")
+                            {
+                                getChassisUUID(asyncResp, connectionName, path);
+                            }
+                            else if (interface ==
+                                     "xyz.openbmc_project.Inventory."
+                                     "Decorator.LocationCode")
+                            {
+                                getChassisLocationCode(asyncResp,
+                                                       connectionName, path);
+                            }
                         }
 
                         return;