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

Correctly handle UIC station codes in OJP responses

Still needs proper configuration support though.
parent 58edfbb3
Pipeline #79862 passed with stage
in 19 seconds
......@@ -9,6 +9,7 @@
"expectedDepartureTime": "2021-09-07T15:46:00Z",
"from": {
"identifier": {
"test_id": "8503016",
"uic": "8503016"
},
"latitude": 47.45038986206055,
......@@ -41,6 +42,7 @@
"scheduledDepartureTime": "2021-09-07T15:45:00Z",
"to": {
"identifier": {
"test_id": "8501605",
"uic": "8501605"
},
"latitude": 46.294029235839844,
......@@ -55,6 +57,7 @@
"distance": 0,
"from": {
"identifier": {
"test_id": "8501605",
"uic": "8501605"
},
"latitude": 46.294029235839844,
......@@ -68,6 +71,7 @@
"scheduledDepartureTime": "2021-09-07T18:02:00Z",
"to": {
"identifier": {
"test_id": "8501605",
"uic": "8501605"
},
"latitude": 46.294029235839844,
......@@ -84,6 +88,7 @@
"expectedDepartureTime": "2021-09-07T18:08:00Z",
"from": {
"identifier": {
"test_id": "8501605",
"uic": "8501605"
},
"latitude": 46.294029235839844,
......@@ -108,6 +113,7 @@
"scheduledDepartureTime": "2021-09-07T18:08:00Z",
"to": {
"identifier": {
"test_id": "8501687",
"uic": "8501687"
},
"latitude": 46.09992980957031,
......
[
{
"identifier": {
"test_id": "8501687",
"uic": "8501687"
},
"latitude": 46.09992980957031,
......
[
{
"identifier": {
"test_id": "8503016",
"uic": "8503016"
},
"latitude": 47.45038986206055,
......@@ -11,6 +12,7 @@
},
{
"identifier": {
"test_id": "8580301",
"uic": "8580301"
},
"latitude": 47.4526481628418,
......
......@@ -15,6 +15,7 @@
"scheduledDepartureTime": "2021-09-06T20:27:00Z",
"stopPoint": {
"identifier": {
"test_id": "8501687",
"uic": "8501687"
},
"latitude": 46.09992980957031,
......@@ -40,6 +41,7 @@
"scheduledDepartureTime": "2021-09-06T21:29:00Z",
"stopPoint": {
"identifier": {
"test_id": "8501687",
"uic": "8501687"
},
"latitude": 46.09992980957031,
......
......@@ -2,7 +2,7 @@
{
"identifier": {
"ifopt": "de:14612:28",
"uic": "de:14612:28"
"test_id": "de:14612:28"
},
"latitude": 51.0399284362793,
"locality": "Dresden",
......@@ -13,7 +13,7 @@
{
"identifier": {
"ifopt": "de:14612:32",
"uic": "de:14612:32"
"test_id": "de:14612:32"
},
"latitude": 51.0413703918457,
"locality": "Dresden",
......@@ -24,7 +24,7 @@
{
"identifier": {
"ifopt": "de:14612:36",
"uic": "de:14612:36"
"test_id": "de:14612:36"
},
"latitude": 51.038719177246094,
"locality": "Dresden",
......
......@@ -59,6 +59,8 @@ private Q_SLOTS:
QFETCH(QString, refFileName);
OpenJourneyPlannerParser p;
p.setLocationIdentifierType(QStringLiteral("test_id"));
p.setUicLocationIdentifierType(QStringLiteral("uic"));
const auto res = p.parseLocationInformationResponse(readFile(inFileName));
QVERIFY(!p.hasError());
const auto jsonRes = Location::toJson(res);
......@@ -87,6 +89,8 @@ private Q_SLOTS:
QFETCH(QString, refFileName);
OpenJourneyPlannerParser p;
p.setLocationIdentifierType(QStringLiteral("test_id"));
p.setUicLocationIdentifierType(QStringLiteral("uic"));
const auto res = p.parseStopEventResponse(readFile(inFileName));
QVERIFY(!p.hasError());
const auto jsonRes = Stopover::toJson(res);
......@@ -115,6 +119,8 @@ private Q_SLOTS:
QFETCH(QString, refFileName);
OpenJourneyPlannerParser p;
p.setLocationIdentifierType(QStringLiteral("test_id"));
p.setUicLocationIdentifierType(QStringLiteral("uic"));
const auto res = p.parseTripResponse(readFile(inFileName));
QVERIFY(!p.hasError());
const auto jsonRes = Journey::toJson(res);
......@@ -130,6 +136,8 @@ private Q_SLOTS:
void testParseError()
{
OpenJourneyPlannerParser p;
p.setLocationIdentifierType(QStringLiteral("test_id"));
p.setUicLocationIdentifierType(QStringLiteral("uic"));
const auto res = p.parseTripResponse(readFile(s(SOURCE_DIR "/data/ojp/ch-error-notripfound.xml")));
QVERIFY(res.empty());
QVERIFY(p.hasError());
......
......@@ -58,7 +58,7 @@ bool OpenJourneyPlannerBackend::queryLocation(const LocationRequest &request, Lo
return;
}
OpenJourneyPlannerParser p;
auto p = parser();
auto locs = p.parseLocationInformationResponse(data);
if (p.hasError()) {
addError(reply, Reply::NotFoundError, p.errorMessage());
......@@ -87,7 +87,7 @@ bool OpenJourneyPlannerBackend::queryStopover(const StopoverRequest &request, St
return;
}
OpenJourneyPlannerParser p;
auto p = parser();
auto stops = p.parseStopEventResponse(data);
if (p.hasError()) {
addError(reply, Reply::NotFoundError, p.errorMessage());
......@@ -116,7 +116,7 @@ bool OpenJourneyPlannerBackend::queryJourney(const JourneyRequest &request, Jour
return;
}
OpenJourneyPlannerParser p;
auto p = parser();
auto jnys = p.parseTripResponse(data);
if (p.hasError()) {
addError(reply, Reply::NotFoundError, p.errorMessage());
......@@ -146,3 +146,11 @@ OpenJourneyPlannerRequestBuilder OpenJourneyPlannerBackend::requestBuilder() con
builder.setUseTrias(m_useTrias);
return builder;
}
OpenJourneyPlannerParser OpenJourneyPlannerBackend::parser() const
{
OpenJourneyPlannerParser p;
p.setLocationIdentifierType(backendId());
p.setUicLocationIdentifierType(QStringLiteral("uic")); // TODO
return p;
}
......@@ -16,6 +16,7 @@ class QNetworkRequest;
namespace KPublicTransport {
class OpenJourneyPlannerParser;
class OpenJourneyPlannerRequestBuilder;
/** Backend for OpenJourneyPlanner services
......@@ -42,6 +43,7 @@ public:
private:
QNetworkRequest networkRequest() const;
OpenJourneyPlannerRequestBuilder requestBuilder() const;
OpenJourneyPlannerParser parser() const;
QUrl m_endpoint;
QString m_authorization;
......
......@@ -9,6 +9,7 @@
#include <gtfs/hvt.h>
#include <ifopt/ifoptutil.h>
#include <uic/uicutil.h>
#include <KPublicTransport/Journey>
#include <KPublicTransport/Location>
......@@ -31,6 +32,16 @@ QString OpenJourneyPlannerParser::errorMessage() const
return m_errorMsg;
}
void OpenJourneyPlannerParser::setLocationIdentifierType(const QString &idType)
{
m_identifierType = idType;
}
void OpenJourneyPlannerParser::setUicLocationIdentifierType(const QString &uicIdType)
{
m_uicIdentifierType = uicIdType;
}
std::vector<Location> OpenJourneyPlannerParser::parseLocationInformationResponse(const QByteArray &responseData)
{
QXmlStreamReader reader(responseData);
......@@ -108,6 +119,9 @@ Location OpenJourneyPlannerParser::parseLocationInformationLocation(ScopedXmlStr
if (IfoptUtil::isValid(id)) {
loc.setIdentifier(IfoptUtil::identifierType(), id);
}
if (!m_uicIdentifierType.isEmpty() && UicUtil::isStationId(id)) {
loc.setIdentifier(m_uicIdentifierType, id);
}
} else if (subR.isElement("StopPlaceName") || subR.isElement("StopPointName")) {
loc.setName(parseTextElement(subR.subReader()));
}
......
......@@ -43,6 +43,9 @@ public:
bool hasError() const;
QString errorMessage() const;
void setLocationIdentifierType(const QString &idType);
void setUicLocationIdentifierType(const QString &uicIdType);
private:
std::vector<Location> parseLocationInformationDelivery(ScopedXmlStreamReader &&r);
Location parseLocationInformationLocationResult(ScopedXmlStreamReader &&r) const;
......@@ -75,7 +78,8 @@ private:
void parseError(ScopedXmlStreamReader &&r);
QString m_identifierType = QStringLiteral("uic"); // TODO
QString m_identifierType;
QString m_uicIdentifierType;
QHash<QString, Location> m_contextLocations;
QString m_errorMsg;
};
......
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