Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.

Commit 1bbe0a1

Browse files
author
weissarn
committed
Merge remote-tracking branch 'origin/master' into admin-shell/main
2 parents b887d27 + 3e9508a commit 1bbe0a1

59 files changed

Lines changed: 1661 additions & 6601 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

LICENSE

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,4 @@
1-
Copyright (c) 2021 Fraunhofer IOSB-INA Lemgo,
2-
eine rechtlich nicht selbstaendige Einrichtung der Fraunhofer-Gesellschaft
3-
zur Foerderung der angewandten Forschung e.V.
4-
5-
Copyright (c) 2021 Fraunhofer IOSB-ILT Karlsruhe,
6-
eine rechtlich nicht selbstaendige Einrichtung der Fraunhofer-Gesellschaft
7-
zur Foerderung der angewandten Forschung e.V.
8-
9-
Copyright (c) 2021 Fraunhofer IAIS,
10-
eine rechtlich nicht selbstaendige Einrichtung der Fraunhofer-Gesellschaft
11-
zur Foerderung der angewandten Forschung e.V.
12-
13-
Copyright (c) 2021 Fraunhofer IESE,
14-
eine rechtlich nicht selbstaendige Einrichtung der Fraunhofer-Gesellschaft
15-
zur Foerderung der angewandten Forschung e.V.
16-
17-
Copyright (c) 2021 Fraunhofer IWU Karlsruhe,
18-
eine rechtlich nicht selbstaendige Einrichtung der Fraunhofer-Gesellschaft
19-
zur Foerderung der angewandten Forschung e.V.
1+
Copyright (C) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
202

213
The Serializers contained in this repository provide the functionalities to
224
serialize and deserialize instances of the Asset Administration Shell data model
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ local.properties
2828
.project
2929

3030
testJsonSerialization.json
31+
Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
Apache License
1+
Copyright (C) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
2+
3+
The AASX Serializer contained in this repository provide the functionalities to
4+
serialize and deserialize instances of the Asset Administration Shell data model
5+
from and to the AAS Java Model library. It is licensed under the Apache License
6+
2.0 (Apache-2.0, see below).
7+
The Model uses the concepts of the document "Details of the Asset
8+
Administration Shell" published on www.plattform-i40.de which is licensed
9+
under Creative Commons CC BY-ND 3.0 DE.
10+
11+
-------------------------------------------------------------------------------
12+
13+
14+
15+
Apache License
216
Version 2.0, January 2004
317
http://www.apache.org/licenses/
418

@@ -175,14 +189,18 @@ Apache License
175189

176190
END OF TERMS AND CONDITIONS
177191

178-
Copyright 2021-today Fraunhofer IAIS/EIS
192+
APPENDIX: How to apply the Apache License to your work.
193+
194+
To apply the Apache License to your work, attach the following
195+
boilerplate notice, with the fields enclosed by brackets "[]"
196+
replaced with your own identifying information. (Don't include
197+
the brackets!) The text should be enclosed in the appropriate
198+
comment syntax for the file format. We also recommend that a
199+
file or class name and description of purpose be included on the
200+
same "printed page" as the copyright notice for easier
201+
identification within third-party archives.
179202

180-
Contact:
181-
Fraunhofer Institute for Intelligent Analysis and Information Systems IAIS
182-
Department Enterprise Information Systems
183-
Schloss Birlinghoven
184-
53757 Sankt Augustin
185-
E-Mail: ids-support@iais.fraunhofer.de
203+
Copyright 2020 Fraunhofer IAIS
186204

187205
Licensed under the Apache License, Version 2.0 (the "License");
188206
you may not use this file except in compliance with the License.

