~aleteoryx/muditaos

b63f51a7bf014ea194f0d809ae14ee3c06387de5 — Pawel Olejniczak 5 years ago 44c717e
[EGD-5963] Unify type of UUID field in all endpoints

UUID is no longer stored as a string, since we are not
going to use 128b UUID.
M module-services/service-desktop/endpoints/Context.hpp => module-services/service-desktop/endpoints/Context.hpp +17 -25
@@ 11,12 11,12 @@ namespace parserFSM

    namespace json
    {
        inline constexpr auto method   = "method";
        inline constexpr auto endpoint = "endpoint";
        inline constexpr auto uuid     = "uuid";
        inline constexpr auto status   = "status";
        inline constexpr auto method     = "method";
        inline constexpr auto endpoint   = "endpoint";
        inline constexpr auto uuid       = "uuid";
        inline constexpr auto status     = "status";
        inline constexpr auto totalCount = "totalCount";
        inline constexpr auto body     = "body";
        inline constexpr auto body       = "body";
        inline constexpr auto offset     = "offset";
        inline constexpr auto limit      = "limit";
        inline constexpr auto nextPage   = "nextPage";


@@ 30,7 30,7 @@ namespace parserFSM
      protected:
        json11::Json body;
        EndpointType endpoint;
        uint32_t uuid;
        int uuid;
        http::Method method;
        endpoint::ResponseContext responseContext;



@@ 46,7 46,7 @@ namespace parserFSM
                method = http::Method::get;
            }
        }
        auto buildResponseStr(std::size_t responseSize, std::string responsePayloadString) -> std::string
        auto buildResponseStr(std::size_t responseSize, const std::string &responsePayloadString) -> std::string
        {
            constexpr auto pos                 = 0;
            constexpr auto count               = 1;


@@ 60,20 60,12 @@ namespace parserFSM
        }

      public:
        Context(json11::Json &js)
        explicit Context(json11::Json &js)
        {
            body     = js[json::body];
            endpoint = static_cast<EndpointType>(js[json::endpoint].int_value());
            uuid     = js[json::uuid].int_value();
            if (uuid == invalidUuid) {
                try {
                    uuid = stoi(js[json::uuid].string_value());
                }
                catch (...) {
                    uuid = invalidUuid;
                }
            }
            method = static_cast<http::Method>(js[json::method].int_value());
            method   = static_cast<http::Method>(js[json::method].int_value());
            validate();
        }
        Context()


@@ 89,7 81,7 @@ namespace parserFSM
        {
            json11::Json responseJson = json11::Json::object{{json::endpoint, static_cast<int>(getEndpoint())},
                                                             {json::status, static_cast<int>(responseContext.status)},
                                                             {json::uuid, std::to_string(getUuid())},
                                                             {json::uuid, getUuid()},
                                                             {json::body, responseContext.body}};
            return buildResponseStr(responseJson.dump().size(), responseJson.dump());
        }


