From 7dc72cc510ff39df87ff86d53d9086ac17a98dc1 2017-12-11 09:29:38 From: Alexandre Leroux Date: 2017-12-11 09:29:38 Subject: [PATCH] Adds "hybrid" server mode Hybrid mode allows to use both the default server and the test server, depending on the "server" setting of each product in the JSON file --- diff --git a/cmake/sciqlop_applications.cmake b/cmake/sciqlop_applications.cmake index 99ddb70..c0a9258 100644 --- a/cmake/sciqlop_applications.cmake +++ b/cmake/sciqlop_applications.cmake @@ -31,8 +31,9 @@ IF(BUILD_PLUGINS) # Available values are: # - "default": default AMDA server # - "amdatest": AMDA test server + # - "hybrid": use both the default server and the test server (the server used is relative to each product, according to its "server" property in the JSON file) # Any other value will lead to the use of the default server - ADD_DEFINITIONS(-DSCIQLOP_AMDA_SERVER="default") + ADD_DEFINITIONS(-DSCIQLOP_AMDA_SERVER="hybrid") set(sciqlop-amda_DIR "${CMAKE_SOURCE_DIR}/plugins/amda/cmake") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-amda_DIR}") diff --git a/meson.build b/meson.build index e6bc9f4..4cc8ed1 100644 --- a/meson.build +++ b/meson.build @@ -26,8 +26,9 @@ endif # Available values are: # - "default": default AMDA server # - "amdatest": AMDA test server +# - "hybrid": use both the default server and the test server (the server used is relative to each product, according to its "server" property in the JSON file) # Any other value will lead to the use of the default server -add_project_arguments('-DSCIQLOP_AMDA_SERVER="default"', language : 'cpp') +add_project_arguments('-DSCIQLOP_AMDA_SERVER="hybrid"', language : 'cpp') subdir('core') subdir('gui') diff --git a/plugins/amda/include/AmdaServer.h b/plugins/amda/include/AmdaServer.h index 1f836d3..1826bdb 100644 --- a/plugins/amda/include/AmdaServer.h +++ b/plugins/amda/include/AmdaServer.h @@ -26,8 +26,10 @@ public: /// @return the name of the server virtual QString name() const = 0; + + /// @param properties used to generate url /// @return the url of the server (used to retrieve data) - virtual QString url() const = 0; + virtual QString url(const QVariantHash &properties = {}) const = 0; }; #endif // SCIQLOP_AMDASERVER_H diff --git a/plugins/amda/src/AmdaProvider.cpp b/plugins/amda/src/AmdaProvider.cpp index 8eab704..63e2ffc 100644 --- a/plugins/amda/src/AmdaProvider.cpp +++ b/plugins/amda/src/AmdaProvider.cpp @@ -180,8 +180,9 @@ void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa auto startDate = dateFormat(dateTime.m_TStart); auto endDate = dateFormat(dateTime.m_TEnd); - auto url = QUrl{ - QString{AMDA_URL_FORMAT}.arg(AmdaServer::instance().url(), startDate, endDate, productId)}; + QVariantHash urlProperties{{AMDA_SERVER_KEY, data.value(AMDA_SERVER_KEY)}}; + auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(AmdaServer::instance().url(urlProperties), + startDate, endDate, productId)}; qCInfo(LOG_AmdaProvider()) << tr("TORM AmdaProvider::retrieveData url:") << url; auto tempFile = std::make_shared(); diff --git a/plugins/amda/src/AmdaServer.cpp b/plugins/amda/src/AmdaServer.cpp index 73956b9..8306d0e 100644 --- a/plugins/amda/src/AmdaServer.cpp +++ b/plugins/amda/src/AmdaServer.cpp @@ -1,21 +1,51 @@ #include "AmdaServer.h" +#include "AmdaDefs.h" + Q_LOGGING_CATEGORY(LOG_AmdaServer, "AmdaServer") namespace { +/// URL of the default AMDA server +const auto AMDA_DEFAULT_SERVER_URL = QStringLiteral("amda.irap.omp.eu"); + +/// URL of the AMDA test server +const auto AMDA_TEST_SERVER_URL = QStringLiteral("amdatest.irap.omp.eu"); + /// Default AMDA server struct AmdaDefaultServer : public AmdaServer { public: QString name() const override { return QStringLiteral("AMDA (default)"); } - QString url() const override { return QStringLiteral("amda.irap.omp.eu"); } + QString url(const QVariantHash &properties) const override + { + Q_UNUSED(properties); + return AMDA_DEFAULT_SERVER_URL; + } }; /// Alternative AMDA server (tests) struct AmdaTestServer : public AmdaServer { public: QString name() const override { return QStringLiteral("AMDA (test)"); } - QString url() const override { return QStringLiteral("amdatest.irap.omp.eu"); } + QString url(const QVariantHash &properties) const override + { + Q_UNUSED(properties); + return AMDA_TEST_SERVER_URL; + } +}; + +/// Hybrid AMDA server: use both of default and test server. +/// The server used is relative to each product for which to retrieve url, according to its "server" +/// property +struct AmdaHybridServer : public AmdaServer { +public: + QString name() const override { return QStringLiteral("AMDA (hybrid)"); } + QString url(const QVariantHash &properties) const override + { + // Reads "server" property to determine which server url to use + auto server = properties.value(AMDA_SERVER_KEY).toString(); + return server == QString{"amdatest"} ? AMDA_TEST_SERVER_URL : AMDA_DEFAULT_SERVER_URL; + } }; /// @return an AMDA server instance created from the name of the server passed in parameter. If the @@ -25,6 +55,9 @@ std::unique_ptr createInstance(const QString &server) if (server == QString{"amdatest"}) { return std::make_unique(); } + else if (server == QString{"hybrid"}) { + return std::make_unique(); + } else { if (server != QString{"default"}) { qCWarning(LOG_AmdaServer())