dataformat-aasx/pom.xml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>io.admin-shell.aas</groupId>
8+
<artifactId>dataformat-parent</artifactId>
9+
<version>${revision}</version>
10+
</parent>
11+
<artifactId>dataformat-aasx</artifactId>
12+
<dependencies>
13+
<dependency>
14+
<groupId>io.admin-shell.aas</groupId>
15+
<artifactId>dataformat-xml</artifactId>
16+
<version>${revision}</version>
17+
<scope>compile</scope>
18+
</dependency>
19+
<dependency>
20+
<groupId>io.admin-shell.aas</groupId>
21+
<artifactId>model</artifactId>
22+
<version>${revision}</version>
23+
<scope>compile</scope>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.apache.poi</groupId>
27+
<artifactId>poi-ooxml</artifactId>
28+
<version>${poi.version}</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.slf4j</groupId>
32+
<artifactId>slf4j-api</artifactId>
33+
<version>${slf4j.version}</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>junit</groupId>
37+
<artifactId>junit</artifactId>
38+
<version>${junit.version}</version>
39+
<scope>test</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>pl.pragmatists</groupId>
43+
<artifactId>JUnitParams</artifactId>
44+
<version>${junit-params.version}</version>
45+
<scope>test</scope>
46+
</dependency>
47+
<dependency>
48+
<groupId>commons-io</groupId>
49+
<artifactId>commons-io</artifactId>
50+
<version>${commons-io.version}</version>
51+
</dependency>
52+
</dependencies>
53+
<build>
54+
<plugins>
55+
<plugin>
56+
<groupId>org.apache.maven.plugins</groupId>
57+
<artifactId>maven-compiler-plugin</artifactId>
58+
<configuration>
59+
<source>11</source>
60+
<target>11</target>
61+
</configuration>
62+
</plugin>
63+
<plugin>
64+
<groupId>org.codehaus.mojo</groupId>
65+
<artifactId>flatten-maven-plugin</artifactId>
66+
<version>1.2.2</version>
67+
<configuration>
68+
<updatePomFile>true</updatePomFile>
69+
</configuration>
70+
<executions>
71+
<execution>
72+
<id>flatten</id>
73+
<phase>process-resources</phase>
74+
<goals>
75+
<goal>flatten</goal>
76+
</goals>
77+
</execution>
78+
<execution>
79+
<id>flatten.clean</id>
80+
<phase>clean</phase>
81+
<goals>
82+
<goal>clean</goal>
83+
</goals>
84+
</execution>
85+
</executions>
86+
</plugin>
87+
</plugins>
88+
</build>
89+
<repositories>
90+
<repository>
91+
<id>eis-public-repo</id>
92+
<name>maven-public</name>
93+
<url>http://maven.iais.fraunhofer.de/artifactory/eis-ids-public</url>
94+
</repository>
95+
</repositories>
96+
</project>
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
package io.adminshell.aas.v3.dataformat.aasx;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.io.StringWriter;
6+
import java.nio.charset.StandardCharsets;
7+
import java.util.ArrayList;
8+
import java.util.Collection;
9+
import java.util.List;
10+
11+
import javax.xml.parsers.ParserConfigurationException;
12+
13+
import org.apache.commons.io.IOUtils;
14+
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
15+
import org.apache.poi.openxml4j.opc.OPCPackage;
16+
import org.apache.poi.openxml4j.opc.PackagePart;
17+
import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
18+
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
19+
import org.xml.sax.SAXException;
20+
21+
import io.adminshell.aas.v3.dataformat.DeserializationException;
22+
import io.adminshell.aas.v3.dataformat.xml.XmlDeserializer;
23+
import io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment;
24+
import io.adminshell.aas.v3.model.File;
25+
import io.adminshell.aas.v3.model.Submodel;
26+
import io.adminshell.aas.v3.model.SubmodelElement;
27+
import io.adminshell.aas.v3.model.SubmodelElementCollection;
28+
29+
/**
30+
* The AASX package converter converts a aasx package into a list of aas, a list
31+
* of submodels a list of assets, a list of Concept descriptions
32+
*
33+
* The aas provides the references to the submodels and assets
34+
*
35+
* @author zhangzai, conradi
36+
*
37+
*/
38+
public class AASXDeserializer {
39+
40+
private static final String XML_TYPE = "http://www.admin-shell.io/aasx/relationships/aas-spec";
41+
private static final String AASX_ORIGIN = "/aasx/aasx-origin";
42+
43+
private XmlDeserializer deserializer = new XmlDeserializer();
44+
45+
private AssetAdministrationShellEnvironment environment;
46+
private OPCPackage aasxRoot;
47+
48+
public AASXDeserializer(InputStream inputStream) throws InvalidFormatException, IOException {
49+
aasxRoot = OPCPackage.open(inputStream);
50+
}
51+
52+
public AASXDeserializer(XmlDeserializer deserializer, InputStream inputStream) throws InvalidFormatException, IOException {
53+
aasxRoot = OPCPackage.open(inputStream);
54+
this.deserializer = deserializer;
55+
}
56+
57+
public AssetAdministrationShellEnvironment read() throws InvalidFormatException, IOException, DeserializationException {
58+
59+
// If the XML was already parsed return cached environment
60+
if (environment != null) {
61+
return environment;
62+
}
63+
64+
environment = deserializer.read(getXMLResourceString(aasxRoot));
65+
66+
return environment;
67+
}
68+
69+
/**
70+
* Return the Content of the xml file in the aasx-package as String
71+
*
72+
* @param aasxPackage
73+
* - the root package of the AASX
74+
* @return Content of XML as String
75+
* @throws InvalidFormatException
76+
* @throws IOException
77+
*/
78+
private String getXMLResourceString(OPCPackage aasxPackage) throws InvalidFormatException, IOException {
79+
80+
// Get the "/aasx/aasx-origin" Part. It is Relationship source for the
81+
// XML-Document
82+
PackagePart originPart = aasxPackage.getPart(PackagingURIHelper.createPartName(AASX_ORIGIN));
83+
84+
// Get the Relation to the XML Document
85+
PackageRelationshipCollection originRelationships = originPart.getRelationshipsByType(XML_TYPE);
86+
87+
// If there is more than one or no XML-Document that is an error
88+
if (originRelationships.size() > 1) {
89+
throw new RuntimeException("More than one 'aasx-spec' document found in .aasx");
90+
} else if (originRelationships.size() == 0) {
91+
throw new RuntimeException("No 'aasx-spec' document found in .aasx");
92+
}
93+
94+
// Get the PackagePart of the XML-Document
95+
PackagePart xmlPart = originPart.getRelatedPart(originRelationships.getRelationship(0));
96+
97+
// Read the content from the PackagePart
98+
InputStream stream = xmlPart.getInputStream();
99+
StringWriter writer = new StringWriter();
100+
IOUtils.copy(stream, writer, StandardCharsets.UTF_8);
101+
return writer.toString();
102+
}
103+
104+
/**
105+
* Load the referenced filepaths in the submodels such as PDF, PNG files from
106+
* the package
107+
*
108+
* @return a map of the folder name and folder path, the folder holds the files
109+
* @throws IOException
110+
* @throws SAXException
111+
* @throws ParserConfigurationException
112+
* @throws InvalidFormatException
113+
* @throws DeserializationException
114+
*
115+
*/
116+
private List<String> parseReferencedFilePathsFromAASX() throws IOException, InvalidFormatException, DeserializationException {
117+
118+
AssetAdministrationShellEnvironment environment = read();
119+
120+
List<String> paths = new ArrayList<String>();
121+
122+
for (Submodel sm : environment.getSubmodels()) {
123+
paths.addAll(parseElements(sm.getSubmodelElements()));
124+
}
125+
return paths;
126+
}
127+
128+
/**
129+
* Gets the paths from a collection of ISubmodelElement
130+
*
131+
* @param elements
132+
* @return the Paths from the File elements
133+
*/
134+
private List<String> parseElements(Collection<SubmodelElement> elements) {
135+
List<String> paths = new ArrayList<String>();
136+
137+
for (SubmodelElement element : elements) {
138+
if (element instanceof File) {
139+
File file = (File) element;
140+
// If the path contains a "://", we can assume, that the Path is a link to an
141+
// other server
142+
// e.g. http://localhost:8080/aasx/...
143+
if (!file.getValue().contains("://")) {
144+
paths.add(file.getValue());
145+
}
146+
} else if (element instanceof SubmodelElementCollection) {
147+
SubmodelElementCollection collection = (SubmodelElementCollection) element;
148+
paths.addAll(parseElements(collection.getValues()));
149+
}
150+
}
151+
return paths;
152+
}
153+
154+
public List<InMemoryFile> getRelatedFiles() throws InvalidFormatException, IOException, DeserializationException {
155+
List<String> filePaths = parseReferencedFilePathsFromAASX();
156+
157+
List<InMemoryFile> files = new ArrayList<>();
158+
159+
for (String filePath : filePaths) {
160+
files.add(readFile(aasxRoot, filePath));
161+
}
162+
163+
return files;
164+
}
165+
166+
private InMemoryFile readFile(OPCPackage aasxRoot, String filePath) throws InvalidFormatException, IOException {
167+
PackagePart part = aasxRoot.getPart(PackagingURIHelper.createPartName(filePath));
168+
InputStream stream = part.getInputStream();
169+
return new InMemoryFile(stream.readAllBytes(), filePath);
170+
}
171+
}

0 commit comments

Comments
 (0)