diff --git a/src/mergeutil.cpp b/src/mergeutil.cpp index d0f0643..f5ec1a0 100644 --- a/src/mergeutil.cpp +++ b/src/mergeutil.cpp @@ -1,100 +1,126 @@ /* 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 using namespace KItinerary; +static bool isSameTrainTrip(const TrainTrip &lhs, const TrainTrip &rhs); +static bool isSameLodingBusiness(const LodgingBusiness &lhs, const LodgingBusiness &rhs); + bool MergeUtil::isSameReservation(const QVariant& lhs, const QVariant& rhs) { if (lhs.isNull() || rhs.isNull()) { 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; } } // TODO bus: booking ref, train number and depature day match - // TODO hotel: booking ref, checkin day match + + // 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.checkinDate() != rhsRes.checkinDate()) { + return false; + } + } // for all: underName either matches or is not set const auto lhsUN = JsonLdDocument::readProperty(lhs, "underName"); const auto rhsUN = JsonLdDocument::readProperty(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(); } -bool MergeUtil::isSameTrainTrip(const TrainTrip &lhs, const TrainTrip &rhs) +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 isSameLodingBusiness(const LodgingBusiness &lhs, const LodgingBusiness &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; } diff --git a/src/mergeutil.h b/src/mergeutil.h index 2959a8d..b5cd0cc 100644 --- a/src/mergeutil.h +++ b/src/mergeutil.h @@ -1,71 +1,64 @@ /* 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 . */ #ifndef KITINERARY_MERGEUTIL_H #define KITINERARY_MERGEUTIL_H #include "kitinerary_export.h" class QVariant; namespace KItinerary { class Flight; class Person; class TrainTrip; /** Utilities for merging reservations or elements of them. */ namespace MergeUtil { /** * Checks if two reservations refer to the same booking element. * * This depends on the reservation type: * - Flights: booking reference, flight number and departure day match * - Train trip: booking reference, train number and departure day match * - But trip: TODO - * - Hotel booking: booking reference and checkin day match + * - Hotel booking: hotel name, booking reference and checkin day match * * For all reservation types, the Reservation::underName property is * checked and either needs to be equal or absent in one of the values. */ KITINERARY_EXPORT bool isSameReservation(const QVariant &lhs, const QVariant &rhs); /** * Checks if two Flight objects refer to the same flight. * * That is, if the flight number and departure day match. */ KITINERARY_EXPORT bool isSameFlight(const Flight &lhs, const Flight &rhs); -/** - * Checks if two TrainTrip objects refer to the same trip - * - * That is, if the train name/number and departure day match. - */ -KITINERARY_EXPORT bool isSameTrainTrip(const TrainTrip &lhs, const TrainTrip &rhs); - /** * Checks if two Person objects refer to the same person. * * Essentially a case-insensitive comparisson of the name components. */ KITINERARY_EXPORT bool isSamePerson(const Person &lhs, const Person &rhs); } } #endif // KITINERARY_MERGEUTIL_H