Skip to content

Commit dde377f

Browse files
committed
Add correct handling of repeated properties in resolver
1 parent 65b1fae commit dde377f

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

core/sds-aspect-model-resolver/src/main/java/io/openmanufacturing/sds/aspectmodel/resolver/AspectModelResolver.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import io.openmanufacturing.sds.aspectmodel.resolver.services.VersionedModel;
3838
import io.openmanufacturing.sds.aspectmodel.urn.AspectModelUrn;
3939
import io.openmanufacturing.sds.aspectmodel.urn.ElementType;
40+
import io.openmanufacturing.sds.aspectmodel.urn.UrnSyntaxException;
4041
import io.openmanufacturing.sds.aspectmodel.versionupdate.MigratorFactory;
4142
import io.openmanufacturing.sds.aspectmodel.versionupdate.MigratorService;
4243
import io.openmanufacturing.sds.aspectmodel.versionupdate.MigratorServiceLoader;
@@ -170,16 +171,22 @@ private Try<Model> getModelForUrn( final String urn, final ResolutionStrategy re
170171
return Try.success( EMPTY_MODEL );
171172
}
172173

173-
final AspectModelUrn aspectModelUrn = AspectModelUrn.fromUrn( urn );
174-
if ( aspectModelUrn.getElementType() != ElementType.NONE ) {
174+
try {
175+
final AspectModelUrn aspectModelUrn = AspectModelUrn.fromUrn( urn );
176+
if ( aspectModelUrn.getElementType() != ElementType.NONE ) {
177+
return Try.success( EMPTY_MODEL );
178+
}
179+
return resolutionStrategy.apply( aspectModelUrn ).flatMap( model -> {
180+
if ( !model.contains( model.createResource( urn ), RDF.type, (RDFNode) null ) ) {
181+
return Try.failure( new ModelResolutionException( "Resolution strategy returned a model which does contain element definition for " + urn ) );
182+
}
183+
return Try.success( model );
184+
} );
185+
} catch ( final UrnSyntaxException e ) {
186+
// If it's no valid Aspect Model URN but some other URI (e.g., a bamm:see value), there is nothing
187+
// to resolve, so we return just an empty model
175188
return Try.success( EMPTY_MODEL );
176189
}
177-
return resolutionStrategy.apply( aspectModelUrn ).flatMap( model -> {
178-
if ( !model.contains( model.createResource( urn ), RDF.type, (RDFNode) null ) ) {
179-
return Try.failure( new ModelResolutionException( "Resolution strategy returned a model which does contain element definition for " + urn ) );
180-
}
181-
return Try.success( model );
182-
} );
183190
}
184191

185192
private void mergeModels( final Model target, final Model other ) {
@@ -193,10 +200,15 @@ private void mergeModels( final Model target, final Model other ) {
193200
final Statement statement = it.next();
194201

195202
if ( target.contains( statement.getSubject(), statement.getPredicate(), (RDFNode) null ) ) {
196-
// Only add the assertion that is already present in the target model if the value is a language string
203+
// If the value is a language string, add the additional assertion
197204
if ( statement.getObject().isLiteral() && !statement.getLiteral().getLanguage().isEmpty() ) {
198205
target.add( statement );
199206
}
207+
// If the value is a named resource, also add the additional assertion. This for example
208+
// is the case with multiple bamm:see assertions
209+
if ( statement.getObject().isResource() && statement.getResource().isURIResource() ) {
210+
target.add( statement );
211+
}
200212
} else {
201213
target.add( statement );
202214
}

0 commit comments

Comments
 (0)