Skip to content

Commit 8075c5b

Browse files
authored
Merge pull request #222 from bci-oss/221-validate-models-with-multiple-aspects
Successfully validate RDF models containing multiple Aspects
2 parents 665ec18 + 7e08571 commit 8075c5b

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

core/sds-aspect-model-validator/src/main/java/io/openmanufacturing/sds/aspectmodel/validation/services/AspectModelValidator.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import io.openmanufacturing.sds.aspectmetamodel.KnownVersion;
4444
import io.openmanufacturing.sds.aspectmodel.UnsupportedVersionException;
4545
import io.openmanufacturing.sds.aspectmodel.resolver.ModelResolutionException;
46+
import io.openmanufacturing.sds.aspectmodel.resolver.exceptions.InvalidRootElementCountException;
4647
import io.openmanufacturing.sds.aspectmodel.resolver.exceptions.InvalidVersionException;
4748
import io.openmanufacturing.sds.aspectmodel.resolver.services.SdsAspectMetaModelResourceResolver;
4849
import io.openmanufacturing.sds.aspectmodel.resolver.services.VersionedModel;
@@ -130,14 +131,14 @@ public ValidationReport validate( final Try<VersionedModel> versionedModel ) {
130131
if ( report.getProperty( SH.conforms ).getObject().asLiteral().getBoolean() ) {
131132
// The SHACL validation succeeded. But to catch false positives, also try to load the model
132133
final Try<Aspect> aspects = AspectModelLoader.fromVersionedModel( model );
133-
if ( aspects.isFailure() ) {
134+
if ( aspects.isFailure() && !(aspects.getCause() instanceof InvalidRootElementCountException) ) {
134135
return new ValidationReportBuilder()
135136
.withValidationErrors( List.of( new ValidationError.Processing(
136-
"Validation succeeded, but an error was found while processing the model. "
137-
+ "This indicates an error in the model validation; please consider reporting this issue including the model "
138-
+ "at https://github.com/OpenManufacturingPlatform/sds-bamm-aspect-meta-model/issues -- "
139-
+ buildCauseMessage( aspects.getCause() ) ) ) )
140-
.buildInvalidReport();
137+
"Validation succeeded, but an error was found while processing the model. "
138+
+ "This indicates an error in the model validation; please consider reporting this issue including the model "
139+
+ "at https://github.com/OpenManufacturingPlatform/sds-bamm-aspect-meta-model/issues -- "
140+
+ buildCauseMessage( aspects.getCause() ) ) ) )
141+
.buildInvalidReport();
141142
}
142143
return new ValidationReportBuilder().buildValidReport();
143144
}

core/sds-aspect-model-validator/src/test/java/io/openmanufacturing/sds/aspectmodel/validation/services/AspectModelValidatorTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,4 +312,21 @@ public Void visit( final ValidationError.Processing error ) {
312312
}
313313
} );
314314
}
315+
316+
@ParameterizedTest
317+
@MethodSource( value = "allVersions" )
318+
public void testValidationWithMultipleAspects( final KnownVersion metaModelVersion ) {
319+
final Try<VersionedModel> model = TestResources.getModel( TestAspect.ASPECT, metaModelVersion );
320+
model.forEach( versionedModel -> {
321+
final VersionedModel model2 = TestResources.getModel( TestAspect.ASPECT_WITH_SIMPLE_TYPES, metaModelVersion ).get();
322+
versionedModel.getModel().add( model2.getRawModel() );
323+
versionedModel.getRawModel().add( model2.getRawModel() );
324+
} );
325+
326+
final ValidationReport report = service.validate( model );
327+
if ( !report.conforms() ) {
328+
report.getValidationErrors().forEach( System.out::println );
329+
}
330+
assertThat( report.conforms() ).isTrue();
331+
}
315332
}

0 commit comments

Comments
 (0)