3535import org .eclipse .rdf4j .rio .Rio ;
3636import org .eclipse .rdf4j .rio .WriterConfig ;
3737import org .eclipse .rdf4j .rio .helpers .BasicWriterSettings ;
38+ import org .eclipse .rdf4j .sail .shacl .ShaclSailConnection ;
3839import org .eclipse .rdf4j .sail .shacl .results .ValidationReport ;
3940import org .eclipse .rdf4j .sail .shacl .results .ValidationResult ;
41+ import org .slf4j .Logger ;
42+ import org .slf4j .LoggerFactory ;
4043
4144/**
4245 * A ValidationReport that will defer calculating any ValidationResults until the user asks for them
4346 */
4447@ InternalUseOnly
4548public class LazyValidationReport extends ValidationReport {
4649
50+ private static final Logger logger = LoggerFactory .getLogger (LazyValidationReport .class );
51+
4752 private List <ValidationResultIterator > validationResultIterators ;
4853 private final long limit ;
4954
@@ -55,44 +60,55 @@ public LazyValidationReport(List<ValidationResultIterator> validationResultItera
5560 }
5661
5762 private void evaluateLazyAspect () {
58- if (validationResultIterators != null ) {
59- long counter = 0 ;
60- for (ValidationResultIterator validationResultIterator : validationResultIterators ) {
61- while (validationResultIterator .hasNext ()) {
62- if (limit >= 0 && counter >= limit ) {
63- truncated = true ;
64- break ;
63+ try {
64+ if (validationResultIterators != null ) {
65+ long counter = 0 ;
66+ for (ValidationResultIterator validationResultIterator : validationResultIterators ) {
67+ while (validationResultIterator .hasNext ()) {
68+ if (limit >= 0 && counter >= limit ) {
69+ truncated = true ;
70+ break ;
71+ }
72+ counter ++;
73+
74+ validationResult .add (validationResultIterator .next ());
6575 }
66- counter ++;
6776
68- validationResult .add (validationResultIterator .next ());
77+ this .conforms = conforms && validationResultIterator .conforms ();
78+ this .truncated = truncated || validationResultIterator .isTruncated ();
6979 }
7080
71- this .conforms = conforms && validationResultIterator .conforms ();
72- this .truncated = truncated || validationResultIterator .isTruncated ();
73- }
74-
75- validationResultIterators = null ;
81+ validationResultIterators = null ;
7682
83+ }
84+ } catch (Exception e ) {
85+ logger .warn ("Error evaluating lazy validation report" , e );
86+ throw e ;
7787 }
7888
7989 }
8090
8191 public Model asModel (Model model ) {
82- evaluateLazyAspect ();
92+ try {
93+ evaluateLazyAspect ();
94+
95+ model .add (getId (), SHACL .CONFORMS , literal (conforms ));
96+ model .add (getId (), RDF .TYPE , SHACL .VALIDATION_REPORT );
97+ model .add (getId (), RDF4J .TRUNCATED , BooleanLiteral .valueOf (truncated ));
8398
84- model .add (getId (), SHACL .CONFORMS , literal (conforms ));
85- model .add (getId (), RDF .TYPE , SHACL .VALIDATION_REPORT );
86- model .add (getId (), RDF4J .TRUNCATED , BooleanLiteral .valueOf (truncated ));
99+ HashSet <Resource > rdfListDedupe = new HashSet <>();
87100
88- HashSet <Resource > rdfListDedupe = new HashSet <>();
101+ for (ValidationResult result : validationResult ) {
102+ model .add (getId (), SHACL .RESULT , result .getId ());
103+ result .asModel (model , rdfListDedupe );
104+ }
89105
90- for (ValidationResult result : validationResult ) {
91- model .add (getId (), SHACL .RESULT , result .getId ());
92- result .asModel (model , rdfListDedupe );
106+ return model ;
107+ } catch (Exception e ) {
108+ logger .warn ("Error converting validation report to model" , e );
109+ throw e ;
93110 }
94111
95- return model ;
96112 }
97113
98114 public Model asModel () {
0 commit comments