@@ -9,6 +9,7 | |||
|
9 | 9 | |
|
10 | 10 | // Relevant keys in JSON file |
|
11 | 11 | extern const QString AMDA_COMPONENT_KEY; |
|
12 | extern const QString AMDA_DATA_TYPE_KEY; | |
|
12 | 13 | extern const QString AMDA_PRODUCT_KEY; |
|
13 | 14 | extern const QString AMDA_ROOT_KEY; |
|
14 | 15 | extern const QString AMDA_XML_ID_KEY; |
@@ -1,6 +1,7 | |||
|
1 | 1 | #include "AmdaDefs.h" |
|
2 | 2 | |
|
3 | 3 | const QString AMDA_COMPONENT_KEY = QStringLiteral("component"); |
|
4 | const QString AMDA_DATA_TYPE_KEY = QStringLiteral("dataType"); | |
|
4 | 5 | const QString AMDA_PRODUCT_KEY = QStringLiteral("parameter"); |
|
5 | 6 | const QString AMDA_ROOT_KEY = QStringLiteral("dataCenter"); |
|
6 | 7 | const QString AMDA_XML_ID_KEY = QStringLiteral("xml:id"); |
@@ -36,6 +36,19 QString dateFormat(double sqpRange) noexcept | |||
|
36 | 36 | return dateTime.toString(AMDA_TIME_FORMAT); |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | AmdaResultParser::ValueType valueType(const QString &valueType) | |
|
40 | { | |
|
41 | if (valueType == QStringLiteral("scalar")) { | |
|
42 | return AmdaResultParser::ValueType::SCALAR; | |
|
43 | } | |
|
44 | else if (valueType == QStringLiteral("vector")) { | |
|
45 | return AmdaResultParser::ValueType::VECTOR; | |
|
46 | } | |
|
47 | else { | |
|
48 | return AmdaResultParser::ValueType::UNKNOWN; | |
|
49 | } | |
|
50 | } | |
|
51 | ||
|
39 | 52 | } // namespace |
|
40 | 53 | |
|
41 | 54 | AmdaProvider::AmdaProvider() |
@@ -86,6 +99,10 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa | |||
|
86 | 99 | } |
|
87 | 100 | qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime; |
|
88 | 101 | |
|
102 | // Retrieves the data type that determines whether the expected format for the result file is | |
|
103 | // scalar, vector... | |
|
104 | auto productValueType = valueType(data.value(AMDA_DATA_TYPE_KEY).toString()); | |
|
105 | ||
|
89 | 106 | // /////////// // |
|
90 | 107 | // Creates URL // |
|
91 | 108 | // /////////// // |
@@ -98,30 +115,31 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa | |||
|
98 | 115 | auto tempFile = std::make_shared<QTemporaryFile>(); |
|
99 | 116 | |
|
100 | 117 | // LAMBDA |
|
101 | auto httpDownloadFinished | |
|
102 |
|
|
|
103 | ||
|
104 |
|
|
|
105 |
|
|
|
106 | ||
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
|
112 |
|
|
|
113 | ||
|
114 |
|
|
|
115 | if (auto dataSeries = AmdaResultParser::readTxt(tempFile->fileName())) { | |
|
116 | emit dataProvided(dataId, dataSeries, dateTime); | |
|
117 | } | |
|
118 |
|
|
|
119 | /// @todo ALX : debug | |
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
|
123 | ||
|
124 | }; | |
|
118 | auto httpDownloadFinished = [this, dateTime, tempFile, | |
|
119 | productValueType](QNetworkReply *reply, QUuid dataId) noexcept { | |
|
120 | ||
|
121 | // Don't do anything if the reply was abort | |
|
122 | if (reply->error() != QNetworkReply::OperationCanceledError) { | |
|
123 | ||
|
124 | if (tempFile) { | |
|
125 | auto replyReadAll = reply->readAll(); | |
|
126 | if (!replyReadAll.isEmpty()) { | |
|
127 | tempFile->write(replyReadAll); | |
|
128 | } | |
|
129 | tempFile->close(); | |
|
130 | ||
|
131 | // Parse results file | |
|
132 | if (auto dataSeries | |
|
133 | = AmdaResultParser::readTxt(tempFile->fileName(), productValueType)) { | |
|
134 | emit dataProvided(dataId, dataSeries, dateTime); | |
|
135 | } | |
|
136 | else { | |
|
137 | /// @todo ALX : debug | |
|
138 | } | |
|
139 | } | |
|
140 | } | |
|
141 | ||
|
142 | }; | |
|
125 | 143 | auto httpFinishedLambda |
|
126 | 144 | = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept { |
|
127 | 145 |
General Comments 0
You need to be logged in to leave comments.
Login now