Commit 86fd5c8e authored by Volker Krause's avatar Volker Krause
Browse files

Generalize QJP request generation to also support TRIAS

Besides different XML namespaces there are just minor differences in a few
tags. Good enough already to trigger valid responses from the VVO TRIAS
endpoint.
parent 7fb16beb
<?xml version="1.0" encoding="UTF-8"?>
<trias:Trias xmlns:siri="http://www.siri.org.uk/siri" xmlns:trias="http://www.vdv.de/trias" version="1.2">
<trias:ServiceRequest>
<siri:RequestorRef>KPublicTransport</siri:RequestorRef>
<trias:RequestPayload>
<trias:TripRequest>
<trias:Origin>
<trias:LocationRef>
<trias:GeoPosition>
<siri:Longitude>7.78</siri:Longitude>
<siri:Latitude>46.1</siri:Latitude>
</trias:GeoPosition>
<trias:LocationName>
<trias:Text>Randa</trias:Text>
</trias:LocationName>
</trias:LocationRef>
</trias:Origin>
<trias:Destination>
<trias:LocationRef>
<trias:StopPointRef>8500010</trias:StopPointRef>
</trias:LocationRef>
<trias:DepArrTime>2020-09-06T20:54:00Z</trias:DepArrTime>
</trias:Destination>
<trias:Params>
<trias:IncludeTrackSections>true</trias:IncludeTrackSections>
<trias:IncludeLegProjection>true</trias:IncludeLegProjection>
<trias:IncludeTurnDescription>true</trias:IncludeTurnDescription>
<trias:IncludeAccessibility>true</trias:IncludeAccessibility>
<trias:IncludeIntermediateStops>false</trias:IncludeIntermediateStops>
<trias:IncludeFares>false</trias:IncludeFares>
<trias:NumberOfResults>3</trias:NumberOfResults>
</trias:Params>
</trias:TripRequest>
</trias:RequestPayload>
</trias:ServiceRequest>
</trias:Trias>
......@@ -2,7 +2,7 @@
<siri:OJP xmlns:siri="http://www.siri.org.uk/siri" xmlns:ojp="http://www.vdv.de/ojp" version="1.0">
<siri:OJPRequest>
<siri:ServiceRequest>
<siri:RequestRef>KPublicTransport</siri:RequestRef>
<siri:RequestorRef>KPublicTransport</siri:RequestorRef>
<ojp:OJPTripRequest>
<ojp:Origin>
<ojp:PlaceRef>
......
<?xml version="1.0" encoding="UTF-8"?>
<trias:Trias xmlns:siri="http://www.siri.org.uk/siri" xmlns:trias="http://www.vdv.de/trias" version="1.2">
<trias:ServiceRequest>
<siri:RequestorRef>KPublicTransport</siri:RequestorRef>
<trias:RequestPayload>
<trias:TripRequest>
<trias:Origin>
<trias:LocationRef>
<trias:GeoPosition>
<siri:Longitude>7.78</siri:Longitude>
<siri:Latitude>46.1</siri:Latitude>
</trias:GeoPosition>
<trias:LocationName>
<trias:Text> </trias:Text>
</trias:LocationName>
</trias:LocationRef>
<trias:DepArrTime>2020-09-06T20:54:00Z</trias:DepArrTime>
</trias:Origin>
<trias:Destination>
<trias:LocationRef>
<trias:StopPointRef>8500010</trias:StopPointRef>
</trias:LocationRef>
</trias:Destination>
<trias:Params>
<trias:IncludeTrackSections>false</trias:IncludeTrackSections>
<trias:IncludeLegProjection>false</trias:IncludeLegProjection>
<trias:IncludeTurnDescription>false</trias:IncludeTurnDescription>
<trias:IncludeAccessibility>true</trias:IncludeAccessibility>
<trias:IncludeIntermediateStops>true</trias:IncludeIntermediateStops>
<trias:IncludeFares>false</trias:IncludeFares>
<trias:NumberOfResults>3</trias:NumberOfResults>
</trias:Params>
</trias:TripRequest>
</trias:RequestPayload>
</trias:ServiceRequest>
</trias:Trias>
......@@ -2,7 +2,7 @@
<siri:OJP xmlns:siri="http://www.siri.org.uk/siri" xmlns:ojp="http://www.vdv.de/ojp" version="1.0">
<siri:OJPRequest>
<siri:ServiceRequest>
<siri:RequestRef>KPublicTransport</siri:RequestRef>
<siri:RequestorRef>KPublicTransport</siri:RequestorRef>
<ojp:OJPTripRequest>
<ojp:Origin>
<ojp:PlaceRef>
......
<?xml version="1.0" encoding="UTF-8"?>
<trias:Trias xmlns:siri="http://www.siri.org.uk/siri" xmlns:trias="http://www.vdv.de/trias" version="1.2">
<trias:ServiceRequest>
<siri:RequestorRef>KPublicTransport</siri:RequestorRef>
<trias:RequestPayload>
<trias:LocationInformationRequest>
<trias:InitialInput>
<trias:GeoRestriction>
<trias:Circle>
<trias:Center>
<siri:Longitude>7.78</siri:Longitude>
<siri:Latitude>46.1</siri:Latitude>
</trias:Center>
<trias:Radius>500</trias:Radius>
</trias:Circle>
</trias:GeoRestriction>
</trias:InitialInput>
<trias:Restrictions>
<trias:Type>stop</trias:Type>
<trias:NumberOfResults>23</trias:NumberOfResults>
</trias:Restrictions>
</trias:LocationInformationRequest>
</trias:RequestPayload>
</trias:ServiceRequest>
</trias:Trias>
......@@ -2,7 +2,7 @@
<siri:OJP xmlns:siri="http://www.siri.org.uk/siri" xmlns:ojp="http://www.vdv.de/ojp" version="1.0">
<siri:OJPRequest>
<siri:ServiceRequest>
<siri:RequestRef>KPublicTransport</siri:RequestRef>
<siri:RequestorRef>KPublicTransport</siri:RequestorRef>
<ojp:OJPLocationInformationRequest>
<ojp:InitialInput>
<ojp:GeoRestriction>
......
<?xml version="1.0" encoding="UTF-8"?>
<trias:Trias xmlns:siri="http://www.siri.org.uk/siri" xmlns:trias="http://www.vdv.de/trias" version="1.2">
<trias:ServiceRequest>
<siri:RequestorRef>KPublicTransport</siri:RequestorRef>
<trias:RequestPayload>
<trias:LocationInformationRequest>
<trias:InitialInput>
<trias:LocationName>Randa</trias:LocationName>
</trias:InitialInput>
<trias:Restrictions>
<trias:Type>stop</trias:Type>
<trias:NumberOfResults>23</trias:NumberOfResults>
</trias:Restrictions>
</trias:LocationInformationRequest>
</trias:RequestPayload>
</trias:ServiceRequest>
</trias:Trias>
......@@ -2,7 +2,7 @@
<siri:OJP xmlns:siri="http://www.siri.org.uk/siri" xmlns:ojp="http://www.vdv.de/ojp" version="1.0">
<siri:OJPRequest>
<siri:ServiceRequest>
<siri:RequestRef>KPublicTransport</siri:RequestRef>
<siri:RequestorRef>KPublicTransport</siri:RequestorRef>
<ojp:OJPLocationInformationRequest>
<ojp:InitialInput>
<ojp:LocationName>Randa</ojp:LocationName>
......
<?xml version="1.0" encoding="UTF-8"?>
<trias:Trias xmlns:siri="http://www.siri.org.uk/siri" xmlns:trias="http://www.vdv.de/trias" version="1.2">
<trias:ServiceRequest>
<siri:RequestorRef>KPublicTransport</siri:RequestorRef>
<trias:RequestPayload>
<trias:StopEventRequest>
<trias:Location>
<trias:LocationRef>
<trias:StopPointRef>8501687</trias:StopPointRef>
</trias:LocationRef>
<trias:DepArrTime>2020-09-06T20:54:00Z</trias:DepArrTime>
</trias:Location>
<trias:Params>
<trias:StopEventType>arrival</trias:StopEventType>
<trias:IncludePreviousCalls>false</trias:IncludePreviousCalls>
<trias:IncludeOnwardCalls>false</trias:IncludeOnwardCalls>
<trias:IncludeOperatingDays>false</trias:IncludeOperatingDays>
<trias:IncludeRealtimeData>true</trias:IncludeRealtimeData>
<trias:NumberOfResults>4</trias:NumberOfResults>
</trias:Params>
</trias:StopEventRequest>
</trias:RequestPayload>
</trias:ServiceRequest>
</trias:Trias>
......@@ -2,7 +2,7 @@
<siri:OJP xmlns:siri="http://www.siri.org.uk/siri" xmlns:ojp="http://www.vdv.de/ojp" version="1.0">
<siri:OJPRequest>
<siri:ServiceRequest>
<siri:RequestRef>KPublicTransport</siri:RequestRef>
<siri:RequestorRef>KPublicTransport</siri:RequestorRef>
<ojp:OJPStopEventRequest>
<ojp:Location>
<ojp:PlaceRef>
......
<?xml version="1.0" encoding="UTF-8"?>
<trias:Trias xmlns:siri="http://www.siri.org.uk/siri" xmlns:trias="http://www.vdv.de/trias" version="1.2">
<trias:ServiceRequest>
<siri:RequestorRef>KPublicTransport</siri:RequestorRef>
<trias:RequestPayload>
<trias:StopEventRequest>
<trias:Location>
<trias:LocationRef>
<trias:StopPointRef>8501687</trias:StopPointRef>
</trias:LocationRef>
<trias:DepArrTime>2020-09-06T20:54:00Z</trias:DepArrTime>
</trias:Location>
<trias:Params>
<trias:StopEventType>departure</trias:StopEventType>
<trias:IncludePreviousCalls>false</trias:IncludePreviousCalls>
<trias:IncludeOnwardCalls>false</trias:IncludeOnwardCalls>
<trias:IncludeOperatingDays>false</trias:IncludeOperatingDays>
<trias:IncludeRealtimeData>true</trias:IncludeRealtimeData>
<trias:NumberOfResults>4</trias:NumberOfResults>
</trias:Params>
</trias:StopEventRequest>
</trias:RequestPayload>
</trias:ServiceRequest>
</trias:Trias>
......@@ -2,7 +2,7 @@
<siri:OJP xmlns:siri="http://www.siri.org.uk/siri" xmlns:ojp="http://www.vdv.de/ojp" version="1.0">
<siri:OJPRequest>
<siri:ServiceRequest>
<siri:RequestRef>KPublicTransport</siri:RequestRef>
<siri:RequestorRef>KPublicTransport</siri:RequestorRef>
<ojp:OJPStopEventRequest>
<ojp:Location>
<ojp:PlaceRef>
......
......@@ -61,9 +61,19 @@ private Q_SLOTS:
QFETCH(QString, refFileName);
OpenJourneyPlannerRequestBuilder builder;
builder.setRequestorRef(QStringLiteral("KPublicTransport"));
builder.setTestMode(true);
const auto res = builder.buildLocationInformationRequest(request);
const auto ref = readFile(refFileName);
auto res = builder.buildLocationInformationRequest(request);
auto ref = readFile(refFileName);
if (res != ref) {
qDebug().noquote() << res;
}
QVERIFY(!res.isEmpty());
QCOMPARE(res, ref);
builder.setUseTrias(true);
res = builder.buildLocationInformationRequest(request);
ref = readFile(refFileName.insert(refFileName.size() -4, u"-trias"));
if (res != ref) {
qDebug().noquote() << res;
}
......@@ -94,9 +104,19 @@ private Q_SLOTS:
QFETCH(QString, refFileName);
OpenJourneyPlannerRequestBuilder builder;
builder.setRequestorRef(QStringLiteral("KPublicTransport"));
builder.setTestMode(true);
const auto res = builder.buildStopEventRequest(request);
const auto ref = readFile(refFileName);
auto res = builder.buildStopEventRequest(request);
auto ref = readFile(refFileName);
if (res != ref) {
qDebug().noquote() << res;
}
QVERIFY(!res.isEmpty());
QCOMPARE(res, ref);
builder.setUseTrias(true);
res = builder.buildStopEventRequest(request);
ref = readFile(refFileName.insert(refFileName.size() -4, u"-trias"));
if (res != ref) {
qDebug().noquote() << res;
}
......@@ -136,9 +156,19 @@ private Q_SLOTS:
QFETCH(QString, refFileName);
OpenJourneyPlannerRequestBuilder builder;
builder.setRequestorRef(QStringLiteral("KPublicTransport"));
builder.setTestMode(true);
const auto res = builder.buildTripRequest(request);
const auto ref = readFile(refFileName);
auto res = builder.buildTripRequest(request);
auto ref = readFile(refFileName);
if (res != ref) {
qDebug().noquote() << res;
}
QVERIFY(!res.isEmpty());
QCOMPARE(res, ref);
builder.setUseTrias(true);
res = builder.buildTripRequest(request);
ref = readFile(refFileName.insert(refFileName.size() -4, u"-trias"));
if (res != ref) {
qDebug().noquote() << res;
}
......
......@@ -44,8 +44,7 @@ bool OpenJourneyPlannerBackend::queryLocation(const LocationRequest &request, Lo
return false;
}
OpenJourneyPlannerRequestBuilder builder;
const auto postData = builder.buildLocationInformationRequest(request);
const auto postData = requestBuilder().buildLocationInformationRequest(request);
const auto netReq = networkRequest();
logRequest(request, netReq, postData);
const auto netReply = nam->post(netReq, postData);
......@@ -74,8 +73,7 @@ bool OpenJourneyPlannerBackend::queryLocation(const LocationRequest &request, Lo
bool OpenJourneyPlannerBackend::queryStopover(const StopoverRequest &request, StopoverReply *reply, QNetworkAccessManager *nam) const
{
OpenJourneyPlannerRequestBuilder builder;
const auto postData = builder.buildStopEventRequest(request);
const auto postData = requestBuilder().buildStopEventRequest(request);
const auto netReq = networkRequest();
logRequest(request, netReq, postData);
const auto netReply = nam->post(netReq, postData);
......@@ -104,8 +102,7 @@ bool OpenJourneyPlannerBackend::queryStopover(const StopoverRequest &request, St
bool OpenJourneyPlannerBackend::queryJourney(const JourneyRequest &request, JourneyReply *reply, QNetworkAccessManager *nam) const
{
OpenJourneyPlannerRequestBuilder builder;
const auto postData = builder.buildTripRequest(request);
const auto postData = requestBuilder().buildTripRequest(request);
const auto netReq = networkRequest();
logRequest(request, netReq, postData);
const auto netReply = nam->post(netReq, postData);
......@@ -141,3 +138,11 @@ QNetworkRequest OpenJourneyPlannerBackend::networkRequest() const
}
return req;
}
OpenJourneyPlannerRequestBuilder OpenJourneyPlannerBackend::requestBuilder() const
{
OpenJourneyPlannerRequestBuilder builder;
builder.setRequestorRef(m_requestorRef);
builder.setUseTrias(m_useTrias);
return builder;
}
......@@ -15,6 +15,8 @@ class QNetworkRequest;
namespace KPublicTransport {
class OpenJourneyPlannerRequestBuilder;
/** Backend for OpenJourneyPlanner services
* Due to its similarities, this might also be viable for TRIAS-based services.
*/
......@@ -23,6 +25,8 @@ class OpenJourneyPlannerBackend : public AbstractBackend
Q_GADGET
Q_PROPERTY(QUrl endpoint MEMBER m_endpoint)
Q_PROPERTY(QString authorization MEMBER m_authorization)
Q_PROPERTY(QString requestorRef MEMBER m_requestorRef)
Q_PROPERTY(bool useTrias MEMBER m_useTrias)
public:
static inline constexpr const char* type() { return "openJourneyPlanner"; }
......@@ -34,9 +38,12 @@ public:
private:
QNetworkRequest networkRequest() const;
OpenJourneyPlannerRequestBuilder requestBuilder() const;
QUrl m_endpoint;
QString m_authorization;
QString m_requestorRef;
bool m_useTrias = false;
};
}
......
......@@ -19,6 +19,20 @@ using namespace KPublicTransport;
static QString siriNS() { return QStringLiteral("http://www.siri.org.uk/siri"); }
static QString ojpNS() { return QStringLiteral("http://www.vdv.de/ojp"); }
static QString triasNS() { return QStringLiteral("http://www.vdv.de/trias"); }
OpenJourneyPlannerRequestBuilder::OpenJourneyPlannerRequestBuilder() = default;
OpenJourneyPlannerRequestBuilder::~OpenJourneyPlannerRequestBuilder() = default;
void OpenJourneyPlannerRequestBuilder::setRequestorRef(const QString &ref)
{
m_requestorRef = ref;
}
void OpenJourneyPlannerRequestBuilder::setUseTrias(bool isTrias)
{
m_useTrias = isTrias;
}
void OpenJourneyPlannerRequestBuilder::setTestMode(bool testMode)
{
......@@ -31,32 +45,31 @@ QByteArray OpenJourneyPlannerRequestBuilder::buildLocationInformationRequest(con
QXmlStreamWriter w(&output);
setupWriter(w);
writeStartServiceRequest(w);
w.writeTextElement(siriNS(), QStringLiteral("RequestRef"), QStringLiteral("KPublicTransport"));
w.writeStartElement(ojpNS(), QStringLiteral("OJPLocationInformationRequest"));
w.writeStartElement(ns(), m_useTrias ? QStringLiteral("LocationInformationRequest") : QStringLiteral("OJPLocationInformationRequest"));
w.writeStartElement(ojpNS(), QStringLiteral("InitialInput"));
w.writeStartElement(ns(), QStringLiteral("InitialInput"));
if (req.hasCoordinate()) {
w.writeStartElement(ojpNS(), QStringLiteral("GeoRestriction"));
w.writeStartElement(ojpNS(), QStringLiteral("Circle"));
w.writeStartElement(ojpNS(), QStringLiteral("Center"));
w.writeStartElement(ns(), QStringLiteral("GeoRestriction"));
w.writeStartElement(ns(), QStringLiteral("Circle"));
w.writeStartElement(ns(), QStringLiteral("Center"));
w.writeTextElement(siriNS(), QStringLiteral("Longitude"), QString::number(req.location().longitude()));
w.writeTextElement(siriNS(), QStringLiteral("Latitude"), QString::number(req.location().latitude()));
w.writeEndElement(); // </ojp:Center>
w.writeTextElement(ojpNS(), QStringLiteral("Radius"), QString::number(req.maximumDistance()));
w.writeEndElement(); // </ojp:Circle>
w.writeEndElement(); // </ojp:GeoRestriction>
w.writeEndElement(); // </Center>
w.writeTextElement(ns(), QStringLiteral("Radius"), QString::number(req.maximumDistance()));
w.writeEndElement(); // </Circle>
w.writeEndElement(); // </GeoRestriction>
} else {
w.writeTextElement(ojpNS(), QStringLiteral("LocationName"), req.location().name());
w.writeTextElement(ns(), QStringLiteral("LocationName"), req.location().name());
}
w.writeEndElement(); // </ojp:InitialInput>
w.writeEndElement(); // </InitialInput>
w.writeStartElement(ojpNS(), QStringLiteral("Restrictions"));
w.writeTextElement(ojpNS(), QStringLiteral("Type"), QStringLiteral("stop"));
w.writeTextElement(ojpNS(), QStringLiteral("NumberOfResults"), QString::number(req.maximumResults()));
w.writeStartElement(ns(), QStringLiteral("Restrictions"));
w.writeTextElement(ns(), QStringLiteral("Type"), QStringLiteral("stop"));
w.writeTextElement(ns(), QStringLiteral("NumberOfResults"), QString::number(req.maximumResults()));
// TODO ojp:Language
w.writeEndElement(); // </ojp:Restrictions>
w.writeEndElement(); // </Restrictions>
w.writeEndElement(); // </ojp:OJPLocationInformationRequest>
w.writeEndElement(); // </LocationInformationRequest>
writeEndServiceRequest(w);
return output;
}
......@@ -67,24 +80,23 @@ QByteArray OpenJourneyPlannerRequestBuilder::buildStopEventRequest(const Stopove
QXmlStreamWriter w(&output);
setupWriter(w);
writeStartServiceRequest(w);
w.writeTextElement(siriNS(), QStringLiteral("RequestRef"), QStringLiteral("KPublicTransport"));
w.writeStartElement(ojpNS(), QStringLiteral("OJPStopEventRequest"));
w.writeStartElement(ns(), m_useTrias ? QStringLiteral("StopEventRequest") : QStringLiteral("OJPStopEventRequest"));
w.writeStartElement(ojpNS(), QStringLiteral("Location"));
w.writeStartElement(ns(), QStringLiteral("Location"));
writePlaceRef(w, req.stop());
w.writeTextElement(ojpNS(), QStringLiteral("DepArrTime"), req.dateTime().toUTC().toString(Qt::ISODate));
w.writeEndElement(); // </ojp:Location>
w.writeStartElement(ojpNS(), QStringLiteral("Params"));
w.writeTextElement(ojpNS(), QStringLiteral("StopEventType"), req.mode() == StopoverRequest::QueryArrival ? QStringLiteral("arrival") : QStringLiteral("departure")); // "both" is also supported
w.writeTextElement(ojpNS(), QStringLiteral("IncludePreviousCalls"), QStringLiteral("false"));
w.writeTextElement(ojpNS(), QStringLiteral("IncludeOnwardCalls"), QStringLiteral("false"));
w.writeTextElement(ojpNS(), QStringLiteral("IncludeOperatingDays"), QStringLiteral("false"));
w.writeTextElement(ojpNS(), QStringLiteral("IncludeRealtimeData"), QStringLiteral("true"));
w.writeTextElement(ojpNS(), QStringLiteral("NumberOfResults"), QString::number(req.maximumResults()));
w.writeEndElement(); // </ojp:Params>
w.writeEndElement(); // </ojp:OJPStopEventRequest>
w.writeTextElement(ns(), QStringLiteral("DepArrTime"), req.dateTime().toUTC().toString(Qt::ISODate));
w.writeEndElement(); // </Location>
w.writeStartElement(ns(), QStringLiteral("Params"));
w.writeTextElement(ns(), QStringLiteral("StopEventType"), req.mode() == StopoverRequest::QueryArrival ? QStringLiteral("arrival") : QStringLiteral("departure")); // "both" is also supported
w.writeTextElement(ns(), QStringLiteral("IncludePreviousCalls"), QStringLiteral("false"));
w.writeTextElement(ns(), QStringLiteral("IncludeOnwardCalls"), QStringLiteral("false"));
w.writeTextElement(ns(), QStringLiteral("IncludeOperatingDays"), QStringLiteral("false"));
w.writeTextElement(ns(), QStringLiteral("IncludeRealtimeData"), QStringLiteral("true"));
w.writeTextElement(ns(), QStringLiteral("NumberOfResults"), QString::number(req.maximumResults()));
w.writeEndElement(); // </Params>
w.writeEndElement(); // </StopEventRequest>
writeEndServiceRequest(w);
return output;
}
......@@ -95,37 +107,36 @@ QByteArray OpenJourneyPlannerRequestBuilder::buildTripRequest(const JourneyReque
QXmlStreamWriter w(&output);
setupWriter(w);
writeStartServiceRequest(w);
w.writeTextElement(siriNS(), QStringLiteral("RequestRef"), QStringLiteral("KPublicTransport"));
w.writeStartElement(ojpNS(), QStringLiteral("OJPTripRequest"));
w.writeStartElement(ns(), m_useTrias ? QStringLiteral("TripRequest") : QStringLiteral("OJPTripRequest"));
w.writeStartElement(ojpNS(), QStringLiteral("Origin"));
w.writeStartElement(ns(), QStringLiteral("Origin"));
writePlaceRef(w, req.from());
if (req.dateTimeMode() == JourneyRequest::Departure) {
w.writeTextElement(ojpNS(), QStringLiteral("DepArrTime"), req.dateTime().toUTC().toString(Qt::ISODate));
w.writeTextElement(ns(), QStringLiteral("DepArrTime"), req.dateTime().toUTC().toString(Qt::ISODate));
}
w.writeEndElement(); // </ojp:Origin>
w.writeEndElement(); // </Origin>
w.writeStartElement(ojpNS(), QStringLiteral("Destination"));
w.writeStartElement(ns(), QStringLiteral("Destination"));
writePlaceRef(w, req.to());
if (req.dateTimeMode() == JourneyRequest::Arrival) {
w.writeTextElement(ojpNS(), QStringLiteral("DepArrTime"), req.dateTime().toUTC().toString(Qt::ISODate));
w.writeTextElement(ns(), QStringLiteral("DepArrTime"), req.dateTime().toUTC().toString(Qt::ISODate));
}
w.writeEndElement(); // </ojp:Destination>
w.writeEndElement(); // </Destination>
// TODO IndividualTransportOptions
w.writeStartElement(ojpNS(), QStringLiteral("Params"));
w.writeTextElement(ojpNS(), QStringLiteral("IncludeTrackSections"), req.includePaths() ? QStringLiteral("true") : QStringLiteral("false"));
w.writeTextElement(ojpNS(), QStringLiteral("IncludeLegProjection"), req.includePaths() ? QStringLiteral("true") : QStringLiteral("false"));
w.writeTextElement(ojpNS(), QStringLiteral("IncludeTurnDescription"), req.includePaths() ? QStringLiteral("true") : QStringLiteral("false"));
w.writeTextElement(ojpNS(), QStringLiteral("IncludeAccessibility"), QStringLiteral("true")); // ???
w.writeTextElement(ojpNS(), QStringLiteral("IncludeIntermediateStops"), req.includeIntermediateStops() ? QStringLiteral("true") : QStringLiteral("false"));
w.writeTextElement(ojpNS(), QStringLiteral("IncludeFares"), QStringLiteral("false")); // TODO
w.writeTextElement(ojpNS(), QStringLiteral("NumberOfResults"), QString::number(req.maximumResults()));
w.writeStartElement(ns(), QStringLiteral("Params"));
w.writeTextElement(ns(), QStringLiteral("IncludeTrackSections"), req.includePaths() ? QStringLiteral("true") : QStringLiteral("false"));
w.writeTextElement(ns(), QStringLiteral("IncludeLegProjection"), req.includePaths() ? QStringLiteral("true") : QStringLiteral("false"));
w.writeTextElement(ns(), QStringLiteral("IncludeTurnDescription"), req.includePaths() ? QStringLiteral("true") : QStringLiteral("false"));
w.writeTextElement(ns(), QStringLiteral("IncludeAccessibility"), QStringLiteral("true")); // ???
w.writeTextElement(ns(), QStringLiteral("IncludeIntermediateStops"), req.includeIntermediateStops() ? QStringLiteral("true") : QStringLiteral("false"));
w.writeTextElement(ns(), QStringLiteral("IncludeFares"), QStringLiteral("false")); // TODO
w.writeTextElement(ns(), QStringLiteral("NumberOfResults"), QString::number(req.maximumResults()));
// TODO NumberOfResultsBefore|After for next/prev requests
w.writeEndElement(); // </ojp:Params>
w.writeEndElement(); // </Params>
w.writeEndElement(); // </ojp:OJPTripRequest>
w.writeEndElement(); // </TripRequest>
writeEndServiceRequest(w);
return output;
}
......@@ -142,36 +153,60 @@ void OpenJourneyPlannerRequestBuilder::writeStartServiceRequest(QXmlStreamWriter
{
w.writeStartDocument();
w.writeNamespace(siriNS(), QStringLiteral("siri"));
w.writeNamespace(ojpNS(), QStringLiteral("ojp"));
w.writeStartElement(siriNS(), QStringLiteral("OJP"));
w.writeAttribute(QStringLiteral("version"), QStringLiteral("1.0"));
w.writeStartElement(siriNS(), QStringLiteral("OJPRequest"));
w.writeStartElement(siriNS(), QStringLiteral("ServiceRequest"));
if (m_useTrias) {
w.writeNamespace(triasNS(), QStringLiteral("trias"));
w.writeStartElement(triasNS(), QStringLiteral("Trias"));
w.writeAttribute(QStringLiteral("version"), QStringLiteral("1.2"));
w.writeStartElement(triasNS(), QStringLiteral("ServiceRequest"));
} else {
w.writeNamespace(ojpNS(), QStringLiteral("ojp"));
w.writeStartElement(siriNS(), QStringLiteral("OJP"));
w.writeAttribute(QStringLiteral("version"), QStringLiteral("1.0"));
w.writeStartElement(siriNS(), QStringLiteral("OJPRequest"));
w.writeStartElement(siriNS(), QStringLiteral("ServiceRequest"));
}
if (!m_requestorRef.isEmpty()) {
w.writeTextElement(siriNS(), QStringLiteral("RequestorRef"), m_requestorRef);
}
if (m_useTrias) {
w.writeStartElement(ns(), QStringLiteral("RequestPayload"));
}
}
void OpenJourneyPlannerRequestBuilder::writeEndServiceRequest(QXmlStreamWriter &w) const
{
if (m_useTrias) {
w.writeEndElement(); // </trias:RequestPayload>
}
w.writeEndElement(); // </siri:ServiceRequest>
w.writeEndElement(); // </siri:OJPRequest>
w.writeEndElement(); // </siri:OJP>
if (!m_useTrias) {
w.writeEndElement(); // </siri:OJPRequest>
}
w.writeEndElement(); // </siri:OJP> or </siri:TRIAS>
w.writeEndDocument();
}
void OpenJourneyPlannerRequestBuilder::writePlaceRef(QXmlStreamWriter &w, const Location &loc) const
{
w.writeStartElement(ojpNS(), QStringLiteral("PlaceRef"));
w.writeStartElement(ns(), m_useTrias ? QStringLiteral("LocationRef") : QStringLiteral("PlaceRef"));
const auto id = loc.identifier(QStringLiteral("uic")); // ### TODO configure id type
if (!id.isEmpty()) {
w.writeTextElement(ojpNS(), QStringLiteral("StopPlaceRef"), id);