diff --git a/src/mergeutil.cpp b/src/mergeutil.cpp index 313e672..6c58a73 100644 --- a/src/mergeutil.cpp +++ b/src/mergeutil.cpp @@ -1,149 +1,173 @@ /* Copyright (C) 2018 Volker Krause This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "mergeutil.h" #include #include #include #include #include #include #include #include #include #include using namespace KItinerary; static bool isSameTrainTrip(const TrainTrip &lhs, const TrainTrip &rhs); static bool isSameBusTrip(const BusTrip &lhs, const BusTrip &rhs); static bool isSameLodingBusiness(const LodgingBusiness &lhs, const LodgingBusiness &rhs); +static bool isSameFoodEstablishment(const FoodEstablishment &lhs, const FoodEstablishment &rhs); bool MergeUtil::isSameReservation(const QVariant& lhs, const QVariant& rhs) { if (lhs.isNull() || rhs.isNull() || !JsonLd::canConvert(lhs) || !JsonLd::canConvert(rhs)) { return false; } if (lhs.userType() != rhs.userType()) { return false; } // flight: booking ref, flight number and departure day match if (lhs.userType() == qMetaTypeId()) { const auto lhsRes = lhs.value(); const auto rhsRes = rhs.value(); if (lhsRes.reservationNumber() != rhsRes.reservationNumber() || lhsRes.reservationNumber().isEmpty()) { return false; } const auto lhsFlight = lhsRes.reservationFor().value(); const auto rhsFlight = rhsRes.reservationFor().value(); if (!isSameFlight(lhsFlight, rhsFlight)) { return false; } } // train: booking ref, train number and depature day match if (lhs.userType() == qMetaTypeId()) { const auto lhsRes = lhs.value(); const auto rhsRes = rhs.value(); if (lhsRes.reservationNumber() != rhsRes.reservationNumber()) { return false; } const auto lhsTrip = lhsRes.reservationFor().value(); const auto rhsTrip = rhsRes.reservationFor().value(); if (!isSameTrainTrip(lhsTrip, rhsTrip)) { return false; } } // bus: booking ref, number and depature time match if (lhs.userType() == qMetaTypeId()) { const auto lhsRes = lhs.value(); const auto rhsRes = rhs.value(); if (lhsRes.reservationNumber() != rhsRes.reservationNumber()) { return false; } const auto lhsTrip = lhsRes.reservationFor().value(); const auto rhsTrip = rhsRes.reservationFor().value(); if (!isSameBusTrip(lhsTrip, rhsTrip)) { return false; } } // hotel: booking ref, checkin day, name match if (lhs.userType() == qMetaTypeId()) { const auto lhsRes = lhs.value(); const auto rhsRes = rhs.value(); if (lhsRes.reservationNumber() != rhsRes.reservationNumber()) { return false; } const auto lhsHotel = lhsRes.reservationFor().value(); const auto rhsHotel = rhsRes.reservationFor().value(); if (!isSameLodingBusiness(lhsHotel, rhsHotel) || lhsRes.checkinTime().date() != rhsRes.checkinTime().date()) { return false; } } + // restaurant reservation: sane restaurant, same booking ref, same day + if (lhs.userType() == qMetaTypeId()) { + const auto lhsRes = lhs.value(); + const auto rhsRes = rhs.value(); + if (lhsRes.reservationNumber() != rhsRes.reservationNumber()) { + return false; + } + const auto lhsRestaurant = lhsRes.reservationFor().value(); + const auto rhsRestaurant = rhsRes.reservationFor().value(); + if (!isSameFoodEstablishment(lhsRestaurant, rhsRestaurant) || lhsRes.startTime().date() != rhsRes.endTime().date()) { + return false; + } + } + // for all: underName either matches or is not set const auto lhsUN = JsonLd::convert(lhs).underName(); const auto rhsUN = JsonLd::convert(rhs).underName(); return lhsUN.isNull() || rhsUN.isNull() || isSamePerson(lhsUN.value(), rhsUN.value()); } bool MergeUtil::isSameFlight(const Flight& lhs, const Flight& rhs) { if (lhs.flightNumber().isEmpty() || rhs.flightNumber().isEmpty()) { return false; } return lhs.flightNumber() == rhs.flightNumber() && lhs.airline().iataCode() == rhs.airline().iataCode() && lhs.departureDay() == rhs.departureDay(); } static bool isSameTrainTrip(const TrainTrip &lhs, const TrainTrip &rhs) { if (lhs.trainNumber().isEmpty() || rhs.trainNumber().isEmpty()) { return false; } return lhs.trainName() == rhs.trainName() && lhs.trainNumber() == rhs.trainNumber() && lhs.departureTime().date() == rhs.departureTime().date(); } static bool isSameBusTrip(const BusTrip &lhs, const BusTrip &rhs) { if (lhs.busNumber().isEmpty() || rhs.busNumber().isEmpty()) { return false; } return lhs.busName() == rhs.busName() && lhs.busNumber() == rhs.busNumber() && lhs.departureTime() == rhs.departureTime(); } static bool isSameLodingBusiness(const LodgingBusiness &lhs, const LodgingBusiness &rhs) { if (lhs.name().isEmpty() || rhs.name().isEmpty()) { return false; } return lhs.name() == rhs.name(); } +static bool isSameFoodEstablishment(const FoodEstablishment &lhs, const FoodEstablishment &rhs) +{ + if (lhs.name().isEmpty() || rhs.name().isEmpty()) { + return false; + } + + return lhs.name() == rhs.name(); +} + bool MergeUtil::isSamePerson(const Person& lhs, const Person& rhs) { // TODO: extend this once Person has familiy and given name fields return lhs.name().compare(rhs.name(), Qt::CaseInsensitive) == 0; }