7#include "extractorvalidator.h"
8#include "validator-logging.h"
10#include <KItinerary/BoatTrip>
11#include <KItinerary/BusTrip>
12#include <KItinerary/Event>
13#include <KItinerary/Flight>
14#include <KItinerary/Place>
15#include <KItinerary/ProgramMembership>
16#include <KItinerary/RentalCar>
17#include <KItinerary/Reservation>
18#include <KItinerary/Taxi>
19#include <KItinerary/Ticket>
20#include <KItinerary/TrainTrip>
21#include <KItinerary/Visit>
28class ExtractorValidatorPrivate {
30 bool isSupportedTopLevelType(
const QVariant &elem)
const;
31 bool filterElement(
const QVariant &elem)
const;
34 bool filterAirport(
const Airport &airport)
const;
35 bool filterFlight(
const Flight &flight)
const;
36 bool filterTrainTrip(
const TrainTrip &trip)
const;
37 bool filterBusTrip(
const BusTrip &trip)
const;
38 bool filterBoatTrip(
const BoatTrip &trip)
const;
39 bool filterEvent(
const Event &event)
const;
41 bool filterLocalBusiness(
const LocalBusiness &business)
const;
42 bool filterReservation(
const Reservation &res)
const;
44 bool filterTicket(
const Ticket &ticket)
const;
46 std::vector<const QMetaObject*> m_acceptedTypes;
47 bool m_onlyComplete =
true;
51ExtractorValidator::ExtractorValidator() :
52 d(new ExtractorValidatorPrivate)
61 d->m_acceptedTypes = std::move(accptedTypes);
66 d->m_onlyComplete = completeOnly;
70bool ExtractorValidatorPrivate::filterLodgingReservation(
const LodgingReservation &res)
const
72 return res.checkinTime().
isValid() && res.checkoutTime().
isValid() && res.checkinTime() <= res.checkoutTime();
75bool ExtractorValidatorPrivate::filterAirport(
const Airport &airport)
const
80bool ExtractorValidatorPrivate::filterFlight(
const Flight &flight)
const
84 return filterAirport(flight.departureAirport())
85 && filterAirport(flight.arrivalAirport())
90static bool filterPlace(
const T &place)
92 return !place.name().isEmpty();
95bool ExtractorValidatorPrivate::filterTrainTrip(
const TrainTrip &trip)
const
97 return filterPlace(trip.departureStation())
98 && filterPlace(trip.arrivalStation())
102bool ExtractorValidatorPrivate::filterBusTrip(
const BusTrip &trip)
const
104 return filterPlace(trip.departureBusStop())
105 && filterPlace(trip.arrivalBusStop())
106 && trip.departureTime().
isValid();
109bool ExtractorValidatorPrivate::filterBoatTrip(
const BoatTrip &trip)
const
111 return filterPlace(trip.departureBoatTerminal())
112 && filterPlace(trip.arrivalBoatTerminal())
113 && trip.departureTime().
isValid()
114 && trip.arrivalTime().
isValid();
117bool ExtractorValidatorPrivate::filterEvent(
const Event &event)
const
119 return !
event.name().isEmpty() &&
event.startDate().isValid();
124 return res.startTime().
isValid();
127bool ExtractorValidatorPrivate::filterLocalBusiness(
const LocalBusiness &business)
const
129 return !business.name().isEmpty();
132bool ExtractorValidatorPrivate::filterReservation(
const Reservation &res)
const
134 if (!m_onlyComplete) {
135 if (res.reservationFor().
isNull()
136 && res.modifiedTime().
isValid()
137 && !res.reservationNumber().
isEmpty()
138 && res.reservationStatus() == Reservation::ReservationCancelled)
144 if (!filterElement(res.reservationFor())) {
145 qCDebug(ValidatorLog) <<
"Reservation element discarded due to rejected reservationFor property:" << res.reservationFor().
typeName();
151bool ExtractorValidatorPrivate::filterProgramMembership(
const ProgramMembership &program)
const
156bool ExtractorValidatorPrivate::filterTicket(
const Ticket &ticket)
const
161template <
typename T,
bool (ExtractorVal
idatorPrivate::*F)(const T&) const>
162static inline bool callFilterWithType(
const ExtractorValidatorPrivate *d,
const QVariant &v)
168#define FILTER(Type, Func) { &Type::staticMetaObject, callFilterWithType<Type, &ExtractorValidatorPrivate::Func> }
171 bool (*filter)(
const ExtractorValidatorPrivate *d,
const QVariant &v);
172}
static const filter_func_map[] {
173 FILTER(
Flight, filterFlight),
175 FILTER(
BusTrip, filterBusTrip),
183 FILTER(
Ticket, filterTicket),
187bool ExtractorValidatorPrivate::filterElement(
const QVariant &elem)
const
191 qCDebug(ValidatorLog) <<
"Element discarded due to non-gadget type:" << elem.
typeName();
195 for (
const auto &f : filter_func_map) {
196 if (f.metaObject != mo) {
199 if (!f.filter(
this, elem)) {
204 mo = mo->superClass();
209bool ExtractorValidatorPrivate::isSupportedTopLevelType(
const QVariant &elem)
const
211 if (m_acceptedTypes.empty()) {
217 qCDebug(ValidatorLog) <<
"Element discarded due to non-gadget top-level type:" << elem.
typeName();
221 const auto it = std::find(m_acceptedTypes.begin(), m_acceptedTypes.end(), mo);
222 if (it != m_acceptedTypes.end()) {
225 mo = mo->superClass();
233 if (!d->isSupportedTopLevelType(elem)) {
234 qCDebug(ValidatorLog) <<
"Element discarded due to unsupported top-level type:" << elem.
typeName();
239 return d->filterElement(elem);
QDate departureDay
The scheduled day of departure.
A restaurant reservation.
A frequent traveler, bonus points or discount scheme program membership.
QString token
KItinerary extension: barcode token for program membership cards having a barcode representation (e....
Abstract base class for reservations.
QString ticketToken
The raw ticket token string.
QDate departureDay
The scheduled day of departure.
T convert(const QVariant &value)
Up-cast value to T.
Classes for reservation/travel data models, data extraction and data augmentation.
bool isValid(int year, int month, int day)
bool isValid() const const
bool isEmpty() const const
bool isNull() const const
const char * typeName() const const
int userType() const const