@@ 109,7 101,7 @@ namespace parserFSM
        }
        auto setResponseBody(json11::Json respBody)
        {
            responseContext.body = respBody;
            responseContext.body = std::move(respBody);
        }
        auto getBody() -> const json11::Json &
        {


@@ 119,7 111,7 @@ namespace parserFSM
        {
            return endpoint;
        }
        auto getUuid() -> uint32_t
        auto getUuid() -> int
        {
            return uuid;
        }


@@ 133,11 125,11 @@ namespace parserFSM
    {
      private:
        // from request
        std::size_t requestedLimit, requestedOffset;
        std::size_t requestedLimit{}, requestedOffset{};
        // set by query (during helper run)
        std::size_t totalCount;
        std::size_t totalCount{};
        // set it before calling handle on helper
        std::size_t pageSize;
        std::size_t pageSize{};

      public:
        explicit PagedContext(json11::Json &js, size_t pageSize) : Context(js), pageSize(pageSize)


@@ 183,10 175,10 @@ namespace parserFSM

    namespace endpoint_pageing
    {
        inline constexpr std::size_t contactsPageSize = 10;
        inline constexpr std::size_t contactsPageSize       = 10;
        inline constexpr std::size_t calendarEventsPageSize = 10;
        inline constexpr std::size_t messagesPageSize       = 4;
    }
    } // namespace endpoint_pageing

    class ContextFactory
    {

M module-services/service-desktop/parser/MessageHandler.cpp => module-services/service-desktop/parser/MessageHandler.cpp +1 -2
@@ 10,7 10,6 @@
#include <log/log.hpp>

#include <bits/exception.h>
#include <cinttypes>
#include <memory>

namespace sys


@@ 40,7 39,7 @@ void MessageHandler::processMessage()
{
    auto context = ContextFactory::create(messageJson);

    LOG_DEBUG("[MsgHandler]\nmethod: %d\nendpoint: %d\nuuid: %" PRIu32 "\nbody: %s\n",
    LOG_DEBUG("[MsgHandler]\nmethod: %d\nendpoint: %d\nuuid: %d\nbody: %s\n",
              static_cast<int>(context->getMethod()),
              static_cast<int>(context->getEndpoint()),
              context->getUuid(),

M module-services/service-desktop/tests/test-contacts.cpp => module-services/service-desktop/tests/test-contacts.cpp +4 -3
@@ 171,9 171,10 @@ TEST_CASE("Endpoint Contacts Test")
    {
        auto count       = 29; // requested number of record to return
        auto endpoint    = 7;
        auto uuid        = "1103";
        auto uuid        = 1103;
        auto totalCount  = contactsDb->contacts.count();
        auto testMessage = "{\"endpoint\":" + std::to_string(endpoint) + ", \"method\":1, \"uuid\":" + uuid +
        auto testMessage = "{\"endpoint\":" + std::to_string(endpoint) +
                           ", \"method\":1, \"uuid\":" + std::to_string(uuid) +
                           ", \"body\":{\"limit\":" + std::to_string(count) + ", \"offset\":20}}";
        std::string err;
        auto msgJson = json11::Json::parse(testMessage, err);


@@ 191,7 192,7 @@ TEST_CASE("Endpoint Contacts Test")
        auto retJson = json11::Json::parse(msg.substr(10), err); // string length and go to real data

        REQUIRE(err.empty());
        REQUIRE(uuid == retJson[parserFSM::json::uuid].string_value());
        REQUIRE(uuid == retJson[parserFSM::json::uuid].int_value());
        REQUIRE(endpoint == retJson[parserFSM::json::endpoint].int_value());

        auto body = retJson[parserFSM::json::body];

M module-services/service-desktop/tests/unittest.cpp => module-services/service-desktop/tests/unittest.cpp +5 -5
@@ 247,15 247,15 @@ TEST_CASE("Context class test")
        REQUIRE(context.getUuid() == 12345);
        REQUIRE(context.getEndpoint() == EndpointType::contacts);
        REQUIRE(context.createSimpleResponse() ==
                R"(#000000061{"body": null, "endpoint": 7, "status": 200, "uuid": "12345"})");
                R"(#000000061{"body": null, "endpoint": 7, "status": 200, "uuid": 12345})");

        context.setResponseBody(context.getBody());
        REQUIRE(context.createSimpleResponse() ==
                R"(#000000073{"body": {"test": "test"}, "endpoint": 7, "status": 200, "uuid": "12345"})");
                R"(#000000073{"body": {"test": "test"}, "endpoint": 7, "status": 200, "uuid": 12345})");
    }
    SECTION("Invalid message")
    {
        auto testMessage = R"({"endpoint":25, "method":8, "uuid":"0", "body":{"te":"test"}})";
        auto testMessage = R"({"endpoint":25, "method":8, "uuid":0, "body":{"te":"test"}})";
        std::string err;
        auto msgJson = json11::Json::parse(testMessage, err);
        REQUIRE(err.empty());


@@ 285,7 285,7 @@ TEST_CASE("Endpoint Factory test")

    SECTION("Wrong endpoint")
    {
        auto testMessage = R"({"endpoint":25, "method":8, "uuid":"12345", "body":{"te":"test"}})";
        auto testMessage = R"({"endpoint":25, "method":8, "uuid":12345, "body":{"te":"test"}})";
        std::string err;
        auto msgJson = json11::Json::parse(testMessage, err);
        REQUIRE(err.empty());


@@ 314,7 314,7 @@ TEST_CASE("Secured Endpoint Factory test")

    SECTION("Secured endpoint")
    {
        auto testMessage = R"({"endpoint":25, "method":8, "uuid":"12345", "body":{"te":"test"}})";
        auto testMessage = R"({"endpoint":25, "method":8, "uuid":12345, "body":{"te":"test"}})";
        std::string err;
        auto msgJson = json11::Json::parse(testMessage, err);
        REQUIRE(err.empty());