Skip to content

Commit a16686d

Browse files
authored
Merge pull request #147 from bci-oss/feature/aasxgeneration
Feature/aasxgeneration
2 parents 4bc2a29 + 1735d0f commit a16686d

File tree

12 files changed

+1550
-69
lines changed

12 files changed

+1550
-69
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# AAS Generator Module of the BAMM SDK
2+
3+
The Asset Administration Shell (AAS) and its information model [1] is a widely recognized standard developed by the
4+
Industrial Digital Twin Association (IDTA) [2] to express and handle Digital Twins. Central element of the AAS is
5+
the concept of Submodels, which describe certain aspects of a Digital Twin.
6+
7+
The BAMM Aspect Meta Model allows to specify aspects of a digital twin and its semantics.
8+
The AAS Generator module provides mapping implementations to derive AAS Submodels from BAMM Aspect models
9+
and by that allows to on the one hand integrate BAMM models in AAS environments and on the other hand allow
10+
AAS Submodels to be described with rich semantics, as it is possible with BAMM.
11+
12+
The implementation relies on the AAS Meta Model implementation [3] and the AAS file serializers provided by [4].
13+
14+
## Example uses
15+
One example use of the generator is with the BAMM CLI, which provides the AAS generator functionality by
16+
```
17+
java -jar bamm-cli.jar aspect org.idtwin/1.0.0/Nameplate.ttl to aas -f xml -o nameplate.xml
18+
```
19+
or
20+
```
21+
java -jar bamm-cli.jar aspect org.idtwin/1.0.0/Nameplate.ttl to aas -f aasx -o nameplate.aasx
22+
```
23+
The first call generates a plain xml representation of the AAS whereas the second one generates an AASX archive
24+
with the AAS xml file in it.
25+
26+
Should the generator be integrated into custom implementations, the class `AspectModelAASGenerator`
27+
with its method `io.openmanufacturing.sds.aspectmodel.aas.AspectModelAASGenerator.generateOutput` is the
28+
proper entry point. It expects an `io.openmanufacturing.sds.metamodel.Aspect` and returns a
29+
`ByteArrayOutputStream`.
30+
31+
32+
## Details of the Mapping Concept
33+
The mapping rules applied by the generator are explained in the [user documentation](https://openmanufacturingplatform.github.io/sds-documentation/sds-developer-guide/tooling-guide/java-aspect-tooling.html#details-mapping-aas).
34+
The rules apply to BAMM v1.0.0 [6] and AAS Specification Part 1 V3.0RC01 [7].
35+
36+
37+
## References
38+
[1] https://www.plattform-i40.de/IP/Redaktion/EN/Standardartikel/specification-administrationshell.html
39+
40+
[2] https://industrialdigitaltwin.org
41+
42+
[3] https://github.com/admin-shell-io/java-model
43+
44+
[4] https://github.com/admin-shell-io/java-serializer
45+
46+
[5] https://openmanufacturingplatform.github.io/sds-documentation/bamm-specification/v1.0.0/characteristics.html
47+
48+
[6] https://openmanufacturingplatform.github.io/sds-documentation/bamm-specification/v1.0.0/index.html
49+
50+
[7] https://www.plattform-i40.de/IP/Redaktion/EN/Downloads/Publikation/Details_of_the_Asset_Administration_Shell_Part1_V3.html
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>sds-sdk-parent</artifactId>
7+
<groupId>io.openmanufacturing</groupId>
8+
<version>DEV-SNAPSHOT</version>
9+
<relativePath>../../pom.xml</relativePath>
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<artifactId>sds-aspect-model-aas-generator</artifactId>
14+
15+
<properties>
16+
<maven.compiler.source>11</maven.compiler.source>
17+
<maven.compiler.target>11</maven.compiler.target>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>io.openmanufacturing</groupId>
23+
<artifactId>sds-aspect-model-starter</artifactId>
24+
</dependency>
25+
<dependency>
26+
<groupId>io.openmanufacturing</groupId>
27+
<artifactId>sds-aspect-meta-model-java</artifactId>
28+
</dependency>
29+
<dependency>
30+
<groupId>io.admin-shell.aas</groupId>
31+
<artifactId>model</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>io.admin-shell.aas</groupId>
35+
<artifactId>dataformat-xml</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>io.admin-shell.aas</groupId>
39+
<artifactId>dataformat-aasx</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>io.openmanufacturing</groupId>
43+
<artifactId>sds-test-resources</artifactId>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.junit.jupiter</groupId>
47+
<artifactId>junit-jupiter</artifactId>
48+
<scope>test</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.assertj</groupId>
52+
<artifactId>assertj-core</artifactId>
53+
<scope>test</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>junit</groupId>
57+
<artifactId>junit</artifactId>
58+
</dependency>
59+
</dependencies>
60+
</project>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright (c) 2021, 2022 Robert Bosch Manufacturing Solutions GmbH
3+
*
4+
* See the AUTHORS file(s) distributed with this work for additional
5+
* 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+
package io.openmanufacturing.sds.aspectmodel.aas;
14+
15+
import java.io.ByteArrayOutputStream;
16+
import java.io.IOException;
17+
import java.io.OutputStream;
18+
import java.util.function.Function;
19+
20+
import io.adminshell.aas.v3.dataformat.SerializationException;
21+
import io.adminshell.aas.v3.dataformat.aasx.AASXSerializer;
22+
import io.adminshell.aas.v3.dataformat.xml.XmlSerializer;
23+
import io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment;
24+
import io.openmanufacturing.sds.metamodel.Aspect;
25+
26+
/** Generator that generates an AASX file containing an AAS submodel for a given Aspect model */
27+
public class AspectModelAASGenerator {
28+
29+
/**
30+
* Generates an AASX archive file for a given Aspect and writes it to a given OutputStream provided by <code>nameMapper<code/>
31+
*
32+
* @param aspect the Aspect for which an AASX archive shall be generated
33+
* @param nameMapper a Name Mapper implementation, which provides an OutputStream for a given filename
34+
* @throws IOException in case the generation can not properly be executed
35+
*/
36+
public void generateAASXFile( final Aspect aspect, final Function<String, OutputStream> nameMapper )
37+
throws IOException {
38+
try ( final OutputStream output = nameMapper.apply( aspect.getName() ) ) {
39+
output.write( generateAasxOutput( aspect ).toByteArray() );
40+
}
41+
}
42+
43+
/**
44+
* Generates an AAS XML archive file for a given Aspect and writes it to a given OutputStream provided by <code>nameMapper<code/>
45+
*
46+
* @param aspect the Aspect for which an AASX archive shall be generated
47+
* @param nameMapper a Name Mapper implementation, which provides an OutputStream for a given filename
48+
* @throws IOException in case the generation can not properly be executed
49+
*/
50+
public void generateAasXmlFile(
51+
final Aspect aspect, final Function<String, OutputStream> nameMapper ) throws IOException {
52+
try ( final OutputStream output = nameMapper.apply( aspect.getName() ) ) {
53+
output.write( generateXmlOutput( aspect ).toByteArray() );
54+
}
55+
}
56+
57+
protected ByteArrayOutputStream generateAasxOutput( Aspect aspect ) throws IOException {
58+
final AspectModelAASVisitor visitor = new AspectModelAASVisitor();
59+
AssetAdministrationShellEnvironment environment = visitor.visitAspect( aspect, null );
60+
61+
try ( ByteArrayOutputStream out = new ByteArrayOutputStream() ) {
62+
AASXSerializer serializer = new AASXSerializer();
63+
serializer.write( environment, null, out );
64+
return out;
65+
} catch ( SerializationException e ) {
66+
throw new IOException( e );
67+
}
68+
}
69+
70+
protected ByteArrayOutputStream generateXmlOutput( Aspect aspect ) throws IOException {
71+
final AspectModelAASVisitor visitor = new AspectModelAASVisitor();
72+
AssetAdministrationShellEnvironment environment = visitor.visitAspect( aspect, null );
73+
74+
try ( ByteArrayOutputStream out = new ByteArrayOutputStream() ) {
75+
XmlSerializer serializer = new XmlSerializer();
76+
serializer.write( out, environment );
77+
return out;
78+
} catch ( SerializationException e ) {
79+
throw new IOException( e );
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)