Commit f005117b authored by Volker Krause's avatar Volker Krause
Browse files

Support IFOPT location identifiers in OTP responses

parent 7eab3af0
......@@ -120,7 +120,8 @@
"scheduledDepartureTime": "2020-08-08T09:24:02Z",
"to": {
"identifier": {
"gtfs": "1:de:08421:1008:1:2"
"gtfs": "1:de:08421:1008:1:2",
"ifopt": "de:08421:1008:1:2"
},
"latitude": 48.399295806884766,
"longitude": 9.984164237976074,
......@@ -133,7 +134,8 @@
"distance": 1720,
"from": {
"identifier": {
"gtfs": "1:de:08421:1008:1:2"
"gtfs": "1:de:08421:1008:1:2",
"ifopt": "de:08421:1008:1:2"
},
"latitude": 48.399295806884766,
"longitude": 9.984164237976074,
......@@ -147,7 +149,8 @@
"scheduledDepartureTime": "2020-08-08T09:30:00Z",
"stopPoint": {
"identifier": {
"gtfs": "1:de:08421:1001:0:1"
"gtfs": "1:de:08421:1001:0:1",
"ifopt": "de:08421:1001:0:1"
},
"latitude": 48.397186279296875,
"longitude": 9.987756729125977,
......@@ -168,7 +171,8 @@
"scheduledDepartureTime": "2020-08-08T09:28:00Z",
"to": {
"identifier": {
"gtfs": "1:de:08421:1002:1:1"
"gtfs": "1:de:08421:1002:1:1",
"ifopt": "de:08421:1002:1:1"
},
"latitude": 48.397403717041016,
"longitude": 9.992769241333008,
......@@ -181,7 +185,8 @@
"distance": 235,
"from": {
"identifier": {
"gtfs": "1:de:08421:1002:1:1"
"gtfs": "1:de:08421:1002:1:1",
"ifopt": "de:08421:1002:1:1"
},
"latitude": 48.397403717041016,
"longitude": 9.992769241333008,
......
......@@ -168,7 +168,7 @@ private Q_SLOTS:
rentalVehicleNetworks.insert(it.key(), std::move(n));
}
OpenTripPlannerParser p(s("gtfs"));
OpenTripPlannerParser p(s("gtfs"), s("1"));
p.setKnownRentalVehicleNetworks(rentalVehicleNetworks);
const auto res = p.parseJourneys(QJsonDocument::fromJson(readFile(inFileName)).object());
const auto jsonRes = Journey::toJson(res);
......
......@@ -80,7 +80,7 @@ bool OpenTripPlannerGraphQLBackend::queryLocation(const LocationRequest &req, Lo
return;
}
OpenTripPlannerParser p(backendId());
OpenTripPlannerParser p(backendId(), m_ifoptPrefix);
p.setKnownRentalVehicleNetworks(m_rentalNetworks);
std::vector<Location> res;
if (req.hasCoordinate()) {
......@@ -122,7 +122,7 @@ bool OpenTripPlannerGraphQLBackend::queryStopover(const StopoverRequest &req, St
if (gqlReply.error() != KGraphQLReply::NoError) {
addError(reply, Reply::NetworkError, gqlReply.errorString());
} else {
OpenTripPlannerParser p(backendId());
OpenTripPlannerParser p(backendId(), m_ifoptPrefix);
addResult(reply, this, p.parseDepartures(gqlReply.data()));
}
});
......@@ -189,7 +189,7 @@ bool OpenTripPlannerGraphQLBackend::queryJourney(const JourneyRequest &req, Jour
if (gqlReply.error() != KGraphQLReply::NoError) {
addError(reply, Reply::NetworkError, gqlReply.errorString());
} else {
OpenTripPlannerParser p(backendId());
OpenTripPlannerParser p(backendId(), m_ifoptPrefix);
p.setKnownRentalVehicleNetworks(m_rentalNetworks);
addResult(reply, this, p.parseJourneys(gqlReply.data()));
if (p.m_nextJourneyContext.dateTime.isValid()) {
......
......@@ -29,6 +29,7 @@ class OpenTripPlannerGraphQLBackend : public AbstractBackend
Q_PROPERTY(QStringList supportedRentalModes MEMBER m_supportedRentalModes)
Q_PROPERTY(QJsonValue extraHttpHeaders WRITE setExtraHttpHeaders)
Q_PROPERTY(QJsonObject rentalVehicleNetworks WRITE setRentalVehicleNetworks)
Q_PROPERTY(QString ifoptPrefix MEMBER m_ifoptPrefix)
public:
OpenTripPlannerGraphQLBackend();
......@@ -55,6 +56,7 @@ private:
QStringList m_supportedRentalModes = { QStringLiteral("BICYCLE") };
std::vector<std::pair<QByteArray, QByteArray>> m_extraHeaders;
QHash<QString, RentalVehicleNetwork> m_rentalNetworks;
QString m_ifoptPrefix;
};
}
......
......@@ -7,6 +7,7 @@
#include "opentripplannerparser.h"
#include "gtfs/hvt.h"
#include "geo/polylinedecoder_p.h"
#include "ifopt/ifoptutil.h"
#include <KPublicTransport/Journey>
#include <KPublicTransport/RentalVehicle>
......@@ -22,8 +23,9 @@
using namespace KPublicTransport;
OpenTripPlannerParser::OpenTripPlannerParser(const QString &identifierType)
OpenTripPlannerParser::OpenTripPlannerParser(const QString &identifierType, const QString &ifoptPrefix)
: m_identifierType(identifierType)
, m_ifoptPrefix(ifoptPrefix)
{
}
......@@ -87,6 +89,12 @@ bool OpenTripPlannerParser::parseLocationFragment(const QJsonObject &obj, Locati
if (!id.isEmpty()) {
loc.setIdentifier(m_identifierType, id);
}
if (!m_ifoptPrefix.isEmpty() && id.size() > m_ifoptPrefix.size() + 1 && id.startsWith(m_ifoptPrefix) && id.at(m_ifoptPrefix.size()) == QLatin1Char(':')) {
const auto ifopt = QStringView(id).mid(m_ifoptPrefix.size() + 1);
if (IfoptUtil::isValid(ifopt)) {
loc.setIdentifier(QStringLiteral("ifopt"), ifopt.toString());
}
}
const auto bss = obj.value(QLatin1String("bikeRentalStation")).toObject();
if (!bss.isEmpty()) {
......
......@@ -36,7 +36,7 @@ class Stopover;
class KPUBLICTRANSPORT_EXPORT OpenTripPlannerParser
{
public:
explicit OpenTripPlannerParser(const QString &identifierType);
explicit OpenTripPlannerParser(const QString &identifierType, const QString &ifoptPrefix = {});
~OpenTripPlannerParser();
void setKnownRentalVehicleNetworks(const QHash<QString, RentalVehicleNetwork> &networks);
......@@ -66,6 +66,7 @@ private:
Journey parseJourney(const QJsonObject &obj) const;
QString m_identifierType;
QString m_ifoptPrefix;
QHash<QString, RentalVehicleNetwork> m_rentalVehicleNetworks;
mutable QStringList m_alerts;
};
......
......@@ -81,6 +81,7 @@
},
"options": {
"endpoint": "https://api.stadtnavi.de/routing/v1/router/",
"ifoptPrefix": "hbg",
"rentalVehicleNetworks": {
"car-sharing": {},
"regiorad": {
......
......@@ -81,6 +81,7 @@
},
"options": {
"endpoint": "https://api.digitransit.im.verschwoerhaus.de/routing/v1/routers/vsh/",
"ifoptPrefix": "1",
"rentalVehicleNetworks": {
"openbike": {
"name": "OpenBike Ulm",
......
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