diff --git a/EtsiServerGen/patches/applyPatches.sh b/EtsiServerGen/patches/applyPatches.sh index ae585fe39da391dc582653548dcda32eda46cd21..446a9007025427629eed80b5dc000cb8f6fc50e9 100755 --- a/EtsiServerGen/patches/applyPatches.sh +++ b/EtsiServerGen/patches/applyPatches.sh @@ -2,8 +2,11 @@ patch -u ../api/DefaultApi.h -i fixHeaderModelIssue.patch patch -u ../api/DefaultApi.cpp -i fixCppModelIssue.patch patch -u ../api/RelocalizationInformationApi.cpp -i fixCppRelocalizationInformation.patch -#patch -u ../api/WorldAnchorsApi.cpp -i fixCppWorldAnchors.patch -#patch -u ../model/WorldAnchor.cpp -i fixCppWorldAnchorModel.patch -#patch -u ../api/WorldLinksApi.cpp -i fixCppWorldLinks.patch -#patch -u ../model/WorldLink.cpp -i fixCppWorldLinksModel.patch - +patch -u ../api/TrackablesApi.cpp -i fixCppTrackables.patch +patch -u ../api/WorldAnchorsApi.cpp -i fixCppWorldAnchors.patch +patch -u ../api/WorldLinksApi.cpp -i fixCppWorldLinks.patch +patch -u ../model/Capability.cpp -i fixCppCapabilityModel.patch +patch -u ../model/Trackable.cpp -i fixCppTrackableModel.patch +patch -u ../model/UuidAndMode.cpp -i fixCppUuidAndModeModel.patch +patch -u ../model/WorldAnchor.cpp -i fixCppWorldAnchorModel.patch +patch -u ../model/WorldLink.cpp -i fixCppWorldLinkModel.patch diff --git a/EtsiServerGen/patches/fixCppCapabilityModel.patch b/EtsiServerGen/patches/fixCppCapabilityModel.patch index 35b5d4ff76ec162f064e0f5916432a827a005200..06531f06457f92f80072b1c69a4d20a551988865 100644 --- a/EtsiServerGen/patches/fixCppCapabilityModel.patch +++ b/EtsiServerGen/patches/fixCppCapabilityModel.patch @@ -1,20 +1,22 @@ -diff --git a/EtsiServerGen/model/Capability.cpp b/../../world-storage-cpp-server/EtsiServerGen/model/Capability.cpp -index 8df709d..442bc9d 100644 ---- a/EtsiServerGen/model/Capability.cpp -+++ b/../../world-storage-cpp-server/EtsiServerGen/model/Capability.cpp -@@ -63,6 +63,7 @@ ptree Capability::toPropertyTree() const +--- Capability.cpp 2024-09-19 23:18:16.290090280 +0200 ++++ Capability-corrected.cpp 2024-09-20 13:40:09.082949533 +0200 +@@ -63,7 +63,8 @@ { ptree pt; ptree tmp_node; -+ pt.put("trackableType", m_TrackableType.getEnumValue()); - pt.add_child("encodingInformation", m_EncodingInformation.toPropertyTree()); +- pt.add_child("encodingInformation", m_EncodingInformation.toPropertyTree()); ++ pt.put("trackableType", m_TrackableType.getEnumValue()); ++ pt.add_child("encodingInformation", m_EncodingInformation.toPropertyTree()); pt.put("framerate", m_Framerate); pt.put("latency", m_Latency); -@@ -73,6 +74,7 @@ ptree Capability::toPropertyTree() const + pt.put("accuracy", m_Accuracy); +@@ -73,7 +74,8 @@ void Capability::fromPropertyTree(ptree const &pt) { ptree tmp_node; -+ m_TrackableType.setEnumValue(pt.get("trackableType","")); - if (pt.get_child_optional("encodingInformation")) { +- if (pt.get_child_optional("encodingInformation")) { ++ m_TrackableType.setEnumValue(pt.get("trackableType","")); ++ if (pt.get_child_optional("encodingInformation")) { m_EncodingInformation = fromPt<EncodingInformationStructure>(pt.get_child("encodingInformation")); } + m_Framerate = pt.get("framerate", 0.0); diff --git a/EtsiServerGen/patches/fixCppGetRelocResponse.patch b/EtsiServerGen/patches/fixCppGetRelocResponse.patch deleted file mode 100644 index 2c85329cc44ae45de06f7b1c917be7e6579a2597..0000000000000000000000000000000000000000 --- a/EtsiServerGen/patches/fixCppGetRelocResponse.patch +++ /dev/null @@ -1,14 +0,0 @@ -diff --git a/EtsiServerGen/model/GetRelocalizationInformation_200_response.cpp b/../../world-storage-cpp-server/EtsiServerGen/model/GetRelocalizationInformation_200_response.cpp -index d6f90df..ce6079e 100644 ---- a/EtsiServerGen/model/GetRelocalizationInformation_200_response.cpp -+++ b/../../world-storage-cpp-server/EtsiServerGen/model/GetRelocalizationInformation_200_response.cpp -@@ -47,6 +47,9 @@ std::string GetRelocalizationInformation_200_response::toJsonString(bool prettyJ - // workaround inspired by: https://stackoverflow.com/a/56395440 - std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\""); - std::string result = std::regex_replace(ss.str(), reg, "$1"); -+ -+ result.erase(std::remove(result.begin(), result.end(), '|'), result.end()); -+ - return result; - } - diff --git a/EtsiServerGen/patches/fixCppRelocalizationInformation.patch b/EtsiServerGen/patches/fixCppRelocalizationInformation.patch index 2ad31dfd1561a7a597088412d7ccc360d5c6767e..0ab4692ee561c2fc546ab19dbb0e581063b406e7 100644 --- a/EtsiServerGen/patches/fixCppRelocalizationInformation.patch +++ b/EtsiServerGen/patches/fixCppRelocalizationInformation.patch @@ -1,17 +1,23 @@ ---- RelocalizationInformationApi.cpp 2024-09-17 15:53:04.949160050 +0200 -+++ RelocalizationInformationApi_corrected.cpp 2024-09-17 15:44:29.639017895 +0200 -@@ -161,12 +161,12 @@ +--- RelocalizationInformationApi.cpp 2024-09-19 22:57:54.664539447 +0200 ++++ RelocalizationInformationApi_corrected.cpp 2024-09-19 22:57:22.213975949 +0200 +@@ -157,16 +157,12 @@ + { + const auto request = session->get_request(); + // Getting the query params +- std::string uuids_raw = request->get_query_parameter("uuids"); ++ std::multimap<std::string, std::string> uuids_raw = request->get_query_parameters("uuids"); std::vector<UuidAndMode> uuids; - std::vector<std::string> uuids_temp; - boost::split(uuids_temp, uuids_raw, boost::is_any_of(",")); +- std::vector<std::string> uuids_temp; +- boost::split(uuids_temp, uuids_raw, boost::is_any_of(",")); - std::transform(uuids_temp.begin(), uuids_temp.end(), std::back_inserter(uuids), [](const auto& i){ UuidAndMode ret; ret.fromString(i); return ret;}); -+ std::transform(uuids_temp.begin(), uuids_temp.end(), std::back_inserter(uuids), [](const auto& i){ UuidAndMode ret; ret.fromJsonString(i); return ret;}); - std::string capabilities_raw = request->get_query_parameter("capabilities"); +- std::string capabilities_raw = request->get_query_parameter("capabilities"); ++ std::transform(uuids_raw.begin(), uuids_raw.end(), std::back_inserter(uuids), [](const auto& i){ UuidAndMode ret; ret.fromJsonString(i.second); return ret;}); ++ std::multimap<std::string, std::string> capabilities_raw = request->get_query_parameters("capabilities"); std::vector<Capability> capabilities; - std::vector<std::string> capabilities_temp; - boost::split(capabilities_temp, capabilities_raw, boost::is_any_of(",")); +- std::vector<std::string> capabilities_temp; +- boost::split(capabilities_temp, capabilities_raw, boost::is_any_of(",")); - std::transform(capabilities_temp.begin(), capabilities_temp.end(), std::back_inserter(capabilities), [](const auto& i){ Capability ret; ret.fromString(i); return ret;}); -+ std::transform(capabilities_temp.begin(), capabilities_temp.end(), std::back_inserter(capabilities), [](const auto& i){ Capability ret; ret.fromJsonString(i); return ret;}); ++ std::transform(capabilities_raw.begin(), capabilities_raw.end(), std::back_inserter(capabilities), [](const auto& i){ Capability ret; ret.fromJsonString(i.second); return ret;}); // Getting the headers std::string token = request->get_header("token", ""); diff --git a/EtsiServerGen/patches/fixCppRelocalizationInformationModel.patch b/EtsiServerGen/patches/fixCppRelocalizationInformationModel.patch deleted file mode 100644 index 4fe2132f89fe0cd4649f3b7ed7c02ea5fb601c5a..0000000000000000000000000000000000000000 --- a/EtsiServerGen/patches/fixCppRelocalizationInformationModel.patch +++ /dev/null @@ -1,21 +0,0 @@ -diff --git a/EtsiServerGen/model/RelocalizationInformation.cpp b/../../world-storage-cpp-server/EtsiServerGen/model/RelocalizationInformation.cpp -index 46fd7ec..8a020e9 100644 ---- a/EtsiServerGen/model/RelocalizationInformation.cpp -+++ b/../../world-storage-cpp-server/EtsiServerGen/model/RelocalizationInformation.cpp -@@ -64,6 +64,7 @@ ptree RelocalizationInformation::toPropertyTree() const - ptree pt; - ptree tmp_node; - pt.put("requestUUID", m_RequestUUID); -+ pt.put("requestType", m_RequestType.getEnumValue()); - // generate tree for RelocObjects - tmp_node.clear(); - if (!m_RelocObjects.empty()) { -@@ -78,6 +79,8 @@ void RelocalizationInformation::fromPropertyTree(ptree const &pt) - { - ptree tmp_node; - m_RequestUUID = pt.get("requestUUID", ""); -+ m_RequestType.setEnumValue(pt.get("requestType","")); -+ - // push all items of RelocObjects into member - if (pt.get_child_optional("relocObjects")) { - m_RelocObjects = fromPt<std::vector<RelocalizationInformation_relocObjects_inner>>(pt.get_child("relocObjects")); diff --git a/EtsiServerGen/patches/fixCppRelocalizationInformationParamModel.patch b/EtsiServerGen/patches/fixCppRelocalizationInformationParamModel.patch deleted file mode 100644 index 37a5d72824e7c541bb0465dccd8898795e1c2460..0000000000000000000000000000000000000000 --- a/EtsiServerGen/patches/fixCppRelocalizationInformationParamModel.patch +++ /dev/null @@ -1,20 +0,0 @@ -diff --git a/EtsiServerGen/model/RelocalizationInformationParam.cpp b/../../world-storage-cpp-server/EtsiServerGen/model/RelocalizationInformationParam.cpp -index 2890d6f..4c36c18 100644 ---- a/EtsiServerGen/model/RelocalizationInformationParam.cpp -+++ b/../../world-storage-cpp-server/EtsiServerGen/model/RelocalizationInformationParam.cpp -@@ -63,6 +63,7 @@ ptree RelocalizationInformationParam::toPropertyTree() const - { - ptree pt; - ptree tmp_node; -+ pt.put("mode", m_Mode.getEnumValue()); - pt.put("uuid", m_Uuid); - return pt; - } -@@ -70,6 +71,7 @@ ptree RelocalizationInformationParam::toPropertyTree() const - void RelocalizationInformationParam::fromPropertyTree(ptree const &pt) - { - ptree tmp_node; -+ m_Mode.setEnumValue(pt.get("mode","")); - m_Uuid = pt.get("uuid", ""); - } - diff --git a/EtsiServerGen/patches/fixCppTrackable.patch b/EtsiServerGen/patches/fixCppTrackable.patch deleted file mode 100644 index ab291d709cb51a1b31cab309c4dca1ee09c343dc..0000000000000000000000000000000000000000 --- a/EtsiServerGen/patches/fixCppTrackable.patch +++ /dev/null @@ -1,397 +0,0 @@ -diff --git a/EtsiServerGen/api/TrackablesApi.cpp b/../../world-storage-cpp-server/EtsiServerGen/api/TrackablesApi.cpp -index 4360e8b..9075a53 100644 ---- a/EtsiServerGen/api/TrackablesApi.cpp -+++ b/../../world-storage-cpp-server/EtsiServerGen/api/TrackablesApi.cpp -@@ -20,9 +20,12 @@ - #include <boost/property_tree/json_parser.hpp> - #include <boost/lexical_cast.hpp> - #include <boost/algorithm/string.hpp> -- -+#include <iostream> -+#include <stdlib.h> - #include "TrackablesApi.h" - -+ -+ - namespace org { - namespace openapitools { - namespace server { -@@ -80,6 +83,13 @@ MODEL_T extractJsonModelBodyParam(const std::string& bodyContent) - boost::property_tree::json_parser::read_json(sstream, pt); - - auto model = MODEL_T(pt); -+ -+ if constexpr(std::is_same_v<MODEL_T, Trackable>) { -+ auto unitStr = pt.get<std::string>("unit", ""); -+ UnitSystem unit; -+ unit.fromString(unitStr);// Convertir unitStr en UnitSystem -+ model.setUnit(unit); -+ } - return model; - } - -@@ -159,88 +169,102 @@ void TrackablesResource::defaultSessionClose(const std::shared_ptr<restbed::Sess - session->close(status, result, { {"Connection", "close"} }); - } - -+void extractBodyContentAsync( -+ const std::shared_ptr<restbed::Session>& session, -+ int content_length, -+ std::function<void(const std::string&)> callback) -+{ -+ session->fetch(content_length, -+ [callback](const std::shared_ptr<restbed::Session> session, -+ const restbed::Bytes &body) { -+ std::string bodyContent = restbed::String::format( -+ "%.*s\n", (int)body.size(), body.data()); -+ callback(bodyContent); -+ }); -+} -+ - void TrackablesResource::handler_POST_internal(const std::shared_ptr<restbed::Session> session) - { - const auto request = session->get_request(); -- // body params or form params here from the body content string -- std::string bodyContent = extractBodyContent(session); -- auto trackable = extractJsonModelBodyParam<Trackable>(bodyContent); -- // Getting the headers -- std::string token = request->get_header("token", ""); -- -- int status_code = 500; -- std::string resultObject = ""; -- std::string result = ""; -- -- try { -- std::tie(status_code, resultObject) = -- handler_POST(trackable, token); -- } -- catch(const TrackablesApiException& e) { -- std::tie(status_code, result) = handleTrackablesApiException(e); -- } -- catch(const std::exception& e) { -- std::tie(status_code, result) = handleStdException(e); -- } -- catch(...) { -- std::tie(status_code, result) = handleUnspecifiedException(); -- } -- -- std::multimap< std::string, std::string > responseHeaders {}; -- static const std::vector<std::string> contentTypes{ -- "text/plain","application/json", -- }; -- static const std::string acceptTypes{ -- "application/json, " -- }; -- -- if (status_code == 200) { -- responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes))); -- if (!acceptTypes.empty()) { -- responseHeaders.insert(std::make_pair("Accept", acceptTypes)); -- } -- -- result = resultObject; -- returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); -- return; -- } -- if (status_code == 201) { -- responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes))); -- if (!acceptTypes.empty()) { -- responseHeaders.insert(std::make_pair("Accept", acceptTypes)); -- } -- -- result = resultObject; -- returnResponse(session, 201, result.empty() ? "{}" : result, responseHeaders); -- return; -- } -- if (status_code == 400) { -- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); -- result = "Bad request."; -- -- result = resultObject; -- returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); -- return; -- } -- if (status_code == 409) { -- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); -- result = "Invalid UUID, id must be a Nil value."; -- -- result = resultObject; -- returnResponse(session, 409, result.empty() ? "{}" : result, responseHeaders); -- return; -- } -- if (status_code == 0) { -- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); -- result = "Unexpected error."; -- -- result = resultObject.toJsonString(); -- returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); -- return; -- } -- defaultSessionClose(session, status_code, result); -- -- -+ int content_length = request->get_header("Content-Length", 0); -+ extractBodyContentAsync(session, content_length, [this, session,request](const std::string& bodyContent) { -+ -+ -+ std::string token = request->get_header("token", ""); -+ -+ int status_code = 500; -+ std::string resultObject = ""; -+ std::string result = ""; -+ -+ auto trackable = extractJsonModelBodyParam<Trackable>(bodyContent); -+ -+ try { -+ std::tie(status_code, resultObject) = -+ handler_POST(trackable, token); -+ } -+ catch (const TrackablesApiException& e) { -+ std::tie(status_code, result) = handleTrackablesApiException(e); -+ } -+ catch (const std::exception& e) { -+ std::tie(status_code, result) = handleStdException(e); -+ } -+ catch (...) { -+ std::tie(status_code, result) = handleUnspecifiedException(); -+ } -+ -+ std::multimap< std::string, std::string > responseHeaders {}; -+ static const std::vector<std::string> contentTypes{ -+ "text/plain","application/json", -+ }; -+ static const std::string acceptTypes{ -+ "application/json, " -+ }; -+ -+ if (status_code == 200) { -+ responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes))); -+ if (!acceptTypes.empty()) { -+ responseHeaders.insert(std::make_pair("Accept", acceptTypes)); -+ } -+ -+ auto result = resultObject; -+ returnResponse(session, 200, result, responseHeaders); -+ return; -+ } -+ if (status_code == 201) { -+ responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes))); -+ if (!acceptTypes.empty()) { -+ responseHeaders.insert(std::make_pair("Accept", acceptTypes)); -+ } -+ -+ auto result = resultObject; -+ returnResponse(session, 201, result, responseHeaders); -+ return; -+ } -+ if (status_code == 400) { -+ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); -+ result = "Bad request."; -+ -+ auto result = resultObject; -+ returnResponse(session, 400, result, responseHeaders); -+ return; -+ } -+ if (status_code == 409) { -+ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); -+ result = "Invalid UUID, id must be a Nil value."; -+ -+ auto result = resultObject; -+ returnResponse(session, 409, result, responseHeaders); -+ return; -+ } -+ if (status_code == 0) { -+ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); -+ result = "Unexpected error."; -+ -+ returnResponse(session, 0, result, responseHeaders); -+ return; -+ } -+ defaultSessionClose(session, status_code, result); -+ }); - } - - // x-extension -@@ -279,8 +303,16 @@ void TrackablesResource::handler_GET_internal(const std::shared_ptr<restbed::Ses - if (!acceptTypes.empty()) { - responseHeaders.insert(std::make_pair("Accept", acceptTypes)); - } -- -- returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); -+ std::string rep= "[\n"; -+ for (const Trackable& item : resultObject) { -+ rep += item.toJsonString() + ",\n"; -+ } -+ if (!resultObject.empty()) { -+ rep = rep.substr(0, rep.size() - 2); -+ } -+ rep += "\n]"; -+ -+ returnResponse(session, 200, rep, responseHeaders); - return; - } - if (status_code == 201) { -@@ -288,17 +320,20 @@ void TrackablesResource::handler_GET_internal(const std::shared_ptr<restbed::Ses - if (!acceptTypes.empty()) { - responseHeaders.insert(std::make_pair("Accept", acceptTypes)); - } -- -- result = resultObject; -- returnResponse(session, 201, result.empty() ? "{}" : result, responseHeaders); -+ std::string rep; -+ for (const Trackable& item : resultObject) { -+ rep += item.toJsonString() + ",\n"; -+ } -+ -+ returnResponse(session, 201, rep, responseHeaders); - return; - } - if (status_code == 0) { - responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); - result = "Unexpected error."; - -- result = resultObject.toJsonString(); -- returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); -+ -+ returnResponse(session, 0, result, responseHeaders); - return; - } - defaultSessionClose(session, status_code, result); -@@ -308,8 +343,11 @@ void TrackablesResource::handler_GET_internal(const std::shared_ptr<restbed::Ses - // x-extension - void TrackablesResource::handler_PUT_internal(const std::shared_ptr<restbed::Session> session) { - const auto request = session->get_request(); -+ int content_length = request->get_header("Content-Length", 0); -+ - // body params or form params here from the body content string -- std::string bodyContent = extractBodyContent(session); -+ extractBodyContentAsync(session, content_length, [this, session,request](const std::string& bodyContent) { -+ - auto trackable = extractJsonModelBodyParam<Trackable>(bodyContent); - // Getting the headers - std::string token = request->get_header("token", ""); -@@ -346,8 +384,8 @@ void TrackablesResource::handler_PUT_internal(const std::shared_ptr<restbed::Ses - responseHeaders.insert(std::make_pair("Accept", acceptTypes)); - } - -- result = resultObject; -- returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); -+ auto result = resultObject; -+ returnResponse(session, 200, result, responseHeaders); - return; - } - if (status_code == 400) { -@@ -362,21 +400,19 @@ void TrackablesResource::handler_PUT_internal(const std::shared_ptr<restbed::Ses - responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); - result = "Not found, could not find UUID in database."; - -- result = resultObject; -- returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders); -+ auto result = resultObject; -+ returnResponse(session, 404, result, responseHeaders); - return; - } - if (status_code == 0) { - responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); - result = "Unexpected error."; - -- result = resultObject.toJsonString(); -- returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); -+ returnResponse(session, 0, result, responseHeaders); - return; - } - defaultSessionClose(session, status_code, result); -- -- -+ }); - } - - std::pair<int, std::string> TrackablesResource::handler_POST( -@@ -396,18 +432,24 @@ std::pair<int, std::string> TrackablesResource::handler_PUT( - return handler_PUT_func(trackable, token); - } - --std::string TrackablesResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) { -- const auto request = session->get_request(); -- int content_length = request->get_header("Content-Length", 0); -- std::string bodyContent; -- session->fetch(content_length, -+ -+ -+std::string TrackablesResource::extractBodyContent( -+ const std::shared_ptr<restbed::Session>& session) { -+ const auto request = session->get_request(); -+ int content_length = request->get_header("Content-Length", 0); -+ -+ std::string bodyContent; -+ session->fetch(content_length, - [&bodyContent](const std::shared_ptr<restbed::Session> session, - const restbed::Bytes &body) { - bodyContent = restbed::String::format( - "%.*s\n", (int)body.size(), body.data()); - }); -- return bodyContent; -+ return bodyContent; - } -+ -+ - - std::string TrackablesResource::extractFormParamsFromBody(const std::string& paramName, const std::string& body) { - const auto uri = restbed::Uri("urlencoded?" + body, true); -@@ -499,24 +541,22 @@ void TrackablesTrackableUUIDResource::handler_DELETE_internal(const std::shared_ - responseHeaders.insert(std::make_pair("Accept", acceptTypes)); - } - -- result = resultObject; -- returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); -+ auto result = resultObject; -+ returnResponse(session, 200, result, responseHeaders); - return; - } - if (status_code == 400) { - responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); - result = "Invalid UUID supplied."; - -- result = resultObject; -- returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); -+ returnResponse(session, 400,result, responseHeaders); - return; - } - if (status_code == 404) { - responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); - result = "Not found, could not find UUID in database."; - -- result = resultObject; -- returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders); -+ returnResponse(session, 404, result, responseHeaders); - return; - } - defaultSessionClose(session, status_code, result); -@@ -564,23 +604,22 @@ void TrackablesTrackableUUIDResource::handler_GET_internal(const std::shared_ptr - } - - result = resultObject.toJsonString(); -- returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); -+ returnResponse(session, 200,result, responseHeaders); - return; - } - if (status_code == 400) { - responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); - result = "Invalid UUID supplied."; - -- result = resultObject; -- returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); -+ auto result = resultObject; -+ returnResponse(session, 400, "{}", responseHeaders); - return; - } - if (status_code == 404) { - responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); - result = "Not found, could not find UUID in database."; - -- result = resultObject; -- returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders); -+ returnResponse(session, 404, result, responseHeaders); - return; - } - defaultSessionClose(session, status_code, result); diff --git a/EtsiServerGen/patches/fixCppTrackableModel.patch b/EtsiServerGen/patches/fixCppTrackableModel.patch index def0e935e4c918562e3a74647205504b6bd7d2a3..123c6b65030bf770516a548a4afe507df903fda4 100644 --- a/EtsiServerGen/patches/fixCppTrackableModel.patch +++ b/EtsiServerGen/patches/fixCppTrackableModel.patch @@ -1,15 +1,25 @@ ---- Trackable.cpp 2024-08-30 11:59:56.122059845 +0200 -+++ Trackable_corrected.cpp 2024-08-30 15:24:54.948427783 +0200 -@@ -48,6 +48,8 @@ +--- Trackable.cpp 2024-09-19 16:25:49.067872578 +0200 ++++ Trackable_corrected.cpp 2024-09-19 16:18:02.183949340 +0200 +@@ -48,6 +48,7 @@ // workaround inspired by: https://stackoverflow.com/a/56395440 std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\""); std::string result = std::regex_replace(ss.str(), reg, "$1"); -+ + result.erase(std::remove(result.begin(), result.end(), '|'), result.end()); return result; } -@@ -85,8 +87,19 @@ +@@ -65,7 +66,10 @@ + ptree tmp_node; + pt.put("UUID", m_UUID); + pt.put("name", m_Name); ++ pt.put("trackablePayload", "|" + m_TrackablePayload + "|" ); + pt.put("creatorUUID", m_CreatorUUID); ++ pt.put("trackableType", m_TrackableType.getEnumValue()); ++ pt.put("unit", m_Unit.getEnumValue()); + pt.add_child("trackableEncodingInformation", m_TrackableEncodingInformation.toPropertyTree()); + // generate tree for LocalCRS + tmp_node.clear(); +@@ -83,8 +87,19 @@ } // generate tree for KeyvalueTags if (!m_KeyvalueTags.empty()) { @@ -27,16 +37,27 @@ + keyvalueTags.add_child(kv.first,tag_node); + + } -+ pt.add_child("keyvalueTags", keyvalueTags); ++ pt.add_child("keyvalueTags", keyvalueTags); } tmp_node.clear(); pt.put("confidence", m_Confidence); -@@ -115,6 +128,8 @@ +@@ -96,6 +111,9 @@ + ptree tmp_node; + m_UUID = pt.get("UUID", ""); + m_Name = pt.get("name", ""); ++ m_TrackableType.setEnumValue(pt.get("trackableType","")); ++ m_Unit.setEnumValue(pt.get("unit","")); ++ + m_CreatorUUID = pt.get("creatorUUID", ""); + if (pt.get_child_optional("trackableEncodingInformation")) { + m_TrackableEncodingInformation = fromPt<EncodingInformationStructure>(pt.get_child("trackableEncodingInformation")); +@@ -111,6 +129,9 @@ if (pt.get_child_optional("keyvalueTags")) { m_KeyvalueTags = fromPt<std::map<std::string, std::vector<std::string>>>(pt.get_child("keyvalueTags")); } + if (pt.get_child_optional("trackablePayload")) { + m_TrackablePayload = fromPt<std::string>(pt.get_child("trackablePayload")); ++ } m_Confidence = pt.get("confidence", 0.0); } diff --git a/EtsiServerGen/patches/fixCppTrackables.patch b/EtsiServerGen/patches/fixCppTrackables.patch new file mode 100644 index 0000000000000000000000000000000000000000..0fbbb30fd1bbd1f0d89d901ae22a153da17df809 --- /dev/null +++ b/EtsiServerGen/patches/fixCppTrackables.patch @@ -0,0 +1,178 @@ +--- TrackablesApi.cpp 2024-09-19 14:26:36.877177137 +0200 ++++ TrackablesApi_corrected.cpp 2024-09-19 14:27:58.857174515 +0200 +@@ -159,86 +159,100 @@ + session->close(status, result, { {"Connection", "close"} }); + } + ++void extractBodyContentAsync( ++ const std::shared_ptr<restbed::Session>& session, ++ int content_length, ++ std::function<void(const std::string&)> callback) ++{ ++ session->fetch(content_length, ++ [callback](const std::shared_ptr<restbed::Session> session, ++ const restbed::Bytes &body) { ++ std::string bodyContent = restbed::String::format( ++ "%.*s\n", (int)body.size(), body.data()); ++ callback(bodyContent); ++ }); ++} ++ + void TrackablesResource::handler_POST_internal(const std::shared_ptr<restbed::Session> session) + { + const auto request = session->get_request(); +- // body params or form params here from the body content string +- std::string bodyContent = extractBodyContent(session); +- auto trackable = extractJsonModelBodyParam<Trackable>(bodyContent); ++ + // Getting the headers +- std::string token = request->get_header("token", ""); +- +- int status_code = 500; +- Success resultObject = Success{}; +- std::string result = ""; +- +- try { +- std::tie(status_code, resultObject) = +- handler_POST(trackable, token); +- } +- catch(const TrackablesApiException& e) { +- std::tie(status_code, result) = handleTrackablesApiException(e); +- } +- catch(const std::exception& e) { +- std::tie(status_code, result) = handleStdException(e); +- } +- catch(...) { +- std::tie(status_code, result) = handleUnspecifiedException(); +- } +- +- std::multimap< std::string, std::string > responseHeaders {}; +- static const std::vector<std::string> contentTypes{ +- "application/json", +- }; +- static const std::string acceptTypes{ +- "application/json, " +- }; +- +- if (status_code == 200) { +- responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes))); +- if (!acceptTypes.empty()) { +- responseHeaders.insert(std::make_pair("Accept", acceptTypes)); ++ int content_length = request->get_header("Content-Length", 0); ++ extractBodyContentAsync(session, content_length, [this, session,request](const std::string& bodyContent) { ++ std::string token = request->get_header("token", ""); ++ ++ int status_code = 500; ++ Success resultObject; ++ std::string result = ""; ++ ++ auto trackable = extractJsonModelBodyParam<Trackable>(bodyContent); ++ try { ++ std::tie(status_code, resultObject) = ++ handler_POST(trackable, token); + } +- +- result = resultObject.toJsonString(); +- returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- if (status_code == 400) { +- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); +- result = "Bad request."; +- +- result = resultObject.toJsonString(); +- returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- if (status_code == 409) { +- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); +- result = "Invalid UUID, id must be a Nil value."; +- +- result = resultObject.toJsonString(); +- returnResponse(session, 409, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- if (status_code == 511) { +- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); +- result = "The secret token is not valid. Please ask an ISG ARF team member for a valid token."; +- +- result = resultObject.toJsonString(); +- returnResponse(session, 511, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- if (status_code == 0) { +- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); +- result = "Unexpected error."; +- +- result = resultObject.toJsonString(); +- returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- defaultSessionClose(session, status_code, result); +- +- ++ catch(const TrackablesApiException& e) { ++ std::tie(status_code, result) = handleTrackablesApiException(e); ++ } ++ catch(const std::exception& e) { ++ std::tie(status_code, result) = handleStdException(e); ++ } ++ catch(...) { ++ std::tie(status_code, result) = handleUnspecifiedException(); ++ } ++ ++ std::multimap< std::string, std::string > responseHeaders {}; ++ static const std::vector<std::string> contentTypes{ ++ "application/json", ++ }; ++ static const std::string acceptTypes{ ++ "application/json, " ++ }; ++ ++ if (status_code == 200) { ++ responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes))); ++ if (!acceptTypes.empty()) { ++ responseHeaders.insert(std::make_pair("Accept", acceptTypes)); ++ } ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ if (status_code == 400) { ++ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); ++ result = "Bad request."; ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ if (status_code == 409) { ++ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); ++ result = "Invalid UUID, id must be a Nil value."; ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 409, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ if (status_code == 511) { ++ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); ++ result = "The secret token is not valid. Please ask an ISG ARF team member for a valid token."; ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 511, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ if (status_code == 0) { ++ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); ++ result = "Unexpected error."; ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ defaultSessionClose(session, status_code, result); ++ }); + } + + // x-extension diff --git a/EtsiServerGen/patches/fixCppUuidAndModeModel.patch b/EtsiServerGen/patches/fixCppUuidAndModeModel.patch new file mode 100644 index 0000000000000000000000000000000000000000..c577d0a17b0d39fa62d46769a605533c5da64e37 --- /dev/null +++ b/EtsiServerGen/patches/fixCppUuidAndModeModel.patch @@ -0,0 +1,18 @@ +--- UuidAndMode.cpp 2024-09-19 23:00:03.766677271 +0200 ++++ UuidAndMode_corrected.cpp 2024-09-19 23:02:48.899142341 +0200 +@@ -64,6 +64,7 @@ + ptree pt; + ptree tmp_node; + pt.put("uuid", m_Uuid); ++ pt.put("mode", m_Mode.getEnumValue()); + return pt; + } + +@@ -71,6 +72,7 @@ + { + ptree tmp_node; + m_Uuid = pt.get("uuid", ""); ++ m_Mode.setEnumValue(pt.get("mode","")); + } + + std::string UuidAndMode::getUuid() const diff --git a/EtsiServerGen/patches/fixCppWorldAnchorModel.patch b/EtsiServerGen/patches/fixCppWorldAnchorModel.patch index 325d8f92463926a24d737e201c82c31646a6460c..81295f9021276ff73ee460ff78a65205ed41c289 100644 --- a/EtsiServerGen/patches/fixCppWorldAnchorModel.patch +++ b/EtsiServerGen/patches/fixCppWorldAnchorModel.patch @@ -1,6 +1,22 @@ ---- WorldAnchor.cpp 2024-08-30 16:07:36.273085120 +0200 -+++ WorldAnchor_corrected.cpp 2024-08-30 16:10:28.143238251 +0200 -@@ -83,8 +83,20 @@ +--- WorldAnchor.cpp 2024-09-19 16:26:22.388046412 +0200 ++++ WorldAnchor_corrected.cpp 2024-09-19 16:35:37.881343480 +0200 +@@ -48,6 +48,7 @@ + // workaround inspired by: https://stackoverflow.com/a/56395440 + std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\""); + std::string result = std::regex_replace(ss.str(), reg, "$1"); ++ result.erase(std::remove(result.begin(), result.end(), '|'), result.end()); + return result; + } + +@@ -66,6 +67,7 @@ + pt.put("UUID", m_UUID); + pt.put("name", m_Name); + pt.put("creatorUUID", m_CreatorUUID); ++ pt.put("unit", m_Unit.getEnumValue()); + // generate tree for LocalCRS + tmp_node.clear(); + if (!m_LocalCRS.empty()) { +@@ -82,8 +84,17 @@ } // generate tree for KeyvalueTags if (!m_KeyvalueTags.empty()) { @@ -14,12 +30,17 @@ + value_node.put("", "|" + val + "|"); // Ensure value is treated as string + tag_node.push_back(std::make_pair("", value_node)); + } -+ -+ keyvalueTags.add_child(kv.first,tag_node); -+ ++ keyvalueTags.add_child(kv.first,tag_node); + } + pt.add_child("keyvalueTags", keyvalueTags); -+ } tmp_node.clear(); return pt; +@@ -95,6 +106,7 @@ + m_UUID = pt.get("UUID", ""); + m_Name = pt.get("name", ""); + m_CreatorUUID = pt.get("creatorUUID", ""); ++ m_Unit.setEnumValue(pt.get("unit","")); + // push all items of LocalCRS into member + if (pt.get_child_optional("localCRS")) { + m_LocalCRS = fromPt<std::vector<float>>(pt.get_child("localCRS")); diff --git a/EtsiServerGen/patches/fixCppWorldAnchors.patch b/EtsiServerGen/patches/fixCppWorldAnchors.patch index c8962f00f167bd5077ab205ee377daeaf537d1cb..f6af32ebfb22d1a826006fabe44d7b94be7d7312 100644 --- a/EtsiServerGen/patches/fixCppWorldAnchors.patch +++ b/EtsiServerGen/patches/fixCppWorldAnchors.patch @@ -1,14 +1,6 @@ ---- WorldAnchorsApi.cpp 2024-08-30 11:59:56.242044753 +0200 -+++ WorldAnchorsApi_corrected.cpp 2024-08-30 15:32:20.829988554 +0200 -@@ -21,6 +21,7 @@ - #include <boost/lexical_cast.hpp> - #include <boost/algorithm/string.hpp> - -+#include <iostream> - #include "WorldAnchorsApi.h" - - namespace org { -@@ -159,11 +160,26 @@ +--- WorldAnchorsApi.cpp 2024-09-19 14:34:27.853783839 +0200 ++++ WorldAnchorsApi_corrected.cpp 2024-09-19 14:34:04.503291590 +0200 +@@ -159,85 +159,100 @@ session->close(status, result, { {"Connection", "close"} }); } @@ -29,40 +21,317 @@ void WorldAnchorsResource::handler_POST_internal(const std::shared_ptr<restbed::Session> session) { const auto request = session->get_request(); -+ int content_length = request->get_header("Content-Length", 0); - // body params or form params here from the body content string +- // body params or form params here from the body content string - std::string bodyContent = extractBodyContent(session); +- auto worldAnchor = extractJsonModelBodyParam<WorldAnchor>(bodyContent); +- // Getting the headers +- std::string token = request->get_header("token", ""); +- +- int status_code = 500; +- Success resultObject = Success{}; +- std::string result = ""; +- +- try { +- std::tie(status_code, resultObject) = +- handler_POST(worldAnchor, token); +- } +- catch(const WorldAnchorsApiException& e) { +- std::tie(status_code, result) = handleWorldAnchorsApiException(e); +- } +- catch(const std::exception& e) { +- std::tie(status_code, result) = handleStdException(e); +- } +- catch(...) { +- std::tie(status_code, result) = handleUnspecifiedException(); +- } +- +- std::multimap< std::string, std::string > responseHeaders {}; +- static const std::vector<std::string> contentTypes{ +- "application/json", +- }; +- static const std::string acceptTypes{ +- "application/json, " +- }; +- +- if (status_code == 200) { +- responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes))); +- if (!acceptTypes.empty()) { +- responseHeaders.insert(std::make_pair("Accept", acceptTypes)); ++ int content_length = request->get_header("Content-Length", 0); ++ + extractBodyContentAsync(session, content_length, [this, session,request](const std::string& bodyContent) { - auto worldAnchor = extractJsonModelBodyParam<WorldAnchor>(bodyContent); - // Getting the headers - std::string token = request->get_header("token", ""); -@@ -239,7 +255,7 @@ - return; - } - defaultSessionClose(session, status_code, result); -- -+ }); ++ auto worldAnchor = extractJsonModelBodyParam<WorldAnchor>(bodyContent); ++ // Getting the headers ++ std::string token = request->get_header("token", ""); ++ ++ int status_code = 500; ++ Success resultObject = Success{}; ++ std::string result = ""; ++ ++ try { ++ std::tie(status_code, resultObject) = ++ handler_POST(worldAnchor, token); + } +- +- result = resultObject.toJsonString(); +- returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- if (status_code == 400) { +- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); +- result = "Bad request."; +- +- result = resultObject.toJsonString(); +- returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- if (status_code == 409) { +- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); +- result = "Invalid UUID, id must be a Nil value."; +- +- result = resultObject.toJsonString(); +- returnResponse(session, 409, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- if (status_code == 511) { +- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); +- result = "The secret token is not valid. Please ask an ISG ARF team member for a valid token."; +- +- result = resultObject.toJsonString(); +- returnResponse(session, 511, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- if (status_code == 0) { +- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); +- result = "Unexpected error."; +- +- result = resultObject.toJsonString(); +- returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- defaultSessionClose(session, status_code, result); +- ++ catch(const WorldAnchorsApiException& e) { ++ std::tie(status_code, result) = handleWorldAnchorsApiException(e); ++ } ++ catch(const std::exception& e) { ++ std::tie(status_code, result) = handleStdException(e); ++ } ++ catch(...) { ++ std::tie(status_code, result) = handleUnspecifiedException(); ++ } ++ ++ std::multimap< std::string, std::string > responseHeaders {}; ++ static const std::vector<std::string> contentTypes{ ++ "application/json", ++ }; ++ static const std::string acceptTypes{ ++ "application/json, " ++ }; ++ ++ if (status_code == 200) { ++ responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes))); ++ if (!acceptTypes.empty()) { ++ responseHeaders.insert(std::make_pair("Accept", acceptTypes)); ++ } ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ if (status_code == 400) { ++ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); ++ result = "Bad request."; ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ if (status_code == 409) { ++ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); ++ result = "Invalid UUID, id must be a Nil value."; ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 409, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ if (status_code == 511) { ++ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); ++ result = "The secret token is not valid. Please ask an ISG ARF team member for a valid token."; ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 511, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ if (status_code == 0) { ++ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); ++ result = "Unexpected error."; ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ defaultSessionClose(session, status_code, result); ++ }); } -@@ -309,8 +325,9 @@ +@@ -313,82 +328,83 @@ // x-extension void WorldAnchorsResource::handler_PUT_internal(const std::shared_ptr<restbed::Session> session) { const auto request = session->get_request(); -+ int content_length = request->get_header("Content-Length", 0); - // body params or form params here from the body content string +- // body params or form params here from the body content string - std::string bodyContent = extractBodyContent(session); +- auto worldAnchor = extractJsonModelBodyParam<WorldAnchor>(bodyContent); +- // Getting the headers +- std::string token = request->get_header("token", ""); +- +- int status_code = 500; +- Success resultObject = Success{}; +- std::string result = ""; +- +- try { +- std::tie(status_code, resultObject) = +- handler_PUT(worldAnchor, token); +- } +- catch(const WorldAnchorsApiException& e) { +- std::tie(status_code, result) = handleWorldAnchorsApiException(e); +- } +- catch(const std::exception& e) { +- std::tie(status_code, result) = handleStdException(e); +- } +- catch(...) { +- std::tie(status_code, result) = handleUnspecifiedException(); +- } +- +- std::multimap< std::string, std::string > responseHeaders {}; +- static const std::vector<std::string> contentTypes{ +- "application/json", +- }; +- static const std::string acceptTypes{ +- "application/json, " +- }; +- +- if (status_code == 200) { +- responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes))); +- if (!acceptTypes.empty()) { +- responseHeaders.insert(std::make_pair("Accept", acceptTypes)); ++ int content_length = request->get_header("Content-Length", 0); ++ + extractBodyContentAsync(session, content_length, [this, session,request](const std::string& bodyContent) { - auto worldAnchor = extractJsonModelBodyParam<WorldAnchor>(bodyContent); - // Getting the headers - std::string token = request->get_header("token", ""); -@@ -386,8 +403,7 @@ - return; - } - defaultSessionClose(session, status_code, result); ++ auto worldAnchor = extractJsonModelBodyParam<WorldAnchor>(bodyContent); ++ // Getting the headers ++ std::string token = request->get_header("token", ""); ++ ++ int status_code = 500; ++ Success resultObject = Success{}; ++ std::string result = ""; ++ ++ try { ++ std::tie(status_code, resultObject) = ++ handler_PUT(worldAnchor, token); + } +- +- result = resultObject.toJsonString(); +- returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- if (status_code == 400) { +- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); +- result = "Bad request."; +- +- result = resultObject.toJsonString(); +- returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- if (status_code == 404) { +- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); +- result = "Not found, could not find UUID in database."; - +- result = resultObject.toJsonString(); +- returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- if (status_code == 511) { +- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); +- result = "The secret token is not valid. Please ask an ISG ARF team member for a valid token."; - +- result = resultObject.toJsonString(); +- returnResponse(session, 511, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- if (status_code == 0) { +- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); +- result = "Unexpected error."; +- +- result = resultObject.toJsonString(); +- returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- defaultSessionClose(session, status_code, result); +- ++ catch(const WorldAnchorsApiException& e) { ++ std::tie(status_code, result) = handleWorldAnchorsApiException(e); ++ } ++ catch(const std::exception& e) { ++ std::tie(status_code, result) = handleStdException(e); ++ } ++ catch(...) { ++ std::tie(status_code, result) = handleUnspecifiedException(); ++ } ++ ++ std::multimap< std::string, std::string > responseHeaders {}; ++ static const std::vector<std::string> contentTypes{ ++ "application/json", ++ }; ++ static const std::string acceptTypes{ ++ "application/json, " ++ }; ++ ++ if (status_code == 200) { ++ responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes))); ++ if (!acceptTypes.empty()) { ++ responseHeaders.insert(std::make_pair("Accept", acceptTypes)); ++ } ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ if (status_code == 400) { ++ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); ++ result = "Bad request."; ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ if (status_code == 404) { ++ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); ++ result = "Not found, could not find UUID in database."; ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ if (status_code == 511) { ++ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); ++ result = "The secret token is not valid. Please ask an ISG ARF team member for a valid token."; ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 511, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ if (status_code == 0) { ++ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); ++ result = "Unexpected error."; ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ defaultSessionClose(session, status_code, result); + }); + } - std::pair<int, Error> WorldAnchorsResource::handler_POST( diff --git a/EtsiServerGen/patches/fixCppWorldLinkModel.patch b/EtsiServerGen/patches/fixCppWorldLinkModel.patch new file mode 100644 index 0000000000000000000000000000000000000000..502c97b09b246567181bf6d46147d8c8b4dbf62e --- /dev/null +++ b/EtsiServerGen/patches/fixCppWorldLinkModel.patch @@ -0,0 +1,22 @@ +--- WorldLink.cpp 2024-09-19 16:49:24.736599495 +0200 ++++ WorldLink_corrected.cpp 2024-09-19 16:49:12.816378721 +0200 +@@ -67,6 +67,9 @@ + pt.put("creatorUUID", m_CreatorUUID); + pt.put("UUIDFrom", m_UUIDFrom); + pt.put("UUIDTo", m_UUIDTo); ++ pt.put("typeFrom", m_TypeFrom.getEnumValue()); ++ pt.put("typeTo", m_TypeTo.getEnumValue()); ++ pt.put("unit", m_Unit.getEnumValue()); + // generate tree for Transform + tmp_node.clear(); + if (!m_Transform.empty()) { +@@ -90,6 +93,9 @@ + m_CreatorUUID = pt.get("creatorUUID", ""); + m_UUIDFrom = pt.get("UUIDFrom", ""); + m_UUIDTo = pt.get("UUIDTo", ""); ++ m_TypeFrom.setEnumValue(pt.get("typeFrom","")); ++ m_TypeTo.setEnumValue(pt.get("typeTo","")); ++ m_Unit.setEnumValue(pt.get("unit","")); + // push all items of Transform into member + if (pt.get_child_optional("transform")) { + m_Transform = fromPt<std::vector<float>>(pt.get_child("transform")); diff --git a/EtsiServerGen/patches/fixCppWorldLinks.patch b/EtsiServerGen/patches/fixCppWorldLinks.patch index c74b39621832383a3573ad241b1c6b8d04ab1be3..63b2f1ed9b095bf06e284c60abe0d44dca4c30b8 100644 --- a/EtsiServerGen/patches/fixCppWorldLinks.patch +++ b/EtsiServerGen/patches/fixCppWorldLinks.patch @@ -1,6 +1,6 @@ ---- WorldLinksApi.cpp 2024-08-30 15:39:14.710928653 +0200 -+++ WorldLinksApi_corrected.cpp 2024-08-30 15:39:10.800920831 +0200 -@@ -159,11 +159,26 @@ +--- WorldLinksApi.cpp 2024-09-19 14:34:27.853783839 +0200 ++++ WorldLinksApi_corrected.cpp 2024-09-19 14:31:59.140606768 +0200 +@@ -159,85 +159,100 @@ session->close(status, result, { {"Connection", "close"} }); } @@ -21,41 +21,317 @@ void WorldLinksResource::handler_POST_internal(const std::shared_ptr<restbed::Session> session) { const auto request = session->get_request(); -+ int content_length = request->get_header("Content-Length", 0); - // body params or form params here from the body content string +- // body params or form params here from the body content string - std::string bodyContent = extractBodyContent(session); +- auto worldLink = extractJsonModelBodyParam<WorldLink>(bodyContent); +- // Getting the headers +- std::string token = request->get_header("token", ""); +- +- int status_code = 500; +- Success resultObject = Success{}; +- std::string result = ""; +- +- try { +- std::tie(status_code, resultObject) = +- handler_POST(worldLink, token); +- } +- catch(const WorldLinksApiException& e) { +- std::tie(status_code, result) = handleWorldLinksApiException(e); +- } +- catch(const std::exception& e) { +- std::tie(status_code, result) = handleStdException(e); +- } +- catch(...) { +- std::tie(status_code, result) = handleUnspecifiedException(); +- } +- +- std::multimap< std::string, std::string > responseHeaders {}; +- static const std::vector<std::string> contentTypes{ +- "application/json", +- }; +- static const std::string acceptTypes{ +- "application/json, " +- }; +- +- if (status_code == 200) { +- responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes))); +- if (!acceptTypes.empty()) { +- responseHeaders.insert(std::make_pair("Accept", acceptTypes)); ++ int content_length = request->get_header("Content-Length", 0); ++ + extractBodyContentAsync(session, content_length, [this, session,request](const std::string& bodyContent) { - auto worldLink = extractJsonModelBodyParam<WorldLink>(bodyContent); - // Getting the headers - std::string token = request->get_header("token", ""); -@@ -239,8 +254,7 @@ - return; - } - defaultSessionClose(session, status_code, result); ++ auto worldLink = extractJsonModelBodyParam<WorldLink>(bodyContent); ++ // Getting the headers ++ std::string token = request->get_header("token", ""); ++ ++ int status_code = 500; ++ Success resultObject = Success{}; ++ std::string result = ""; ++ ++ try { ++ std::tie(status_code, resultObject) = ++ handler_POST(worldLink, token); + } +- +- result = resultObject.toJsonString(); +- returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- if (status_code == 400) { +- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); +- result = "Bad request."; +- +- result = resultObject.toJsonString(); +- returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- if (status_code == 409) { +- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); +- result = "Invalid UUID, id must be a Nil value."; - +- result = resultObject.toJsonString(); +- returnResponse(session, 409, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- if (status_code == 511) { +- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); +- result = "The secret token is not valid. Please ask an ISG ARF team member for a valid token."; - +- result = resultObject.toJsonString(); +- returnResponse(session, 511, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- if (status_code == 0) { +- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); +- result = "Unexpected error."; +- +- result = resultObject.toJsonString(); +- returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- defaultSessionClose(session, status_code, result); +- ++ catch(const WorldLinksApiException& e) { ++ std::tie(status_code, result) = handleWorldLinksApiException(e); ++ } ++ catch(const std::exception& e) { ++ std::tie(status_code, result) = handleStdException(e); ++ } ++ catch(...) { ++ std::tie(status_code, result) = handleUnspecifiedException(); ++ } ++ ++ std::multimap< std::string, std::string > responseHeaders {}; ++ static const std::vector<std::string> contentTypes{ ++ "application/json", ++ }; ++ static const std::string acceptTypes{ ++ "application/json, " ++ }; ++ ++ if (status_code == 200) { ++ responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes))); ++ if (!acceptTypes.empty()) { ++ responseHeaders.insert(std::make_pair("Accept", acceptTypes)); ++ } ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ if (status_code == 400) { ++ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); ++ result = "Bad request."; ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ if (status_code == 409) { ++ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); ++ result = "Invalid UUID, id must be a Nil value."; ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 409, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ if (status_code == 511) { ++ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); ++ result = "The secret token is not valid. Please ask an ISG ARF team member for a valid token."; ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 511, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ if (status_code == 0) { ++ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); ++ result = "Unexpected error."; ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ defaultSessionClose(session, status_code, result); + }); + } - // x-extension -@@ -309,8 +323,9 @@ +@@ -313,82 +328,83 @@ // x-extension void WorldLinksResource::handler_PUT_internal(const std::shared_ptr<restbed::Session> session) { const auto request = session->get_request(); -+ int content_length = request->get_header("Content-Length", 0); - // body params or form params here from the body content string +- // body params or form params here from the body content string - std::string bodyContent = extractBodyContent(session); +- auto worldLink = extractJsonModelBodyParam<WorldLink>(bodyContent); +- // Getting the headers +- std::string token = request->get_header("token", ""); +- +- int status_code = 500; +- Success resultObject = Success{}; +- std::string result = ""; +- +- try { +- std::tie(status_code, resultObject) = +- handler_PUT(worldLink, token); +- } +- catch(const WorldLinksApiException& e) { +- std::tie(status_code, result) = handleWorldLinksApiException(e); +- } +- catch(const std::exception& e) { +- std::tie(status_code, result) = handleStdException(e); +- } +- catch(...) { +- std::tie(status_code, result) = handleUnspecifiedException(); +- } +- +- std::multimap< std::string, std::string > responseHeaders {}; +- static const std::vector<std::string> contentTypes{ +- "application/json", +- }; +- static const std::string acceptTypes{ +- "application/json, " +- }; +- +- if (status_code == 200) { +- responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes))); +- if (!acceptTypes.empty()) { +- responseHeaders.insert(std::make_pair("Accept", acceptTypes)); ++ int content_length = request->get_header("Content-Length", 0); ++ + extractBodyContentAsync(session, content_length, [this, session,request](const std::string& bodyContent) { - auto worldLink = extractJsonModelBodyParam<WorldLink>(bodyContent); - // Getting the headers - std::string token = request->get_header("token", ""); -@@ -386,8 +401,7 @@ - return; - } - defaultSessionClose(session, status_code, result); ++ auto worldLink = extractJsonModelBodyParam<WorldLink>(bodyContent); ++ // Getting the headers ++ std::string token = request->get_header("token", ""); ++ ++ int status_code = 500; ++ Success resultObject = Success{}; ++ std::string result = ""; ++ ++ try { ++ std::tie(status_code, resultObject) = ++ handler_PUT(worldLink, token); + } +- +- result = resultObject.toJsonString(); +- returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- if (status_code == 400) { +- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); +- result = "Bad request."; +- +- result = resultObject.toJsonString(); +- returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- if (status_code == 404) { +- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); +- result = "Not found, could not find UUID in database."; +- +- result = resultObject.toJsonString(); +- returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- if (status_code == 511) { +- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); +- result = "The secret token is not valid. Please ask an ISG ARF team member for a valid token."; +- +- result = resultObject.toJsonString(); +- returnResponse(session, 511, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- if (status_code == 0) { +- responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); +- result = "Unexpected error."; - +- result = resultObject.toJsonString(); +- returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); +- return; +- } +- defaultSessionClose(session, status_code, result); - ++ catch(const WorldLinksApiException& e) { ++ std::tie(status_code, result) = handleWorldLinksApiException(e); ++ } ++ catch(const std::exception& e) { ++ std::tie(status_code, result) = handleStdException(e); ++ } ++ catch(...) { ++ std::tie(status_code, result) = handleUnspecifiedException(); ++ } ++ ++ std::multimap< std::string, std::string > responseHeaders {}; ++ static const std::vector<std::string> contentTypes{ ++ "application/json", ++ }; ++ static const std::string acceptTypes{ ++ "application/json, " ++ }; ++ ++ if (status_code == 200) { ++ responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes))); ++ if (!acceptTypes.empty()) { ++ responseHeaders.insert(std::make_pair("Accept", acceptTypes)); ++ } ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ if (status_code == 400) { ++ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); ++ result = "Bad request."; ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ if (status_code == 404) { ++ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); ++ result = "Not found, could not find UUID in database."; ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ if (status_code == 511) { ++ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); ++ result = "The secret token is not valid. Please ask an ISG ARF team member for a valid token."; ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 511, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ if (status_code == 0) { ++ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); ++ result = "Unexpected error."; ++ ++ result = resultObject.toJsonString(); ++ returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); ++ return; ++ } ++ defaultSessionClose(session, status_code, result); + }); + } - std::pair<int, Error> WorldLinksResource::handler_POST( diff --git a/EtsiServerGen/patches/fixCppWorldLinksModel.patch b/EtsiServerGen/patches/fixCppWorldLinksModel.patch deleted file mode 100644 index f9d2599ba0c5baef7e6322d72c1b5cb1e720e113..0000000000000000000000000000000000000000 --- a/EtsiServerGen/patches/fixCppWorldLinksModel.patch +++ /dev/null @@ -1,24 +0,0 @@ ---- WorldLink.cpp 2024-08-30 15:49:02.321890614 +0200 -+++ WorldLink_corrected.cpp 2024-08-30 15:50:43.262030987 +0200 -@@ -79,8 +79,19 @@ - pt.put("unit", m_Unit); - // generate tree for KeyvalueTags - if (!m_KeyvalueTags.empty()) { -- tmp_node = toPt(m_KeyvalueTags); -- pt.add_child("keyvalueTags", tmp_node); -+ ptree keyvalueTags; -+ for (const auto& kv : m_KeyvalueTags) { -+ ptree tag_node; -+ for (const auto& val : kv.second) { -+ ptree value_node; -+ value_node.put("", "|" + val + "|"); // Ensure value is treated as string -+ tag_node.push_back(std::make_pair("", value_node)); -+ } -+ -+ keyvalueTags.add_child(kv.first,tag_node); -+ -+ } -+ pt.add_child("keyvalueTags", keyvalueTags); - } - tmp_node.clear(); - return pt; diff --git a/EtsiServerGen/patches/fixHelperHeader.patch b/EtsiServerGen/patches/fixHelperHeader.patch deleted file mode 100644 index 9cd269aa543c8df1fd663ca4c4a30d637d278127..0000000000000000000000000000000000000000 --- a/EtsiServerGen/patches/fixHelperHeader.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- ../../../../world-storage-cpp-server/EtsiServerGen/model/helpers.h 2024-04-15 17:47:05.562444771 +0200 -+++ ../model/helpers.h 2024-04-26 11:02:43.147098575 +0200 -@@ -15,7 +15,7 @@ - #define OPENAPI_MODELS_HELPER_H_ - - -- -+#include <boost/property_tree/ptree.hpp> - #include <string> - #include <map> - #include <vector> diff --git a/EtsiServerGen/patches/fixYAMLrestbedSchema.patch b/EtsiServerGen/patches/fixYAMLrestbedSchema.patch deleted file mode 100644 index c39de9c7cd4222562f9f8358813a1a634901f351..0000000000000000000000000000000000000000 --- a/EtsiServerGen/patches/fixYAMLrestbedSchema.patch +++ /dev/null @@ -1,36 +0,0 @@ ---- arf005/API/worldstorage/worldstorageopenapi.yaml 2024-04-26 15:38:19.205331526 +0200 -+++ arf005/API/worldstorage/worldstorageopenapiToPatch.yaml 2024-04-26 16:50:23.200217962 +0200 -@@ -100,16 +100,8 @@ - required: true - schema: - type: array -- uniqueItems: true - items: -- type: object -- properties: -- uuid: -- type: string -- format: uuid -- example: "fa8bbe40-8052-11ec-a8a3-0242ac120002" -- mode: -- $ref: '../common/commonopenapi.yaml#/components/schemas/Mode_WorldStorage' -+ $ref: '#/components/schemas/relocalizationInformationParam' - - - in: query - name: capabilities -@@ -650,6 +642,15 @@ - # Reusable schemas (data models) - #------------------------------- - schemas: -+ RelocalizationInformationParam: -+ properties: -+ uuid: -+ type: string -+ format: uuid -+ example: "fa8bbe40-8052-11ec-a8a3-0242ac120002" -+ mode: -+ $ref: '../common/commonopenapi.yaml#/components/schemas/Mode_WorldStorage' -+ - RelocalizationInformation: - description: An element representing all information needed in relation with a Trackable or a WorldAnchor. - type: object