diff --git a/src/main/java/eu/europa/ted/eforms/sdk/analysis/fact/SchematronFileFact.java b/src/main/java/eu/europa/ted/eforms/sdk/analysis/fact/SchematronFileFact.java index 76be4ad..97140a7 100644 --- a/src/main/java/eu/europa/ted/eforms/sdk/analysis/fact/SchematronFileFact.java +++ b/src/main/java/eu/europa/ted/eforms/sdk/analysis/fact/SchematronFileFact.java @@ -46,6 +46,23 @@ public List getDuplicateAssertIds() { .collect(Collectors.toList()); } + /** + * Returns the list of diagnostic identifiers that are referenced in an assert but not defined by + * a diagnostic element. + * + * @return List of diagnostic identifiers missing a definition. + */ + public List getMissingDiagnostics() { + Set definedDiagnosticIds = getDiagnostics().stream() + .map(SchematronDiagnostic::getId) + .collect(Collectors.toSet()); + + return getAsserts().stream() + .map(SchematronAssert::getDiagnostics) + .filter(id -> !definedDiagnosticIds.contains(id)) + .collect(Collectors.toList()); + } + @Override public String getId() { return schematronFile.getPath().toString(); diff --git a/src/main/resources/eu/europa/ted/eforms/sdk/analysis/drools/schematronRules.drl b/src/main/resources/eu/europa/ted/eforms/sdk/analysis/drools/schematronRules.drl index 900e180..47d4c54 100644 --- a/src/main/resources/eu/europa/ted/eforms/sdk/analysis/drools/schematronRules.drl +++ b/src/main/resources/eu/europa/ted/eforms/sdk/analysis/drools/schematronRules.drl @@ -35,8 +35,7 @@ end rule "Every assert diagnostics is defined in the schematron file" when - /schematrons[ $sch: this, $schId: id ]/asserts[ $diagnosticId: diagnostics, diagnostics != null ] - not (exists /schematrons[ id == $schId ]/diagnostics[ id == $diagnosticId ]) + $missing : /schematrons[ $sch: this]/missingDiagnostics then - results.add(new ValidationResult($sch, "Schematron is missing diagnostic definitions for: " + $diagnosticId, ValidationStatusEnum.ERROR)); + results.add(new ValidationResult($sch, "Schematron is missing diagnostic definitions for: " + $missing, ValidationStatusEnum.ERROR)); end