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

Parse TRIAS situation messages

parent a39d7551
Pipeline #79865 passed with stage
in 18 seconds
......@@ -3,6 +3,9 @@
"disruptionEffect": "NormalService",
"expectedDepartureTime": "2021-09-10T19:41:00Z",
"expectedPlatform": "1",
"notes": [
"Linienaenderung: Geänderte Verkehrslenkung B170 und Sperrung Boderitzer Straße Ost in Bannewitz"
],
"route": {
"direction": "Dresden Pirnaischer Platz",
"line": {
......
......@@ -190,6 +190,8 @@ void OpenJourneyPlannerParser::parseResponseContext(ScopedXmlStreamReader &&r)
while (r.readNextSibling()) {
if (r.isElement("Places")) {
parseResponseContextPlaces(r.subReader());
} else if (r.isElement("Situations")) {
parseResponseContextSituations(r.subReader());
}
}
}
......@@ -204,6 +206,32 @@ void OpenJourneyPlannerParser::parseResponseContextPlaces(ScopedXmlStreamReader
}
}
void OpenJourneyPlannerParser::parseResponseContextSituations(ScopedXmlStreamReader &&r)
{
while (r.readNextSibling()) {
if (r.isElement("PtSituation")) {
parseSituation(r.subReader());
}
}
}
void OpenJourneyPlannerParser::parseSituation(ScopedXmlStreamReader &&r)
{
QString source, id, summary, desc;
while (r.readNextSibling()) {
if (r.isElement("ParticipantRef")) {
source = r.readElementText();
} else if (r.isElement("SituationNumber")) {
id = r.readElementText();
} else if (r.isElement("Summary")) {
summary = r.readElementText();
} else if (r.isElement("Description")) {
desc = r.readElementText();
} // TODO there's also <Detail>, but that seems a bit excessive?
}
m_contextSituations.insert(source + QLatin1Char('-') + id, summary + QLatin1String(": ") + desc);
}
Stopover OpenJourneyPlannerParser::parseStopEventResult(ScopedXmlStreamReader &&r) const
{
Stopover stop;
......@@ -298,6 +326,9 @@ void OpenJourneyPlannerParser::parseService(ScopedXmlStreamReader &&r, Route &ro
route.setLine(std::move(line));
parseService(r.subReader(), route, attributes);
line = route.line();
} else if (r.isElement("SituationFullRef")) {
const auto situationId = parseSituationRef(r.subReader());
attributes.push_back(m_contextSituations.value(situationId));
}
}
route.setLine(std::move(line));
......@@ -334,6 +365,20 @@ Line::Mode OpenJourneyPlannerParser::parseMode(ScopedXmlStreamReader &&r) const
return m;
}
QString OpenJourneyPlannerParser::parseSituationRef(ScopedXmlStreamReader &&r) const
{
QString source, id;
while (r.readNextSibling()) {
if (r.isElement("ParticipantRef")) {
source = r.readElementText();
} else if (r.isElement("SituationNumber")) {
id = r.readElementText();
}
}
return source + QLatin1Char('-') + id;
}
std::vector<Journey> OpenJourneyPlannerParser::parseTripDelivery(ScopedXmlStreamReader &&r)
{
std::vector<Journey> l;
......
......@@ -56,6 +56,9 @@ private:
std::vector<Stopover> parseStopEventDelivery(ScopedXmlStreamReader &&r);
void parseResponseContext(ScopedXmlStreamReader &&r);
void parseResponseContextPlaces(ScopedXmlStreamReader &&r);
void parseResponseContextSituations(ScopedXmlStreamReader &&r);
void parseSituation(ScopedXmlStreamReader &&r);
Stopover parseStopEventResult(ScopedXmlStreamReader &&r) const;
Stopover parseStopEvent(ScopedXmlStreamReader &&r) const;
void parseCallAtStop(ScopedXmlStreamReader &&r, Stopover &stop) const;
......@@ -66,6 +69,7 @@ private:
};
TimePair parseTime(ScopedXmlStreamReader &&r) const;
Line::Mode parseMode(ScopedXmlStreamReader &&r) const;
QString parseSituationRef(ScopedXmlStreamReader &&r) const;
std::vector<Journey> parseTripDelivery(ScopedXmlStreamReader &&r);
Journey parseTripResult(ScopedXmlStreamReader &&r) const;
......@@ -81,6 +85,7 @@ private:
QString m_identifierType;
QString m_uicIdentifierType;
QHash<QString, Location> m_contextLocations;
QHash<QString, QString> m_contextSituations;
QString m_errorMsg;
};
......
Supports Markdown
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