#55 More robust reporting in case of Schematron Error

This commit is contained in:
Andreas Penski 2020-07-29 13:22:55 +00:00
parent cd061b22c0
commit 8fb1098925
9 changed files with 365 additions and 23 deletions

View file

@ -132,7 +132,7 @@ public class DefaultCheck implements Check {
result.setSchemaViolations(convertErrors(t.getSchemaValidationResult().getErrors()));
}
result.setProcessingSuccessful(!t.isStopped() && t.isFinished());
result.setSchematronResult(t.getReportInput().getValidationResultsSchematron().stream()
result.setSchematronResult(t.getReportInput().getValidationResultsSchematron().stream().filter(e -> e.getResults() != null)
.map(e -> e.getResults().getSchematronOutput()).collect(Collectors.toList()));
return result;
}

View file

@ -139,8 +139,13 @@ public class DefaultResult implements Result {
: Collections.emptyList();
}
private boolean isSchematronEvaluated() {
return getSchematronResult() != null
&& getSchematronResult().stream().noneMatch(e -> e.getActivePatternAndFiredRuleAndFailedAssert().isEmpty());
}
@Override
public boolean isSchematronValid() {
return getSchematronResult() != null && getFailedAsserts().isEmpty();
return isSchematronEvaluated() && getFailedAsserts().isEmpty();
}
}

View file

@ -24,6 +24,10 @@ public class ComputeAcceptanceAction implements CheckAction {
@Override
public void check(final Bag results) {
if (results.isStopped() && results.getParserResult().isValid()) {
// xml wurde aus irgendwelchen Gründen nicht korrekt verarbeitet, dann lassen wir es als undefined
return;
}
if (preCondtionsMatch(results)) {
final Optional<XPathSelector> acceptMatch = results.getScenarioSelectionResult().getObject().getAcceptSelector();
if (results.getSchemaValidationResult().isValid() && acceptMatch.isPresent()) {
@ -44,11 +48,11 @@ public class ComputeAcceptanceAction implements CheckAction {
}
}
private boolean isSchematronValid(final Bag results) {
private static boolean isSchematronValid(final Bag results) {
return !hasSchematronErrors(results);
}
private boolean hasSchematronErrors(final Bag results) {
private static boolean hasSchematronErrors(final Bag results) {
return results.getReportInput().getValidationResultsSchematron().stream().map(e -> e.getResults().getSchematronOutput())
.flatMap(e -> e.getActivePatternAndFiredRuleAndFailedAssert().stream()).anyMatch(FailedAssert.class::isInstance);
}

View file

@ -35,6 +35,7 @@ import de.kosit.validationtool.impl.ConversionService;
import de.kosit.validationtool.impl.Scenario;
import de.kosit.validationtool.model.reportInput.CreateReportInput;
import de.kosit.validationtool.model.reportInput.ValidationResultsSchematron;
import de.kosit.validationtool.model.reportInput.ValidationResultsSchematron.Results;
import net.sf.saxon.dom.NodeOverNodeInfo;
import net.sf.saxon.s9api.SaxonApiException;
@ -81,13 +82,21 @@ public class SchematronValidationAction implements CheckAction {
s.setResults(r);
} catch (final SaxonApiException e) {
final String msg = String.format("Error processing schematron validation %s", validation.getResourceType().getName());
final String msg = String.format("Error processing schematron validation %s. Error is %s",
validation.getResourceType().getName(), e.getMessage());
log.error(msg, e);
results.addProcessingError(msg);
s.setResults(createErrorResult());
}
return s;
}
private static Results createErrorResult() {
final Results r = new Results();
r.setSchematronOutput(new SchematronOutput());
return r;
}
@Override
public void check(final Bag results) {
final CreateReportInput report = results.getReportInput();