Skip to content

Commit a381917

Browse files
committed
Improve aspect model file filtering logic
Updated the filtering logic in ModelService to better identify aspect model files by checking for DefaultScalarValue types and their associated types, in addition to matching URNs. Also performed minor formatting and code cleanup for readability.
1 parent ba03594 commit a381917

File tree

1 file changed

+11
-15
lines changed
  • aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services

1 file changed

+11
-15
lines changed

aspect-model-editor-service/src/main/java/org/eclipse/esmf/ame/services/ModelService.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn;
4848
import org.eclipse.esmf.aspectmodel.validation.services.AspectModelValidator;
4949
import org.eclipse.esmf.metamodel.AspectModel;
50+
import org.eclipse.esmf.metamodel.impl.DefaultScalar;
51+
import org.eclipse.esmf.metamodel.impl.DefaultScalarValue;
5052
import org.eclipse.esmf.samm.KnownVersion;
5153

5254
import io.micronaut.http.multipart.CompletedFileUpload;
@@ -82,11 +84,10 @@ public AspectModelResult getModel( final AspectModelUrn aspectModelUrn, final St
8284
loadModelFromUrn( aspectModelUrn );
8385
validateModel( aspectModel );
8486

85-
return aspectModel.files().stream()
86-
.filter( a -> a.elements().stream().anyMatch( e -> e.urn().equals( aspectModelUrn ) ) )
87-
.findFirst()
88-
.map( aspectModelFile -> new AspectModelResult(
89-
aspectModelFile.filename(),
87+
return aspectModel.files().stream().filter( a -> a.elements().stream().anyMatch(
88+
e -> ( e instanceof DefaultScalarValue && ( (DefaultScalarValue) e ).getType()
89+
.equals( new DefaultScalar( aspectModelUrn.toString() ) ) ) || e.urn().equals( aspectModelUrn ) ) ).findFirst()
90+
.map( aspectModelFile -> new AspectModelResult( aspectModelFile.filename(),
9091
AspectSerializer.INSTANCE.aspectModelFileToString( aspectModelFile ) ) )
9192
.orElseThrow( () -> new FileNotFoundException( "Aspect Model not found" ) );
9293
} catch ( final ModelResolutionException e ) {
@@ -126,11 +127,8 @@ public void createOrSaveModel( final String turtleData, final AspectModelUrn asp
126127
ModelUtils.createFile( newFile );
127128

128129
final AspectModelFile createdFile = aspectModelSupplier.get().files().stream()
129-
.filter( aspectModelFile -> aspectModelFile.sourceLocation()
130-
.map( src -> src.equals( newFile.toUri() ) )
131-
.orElse( false ) )
132-
.findFirst()
133-
.orElseThrow( () -> new FileNotFoundException( "Created aspect model file not found: " + newFile ) );
130+
.filter( aspectModelFile -> aspectModelFile.sourceLocation().map( src -> src.equals( newFile.toUri() ) ).orElse( false ) )
131+
.findFirst().orElseThrow( () -> new FileNotFoundException( "Created aspect model file not found: " + newFile ) );
134132

135133
AspectSerializer.INSTANCE.write( createdFile );
136134
} catch ( final IOException e ) {
@@ -184,9 +182,8 @@ public MigrationResult migrateWorkspace( final boolean setNewVersion, final Path
184182
final List<String> errors = new ArrayList<>();
185183

186184
try {
187-
getAllNamespaces( false ).forEach(
188-
( namespace, versions ) -> versions.forEach(
189-
version -> processVersion( namespace, version, setNewVersion, errors, metaModelStoragePath ) ) );
185+
getAllNamespaces( false ).forEach( ( namespace, versions ) -> versions.forEach(
186+
version -> processVersion( namespace, version, setNewVersion, errors, metaModelStoragePath ) ) );
190187
return new MigrationResult( true, errors );
191188
} catch ( final Exception e ) {
192189
errors.add( e.getMessage() );
@@ -244,8 +241,7 @@ private void applyNamespaceVersionChange( final AspectModel aspectModel, final L
244241
}
245242

246243
ModelUtils.createFile( updatedFile.namespaceUrn(),
247-
updatedFile.filename().orElseThrow( () -> new FileHandlingException( "Filename missing" ) ),
248-
metaModelStoragePath );
244+
updatedFile.filename().orElseThrow( () -> new FileHandlingException( "Filename missing" ) ), metaModelStoragePath );
249245

250246
AspectSerializer.INSTANCE.write( updatedFile );
251247
} catch ( final IOException e ) {

0 commit comments

Comments
 (0)