Skip to content

Commit 7fcbc91

Browse files
committed
Fix bamm-cli validation problem.
1 parent a65434b commit 7fcbc91

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

tools/bamm-cli/src/main/java/io/openmanufacturing/sds/AbstractCommand.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,26 @@
4747
public abstract class AbstractCommand implements Runnable {
4848
protected static final Logger LOG = LoggerFactory.getLogger( AbstractCommand.class );
4949

50-
protected Try<AspectContext> loadAndResolveModel( final File input, final ExternalResolverMixin resolverConfig ) {
50+
protected Try<VersionedModel> loadAndResolveModel( final File input, final ExternalResolverMixin resolverConfig ) {
5151
final Try<VersionedModel> versionedModel;
5252
if ( resolverConfig.commandLine.isBlank() ) {
5353
versionedModel = AspectModelResolver.loadAndResolveModel( input );
5454
} else {
5555
final AspectModelUrn urn = fileToUrn( input.getAbsoluteFile() );
5656
versionedModel = new AspectModelResolver().resolveAspectModel( new ExternalResolverStrategy( resolverConfig.commandLine ), urn );
5757
}
58-
return versionedModel.flatMap( model -> {
59-
final AspectModelUrn urn = fileToUrn( input.getAbsoluteFile() );
60-
return AspectModelLoader.getSingleAspect( model, aspect -> aspect.getName().equals( urn.getName() ) )
61-
.map( aspect -> new AspectContext( model, aspect ) );
62-
} );
58+
return versionedModel;
6359
}
6460

6561
protected AspectContext loadModelOrFail( final String modelFileName, final ExternalResolverMixin resolverConfig ) {
6662
final File inputFile = new File( modelFileName );
67-
final Try<AspectContext> context = loadAndResolveModel( inputFile, resolverConfig );
63+
final Try<VersionedModel> versionedModel = loadAndResolveModel( inputFile, resolverConfig );
64+
final Try<AspectContext> context = versionedModel.flatMap( model -> {
65+
final AspectModelUrn urn = fileToUrn( inputFile.getAbsoluteFile() );
66+
return AspectModelLoader.getSingleAspect( model, aspect -> aspect.getName().equals( urn.getName() ) )
67+
.map( aspect -> new AspectContext( model, aspect ) );
68+
} );
69+
6870
return context.recover( throwable -> {
6971
// Model can not be loaded, root cause e.g. File not found
7072
if ( throwable instanceof IllegalArgumentException ) {

tools/bamm-cli/src/main/java/io/openmanufacturing/sds/aspect/AspectValidateCommand.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import io.openmanufacturing.sds.aspectmodel.validation.services.AspectModelValidator;
2424
import io.openmanufacturing.sds.aspectmodel.validation.services.DetailedViolationFormatter;
2525
import io.openmanufacturing.sds.aspectmodel.validation.services.ViolationFormatter;
26-
import io.openmanufacturing.sds.metamodel.AspectContext;
2726
import io.vavr.control.Try;
2827
import picocli.CommandLine;
2928

@@ -50,7 +49,7 @@ public class AspectValidateCommand extends AbstractCommand {
5049

5150
@Override
5251
public void run() {
53-
final Try<VersionedModel> versionedModel = loadAndResolveModel( new File( parentCommand.getInput() ), customResolver ).map( AspectContext::rdfModel );
52+
final Try<VersionedModel> versionedModel = loadAndResolveModel( new File( parentCommand.getInput() ), customResolver );
5453
final AspectModelValidator validator = new AspectModelValidator();
5554

5655
final List<Violation> violations = validator.validateModel( versionedModel );

0 commit comments

Comments
 (0)