diff --git a/EtsiServerGen/patches/applyPatches.sh b/EtsiServerGen/patches/applyPatches.sh index 46db8f3f0ee552c3bc0f2b706af9ce763d0b9733..89e9b59de59cdce0e27f11fc2f9f2ae7261bed2d 100755 --- a/EtsiServerGen/patches/applyPatches.sh +++ b/EtsiServerGen/patches/applyPatches.sh @@ -4,4 +4,7 @@ patch -u ../api/DefaultApi.cpp -i fixCppModelIssue.patch patch -u ../api/RelocalizationInformationApi.cpp -i fixRelocInfoJSONIssue.patch patch -u ../api/TrackablesApi.cpp -i fixCppTrackable.patch patch -u ../api/WorldAnchorsApi.cpp -i fixCppWorldAnchor.patch -patch -u ../api/WorldLinksApi.cpp -i fixCppWorldLink.patch \ No newline at end of file +patch -u ../api/WorldLinksApi.cpp -i fixCppWorldLink.patch +patch -u ../model/WorldLink.cpp -i fixCppWorldLinkModel.patch +patch -u ../model/WorldAnchor.cpp -i fixCppWorldAnchorModel.patch +patch -u ../model/Trackable.cpp -i fixCppTrackableModel.patch \ No newline at end of file diff --git a/EtsiServerGen/patches/fixCppTrackable.patch b/EtsiServerGen/patches/fixCppTrackable.patch index 9446cf8267922e34945717ac01170f961008fbab..00072842fe2e0ade8faf7c7f4959202175120f86 100644 --- a/EtsiServerGen/patches/fixCppTrackable.patch +++ b/EtsiServerGen/patches/fixCppTrackable.patch @@ -1,77 +1,240 @@ ---- TrackablesApi.cpp 2024-04-15 17:52:21.000357100 +0200 -+++ TrackablesApi_patched.cpp 2024-04-15 18:08:32.955228320 +0200 -@@ -201,7 +201,7 @@ - } - - result = resultObject; +--- ../../../world-storage-cpp-server/EtsiServerGen/api/TrackablesApi.cpp 2024-04-15 17:47:05.542444638 +0200 ++++ ../api/TrackablesApi.cpp 2024-04-22 18:14:43.144871367 +0200 +@@ -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 @@ + 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,86 +169,102 @@ + 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); -+ returnResponse(session, 200, result, responseHeaders); - return; - } - if (status_code == 201) { -@@ -211,7 +211,7 @@ - } - - result = resultObject; +- 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); -+ returnResponse(session, 201, result, responseHeaders); - return; - } - if (status_code == 400) { -@@ -219,7 +219,7 @@ - result = "Bad request."; - - result = resultObject; +- 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); -+ returnResponse(session, 400, result, responseHeaders); - return; - } - if (status_code == 409) { -@@ -227,15 +227,14 @@ - result = "Invalid UUID, id must be a Nil value."; - - result = resultObject; +- 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); -+ returnResponse(session, 409, result, responseHeaders); - return; - } - if (status_code == 0) { - responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); - result = "Unexpected error."; - +- 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); -@@ -277,8 +276,12 @@ +- 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 +@@ -277,8 +303,11 @@ if (!acceptTypes.empty()) { responseHeaders.insert(std::make_pair("Accept", acceptTypes)); } - - returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); -+ std::string response; -+ for (const Trackable& item :resultObject) { -+ response += item.toJsonString() + ",\n"; ++ std::string rep; ++ for (const Trackable& item : resultObject) { ++ rep += item.toJsonString() + ",\n"; + } -+ -+ returnResponse(session, 200, response, responseHeaders); ++ returnResponse(session, 200, rep, responseHeaders); return; } if (status_code == 201) { -@@ -286,17 +289,18 @@ +@@ -286,17 +315,20 @@ if (!acceptTypes.empty()) { responseHeaders.insert(std::make_pair("Accept", acceptTypes)); } - - result = resultObject; - returnResponse(session, 201, result.empty() ? "{}" : result, responseHeaders); -+ std::string response; -+ for (const Trackable& item :resultObject) { -+ response += item.toJsonString() + ",\n"; ++ std::string rep; ++ for (const Trackable& item : resultObject) { ++ rep += item.toJsonString() + ",\n"; + } -+ returnResponse(session, 201, response, responseHeaders); ++ ++ returnResponse(session, 201, rep, responseHeaders); return; } if (status_code == 0) { @@ -80,33 +243,51 @@ - result = resultObject.toJsonString(); - returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); ++ + returnResponse(session, 0, result, responseHeaders); return; } defaultSessionClose(session, status_code, result); -@@ -343,7 +347,7 @@ +@@ -304,8 +336,11 @@ + // 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", ""); +@@ -342,35 +377,36 @@ + responseHeaders.insert(std::make_pair("Accept", acceptTypes)); } - result = resultObject; +- result = resultObject; - returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); ++ auto result = resultObject; + returnResponse(session, 200, result, responseHeaders); return; } if (status_code == 400) { -@@ -351,7 +355,7 @@ + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); result = "Bad request."; - result = resultObject; +- result = resultObject; - returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); ++ auto result = resultObject; + returnResponse(session, 400, result, responseHeaders); return; } if (status_code == 404) { -@@ -359,15 +363,15 @@ + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); result = "Not found, could not find UUID in database."; - result = resultObject; +- result = resultObject; - returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders); ++ auto result = resultObject; + returnResponse(session, 404, result, responseHeaders); return; } @@ -116,44 +297,79 @@ - result = resultObject.toJsonString(); - returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); -+ result = resultObject; ++ + returnResponse(session, 0, result, responseHeaders); return; } defaultSessionClose(session, status_code, result); -@@ -494,7 +498,7 @@ ++ }); + } + + std::pair<int, std::string> TrackablesResource::handler_POST( +@@ -390,9 +426,13 @@ + return handler_PUT_func(trackable, token); + } + +-std::string TrackablesResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) { ++ ++ ++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, +@@ -400,8 +440,10 @@ + 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); +@@ -493,24 +535,24 @@ + responseHeaders.insert(std::make_pair("Accept", acceptTypes)); } - result = resultObject; +- result = resultObject; - returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); ++ auto result = resultObject; + returnResponse(session, 200, result, responseHeaders); return; } if (status_code == 400) { -@@ -502,7 +506,7 @@ + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); result = "Invalid UUID supplied."; - result = resultObject; +- result = resultObject; - returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); -+ returnResponse(session, 400, result, responseHeaders); ++ auto result = resultObject; ++ returnResponse(session, 400,result, responseHeaders); return; } if (status_code == 404) { -@@ -510,7 +514,7 @@ + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); result = "Not found, could not find UUID in database."; - result = resultObject; +- result = resultObject; - returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders); ++ auto result = resultObject; + returnResponse(session, 404, result, responseHeaders); return; } defaultSessionClose(session, status_code, result); -@@ -556,23 +560,23 @@ +@@ -556,23 +598,23 @@ } result = resultObject.toJsonString(); - returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); -+ returnResponse(session, 200, result, responseHeaders); ++ returnResponse(session, 200,result, responseHeaders); return; } if (status_code == 400) { @@ -162,8 +378,8 @@ - result = resultObject; - returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); -+ result = resultObject.toJsonString(); -+ returnResponse(session, 400, result, responseHeaders); ++ auto result = resultObject; ++ returnResponse(session, 400, "{}", responseHeaders); return; } if (status_code == 404) { @@ -172,8 +388,8 @@ - result = resultObject; - returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders); -+ result = resultObject.toJsonString(); -+ returnResponse(session, 404, result, responseHeaders); ++ auto result = resultObject; ++ returnResponse(session, 404, "{}", responseHeaders); return; } defaultSessionClose(session, status_code, result); diff --git a/EtsiServerGen/patches/fixCppTrackableModel.patch b/EtsiServerGen/patches/fixCppTrackableModel.patch new file mode 100644 index 0000000000000000000000000000000000000000..82d7c08ed1f48793e3bb4e9583195d68919ad76c --- /dev/null +++ b/EtsiServerGen/patches/fixCppTrackableModel.patch @@ -0,0 +1,18 @@ +--- ../../../cpp-server-patch/world-storage-cpp-server/EtsiServerGen/model/Trackable.cpp 2024-04-23 15:04:24.911615729 +0200 ++++ ../model/Trackable.cpp 2024-04-22 18:23:44.610773480 +0200 +@@ -41,6 +41,7 @@ + } + + ++ + std::string Trackable::toJsonString(bool prettyJson /* = false */) const + { + std::stringstream ss; +@@ -51,6 +52,7 @@ + return result; + } + ++ + void Trackable::fromJsonString(std::string const& jsonString) + { + std::stringstream ss(jsonString); diff --git a/EtsiServerGen/patches/fixCppWorldAnchor.patch b/EtsiServerGen/patches/fixCppWorldAnchor.patch index fa4ef23b1a2433980aef419abe8f2085aad1acbc..89128a7972b7b4de6840f36277675b9212acec57 100644 --- a/EtsiServerGen/patches/fixCppWorldAnchor.patch +++ b/EtsiServerGen/patches/fixCppWorldAnchor.patch @@ -1,6 +1,43 @@ ---- WorldAnchorsApi.cpp 2024-04-18 15:54:51.026541100 +0200 -+++ WorldAnchorsApi_patched.cpp 2024-04-11 15:19:00.660580000 +0200 -@@ -234,7 +234,7 @@ +--- ../../../cpp-server-patch/world-storage-cpp-server/EtsiServerGen/api/WorldAnchorsApi.cpp 2024-04-23 11:31:29.141217249 +0200 ++++ ../api/WorldAnchorsApi.cpp 2024-04-22 10:38:47.298434241 +0200 +@@ -20,7 +20,7 @@ + #include <boost/property_tree/json_parser.hpp> + #include <boost/lexical_cast.hpp> + #include <boost/algorithm/string.hpp> +- ++#include <iostream> + #include "WorldAnchorsApi.h" + + namespace org { +@@ -159,11 +159,26 @@ + 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 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 +- std::string bodyContent = extractBodyContent(session); ++ 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", ""); +@@ -234,11 +249,12 @@ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); result = "Unexpected error."; @@ -9,7 +46,12 @@ returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); return; } -@@ -278,7 +278,11 @@ + defaultSessionClose(session, status_code, result); ++ }); + } + + // x-extension +@@ -278,7 +294,11 @@ responseHeaders.insert(std::make_pair("Accept", acceptTypes)); } @@ -22,7 +64,7 @@ return; } if (status_code == 201) { -@@ -287,16 +291,20 @@ +@@ -287,16 +307,20 @@ responseHeaders.insert(std::make_pair("Accept", acceptTypes)); } @@ -47,7 +89,19 @@ return; } defaultSessionClose(session, status_code, result); -@@ -366,8 +374,8 @@ +@@ -304,8 +328,10 @@ + // 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 +- std::string bodyContent = extractBodyContent(session); ++ 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", ""); +@@ -366,11 +392,12 @@ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); result = "Unexpected error."; @@ -58,7 +112,11 @@ return; } defaultSessionClose(session, status_code, result); -@@ -563,7 +571,7 @@ ++ }); + } + + std::pair<int, std::string> WorldAnchorsResource::handler_POST( +@@ -563,7 +590,7 @@ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); result = "Invalid UUID supplied."; @@ -67,7 +125,7 @@ returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); return; } -@@ -571,7 +579,7 @@ +@@ -571,7 +598,7 @@ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); result = "Not found, could not find UUID in database."; @@ -76,3 +134,11 @@ returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders); return; } +@@ -590,6 +617,7 @@ + return handler_GET_func(worldAnchorUUID, token); + } + ++ + std::string WorldAnchorsWorldAnchorUUIDResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) { + const auto request = session->get_request(); + int content_length = request->get_header("Content-Length", 0); diff --git a/EtsiServerGen/patches/fixCppWorldAnchorModel.patch b/EtsiServerGen/patches/fixCppWorldAnchorModel.patch new file mode 100644 index 0000000000000000000000000000000000000000..aec8807c7eae5a4a2982e36c2dbbfae6ccb1f699 --- /dev/null +++ b/EtsiServerGen/patches/fixCppWorldAnchorModel.patch @@ -0,0 +1,18 @@ +--- ../../../cpp-server-patch/world-storage-cpp-server/EtsiServerGen/model/WorldAnchor.cpp 2024-04-23 11:31:29.041217253 +0200 ++++ ../model/WorldAnchor.cpp 2024-04-23 09:52:17.137467999 +0200 +@@ -66,6 +66,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()) { +@@ -95,6 +96,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/fixCppWorldLink.patch b/EtsiServerGen/patches/fixCppWorldLink.patch index 78d18867d4e58df51e83a72906071ebc027d8eb1..66a8a03e893f3834ff2e46367817e76834f1c672 100644 --- a/EtsiServerGen/patches/fixCppWorldLink.patch +++ b/EtsiServerGen/patches/fixCppWorldLink.patch @@ -1,6 +1,34 @@ ---- WorldLinksApi.cpp 2024-04-18 15:57:51.750705600 +0200 -+++ WorldLinksApi_patched.cpp 2024-04-11 15:18:49.350577500 +0200 -@@ -234,8 +234,8 @@ +--- ../../../cpp-server-patch/world-storage-cpp-server/EtsiServerGen/api/WorldLinksApi.cpp 2024-04-23 11:31:29.141217249 +0200 ++++ ../api/WorldLinksApi.cpp 2024-04-22 16:21:40.875779442 +0200 +@@ -159,11 +159,26 @@ + 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 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 +- std::string bodyContent = extractBodyContent(session); ++ 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", ""); +@@ -234,11 +249,12 @@ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); result = "Unexpected error."; @@ -11,21 +39,24 @@ return; } defaultSessionClose(session, status_code, result); -@@ -278,8 +278,11 @@ ++ }); + } + + // x-extension +@@ -278,7 +294,11 @@ responseHeaders.insert(std::make_pair("Accept", acceptTypes)); } - returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); -- return; + std::string rep; + for (const WorldLink& item : resultObject) { + rep += item.toJsonString() + ",\n"; + } -+ returnResponse(session, 200, rep, responseHeaders); return; ++ returnResponse(session, 200, rep, responseHeaders); + return; } if (status_code == 201) { - responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes))); -@@ -287,16 +290,20 @@ +@@ -287,16 +307,20 @@ responseHeaders.insert(std::make_pair("Accept", acceptTypes)); } @@ -50,7 +81,19 @@ return; } defaultSessionClose(session, status_code, result); -@@ -366,8 +373,8 @@ +@@ -304,8 +328,10 @@ + // 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 +- std::string bodyContent = extractBodyContent(session); ++ 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", ""); +@@ -366,11 +392,12 @@ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); result = "Unexpected error."; @@ -61,7 +104,11 @@ return; } defaultSessionClose(session, status_code, result); -@@ -563,16 +570,16 @@ ++ }); + } + + std::pair<int, std::string> WorldLinksResource::handler_POST( +@@ -563,16 +590,16 @@ responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); result = "Invalid UUID supplied."; diff --git a/EtsiServerGen/patches/fixCppWorldLinkModel.patch b/EtsiServerGen/patches/fixCppWorldLinkModel.patch new file mode 100644 index 0000000000000000000000000000000000000000..90ec552c2e732739bb81218fadef7825e9848377 --- /dev/null +++ b/EtsiServerGen/patches/fixCppWorldLinkModel.patch @@ -0,0 +1,21 @@ +--- ../../../cpp-server-patch/world-storage-cpp-server/EtsiServerGen/model/WorldLink.cpp 2024-04-23 11:31:29.041217253 +0200 ++++ ../model/WorldLink.cpp 2024-04-23 11:01:03.955841667 +0200 +@@ -67,6 +67,8 @@ + 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()); + // generate tree for Transform + tmp_node.clear(); + if (!m_Transform.empty()) { +@@ -90,6 +92,9 @@ + m_CreatorUUID = pt.get("creatorUUID", ""); + m_UUIDFrom = pt.get("UUIDFrom", ""); + m_UUIDTo = pt.get("UUIDTo", ""); ++ m_Unit.setEnumValue(pt.get("unit","")); ++ m_TypeFrom.setEnumValue(pt.get("typeFrom", "")); ++ m_TypeTo.setEnumValue(pt.get("typeTo", "")); + // 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/fixHeaderModelIssue.patch b/EtsiServerGen/patches/fixHeaderModelIssue.patch index ae478ee80e152c43ba0468b6a2c82edf4d2bbbef..46478a160ab81ea3f847360d271fc82f9b04daf8 100644 --- a/EtsiServerGen/patches/fixHeaderModelIssue.patch +++ b/EtsiServerGen/patches/fixHeaderModelIssue.patch @@ -1,5 +1,5 @@ ---- ../api/DefaultApi.h 2024-04-15 16:10:32.793819920 +0200 -+++ ../api/DefaultApi.h 2024-04-15 16:15:52.916456642 +0200 +--- ../../../cpp-server-patch/world-storage-cpp-server/EtsiServerGen/api/DefaultApi.h 2024-04-23 15:28:41.844636318 +0200 ++++ DefaultApi.h 2024-04-23 15:29:43.295897540 +0200 @@ -38,8 +38,6 @@ namespace server { namespace api { @@ -8,4 +8,4 @@ - /// /// Exception to flag problems in the handlers - /// \ No newline at end of file + ///