Commit 2609f5b8 authored by Volker Krause's avatar Volker Krause
Browse files

Properly merge attached documents

This fixes attached travel documents replacing existing ones when
merging two reservations, e.g. when adding a rebooked seat reservation
on top of an alternative connection.
parent 718fa90b
Pipeline #247891 passed with stage
in 11 minutes and 46 seconds
[
{
"@context": "http://schema.org",
"@type": "TrainReservation",
"modifiedTime": "2020-01-14T00:00:00Z",
"reservationFor": {
"@type": "TrainTrip",
"arrivalStation": {
"@type": "TrainStation",
"name": "Köln Hbf"
},
"arrivalTime": "2019-02-03T10:15:00",
"departureDay": "2019-02-03",
"departureStation": {
"@type": "TrainStation",
"name": "Bruxelles"
},
"departureTime": "2019-02-03T08:32:00",
"trainNumber": "ICE 13"
},
"reservationNumber": "XXX007",
"reservedTicket": {
"@type": "Ticket",
"ticketToken": "aztecbin:foo"
},
"subjectOf": [ "id2", "id1" ]
}
]
[
{
"@context": "http://schema.org",
"@type": "TrainReservation",
"modifiedTime": "2020-01-14T00:00:00Z",
"reservationFor": {
"@type": "TrainTrip",
"arrivalStation": {
"@type": "TrainStation",
"name": "Köln Hbf"
},
"arrivalTime": "2019-02-03T10:15:00",
"departureDay": "2019-02-03",
"departureStation": {
"@type": "TrainStation",
"name": "Bruxelles"
},
"departureTime": "2019-02-03T08:32:00",
"trainNumber": "ICE 13"
},
"reservationNumber": "XXX007",
"reservationStatus": "http://schema.org/ReservationConfirmed",
"reservedTicket": {
"@type": "Ticket",
"ticketToken": "aztecbin:foo"
},
"subjectOf": [ "id1", "id2" ]
}
]
[
{
"@context": "http://schema.org",
"@type": "TrainReservation",
"modifiedTime": "2020-01-14T00:00:00Z",
"reservationFor": {
"@type": "TrainTrip",
"arrivalStation": {
"@type": "TrainStation",
"name": "Köln Hbf"
},
"arrivalTime": "2019-02-03T10:15:00",
"departureDay": "2019-02-03",
"departureStation": {
"@type": "TrainStation",
"name": "Bruxelles"
},
"departureTime": "2019-02-03T08:32:00",
"trainNumber": "ICE 13"
},
"reservationNumber": "XXX007",
"reservedTicket": {
"@type": "Ticket",
"ticketToken": "aztecbin:foo"
},
"subjectOf": [ "id1" ]
}
]
......@@ -34,6 +34,8 @@
#include <QVariant>
#include <cmath>
#include <cstring>
#include <set>
using namespace KItinerary;
......@@ -560,6 +562,28 @@ static Person mergeValue(const Person &lhs, const Person &rhs)
return p;
}
static QVariantList mergeSubjectOf(const QVariantList &lhs, const QVariantList &rhs)
{
std::set<QString> mergedSet;
for (const auto &v : lhs) {
if (v.type() != QVariant::String) {
return rhs.isEmpty() ? lhs : rhs;
}
mergedSet.insert(v.toString());
}
for (const auto &v : rhs) {
if (v.type() != QVariant::String) {
return rhs.isEmpty() ? lhs : rhs;
}
mergedSet.insert(v.toString());
}
QVariantList result;
result.reserve(mergedSet.size());
std::copy(mergedSet.begin(), mergedSet.end(), std::back_inserter(result));
return result;
}
static int ticketTokenSize(const QVariant &v)
{
if (v.type() == QVariant::String) {
......@@ -629,6 +653,8 @@ QVariant MergeUtil::merge(const QVariant &lhs, const QVariant &rhs)
rv = mergeValue(lv.value<Ticket>(), rv.value<Ticket>());
} else if ((metaType.flags() & QMetaType::IsGadget) && metaType.metaObject()) {
rv = merge(prop.readOnGadget(lhs.constData()), rv);
} else if (mt == QVariant::List && std::strcmp(prop.name(), "subjectOf") == 0) {
rv = mergeSubjectOf(lv.toList(), rv.toList());
} else if (mt == QVariant::String) {
rv = StringUtil::betterString(lv.toString(), rv.toString()).toString();
}
......
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