From 1e0772e9e7a5ca6e102872ee11cc723852300df2 2017-07-10 08:09:24 From: Alexandre Leroux Date: 2017-07-10 08:09:24 Subject: [PATCH] Amda provider (1) Creates url to retrieve the address for downloading the results file --- diff --git a/plugins/amda/CMakeLists.txt b/plugins/amda/CMakeLists.txt index bfa7e21..1b66326 100644 --- a/plugins/amda/CMakeLists.txt +++ b/plugins/amda/CMakeLists.txt @@ -13,7 +13,7 @@ INCLUDE_DIRECTORIES(${RESOURCES_DIR}) # # Find Qt modules # -SCIQLOP_FIND_QT(Core Widgets) +SCIQLOP_FIND_QT(Core Widgets Network) # # Find dependent libraries @@ -68,7 +68,7 @@ INSTALL(TARGETS ${SQPAMDA_LIBRARY_NAME} TARGET_LINK_LIBRARIES(${SQPAMDA_LIBRARY_NAME} ${LIBRARIES}) -qt5_use_modules(${SQPAMDA_LIBRARY_NAME} Core Widgets) +qt5_use_modules(${SQPAMDA_LIBRARY_NAME} Core Widgets Network) add_dependencies(${SQPAMDA_LIBRARY_NAME} ${SQPPLUGIN_LIBRARY_NAME} ${SQPGUI_LIBRARY_NAME} ${SQPCORE_LIBRARY_NAME}) diff --git a/plugins/amda/include/AmdaProvider.h b/plugins/amda/include/AmdaProvider.h index c346dae..79b2b8b 100644 --- a/plugins/amda/include/AmdaProvider.h +++ b/plugins/amda/include/AmdaProvider.h @@ -26,6 +26,9 @@ private: class AmdaProviderPrivate; spimpl::unique_impl_ptr impl; + +private slots: + void httpFinished() noexcept; }; #endif // SCIQLOP_AMDAPROVIDER_H diff --git a/plugins/amda/src/AmdaProvider.cpp b/plugins/amda/src/AmdaProvider.cpp index ea54307..c36bbec 100644 --- a/plugins/amda/src/AmdaProvider.cpp +++ b/plugins/amda/src/AmdaProvider.cpp @@ -1,8 +1,40 @@ #include "AmdaProvider.h" +#include + +#include +#include Q_LOGGING_CATEGORY(LOG_AmdaProvider, "AmdaProvider") +namespace { + +/// URL format for a request on AMDA server. The parameters are as follows: +/// - %1: start date +/// - %2: end date +/// - %3: parameter id +const auto AMDA_URL_FORMAT = QStringLiteral( + "http://amda.irap.omp.eu/php/rest/" + "getParameter.php?startTime=%1&stopTime=%2¶meterID=%3&sampling=60&outputFormat=ASCII&" + "timeFormat=ISO8601&gzip=0"); + +/// Dates format passed in the URL (e.g 2013-09-23T09:00) +const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:ss"); + +/// Formats a time to a date that can be passed in URL +QString dateFormat(double sqpDateTime) noexcept +{ + auto dateTime = QDateTime::fromMSecsSinceEpoch(sqpDateTime * 1000.); + return dateTime.toString(AMDA_TIME_FORMAT); +} + +} // namespace + struct AmdaProvider::AmdaProviderPrivate { + DataProviderParameters m_Params{}; + std::unique_ptr m_AccessManager{nullptr}; + QNetworkReply *m_Reply{nullptr}; + std::unique_ptr m_File{nullptr}; + QUuid m_Token; }; AmdaProvider::AmdaProvider() : impl{spimpl::make_unique_impl()} @@ -19,5 +51,28 @@ void AmdaProvider::requestDataLoading(QUuid token, const QVector &d void AmdaProvider::retrieveData(QUuid token, const DataProviderParameters ¶meters) const { + // /////////// // + // Creates URL // + // /////////// // + + auto startDate = dateFormat(parameters.m_Time.m_TStart); + auto endDate = dateFormat(parameters.m_Time.m_TEnd); + auto productId = QStringLiteral("imf(0)"); + + auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)}; + + // //////////////// // + // Executes request // + // //////////////// // + + impl->m_Token = token; + impl->m_Params = parameters; + impl->m_AccessManager = std::make_unique(); + impl->m_Reply = impl->m_AccessManager->get(QNetworkRequest{url}); + connect(impl->m_Reply, &QNetworkReply::finished, this, &AmdaProvider::httpFinished); +} + +void AmdaProvider::httpFinished() noexcept +{ /// @todo ALX }