From b0e88ffb7adec47fd2d8173ea74c23d8be0151db Mon Sep 17 00:00:00 2001 From: Mikhail Mineev <Mikhail.Mineev@cern.ch> Date: Thu, 20 Jun 2024 14:53:34 +0200 Subject: [PATCH] corrected IovDto --- CMakeLists.txt.athena | 2 +- src/CrestModel.cxx | 41 ++++++++++++++++++++++++++++++++++++---- test/CrestApiFs_test.cxx | 5 +++-- test/CrestApi_test.cxx | 5 +++-- 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt.athena b/CMakeLists.txt.athena index 8822da8..489f43f 100644 --- a/CMakeLists.txt.athena +++ b/CMakeLists.txt.athena @@ -61,7 +61,7 @@ set(HEADERS ${header_path}/CrestApi.h ${header_path}/CrestApiExt.h ${header_path}/picosha2.h) -set(SOURCES src/CrestApi.cxx src/CrestRequest.cxx src/CrestApiFs.cxx) +set(SOURCES src/CrestApi.cxx src/CrestRequest.cxx src/CrestApiFs.cxx src/CrestModel.cxx) include_directories(CrestApi ./ nlohmann ${Boost_INCLUDE_DIRS}) diff --git a/src/CrestModel.cxx b/src/CrestModel.cxx index 6b8ed41..0217250 100644 --- a/src/CrestModel.cxx +++ b/src/CrestModel.cxx @@ -79,7 +79,15 @@ crestResponse.format = j.value("format", ""); // Check for the presence of "page" key and create an optional - crestResponse.page = j.contains("page") ? std::make_optional(RespPage::from_json(j["page"])) : std::nullopt; + if (j.contains("page")){ + if (!j["page"].is_null()){ + crestResponse.page = std::make_optional((RespPage::from_json(j["page"]))); + } + } + else { + crestResponse.page = std::nullopt; + } + // Check for the presence of "filter" key and create an optional crestResponse.filter = j.contains("filter") ? std::make_optional(GenericMap::from_json(j["filter"])) : std::nullopt; @@ -365,6 +373,7 @@ } return tagSet; } + json IovDto::to_json() const { return { @@ -373,13 +382,37 @@ {"insertionTime", insertionTime}, {"payloadHash", payloadHash}}; } + IovDto IovDto::from_json(const json &j) { IovDto iov; iov.tagName = j.value("tagName", ""); - iov.since = j.value<long_t>("since", 0); - iov.insertionTime = j.value("insertionTime", ""); - iov.payloadHash = j.value("payloadHash", ""); + iov.since = j.value<long_t>("since", 0); + + if (j.contains("insertionTime")){ + if (!j["insertionTime"].is_null()){ + iov.insertionTime = j["insertionTime"]; + } + else { + iov.insertionTime = ""; + } + } + else { + iov.insertionTime = ""; + } + + if (j.contains("payloadHash")){ + if (!j["payloadHash"].is_null()){ + iov.payloadHash = j["payloadHash"]; + } + else { + iov.payloadHash = ""; + } + } + else { + iov.payloadHash = ""; + } + return iov; } diff --git a/test/CrestApiFs_test.cxx b/test/CrestApiFs_test.cxx index 6c76c8b..9ef76f7 100644 --- a/test/CrestApiFs_test.cxx +++ b/test/CrestApiFs_test.cxx @@ -22,7 +22,7 @@ BOOST_AUTO_TEST_SUITE(CrestApiFsTest) std::string workdir = "/tmp/crest"; CrestFsClient myCrestClient = CrestFsClient(true, workdir); - std::string tagname = "test_tag_01"; + std::string tagname = "test_ctest_tag_01"; std::string global_tag = "TEST_GLOBAL_TAG_01"; @@ -40,7 +40,8 @@ BOOST_AUTO_TEST_SUITE(CrestApiFsTest) {"lastValidatedTime", 0}, {"modificationTime", "2018-12-06T11:18:35.641+0000"}, {"name", tagname}, - {"payloadSpec", "Json2Cool"}, + //{"objectType", "Json2Cool"}, + {"payloadSpec", "Json2Cool"}, {"synchronization", "none"}, {"timeType", "time"} }; diff --git a/test/CrestApi_test.cxx b/test/CrestApi_test.cxx index dbbf5bc..8254124 100644 --- a/test/CrestApi_test.cxx +++ b/test/CrestApi_test.cxx @@ -17,9 +17,10 @@ using namespace Crest; BOOST_AUTO_TEST_SUITE(CrestApiTest) - std::string crest_server = "http://crest-undertow-api.web.cern.ch:80/api-v4.0"; + // std::string crest_server = "http://crest-undertow-api.web.cern.ch:80/api-v4.0"; + std::string crest_server = "http://crest-03.cern.ch:8090"; CrestClient myCrestClient = CrestClient(crest_server,false); - std::string tagname = "test_tag_01"; + std::string tagname = "test_ctest_tag_01"; std::string global_tag = "TEST_GLOBAL_TAG_01"; -- GitLab