Generation interfaces derived from an Aspect Model

Dealing with an Aspect Model and generating components or other elements based on it, the type safety and definition must be ensured for a smooth development process. Generating interfaces is included for each element derived from an Aspect Model.

The type generation functionality is provided through a schematics and can be used as follows:

ng generate @esmf/semantic-ui-schematics:types --aspectModelTFilesString=<relative-path-model-ttl>

or

ng g @esmf/semantic-ui-schematics:types --aspectModelTFilesString=<relative-path-model-ttl-1>,<relative-path-model-ttl-2>

Afterwards you can choose the Aspect Model and all referenced .ttl files to generate the desired interfaces. The interfaces will be generated under src/app/shared/types/<aspect-model-name>/<aspect-model-version>/<aspect-model-name>.types.ts.

Example using the Movement.ttl:

Show stacktrace
# Copyright (c) 2024 Robert Bosch Manufacturing Solutions GmbH
#
# See the AUTHORS file(s) distributed with this work for
# additional information regarding authorship.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0

@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.1.0#> .
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.1.0#> .
@prefix samm-e: <urn:samm:org.eclipse.esmf.samm:entity:2.1.0#> .
@prefix unit: <urn:samm:org.eclipse.esmf.samm:unit:2.1.0#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix : <urn:samm:org.eclipse.examples:2.1.0#> .

:Movement a samm:Aspect ;
   samm:name "Movement" ;
   samm:preferredName "movement"@en ;
   samm:description "Aspect for movement information"@en ;
   samm:properties ( :isMoving :position :speed :speedLimitWarning ) ;
   samm:operations ( ) ;
   samm:events ( ) .

:isMoving a samm:Property ;
   samm:name "isMoving" ;
   samm:preferredName "is moving"@en ;
   samm:description "Flag indicating whether the asset is currently moving"@en ;
   samm:characteristic samm-c:Boolean .

:position a samm:Property ;
   samm:name "position" ;
   samm:preferredName "position"@en ;
   samm:description "Indicates a position"@en ;
   samm:characteristic :SpatialPositionCharacteristic .

:speed a samm:Property ;
   samm:name "speed" ;
   samm:preferredName "speed"@en ;
   samm:description "speed of vehicle"@en ;
   samm:characteristic :Speed .

:speedLimitWarning a samm:Property ;
   samm:name "speedLimitWarning" ;
   samm:preferredName "speed limit warning"@en ;
   samm:description "Indicates if the speed limit is adhered to."@en ;
   samm:characteristic :TrafficLight .

:SpatialPositionCharacteristic a samm-c:SingleEntity ;
   samm:name "SpatialPositionCharacteristic" ;
   samm:preferredName "spatial position characteristic"@en ;
   samm:description "Represents a single position in space with optional z coordinate."@en ;
   samm:dataType :SpatialPosition .

:Speed a samm-c:Measurement ;
   samm:name "Speed" ;
   samm:preferredName "speed"@en ;
   samm:description "Scalar representation of speed of an object in kilometers per hour."@en ;
   samm:dataType xsd:float ;
   samm-c:unit unit:kilometrePerHour .

:TrafficLight a samm-c:Enumeration ;
   samm:name "TrafficLight" ;
   samm:preferredName "warning level"@en ;
   samm:description "Represents if speed of position change is within specification (green), within tolerance (yellow), or outside specification (red)."@en ;
   samm:dataType xsd:string ;
   samm-c:values ( "green" "yellow" "red" ) .

:SpatialPosition a samm:Entity ;
   samm:name "SpatialPosition" ;
   samm:preferredName "spatial position"@en ;
   samm:description "Represents latitude, longitude and altitude information in the WGS84 geodetic reference datum"@en ;
   samm:see <https://www.w3.org/2003/01/geo/> ;
   samm:properties ( :latitude :longitude [ samm:property :altitude; samm:optional true ] ) .

:latitude a samm:Property ;
   samm:name "latitude" ;
   samm:preferredName "latitude"@en ;
   samm:description "latitude coordinate in space (WGS84)"@en ;
   samm:see <http://www.w3.org/2003/01/geo/wgs84_pos#lat> ;
   samm:characteristic :Coordinate ;
   samm:exampleValue "9.1781"^^xsd:decimal .

:longitude a samm:Property ;
   samm:name "longitude" ;
   samm:preferredName "longitude"@en ;
   samm:description "longitude coordinate in space (WGS84)"@en ;
   samm:see <http://www.w3.org/2003/01/geo/wgs84_pos#long> ;
   samm:characteristic :Coordinate ;
   samm:exampleValue "48.80835"^^xsd:decimal .

:altitude a samm:Property ;
   samm:name "altitude" ;
   samm:preferredName "altitude"@en ;
   samm:description "Elevation above sea level zero"@en ;
   samm:see <http://www.w3.org/2003/01/geo/wgs84_pos#alt> ;
   samm:characteristic :MetresAboveMeanSeaLevel ;
   samm:exampleValue "153"^^xsd:float .

:Coordinate a samm-c:Measurement ;
   samm:name "Coordinate" ;
   samm:preferredName "coordinate"@en ;
   samm:description "Representing the geographical coordinate"@en ;
   samm:dataType xsd:decimal ;
   samm-c:unit unit:degreeUnitOfAngle .

:MetresAboveMeanSeaLevel a samm-c:Measurement ;
   samm:name "MetresAboveMeanSeaLevel" ;
   samm:preferredName "metres above mean sea level"@en ;
   samm:description "Signifies the vertical distance in reference to a historic mean sea level as a vertical datum"@en ;
   samm:see <https://en.wikipedia.org/wiki/Height_above_sea_level> ;
   samm:dataType xsd:float ;
   samm-c:unit unit:metre .

Running the following CLI command. Movement.ttl is stored in the root folder of the Angular project:

ng g @esmf/semantic-ui-schematics:types --aspectModelTFilesString=Movement.ttl

The following interfaces will be generated:

/*
 * Copyright (c) 2024 Robert Bosch Manufacturing Solutions GmbH
 *
 * See the AUTHORS file(s) distributed with this work for
 * additional information regarding authorship.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 *
 * SPDX-License-Identifier: MPL-2.0
 */

export interface MultiLanguageText {
    /** key defines the locale. Value is the translated text for that locale. */
    [key: string]: string;
}

/** Aspect for movement information */
export interface Movement {
    /** Flag indicating whether the asset is currently moving */
    isMoving: boolean;
    /** Indicates a position */
    position: SpatialPosition;
    /** speed of vehicle */
    speed: number;
    /** Indicates if the speed limit is adhered to. */
    speedLimitWarning: TrafficLight;
}

/** Represents latitude, longitude and altitude information in the WGS84 geodetic reference datum */
export interface SpatialPosition {
    /** latitude coordinate in space (WGS84) */
    latitude: number;
    /** longitude coordinate in space (WGS84) */
    longitude: number;
    /** Elevation above sea level zero */
    altitude?: number;
}

/** Represents if speed of position change is within specification (green), within tolerance (yellow), or outside specification (red). */
export enum TrafficLight {
    Green = 'green',
    Yellow = 'yellow',
    Red = 'red',
}