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

Set individual transport options in OJP requests

Those are documented but don't seem to have any noticeable impact
unfortunately so far.
parent a2320381
......@@ -21,6 +21,9 @@
</ojp:PlaceRef>
<ojp:DepArrTime>2020-09-06T20:54:00Z</ojp:DepArrTime>
</ojp:Destination>
<ojp:IndividualTransportOptions>
<ojp:Mode>walk</ojp:Mode>
</ojp:IndividualTransportOptions>
<ojp:Params>
<ojp:IncludeTrackSections>true</ojp:IncludeTrackSections>
<ojp:IncludeLegProjection>true</ojp:IncludeLegProjection>
......
......@@ -21,6 +21,9 @@
<ojp:StopPlaceRef>8500010</ojp:StopPlaceRef>
</ojp:PlaceRef>
</ojp:Destination>
<ojp:IndividualTransportOptions>
<ojp:Mode>walk</ojp:Mode>
</ojp:IndividualTransportOptions>
<ojp:Params>
<ojp:IncludeTrackSections>false</ojp:IncludeTrackSections>
<ojp:IncludeLegProjection>false</ojp:IncludeLegProjection>
......
......@@ -4,6 +4,7 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "testhelpers.h"
#include "backends/openjourneyplannerrequestbuilder.cpp"
#include <KPublicTransport/JourneyRequest>
......@@ -22,14 +23,6 @@ using namespace KPublicTransport;
class OjpRequestTest : public QObject
{
Q_OBJECT
private:
QByteArray readFile(const QString &fn)
{
QFile f(fn);
f.open(QFile::ReadOnly);
return f.readAll();
}
private Q_SLOTS:
void initTestCase()
{
......@@ -64,7 +57,7 @@ private Q_SLOTS:
builder.setRequestorRef(QStringLiteral("KPublicTransport"));
builder.setTestMode(true);
auto res = builder.buildLocationInformationRequest(request);
auto ref = readFile(refFileName);
auto ref = Test::readFile(refFileName);
if (res != ref) {
qDebug().noquote() << res;
}
......@@ -73,7 +66,7 @@ private Q_SLOTS:
builder.setUseTrias(true);
res = builder.buildLocationInformationRequest(request);
ref = readFile(refFileName.insert(refFileName.size() -4, u"-trias"));
ref = Test::readFile(refFileName.insert(refFileName.size() -4, u"-trias"));
if (res != ref) {
qDebug().noquote() << res;
}
......@@ -107,7 +100,7 @@ private Q_SLOTS:
builder.setRequestorRef(QStringLiteral("KPublicTransport"));
builder.setTestMode(true);
auto res = builder.buildStopEventRequest(request);
auto ref = readFile(refFileName);
auto ref = Test::readFile(refFileName);
if (res != ref) {
qDebug().noquote() << res;
}
......@@ -116,7 +109,7 @@ private Q_SLOTS:
builder.setUseTrias(true);
res = builder.buildStopEventRequest(request);
ref = readFile(refFileName.insert(refFileName.size() -4, u"-trias"));
ref = Test::readFile(refFileName.insert(refFileName.size() -4, u"-trias"));
if (res != ref) {
qDebug().noquote() << res;
}
......@@ -159,7 +152,7 @@ private Q_SLOTS:
builder.setRequestorRef(QStringLiteral("KPublicTransport"));
builder.setTestMode(true);
auto res = builder.buildTripRequest(request);
auto ref = readFile(refFileName);
auto ref = Test::readFile(refFileName);
if (res != ref) {
qDebug().noquote() << res;
}
......@@ -168,7 +161,8 @@ private Q_SLOTS:
builder.setUseTrias(true);
res = builder.buildTripRequest(request);
ref = readFile(refFileName.insert(refFileName.size() -4, u"-trias"));
ref = Test::readFile(refFileName.insert(refFileName.size() -4, u"-trias"));
if (res != ref) {
qDebug().noquote() << res;
}
......
......@@ -101,6 +101,15 @@ QByteArray OpenJourneyPlannerRequestBuilder::buildStopEventRequest(const Stopove
return output;
}
struct {
IndividualTransport::Mode mode;
const char *ojpMode;
} static constexpr const individual_transport_modes[] = {
{ IndividualTransport::Walk, "walk" },
{ IndividualTransport::Bike, "cycle" },
// TODO taxi, self-drive-car others-drive-car motorcycle truck
};
QByteArray OpenJourneyPlannerRequestBuilder::buildTripRequest(const JourneyRequest &req) const
{
QByteArray output;
......@@ -123,7 +132,19 @@ QByteArray OpenJourneyPlannerRequestBuilder::buildTripRequest(const JourneyReque
}
w.writeEndElement(); // </Destination>
// TODO IndividualTransportOptions
if (!m_useTrias) {
w.writeStartElement(ns(), QStringLiteral("IndividualTransportOptions"));
for (const auto &accessMode : req.accessModes()) {
const auto it = std::find_if(std::begin(individual_transport_modes), std::end(individual_transport_modes), [accessMode](const auto &m) {
return m.mode == accessMode.mode();
});
if (it != std::end(individual_transport_modes)) {
w.writeTextElement(ns(), QStringLiteral("Mode"), QLatin1String((*it).ojpMode));
break;
}
}
w.writeEndElement(); // </IndividualTransportOptions>
}
w.writeStartElement(ns(), QStringLiteral("Params"));
w.writeTextElement(ns(), QStringLiteral("IncludeTrackSections"), req.includePaths() ? QStringLiteral("true") : QStringLiteral("false"));
......@@ -134,6 +155,7 @@ QByteArray OpenJourneyPlannerRequestBuilder::buildTripRequest(const JourneyReque
w.writeTextElement(ns(), QStringLiteral("IncludeFares"), QStringLiteral("false")); // TODO
w.writeTextElement(ns(), QStringLiteral("NumberOfResults"), QString::number(req.maximumResults()));
// TODO NumberOfResultsBefore|After for next/prev requests
// TODO BikeTransport
w.writeEndElement(); // </Params>
w.writeEndElement(); // </TripRequest>
......
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