Commit 752ec4d2 authored by Volker Krause's avatar Volker Krause
Browse files

Align BusTrip API with schema.org

With this structured annotations in Flixbus booking confirmations are
parsed correctly.
parent 6221721b
......@@ -10,14 +10,14 @@
],
"reservationFor": {
"@type": "BusTrip",
"arrivalStation": {
"arrivalBusStop": {
"@type": "BusStation",
"name": "Wien, Lassallestr./Praterstern"
},
"arrivalTime": "2012-08-11T11:20:00",
"busName": "Praha → Vídeň",
"busNumber": "SA",
"departureStation": {
"departureBusStop": {
"@type": "BusStation",
"name": "Brno, AN u hotelu Grand"
},
......@@ -43,14 +43,14 @@
],
"reservationFor": {
"@type": "BusTrip",
"arrivalStation": {
"arrivalBusStop": {
"@type": "BusStation",
"name": "Brno, AN u hotelu Grand"
},
"arrivalTime": "2012-08-12T00:30:00",
"busName": "Vídeň → Praha",
"busNumber": "SA",
"departureStation": {
"departureBusStop": {
"@type": "BusStation",
"name": "Wien, Lassallestr./Praterstern"
},
......
......@@ -10,14 +10,14 @@
],
"reservationFor": {
"@type": "BusTrip",
"arrivalStation": {
"arrivalBusStop": {
"@type": "BusStation",
"name": "Wien, SchwechatAirport Bbf."
},
"arrivalTime": "2012-06-29T05:35:00",
"busName": "Praha → Vídeň",
"busNumber": "SA",
"departureStation": {
"departureBusStop": {
"@type": "BusStation",
"name": "Brno, AN u hotelu Grand"
},
......
......@@ -10,18 +10,18 @@
],
"reservationFor": {
"@type": "BusTrip",
"arrivalStation": {
"arrivalBusStop": {
"@type": "BusStation",
"name": "Brno, AN u hotelu Grand"
},
"arrivalTime": "2015-08-01T00:30:00",
"busName": "Vienna → Prague",
"busNumber": "SA",
"departurePlatform": "2",
"departureStation": {
"departureBusStop": {
"@type": "BusStation",
"name": "Wien, Schwechat Airport Bbf."
},
"departurePlatform": "2",
"departureTime": "2015-07-31T22:10:00"
},
"reservationNumber": "0123456789",
......
......@@ -263,8 +263,8 @@ static void fillTrainReservation(const TrainReservation &reservation, const KCal
static void fillBusReservation(const BusReservation &reservation, const KCalCore::Event::Ptr &event)
{
const auto trip = reservation.reservationFor().value<BusTrip>();
const auto depStation = trip.departureStation();
const auto arrStation = trip.arrivalStation();
const auto depStation = trip.departureBusStop();
const auto arrStation = trip.arrivalBusStop();
event->setSummary(i18n("Bus %1 from %2 to %3", trip.busNumber(), depStation.name(), arrStation.name()));
event->setLocation(depStation.name());
......
......@@ -28,10 +28,10 @@ class BusTripPrivate : public QSharedData
{
public:
QString arrivalPlatform;
BusStation arrivalStation;
BusStation arrivalBusStop;
QDateTime arrivalTime;
QString departurePlatform;
BusStation departureStation;
BusStation departureBusStop;
QDateTime departureTime;
QString busName;
QString busNumber;
......@@ -40,10 +40,10 @@ public:
KITINERARY_MAKE_SIMPLE_CLASS(BusTrip)
KITINERARY_MAKE_PROPERTY(BusTrip, QString, arrivalPlatform, setArrivalPlatform)
KITINERARY_MAKE_PROPERTY(BusTrip, BusStation, arrivalStation, setArrivalStation)
KITINERARY_MAKE_PROPERTY(BusTrip, BusStation, arrivalBusStop, setArrivalBusStop)
KITINERARY_MAKE_PROPERTY(BusTrip, QDateTime, arrivalTime, setArrivalTime)
KITINERARY_MAKE_PROPERTY(BusTrip, QString, departurePlatform, setDeparturePlatform)
KITINERARY_MAKE_PROPERTY(BusTrip, BusStation, departureStation, setDepartureStation)
KITINERARY_MAKE_PROPERTY(BusTrip, BusStation, departureBusStop, setDepartureBusStop)
KITINERARY_MAKE_PROPERTY(BusTrip, QDateTime, departureTime, setDepartureTime)
KITINERARY_MAKE_PROPERTY(BusTrip, QString, busName, setBusName)
KITINERARY_MAKE_PROPERTY(BusTrip, QString, busNumber, setBusNumber)
......
......@@ -34,15 +34,19 @@ class KITINERARY_EXPORT BusTrip
{
KITINERARY_GADGET(BusTrip)
KITINERARY_PROPERTY(QString, arrivalPlatform, setArrivalPlatform) // ### is this used? it's not in the schema
KITINERARY_PROPERTY(KItinerary::BusStation, arrivalStation, setArrivalStation) // ### the schema calls this arrivalBusStop?
KITINERARY_PROPERTY(KItinerary::BusStation, arrivalBusStop, setArrivalBusStop)
KITINERARY_PROPERTY(QDateTime, arrivalTime, setArrivalTime)
KITINERARY_PROPERTY(QString, departurePlatform, setDeparturePlatform) // ### not in the schema
KITINERARY_PROPERTY(KItinerary::BusStation, departureStation, setDepartureStation) // ### see above
KITINERARY_PROPERTY(KItinerary::BusStation, departureBusStop, setDepartureBusStop)
KITINERARY_PROPERTY(QDateTime, departureTime, setDepartureTime)
KITINERARY_PROPERTY(QString, busName, setBusName)
KITINERARY_PROPERTY(QString, busNumber, setBusNumber)
KITINERARY_PROPERTY(KItinerary::Organization, provider, setProvider)
[[deprecated]] inline KItinerary::BusStation arrivalStation() const { return arrivalBusStop(); }
[[deprecated]] inline KItinerary::BusStation departureStation() const { return departureBusStop(); }
Q_PROPERTY(KItinerary::BusStation arrivalStation READ arrivalStation STORED false)
Q_PROPERTY(KItinerary::BusStation departureStation READ departureStation STORED false)
private:
QExplicitlySharedDataPointer<BusTripPrivate> d;
};
......
......@@ -392,10 +392,10 @@ BusReservation ExtractorPostprocessorPrivate::processBusReservation(BusReservati
BusTrip ExtractorPostprocessorPrivate::processBusTrip(BusTrip trip) const
{
trip.setDepartureStation(processPlace(trip.departureStation()));
trip.setArrivalStation(processPlace(trip.arrivalStation()));
trip.setDepartureTime(processTimeForLocation(trip.departureTime(), trip.departureStation()));
trip.setArrivalTime(processTimeForLocation(trip.arrivalTime(), trip.arrivalStation()));
trip.setDepartureBusStop(processPlace(trip.departureBusStop()));
trip.setArrivalBusStop(processPlace(trip.arrivalBusStop()));
trip.setDepartureTime(processTimeForLocation(trip.departureTime(), trip.departureBusStop()));
trip.setArrivalTime(processTimeForLocation(trip.arrivalTime(), trip.arrivalBusStop()));
return trip;
}
......@@ -659,8 +659,8 @@ bool ExtractorPostprocessorPrivate::filterTrainTrip(const TrainTrip &trip) const
bool ExtractorPostprocessorPrivate::filterBusTrip(const BusTrip &trip) const
{
return filterTrainOrBusStation(trip.departureStation())
&& filterTrainOrBusStation(trip.arrivalStation())
return filterTrainOrBusStation(trip.departureBusStop())
&& filterTrainOrBusStation(trip.arrivalBusStop())
&& trip.departureTime().isValid() && trip.arrivalTime().isValid();
}
......
......@@ -148,6 +148,33 @@ static void filterEventReservation(QJsonObject &res)
res.insert(QLatin1String("reservationFor"), event);
}
static void filterBusStop(QJsonObject &station)
{
renameType(station, "BusStop", "BusStation");
}
static void filterBusTrip(QJsonObject &trip)
{
renameProperty(trip, "arrivalStation", "arrivalBusStop");
renameProperty(trip, "departureStation", "departureBusStop");
renameProperty(trip, "busCompany", "provider");
auto station = trip.value(QLatin1String("arrivalBusStop")).toObject();
filterBusStop(station);
trip.insert(QLatin1String("arrivalBusStop"), station);
station = trip.value(QLatin1String("departureBusStop")).toObject();
filterBusStop(station);
trip.insert(QLatin1String("departureBusStop"), station);
}
static void filterBusReservation(QJsonObject &res)
{
QJsonObject trip = res.value(QLatin1String("reservationFor")).toObject();
filterBusTrip(trip);
res.insert(QLatin1String("reservationFor"), trip);
}
static QJsonArray filterActions(const QJsonValue &v)
{
QJsonArray actions;
......@@ -193,6 +220,8 @@ QJsonObject JsonLdImportFilter::filterObject(const QJsonObject& obj)
filterTaxiReservation(res);
} else if (type == QLatin1String("EventReservation")) {
filterEventReservation(res);
} else if (type == QLatin1String("BusReservation")) {
filterBusReservation(res);
}
auto actions = res.value(QLatin1String("potentialAction"));
......
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