Commit 19db1590 authored by Volker Krause's avatar Volker Krause

Filter out action URLs that obviously don't carry the intended semantic

This prevents the corresponding actions from showing up in the UI.
parent 93638b4f
......@@ -2,8 +2,6 @@
{
"@context": "http://schema.org",
"@type": "TrainReservation",
"cancelReservationUrl": "https://www.trainline.fr/tickets",
"modifyReservationUrl": "https://www.trainline.fr/tickets",
"reservationFor": {
"@type": "TrainTrip",
"arrivalStation": {
......@@ -43,8 +41,6 @@
{
"@context": "http://schema.org",
"@type": "TrainReservation",
"cancelReservationUrl": "https://www.trainline.fr/tickets",
"modifyReservationUrl": "https://www.trainline.fr/tickets",
"reservationFor": {
"@type": "TrainTrip",
"arrivalStation": {
......
......@@ -34,6 +34,10 @@ void ExtractorPostprocessor::process(const QVector<QVariant> &data)
for (auto d : data) {
if (d.userType() == qMetaTypeId<FlightReservation>()) {
d = processFlightReservation(d);
} else if (d.userType() == qMetaTypeId<TrainReservation>()) {
d = processReservation(d);
} else if (d.userType() == qMetaTypeId<LodgingReservation>()) {
d = processReservation(d);
}
if (filterReservation(d)) {
......@@ -61,7 +65,9 @@ QVariant ExtractorPostprocessor::processProperty(QVariant obj, const char *name,
QVariant ExtractorPostprocessor::processFlightReservation(QVariant res) const
{
return processProperty(res, "reservationFor", &ExtractorPostprocessor::processFlight);
res = processReservation(res);
res = processProperty(res, "reservationFor", &ExtractorPostprocessor::processFlight);
return res;
}
QVariant ExtractorPostprocessor::processFlight(QVariant flight) const
......@@ -146,6 +152,21 @@ void ExtractorPostprocessor::processFlightTime(QVariant &flight, const char *tim
JsonLdDocument::writeProperty(flight, timePropName, dt);
}
QVariant ExtractorPostprocessor::processReservation(QVariant res) const
{
const auto viewUrl = JsonLdDocument::readProperty(res, "url").toUrl();
const auto modUrl = JsonLdDocument::readProperty(res, "modifyReservationUrl").toUrl();
const auto cancelUrl = JsonLdDocument::readProperty(res, "cancelReservationUrl").toUrl();
if (modUrl.isValid() && viewUrl == modUrl) {
JsonLdDocument::removeProperty(res, "modifyReservationUrl");
}
if (cancelUrl.isValid() && viewUrl == cancelUrl) {
JsonLdDocument::removeProperty(res, "cancelReservationUrl");
}
return res;
}
bool ExtractorPostprocessor::filterReservation(const QVariant &res) const
{
const auto resFor = JsonLdDocument::readProperty(res, "reservationFor");
......
......@@ -38,6 +38,7 @@ private:
QVariant processAirport(QVariant airport) const;
QVariant processAirline(QVariant airline) const;
void processFlightTime(QVariant &flight, const char *timePropName, const char *airportPropName) const;
QVariant processReservation(QVariant res) const;
bool filterReservation(const QVariant &res) const;
bool filterLodgingReservation(const QVariant &res) const;
......
......@@ -219,3 +219,8 @@ void JsonLdDocument::writeProperty(QVariant &obj, const char *name, const QVaria
const auto prop = mo->property(idx);
prop.writeOnGadget(obj.data(), value);
}
void JsonLdDocument::removeProperty(QVariant &obj, const char *name)
{
writeProperty(obj, name, QVariant());
}
......@@ -34,6 +34,8 @@ QJsonArray toJson(const QVector<QVariant> &data);
QVariant readProperty(const QVariant &obj, const char *name);
/** Set property @p name on object @p obj to value @p value. */
void writeProperty(QVariant &obj, const char *name, const QVariant &value);
/** Removes property @p name on object @p obj. */
void removeProperty(QVariant &obj, const char *name);
}
#endif // JSONLDDOCUMENT_H
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