Skip to content

Commit ccc5b46

Browse files
authored
Merge pull request #252 from bci-oss/251-aspectmodelresolver-allow-multiple-urns
Allow resolution of multiple elements at once in AspectModelResolver
2 parents 646aa93 + de6cb14 commit ccc5b46

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.io.FileNotFoundException;
1717
import java.util.Collections;
1818
import java.util.HashSet;
19+
import java.util.List;
1920
import java.util.Map;
2021
import java.util.Set;
2122
import java.util.Stack;
@@ -97,7 +98,19 @@ private static Try<String> resolveBammUrn( final String urn ) {
9798
* @return The resolved model on success
9899
*/
99100
public Try<VersionedModel> resolveAspectModel( final ResolutionStrategy resolver, final AspectModelUrn input ) {
100-
final Try<Model> mergedModel = resolve( input.toString(), resolver );
101+
return resolveAspectModel( resolver, List.of( input ) );
102+
}
103+
104+
/**
105+
* Method to resolve multiple {@link AspectModelUrn}s using a suitable {@link ResolutionStrategy}.
106+
* This creates the closure (merged model) of all referenced models and the corresponding meta model.
107+
*
108+
* @param resolver The strategy to resolve input URNs to RDF models
109+
* @param input The input to be resolved by the strategy
110+
* @return The resolved model on success
111+
*/
112+
public Try<VersionedModel> resolveAspectModel( final ResolutionStrategy resolver, final List<AspectModelUrn> input ) {
113+
final Try<Model> mergedModel = resolve( input.stream().map( AspectModelUrn::toString ).toList(), resolver );
101114

102115
if ( mergedModel.isFailure() ) {
103116
if ( mergedModel.getCause() instanceof FileNotFoundException ) {
@@ -151,18 +164,20 @@ public static boolean containsDefinition( final Model model, final AspectModelUr
151164
}
152165

153166
/**
154-
* The main model resolution method that takes an Aspect Model element URN and a resolution strategy as input.
155-
* The strategy is applied to the URN to load a model, and then repeated for all URNs in the loaded model that
167+
* The main model resolution method that takes Aspect Model element URNs and a resolution strategy as input.
168+
* The strategy is applied to the URNs to load a model, and then repeated for all URNs in the loaded model that
156169
* have not yet been loaded.
157-
* @param urn the Aspect Model element URN
170+
* @param urns the Aspect Model element URNs
158171
* @param resolutionStrategy the resolution strategy that knowns how to turn a URN into a Model
159172
* @return the fully resolved model, or a failure if one of the transitively referenced elements can't be found
160173
*/
161-
private Try<Model> resolve( final String urn, final ResolutionStrategy resolutionStrategy ) {
174+
private Try<Model> resolve( final List<String> urns, final ResolutionStrategy resolutionStrategy ) {
162175
final Model result = ModelFactory.createDefaultModel();
163176
final Stack<String> unresolvedUrns = new Stack<>();
164177
final Set<Model> mergedModels = new HashSet<>();
165-
unresolvedUrns.push( urn );
178+
for ( final String urn : urns ) {
179+
unresolvedUrns.push( urn );
180+
}
166181

167182
while ( !unresolvedUrns.isEmpty() ) {
168183
final String urnToResolve = unresolvedUrns.pop();

0 commit comments

Comments
 (0)