Commit 06e6feb0 authored by Volker Krause's avatar Volker Krause
Browse files

Support finding calendar events for minimal cancellations

parent da69aee3
BEGIN:VCALENDAR
PRODID:-//K Desktop Environment//NONSGML libkcal 4.3//EN
VERSION:2.0
BEGIN:VEVENT
DTSTAMP:20200328T095155Z
X-KDE-KITINERARY-RESERVATION:[{"@context":"http://schema.org"\,"@type":
"FlightReservation"\,"modifiedTime":"2027-01-01T08:30:00-08:
00"\,"reservationFor":{"@type":"Flight"\,"airline":{"@type":
"Airline"\,"iataCode":"UA"\,"name":"United"}\,"arrivalAirport":{"@type":
"Airport"\,"address":{"@type":"PostalAddress"\,"addressCountry":
"US"}\,"geo":{"@type":"GeoCoordinates"\,"latitude":
40.63970184326172\,"longitude":-73.77890014648438}\,"iataCode":
"JFK"\,"name":"John F. Kennedy International Airport"}\,"arrivalTime":
{"@type":"QDateTime"\,"@value":"2027-03-05T06:30:00-05:00"\,"timezone":
"America/New_York"}\,"departureAirport":{"@type":"Airport"\,"address":
{"@type":"PostalAddress"\,"addressCountry":"US"}\,"geo":{"@type":
"GeoCoordinates"\,"latitude":37.618900299072266\,"longitude":
-122.375}\,"iataCode":"SFO"\,"name":"San Francisco
Airport"}\,"departureDay":"2027-03-04"\,"departureTime":{"@type":
"QDateTime"\,"@value":"2027-03-04T20:15:00-08:00"\,"timezone":
"America/Los_Angeles"}\,"flightNumber":"110"}\,"reservationNumber":
"RXJ34P"\,"reservationStatus":"http:
//schema.org/ReservationConfirmed"\,"underName":{"@type":"Person"\,"name":
"Eva Green"}}]
CREATED:20200328T095155Z
UID:KIT-74e55159-9032-4e97-a947-59a92a5af9cc
LAST-MODIFIED:20200328T095155Z
DESCRIPTION:Eva Green\nBooking reference: RXJ34P
SUMMARY:Flight UA 110 from SFO to JFK
LOCATION:San Francisco Airport
GEO:37.618900;-122.375000
DTSTART;TZID=America/Los_Angeles:20270304T201500
DTEND;TZID=America/New_York:20270305T063000
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR
......@@ -146,6 +146,22 @@ private Q_SLOTS:
const auto event = CalendarHandler::findEvent(refCal, postproc.result().at(0));
QVERIFY(event);
}
void testFindEventForCancellation()
{
QFile f(QStringLiteral(SOURCE_DIR "/mergedata/cancellation.rhs.json"));
QVERIFY(f.open(QFile::ReadOnly));
const auto in = JsonLdDocument::fromJson(QJsonDocument::fromJson(f.readAll()).array());
QCOMPARE(in.size(), 1);
const auto cancel = in[0];
MemoryCalendar::Ptr refCal(new MemoryCalendar(QTimeZone::systemTimeZone()));
ICalFormat format;
format.load(refCal, QStringLiteral(SOURCE_DIR "/calendarhandlerdata/to-be-cancelled.ics"));
const auto event = CalendarHandler::findEvent(refCal, cancel);
QVERIFY(event);
}
};
QTEST_APPLESS_MAIN(CalendarHandlerTest)
......
......@@ -73,7 +73,7 @@ static void fillFlightReservation(const QVector<QVariant> &reservations, const K
static void fillTrainReservation(const TrainReservation &reservation, const KCalendarCore::Event::Ptr &event);
static void fillBusReservation(const BusReservation &reservation, const KCalendarCore::Event::Ptr &event);
static void fillLodgingReservation(const QVector<QVariant> &reservations, const KCalendarCore::Event::Ptr &event);
static void fillEvent(const KItinerary::Event &ev, const KCalCore::Event::Ptr &event);
static void fillEvent(const KItinerary::Event &ev, const KCalendarCore::Event::Ptr &event);
static void fillEventReservation(const QVector<QVariant> &reservations, const KCalendarCore::Event::Ptr &event);
static void fillGeoPosition(const QVariant &place, const KCalendarCore::Event::Ptr &event);
static void fillFoodReservation(const FoodEstablishmentReservation &reservation, const KCalendarCore::Event::Ptr &event);
......@@ -88,8 +88,21 @@ QSharedPointer<KCalendarCore::Event> CalendarHandler::findEvent(const QSharedPoi
return {};
}
QVector<KCalendarCore::Event::Ptr> events;
const auto dt = SortUtil::startDateTime(reservation).toTimeZone(calendar->timeZone()).date();
const auto events = calendar->events(dt);
if (dt.isValid()) {
// we know the exact day to search at
events = calendar->events(dt);
} else if (JsonLd::canConvert<Reservation>(reservation)) {
// for minimal cancellations, we need to search in a larger range
const auto res = JsonLd::convert<Reservation>(reservation);
if (!res.modifiedTime().isValid() || res.reservationStatus() != Reservation::ReservationCancelled) {
return {};
}
const auto date = res.modifiedTime().toTimeZone(calendar->timeZone()).date();
events = calendar->events(date, date.addDays(180));
}
for (const auto &event : events) {
if (!event->uid().startsWith(QLatin1String("KIT-"))) {
continue;
......@@ -359,7 +372,7 @@ static void fillLodgingReservation(const QVector<QVariant> &reservations, const
event->setDescription(desc.join(QLatin1Char('\n')));
}
static void fillEvent(const KItinerary::Event &ev, const KCalCore::Event::Ptr &event)
static void fillEvent(const KItinerary::Event &ev, const KCalendarCore::Event::Ptr &event)
{
Place location;
if (JsonLd::canConvert<Place>(ev.location())) {
......
Markdown is supported
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