Commit 854b9b41 authored by Volker Krause's avatar Volker Krause
Browse files

Check more thoroughly whether we have a valid trip

This avoids generating invalid trips just because we find partial
information for that somehow. Instead, fall back to generating a
generic ticket in that case.
parent d7ce7f11
......@@ -55,14 +55,29 @@ void Uic9183DocumentProcessor::expandNode(ExtractorDocumentNode &node, [[maybe_u
}
}
static QJsonObject makeStation(const QString &name)
static QJsonValue makeStation(const QString &name)
{
if (name.isEmpty()) {
return {};
}
QJsonObject station;
station.insert(QStringLiteral("@type"), QLatin1String("TrainStation"));
station.insert(QStringLiteral("name"), name);
return station;
}
static bool isValidTrip(const QJsonObject &trip)
{
if (trip.size() <= 1) {
return false;
}
return trip.contains(QLatin1String("departureDay"))
&& trip.value(QLatin1String("departureStation")).isObject()
&& trip.value(QLatin1String("arrivalStation")).isObject();
}
void Uic9183DocumentProcessor::preExtract(ExtractorDocumentNode &node, [[maybe_unused]] const ExtractorEngine *engine) const
{
const auto p = node.content<Uic9183Parser>();
......@@ -150,7 +165,7 @@ void Uic9183DocumentProcessor::preExtract(ExtractorDocumentNode &node, [[maybe_u
}
// we have enough for a full TrainReservation result
if (trip.size() > 1) {
if (isValidTrip(trip)) {
trip.insert(QLatin1String("provider"), provider);
QJsonArray results;
......@@ -162,7 +177,7 @@ void Uic9183DocumentProcessor::preExtract(ExtractorDocumentNode &node, [[maybe_u
res.insert(QStringLiteral("underName"), JsonLdDocument::toJson(p.person()));
results.push_back(res);
if (returnTrip.size() > 1) {
if (isValidTrip(returnTrip)) {
res.insert(QStringLiteral("reservationFor"), returnTrip);
results.push_back(res);
}
......
Supports Markdown
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