Skip to content
Open
36 changes: 22 additions & 14 deletions src/mtconnect/sink/rest_sink/rest_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,8 @@ namespace mtconnect {
request->m_request = "MTConnectAssets";

respond(session,
assetRequest(printer, count, removed, request->parameter<string>("type"),
request->parameter<string>("device"), pretty, request->m_requestId),
assetRequest(printer, count, removed, request->parameter<string>("type"),
request->parameter<string>("device"), pretty, request->m_requestId),
request->m_requestId);
return true;
};
Expand Down Expand Up @@ -566,23 +566,30 @@ namespace mtconnect {

string qp(
"type={string}&removed={bool:false}&"
"count={integer:100}&device={string}&pretty={bool:false}&format={string}");
m_server->addRouting({boost::beast::http::verb::get, "/assets?" + qp, handler})
.document("MTConnect assets request", "Returns up to `count` assets");
m_server->addRouting({boost::beast::http::verb::get, "/asset?" + qp, handler})
.document("MTConnect asset request", "Returns up to `count` assets");
m_server->addRouting({boost::beast::http::verb::get, "/{device}/assets?" + qp, handler})
.document("MTConnect assets request", "Returns up to `count` assets for deivce `device`");
m_server->addRouting({boost::beast::http::verb::get, "/{device}/asset?" + qp, handler})
.document("MTConnect asset request", "Returns up to `count` assets for deivce `device`");
"count={integer:100}&deviceType={string}&pretty={bool:false}&format={string}");

m_server->addRouting({boost::beast::http::verb::get, "/asset?" + qp, handler})
.document("MTConnect assets request", "Returns up to `count` assets");
m_server->addRouting({boost::beast::http::verb::get, "/{device}/asset?" + qp, handler})
.document("MTConnect assets request", "Returns up to `count` assets for deivce `device`")
.command("asset"); //Wickelhaus added the asset command for websocket processing.

m_server->addRouting({boost::beast::http::verb::get, "/assets?" + qp, handler})
.document("MTConnect assets request", "Returns up to `count` assets");
m_server->addRouting({boost::beast::http::verb::get, "/{device}/assets?" + qp, handler})
.document("MTConnect assets request", "Returns up to `count` assets for deivce `device`")
.command("assets"); //Wickelhaus added the assets command for websocket processing.

m_server->addRouting({boost::beast::http::verb::get, "/assets/{assetIds}", idHandler})
.document(
"MTConnect assets request",
"Returns a set assets identified by asset ids `asset` separated by semi-colon (;)");
m_server->addRouting({boost::beast::http::verb::get, "/asset/{assetIds}", idHandler})
m_server->addRouting({boost::beast::http::verb::get, "/asset/{assetIds}", idHandler})
.document("MTConnect asset request",
"Returns a set of assets identified by asset ids `asset` separated by "
"semi-colon (;)");
"semi-colon (;)")
.command("assetsById");
//Wickelhaus added assetsById command to process the assetIds values for websocket processing.

if (m_server->arePutsAllowed())
{
Expand Down Expand Up @@ -780,7 +787,8 @@ namespace mtconnect {

string qp(
"path={string}&from={unsigned_integer}&"
"interval={integer}&count={integer:100}&"
//"interval={integer}&count={integer:100}&"
"count={integer:100}&"
"heartbeat={integer:10000}&to={unsigned_integer}&"
"pretty={bool:false}&"
"deviceType={string}&format={string}");
Expand Down
24 changes: 20 additions & 4 deletions src/mtconnect/sink/rest_sink/websocket_session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ namespace mtconnect::sink::rest_sink {
#ifdef __GOSave__
#define GetObject __GOSave__
#endif

for (auto &it : object)
{
switch (it.value.GetType())
Expand All @@ -380,7 +379,6 @@ namespace mtconnect::sink::rest_sink {
case rapidjson::kStringType:
request->m_parameters.emplace(
make_pair(it.name.GetString(), ParameterValue(string(it.value.GetString()))));

break;
case rapidjson::kNumberType:
if (it.value.IsInt())
Expand All @@ -401,16 +399,32 @@ namespace mtconnect::sink::rest_sink {

break;
}
}
}
}

//Wickelhaus
//Added code to change the command from asset or assets to assetsById when the assetIds parameter has values
string command = *request->parameter<string>("request");
if ( *request->parameter<string>("assetIds") != "" && ( command == "asset" || command == "assets")) {
request->m_parameters["request"] = "assetsById";
}


return request;
}

bool dispatchRequest(RequestPtr &&request)
{
using namespace std;

// LOG(debug) << "WebsocketSession::dispatchRequest command: " << *request->parameter<string>("request");
// LOG(debug) << "WebsocketSession::dispatchRequest assetIds: " << *request->parameter<string>("assetIds");
// string value = *request->parameter<string>("assetIds");
// if (!value.empty() && !(value == "asset")) {
// request->m_parameters.emplace("request", "assetIds");
// LOG(debug) << "WebsocketSession::dispatchRequest command: " << *request->parameter<string>("request");
// }


if (request->m_parameters.count("id") > 0)
{
auto &v = request->m_parameters["id"];
Expand Down Expand Up @@ -493,6 +507,8 @@ namespace mtconnect::sink::rest_sink {
try
{
auto request = parseRequest(buffer);
//auto command = request->m_parameters["request"];
LOG(debug) << "WebsocketSession::onRead parsed request: " << *request->m_command;
if (!request || !dispatchRequest(std::move(request)))
{
std::stringstream txt;
Expand Down
Loading