diff --git a/plugins/amda/src/AmdaResultParser.cpp b/plugins/amda/src/AmdaResultParser.cpp index 668399b..e435dce 100644 --- a/plugins/amda/src/AmdaResultParser.cpp +++ b/plugins/amda/src/AmdaResultParser.cpp @@ -12,6 +12,9 @@ Q_LOGGING_CATEGORY(LOG_AmdaResultParser, "AmdaResultParser") namespace { +/// Message in result file when the file was not found on server +const auto FILE_NOT_FOUND_MESSAGE = QStringLiteral("Not Found"); + /// Format for dates in result files const auto DATE_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss.zzz"); @@ -119,8 +122,16 @@ std::shared_ptr AmdaResultParser::readTxt(const QString &filePath) QTextStream stream{&file}; - // Ignore first two lines (comments lines) - stream.readLine(); + // Checks if the file was found on the server + auto firstLine = stream.readLine(); + if (firstLine.compare(FILE_NOT_FOUND_MESSAGE) == 0) { + qCCritical(LOG_AmdaResultParser()) + << QObject::tr("Can't retrieve AMDA data from file %1: file was not found on server") + .arg(filePath); + return nullptr; + } + + // Ignore comments lines stream.readLine(); // Reads x-axis unit diff --git a/plugins/amda/tests-resources/TestAmdaResultParser/FileNotFound.txt b/plugins/amda/tests-resources/TestAmdaResultParser/FileNotFound.txt new file mode 100644 index 0000000..bba04b0 --- /dev/null +++ b/plugins/amda/tests-resources/TestAmdaResultParser/FileNotFound.txt @@ -0,0 +1,3 @@ +Not Found + +The requested URL /AMDA/data/WSRESULT/imf(0)-1343153090-1343153092-60.txt was not found on this server. \ No newline at end of file diff --git a/plugins/amda/tests/TestAmdaResultParser.cpp b/plugins/amda/tests/TestAmdaResultParser.cpp index ece3bf5..961a746 100644 --- a/plugins/amda/tests/TestAmdaResultParser.cpp +++ b/plugins/amda/tests/TestAmdaResultParser.cpp @@ -155,9 +155,12 @@ void TestAmdaResultParser::testReadTxt_data() QVector{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}, QVector{-2.71850, -2.52150}}; - // Invalid file - QTest::newRow("Invalid file (unexisting file)") << QStringLiteral("UnexistingFile.txt") - << ExpectedResults{}; + // Invalid files + QTest::newRow("Invalid file (unexisting file)") + << QStringLiteral("UnexistingFile.txt") << ExpectedResults{}; + + QTest::newRow("Invalid file (file not found on server)") + << QStringLiteral("FileNotFound.txt") << ExpectedResults{}; } void TestAmdaResultParser::testReadTxt()