Commit 45352898 authored by Volker Krause's avatar Volker Krause
Browse files

Add VDV generic extractor, and integrate that into the PDF extractor

This in itself doesn't produce useful output yet (we need more work on
VDV ticket parsing for that), but it is already producing enough to trigger
custom extractors on.
parent c12a5f28
......@@ -27,6 +27,7 @@ set(kitinerary_lib_srcs
generic/genericpdfextractor.cpp
generic/genericpkpassextractor.cpp
generic/genericuic918extractor.cpp
generic/genericvdvextractor.cpp
generic/structureddataextractor.cpp
jsapi/barcode.cpp
......
......@@ -17,12 +17,14 @@
#include "genericpdfextractor_p.h"
#include "genericuic918extractor_p.h"
#include "genericvdvextractor_p.h"
#include <KItinerary/BarcodeDecoder>
#include <KItinerary/IataBcbpParser>
#include <KItinerary/JsonLdDocument>
#include <KItinerary/PdfDocument>
#include <KItinerary/Uic9183Parser>
#include <KItinerary/VdvTicketParser>
#include <QDebug>
#include <QImage>
......@@ -124,6 +126,13 @@ GenericExtractor::Result GenericPdfExtractor::extractImage(const PdfImage &img,
}
return {};
}
if (VdvTicketParser::maybeVdvTicket(b)) {
const auto result = GenericVdvExtractor::extract(b);
if (!result.isEmpty()) {
return GenericExtractor::Result{result, b, -1};
}
}
}
// string barcode content
......
/*
Copyright (C) 2019 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "genericvdvextractor_p.h"
#include <KItinerary/VdvTicket>
#include <KItinerary/VdvTicketParser>
#include <QByteArray>
#include <QJsonArray>
#include <QJsonObject>
using namespace KItinerary;
QJsonArray GenericVdvExtractor::extract(const QByteArray &data)
{
VdvTicketParser p;
if (!p.parse(data)) {
return {};
}
const auto vdv = p.ticket();
QJsonObject org;
org.insert(QStringLiteral("@type"), QLatin1String("Organization"));
org.insert(QStringLiteral("identifier"), QString(QLatin1String("vdv:") + QString::number(vdv.issuerId())));
QJsonObject trip;
trip.insert(QStringLiteral("@type"), QLatin1String("TrainTrip"));
trip.insert(QStringLiteral("provider"), org);
QJsonObject seat;
seat.insert(QStringLiteral("@type"), QLatin1String("Seat"));
// seat.insert(QStringLiteral("seatingType"), vdv.serviceClass());
QJsonObject ticket;
ticket.insert(QStringLiteral("@type"), QLatin1String("Ticket"));
ticket.insert(QStringLiteral("ticketToken"), QString(QLatin1String("aztecbin:") + QString::fromLatin1(data.toBase64())));
ticket.insert(QStringLiteral("ticketedSeat"), seat);
QJsonObject person;
person.insert(QStringLiteral("@type"), QLatin1String("Person"));
// person.insert(QStringLiteral("name"), vdv.passengerName());
QJsonObject res;
res.insert(QStringLiteral("@type"), QLatin1String("TrainReservation"));
res.insert(QStringLiteral("reservationFor"), trip);
// res.insert(QStringLiteral("reservationNumber"), vdv.ticketNumber());
res.insert(QStringLiteral("reservedTicket"), ticket);
res.insert(QStringLiteral("underName"), person);
return {res};
}
/*
Copyright (C) 2019 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef KITINERARY_GENERICVDVEXTRACTOR_P_H
#define KITINERARY_GENERICVDVEXTRACTOR_P_H
class QByteArray;
class QJsonArray;
namespace KItinerary {
/** Generic extractor for VDV tickets. */
namespace GenericVdvExtractor
{
QJsonArray extract(const QByteArray &data);
}
}
#endif // KITINERARY_GENERICVDVEXTRACTOR_P_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