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

Implement earlier/later journey queries for Hafas

This produces seamless result sets in the requested size, much better than
our manual fallback mechanism.
parent 94a1db3f
Pipeline #66121 canceled with stage
......@@ -63,7 +63,8 @@ void HafasMgateBackend::init()
AbstractBackend::Capabilities HafasMgateBackend::capabilities() const
{
return (m_endpoint.startsWith(QLatin1String("https")) ? Secure : NoCapability) | CanQueryArrivals | CanQueryPreviousDeparture;
return (m_endpoint.startsWith(QLatin1String("https")) ? Secure : NoCapability)
| CanQueryArrivals | CanQueryPreviousDeparture | CanQueryPreviousJourney | CanQueryNextJourney;
}
bool HafasMgateBackend::needsLocationQuery(const Location &loc, AbstractBackend::QueryType type) const
......@@ -133,6 +134,10 @@ bool HafasMgateBackend::queryJourney(const JourneyRequest &request, JourneyReply
req.insert(QStringLiteral("outDate"), dt.date().toString(QStringLiteral("yyyyMMdd")));
req.insert(QStringLiteral("outTime"), dt.time().toString(QStringLiteral("hhmmss")));
req.insert(QStringLiteral("outFrwd"), request.dateTimeMode() == JourneyRequest::Departure);
const auto ctxSrc = requestContext(request).toString();
if (!ctxSrc.isEmpty()) {
req.insert(QStringLiteral("ctxScr"), ctxSrc);
}
tripSearch.insert(QStringLiteral("cfg"), cfg);
tripSearch.insert(QStringLiteral("meth"), QLatin1String("TripSearch"));
......@@ -152,6 +157,8 @@ bool HafasMgateBackend::queryJourney(const JourneyRequest &request, JourneyReply
{
auto res = m_parser.parseJourneys(data);
if (m_parser.error() == Reply::NoError) {
setNextRequestContext(reply, m_parser.m_nextJourneyContext);
setPreviousRequestContext(reply, m_parser.m_previousJourneyContext);
addResult(reply, this, std::move(res));
} else {
addError(reply, m_parser.error(), m_parser.errorMessage());
......
......@@ -400,8 +400,11 @@ std::vector<Location> HafasMgateParser::parseLocations(const QByteArray &data) c
return {};
}
std::vector<Journey> HafasMgateParser::parseJourneys(const QByteArray &data) const
std::vector<Journey> HafasMgateParser::parseJourneys(const QByteArray &data)
{
m_nextJourneyContext.clear();
m_previousJourneyContext.clear();
const auto topObj = QJsonDocument::fromJson(data).object();
if (!parseError(topObj)) {
return {};
......@@ -531,7 +534,7 @@ static Path parsePolyG(const QJsonObject &obj, const std::vector<Path> &paths)
return {};
}
std::vector<Journey> HafasMgateParser::parseTripSearch(const QJsonObject &obj) const
std::vector<Journey> HafasMgateParser::parseTripSearch(const QJsonObject &obj)
{
const auto commonObj = obj.value(QLatin1String("common")).toObject();
const auto icos = parseIcos(commonObj.value(QLatin1String("icoL")).toArray());
......@@ -683,6 +686,9 @@ std::vector<Journey> HafasMgateParser::parseTripSearch(const QJsonObject &obj) c
res.push_back(journey);
}
m_previousJourneyContext = obj.value(QLatin1String("outCtxScrB")).toString();
m_nextJourneyContext = obj.value(QLatin1String("outCtxScrF")).toString();
return res;
}
......
......@@ -44,16 +44,18 @@ public:
std::vector<Stopover> parseDepartures(const QByteArray &data) const;
std::vector<Location> parseLocations(const QByteArray &data) const;
std::vector<Journey> parseJourneys(const QByteArray &data) const;
std::vector<Journey> parseJourneys(const QByteArray &data);
static QDateTime parseDateTime(const QString &date, const QJsonValue &time, const QJsonValue &tzOffset);
QString m_previousJourneyContext;
QString m_nextJourneyContext;
private:
Q_DISABLE_COPY(HafasMgateParser)
std::vector<Stopover> parseStationBoardResponse(const QJsonObject &obj) const;
std::vector<Line> parseLines(const QJsonArray &prodL, const std::vector<Ico> &icos) const;
std::vector<Location> parseLocations(const QJsonArray &locL) const;
std::vector<Journey> parseTripSearch(const QJsonObject &obj) const;
std::vector<Journey> parseTripSearch(const QJsonObject &obj);
bool parseError(const QJsonObject &obj) const;
};
......
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