Skip to content

Commit

Permalink
schematron: Move calculation of missing diagnostics to Java code
Browse files Browse the repository at this point in the history
Doing this in Drools causes very high memory usage (over 5GB) when run
on the SDK, probably because of the high number of asserts.
  • Loading branch information
bertrand-lorentz committed Aug 12, 2024
1 parent ec9288e commit dc1ae16
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ public List<String> 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<String> getMissingDiagnostics() {
Set<String> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit dc1ae16

Please sign in to comment.