Commit 333834f5 authored by Volker Krause's avatar Volker Krause
Browse files

Unify extractor filter field name key

Now that we don't need that anymore to determine the filter type, we can
name them the same everywhere. This is not only less error prone and
simplifies the code, it also a first step towards making the extractor
engine core more type-agnostic.
parent 84136cd4
Pipeline #54443 passed with stages
in 11 minutes and 40 seconds
......@@ -46,10 +46,9 @@ class ExtractorRepositoryPrivate;
*
* Filter definitions have the following field:
* - \c type: The type of data this filter applies to, one of: @c Mime, @c PkPass, @c JsonLd, @c Barcode, @c ICal, @c Text.
* Can often be omitted as it's auto-detected based on the following fields.
* - \c header: A MIME message header name (valid and mandatory for type @c Mime).
* - \c field: A field id in a Apple Wallet pass (valid and mandatory for type @c PkPass).
* - \c property: A property on a Json-LD object (valid and mandatory for type @c JsonLd and @c ICal).
* - \c field: The name of the field to match against. This can be a field id in a Apple Wallet pass,
* A MIME message header name, a property on a Json-LD object or an iCal calendar or event.
* For @c Text or @c Barcode, this is ignored.
* - \c match: A regular expression that is matched against the specified value (see QRegularExpression).
*
* Example:
......@@ -57,13 +56,13 @@ class ExtractorRepositoryPrivate;
* [
* {
* "type": "Pdf",
* "filter": [ { "header": "From", "match": "@swiss.com" } ],
* "filter": [ { "field": "From", "match": "@swiss.com", "type": "Email" } ],
* "script": "swiss.js",
* "function": "parsePdf"
* },
* {
* "type": "PkPass",
* "filter": [ { "field": "passTypeIdentifier", "match": "pass.booking.swiss.com" } ],
* "filter": [ { "field": "passTypeIdentifier", "match": "pass.booking.swiss.com", "type": "PkPass" } ],
* "script": "swiss.js",
* "function": "parsePkPass"
* }
......
......@@ -79,27 +79,7 @@ bool ExtractorFilter::load(const QJsonObject &obj)
if (d->m_type == ExtractorInput::Unknown) {
qCDebug(Log) << "unspecified filter type";
}
auto it = obj.find(QLatin1String("header"));
if (it != obj.end()) {
d->m_fieldName = it.value().toString();
d->m_type = ExtractorInput::Email;
}
it = obj.find(QLatin1String("field"));
if (it != obj.end()) {
d->m_fieldName = it.value().toString();
d->m_type = ExtractorInput::PkPass;
}
it = obj.find(QLatin1String("property"));
if (it != obj.end()) {
d->m_fieldName = it.value().toString();
if (d->m_type == ExtractorInput::Unknown) { // backward compat, can be removed once all extractors are adjusted
d->m_type = ExtractorInput::JsonLd;
}
}
d->m_fieldName = obj.value(QLatin1String("field")).toString();
d->m_exp.setPattern(obj.value(QLatin1String("match")).toString());
return d->m_type != ExtractorInput::Unknown && (!d->m_fieldName.isEmpty() || !needsFieldName(d->m_type)) && d->m_exp.isValid();
}
......@@ -109,17 +89,7 @@ QJsonObject ExtractorFilter::toJson() const
QJsonObject obj;
obj.insert(QStringLiteral("type"), ExtractorInput::typeToString(d->m_type));
if (needsFieldName(d->m_type)) {
switch (d->m_type) {
case ExtractorInput::Email:
obj.insert(QStringLiteral("header"), d->m_fieldName);
break;
case ExtractorInput::PkPass:
obj.insert(QStringLiteral("field"), d->m_fieldName);
break;
default:
obj.insert(QStringLiteral("property"), d->m_fieldName);
break;
}
obj.insert(QStringLiteral("field"), d->m_fieldName);
}
obj.insert(QStringLiteral("match"), pattern());
return obj;
......
{
"filter": [
{
"header": "From",
"field": "From",
"match": "@reservation.accor-mail.com",
"type": "Email"
}
......
{
"filter": [
{
"header": "From",
"field": "From",
"match": "@acprail.com",
"type": "Email"
}
......
[{
"type": "html",
"filter": [
{ "header": "From", "match": "aerlingus.com", "type": "Email" }
{ "field": "From", "match": "aerlingus.com", "type": "Email" }
],
"script": "aerlingus.js"
}]
{
"filter": [
{
"header": "From",
"field": "From",
"match": "@agoda.com",
"type": "Email"
}
......
{
"type": "pdf",
"filter": [
{ "header": "From", "match": "@airbaltic.com", "type": "Email" },
{ "property": "reservationFor.airline.iataCode", "match": "BT", "type": "JsonLd" }
{ "field": "From", "match": "@airbaltic.com", "type": "Email" },
{ "field": "reservationFor.airline.iataCode", "match": "BT", "type": "JsonLd" }
],
"script": "airbaltic.js"
}
{
"filter": [
{
"header": "From",
"field": "From",
"match": "@aircoach.ie",
"type": "Email"
}
......
......@@ -2,16 +2,16 @@
{
"type": "text",
"filter": [
{ "header": "From", "match": "@amadeus.com", "type": "Email" },
{ "header": "Message-ID", "match": "amadeus.com", "type": "Email" }
{ "field": "From", "match": "@amadeus.com", "type": "Email" },
{ "field": "Message-ID", "match": "amadeus.com", "type": "Email" }
],
"script": "amadeus.js"
},
{
"type": "ical",
"filter": [
{ "header": "From", "match": "@amadeus.com", "type": "Email" },
{ "property": "productId", "match": "//AMADEUS//", "type": "ICal" }
{ "field": "From", "match": "@amadeus.com", "type": "Email" },
{ "field": "productId", "match": "//AMADEUS//", "type": "ICal" }
],
"script": "amadeus.js",
"function": "parseEvent"
......
{
"type": "pdf",
"filter": [
{ "header": "From", "match": "americanairlines@aa.com", "type": "Email" },
{ "property": "reservationFor.airline.iataCode", "match": "AA", "type": "JsonLd" }
{ "field": "From", "match": "americanairlines@aa.com", "type": "Email" },
{ "field": "reservationFor.airline.iataCode", "match": "AA", "type": "JsonLd" }
],
"script": "americanairlines.js"
}
{
"filter": [
{ "header": "From", "match": "@aohostels.com", "type": "Email" }
{ "field": "From", "match": "@aohostels.com", "type": "Email" }
],
"script": "aohostels.js",
"type": "Text"
......
[
{
"type": "html",
"filter": [ { "header": "From", "match": "@availpro.com", "type": "Email" } ],
"filter": [ { "field": "From", "match": "@availpro.com", "type": "Email" } ],
"script": "availpro.js",
"function": "parseHtml"
}
......
[
{
"type": "text",
"filter": [ { "header": "From", "match": "@booking.com", "type": "Email" } ],
"filter": [ { "field": "From", "match": "@booking.com", "type": "Email" } ],
"script": "booking.js"
},
{
"type": "html",
"filter": [ { "header": "From", "match": "@booking.com", "type": "Email" } ],
"filter": [ { "field": "From", "match": "@booking.com", "type": "Email" } ],
"script": "booking.js",
"function": "parseHtml"
}
......
......@@ -2,15 +2,15 @@
{
"type": "html",
"filter": [
{ "header": "From", "match": "@brusselsairlines.com", "type": "Email" }
{ "field": "From", "match": "@brusselsairlines.com", "type": "Email" }
],
"script": "brusselsairlines.js"
},
{
"type": "pdf",
"filter": [
{ "header": "From", "match": "brusselsairlines.com", "type": "Email" },
{ "property": "reservationFor.airline.iataCode", "match": "SN", "type": "JsonLd" }
{ "field": "From", "match": "brusselsairlines.com", "type": "Email" },
{ "field": "reservationFor.airline.iataCode", "match": "SN", "type": "JsonLd" }
],
"script": "brusselsairlines-receipt.js"
}
......
......@@ -2,7 +2,7 @@
"filter": [
{
"match": "uic:9997",
"property": "reservationFor.provider.identifier",
"field": "reservationFor.provider.identifier",
"type": "JsonLd"
}
],
......
{
"filter": [
{ "header": "From", "match": "info@cd.cz", "type": "Email" },
{ "header": "From", "match": "eshop@cd.cz", "type": "Email" }
{ "field": "From", "match": "info@cd.cz", "type": "Email" },
{ "field": "From", "match": "eshop@cd.cz", "type": "Email" }
],
"script": "czechrailways.js",
"type": "Text"
......
......@@ -2,18 +2,18 @@
{
"filter": [
{
"header": "From",
"field": "From",
"match": "buchungsbestaetigung@bahn.de",
"type": "Email"
},
{
"match": "uic:0080",
"property": "reservationFor.provider.identifier",
"field": "reservationFor.provider.identifier",
"type": "JsonLd"
},
{
"match": "vdv:6260",
"property": "reservationFor.provider.identifier",
"field": "reservationFor.provider.identifier",
"type": "JsonLd"
}
],
......@@ -24,7 +24,7 @@
{
"filter": [
{
"header": "From",
"field": "From",
"match": "UNITTEST-buchungsbestaetigung@bahn.de",
"type": "Email"
}
......@@ -36,7 +36,7 @@
{
"filter": [
{
"header": "From",
"field": "From",
"match": "buchungsbestaetigung@bahn.de",
"type": "Email"
}
......
[
{
"type": "ical",
"filter": [ { "property": "productId", "match": "//DinnerBooking//", "type": "ICal" } ],
"filter": [ { "field": "productId", "match": "//DinnerBooking//", "type": "ICal" } ],
"script": "dinnerbooking.js",
"function": "parseEvent"
}
......
[
{
"type": "html",
"filter": [ { "header": "From", "match": "@easyjet.com", "type": "Email" } ],
"filter": [ { "field": "From", "match": "@easyjet.com", "type": "Email" } ],
"script": "easyjet.js",
"function": "parseHtmlBooking"
},
{
"type": "pdf",
"filter": [
{ "property": "reservationFor.airline.iataCode", "match": "EJU", "type": "JsonLd" },
{ "property": "reservationFor.airline.iataCode", "match": "EZS", "type": "JsonLd" },
{ "property": "reservationFor.airline.iataCode", "match": "EZY", "type": "JsonLd" }
{ "field": "reservationFor.airline.iataCode", "match": "EJU", "type": "JsonLd" },
{ "field": "reservationFor.airline.iataCode", "match": "EZS", "type": "JsonLd" },
{ "field": "reservationFor.airline.iataCode", "match": "EZY", "type": "JsonLd" }
],
"script": "easyjet.js",
"function": "parsePdfBoardingPass"
......
[{
"type": "text",
"filter": [
{ "header": "From", "match": "@booking.eurowings.com", "type": "Email" }
{ "field": "From", "match": "@booking.eurowings.com", "type": "Email" }
],
"script": "eurowings.js"
}, {
......
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