Commit 9488a1fa authored by Volker Krause's avatar Volker Krause
Browse files

Multiply results when encountering reservationFor arrays

This case actually occurs in the wild after all, in Swiss JSON-LD booking
confirmations.
parent f53cf7f6
[
{
"@context": "http://schema.org",
"@type": "FlightReservation",
"reservationFor": [
{
"@type": "Flight",
"airline": {
"@type": "Airline",
"iataCode": "AB"
},
"arrivalAirport": {
"@type": "Airport",
"iataCode": "TXL"
},
"arrivalTime": "1970-01-01T01:00:00",
"departureAirport": {
"@type": "Airport",
"iataCode": "SXF"
},
"departureTime": "1970-01-01T00:45:00",
"flightNumber": "1234"
},
{
"@type": "Flight",
"airline": {
"@type": "Airline",
"iataCode": "AB"
},
"arrivalAirport": {
"@type": "Airport",
"iataCode": "SXF"
},
"arrivalTime": "1970-01-02T01:00:00",
"departureAirport": {
"@type": "Airport",
"iataCode": "TXL"
},
"departureTime": "1970-01-02T00:45:00",
"flightNumber": "4321"
}
],
"reservationNumber": "XXX007"
}
]
[
{
"@context": "http://schema.org",
"@type": "FlightReservation",
"reservationFor": {
"@type": "Flight",
"airline": {
"@type": "Airline",
"iataCode": "AB"
},
"arrivalAirport": {
"@type": "Airport",
"iataCode": "TXL"
},
"arrivalTime": "1970-01-01T01:00:00",
"departureAirport": {
"@type": "Airport",
"iataCode": "SXF"
},
"departureTime": "1970-01-01T00:45:00",
"flightNumber": "1234"
},
"reservationNumber": "XXX007",
"reservationStatus": "http://schema.org/ReservationConfirmed"
},
{
"@context": "http://schema.org",
"@type": "FlightReservation",
"reservationFor": {
"@type": "Flight",
"airline": {
"@type": "Airline",
"iataCode": "AB"
},
"arrivalAirport": {
"@type": "Airport",
"iataCode": "SXF"
},
"arrivalTime": "1970-01-02T01:00:00",
"departureAirport": {
"@type": "Airport",
"iataCode": "TXL"
},
"departureTime": "1970-01-02T00:45:00",
"flightNumber": "4321"
},
"reservationNumber": "XXX007",
"reservationStatus": "http://schema.org/ReservationConfirmed"
}
]
......@@ -114,18 +114,6 @@ static void filterReservation(QJsonObject &res)
}
}
// unpack reservationFor array - if we ever encounter more than one element in here we'd need to multiply the result
const auto resFor = res.value(QLatin1String("reservationFor"));
if (resFor.isArray()) {
const auto a = resFor.toArray();
if (a.size() > 1) {
qCWarning(Log) << "Found reservationFor array with" << a.size() << "elements!";
}
if (!a.isEmpty()) {
res.insert(QStringLiteral("reservationFor"), a.at(0));
}
}
// normalize reservationStatus enum
auto resStat = res.value(QLatin1String("reservationStatus")).toString();
if (!resStat.isEmpty() && !resStat.contains(QLatin1String("/Reservation"))) {
......@@ -331,7 +319,16 @@ QJsonArray JsonLdImportFilter::filterObject(const QJsonObject &obj)
}
}
results.push_back(res);
// unpack reservationFor array - multiply the result for each entry in here
const auto resFor = res.value(QLatin1String("reservationFor"));
if (const auto a = resFor.toArray(); !a.isEmpty()) {
for (const auto &entry : a) {
res.insert(QLatin1String("reservationFor"), entry);
results.push_back(res);
}
} else {
results.push_back(res);
}
}
return results;
......
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