From 0a54788270ecc39d78526d357db21636a080d6a5 Mon Sep 17 00:00:00 2001
From: Mikhail Mineev <Mikhail.Mineev@cern.ch>
Date: Thu, 12 Sep 2024 15:53:41 +0200
Subject: [PATCH] method getPayloadMeta corrected

---
 CrestApi/CrestModel.h |  2 +-
 src/CrestApi.cxx      | 15 ++++++---------
 src/CrestModel.cxx    | 12 +++++++-----
 3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/CrestApi/CrestModel.h b/CrestApi/CrestModel.h
index d121441..95a9604 100644
--- a/CrestApi/CrestModel.h
+++ b/CrestApi/CrestModel.h
@@ -62,7 +62,7 @@ public:
     std::string description;
     std::string release;
     std::optional<std::string> insertionTime;
-    std::string snapshotTime;
+    std::optional<std::string> snapshotTime;
     std::string scenario;
     std::string workflow;
     std::string type;
diff --git a/src/CrestApi.cxx b/src/CrestApi.cxx
index 6eb6816..977b1a6 100644
--- a/src/CrestApi.cxx
+++ b/src/CrestApi.cxx
@@ -792,20 +792,17 @@ namespace Crest
 
         std::string current_path = m_PATH;
         current_path += s_PAYLOAD_PATH;
-        current_path += '/';
-        current_path += hash;
-        current_path += "?format=META";
+	current_path += s_DATA_PATH;
+        current_path += "?format=META&hash=";
+	current_path += hash;
         std::string retv;
         nlohmann::json js = nullptr;
         retv = m_request.performRequest(current_path, GET, js, method_name);
-        // std::cout << "CrestClient::getPayloadMeta: retv = " << retv << std::endl;
         nlohmann::json response = getJson(retv, method_name);
-
-        PayloadSetDto dto = PayloadSetDto::from_json(response);
-        std::vector<PayloadDto> v = dto.resources;
-        // Only one element is expected:
-        return v[0];
+	PayloadDto dto = PayloadDto::from_json(response);
+	return dto;
     }
+ 
 } // namespace Crest
 
 #pragma GCC diagnostic pop
diff --git a/src/CrestModel.cxx b/src/CrestModel.cxx
index e1e71c9..f65ed0c 100644
--- a/src/CrestModel.cxx
+++ b/src/CrestModel.cxx
@@ -120,13 +120,13 @@ GlobalTagSetDto GlobalTagSetDto::from_json(const json &j)
 }
 
 GlobalTagDto::GlobalTagDto() : name(""), validity(0), description(""), release(""),
-                               snapshotTime(""), scenario(""), workflow(""), type("T"),
+                               scenario(""), workflow(""), type("T"),
                                snapshotTimeMilli(0), insertionTimeMilli(0)
 {
 }
 
 GlobalTagDto::GlobalTagDto(const char *l_name, const char *l_description, const char *l_release, const char *l_workflow) : name(l_name), validity(0), description(l_description), release(l_release),
-                                                                                                                           snapshotTime(""), scenario(""), workflow(l_workflow), type("T"),
+                                                                                                                           scenario(""), workflow(l_workflow), type("T"),
                                                                                                                            snapshotTimeMilli(0), insertionTimeMilli(0)
 {
 }
@@ -139,8 +139,9 @@ json GlobalTagDto::to_json() const
     js["description"] = description;
     js["release"] = release;
     if (insertionTime.has_value())
-        js["insertionTime"] = insertionTime.value();
-    js["snapshotTime"] = snapshotTime;
+        js["insertionTime"] = insertionTime.value();;
+    if (snapshotTime.has_value())
+        js["snapshotTime"] = snapshotTime.value();
     js["scenario"] = scenario;
     js["workflow"] = workflow;
     js["type"] = type;
@@ -157,7 +158,8 @@ GlobalTagDto GlobalTagDto::from_json(const json &j)
     globalTag.release = j.value("release", "");
     if (j.contains(std::string{"insertionTime"}))
         globalTag.insertionTime = j.value("insertionTime", "");
-    globalTag.snapshotTime = j.value("snapshotTime", "");
+    if (j.contains(std::string{"snapshotTime"}))
+        globalTag.snapshotTime = j.value("snapshotTime", "");
     globalTag.scenario = j.value("scenario", "");
     globalTag.workflow = j.value("workflow", "");
     globalTag.type = j.value("type", "");
-- 
GitLab