Skip to content

Commit 82beedb

Browse files
committed
Add information into namespaces
1 parent 703bc14 commit 82beedb

File tree

8 files changed

+137
-77
lines changed

8 files changed

+137
-77
lines changed

aspect-model-editor-runtime/bruno/FormateAspectModel.bru

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ headers {
1717
body:text {
1818
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.2.0#> .
1919
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.2.0#> .
20+
@prefix samm-e: <urn:samm:org.eclipse.esmf.samm:entity:2.2.0#> .
2021
@prefix unit: <urn:samm:org.eclipse.esmf.samm:unit:2.2.0#> .
2122
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
2223
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@@ -26,22 +27,46 @@ body:text {
2627
:Movement a samm:Aspect ;
2728
samm:preferredName "movement"@en ;
2829
samm:description "Aspect for movement information"@en ;
29-
samm:properties (:isMoving :position :speed :speedLimitWarning) ;
30+
samm:properties ( :isMoving :position :speed :speedLimitWarning ) ;
3031
samm:operations ( ) ;
3132
samm:events ( ) .
3233

33-
:Coordinate a samm-c:Measurement ;
34-
samm:preferredName "coordinate"@en ;
35-
samm:description "Representing the geographical coordinate"@en ;
36-
samm:dataType xsd:decimal ;
37-
samm-c:unit unit:degreeUnitOfAngle .
34+
:isMoving a samm:Property ;
35+
samm:preferredName "is moving"@en ;
36+
samm:description "Flag indicating whether the asset is currently moving"@en ;
37+
samm:characteristic samm-c:Boolean .
3838

39-
:MetresAboveMeanSeaLevel a samm-c:Measurement ;
40-
samm:preferredName "metres above mean sea level"@en ;
41-
samm:description "Signifies the vertical distance in reference to a historic mean sea level as a vertical datum"@en ;
42-
samm:see <https://en.wikipedia.org/wiki/Height_above_sea_level> ;
39+
:position a samm:Property ;
40+
samm:preferredName "position"@en ;
41+
samm:description "Indicates a position"@en ;
42+
samm:characteristic :SpatialPositionCharacteristic .
43+
44+
:speed a samm:Property ;
45+
samm:preferredName "speed"@en ;
46+
samm:description "speed of vehicle"@en ;
47+
samm:characteristic :Speed .
48+
49+
:speedLimitWarning a samm:Property ;
50+
samm:preferredName "speed limit warning"@en ;
51+
samm:description "Indicates if the speed limit is adhered to."@en ;
52+
samm:characteristic :TrafficLight .
53+
54+
:SpatialPositionCharacteristic a samm-c:SingleEntity ;
55+
samm:preferredName "spatial position characteristic"@en ;
56+
samm:description "Represents a single position in space with optional z coordinate."@en ;
57+
samm:dataType :SpatialPosition .
58+
59+
:Speed a samm-c:Measurement ;
60+
samm:preferredName "speed"@en ;
61+
samm:description "Scalar representation of speed of an object in kilometers per hour."@en ;
4362
samm:dataType xsd:float ;
44-
samm-c:unit unit:metre .
63+
samm-c:unit unit:kilometrePerHour .
64+
65+
:TrafficLight a samm-c:Enumeration ;
66+
samm:preferredName "warning level"@en ;
67+
samm:description "Represents if speed of position change is within specification (green), within tolerance (yellow), or outside specification (red)."@en ;
68+
samm:dataType xsd:string ;
69+
samm-c:values ( "green" "yellow" "red" ) .
4570

4671
:SpatialPosition a samm:Entity ;
4772
samm:preferredName "spatial position"@en ;
@@ -56,52 +81,32 @@ body:text {
5681
samm:characteristic :Coordinate ;
5782
samm:exampleValue "9.1781"^^xsd:decimal .
5883

59-
:speedLimitWarning a samm:Property ;
60-
samm:preferredName "speed limit warning"@en ;
61-
samm:description "Indicates if the speed limit is adhered to."@en ;
62-
samm:characteristic :TrafficLight .
63-
64-
:altitude a samm:Property ;
65-
samm:preferredName "altitude"@en ;
66-
samm:description "Elevation above sea level zero"@en ;
67-
samm:see <http://www.w3.org/2003/01/geo/wgs84_pos#alt> ;
68-
samm:characteristic :MetresAboveMeanSeaLevel ;
69-
samm:exampleValue "153"^^xsd:float .
70-
71-
:position a samm:Property ;
72-
samm:preferredName "position"@en ;
73-
samm:description "Indicates a position"@en ;
74-
samm:characteristic :SpatialPositionCharacteristic .
75-
7684
:longitude a samm:Property ;
7785
samm:preferredName "longitude"@en ;
7886
samm:description "longitude coordinate in space (WGS84)"@en ;
7987
samm:see <http://www.w3.org/2003/01/geo/wgs84_pos#long> ;
8088
samm:characteristic :Coordinate ;
8189
samm:exampleValue "48.80835"^^xsd:decimal .
8290

83-
:TrafficLight a samm-c:Enumeration ;
84-
samm:preferredName "warning level"@en ;
85-
samm:description "Represents if speed of position change is within specification (green), within tolerance (yellow), or outside specification (red)."@en ;
86-
samm:dataType xsd:string ;
87-
samm-c:values ( "green" "yellow" "red" ) .
91+
:altitude a samm:Property ;
92+
samm:preferredName "altitude"@en ;
93+
samm:description "Elevation above sea level zero"@en ;
94+
samm:see <http://www.w3.org/2003/01/geo/wgs84_pos#alt> ;
95+
samm:characteristic :MetresAboveMeanSeaLevel ;
96+
samm:exampleValue "153"^^xsd:float .
8897

89-
:SpatialPositionCharacteristic a samm-c:SingleEntity ;
90-
samm:preferredName "spatial position characteristic"@en ;
91-
samm:description "Represents a single position in space with optional z coordinate."@en ;
92-
samm:dataType :SpatialPosition .
98+
:Coordinate a samm-c:Measurement ;
99+
samm:preferredName "coordinate"@en ;
100+
samm:description "Representing the geographical coordinate"@en ;
101+
samm:dataType xsd:decimal ;
102+
samm-c:unit unit:degreeUnitOfAngle .
93103

94-
:Speed a samm-c:Measurement ;
95-
samm:preferredName "speed"@en ;
96-
samm:description "Scalar representation of speed of an object in kilometers per hour."@en ;
104+
:MetresAboveMeanSeaLevel a samm-c:Measurement ;
105+
samm:preferredName "metres above mean sea level"@en ;
106+
samm:description "Signifies the vertical distance in reference to a historic mean sea level as a vertical datum"@en ;
107+
samm:see <https://en.wikipedia.org/wiki/Height_above_sea_level> ;
97108
samm:dataType xsd:float ;
98-
samm-c:unit unit:kilometrePerHour .
99-
100-
:speed a samm:Property ;
101-
samm:preferredName "speed"@en ;
102-
samm:description "speed of vehicle"@en ;
103-
samm:characteristic :Speed .
104-
109+
samm-c:unit unit:metre .
105110

106111
}
107112

aspect-model-editor-runtime/src/main/resources/application.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ micronaut.server.context-path=/ame/api
1515
micronaut.server.port=9090
1616
micronaut.server.host=127.0.0.1
1717
micronaut.security.enabled=false
18+
micronaut.server.cors.enabled=true
19+
micronaut.server.configurations.all.allowed-origins=["*"]
20+
micronaut.server.configurations.all.allowed-methods=["*"]
21+
micronaut.server.configurations.all.allowed-headers=["*"]
1822
# Logging Configuration
1923
logger.levels.io.micronaut=INFO
2024
logger.levels.io.micronaut.security=INFO

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

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@
1818
import java.io.IOException;
1919
import java.net.URI;
2020
import java.nio.file.Path;
21-
import java.nio.file.Paths;
2221
import java.util.ArrayList;
2322
import java.util.List;
2423
import java.util.Map;
2524
import java.util.function.Supplier;
2625
import java.util.stream.Stream;
27-
import java.util.stream.StreamSupport;
2826

2927
import org.eclipse.esmf.ame.exceptions.CreateFileException;
3028
import org.eclipse.esmf.ame.exceptions.FileNotFoundException;
@@ -76,7 +74,9 @@ public ModelService( final AspectModelValidator aspectModelValidator, final Aspe
7674

7775
public String getModel( final String aspectModelUrn, final String filePath ) {
7876
try {
79-
final AspectModel aspectModel = ( filePath != null ) ? loadModelFromFile( filePath ) : loadModelFromUrn( aspectModelUrn );
77+
final AspectModel aspectModel = ( filePath != null ) ?
78+
ModelUtils.loadModelFromFile( modelPath, filePath, aspectModelLoader ) :
79+
loadModelFromUrn( aspectModelUrn );
8080
validateModel( aspectModel );
8181

8282
return aspectModel.files().stream()
@@ -88,13 +88,6 @@ public String getModel( final String aspectModelUrn, final String filePath ) {
8888
}
8989
}
9090

91-
private AspectModel loadModelFromFile( final String filePath ) throws ModelResolutionException {
92-
final Path path = Paths.get( filePath ).normalize();
93-
final String[] pathParts = StreamSupport.stream( path.spliterator(), false ).map( Path::toString ).toArray( String[]::new );
94-
final Path aspectModelPath = constructModelPath( pathParts[0], pathParts[1], pathParts[2] );
95-
return aspectModelLoader.load( aspectModelPath.toFile() );
96-
}
97-
9891
private AspectModel loadModelFromUrn( final String aspectModelUrn ) {
9992
final Supplier<AspectModel> aspectModelSupplier = ModelUtils.getAspectModelSupplier( AspectModelUrn.fromUrn( aspectModelUrn ),
10093
aspectModelLoader );
@@ -161,7 +154,7 @@ public String getFormattedModel( final String turtleData ) {
161154
public Map<String, List<Version>> getAllNamespaces() {
162155
try {
163156
final Stream<URI> uriStream = aspectModelLoader.listContents();
164-
return new ModelGroupingUtils( this.modelPath ).groupModelsByNamespaceAndVersion( uriStream );
157+
return new ModelGroupingUtils( this.aspectModelLoader, this.modelPath ).groupModelsByNamespaceAndVersion( uriStream );
165158
} catch ( final UnsupportedVersionException e ) {
166159
LOG.error( "{} There is a loose .ttl file somewhere — remove it along with any other non-standardized files.", sammStructureInfo,
167160
e );
@@ -185,7 +178,7 @@ public MigrationResult migrateWorkspace( final boolean setNewVersion ) {
185178
private void processVersion( final String namespace, final Version version, final boolean setNewVersion, final List<String> errors ) {
186179
version.getModels().forEach( model -> {
187180
try {
188-
final Path aspectModelPath = constructModelPath( namespace, version.getVersion(), model.getModel() );
181+
final Path aspectModelPath = ModelUtils.constructModelPath( modelPath, namespace, version.getVersion(), model.getModel() );
189182
final AspectModel aspectModel = aspectModelLoader.load( aspectModelPath.toFile() );
190183

191184
if ( setNewVersion ) {
@@ -230,8 +223,4 @@ private void saveAspectModelFiles( final AspectModel aspectModel, final boolean
230223
}
231224
} ) );
232225
}
233-
234-
private Path constructModelPath( final String namespace, final String version, final String modelName ) {
235-
return Path.of( modelPath.toString(), namespace, version, modelName );
236-
}
237226
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public Map<String, List<Version>> importPackage( final CompletedFileUpload zipFi
9696

9797
final Stream<URI> savedUris = saveAspectModelFiles( selectedFiles );
9898

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

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
package org.eclipse.esmf.ame.services.models;
1515

16+
import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn;
17+
1618
import io.micronaut.core.annotation.Introspected;
1719
import io.micronaut.serde.annotation.Serdeable;
1820

@@ -23,13 +25,15 @@
2325
@Introspected
2426
public class Model {
2527
private String model;
28+
private AspectModelUrn aspectModelUrn;
2629
private boolean existing;
2730

2831
public Model() {
2932
}
3033

31-
public Model( final String model, final boolean existing ) {
34+
public Model( final String model, final AspectModelUrn aspectModelUrn, final boolean existing ) {
3235
this.model = model;
36+
this.aspectModelUrn = aspectModelUrn;
3337
this.existing = existing;
3438
}
3539

@@ -41,6 +45,14 @@ public void setModel( final String model ) {
4145
this.model = model;
4246
}
4347

48+
public AspectModelUrn getAspectModelUrn() {
49+
return aspectModelUrn;
50+
}
51+
52+
public void setAspectModelUrn( final AspectModelUrn aspectModelUrn ) {
53+
this.aspectModelUrn = aspectModelUrn;
54+
}
55+
4456
public boolean isExisting() {
4557
return existing;
4658
}

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

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,28 @@
2727

2828
import org.eclipse.esmf.ame.services.models.Model;
2929
import org.eclipse.esmf.ame.services.models.Version;
30+
import org.eclipse.esmf.aspectmodel.loader.AspectModelLoader;
31+
import org.eclipse.esmf.metamodel.AspectModel;
32+
import org.eclipse.esmf.metamodel.ModelElement;
33+
34+
import io.vavr.Tuple;
3035

3136
/**
3237
* A utility class for grouping model URIs by namespace and version.
3338
*/
3439
public class ModelGroupingUtils {
3540

41+
private final AspectModelLoader aspectModelLoader;
3642
private final Path modelPath;
3743

3844
/**
3945
* Constructs a ModelGrouper with the given base model path.
4046
*
47+
* @param aspectModelLoader the loader for aspect models
4148
* @param modelPath the base path to relativize URIs against
4249
*/
43-
public ModelGroupingUtils( final Path modelPath ) {
50+
public ModelGroupingUtils( final AspectModelLoader aspectModelLoader, final Path modelPath ) {
51+
this.aspectModelLoader = aspectModelLoader;
4452
this.modelPath = modelPath;
4553
}
4654

@@ -51,14 +59,43 @@ public ModelGroupingUtils( final Path modelPath ) {
5159
* @return a map where the keys are namespaces and the values are lists of maps containing versions and their associated models
5260
*/
5361
public Map<String, List<Version>> groupModelsByNamespaceAndVersion( final Stream<URI> uriStream ) {
54-
return uriStream.map( this::relativizePath ).map( this::splitPath ).collect(
55-
Collectors.groupingBy( this::extractNamespace, TreeMap::new, Collectors.collectingAndThen(
56-
Collectors.groupingBy( this::extractVersion,
57-
Collectors.mapping(
58-
parts -> createModel( parts,
59-
modelPath.resolve( Paths.get( parts[0], parts[1], parts[2] ) ).toFile().exists() ),
60-
Collectors.toList() ) ),
61-
this::convertAndSortVersionMap ) ) );
62+
final List<URI> sortedUris = uriStream
63+
.sorted( Comparator.comparing( uri -> modelPath.relativize( Paths.get( uri ) ).toString() ) )
64+
.toList();
65+
66+
return sortedUris.stream()
67+
.map( this::relativizePath )
68+
.map( relativePath -> {
69+
final AspectModel aspectModel = ModelUtils.loadModelFromFile( modelPath, relativePath, this.aspectModelLoader );
70+
71+
final ModelElement modelElement = !aspectModel.aspects().isEmpty()
72+
? aspectModel.aspect()
73+
: aspectModel.files().stream()
74+
.flatMap( file -> file.elements().stream() )
75+
.findFirst()
76+
.orElse( null );
77+
78+
return Tuple.of( modelElement, splitPath( relativePath ) );
79+
} )
80+
.collect( Collectors.groupingBy(
81+
tuple -> extractNamespace( tuple._2 ),
82+
TreeMap::new,
83+
Collectors.collectingAndThen(
84+
Collectors.groupingBy(
85+
tuple -> extractVersion( tuple._2 ),
86+
Collectors.mapping(
87+
tuple -> {
88+
final String[] parts = tuple._2;
89+
final Path resolvedPath = Paths.get( parts[0], parts[1], parts[2] );
90+
final boolean fileExists = modelPath.resolve( resolvedPath ).toFile().exists();
91+
return createModel( parts, fileExists, tuple._1 );
92+
},
93+
Collectors.toList()
94+
)
95+
),
96+
this::convertAndSortVersionMap
97+
)
98+
) );
6299
}
63100

64101
/**
@@ -105,11 +142,12 @@ private String extractVersion( final String[] parts ) {
105142
* Creates a map representing a model from the given path parts, setting the existing field as specified.
106143
*
107144
* @param parts an array of path parts
145+
* @param modelElement an element of the aspect model
108146
* @param existing whether to set the existing field to true
109147
* @return a map containing the model information
110148
*/
111-
private Model createModel( final String[] parts, final boolean existing ) {
112-
return new Model( parts[2], existing );
149+
private Model createModel( final String[] parts, final boolean existing, final ModelElement modelElement ) {
150+
return new Model( parts[2], modelElement.urn(), existing );
113151
}
114152

115153
/**

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.Optional;
3030
import java.util.function.Predicate;
3131
import java.util.function.Supplier;
32+
import java.util.stream.StreamSupport;
3233

3334
import org.eclipse.esmf.ame.config.ApplicationSettings;
3435
import org.eclipse.esmf.ame.exceptions.FileNotFoundException;
@@ -220,4 +221,15 @@ public static Path resolvePathFromUrn( final String urn, final Path modelPath )
220221

221222
return modelPath.resolve( namespace ).resolve( version ).resolve( fileName + ".ttl" );
222223
}
224+
225+
public static AspectModel loadModelFromFile( final Path modelPath, final String filePath, final AspectModelLoader aspectModelLoader ) {
226+
final Path path = Paths.get( filePath ).normalize();
227+
final String[] pathParts = StreamSupport.stream( path.spliterator(), false ).map( Path::toString ).toArray( String[]::new );
228+
final Path aspectModelPath = constructModelPath( modelPath, pathParts[0], pathParts[1], pathParts[2] );
229+
return aspectModelLoader.load( aspectModelPath.toFile() );
230+
}
231+
232+
public static Path constructModelPath( final Path modelPath, final String namespace, final String version, final String modelName ) {
233+
return Path.of( modelPath.toString(), namespace, version, modelName );
234+
}
223235
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<os.platform/>
6565

6666
<!-- Internal esmf dependencies -->
67-
<esmf-sdk-version>2.10.2</esmf-sdk-version>
67+
<esmf-sdk-version>2.10.3</esmf-sdk-version>
6868

6969
<!-- Versions of third party dependencies -->
7070
<micronaut.version>4.7.6</micronaut.version>

0 commit comments

Comments
 (0)