Commit 470feea2 authored by Volker Krause's avatar Volker Krause
Browse files

Allow to also import health certificates from PDFs

parent 3092eeb3
......@@ -22,6 +22,8 @@
#include <KItinerary/CreativeWork>
#include <KItinerary/DocumentUtil>
#include <KItinerary/ExtractorCapabilities>
#include <KItinerary/ExtractorEngine>
#include <KItinerary/ExtractorDocumentNode>
#include <KItinerary/File>
#include <KItinerary/JsonLdDocument>
......@@ -330,7 +332,7 @@ void ApplicationController::importLocalFile(const QUrl &url)
}
} else {
const auto data = f.readAll();
const auto resIds = m_resMgr->importReservation(data, f.fileName());
const auto resIds = importReservationOrHealthCertificate(data, f.fileName());
if (resIds.empty()) {
return;
}
......@@ -368,7 +370,7 @@ void ApplicationController::importData(const QByteArray &data)
importBundle(data);
}
} else {
m_resMgr->importReservation(data);
importReservationOrHealthCertificate(data);
}
}
......@@ -492,6 +494,40 @@ void ApplicationController::importBundle(KItinerary::File *file)
}
}
QVector<QString> ApplicationController::importReservationOrHealthCertificate(const QByteArray &data, const QString &fileName)
{
using namespace KItinerary;
ExtractorEngine engine;
engine.setContextDate(QDateTime(QDate::currentDate(), QTime(0, 0)));
engine.setData(data, fileName);
const auto resIds = m_resMgr->importReservations(JsonLdDocument::fromJson(engine.extract()));
if (!resIds.isEmpty()) {
return resIds;
}
// look for health certificate barcodes instead
importHealthCertificateRecursive(engine.rootDocumentNode());
return {};
}
void ApplicationController::importHealthCertificateRecursive(const ExtractorDocumentNode &node)
{
if (node.childNodes().size() == 1 && node.mimeType() == QLatin1String("internal/qimage")) {
const auto &child = node.childNodes()[0];
if (child.isA<QString>()) {
return m_healthCertMgr->importCertificate(child.content<QString>().toUtf8());
}
if (child.isA<QByteArray>()) {
return m_healthCertMgr->importCertificate(child.content<QByteArray>());
}
}
for (const auto &child : node.childNodes()) {
importHealthCertificateRecursive(child);
}
}
void ApplicationController::addDocument(const QString &batchId, const QUrl &url)
{
if (!url.isValid()) {
......
......@@ -19,6 +19,7 @@ class TransferManager;
class TripGroupManager;
namespace KItinerary {
class ExtractorDocumentNode;
class File;
}
......@@ -81,6 +82,8 @@ Q_SIGNALS:
private:
void importLocalFile(const QUrl &url);
void importBundle(KItinerary::File *file);
QVector<QString> importReservationOrHealthCertificate(const QByteArray &data, const QString &fileName = {});
void importHealthCertificateRecursive(const KItinerary::ExtractorDocumentNode &node);
static ApplicationController *s_instance;
......
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