Skip to content
Snippets Groups Projects
Commit a23e01e7 authored by Jerome Royan's avatar Jerome Royan
Browse files

Merge branch 'fix/RestBed_Generation' into 'develop'

fix: uniqueItem for array reactivated: Work around found to use std::vector...

See merge request !4
parents 2879534b e9ac77fa
No related branches found
No related tags found
3 merge requests!6Correction of many fixes,!5force the use of version 6.6.0 of openapi-generator-cli due to a bug since...,!4fix: uniqueItem for array reactivated: Work around found to use std::vector...
Showing
with 858 additions and 985 deletions
[requires] [requires]
boost/1.78.0 boost/1.84.0
restbed/4.8 restbed/4.8
[generators] [generators]
......
#!/bin/bash #!/bin/bash
patch -u ../api/DefaultApi.h -i fixHeaderModelIssue.patch patch -u ../api/DefaultApi.h -i fixHeaderModelIssue.patch
patch -u ../api/DefaultApi.cpp -i fixCppModelIssue.patch patch -u ../api/DefaultApi.cpp -i fixCppModelIssue.patch
patch -u ../api/TrackablesApi.cpp -i fixCppTrackable.patch patch -u ../api/RelocalizationInformationApi.cpp -i fixCppRelocalizationInformation.patch
patch -u ../api/TrackablesApi.cpp -i fixCppTrackables.patch
patch -u ../api/WorldAnchorsApi.cpp -i fixCppWorldAnchors.patch patch -u ../api/WorldAnchorsApi.cpp -i fixCppWorldAnchors.patch
patch -u ../api/WorldLinksApi.cpp -i fixCppWorldLinks.patch patch -u ../api/WorldLinksApi.cpp -i fixCppWorldLinks.patch
patch -u ../api/RelocalizationInformationApi.cpp -i fixCppRelocalizationInformation.patch
patch -u ../model/WorldLink.cpp -i fixCppWorldLinksModel.patch
patch -u ../model/WorldAnchor.cpp -i fixCppWorldAnchorModel.patch
patch -u ../model/Trackable.cpp -i fixCppTrackableModel.patch
patch -u ../model/helpers.h -i fixHelperHeader.patch
patch -u ../model/RelocalizationInformation.cpp -i fixCppRelocalizationInformationModel.patch
patch -u ../model/RelocalizationInformationParam.cpp -i fixCppRelocalizationInformationParamModel.patch
patch -u ../model/GetRelocalizationInformation_200_response.cpp -i fixCppGetRelocResponse.patch
patch -u ../model/Capability.cpp -i fixCppCapabilityModel.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/model/Capability.cpp b/../../world-storage-cpp-server/EtsiServerGen/model/Capability.cpp --- Capability.cpp 2024-09-19 23:18:16.290090280 +0200
index 8df709d..442bc9d 100644 +++ Capability-corrected.cpp 2024-09-20 13:40:09.082949533 +0200
--- a/EtsiServerGen/model/Capability.cpp @@ -63,7 +63,8 @@
+++ b/../../world-storage-cpp-server/EtsiServerGen/model/Capability.cpp
@@ -63,6 +63,7 @@ ptree Capability::toPropertyTree() const
{ {
ptree pt; ptree pt;
ptree tmp_node; 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("framerate", m_Framerate);
pt.put("latency", m_Latency); 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) void Capability::fromPropertyTree(ptree const &pt)
{ {
ptree tmp_node; 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_EncodingInformation = fromPt<EncodingInformationStructure>(pt.get_child("encodingInformation"));
} }
m_Framerate = pt.get("framerate", 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/api/RelocalizationInformationApi.cpp b/../../world-storage-cpp-server/EtsiServerGen/api/RelocalizationInformationApi.cpp --- RelocalizationInformationApi.cpp 2024-09-19 22:57:54.664539447 +0200
index f332ad2..6ba51b8 100644 +++ RelocalizationInformationApi_corrected.cpp 2024-09-19 22:57:22.213975949 +0200
--- a/EtsiServerGen/api/RelocalizationInformationApi.cpp @@ -157,16 +157,12 @@
+++ b/../../world-storage-cpp-server/EtsiServerGen/api/RelocalizationInformationApi.cpp
@@ -22,7 +22,7 @@
#include <boost/algorithm/string.hpp>
#include "RelocalizationInformationApi.h"
-
+#include <iostream>
namespace org {
namespace openapitools {
namespace server {
@@ -155,21 +155,28 @@ void RelocalizationInformationResource::defaultSessionClose(const std::shared_pt
void RelocalizationInformationResource::handler_GET_internal(const std::shared_ptr<restbed::Session> session)
{ {
+
const auto request = session->get_request(); const auto request = session->get_request();
// Getting the query params // Getting the query params
- std::string uuids_raw = request->get_query_parameter("uuids"); - std::string uuids_raw = request->get_query_parameter("uuids");
+ std::multimap<std::string, std::string> uuids_raw = request->get_query_parameters("uuids"); + std::multimap<std::string, std::string> uuids_raw = request->get_query_parameters("uuids");
std::vector<RelocalizationInformationParam> uuids; std::vector<UuidAndMode> uuids;
- std::vector<std::string> uuids_temp; - std::vector<std::string> uuids_temp;
- boost::split(uuids_temp, uuids_raw, boost::is_any_of(",")); - 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){ RelocalizationInformationParam ret; ret.fromString(i); return ret;}); - std::transform(uuids_temp.begin(), uuids_temp.end(), std::back_inserter(uuids), [](const auto& i){ UuidAndMode ret; ret.fromString(i); return ret;});
- std::string capabilities_raw = request->get_query_parameter("capabilities"); - std::string capabilities_raw = request->get_query_parameter("capabilities");
+ for (auto it = uuids_raw.begin(); it != uuids_raw.end(); it++) + std::transform(uuids_raw.begin(), uuids_raw.end(), std::back_inserter(uuids), [](const auto& i){ UuidAndMode ret; ret.fromJsonString(i.second); return ret;});
+ {
+ RelocalizationInformationParam relocInformationParam;
+ relocInformationParam.fromJsonString(it->second);
+ uuids.push_back(relocInformationParam);
+ }
+ std::multimap<std::string, std::string> capabilities_raw = request->get_query_parameters("capabilities"); + std::multimap<std::string, std::string> capabilities_raw = request->get_query_parameters("capabilities");
std::vector<Capability> capabilities; std::vector<Capability> capabilities;
- std::vector<std::string> capabilities_temp; - std::vector<std::string> capabilities_temp;
- boost::split(capabilities_temp, capabilities_raw, boost::is_any_of(",")); - 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.fromString(i); return ret;});
+ for (auto it = capabilities_raw.begin(); it != capabilities_raw.end(); it++) + std::transform(capabilities_raw.begin(), capabilities_raw.end(), std::back_inserter(capabilities), [](const auto& i){ Capability ret; ret.fromJsonString(i.second); return ret;});
+ {
+ Capability capability;
+ capability.fromJsonString(it->second);
+ capabilities.push_back(capability);
+ }
// Getting the headers // Getting the headers
std::string token = request->get_header("token", ""); std::string token = request->get_header("token", "");
-
+
int status_code = 500;
GetRelocalizationInformation_200_response resultObject = GetRelocalizationInformation_200_response{};
std::string result = "";
@@ -202,22 +209,22 @@ void RelocalizationInformationResource::handler_GET_internal(const std::shared_p
}
result = resultObject.toJsonString();
- returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders);
+ returnResponse(session, 200, result.empty() ? "empty" : result, responseHeaders);
return;
}
if (status_code == 400) {
responseHeaders.insert(std::make_pair("Content-Type", "text/plain"));
result = "Invalid UUID supplied.";
- result = resultObject;
+ 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 = "Not found, could not find UUID or Supported content in database.";
- result = resultObject;
+
returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders);
return;
}
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/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/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/model/Trackable.cpp b/../../world-storage-cpp-server/EtsiServerGen/model/Trackable.cpp --- Trackable.cpp 2024-09-19 16:25:49.067872578 +0200
index de65bd0..26bc26d 100644 +++ Trackable_corrected.cpp 2024-09-19 16:18:02.183949340 +0200
--- a/EtsiServerGen/model/Trackable.cpp @@ -48,6 +48,7 @@
+++ b/../../world-storage-cpp-server/EtsiServerGen/model/Trackable.cpp
@@ -41,6 +41,7 @@ Trackable::Trackable(boost::property_tree::ptree const& pt)
}
+
std::string Trackable::toJsonString(bool prettyJson /* = false */) const
{
std::stringstream ss;
@@ -48,9 +49,12 @@ std::string Trackable::toJsonString(bool prettyJson /* = false */) const
// workaround inspired by: https://stackoverflow.com/a/56395440 // workaround inspired by: https://stackoverflow.com/a/56395440
std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\""); std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\"");
std::string result = std::regex_replace(ss.str(), reg, "$1"); std::string result = std::regex_replace(ss.str(), reg, "$1");
+
+ result.erase(std::remove(result.begin(), result.end(), '|'), result.end()); + result.erase(std::remove(result.begin(), result.end(), '|'), result.end());
return result; return result;
} }
+ @@ -65,7 +66,10 @@
void Trackable::fromJsonString(std::string const& jsonString)
{
std::stringstream ss(jsonString);
@@ -65,7 +69,10 @@ ptree Trackable::toPropertyTree() const
ptree tmp_node; ptree tmp_node;
pt.put("UUID", m_UUID); pt.put("UUID", m_UUID);
pt.put("name", m_Name); pt.put("name", m_Name);
...@@ -34,7 +19,7 @@ index de65bd0..26bc26d 100644 ...@@ -34,7 +19,7 @@ index de65bd0..26bc26d 100644
pt.add_child("trackableEncodingInformation", m_TrackableEncodingInformation.toPropertyTree()); pt.add_child("trackableEncodingInformation", m_TrackableEncodingInformation.toPropertyTree());
// generate tree for LocalCRS // generate tree for LocalCRS
tmp_node.clear(); tmp_node.clear();
@@ -83,9 +90,22 @@ ptree Trackable::toPropertyTree() const @@ -83,8 +87,19 @@
} }
// generate tree for KeyvalueTags // generate tree for KeyvalueTags
if (!m_KeyvalueTags.empty()) { if (!m_KeyvalueTags.empty()) {
...@@ -52,29 +37,27 @@ index de65bd0..26bc26d 100644 ...@@ -52,29 +37,27 @@ index de65bd0..26bc26d 100644
+ keyvalueTags.add_child(kv.first,tag_node); + keyvalueTags.add_child(kv.first,tag_node);
+ +
+ } + }
+ pt.add_child("keyvalueTags", keyvalueTags); + pt.add_child("keyvalueTags", keyvalueTags);
} }
+
+
tmp_node.clear(); tmp_node.clear();
pt.put("confidence", m_Confidence); pt.put("confidence", m_Confidence);
return pt; @@ -96,6 +111,9 @@
@@ -96,6 +116,8 @@ void Trackable::fromPropertyTree(ptree const &pt)
ptree tmp_node; ptree tmp_node;
m_UUID = pt.get("UUID", ""); m_UUID = pt.get("UUID", "");
m_Name = pt.get("name", ""); m_Name = pt.get("name", "");
+ m_TrackableType.setEnumValue(pt.get("trackableType","")); + m_TrackableType.setEnumValue(pt.get("trackableType",""));
+ m_Unit.setEnumValue(pt.get("unit","")); + m_Unit.setEnumValue(pt.get("unit",""));
+
m_CreatorUUID = pt.get("creatorUUID", ""); m_CreatorUUID = pt.get("creatorUUID", "");
if (pt.get_child_optional("trackableEncodingInformation")) { if (pt.get_child_optional("trackableEncodingInformation")) {
m_TrackableEncodingInformation = fromPt<EncodingInformationStructure>(pt.get_child("trackableEncodingInformation")); m_TrackableEncodingInformation = fromPt<EncodingInformationStructure>(pt.get_child("trackableEncodingInformation"));
@@ -111,6 +133,9 @@ void Trackable::fromPropertyTree(ptree const &pt) @@ -111,6 +129,9 @@
if (pt.get_child_optional("keyvalueTags")) { if (pt.get_child_optional("keyvalueTags")) {
m_KeyvalueTags = fromPt<std::map<std::string, std::vector<std::string>>>(pt.get_child("keyvalueTags")); m_KeyvalueTags = fromPt<std::map<std::string, std::vector<std::string>>>(pt.get_child("keyvalueTags"));
} }
+ if (pt.get_child_optional("trackablePayload")) { + if (pt.get_child_optional("trackablePayload")) {
+ m_TrackablePayload = fromPt<std::string>(pt.get_child("trackablePayload")); + m_TrackablePayload = fromPt<std::string>(pt.get_child("trackablePayload"));
+ } + }
m_Confidence = pt.get("confidence", 0.0); m_Confidence = pt.get("confidence", 0.0);
} }
--- 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
--- 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/model/WorldAnchor.cpp b/../../world-storage-cpp-server/EtsiServerGen/model/WorldAnchor.cpp --- WorldAnchor.cpp 2024-09-19 16:26:22.388046412 +0200
index a26966d..9bf2ac1 100644 +++ WorldAnchor_corrected.cpp 2024-09-19 16:35:37.881343480 +0200
--- a/EtsiServerGen/model/WorldAnchor.cpp @@ -48,6 +48,7 @@
+++ b/../../world-storage-cpp-server/EtsiServerGen/model/WorldAnchor.cpp
@@ -48,6 +48,8 @@ std::string WorldAnchor::toJsonString(bool prettyJson /* = false */) const
// workaround inspired by: https://stackoverflow.com/a/56395440 // workaround inspired by: https://stackoverflow.com/a/56395440
std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\""); std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\"");
std::string result = std::regex_replace(ss.str(), reg, "$1"); std::string result = std::regex_replace(ss.str(), reg, "$1");
+ result.erase(std::remove(result.begin(), result.end(), '|'), result.end()); + result.erase(std::remove(result.begin(), result.end(), '|'), result.end());
+
return result; return result;
} }
@@ -66,6 +68,7 @@ ptree WorldAnchor::toPropertyTree() const @@ -66,6 +67,7 @@
pt.put("UUID", m_UUID); pt.put("UUID", m_UUID);
pt.put("name", m_Name); pt.put("name", m_Name);
pt.put("creatorUUID", m_CreatorUUID); pt.put("creatorUUID", m_CreatorUUID);
...@@ -19,7 +16,7 @@ index a26966d..9bf2ac1 100644 ...@@ -19,7 +16,7 @@ index a26966d..9bf2ac1 100644
// generate tree for LocalCRS // generate tree for LocalCRS
tmp_node.clear(); tmp_node.clear();
if (!m_LocalCRS.empty()) { if (!m_LocalCRS.empty()) {
@@ -82,8 +85,19 @@ ptree WorldAnchor::toPropertyTree() const @@ -82,8 +84,17 @@
} }
// generate tree for KeyvalueTags // generate tree for KeyvalueTags
if (!m_KeyvalueTags.empty()) { if (!m_KeyvalueTags.empty()) {
...@@ -33,15 +30,13 @@ index a26966d..9bf2ac1 100644 ...@@ -33,15 +30,13 @@ index a26966d..9bf2ac1 100644
+ value_node.put("", "|" + val + "|"); // Ensure value is treated as string + value_node.put("", "|" + val + "|"); // Ensure value is treated as string
+ tag_node.push_back(std::make_pair("", value_node)); + 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); + pt.add_child("keyvalueTags", keyvalueTags);
} }
tmp_node.clear(); tmp_node.clear();
return pt; return pt;
@@ -95,6 +109,7 @@ void WorldAnchor::fromPropertyTree(ptree const &pt) @@ -95,6 +106,7 @@
m_UUID = pt.get("UUID", ""); m_UUID = pt.get("UUID", "");
m_Name = pt.get("name", ""); m_Name = pt.get("name", "");
m_CreatorUUID = pt.get("creatorUUID", ""); m_CreatorUUID = pt.get("creatorUUID", "");
......
diff --git a/EtsiServerGen/api/WorldAnchorsApi.cpp b/../../world-storage-cpp-server/EtsiServerGen/api/WorldAnchorsApi.cpp --- WorldAnchorsApi.cpp 2024-09-19 14:34:27.853783839 +0200
index 4d56ab8..36119b5 100644 +++ WorldAnchorsApi_corrected.cpp 2024-09-19 14:34:04.503291590 +0200
--- a/EtsiServerGen/api/WorldAnchorsApi.cpp @@ -159,85 +159,100 @@
+++ b/../../world-storage-cpp-server/EtsiServerGen/api/WorldAnchorsApi.cpp
@@ -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,27 @@ void WorldAnchorsResource::defaultSessionClose(const std::shared_ptr<restbed::Se
session->close(status, result, { {"Connection", "close"} }); session->close(status, result, { {"Connection", "close"} });
} }
...@@ -32,139 +21,317 @@ index 4d56ab8..36119b5 100644 ...@@ -32,139 +21,317 @@ index 4d56ab8..36119b5 100644
void WorldAnchorsResource::handler_POST_internal(const std::shared_ptr<restbed::Session> session) void WorldAnchorsResource::handler_POST_internal(const std::shared_ptr<restbed::Session> session)
{ {
const auto request = session->get_request(); 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); - std::string bodyContent = extractBodyContent(session);
+ extractBodyContentAsync(session, content_length, [this, session,request](const std::string& bodyContent) { - auto worldAnchor = extractJsonModelBodyParam<WorldAnchor>(bodyContent);
auto worldAnchor = extractJsonModelBodyParam<WorldAnchor>(bodyContent); - // Getting the headers
// Getting the headers - std::string token = request->get_header("token", "");
std::string token = request->get_header("token", "");
@@ -234,13 +250,12 @@ void WorldAnchorsResource::handler_POST_internal(const std::shared_ptr<restbed::
responseHeaders.insert(std::make_pair("Content-Type", "text/plain"));
result = "Unexpected error.";
- result = resultObject.toJsonString();
+ result = resultObject;
returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders);
return;
}
defaultSessionClose(session, status_code, result);
- -
- int status_code = 500;
- Success resultObject = Success{};
- std::string result = "";
- -
+ }); - try {
} - std::tie(status_code, resultObject) =
- handler_POST(worldAnchor, token);
// x-extension - }
@@ -280,7 +295,17 @@ void WorldAnchorsResource::handler_GET_internal(const std::shared_ptr<restbed::S - catch(const WorldAnchorsApiException& e) {
responseHeaders.insert(std::make_pair("Accept", acceptTypes)); - std::tie(status_code, result) = handleWorldAnchorsApiException(e);
} - }
- catch(const std::exception& e) {
- returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); - std::tie(status_code, result) = handleStdException(e);
+ std::string rep = "[\n"; - }
+ for (const WorldAnchor& item : resultObject) { - catch(...) {
+ rep += item.toJsonString() + ",\n"; - 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);
+ +
+ if (!resultObject.empty()) { + extractBodyContentAsync(session, content_length, [this, session,request](const std::string& bodyContent) {
+ + auto worldAnchor = extractJsonModelBodyParam<WorldAnchor>(bodyContent);
+ rep = rep.substr(0, rep.size() - 2); + // Getting the headers
+ } + std::string token = request->get_header("token", "");
+ rep += "\n]"; +
+ returnResponse(session, 200, rep, responseHeaders); + int status_code = 500;
return; + Success resultObject = Success{};
} + std::string result = "";
if (status_code == 201) { +
@@ -289,16 +314,19 @@ void WorldAnchorsResource::handler_GET_internal(const std::shared_ptr<restbed::S + try {
responseHeaders.insert(std::make_pair("Accept", acceptTypes)); + std::tie(status_code, resultObject) =
+ handler_POST(worldAnchor, token);
} }
-
- result = resultObject; - result = resultObject.toJsonString();
- returnResponse(session, 201, result.empty() ? "{}" : result, responseHeaders); - returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders);
+ std::string rep; - return;
+ for (const WorldAnchor& item : resultObject) { - }
+ rep += item.toJsonString() + ",\n"; - if (status_code == 400) {
+ } - responseHeaders.insert(std::make_pair("Content-Type", "text/plain"));
+ - result = "Bad request.";
+ returnResponse(session, 201, rep, responseHeaders); -
return; - result = resultObject.toJsonString();
} - returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders);
if (status_code == 0) { - return;
responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); - }
result = "Unexpected error."; - 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(); - result = resultObject.toJsonString();
- returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); - returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders);
+ returnResponse(session, 0, result, responseHeaders); - return;
return; - }
} - defaultSessionClose(session, status_code, result);
defaultSessionClose(session, status_code, result); -
@@ -308,8 +336,10 @@ void WorldAnchorsResource::handler_GET_internal(const std::shared_ptr<restbed::S + 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);
+ });
}
@@ -313,82 +328,83 @@
// x-extension // x-extension
void WorldAnchorsResource::handler_PUT_internal(const std::shared_ptr<restbed::Session> session) { void WorldAnchorsResource::handler_PUT_internal(const std::shared_ptr<restbed::Session> session) {
const auto request = session->get_request(); const auto request = session->get_request();
- // 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); + int content_length = request->get_header("Content-Length", 0);
+ +
// body params or form params here from the body content string + extractBodyContentAsync(session, content_length, [this, session,request](const std::string& bodyContent) {
- std::string bodyContent = extractBodyContent(session); + auto worldAnchor = extractJsonModelBodyParam<WorldAnchor>(bodyContent);
+ extractBodyContentAsync(session, content_length, [this, session,request](const std::string& bodyContent) { + // Getting the headers
auto worldAnchor = extractJsonModelBodyParam<WorldAnchor>(bodyContent); + std::string token = request->get_header("token", "");
// Getting the headers +
std::string token = request->get_header("token", ""); + int status_code = 500;
@@ -370,13 +400,11 @@ void WorldAnchorsResource::handler_PUT_internal(const std::shared_ptr<restbed::S + Success resultObject = Success{};
responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + std::string result = "";
result = "Unexpected error."; +
+ try {
+ std::tie(status_code, resultObject) =
+ handler_PUT(worldAnchor, token);
}
-
- result = resultObject.toJsonString(); - result = resultObject.toJsonString();
- returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); - returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders);
+ returnResponse(session, 0, result, responseHeaders); - return;
return; - }
} - if (status_code == 400) {
defaultSessionClose(session, status_code, result); - 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;
std::pair<int, std::string> WorldAnchorsResource::handler_POST( - }
@@ -507,7 +535,6 @@ void WorldAnchorsWorldAnchorUUIDResource::handler_DELETE_internal(const std::sha - if (status_code == 511) {
responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); - responseHeaders.insert(std::make_pair("Content-Type", "text/plain"));
result = "Invalid UUID supplied."; - result = "The secret token is not valid. Please ask an ISG ARF team member for a valid token.";
-
- result = resultObject; - result = resultObject.toJsonString();
returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); - returnResponse(session, 511, result.empty() ? "{}" : result, responseHeaders);
return; - return;
} - }
@@ -515,7 +542,6 @@ void WorldAnchorsWorldAnchorUUIDResource::handler_DELETE_internal(const std::sha - if (status_code == 0) {
responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); - responseHeaders.insert(std::make_pair("Content-Type", "text/plain"));
result = "Not found, could not find UUID in database."; - result = "Unexpected error.";
-
- result = resultObject; - result = resultObject.toJsonString();
returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders); - returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders);
return; - return;
} - }
@@ -571,7 +597,6 @@ void WorldAnchorsWorldAnchorUUIDResource::handler_GET_internal(const std::shared - defaultSessionClose(session, status_code, result);
responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); -
result = "Invalid UUID supplied."; + catch(const WorldAnchorsApiException& e) {
+ std::tie(status_code, result) = handleWorldAnchorsApiException(e);
- result = resultObject; + }
returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); + catch(const std::exception& e) {
return; + std::tie(status_code, result) = handleStdException(e);
} + }
@@ -579,7 +604,7 @@ void WorldAnchorsWorldAnchorUUIDResource::handler_GET_internal(const std::shared + catch(...) {
responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + std::tie(status_code, result) = handleUnspecifiedException();
result = "Not found, could not find UUID in database."; + }
+
+ 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);
+ });
- result = resultObject;
+
returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders);
return;
}
@@ -600,6 +625,7 @@ std::pair<int, WorldAnchor> WorldAnchorsWorldAnchorUUIDResource::handler_GET(
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);
--- 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/api/WorldLinksApi.cpp b/../../world-storage-cpp-server/EtsiServerGen/api/WorldLinksApi.cpp --- WorldLinksApi.cpp 2024-09-19 14:34:27.853783839 +0200
index 543a4ba..589cd28 100644 +++ WorldLinksApi_corrected.cpp 2024-09-19 14:31:59.140606768 +0200
--- a/EtsiServerGen/api/WorldLinksApi.cpp @@ -159,85 +159,100 @@
+++ b/../../world-storage-cpp-server/EtsiServerGen/api/WorldLinksApi.cpp
@@ -159,11 +159,27 @@ void WorldLinksResource::defaultSessionClose(const std::shared_ptr<restbed::Sess
session->close(status, result, { {"Connection", "close"} }); session->close(status, result, { {"Connection", "close"} });
} }
...@@ -23,119 +21,317 @@ index 543a4ba..589cd28 100644 ...@@ -23,119 +21,317 @@ index 543a4ba..589cd28 100644
void WorldLinksResource::handler_POST_internal(const std::shared_ptr<restbed::Session> session) void WorldLinksResource::handler_POST_internal(const std::shared_ptr<restbed::Session> session)
{ {
const auto request = session->get_request(); const auto request = session->get_request();
- // 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); + 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) { + extractBodyContentAsync(session, content_length, [this, session,request](const std::string& bodyContent) {
auto worldLink = extractJsonModelBodyParam<WorldLink>(bodyContent); + auto worldLink = extractJsonModelBodyParam<WorldLink>(bodyContent);
// Getting the headers + // Getting the headers
std::string token = request->get_header("token", ""); + std::string token = request->get_header("token", "");
@@ -234,13 +250,11 @@ void WorldLinksResource::handler_POST_internal(const std::shared_ptr<restbed::Se +
responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + int status_code = 500;
result = "Unexpected error."; + Success resultObject = Success{};
+ std::string result = "";
+
+ try {
+ std::tie(status_code, resultObject) =
+ handler_POST(worldLink, token);
}
-
- result = resultObject.toJsonString(); - result = resultObject.toJsonString();
- returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); - returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders);
+ returnResponse(session, 0, result, responseHeaders); - return;
return; - }
} - if (status_code == 400) {
defaultSessionClose(session, status_code, result); - 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;
// x-extension - }
@@ -280,7 +294,16 @@ void WorldLinksResource::handler_GET_internal(const std::shared_ptr<restbed::Ses - if (status_code == 511) {
responseHeaders.insert(std::make_pair("Accept", acceptTypes)); - 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.";
-
- returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); - result = resultObject.toJsonString();
+ std::string rep = "[\n"; - returnResponse(session, 511, result.empty() ? "{}" : result, responseHeaders);
+ for (const WorldLink& item : resultObject) { - return;
+ rep += item.toJsonString() + ",\n"; - }
- 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);
+ } + }
+ if (!resultObject.empty()) { + 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));
+ }
+ +
+ rep = rep.substr(0, rep.size() - 2); + result = resultObject.toJsonString();
+ returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders);
+ return;
+ } + }
+ rep += "\n]"; + if (status_code == 400) {
+ returnResponse(session, 200, rep, responseHeaders); + responseHeaders.insert(std::make_pair("Content-Type", "text/plain"));
return; + result = "Bad request.";
} +
if (status_code == 201) { + result = resultObject.toJsonString();
@@ -289,16 +312,19 @@ void WorldLinksResource::handler_GET_internal(const std::shared_ptr<restbed::Ses + returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders);
responseHeaders.insert(std::make_pair("Accept", acceptTypes)); + return;
} + }
+ if (status_code == 409) {
- result = resultObject; + responseHeaders.insert(std::make_pair("Content-Type", "text/plain"));
- returnResponse(session, 201, result.empty() ? "{}" : result, responseHeaders); + result = "Invalid UUID, id must be a Nil value.";
+ std::string rep; +
+ for (const WorldLink& item : resultObject) { + result = resultObject.toJsonString();
+ rep += item.toJsonString() + ",\n"; + returnResponse(session, 409, result.empty() ? "{}" : result, responseHeaders);
+ } + return;
+ + }
+ returnResponse(session, 201, rep, responseHeaders); + if (status_code == 511) {
return; + 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.";
if (status_code == 0) { +
responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + result = resultObject.toJsonString();
result = "Unexpected error."; + 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);
+ });
- result = resultObject.toJsonString(); }
- returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders);
+ returnResponse(session, 0, result, responseHeaders); @@ -313,82 +328,83 @@
return;
}
defaultSessionClose(session, status_code, result);
@@ -308,8 +334,10 @@ void WorldLinksResource::handler_GET_internal(const std::shared_ptr<restbed::Ses
// x-extension // x-extension
void WorldLinksResource::handler_PUT_internal(const std::shared_ptr<restbed::Session> session) { void WorldLinksResource::handler_PUT_internal(const std::shared_ptr<restbed::Session> session) {
const auto request = session->get_request(); const auto request = session->get_request();
- // 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); + int content_length = request->get_header("Content-Length", 0);
+ +
// body params or form params here from the body content string + extractBodyContentAsync(session, content_length, [this, session,request](const std::string& bodyContent) {
- std::string bodyContent = extractBodyContent(session); + auto worldLink = extractJsonModelBodyParam<WorldLink>(bodyContent);
+ extractBodyContentAsync(session, content_length, [this, session,request](const std::string& bodyContent) { + // Getting the headers
auto worldLink = extractJsonModelBodyParam<WorldLink>(bodyContent); + std::string token = request->get_header("token", "");
// Getting the headers +
std::string token = request->get_header("token", ""); + int status_code = 500;
@@ -370,13 +398,11 @@ void WorldLinksResource::handler_PUT_internal(const std::shared_ptr<restbed::Ses + Success resultObject = Success{};
responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + std::string result = "";
result = "Unexpected error."; +
+ try {
+ std::tie(status_code, resultObject) =
+ handler_PUT(worldLink, token);
}
-
- result = resultObject.toJsonString(); - result = resultObject.toJsonString();
- returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); - returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders);
+ returnResponse(session, 0, result, responseHeaders); - return;
return; - }
} - if (status_code == 400) {
defaultSessionClose(session, status_code, result); - 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, std::string> WorldLinksResource::handler_POST(
@@ -570,17 +596,15 @@ void WorldLinksWorldLinkUUIDResource::handler_GET_internal(const std::shared_ptr
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);
diff --git a/EtsiServerGen/model/WorldLink.cpp b/../../world-storage-cpp-server/EtsiServerGen/model/WorldLink.cpp
index fd113d9..cefd41e 100644
--- a/EtsiServerGen/model/WorldLink.cpp
+++ b/../../world-storage-cpp-server/EtsiServerGen/model/WorldLink.cpp
@@ -48,6 +48,9 @@ std::string WorldLink::toJsonString(bool prettyJson /* = false */) const
// 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;
}
@@ -64,9 +67,12 @@ ptree WorldLink::toPropertyTree() const
ptree pt;
ptree tmp_node;
pt.put("UUID", m_UUID);
+ pt.put("unit", m_Unit.getEnumValue());
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()) {
@@ -74,10 +80,22 @@ ptree WorldLink::toPropertyTree() const
pt.add_child("transform", tmp_node);
tmp_node.clear();
}
+
// 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;
@@ -87,9 +105,13 @@ void WorldLink::fromPropertyTree(ptree const &pt)
{
ptree tmp_node;
m_UUID = pt.get("UUID", "");
+ m_Unit.setEnumValue(pt.get("unit",""));
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"));
--- ../../../../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>
--- 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
#
# ARF - Augmented Reality Framework (ETSI ISG ARF)
#
# Copyright 2024 ETSI
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Last change: May 2024
#
cmake_minimum_required(VERSION 3.23)
project(RestBedImpl VERSION 2.1.0)
set(TARGET_NAME RestbedImpl)
find_package(Boost REQUIRED)
find_package(restbed REQUIRED)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pg -g3" )
file(GLOB SRCS
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
)
add_executable(${TARGET_NAME} ${SRCS})
include_directories(src)
target_link_libraries(${TARGET_NAME} boost::boost restbed::restbed)
# WORLD STORAGE CPP SERVER (RESTBED)
## Description
This folder contains the source files for a basic implementation of the library you just created
## Requirements
- Ubuntu 22.04
- CMake > 2.22
- conan V2
## Code usage
Once you are in this directory, to build and execute the server, use the following commands:
conan install . --build=missing
cmake . --preset conan-release
cmake --build build/Release
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment