Commit 2bea95fc authored by Volker Krause's avatar Volker Krause

Run the post-processor on every file we import

This augments the data from the built-in databases, which is necessary to
trigger the country information elements correctly.
parent b6805130
...@@ -108,33 +108,35 @@ private slots: ...@@ -108,33 +108,35 @@ private slots:
QCOMPARE(model.rowCount(), 1); QCOMPARE(model.rowCount(), 1);
QCOMPARE(model.index(0, 0).data(TimelineModel::ElementTypeRole), TimelineModel::TodayMarker); QCOMPARE(model.index(0, 0).data(TimelineModel::ElementTypeRole), TimelineModel::TodayMarker);
resMgr.importReservation(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/haus-randa-v1.json"))); resMgr.importReservation(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/haus-randa-v1.json")));
QCOMPARE(insertSpy.size(), 2); QCOMPARE(insertSpy.size(), 3);
QCOMPARE(insertSpy.at(0).at(1).toInt(), 0); QCOMPARE(insertSpy.at(0).at(1).toInt(), 0);
QCOMPARE(insertSpy.at(0).at(2).toInt(), 0); QCOMPARE(insertSpy.at(0).at(2).toInt(), 0);
QCOMPARE(insertSpy.at(1).at(1).toInt(), 1); QCOMPARE(insertSpy.at(1).at(1).toInt(), 1);
QCOMPARE(insertSpy.at(1).at(2).toInt(), 1); QCOMPARE(insertSpy.at(1).at(2).toInt(), 1);
QVERIFY(updateSpy.isEmpty()); QVERIFY(updateSpy.isEmpty());
QCOMPARE(model.rowCount(), 3); QCOMPARE(model.rowCount(), 4);
QCOMPARE(model.index(0, 0).data(TimelineModel::ElementTypeRole), TimelineModel::Hotel); QCOMPARE(model.index(0, 0).data(TimelineModel::ElementTypeRole), TimelineModel::CountryInfo);
QCOMPARE(model.index(0, 0).data(TimelineModel::ElementRangeRole), TimelineModel::RangeBegin);
QCOMPARE(model.index(1, 0).data(TimelineModel::ElementTypeRole), TimelineModel::Hotel); QCOMPARE(model.index(1, 0).data(TimelineModel::ElementTypeRole), TimelineModel::Hotel);
QCOMPARE(model.index(1, 0).data(TimelineModel::ElementRangeRole), TimelineModel::RangeEnd); QCOMPARE(model.index(1, 0).data(TimelineModel::ElementRangeRole), TimelineModel::RangeBegin);
QCOMPARE(model.index(2, 0).data(TimelineModel::ElementTypeRole), TimelineModel::Hotel);
QCOMPARE(model.index(2, 0).data(TimelineModel::ElementRangeRole), TimelineModel::RangeEnd);
// move end date of a hotel booking: dataChanged on RangeBegin, move (or del/ins) on RangeEnd // move end date of a hotel booking: dataChanged on RangeBegin, move (or del/ins) on RangeEnd
resMgr.importReservation(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/haus-randa-v2.json"))); resMgr.importReservation(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/haus-randa-v2.json")));
QCOMPARE(insertSpy.size(), 3); QCOMPARE(insertSpy.size(), 4);
QCOMPARE(updateSpy.size(), 1); QCOMPARE(updateSpy.size(), 1);
QCOMPARE(rmSpy.size(), 1); QCOMPARE(rmSpy.size(), 1);
QCOMPARE(updateSpy.at(0).at(0).toModelIndex().row(), 0); QCOMPARE(updateSpy.at(0).at(0).toModelIndex().row(), 1);
QCOMPARE(insertSpy.at(2).at(1).toInt(), 1); QCOMPARE(insertSpy.at(2).at(1).toInt(), 0);
QCOMPARE(insertSpy.at(2).at(2).toInt(), 1); QCOMPARE(insertSpy.at(2).at(2).toInt(), 0);
QCOMPARE(rmSpy.at(0).at(1), 1); QCOMPARE(rmSpy.at(0).at(1), 2);
QCOMPARE(model.rowCount(), 3); QCOMPARE(model.rowCount(), 4);
// delete a split element // delete a split element
const auto resId = model.data(model.index(0, 0), TimelineModel::ReservationIdRole).toString(); const auto resId = model.data(model.index(1, 0), TimelineModel::ReservationIdRole).toString();
QVERIFY(!resId.isEmpty());
resMgr.removeReservation(resId); resMgr.removeReservation(resId);
QCOMPARE(rmSpy.size(), 3); QCOMPARE(rmSpy.size(), 4);
QCOMPARE(model.rowCount(), 1); QCOMPARE(model.rowCount(), 1);
QCOMPARE(model.index(0, 0).data(TimelineModel::ElementTypeRole), TimelineModel::TodayMarker); QCOMPARE(model.index(0, 0).data(TimelineModel::ElementTypeRole), TimelineModel::TodayMarker);
} }
......
...@@ -125,10 +125,14 @@ void ReservationManager::importReservation(const QUrl& filename) ...@@ -125,10 +125,14 @@ void ReservationManager::importReservation(const QUrl& filename)
void ReservationManager::importReservations(const QVector<QVariant> &resData) void ReservationManager::importReservations(const QVector<QVariant> &resData)
{ {
ExtractorPostprocessor postproc;
postproc.setContextDate(QDateTime(QDate::currentDate(), QTime(0, 0)));
postproc.process(resData);
const auto basePath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/reservations/"); const auto basePath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/reservations/");
QDir::root().mkpath(basePath); QDir::root().mkpath(basePath);
for (auto res : resData) { for (auto res : postproc.result()) {
QString resId; QString resId;
bool oldResFound = false; bool oldResFound = false;
...@@ -199,11 +203,7 @@ void ReservationManager::passAdded(const QString& passId) ...@@ -199,11 +203,7 @@ void ReservationManager::passAdded(const QString& passId)
engine.setPass(pass); engine.setPass(pass);
const auto data = engine.extract(); const auto data = engine.extract();
const auto res = JsonLdDocument::fromJson(data); const auto res = JsonLdDocument::fromJson(data);
importReservations(res);
ExtractorPostprocessor postproc;
postproc.setContextDate(QDateTime(QDate::currentDate(), QTime(0, 0)));
postproc.process(res);
importReservations(postproc.result());
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment