##// END OF EJS Templates
Remove unused parameter of Amda callback lambda
perrinel -
r528:2ff81754e6cf
parent child
Show More
@@ -1,148 +1,147
1 #include "AmdaProvider.h"
1 #include "AmdaProvider.h"
2 #include "AmdaDefs.h"
2 #include "AmdaDefs.h"
3 #include "AmdaResultParser.h"
3 #include "AmdaResultParser.h"
4
4
5 #include <Common/DateUtils.h>
5 #include <Common/DateUtils.h>
6 #include <Data/DataProviderParameters.h>
6 #include <Data/DataProviderParameters.h>
7 #include <Network/NetworkController.h>
7 #include <Network/NetworkController.h>
8 #include <SqpApplication.h>
8 #include <SqpApplication.h>
9 #include <Variable/Variable.h>
9 #include <Variable/Variable.h>
10
10
11 #include <QNetworkAccessManager>
11 #include <QNetworkAccessManager>
12 #include <QNetworkReply>
12 #include <QNetworkReply>
13 #include <QTemporaryFile>
13 #include <QTemporaryFile>
14 #include <QThread>
14 #include <QThread>
15
15
16 Q_LOGGING_CATEGORY(LOG_AmdaProvider, "AmdaProvider")
16 Q_LOGGING_CATEGORY(LOG_AmdaProvider, "AmdaProvider")
17
17
18 namespace {
18 namespace {
19
19
20 /// URL format for a request on AMDA server. The parameters are as follows:
20 /// URL format for a request on AMDA server. The parameters are as follows:
21 /// - %1: start date
21 /// - %1: start date
22 /// - %2: end date
22 /// - %2: end date
23 /// - %3: parameter id
23 /// - %3: parameter id
24 const auto AMDA_URL_FORMAT = QStringLiteral(
24 const auto AMDA_URL_FORMAT = QStringLiteral(
25 "http://amda.irap.omp.eu/php/rest/"
25 "http://amda.irap.omp.eu/php/rest/"
26 "getParameter.php?startTime=%1&stopTime=%2&parameterID=%3&outputFormat=ASCII&"
26 "getParameter.php?startTime=%1&stopTime=%2&parameterID=%3&outputFormat=ASCII&"
27 "timeFormat=ISO8601&gzip=0");
27 "timeFormat=ISO8601&gzip=0");
28
28
29 /// Dates format passed in the URL (e.g 2013-09-23T09:00)
29 /// Dates format passed in the URL (e.g 2013-09-23T09:00)
30 const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss");
30 const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss");
31
31
32 /// Formats a time to a date that can be passed in URL
32 /// Formats a time to a date that can be passed in URL
33 QString dateFormat(double sqpRange) noexcept
33 QString dateFormat(double sqpRange) noexcept
34 {
34 {
35 auto dateTime = DateUtils::dateTime(sqpRange);
35 auto dateTime = DateUtils::dateTime(sqpRange);
36 return dateTime.toString(AMDA_TIME_FORMAT);
36 return dateTime.toString(AMDA_TIME_FORMAT);
37 }
37 }
38
38
39 } // namespace
39 } // namespace
40
40
41 AmdaProvider::AmdaProvider()
41 AmdaProvider::AmdaProvider()
42 {
42 {
43 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::AmdaProvider") << QThread::currentThread();
43 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::AmdaProvider") << QThread::currentThread();
44 if (auto app = sqpApp) {
44 if (auto app = sqpApp) {
45 auto &networkController = app->networkController();
45 auto &networkController = app->networkController();
46 connect(this, SIGNAL(requestConstructed(QNetworkRequest, QUuid,
46 connect(this, SIGNAL(requestConstructed(QNetworkRequest, QUuid,
47 std::function<void(QNetworkReply *, QUuid)>)),
47 std::function<void(QNetworkReply *, QUuid)>)),
48 &networkController,
48 &networkController,
49 SLOT(onProcessRequested(QNetworkRequest, QUuid,
49 SLOT(onProcessRequested(QNetworkRequest, QUuid,
50 std::function<void(QNetworkReply *, QUuid)>)));
50 std::function<void(QNetworkReply *, QUuid)>)));
51
51
52
52
53 connect(&sqpApp->networkController(), SIGNAL(replyDownloadProgress(QUuid, double)), this,
53 connect(&sqpApp->networkController(), SIGNAL(replyDownloadProgress(QUuid, double)), this,
54 SIGNAL(dataProvidedProgress(QUuid, double)));
54 SIGNAL(dataProvidedProgress(QUuid, double)));
55 }
55 }
56 }
56 }
57
57
58 void AmdaProvider::requestDataLoading(QUuid token, const DataProviderParameters &parameters)
58 void AmdaProvider::requestDataLoading(QUuid token, const DataProviderParameters &parameters)
59 {
59 {
60 // NOTE: Try to use multithread if possible
60 // NOTE: Try to use multithread if possible
61 const auto times = parameters.m_Times;
61 const auto times = parameters.m_Times;
62 const auto data = parameters.m_Data;
62 const auto data = parameters.m_Data;
63 for (const auto &dateTime : qAsConst(times)) {
63 for (const auto &dateTime : qAsConst(times)) {
64 retrieveData(token, dateTime, data);
64 retrieveData(token, dateTime, data);
65 }
65 }
66 }
66 }
67
67
68 void AmdaProvider::requestDataAborting(QUuid identifier)
68 void AmdaProvider::requestDataAborting(QUuid identifier)
69 {
69 {
70 if (auto app = sqpApp) {
70 if (auto app = sqpApp) {
71 auto &networkController = app->networkController();
71 auto &networkController = app->networkController();
72 networkController.onReplyCanceled(identifier);
72 networkController.onReplyCanceled(identifier);
73 }
73 }
74 }
74 }
75
75
76 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data)
76 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data)
77 {
77 {
78 // Retrieves product ID from data: if the value is invalid, no request is made
78 // Retrieves product ID from data: if the value is invalid, no request is made
79 auto productId = data.value(AMDA_XML_ID_KEY).toString();
79 auto productId = data.value(AMDA_XML_ID_KEY).toString();
80 if (productId.isNull()) {
80 if (productId.isNull()) {
81 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id");
81 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id");
82 return;
82 return;
83 }
83 }
84 qCInfo(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime;
84 qCInfo(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime;
85
85
86 // /////////// //
86 // /////////// //
87 // Creates URL //
87 // Creates URL //
88 // /////////// //
88 // /////////// //
89
89
90 auto startDate = dateFormat(dateTime.m_TStart);
90 auto startDate = dateFormat(dateTime.m_TStart);
91 auto endDate = dateFormat(dateTime.m_TEnd);
91 auto endDate = dateFormat(dateTime.m_TEnd);
92
92
93 auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)};
93 auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)};
94 qCInfo(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData url:") << url;
94 qCInfo(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData url:") << url;
95 auto tempFile = std::make_shared<QTemporaryFile>();
95 auto tempFile = std::make_shared<QTemporaryFile>();
96
96
97 // LAMBDA
97 // LAMBDA
98 auto httpDownloadFinished
98 auto httpDownloadFinished
99 = [this, dateTime, tempFile, token](QNetworkReply *reply, QUuid dataId) noexcept {
99 = [this, dateTime, tempFile](QNetworkReply *reply, QUuid dataId) noexcept {
100 Q_UNUSED(dataId);
101
100
102 // Don't do anything if the reply was abort
101 // Don't do anything if the reply was abort
103 if (reply->error() != QNetworkReply::OperationCanceledError) {
102 if (reply->error() != QNetworkReply::OperationCanceledError) {
104
103
105 if (tempFile) {
104 if (tempFile) {
106 auto replyReadAll = reply->readAll();
105 auto replyReadAll = reply->readAll();
107 if (!replyReadAll.isEmpty()) {
106 if (!replyReadAll.isEmpty()) {
108 tempFile->write(replyReadAll);
107 tempFile->write(replyReadAll);
109 }
108 }
110 tempFile->close();
109 tempFile->close();
111
110
112 // Parse results file
111 // Parse results file
113 if (auto dataSeries = AmdaResultParser::readTxt(tempFile->fileName())) {
112 if (auto dataSeries = AmdaResultParser::readTxt(tempFile->fileName())) {
114 emit dataProvided(token, dataSeries, dateTime);
113 emit dataProvided(dataId, dataSeries, dateTime);
115 }
114 }
116 else {
115 else {
117 /// @todo ALX : debug
116 /// @todo ALX : debug
118 }
117 }
119 }
118 }
120 }
119 }
121
120
122 };
121 };
123 auto httpFinishedLambda
122 auto httpFinishedLambda
124 = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept {
123 = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept {
125
124
126 // Don't do anything if the reply was abort
125 // Don't do anything if the reply was abort
127 if (reply->error() != QNetworkReply::OperationCanceledError) {
126 if (reply->error() != QNetworkReply::OperationCanceledError) {
128 auto downloadFileUrl = QUrl{QString{reply->readAll()}};
127 auto downloadFileUrl = QUrl{QString{reply->readAll()}};
129
128
130
129
131 qCInfo(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData downloadFileUrl:")
130 qCInfo(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData downloadFileUrl:")
132 << downloadFileUrl;
131 << downloadFileUrl;
133 // Executes request for downloading file //
132 // Executes request for downloading file //
134
133
135 // Creates destination file
134 // Creates destination file
136 if (tempFile->open()) {
135 if (tempFile->open()) {
137 // Executes request
136 // Executes request
138 emit requestConstructed(QNetworkRequest{downloadFileUrl}, dataId,
137 emit requestConstructed(QNetworkRequest{downloadFileUrl}, dataId,
139 httpDownloadFinished);
138 httpDownloadFinished);
140 }
139 }
141 }
140 }
142 };
141 };
143
142
144 // //////////////// //
143 // //////////////// //
145 // Executes request //
144 // Executes request //
146 // //////////////// //
145 // //////////////// //
147 emit requestConstructed(QNetworkRequest{url}, token, httpFinishedLambda);
146 emit requestConstructed(QNetworkRequest{url}, token, httpFinishedLambda);
148 }
147 }
General Comments 0
You need to be logged in to leave comments. Login now