37
37
import io .openmanufacturing .sds .aspectmodel .resolver .services .VersionedModel ;
38
38
import io .openmanufacturing .sds .aspectmodel .urn .AspectModelUrn ;
39
39
import io .openmanufacturing .sds .aspectmodel .urn .ElementType ;
40
+ import io .openmanufacturing .sds .aspectmodel .urn .UrnSyntaxException ;
40
41
import io .openmanufacturing .sds .aspectmodel .versionupdate .MigratorFactory ;
41
42
import io .openmanufacturing .sds .aspectmodel .versionupdate .MigratorService ;
42
43
import io .openmanufacturing .sds .aspectmodel .versionupdate .MigratorServiceLoader ;
@@ -170,16 +171,22 @@ private Try<Model> getModelForUrn( final String urn, final ResolutionStrategy re
170
171
return Try .success ( EMPTY_MODEL );
171
172
}
172
173
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
175
188
return Try .success ( EMPTY_MODEL );
176
189
}
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
- } );
183
190
}
184
191
185
192
private void mergeModels ( final Model target , final Model other ) {
@@ -193,10 +200,15 @@ private void mergeModels( final Model target, final Model other ) {
193
200
final Statement statement = it .next ();
194
201
195
202
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
197
204
if ( statement .getObject ().isLiteral () && !statement .getLiteral ().getLanguage ().isEmpty () ) {
198
205
target .add ( statement );
199
206
}
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
+ }
200
212
} else {
201
213
target .add ( statement );
202
214
}
0 commit comments