Commit 1a6e069b authored by Volker Krause's avatar Volker Krause
Browse files

Initial support for Hafas mode group configurations

This is far from complete:
- Multiple matching configurations would need multiple queries it seems,
we aren't doing that yet and just pick the first match.
- The current format only covers access/egress modes, not direct modes,
something JourneyRequest doesn't model properly yet.
- Most Hafas endpoints don't have the necessary data yet.

It's already good enough for basic combined bike/PT queries though, and
helps to test the response parsing for those scenarios.
parent c646253c
......@@ -139,6 +139,22 @@ bool HafasMgateBackend::queryJourney(const JourneyRequest &request, JourneyReply
req.insert(QStringLiteral("ctxScr"), ctxSrc);
}
QJsonArray jnyFltrL;
for (const auto &conGroup : m_conGroups) {
const auto accessMatch = std::find(request.accessModes().begin(), request.accessModes().end(), conGroup.access) != request.accessModes().end();
const auto egressMatch = std::find(request.egressModes().begin(), request.egressModes().end(), conGroup.egress) != request.egressModes().end();
if (accessMatch && egressMatch) {
QJsonObject jnyFltr;
jnyFltr.insert(QLatin1String("mode"), QLatin1String("INC"));
jnyFltr.insert(QLatin1String("type"), QLatin1String("GROUP"));
jnyFltr.insert(QLatin1String("value"), conGroup.group);
jnyFltrL.push_back(jnyFltr);
}
}
if (!jnyFltrL.isEmpty()) {
req.insert(QLatin1String("jnyFltrL"), jnyFltrL);
}
tripSearch.insert(QStringLiteral("cfg"), cfg);
tripSearch.insert(QStringLiteral("meth"), QLatin1String("TripSearch"));
tripSearch.insert(QStringLiteral("req"), req);
......@@ -380,3 +396,16 @@ void HafasMgateBackend::setChecksumSalt(const QString &salt)
{
m_checksumSalt = QByteArray::fromHex(salt.toUtf8());
}
void HafasMgateBackend::setConGroups(const QJsonArray &conGroups)
{
m_conGroups.reserve(conGroups.size());
for (const auto &conGroupVal : conGroups) {
const auto conGroupObj = conGroupVal.toObject();
ConGroup cg;
cg.access = IndividualTransport::fromJson(conGroupObj.value(QLatin1String("access")).toObject());
cg.egress = IndividualTransport::fromJson(conGroupObj.value(QLatin1String("egress")).toObject());
cg.group = conGroupObj.value(QLatin1String("conGroup")).toString();
m_conGroups.push_back(std::move(cg));
}
}
......@@ -12,8 +12,11 @@
#include "hafasbackend.h"
#include "hafasmgateparser.h"
#include <KPublicTransport/IndividualTransport>
#include <QString>
class QJsonArray;
class QJsonObject;
class QNetworkReply;
......@@ -38,6 +41,10 @@ class KPUBLICTRANSPORT_EXPORT HafasMgateBackend : public HafasBackend
/** Salt for the request checksum parameter, hex-encoded. */
Q_PROPERTY(QString checksumSalt WRITE setChecksumSalt)
/** Supported journey filter conGroup arguments and their corresponding mapping to
* our transport modes.
*/
Q_PROPERTY(QJsonArray conGroups WRITE setConGroups)
public:
HafasMgateBackend();
~HafasMgateBackend();
......@@ -58,6 +65,7 @@ private:
void setAuthObject(const QJsonObject &obj);
void setMicMacSalt(const QString &salt);
void setChecksumSalt(const QString &salt);
void setConGroups(const QJsonArray &conGroups);
QJsonObject locationToJson(const Location &loc) const;
mutable HafasMgateParser m_parser;
......@@ -68,6 +76,13 @@ private:
QString m_version;
QByteArray m_micMacSalt;
QByteArray m_checksumSalt;
struct ConGroup {
IndividualTransport access;
IndividualTransport egress;
QString group;
};
std::vector<ConGroup> m_conGroups;
};
}
......
......@@ -101,6 +101,14 @@
"id": "VBB",
"type": "AND"
},
"conGroups": [
{ "access": { "mode": "Bike" }, "egress": { "mode": "Bike" }, "conGroup": "BIKE_OEV_BIKE" },
{ "access": { "mode": "Bike", "qualifier": "Park" }, "egress": { "mode": "Walk" }, "conGroup": "BIKEPARK_OEV_WALK" },
{ "access": { "mode": "Bike", "qualifier": "Rent" }, "egress": { "mode": "Bike", "qualifier": "Rent" }, "conGroup": "BIKESHARE_CALLABIKE" },
{ "access": { "mode": "Car", "qualifier": "Park" }, "egress": { "mode": "Walk" }, "conGroup": "PARKRIDE_OEV_WALK" },
{ "access": { "mode": "Car" }, "egress": { "mode": "Car" }, "conGroup": "CAR_ONLY" },
{ "access": { "mode": "Car", "qualifier": "Rent" }, "egress": { "mode": "Car", "qualifier": "Rent" }, "conGroup": "CARSHARE_FLINKSTER" }
],
"endpoint": "https://fahrinfo.vbb.de/bin/mgate.exe",
"ext": "VBB.4",
"locationIdentifierType": "vbb",
......
......@@ -95,13 +95,18 @@
},
"options": {
"auth": {
"aid": "1Rxs112shyHLatUX4fofnmdxK",
"aid": "YoJ05NartnanEGCj",
"type": "AID"
},
"client": {
"id": "BVG",
"type": "AND"
},
"conGroups": [
{ "access": { "mode": "Bike" }, "egress": { "mode": "Bike" }, "conGroup": "BIKE_OEV_BIKE" },
{ "access": { "mode": "Bike", "qualifier": "Park" }, "egress": { "mode": "Walk" }, "conGroup": "BIKE_OEV_WALK" },
{ "access": { "mode": "Bike", "qualifier": "Rent" }, "egress": { "mode": "Bike", "qualifier": "Rent" }, "conGroup": "WALK_BIKESHARE_NEXTBIKE" }
],
"endpoint": "https://bvg-apps.hafas.de/bin/mgate.exe",
"ext": "BVG.1",
"locationIdentifierType": "vbb",
......@@ -163,7 +168,7 @@
"name": "RB/RE"
}
],
"ver": "1.21"
"ver": "1.24"
},
"supportedLanguages": [
"de",
......
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