Commit 820ab761 authored by Volker Krause's avatar Volker Krause

Implement generic extractor for RCT2 reservation tickets

parent 877746c8
......@@ -145,17 +145,51 @@ void GenericPdfExtractor::extractUic9183(const QByteArray &data, QJsonArray &res
return;
}
// TODO: add RCT2 ticket data
QJsonObject org;
org.insert(QLatin1String("@type"), QLatin1String("Organization"));
org.insert(QLatin1String("identifier"), QString(QLatin1String("uic:") + p.carrierId()));
QJsonObject trip;
trip.insert(QLatin1String("@type"), QLatin1String("TrainTrip"));
trip.insert(QLatin1String("provider"), org);
QJsonObject seat;
seat.insert(QLatin1String("@type"), QLatin1String("Seat"));
const auto rct2 = p.rct2Ticket();
if (rct2.isValid()) {
switch (rct2.type()) {
case Rct2Ticket::Reservation:
{
QJsonObject dep;
dep.insert(QLatin1String("@type"), QLatin1String("TrainStation"));
dep.insert(QLatin1String("name"), rct2.outboundDepartureStation());
trip.insert(QLatin1String("departureStation"), dep);
trip.insert(QLatin1String("departureTime"), rct2.outboundDepartureTime().toString(Qt::ISODate));
QJsonObject arr;
arr.insert(QLatin1String("@type"), QLatin1String("TrainStation"));
arr.insert(QLatin1String("name"), rct2.outboundArrivalStation());
trip.insert(QLatin1String("arrivalStation"), arr);
trip.insert(QLatin1String("arrivalTime"), rct2.outboundArrivalTime().toString(Qt::ISODate));
trip.insert(QLatin1String("trainNumber"), rct2.trainNumber());
seat.insert(QLatin1String("seatSection"), rct2.coachNumber());
seat.insert(QLatin1String("seatNumber"), rct2.seatNumber());
break;
}
default:
break;
}
}
QJsonObject ticket;
ticket.insert(QLatin1String("@type"), QLatin1String("Ticket"));
ticket.insert(QLatin1String("ticketedSeat"), seat);
QJsonObject res;
res.insert(QLatin1String("@type"), QLatin1String("TrainReservation"));
res.insert(QLatin1String("reservationFor"), trip);
res.insert(QLatin1String("reservationNumber"), p.pnr());
res.insert(QLatin1String("reservedTicket"), ticket);
result.push_back(res);
}
......@@ -461,6 +461,15 @@ QDate Rct2Ticket::firstDayOfValidity() const
return d->firstDayOfValidity();
}
Rct2Ticket::Type Rct2Ticket::type() const
{
// ### this field can theoretically be translated
if (d->fieldText(0, 18, 51).trimmed().compare(QLatin1String("RESERVATION"), Qt::CaseInsensitive) == 0) {
return Reservation;
}
return Unknown;
}
QDateTime Rct2Ticket::outboundDepartureTime() const
{
return d->parseTime(d->fieldText(6, 1, 5), d->fieldText(6, 7, 5));
......@@ -486,6 +495,30 @@ QString Rct2Ticket::outboundClass() const
return d->fieldText(6, 66, 5).trimmed();
}
QString Rct2Ticket::trainNumber() const
{
if (type() == Reservation) {
return d->fieldText(8, 7, 5).trimmed();
}
return {};
}
QString Rct2Ticket::coachNumber() const
{
if (type() == Reservation) {
return d->fieldText(8, 26, 3).trimmed();
}
return {};
}
QString Rct2Ticket::seatNumber() const
{
if (type() == Reservation) {
return d->fieldText(8, 48, 23).trimmed();
}
return {};
}
Uic9183Parser::Uic9183Parser()
: d(new Uic9183ParserPrivate)
......
......@@ -38,11 +38,15 @@ class KITINERARY_EXPORT Rct2Ticket
{
Q_GADGET
Q_PROPERTY(QDate firstDayOfValidity READ firstDayOfValidity)
Q_PROPERTY(Type type READ type)
Q_PROPERTY(QDateTime outboundDepartureTime READ outboundDepartureTime)
Q_PROPERTY(QDateTime outboundArrivalTime READ outboundArrivalTime)
Q_PROPERTY(QString outboundDepartureStation READ outboundDepartureStation)
Q_PROPERTY(QString outboundArrivalStation READ outboundArrivalStation)
Q_PROPERTY(QString outboundClass READ outboundClass)
Q_PROPERTY(QString trainNumber READ trainNumber)
Q_PROPERTY(QString coachNumber READ coachNumber)
Q_PROPERTY(QString seatNumber READ seatNumber)
public:
Rct2Ticket();
......@@ -58,6 +62,18 @@ public:
/** First day the ticket is valid. */
QDate firstDayOfValidity() const;
/** Type of RCT2 ticket.
* @see ERA TAP TSI Annex B.6.
*/
enum Type {
Reservation, ///< an reservation-only ticket (RES)
Unknown ///< ticket type could not be detected, or ticket type not supported yet
};
Q_ENUM(Type);
/** Returns the ticket type. */
Type type() const;
/** Departure time of the outbound segment. */
QDateTime outboundDepartureTime() const;
/** Arrival time of the outbound segment. */
......@@ -69,6 +85,13 @@ public:
/** Class of the outbound segment. */
QString outboundClass() const;
/** Train number (for reservation tickets). */
QString trainNumber() const;
/** Coach number (for reservation tickets). */
QString coachNumber() const;
/** Seat number (for reservation tickets). */
QString seatNumber() const;
private:
friend class Uic9183Parser;
Rct2Ticket(Uic9183Block block);
......
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