Skip to content

Commit 7367f43

Browse files
ShehriyarShariq-FraunhoferaaronziFriedJannik
authored
feat: Added serialization endpoint to AAS Environment Client (#629)
* feat: Added serialization endpoint to AAS Environment Client * adds missing override * Update basyx.aasenvironment/basyx.aasenvironment-client/src/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/AuthorizedConnectedAasEnvironment.java Co-authored-by: Jannik Fried <Jannik.Fried@iese.fraunhofer.de> * Update basyx.aasenvironment/basyx.aasenvironment-client/src/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/ConnectedAasEnvironment.java Co-authored-by: Jannik Fried <Jannik.Fried@iese.fraunhofer.de> * Update basyx.aasenvironment/basyx.aasenvironment-client/src/test/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/TestAuthorizedConnectedAasEnvironment.java Co-authored-by: Jannik Fried <Jannik.Fried@iese.fraunhofer.de> * Update basyx.aasenvironment/basyx.aasenvironment-client/src/test/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/TestConnectedAasEnvironment.java Co-authored-by: Jannik Fried <Jannik.Fried@iese.fraunhofer.de> * Adds NOtImplementedException to loadEnvironment Overrides --------- Co-authored-by: Aaron Zielstorff <aaron.zi@web.de> Co-authored-by: Aaron Zielstorff <aaron.zielstorff@iese.fraunhofer.de> Co-authored-by: Jannik Fried <Jannik.Fried@iese.fraunhofer.de>
1 parent 7babc9f commit 7367f43

6 files changed

Lines changed: 851 additions & 0 deletions

File tree

basyx.aasenvironment/basyx.aasenvironment-client/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,11 @@
104104
<scope>test</scope>
105105
<classifier>tests</classifier>
106106
</dependency>
107+
<dependency>
108+
<groupId>org.eclipse.digitaltwin.basyx</groupId>
109+
<artifactId>basyx.submodelservice-core</artifactId>
110+
<classifier>tests</classifier>
111+
<scope>test</scope>
112+
</dependency>
107113
</dependencies>
108114
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2025 the Eclipse BaSyx Authors
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*
23+
* SPDX-License-Identifier: MIT
24+
******************************************************************************/
25+
26+
package org.eclipse.digitaltwin.basyx.aasenvironment.client;
27+
28+
import org.eclipse.digitaltwin.basyx.aasenvironment.client.internal.SerializationApi;
29+
import org.eclipse.digitaltwin.basyx.client.internal.authorization.TokenManager;
30+
31+
public class AuthorizedConnectedAasEnvironment extends ConnectedAasEnvironment {
32+
private TokenManager tokenManager;
33+
34+
public AuthorizedConnectedAasEnvironment(TokenManager tokenManager) {
35+
super(new SerializationApi("http", "localhost", 8081, tokenManager));
36+
this.tokenManager = tokenManager;
37+
}
38+
39+
public TokenManager getTokenManager() {
40+
return tokenManager;
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2025 the Eclipse BaSyx Authors
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*
23+
* SPDX-License-Identifier: MIT
24+
******************************************************************************/
25+
26+
package org.eclipse.digitaltwin.basyx.aasenvironment.client;
27+
28+
import java.io.IOException;
29+
import java.nio.charset.StandardCharsets;
30+
import java.util.List;
31+
32+
import org.apache.commons.lang3.NotImplementedException;
33+
import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.SerializationException;
34+
import org.eclipse.digitaltwin.basyx.aasenvironment.AasEnvironment;
35+
import org.eclipse.digitaltwin.basyx.aasenvironment.client.internal.SerializationApi;
36+
import org.eclipse.digitaltwin.basyx.aasenvironment.environmentloader.CompleteEnvironment;
37+
import org.springframework.core.io.ByteArrayResource;
38+
import org.springframework.core.io.Resource;
39+
40+
public class ConnectedAasEnvironment implements AasEnvironment {
41+
protected static final String ENVIRONMENT_BASE_PATH = "http://localhost:8081";
42+
43+
private final SerializationApi serializationApi;
44+
45+
ConnectedAasEnvironment() {
46+
this.serializationApi = new SerializationApi(ENVIRONMENT_BASE_PATH);
47+
}
48+
49+
public ConnectedAasEnvironment(String environmentBaseUrl) {
50+
this.serializationApi = new SerializationApi(environmentBaseUrl);
51+
}
52+
53+
ConnectedAasEnvironment(SerializationApi serializationApi) {
54+
this.serializationApi = serializationApi;
55+
}
56+
57+
/**
58+
* Generates serialization by IDs
59+
*
60+
* @param serializationFormat the format in which the serialization is required
61+
* @param aasIds the list of AAS IDs to be serialized
62+
* @param submodelIds the list of Submodel IDs to be serialized
63+
* @param includeConceptDescriptions whether to include concept descriptions
64+
* @return The serialized object as a byte array or stream
65+
*/
66+
public Resource generateSerializationByIds(String serializationFormat, List<String> aasIds, List<String> submodelIds, boolean includeConceptDescriptions) {
67+
try {
68+
return serializationApi.generateSerializationByIds(serializationFormat, aasIds, submodelIds, includeConceptDescriptions);
69+
} catch (Exception e) {
70+
// Handle the exception, wrap it, or rethrow it as appropriate
71+
throw new RuntimeException("Error generating serialization", e);
72+
}
73+
}
74+
75+
@Override
76+
public String createJSONAASEnvironmentSerialization(List<String> aasIds, List<String> submodelIds,
77+
boolean includeConceptDescriptions) throws SerializationException {
78+
try {
79+
Resource res = serializationApi.generateSerializationByIds("application/json", aasIds, submodelIds, includeConceptDescriptions);
80+
81+
String jsonStr = new String(((ByteArrayResource) res).getByteArray(), StandardCharsets.UTF_8);
82+
83+
return jsonStr;
84+
} catch (Exception e) {
85+
throw new RuntimeException("Error generating serialization", e);
86+
}
87+
}
88+
89+
@Override
90+
public String createXMLAASEnvironmentSerialization(List<String> aasIds, List<String> submodelIds,
91+
boolean includeConceptDescriptions) throws SerializationException {
92+
try {
93+
Resource res = serializationApi.generateSerializationByIds("application/xml", aasIds, submodelIds, includeConceptDescriptions);
94+
95+
String jsonStr = new String(((ByteArrayResource) res).getByteArray(), StandardCharsets.UTF_8);
96+
97+
return jsonStr;
98+
} catch (Exception e) {
99+
throw new RuntimeException("Error generating serialization", e);
100+
}
101+
}
102+
103+
@Override
104+
public byte[] createAASXAASEnvironmentSerialization(List<String> aasIds, List<String> submodelIds,
105+
boolean includeConceptDescriptions) throws SerializationException, IOException {
106+
try {
107+
Resource res = serializationApi.generateSerializationByIds("application/asset-administration-shell-package+xml", aasIds, submodelIds, includeConceptDescriptions);
108+
return ((ByteArrayResource) res).getByteArray();
109+
} catch (Exception e) {
110+
throw new RuntimeException("Error generating serialization", e);
111+
}
112+
}
113+
114+
@Override
115+
public void loadEnvironment(CompleteEnvironment completeEnvironment, boolean ignoreDuplicates) {
116+
throw new NotImplementedException(
117+
"loadEnvironment(CompleteEnvironment completeEnvironment, boolean ignoreDuplicates) is not yet implemented");
118+
}
119+
120+
@Override
121+
public void loadEnvironment(CompleteEnvironment completeEnvironment) {
122+
throw new NotImplementedException(
123+
"loadEnvironment(CompleteEnvironment completeEnvironment) is not yet implemented");
124+
}
125+
}

0 commit comments

Comments
 (0)