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

Provide a way to have minimal cancellation elements pass validation

parent 18ca5d39
......@@ -49,9 +49,11 @@ private Q_SLOTS:
input = JsonLdDocument::fromJson(QJsonDocument::fromJson(readFile(SOURCE_DIR "/mergedata/cancellation.rhs.json")).array());
QCOMPARE(input.size(), 1);
QEXPECT_FAIL("", "not implemented yet", Continue);
QVERIFY(!v.isValidElement(input.at(0)));
v.setAcceptOnlyCompleteElements(false);
QVERIFY(v.isValidElement(input.at(0)));
v.setAcceptOnlyCompleteElements(true);
v.setAcceptedTypes<FlightReservation, TrainReservation>();
input = JsonLdDocument::fromJson(QJsonDocument::fromJson(readFile(SOURCE_DIR "/mergedata/cancellation.lhs.json")).array());
QCOMPARE(input.size(), 1);
......
......@@ -49,6 +49,7 @@ public:
bool filterReservation(const Reservation &res) const;
std::vector<const QMetaObject*> m_acceptedTypes;
bool m_onlyComplete = true;
};
}
......@@ -63,6 +64,12 @@ void ExtractorValidator::setAcceptedTypes(std::vector<const QMetaObject*> &&accp
d->m_acceptedTypes = std::move(accptedTypes);
}
void ExtractorValidator::setAcceptOnlyCompleteElements(bool completeOnly)
{
d->m_onlyComplete = completeOnly;
}
bool ExtractorValidatorPrivate::filterLodgingReservation(const LodgingReservation &res) const
{
return res.checkinTime().isValid() && res.checkoutTime().isValid() && res.checkinTime() <= res.checkoutTime();
......@@ -119,6 +126,16 @@ bool ExtractorValidatorPrivate::filterLocalBusiness(const LocalBusiness &busines
bool ExtractorValidatorPrivate::filterReservation(const Reservation &res) const
{
if (!m_onlyComplete) { // accept minimal cancellation elements
if (res.reservationFor().isNull()
&& res.modifiedTime().isValid()
&& !res.reservationNumber().isEmpty()
&& res.reservationStatus() == Reservation::ReservationCancelled)
{
return true;
}
}
if (!filterElement(res.reservationFor())) {
qCDebug(ValidatorLog) << "Reservation element discarded due to rejected reservationFor property:" << res.reservationFor().typeName();
return false;
......
......@@ -60,6 +60,15 @@ public:
setAcceptedTypes({&Args::staticMetaObject...});
}
/** Configure whether or not to accept also incomplete elements.
* The default is @c true.
* Accepting incomplete elements is useful if the output is
* further processed, for example to merge minimal cancellation
* elements with already existing data. If the output is displayed
* directly, set this to @c true.
*/
void setAcceptOnlyCompleteElements(bool completeOnly);
private:
std::unique_ptr<ExtractorValidatorPrivate> d;
};
......
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