Skip to content

Commit c057ac6

Browse files
authored
Fix/performance issues (#92)
* Add batch model retrieval and file info classes Introduces FileEntry and FileInformation classes for batch operations. Adds a new endpoint to ModelController for retrieving multiple aspect models in a single request. Updates ModelService to return filename and model content as a tuple, and refactors related test and service logic for improved error handling and data structure support. * Refactor model classes to use Java records Converted model classes (FileEntry, FileInformation, MigrationResult, Model, Version) to Java records for improved immutability and conciseness. Added AspectModelResult record. Updated ModelService and ModelController to use new record types and adjusted method signatures and usages accordingly. Minor dependency update in pom.xml for @usebruno/cli. * Update ModelServiceTest.java
1 parent 0c83223 commit c057ac6

File tree

12 files changed

+207
-129
lines changed

12 files changed

+207
-129
lines changed

aspect-model-editor-runtime/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@
446446
</goals>
447447
<configuration>
448448
<workingDirectory>${project.build.directory}</workingDirectory>
449-
<arguments>install . @usebruno/cli</arguments>
449+
<arguments>install --ignore-scripts . @usebruno/cli@2.15.0</arguments>
450450
</configuration>
451451
</execution>
452452
</executions>

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.eclipse.esmf.ame.exceptions.FileNotFoundException;
2828
import org.eclipse.esmf.ame.exceptions.FileReadException;
2929
import org.eclipse.esmf.ame.exceptions.InvalidAspectModelException;
30+
import org.eclipse.esmf.ame.services.models.AspectModelResult;
3031
import org.eclipse.esmf.ame.services.models.MigrationResult;
3132
import org.eclipse.esmf.ame.services.models.Version;
3233
import org.eclipse.esmf.ame.services.utils.ModelGroupingUtils;
@@ -74,15 +75,19 @@ public ModelService( final AspectModelValidator aspectModelValidator, final Aspe
7475
this.modelPath = modelPath;
7576
}
7677

77-
public String getModel( final AspectModelUrn aspectModelUrn, final String filePath ) {
78+
public AspectModelResult getModel( final AspectModelUrn aspectModelUrn, final String filePath ) {
7879
try {
7980
final AspectModel aspectModel = ( filePath != null ) ?
8081
ModelUtils.loadModelFromFile( modelPath, filePath, aspectModelLoader ) :
8182
loadModelFromUrn( aspectModelUrn );
8283
validateModel( aspectModel );
8384

84-
return aspectModel.files().stream().filter( a -> a.elements().stream().anyMatch( e -> e.urn().equals( aspectModelUrn ) ) )
85-
.findFirst().map( AspectSerializer.INSTANCE::aspectModelFileToString )
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(),
90+
AspectSerializer.INSTANCE.aspectModelFileToString( aspectModelFile ) ) )
8691
.orElseThrow( () -> new FileNotFoundException( "Aspect Model not found" ) );
8792
} catch ( final ModelResolutionException e ) {
8893
throw new FileNotFoundException( e.getMessage(), e );
@@ -191,16 +196,16 @@ public MigrationResult migrateWorkspace( final boolean setNewVersion, final Path
191196

192197
private void processVersion( final String namespace, final Version version, final boolean setNewVersion, final List<String> errors,
193198
final Path metaModelStoragePath ) {
194-
version.getModels().forEach( model -> {
199+
version.models().forEach( model -> {
195200
try {
196-
final boolean isNotLatestKnownVersion = KnownVersion.fromVersionString( model.getVersion() )
201+
final boolean isNotLatestKnownVersion = KnownVersion.fromVersionString( model.version() )
197202
.filter( v -> KnownVersion.getLatest().equals( v ) ).isPresent();
198203

199204
if ( isNotLatestKnownVersion ) {
200205
return;
201206
}
202207

203-
final Path aspectModelPath = ModelUtils.constructModelPath( modelPath, namespace, version.getVersion(), model.getModel() );
208+
final Path aspectModelPath = ModelUtils.constructModelPath( modelPath, namespace, version.version(), model.model() );
204209
final AspectModel aspectModel = aspectModelLoader.load( aspectModelPath.toFile() );
205210

206211
if ( setNewVersion ) {
@@ -210,7 +215,7 @@ private void processVersion( final String namespace, final Version version, fina
210215

211216
AspectSerializer.INSTANCE.write( aspectModel );
212217
} catch ( final Exception e ) {
213-
errors.add( String.format( "Error processing model: %s", model.getModel() ) );
218+
errors.add( String.format( "Error processing model: %s", model.model() ) );
214219
}
215220
} );
216221
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.zip.ZipOutputStream;
3131

3232
import org.eclipse.esmf.ame.exceptions.CreateFileException;
33+
import org.eclipse.esmf.ame.exceptions.FileHandlingException;
3334
import org.eclipse.esmf.ame.exceptions.FileNotFoundException;
3435
import org.eclipse.esmf.ame.services.models.Version;
3536
import org.eclipse.esmf.ame.services.utils.ModelGroupingUtils;
@@ -43,7 +44,6 @@
4344
import org.eclipse.esmf.aspectmodel.generator.zip.AspectModelNamespacePackageCreator;
4445
import org.eclipse.esmf.aspectmodel.loader.AspectModelLoader;
4546
import org.eclipse.esmf.aspectmodel.resolver.NamespacePackage;
46-
import org.eclipse.esmf.aspectmodel.resolver.exceptions.ModelResolutionException;
4747
import org.eclipse.esmf.aspectmodel.resolver.fs.ModelsRoot;
4848
import org.eclipse.esmf.aspectmodel.resolver.fs.StructuredModelsRoot;
4949
import org.eclipse.esmf.aspectmodel.resolver.modelfile.RawAspectModelFileBuilder;
@@ -96,11 +96,16 @@ public Map<String, List<Version>> importPackage( final CompletedFileUpload zipFi
9696

9797
return new ModelGroupingUtils( aspectModelLoader ).groupModelsByNamespaceAndVersion( savedUris, false );
9898
} catch ( final IOException e ) {
99-
throw new ModelResolutionException( "Could not read from input", e );
99+
throw new FileHandlingException( "Could not read from input", e );
100100
}
101101
}
102102

103103
private AddAspectModelFile createAddChange( final AspectModelFile file, final ModelsRoot modelsRoot ) {
104+
if ( file.sourceModel().isEmpty() ) {
105+
// TODO check why this will not returend ...
106+
throw new FileHandlingException( "Source model is empty for file: " + file );
107+
}
108+
104109
final URI targetLocation = modelsRoot.directoryForNamespace( file.namespaceUrn() ).resolve( file.filename().orElseThrow() ).toUri();
105110

106111
final RawAspectModelFileBuilder builder = RawAspectModelFileBuilder.builder().sourceModel( file.sourceModel() )
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2025 Robert Bosch Manufacturing Solutions GmbH
3+
*
4+
* See the AUTHORS file(s) distributed with this work for
5+
* additional information regarding authorship.
6+
*
7+
* This Source Code Form is subject to the terms of the Mozilla Public
8+
* License, v. 2.0. If a copy of the MPL was not distributed with this
9+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
10+
*
11+
* SPDX-License-Identifier: MPL-2.0
12+
*/
13+
14+
package org.eclipse.esmf.ame.services.models;
15+
16+
import java.util.Optional;
17+
18+
import com.fasterxml.jackson.annotation.JsonInclude;
19+
import io.micronaut.core.annotation.Introspected;
20+
import io.micronaut.serde.annotation.Serdeable;
21+
22+
/**
23+
* Represents the result of an aspect model operation.
24+
*
25+
* @param filename the optional name of the file associated with the model result
26+
* @param content the content of the model result
27+
*/
28+
@Serdeable
29+
@Introspected
30+
@JsonInclude( JsonInclude.Include.ALWAYS )
31+
public record AspectModelResult( Optional<String> filename, String content ) {}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2025 Robert Bosch Manufacturing Solutions GmbH
3+
*
4+
* See the AUTHORS file(s) distributed with this work for
5+
* additional information regarding authorship.
6+
*
7+
* This Source Code Form is subject to the terms of the Mozilla Public
8+
* License, v. 2.0. If a copy of the MPL was not distributed with this
9+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
10+
*
11+
* SPDX-License-Identifier: MPL-2.0
12+
*/
13+
14+
package org.eclipse.esmf.ame.services.models;
15+
16+
import com.fasterxml.jackson.annotation.JsonInclude;
17+
import io.micronaut.core.annotation.Introspected;
18+
import io.micronaut.serde.annotation.Serdeable;
19+
20+
/**
21+
* Represents a file entry with aspect model information.
22+
*
23+
* @param absoluteName the absolute path of the file
24+
* @param fileName the name of the file
25+
* @param aspectModelUrn the URN of the aspect model
26+
* @param modelVersion the version of the model
27+
*/
28+
@Serdeable
29+
@Introspected
30+
@JsonInclude( JsonInclude.Include.ALWAYS )
31+
public record FileEntry( String absoluteName, String fileName, String aspectModelUrn, String modelVersion ) {
32+
/**
33+
* Creates a FileEntry with only the aspect model URN.
34+
*
35+
* @param aspectModelUrn the URN of the aspect model
36+
*/
37+
public FileEntry( final String aspectModelUrn ) {
38+
this( null, null, aspectModelUrn, null );
39+
}
40+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2025 Robert Bosch Manufacturing Solutions GmbH
3+
*
4+
* See the AUTHORS file(s) distributed with this work for
5+
* additional information regarding authorship.
6+
*
7+
* This Source Code Form is subject to the terms of the Mozilla Public
8+
* License, v. 2.0. If a copy of the MPL was not distributed with this
9+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
10+
*
11+
* SPDX-License-Identifier: MPL-2.0
12+
*/
13+
14+
package org.eclipse.esmf.ame.services.models;
15+
16+
import com.fasterxml.jackson.annotation.JsonInclude;
17+
import io.micronaut.core.annotation.Introspected;
18+
import io.micronaut.serde.annotation.Serdeable;
19+
20+
/**
21+
* Represents information about an Aspect Model file.
22+
*
23+
* @param absoluteName the absolute path of the file
24+
* @param aspectModelUrn the URN of the aspect model
25+
* @param modelVersion the version of the model
26+
* @param aspectModel the aspect model content
27+
* @param fileName the name of the file
28+
*/
29+
@Serdeable
30+
@Introspected
31+
@JsonInclude( JsonInclude.Include.ALWAYS )
32+
public record FileInformation(
33+
String absoluteName,
34+
String aspectModelUrn,
35+
String modelVersion,
36+
String aspectModel,
37+
String fileName
38+
) {}

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

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,20 @@
1515

1616
import java.util.List;
1717

18+
import com.fasterxml.jackson.annotation.JsonInclude;
1819
import io.micronaut.core.annotation.Introspected;
1920
import io.micronaut.serde.annotation.Serdeable;
2021

2122
/**
22-
* Represents a single migration result with success and erros.
23+
* Represents the result of a migration operation.
24+
*
25+
* @param success indicates whether the migration was successful
26+
* @param errors list of error messages encountered during migration, empty if successful
2327
*/
2428
@Serdeable
2529
@Introspected
26-
public class MigrationResult {
27-
private boolean success;
28-
private List<String> errors;
29-
30-
public MigrationResult() {
31-
}
32-
33-
public MigrationResult( final boolean success, final List<String> errors ) {
34-
this.success = success;
35-
this.errors = errors;
36-
}
37-
38-
public boolean isSuccess() {
39-
return success;
40-
}
41-
42-
public void setSuccess( final boolean success ) {
43-
this.success = success;
44-
}
45-
46-
public List<String> getErrors() {
47-
return errors;
48-
}
49-
50-
public void setErrors( final List<String> errors ) {
51-
this.errors = errors;
52-
}
53-
}
30+
@JsonInclude( JsonInclude.Include.ALWAYS )
31+
public record MigrationResult(
32+
boolean success,
33+
List<String> errors
34+
) {}

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

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,59 +15,24 @@
1515

1616
import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn;
1717

18+
import com.fasterxml.jackson.annotation.JsonInclude;
1819
import io.micronaut.core.annotation.Introspected;
1920
import io.micronaut.serde.annotation.Serdeable;
2021

2122
/**
2223
* Represents a single model with its name or properties.
24+
*
25+
* @param model the model name or content
26+
* @param aspectModelUrn the URN of the aspect model
27+
* @param version the version of the model
28+
* @param existing indicates whether the model already exists
2329
*/
2430
@Serdeable
2531
@Introspected
26-
public class Model {
27-
private String model;
28-
private AspectModelUrn aspectModelUrn;
29-
private String version;
30-
private boolean existing;
31-
32-
public Model() {
33-
}
34-
35-
public Model( final String model, final AspectModelUrn aspectModelUrn, final String version, final boolean existing ) {
36-
this.model = model;
37-
this.aspectModelUrn = aspectModelUrn;
38-
this.version = version;
39-
this.existing = existing;
40-
}
41-
42-
public String getModel() {
43-
return model;
44-
}
45-
46-
public void setModel( final String model ) {
47-
this.model = model;
48-
}
49-
50-
public AspectModelUrn getAspectModelUrn() {
51-
return aspectModelUrn;
52-
}
53-
54-
public void setAspectModelUrn( final AspectModelUrn aspectModelUrn ) {
55-
this.aspectModelUrn = aspectModelUrn;
56-
}
57-
58-
public String getVersion() {
59-
return version;
60-
}
61-
62-
public void setVersion( final String version ) {
63-
this.version = version;
64-
}
65-
66-
public boolean isExisting() {
67-
return existing;
68-
}
69-
70-
public void setExisting( final boolean existing ) {
71-
this.existing = existing;
72-
}
73-
}
32+
@JsonInclude( JsonInclude.Include.ALWAYS )
33+
public record Model(
34+
String model,
35+
AspectModelUrn aspectModelUrn,
36+
String version,
37+
boolean existing
38+
) {}

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

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,20 @@
1515

1616
import java.util.List;
1717

18+
import com.fasterxml.jackson.annotation.JsonInclude;
1819
import io.micronaut.core.annotation.Introspected;
1920
import io.micronaut.serde.annotation.Serdeable;
2021

2122
/**
2223
* Represents a version containing a list of models.
24+
*
25+
* @param version the version identifier
26+
* @param models list of models associated with this version
2327
*/
2428
@Serdeable
2529
@Introspected
26-
public class Version {
27-
private String version;
28-
private List<Model> models;
29-
30-
public Version() {
31-
}
32-
33-
public Version( final String version, final List<Model> models ) {
34-
this.version = version;
35-
this.models = models;
36-
}
37-
38-
public String getVersion() {
39-
return version;
40-
}
41-
42-
public void setVersion( final String version ) {
43-
this.version = version;
44-
}
45-
46-
public List<Model> getModels() {
47-
return models;
48-
}
49-
50-
public void setModels( final List<Model> models ) {
51-
this.models = models;
52-
}
53-
}
30+
@JsonInclude( JsonInclude.Include.ALWAYS )
31+
public record Version(
32+
String version,
33+
List<Model> models
34+
) {}

0 commit comments

Comments
 (0)