Commit 3039b79a authored by Volker Krause's avatar Volker Krause
Browse files

Extend Ticket to cover more properties specified in schema.org

We'll use that to model tickets not bound to a reservation, such as time
range flat rate tickets.

Extend the post-processor in the same way, and prepare it for top-level
Ticket objects.
parent d341f083
Pipeline #185481 passed with stage
in 8 minutes and 19 seconds
......@@ -25,12 +25,15 @@ X-KDE-KITINERARY-RESERVATION:[{"@context":"http://schema.org"\,"@type":
"Europe/Paris"}\,"departureDay":"2017-09-29"\,"departureStation":{"@type":
"TrainStation"\,"address":{"@type":"PostalAddress"\,"addressCountry":
"FR"}\,"geo":{"@type":"GeoCoordinates"\,"latitude":
43.83229064941406\,"longitude":4.365845203399658}\,"name":"Nîmes Gare"}\,"departureTime":{"@type":"QDateTime"\,"@value":"2017-09-29T18:26:00+02:00"\,"timezone":"Europe/Paris"}\,"provider":{"@type":
43.83229064941406\,"longitude":4.365845203399658}\,"name":"Nîmes
Gare"}\,"departureTime":{"@type":"QDateTime"\,"@value":"2017-09-29T18:26:
00+02:00"\,"timezone":"Europe/Paris"}\,"provider":{"@type":
"Organization"\,"name":"SNCF"}\,"trainName":"TGV"\,"trainNumber":
"5186"}\,"reservationNumber":"XXX007"\,"reservationStatus":"http://schema.org/ReservationConfirmed"\,"reservedTicket":{"@type":
"Ticket"\,"ticketedSeat":{"@type":
"Seat"\,"seatNumber":"62"\,"seatSection":"17"\,"seatingType":
"Economy"}}\,"underName":{"@type":"Person"\,"name":"John Doe"}\,"url":
"https://www.trainline.fr/tickets"}]
"5186"}\,"reservationNumber":"XXX007"\,"reservationStatus":"http:
//schema.org/ReservationConfirmed"\,"reservedTicket":{"@type":
"Ticket"\,"ticketedSeat":{"@type":"Seat"\,"seatNumber":
"62"\,"seatSection":"17"\,"seatingType":"Economy"}\,"underName":{"@type":
"Person"\,"name":"John Doe"}}\,"underName":{"@type":"Person"\,"name":
"John Doe"}\,"url":"https://www.trainline.fr/tickets"}]
END:VEVENT
END:VCALENDAR
......@@ -65,6 +65,10 @@
"seatNumber": "71",
"seatSection": "13",
"seatingType": "First"
},
"underName": {
"@type": "Person",
"name": "John Doe"
}
},
"underName": {
......@@ -139,6 +143,10 @@
"seatNumber": "62",
"seatSection": "17",
"seatingType": "Economy"
},
"underName": {
"@type": "Person",
"name": "John Doe"
}
},
"underName": {
......
......@@ -33,14 +33,20 @@ class TicketPrivate : public QSharedData
{
public:
QString name;
Organization issuedBy;
QString ticketNumber;
Seat ticketedSeat;
QString ticketToken;
Person underName;
};
KITINERARY_MAKE_SIMPLE_CLASS(Ticket)
KITINERARY_MAKE_PROPERTY(Ticket, QString, name, setName)
KITINERARY_MAKE_PROPERTY(Ticket, Organization, issuedBy, setIssuedBy)
KITINERARY_MAKE_PROPERTY(Ticket, QString, ticketNumber, setTicketNumber)
KITINERARY_MAKE_PROPERTY(Ticket, Seat, ticketedSeat, setTicketedSeat)
KITINERARY_MAKE_PROPERTY(Ticket, QString, ticketToken, setTicketToken)
KITINERARY_MAKE_PROPERTY(Ticket, Person, underName, setUnderName)
KITINERARY_MAKE_OPERATOR(Ticket)
Token::TokenType Ticket::ticketTokenType() const
......
......@@ -8,6 +8,8 @@
#include "kitinerary_export.h"
#include "datatypes.h"
#include "organization.h"
#include "person.h"
#include "token.h"
namespace KItinerary {
......@@ -37,6 +39,8 @@ class KITINERARY_EXPORT Ticket
{
KITINERARY_GADGET(Ticket)
KITINERARY_PROPERTY(QString, name, setName)
KITINERARY_PROPERTY(KItinerary::Organization, issuedBy, setIssuedBy)
KITINERARY_PROPERTY(QString, ticketNumber, setTicketNumber)
KITINERARY_PROPERTY(KItinerary::Seat, ticketedSeat, setTicketedSeat)
/** The raw ticket token string.
* @see ticketTokenType, ticketTokenData
......@@ -50,6 +54,8 @@ class KITINERARY_EXPORT Ticket
*/
Q_PROPERTY(QVariant ticketTokenData READ ticketTokenData STORED false)
KITINERARY_PROPERTY(KItinerary::Person, underName, setUnderName)
public:
/** The type of content in the ticketToken property.
* @deprecated Use Token::TokenType instead.
......
......@@ -121,6 +121,8 @@ void ExtractorPostprocessor::process(const QVector<QVariant> &data)
// non-reservation types
else if (JsonLd::isA<ProgramMembership>(elem)) {
elem = d->processProgramMembership(elem.value<ProgramMembership>());
} else if (JsonLd::isA<Ticket>(elem)) {
elem = d->processTicket(elem.value<Ticket>());
}
d->mergeOrAppend(elem);
......@@ -421,6 +423,14 @@ KItinerary::Event ExtractorPostprocessorPrivate::processEvent(KItinerary::Event
return event;
}
Ticket ExtractorPostprocessorPrivate::processTicket(Ticket ticket) const
{
ticket.setName(StringUtil::clean(ticket.name()));
ticket.setTicketNumber(ticket.ticketNumber().simplified());
ticket.setUnderName(processPerson(ticket.underName()));
return ticket;
}
ProgramMembership ExtractorPostprocessorPrivate::processProgramMembership(ProgramMembership program) const
{
program.setProgramName(program.programName().simplified());
......@@ -439,6 +449,10 @@ T ExtractorPostprocessorPrivate::processReservation(T res) const
res.setPotentialAction(processActions(res.potentialAction()));
res.setReservationNumber(res.reservationNumber().trimmed());
res.setProgramMembershipUsed(processProgramMembership(res.programMembershipUsed()));
if (JsonLd::isA<Ticket>(res.reservedTicket())) {
res.setReservedTicket(processTicket(res.reservedTicket().template value<Ticket>()));
}
return res;
}
......
......@@ -31,6 +31,7 @@ class ProgramMembership;
class RentalCar;
class RentalCarReservation;
class TaxiReservation;
class Ticket;
class TouristAttractionVisit;
class TrainReservation;
class TrainStation;
......@@ -60,6 +61,7 @@ public:
TaxiReservation processTaxiReservation(TaxiReservation res) const;
Event processEvent(Event event) const;
Ticket processTicket(Ticket ticket) const;
ProgramMembership processProgramMembership(ProgramMembership program) const;
template <typename T> T processReservation(T res) const;
......
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