Commit 888733c7 authored by Volker Krause's avatar Volker Krause
Browse files

Make validation optional in post-processing

parent 62042e64
......@@ -110,15 +110,10 @@ void ExtractorPostprocessor::process(const QVector<QVariant> &data)
QVector<QVariant> ExtractorPostprocessor::result() const
{
if (!d->m_resultFinalized) {
for (auto it = d->m_data.begin(); it != d->m_data.end();) {
if (d->m_validator.isValidElement(*it)) {
++it;
} else {
//qCDebug(Log).noquote() << "Discarding element:" << QJsonDocument(JsonLdDocument::toJson({*it})).toJson();
it = d->m_data.erase(it);
}
}
if (!d->m_resultFinalized && d->m_validationEnabled) {
d->m_data.erase(std::remove_if(d->m_data.begin(), d->m_data.end(), [this](const auto &elem) {
return !d->m_validator.isValidElement(elem);
}), d->m_data.end());
d->m_resultFinalized = true;
}
......@@ -131,6 +126,11 @@ void ExtractorPostprocessor::setContextDate(const QDateTime& dt)
d->m_contextDate = dt;
}
void ExtractorPostprocessor::setValidationEnabled(bool validate)
{
d->m_validationEnabled = validate;
}
void ExtractorPostprocessorPrivate::mergeOrAppend(const QVariant &elem)
{
const auto it = std::find_if(m_data.begin(), m_data.end(), [elem](const QVariant &other) {
......
......@@ -94,6 +94,15 @@ public:
*/
void setContextDate(const QDateTime &dt);
/** Enable or disable validation.
* By default this is enabled, and will discard all unknown types
* and incomplete items. If you need more control over this, disable
* this here and pass the items through ExtractorValidator yourself
* (or even use an entirely different validation mechanism entirely).
* @see ExtractorValidator.
*/
void setValidationEnabled(bool validate);
private:
std::unique_ptr<ExtractorPostprocessorPrivate> d;
};
......
......@@ -83,6 +83,7 @@ public:
QDateTime m_contextDate;
ExtractorValidator m_validator;
bool m_resultFinalized = false;
bool m_validationEnabled = true;
};
template<typename T> inline T ExtractorPostprocessorPrivate::processPlace(T place)
......
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