Make propertyValueNotInList typesafe

The error codes for this function accept a string_view, which has caused
a number of cases of users of this function to call dump() to_string()
and all manner of other conversions.  Considering that dump() is
something that's difficult to call correctly, and overly wordy, it would
be ideal if the message code just handled that for us.

Therefore, this commit changes the prototype to include a nlohmann::json
object as an argument instead of string_view, then audits the codebase
for all uses, and moves them to a more normalized usage, which allows
the calling code to call "dump" for them.

Tested: PATCH /redfish/v1/SessionService {"SessionTimeout": 1}

Returns the PropertyValueNotInList error as it did before.

Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: If62909072db1f067ad1f8aa590bb716c84181219
diff --git a/redfish-core/include/error_messages.hpp b/redfish-core/include/error_messages.hpp
index b843970..99e9ae8 100644
--- a/redfish-core/include/error_messages.hpp
+++ b/redfish-core/include/error_messages.hpp
@@ -263,12 +263,11 @@
  * @param[in] arg2 Parameter of message that will replace %2 in its body.
  *
  * @returns Message PropertyValueNotInList formatted to JSON */
-nlohmann::json propertyValueNotInList(std::string_view arg1,
+nlohmann::json propertyValueNotInList(const nlohmann::json& arg1,
                                       std::string_view arg2);
 
-void propertyValueNotInList(crow::Response& res, std::string_view arg1,
+void propertyValueNotInList(crow::Response& res, const nlohmann::json& arg1,
                             std::string_view arg2);
-
 /**
  * @brief Formats PropertyValueOutOfRange message into JSON
  * Message body: "The value '%1' for the property %2 is not in the supported
diff --git a/redfish-core/include/utils/json_utils.hpp b/redfish-core/include/utils/json_utils.hpp
index 5ecce0a..7c70142 100644
--- a/redfish-core/include/utils/json_utils.hpp
+++ b/redfish-core/include/utils/json_utils.hpp
@@ -278,11 +278,7 @@
             }
             else if (ec == UnpackErrorCode::outOfRange)
             {
-                messages::propertyValueNotInList(
-                    res,
-                    jsonValue.dump(2, ' ', true,
-                                   nlohmann::json::error_handler_t::replace),
-                    key);
+                messages::propertyValueNotInList(res, jsonValue, key);
             }
             return false;
         }
diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp
index 6cbb405..5e9de4e 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -1215,8 +1215,8 @@
     {
         if (serviceAddressList->empty())
         {
-            messages::propertyValueNotInList(asyncResp->res, "[]",
-                                             "ServiceAddress");
+            messages::propertyValueNotInList(
+                asyncResp->res, *serviceAddressList, "ServiceAddress");
             return;
         }
     }
@@ -1224,7 +1224,7 @@
     {
         if (baseDNList->empty())
         {
-            messages::propertyValueNotInList(asyncResp->res, "[]",
+            messages::propertyValueNotInList(asyncResp->res, *baseDNList,
                                              "BaseDistinguishedNames");
             return;
         }
@@ -1388,8 +1388,8 @@
                 std::string priv = getPrivilegeFromRoleId(*roleId);
                 if (priv.empty())
                 {
-                    messages::propertyValueNotInList(asyncResp->res, *roleId,
-                                                     "RoleId");
+                    messages::propertyValueNotInList(asyncResp->res, true,
+                                                     "Locked");
                     return;
                 }
 
diff --git a/redfish-core/lib/certificate_service.hpp b/redfish-core/lib/certificate_service.hpp
index d4df6c8..62704c9 100644
--- a/redfish-core/lib/certificate_service.hpp
+++ b/redfish-core/lib/certificate_service.hpp
@@ -719,8 +719,8 @@
     // time consumed in generating private key
     if (*optKeyPairAlgorithm == "RSA" && *optKeyBitLength != rsaKeyBitLength)
     {
-        messages::propertyValueNotInList(
-            asyncResp->res, std::to_string(*optKeyBitLength), "KeyBitLength");
+        messages::propertyValueNotInList(asyncResp->res, *optKeyBitLength,
+                                         "KeyBitLength");
         return;
     }
 
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index 21f74b7..362fdef 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -1559,8 +1559,8 @@
                 if (createNewObject && it.value() == nullptr)
                 {
                     // can't delete a non-existent object
-                    messages::propertyValueNotInList(response->res,
-                                                     it.value().dump(), name);
+                    messages::propertyValueNotInList(response->res, it.value(),
+                                                     name);
                     continue;
                 }
 
diff --git a/redfish-core/lib/redfish_sessions.hpp b/redfish-core/lib/redfish_sessions.hpp
index 0608333..4c98974 100644
--- a/redfish-core/lib/redfish_sessions.hpp
+++ b/redfish-core/lib/redfish_sessions.hpp
@@ -319,8 +319,7 @@
         }
         else
         {
-            messages::propertyValueNotInList(asyncResp->res,
-                                             std::to_string(*sessionTimeout),
+            messages::propertyValueNotInList(asyncResp->res, *sessionTimeout,
                                              "SessionTimeOut");
         }
     }
diff --git a/redfish-core/src/error_messages.cpp b/redfish-core/src/error_messages.cpp
index 4a9e08a..fcb8bcb 100644
--- a/redfish-core/src/error_messages.cpp
+++ b/redfish-core/src/error_messages.cpp
@@ -500,14 +500,17 @@
  * See header file for more information
  * @endinternal
  */
-nlohmann::json propertyValueNotInList(std::string_view arg1,
+
+nlohmann::json propertyValueNotInList(const nlohmann::json& arg1,
                                       std::string_view arg2)
 {
+    std::string arg1Str = arg1.dump(-1, ' ', true,
+                                    nlohmann::json::error_handler_t::replace);
     return getLog(redfish::registries::base::Index::propertyValueNotInList,
-                  std::to_array({arg1, arg2}));
+                  std::to_array<std::string_view>({arg1Str, arg2}));
 }
 
-void propertyValueNotInList(crow::Response& res, std::string_view arg1,
+void propertyValueNotInList(crow::Response& res, const nlohmann::json& arg1,
                             std::string_view arg2)
 {
     res.result(boost::beast::http::status::bad_request);