Commit 4b601aff authored by Volker Krause's avatar Volker Krause
Browse files

Return full station objects from the UIC 918.3 parser

Prepares this for handling ERA FCB data as well.
parent 6b87ead4
Pipeline #256470 passed with stage
in 12 minutes and 37 seconds
......@@ -32,8 +32,50 @@
"url": ""
},
"name": "Normalpreis",
"outboundArrivalStationId": "",
"outboundDepartureStationId": "",
"outboundArrivalStation": {
"address": {
"addressCountry": "",
"addressLocality": "",
"addressRegion": "",
"className": "PostalAddress",
"isEmpty": true,
"postalCode": "",
"streetAddress": ""
},
"className": "TrainStation",
"geo": {
"className": "GeoCoordinates",
"isValid": false,
"latitude": null,
"longitude": null
},
"geoUri": "",
"identifier": "",
"name": "Frankfurt(Main)+City",
"telephone": ""
},
"outboundDepartureStation": {
"address": {
"addressCountry": "",
"addressLocality": "",
"addressRegion": "",
"className": "PostalAddress",
"isEmpty": true,
"postalCode": "",
"streetAddress": ""
},
"className": "TrainStation",
"geo": {
"className": "GeoCoordinates",
"isValid": false,
"latitude": null,
"longitude": null
},
"geoUri": "",
"identifier": "",
"name": "Köln",
"telephone": ""
},
"person": {
"className": "Person",
"email": "",
......@@ -83,8 +125,50 @@
"url": ""
},
"name": "Normalpreis",
"outboundArrivalStationId": "",
"outboundDepartureStationId": "",
"outboundArrivalStation": {
"address": {
"addressCountry": "",
"addressLocality": "",
"addressRegion": "",
"className": "PostalAddress",
"isEmpty": true,
"postalCode": "",
"streetAddress": ""
},
"className": "TrainStation",
"geo": {
"className": "GeoCoordinates",
"isValid": false,
"latitude": null,
"longitude": null
},
"geoUri": "",
"identifier": "",
"name": "Frankfurt(Main)+City",
"telephone": ""
},
"outboundDepartureStation": {
"address": {
"addressCountry": "",
"addressLocality": "",
"addressRegion": "",
"className": "PostalAddress",
"isEmpty": true,
"postalCode": "",
"streetAddress": ""
},
"className": "TrainStation",
"geo": {
"className": "GeoCoordinates",
"isValid": false,
"latitude": null,
"longitude": null
},
"geoUri": "",
"identifier": "",
"name": "Köln",
"telephone": ""
},
"person": {
"className": "Person",
"email": "",
......
......@@ -8,6 +8,14 @@
"identifier": "uic:0080"
},
"name": "Normalpreis",
"outboundArrivalStation": {
"@type": "TrainStation",
"name": "Frankfurt(Main)+City"
},
"outboundDepartureStation": {
"@type": "TrainStation",
"name": "Köln"
},
"person": {
"@type": "Person",
"familyName": "häöür Räß",
......
......@@ -141,8 +141,8 @@ function parseTicket(text, uic918ticket) {
// for outward journeys we have station ids from the UIC 918-3 code
if (uic918ticket && header[1] === "Hin") {
reservations[0].reservationFor.departureStation.identifier = uic918ticket.outboundDepartureStationId;
reservations[reservations.length - 1].reservationFor.arrivalStation.identifier = uic918ticket.outboundArrivalStationId;
reservations[0].reservationFor.departureStation.identifier = uic918ticket.outboundDepartureStation.identifier;
reservations[reservations.length - 1].reservationFor.arrivalStation.identifier = uic918ticket.outboundArrivalStation.identifier;
returnResIndex = reservations.length;
} else {
// propagate station ids from outward to return journey
......@@ -290,15 +290,13 @@ function parseUic9183(code, node) {
// domestic ticket code
const bl = code.block('0080BL');
if (bl) {
if (bl && code.outboundDepartureStation.name && code.outboundArrivalStation.name) {
let res = JsonLd.newTrainReservation();
res.reservedTicket = node.result[0];
applyUic9183ToReservation(res, code);
res.reservationFor.departureDay = JsonLd.toDateTime(bl.findSubBlock('031').content, 'dd.mm.yyyy', 'de');
res.reservationFor.departureStation.name = bl.findSubBlock('015').content;
res.reservationFor.departureStation.identifier = code.outboundDepartureStationId;
res.reservationFor.arrivalStation.name = bl.findSubBlock('016').content;
res.reservationFor.arrivalStation.identifier = code.outboundArrivalStationId;
res.reservationFor.departureStation = JsonLd.toJson(code.outboundDepartureStation);
res.reservationFor.arrivalStation = JsonLd.toJson(code.outboundArrivalStation);
if (!bl.findSubBlock('017')) {
return res;
......@@ -309,9 +307,9 @@ function parseUic9183(code, node) {
applyUic9183ToReservation(ret, code);
ret.reservationFor.departureDay = JsonLd.toDateTime(bl.findSubBlock('032').content, 'dd.mm.yyyy', 'de');
ret.reservationFor.departureStation.name = bl.findSubBlock('017').content;
ret.reservationFor.departureStation.identifier = ret.reservationFor.departureStation.name === res.reservationFor.arrivalStation.name ? code.outboundArrivalStationId : undefined;
ret.reservationFor.departureStation.identifier = ret.reservationFor.departureStation.name === res.reservationFor.arrivalStation.name ? code.outboundArrivalStation.identifier : undefined;
ret.reservationFor.arrivalStation.name = bl.findSubBlock('018').content;
ret.reservationFor.arrivalStation.identifier = ret.reservationFor.arrivalStation.name === res.reservationFor.departureStation.name ? code.outboundDepartureStationId : undefined;
ret.reservationFor.arrivalStation.identifier = ret.reservationFor.arrivalStation.name === res.reservationFor.departureStation.name ? code.outboundDepartureStation.identifier : undefined;
return [res, ret];
}
......
......@@ -399,34 +399,42 @@ Person Uic9183Parser::person() const
return {};
}
QString Uic9183Parser::outboundDepartureStationId() const
TrainStation Uic9183Parser::outboundDepartureStation() const
{
const auto b = findBlock<Vendor0080BLBlock>();
if (b.isValid()) {
TrainStation station;
if (const auto b = findBlock<Vendor0080BLBlock>(); b.isValid()) {
if (const auto sblock = b.findSubBlock("015"); !sblock.isNull()) {
station.setName(sblock.toString());
}
// S035 contains the IBNR, possible with leading '80' country code and leading 0 stripped
const auto sblock = b.findSubBlock("035");
if (!sblock.isNull() && sblock.contentSize() <= 7) {
if (const auto sblock = b.findSubBlock("035"); !sblock.isNull() && sblock.contentSize() <= 7) {
QString ibnr = QStringLiteral("ibnr:8000000");
const auto s = sblock.toString();
return ibnr.replace(ibnr.size() - s.size(), s.size(), s);
station.setIdentifier(ibnr.replace(ibnr.size() - s.size(), s.size(), s));
}
}
return {};
return station;
}
QString Uic9183Parser::outboundArrivalStationId() const
TrainStation Uic9183Parser::outboundArrivalStation() const
{
const auto b = findBlock<Vendor0080BLBlock>();
if (b.isValid()) {
TrainStation station;
if (const auto b = findBlock<Vendor0080BLBlock>(); b.isValid()) {
if (const auto sblock = b.findSubBlock("016"); !sblock.isNull()) {
station.setName(sblock.toString());
}
// S036 contains the IBNR, possible with leading '80' country code and leading 0 stripped
const auto sblock = b.findSubBlock("036");
if (!sblock.isNull() && sblock.contentSize() <= 7) {
if (const auto sblock = b.findSubBlock("036"); !sblock.isNull() && sblock.contentSize() <= 7) {
QString ibnr = QStringLiteral("ibnr:8000000");
const auto s = sblock.toString();
return ibnr.replace(ibnr.size() - s.size(), s.size(), s);
station.setIdentifier(ibnr.replace(ibnr.size() - s.size(), s.size(), s));
}
}
return {};
return station;
}
static QString fcbClassCodeToString(Fcb::TravelClassType classCode)
......
......@@ -10,6 +10,7 @@
#include <KItinerary/Organization>
#include <KItinerary/Person>
#include <KItinerary/Place>
#include <QExplicitlySharedDataPointer>
#include <QMetaType>
......@@ -43,8 +44,8 @@ class KITINERARY_EXPORT Uic9183Parser
Q_PROPERTY(QDateTime validFrom READ validFrom)
Q_PROPERTY(QDateTime validUntil READ validUntil)
Q_PROPERTY(KItinerary::Person person READ person)
Q_PROPERTY(QString outboundDepartureStationId READ outboundDepartureStationId)
Q_PROPERTY(QString outboundArrivalStationId READ outboundArrivalStationId)
Q_PROPERTY(KItinerary::TrainStation outboundDepartureStation READ outboundDepartureStation)
Q_PROPERTY(KItinerary::TrainStation outboundArrivalStation READ outboundArrivalStation)
Q_PROPERTY(QString seatingType READ seatingType)
/** U_TLAY ticket layout block, if present, @c null otherwise. */
Q_PROPERTY(QVariant ticketLayout READ ticketLayoutVariant)
......@@ -82,10 +83,10 @@ public:
/** The person this ticket is issued to. */
Person person() const;
/** Station identifier for the departure station of the outbound trip. */
QString outboundDepartureStationId() const;
/** Station identifier for the arrival station of the outbound trip. */
QString outboundArrivalStationId() const;
/** Station object for the departure station of the outbound trip. */
TrainStation outboundDepartureStation() const;
/** Station object for the arrival station of the outbound trip. */
TrainStation outboundArrivalStation() const;
/** @see Ticket::seatingType */
QString seatingType() 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