Commit 892a817f authored by Volker Krause's avatar Volker Krause
Browse files

Add ProgramMembership type from schema.org

This covers information about frequent traveler or bonus/discount programs.
While that is of limited value in most cases, we will be using this to
model DB BahnCards eventually, something that actually has practical
relevance during a trip.
parent 2fab2b3e
......@@ -23,10 +23,15 @@
"target": "http://cheapair.com/edit?id=RXJ34P"
},
{
"@type": "ViewAction",
"target": "http://cheapair.com/view/RXJ34P"
"@type": "ViewAction",
"target": "http://cheapair.com/view/RXJ34P"
}
],
"programMembershipUsed": {
"@type": "ProgramMembership",
"membershipNumber": "4BY123111",
"programName": "StarAlliance"
},
"reservationFor": {
"@type": "Flight",
"airline": {
......
......@@ -17,6 +17,7 @@ target_sources(KPimItinerary PRIVATE
datatypes/organization.cpp
datatypes/person.cpp
datatypes/place.cpp
datatypes/programmembership.cpp
datatypes/reservation.cpp
datatypes/taxi.cpp
datatypes/ticket.cpp
......@@ -211,6 +212,7 @@ ecm_generate_headers(KItinerary_Datatypes_FORWARDING_HEADERS
RentalCar
Person
Place
ProgramMembership
Taxi
Ticket
TrainTrip
......
/*
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "programmembership.h"
#include "datatypes_p.h"
using namespace KItinerary;
namespace KItinerary {
class ProgramMembershipPrivate : public QSharedData
{
public:
QString programName;
QString membershipNumber;
Person member;
QString token;
};
KITINERARY_MAKE_SIMPLE_CLASS(ProgramMembership)
KITINERARY_MAKE_PROPERTY(ProgramMembership, QString, programName, setProgramName)
KITINERARY_MAKE_PROPERTY(ProgramMembership, QString, membershipNumber, setMembershipNumber)
KITINERARY_MAKE_PROPERTY(ProgramMembership, Person, member, setMember)
KITINERARY_MAKE_PROPERTY(ProgramMembership, QString, token, setToken)
KITINERARY_MAKE_OPERATOR(ProgramMembership)
}
#include "moc_programmembership.cpp"
/*
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KITINERARY_PROGRAMMEMBERSHIP_H
#define KITINERARY_PROGRAMMEMBERSHIP_H
#include "kitinerary_export.h"
#include "datatypes.h"
#include "person.h"
namespace KItinerary {
class ProgramMembershipPrivate;
/** A frequent traveler, bonus points or discount scheme program membership.
* @see https://schema.org/ProgramMembership
*/
class KITINERARY_EXPORT ProgramMembership
{
KITINERARY_GADGET(ProgramMembership)
KITINERARY_PROPERTY(QString, programName, setProgramName)
KITINERARY_PROPERTY(QString, membershipNumber, setMembershipNumber)
KITINERARY_PROPERTY(KItinerary::Person, member, setMember)
/** KItinerary extension: barcode token for program membership cards
* having a barcode representation (e.g. Deutsch Bahn BahnCards).
* Semantics are the same as of Ticket::ticketToken.
* @see Ticket::ticketToken
*/
KITINERARY_PROPERTY(QString, token, setToken)
private:
QExplicitlySharedDataPointer<ProgramMembershipPrivate> d;
};
}
Q_DECLARE_METATYPE(KItinerary::ProgramMembership)
#endif // KITINERARY_PROGRAMMEMBERSHIP_H
......@@ -32,6 +32,7 @@ public:
QDateTime modifiedTime;
QVariantList subjectOf;
Reservation::ReservationStatus reservationStatus = Reservation::ReservationConfirmed;
ProgramMembership programMembershipUsed;
};
KITINERARY_MAKE_BASE_CLASS(Reservation)
......@@ -47,6 +48,7 @@ KITINERARY_MAKE_PROPERTY(Reservation, QVariantList, potentialAction, setPotentia
KITINERARY_MAKE_PROPERTY(Reservation, QDateTime, modifiedTime, setModifiedTime)
KITINERARY_MAKE_PROPERTY(Reservation, QVariantList, subjectOf, setSubjectOf)
KITINERARY_MAKE_PROPERTY(Reservation, Reservation::ReservationStatus, reservationStatus, setReservationStatus)
KITINERARY_MAKE_PROPERTY(Reservation, ProgramMembership, programMembershipUsed, setProgramMembershipUsed)
KITINERARY_MAKE_OPERATOR(Reservation)
class LodgingReservationPrivate : public ReservationPrivate
......
......@@ -10,6 +10,7 @@
#include "datatypes.h"
#include "organization.h"
#include "place.h"
#include "programmembership.h"
class QUrl;
......@@ -45,6 +46,7 @@ public:
KITINERARY_PROPERTY(QDateTime, modifiedTime, setModifiedTime)
KITINERARY_PROPERTY(QVariantList, subjectOf, setSubjectOf)
KITINERARY_PROPERTY(ReservationStatus, reservationStatus, setReservationStatus)
KITINERARY_PROPERTY(KItinerary::ProgramMembership, programMembershipUsed, setProgramMembershipUsed)
// KDE extensions
/** Pass type identifier of an associated Apple Wallet boarding pass.
......
......@@ -26,6 +26,7 @@
#include <KItinerary/Organization>
#include <KItinerary/Person>
#include <KItinerary/Place>
#include <KItinerary/ProgramMembership>
#include <KItinerary/RentalCar>
#include <KItinerary/Reservation>
#include <KItinerary/Taxi>
......@@ -403,12 +404,24 @@ Event ExtractorPostprocessorPrivate::processEvent(Event event) const
return event;
}
ProgramMembership ExtractorPostprocessorPrivate::processProgramMembership(ProgramMembership program) const
{
program.setProgramName(program.programName().simplified());
// avoid emitting spurious empty ProgramMembership objects caused by empty elements in JSON-LD/Microdata input
if (program.programName().isEmpty() && !program.programName().isNull()) {
program.setProgramName(QString());
}
program.setMember(processPerson(program.member()));
return program;
}
template <typename T>
T ExtractorPostprocessorPrivate::processReservation(T res) const
{
res.setUnderName(processPerson(res.underName().template value<Person>()));
res.setPotentialAction(processActions(res.potentialAction()));
res.setReservationNumber(res.reservationNumber().trimmed());
res.setProgramMembershipUsed(processProgramMembership(res.programMembershipUsed()));
return res;
}
......
......@@ -26,6 +26,7 @@ class GeoCoordinates;
class LodgingReservation;
class Person;
class PostalAddress;
class ProgramMembership;
class RentalCar;
class RentalCarReservation;
class TaxiReservation;
......@@ -58,6 +59,8 @@ public:
TaxiReservation processTaxiReservation(TaxiReservation res) const;
Event processEvent(Event event) const;
ProgramMembership processProgramMembership(ProgramMembership program) const;
template <typename T> T processReservation(T res) const;
Person processPerson(Person person) const;
template <typename T> static T processPlace(T place);
......
......@@ -17,6 +17,7 @@
#include <KItinerary/Organization>
#include <KItinerary/Person>
#include <KItinerary/Place>
#include <KItinerary/ProgramMembership>
#include <KItinerary/Reservation>
#include <KItinerary/RentalCar>
#include <KItinerary/Taxi>
......@@ -88,6 +89,7 @@ static void registerBuiltInTypes(std::vector<TypeInfo> &r)
add<Person>(r);
add<Place>(r);
add<PostalAddress>(r);
add<ProgramMembership>(r);
add<RentalCar>(r);
add<RentalCarReservation>(r);
add<ReserveAction>(r);
......
......@@ -156,6 +156,9 @@ static void filterReservation(QJsonObject &res)
res.insert(QStringLiteral("reservationStatus"), resStat.replace(QLatin1String("http://schema.org/"), QLatin1String("http://schema.org/Reservation")));
}
// legacy properties
renameProperty(res, "programMembership", "programMembershipUsed");
// legacy potentialAction property
renameProperty(res, "action", "potentialAction");
......@@ -196,6 +199,12 @@ static void filterFoodEstablishment(QJsonObject &restaurant)
}
}
static void filterProgramMembership(QJsonObject &program)
{
renameProperty(program, "program", "programName");
renameProperty(program, "memberNumber", "membershipNumber");
}
static void filterActionTarget(QJsonObject &action)
{
QJsonArray targets;
......@@ -278,6 +287,7 @@ static const struct {
{ "Flight", filterFlight },
{ "FoodEstablishment", filterFoodEstablishment },
{ "LodgingReservation", filterLodgingReservation },
{ "ProgramMembership", filterProgramMembership },
{ "TrainTrip", filterTrainTrip },
};
......
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