From dc1ae1664e835073ad7f046d935053f5cd9f4fe6 Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Mon, 12 Aug 2024 10:35:09 +0200 Subject: [PATCH] schematron: Move calculation of missing diagnostics to Java code Doing this in Drools causes very high memory usage (over 5GB) when run on the SDK, probably because of the high number of asserts. --- .../sdk/analysis/fact/SchematronFileFact.java | 17 +++++++++++++++++ .../sdk/analysis/drools/schematronRules.drl | 5 ++--- 2 files changed, 19 insertions(+), 3 deletions(-) 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