Skip to content

Commit 75bd05c

Browse files
Merge pull request #105 from eclipse-basyx/release/1.2.0
Release/1.2.0
2 parents 4690323 + 7d5ad98 commit 75bd05c

File tree

51 files changed

+1535
-186
lines changed

Some content is hidden

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

51 files changed

+1535
-186
lines changed

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>org.eclipse.basyx</groupId>
77
<artifactId>basyx.sdk</artifactId>
8-
<version>1.1.0</version>
8+
<version>1.2.0</version>
99
<name>BaSyx SDK</name>
1010
<description>BaSyx Software Development Kit</description>
1111
<url>https://www.eclipse.org/basyx/</url>
@@ -62,13 +62,13 @@
6262
<testSourceDirectory>src/test/java</testSourceDirectory>
6363

6464
<plugins>
65-
<!-- Compile Sources using Java 8 -->
65+
<!-- Compile Sources using Java 11 -->
6666
<plugin>
6767
<artifactId>maven-compiler-plugin</artifactId>
6868
<version>3.8.1</version>
6969
<configuration>
70-
<source>1.8</source>
71-
<target>1.8</target>
70+
<source>11</source>
71+
<target>11</target>
7272
</configuration>
7373
</plugin>
7474

@@ -241,7 +241,7 @@
241241
<dependency>
242242
<groupId>org.apache.tomcat</groupId>
243243
<artifactId>tomcat-catalina</artifactId>
244-
<version>8.5.41</version>
244+
<version>9.0.64</version>
245245
</dependency>
246246

247247
<!-- Used for creating .aasx files -->

src/main/java/org/eclipse/basyx/aas/aggregator/AASAggregatorAPIHelper.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,14 @@ public static String getAASEntryPath(IIdentifier aasId) {
6262
public static String getAASAccessPath(IIdentifier aasId) {
6363
return VABPathTools.concatenatePaths(getAASEntryPath(aasId), AASAggregatorAPIHelper.AAS_SUFFIX);
6464
}
65+
66+
/**
67+
* Removes the "/shells" suffix if it exists
68+
*
69+
* @param url
70+
* @return
71+
*/
72+
public static String harmonizeURL(String url) {
73+
return VABPathTools.stripFromPath(url, AASAggregatorProvider.PREFIX);
74+
}
6575
}

src/main/java/org/eclipse/basyx/aas/aggregator/proxy/AASAggregatorProxy.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,13 @@
3030

3131
import org.eclipse.basyx.aas.aggregator.AASAggregatorAPIHelper;
3232
import org.eclipse.basyx.aas.aggregator.api.IAASAggregator;
33-
import org.eclipse.basyx.aas.aggregator.restapi.AASAggregatorProvider;
3433
import org.eclipse.basyx.aas.metamodel.api.IAssetAdministrationShell;
3534
import org.eclipse.basyx.aas.metamodel.connected.ConnectedAssetAdministrationShell;
3635
import org.eclipse.basyx.aas.metamodel.map.AssetAdministrationShell;
3736
import org.eclipse.basyx.aas.registration.proxy.AASRegistryProxy;
3837
import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
3938
import org.eclipse.basyx.vab.coder.json.connector.JSONConnector;
4039
import org.eclipse.basyx.vab.modelprovider.VABElementProxy;
41-
import org.eclipse.basyx.vab.modelprovider.VABPathTools;
4240
import org.eclipse.basyx.vab.modelprovider.api.IModelProvider;
4341
import org.eclipse.basyx.vab.protocol.http.connector.HTTPConnector;
4442
import org.slf4j.Logger;
@@ -75,7 +73,7 @@ public AASAggregatorProxy(IModelProvider provider) {
7573
* @return
7674
*/
7775
protected static String harmonizeURL(String url) {
78-
return VABPathTools.stripFromPath(url, AASAggregatorProvider.PREFIX);
76+
return AASAggregatorAPIHelper.harmonizeURL(url);
7977
}
8078

8179
@SuppressWarnings("unchecked")

src/main/java/org/eclipse/basyx/aas/manager/ConnectedAssetAdministrationShellManager.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,12 @@ public void deleteSubmodel(IIdentifier aasId, IIdentifier submodelId) {
167167

168168
@Override
169169
public void createAAS(AssetAdministrationShell aas, String endpoint) {
170-
endpoint = VABPathTools.stripSlashes(endpoint);
170+
String harmonizedEndpoint = AASAggregatorAPIHelper.harmonizeURL(endpoint);
171171

172-
IModelProvider provider = connectorFactory.create(endpoint);
172+
IModelProvider provider = connectorFactory.create(harmonizedEndpoint);
173173
AASAggregatorProxy proxy = new AASAggregatorProxy(provider);
174174
proxy.createAAS(aas);
175-
String combinedEndpoint = VABPathTools.concatenatePaths(endpoint, AASAggregatorAPIHelper.getAASAccessPath(aas.getIdentification()));
175+
String combinedEndpoint = VABPathTools.concatenatePaths(harmonizedEndpoint, AASAggregatorAPIHelper.getAASAccessPath(aas.getIdentification()));
176176
aasDirectory.register(new AASDescriptor(aas, combinedEndpoint));
177-
178177
}
179178
}

src/main/java/org/eclipse/basyx/aas/metamodel/map/AasEnv.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ public class AasEnv extends VABModelMap<Object> implements IAasEnv {
5858
public AasEnv() {
5959
// Add model type
6060
putAll(new ModelType(MODELTYPE));
61+
put(ASSETADMINISTRATIONSHELLS, new ArrayList<IAssetAdministrationShell>());
62+
put(SUBMODELS, new ArrayList<ISubmodel>());
63+
put(ASSETS, new ArrayList<IAsset>());
64+
put(CONCEPTDESCRIPTIONS, new ArrayList<IConceptDescription>());
6165
}
6266

6367
public AasEnv(Collection<IAssetAdministrationShell> aasList, Collection<IAsset> assetList, Collection<IConceptDescription> conceptDescriptionList, Collection<ISubmodel> submodelList) {

src/main/java/org/eclipse/basyx/aas/registration/observing/ObservableAASRegistryService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public void delete(IIdentifier aasId) throws ProviderException {
7171

7272
@Override
7373
public void delete(IIdentifier aasId, IIdentifier smId) throws ProviderException {
74+
aasRegistry.delete(aasId, smId);
7475
observers.stream().forEach(o -> o.submodelDeleted(aasId, smId));
7576
}
7677

src/main/java/org/eclipse/basyx/aas/restapi/AASModelProvider.java

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@
2424
******************************************************************************/
2525
package org.eclipse.basyx.aas.restapi;
2626

27+
import java.util.LinkedHashMap;
2728
import java.util.Map;
2829

2930
import org.eclipse.basyx.aas.metamodel.map.AssetAdministrationShell;
3031
import org.eclipse.basyx.aas.restapi.api.IAASAPI;
3132
import org.eclipse.basyx.aas.restapi.vab.VABAASAPI;
33+
import org.eclipse.basyx.submodel.metamodel.api.identifier.IdentifierType;
34+
import org.eclipse.basyx.submodel.metamodel.api.reference.enums.KeyElements;
3235
import org.eclipse.basyx.submodel.metamodel.map.Submodel;
36+
import org.eclipse.basyx.submodel.metamodel.map.identifier.Identifier;
37+
import org.eclipse.basyx.submodel.metamodel.map.qualifier.Identifiable;
38+
import org.eclipse.basyx.submodel.metamodel.map.reference.Reference;
3339
import org.eclipse.basyx.vab.exception.provider.MalformedRequestException;
3440
import org.eclipse.basyx.vab.exception.provider.NotAnInvokableException;
3541
import org.eclipse.basyx.vab.exception.provider.ProviderException;
@@ -77,12 +83,58 @@ public AASModelProvider(IAASAPI aasApi) {
7783
public Object getValue(String path) throws ProviderException {
7884
path = preparePath(path);
7985
if (path.isEmpty()) {
80-
return aasApi.getAAS();
86+
Object value = addAssetReferenceInAAS(aasApi.getAAS());
87+
return value;
8188
} else {
8289
throw new MalformedRequestException("Path " + path + " is not supported");
8390
}
8491
}
8592

93+
94+
/**
95+
* Add asset reference to asset of the aas
96+
*
97+
* @param aas
98+
* @return aas with the modified asset
99+
*/
100+
@SuppressWarnings("unchecked")
101+
private AssetAdministrationShell addAssetReferenceInAAS(Object value) {
102+
AssetAdministrationShell aas = (AssetAdministrationShell) value;
103+
Map<String, Object> asset = (Map<String, Object>) aas.get(AssetAdministrationShell.ASSET);
104+
Map<String, Object> assetMap = addAssetReferenceToAsset(asset);
105+
aas.put(AssetAdministrationShell.ASSET, assetMap);
106+
return aas;
107+
}
108+
109+
/**
110+
* Add asset reference to an asset raw map
111+
*
112+
* @param asset
113+
* @return modified asset map
114+
*/
115+
private Map<String, Object> addAssetReferenceToAsset(Map<String, Object> asset) {
116+
Reference assetReference = createAssetReference(asset);
117+
Map<String, Object> modifiedAsset = new LinkedHashMap<>();
118+
modifiedAsset.put(Reference.KEY, assetReference.getKeys());
119+
modifiedAsset.putAll(asset);
120+
return modifiedAsset;
121+
}
122+
123+
/**
124+
* Create an asset reference from an asset raw map
125+
*
126+
* @param asset
127+
* @return asset reference
128+
*/
129+
private Reference createAssetReference(Map<String, Object> asset) {
130+
@SuppressWarnings("unchecked")
131+
Map<String, Object> assetIdMap = (Map<String, Object>) asset.get(Identifiable.IDENTIFICATION);
132+
String idType = (String) assetIdMap.get(Identifier.IDTYPE);
133+
String id = (String) assetIdMap.get(Identifier.ID);
134+
Identifier assetId = new Identifier(IdentifierType.fromString(idType), id);
135+
return new Reference(assetId, KeyElements.ASSET, true);
136+
}
137+
86138
@Override
87139
public void setValue(String path, Object newValue) throws ProviderException {
88140
throw new MalformedRequestException("For an AAS, Set is not supported");

src/main/java/org/eclipse/basyx/extensions/aas/api/mqtt/MqttAASAPIHelper.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
******************************************************************************/
2525
package org.eclipse.basyx.extensions.aas.api.mqtt;
2626

27+
import org.eclipse.basyx.aas.restapi.observing.ObservableAASAPI;
28+
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
29+
2730
/**
2831
* A helper class containing string constants of topics used by the AASAPI.
2932
*
@@ -33,4 +36,16 @@
3336
public class MqttAASAPIHelper {
3437
public static final String TOPIC_ADDSUBMODEL = "BaSyxAAS_addedSubmodelReference";
3538
public static final String TOPIC_REMOVESUBMODEL = "BaSyxAAS_removedSubmodelReference";
39+
40+
public static String getAASIdShort(ObservableAASAPI observedAPI) {
41+
return observedAPI.getAAS().getIdShort();
42+
}
43+
44+
public static MqttConnectOptions getMqttConnectOptions(String username, char[] password) {
45+
MqttConnectOptions options = new MqttConnectOptions();
46+
options.setUserName(username);
47+
options.setPassword(password);
48+
49+
return options;
50+
}
3651
}

src/main/java/org/eclipse/basyx/extensions/aas/api/mqtt/MqttAASAPIObserver.java

Lines changed: 74 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.eclipse.basyx.submodel.metamodel.api.reference.IReference;
3232
import org.eclipse.paho.client.mqttv3.MqttClient;
3333
import org.eclipse.paho.client.mqttv3.MqttClientPersistence;
34+
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
3435
import org.eclipse.paho.client.mqttv3.MqttException;
3536
import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence;
3637
import org.slf4j.Logger;
@@ -40,34 +41,74 @@
4041
* Implementation of {@link IAASAPIObserver} Triggers MQTT events for different
4142
* operations on the AAS.
4243
*
43-
* @author fried
44+
* @author fried, danish
4445
*
4546
*/
4647
public class MqttAASAPIObserver extends MqttEventService implements IAASAPIObserver {
4748
private static Logger logger = LoggerFactory.getLogger(MqttAASAPIObserver.class);
48-
49-
// The underlying AASAPI
50-
protected ObservableAASAPI observedAPI;
49+
50+
private String aasIdShort;
51+
52+
/**
53+
* Constructor for adding this MQTT extension on top of another AASAPI
54+
*
55+
* @param client
56+
* An already connected mqtt client
57+
* @param aasIdShort
58+
*
59+
* @throws MqttException
60+
*/
61+
public MqttAASAPIObserver(MqttClient client, String aasIdShort) throws MqttException {
62+
super(client);
63+
64+
connectMqttClientIfRequired();
65+
66+
this.aasIdShort = aasIdShort;
67+
}
68+
69+
/**
70+
* Constructor for adding this MQTT extension on top of another AASAPI
71+
*
72+
* @param client
73+
* An already connected mqtt client
74+
* @param aasIdShort
75+
* @param options
76+
*
77+
* @throws MqttException
78+
*/
79+
public MqttAASAPIObserver(MqttClient client, String aasIdShort, MqttConnectOptions options) throws MqttException {
80+
super(client);
81+
82+
connectMqttClientIfRequired(options);
83+
84+
this.aasIdShort = aasIdShort;
85+
}
5186

5287
/**
5388
* Constructor for adding this MQTT extension on top of another AASAPI
5489
*
5590
* @param observedAPI
5691
* The underlying aasAPI
5792
* @throws MqttException
93+
*
94+
* @deprecated This constructor is deprecated please use {@link #MqttAASAPIObserver(MqttClient, String)} instead.
5895
*/
96+
@Deprecated
5997
public MqttAASAPIObserver(ObservableAASAPI observedAPI, String serverEndpoint, String clientId) throws MqttException {
6098
this(observedAPI, serverEndpoint, clientId, new MqttDefaultFilePersistence());
6199
}
62100

63101
/**
64102
* Constructor for adding this MQTT extension on top of another AASAPI with a
65103
* custom persistence strategy
104+
*
105+
* @deprecated This constructor is deprecated please use {@link #MqttAASAPIObserver(MqttClient, String)} instead.
66106
*/
107+
@Deprecated
67108
public MqttAASAPIObserver(ObservableAASAPI observedAPI, String brokerEndpoint, String clientId, MqttClientPersistence persistence) throws MqttException {
68-
super(brokerEndpoint, clientId, persistence);
109+
this(new MqttClient(brokerEndpoint, clientId, persistence), MqttAASAPIHelper.getAASIdShort(observedAPI));
69110
logger.info("Create new MQTT AASAPI for endpoint " + brokerEndpoint);
70-
this.observedAPI = observedAPI;
111+
71112
observedAPI.addObserver(this);
72113
}
73114

@@ -77,19 +118,25 @@ public MqttAASAPIObserver(ObservableAASAPI observedAPI, String brokerEndpoint, S
77118
* @param observedAPI
78119
* The underlying aasAPI
79120
* @throws MqttException
121+
*
122+
* @deprecated This constructor is deprecated please use {@link #MqttAASAPIObserver(MqttClient, String, MqttConnectOptions)} instead.
80123
*/
124+
@Deprecated
81125
public MqttAASAPIObserver(ObservableAASAPI observedAPI, String serverEndpoint, String clientId, String user, char[] pw) throws MqttException {
82126
this(observedAPI, serverEndpoint, clientId, user, pw, new MqttDefaultFilePersistence());
83127
}
84128

85129
/**
86130
* Constructor for adding this MQTT extension on top of another AASAPI with
87131
* credentials and persistency strategy
132+
*
133+
* @deprecated This constructor is deprecated please use {@link #MqttAASAPIObserver(MqttClient, String, MqttConnectOptions)} instead.
88134
*/
135+
@Deprecated
89136
public MqttAASAPIObserver(ObservableAASAPI observedAPI, String serverEndpoint, String clientId, String user, char[] pw, MqttClientPersistence persistence) throws MqttException {
90-
super(serverEndpoint, clientId, user, pw);
137+
this(new MqttClient(serverEndpoint, clientId, persistence), MqttAASAPIHelper.getAASIdShort(observedAPI), MqttAASAPIHelper.getMqttConnectOptions(user, pw));
91138
logger.info("Create new MQTT AASAPI for endpoint " + serverEndpoint);
92-
this.observedAPI = observedAPI;
139+
93140
observedAPI.addObserver(this);
94141
}
95142

@@ -101,26 +148,41 @@ public MqttAASAPIObserver(ObservableAASAPI observedAPI, String serverEndpoint, S
101148
* @param client
102149
* An already connected mqtt client
103150
* @throws MqttException
151+
*
152+
* @deprecated This constructor is deprecated please use {@link #MqttAASAPIObserver(MqttClient, String)} instead.
104153
*/
154+
@Deprecated
105155
public MqttAASAPIObserver(ObservableAASAPI observedAPI, MqttClient client) throws MqttException {
106-
super(client);
107-
this.observedAPI = observedAPI;
156+
this(client, MqttAASAPIHelper.getAASIdShort(observedAPI));
157+
108158
observedAPI.addObserver(this);
109159
}
160+
161+
private void connectMqttClientIfRequired() throws MqttException {
162+
if(!mqttClient.isConnected()) {
163+
mqttClient.connect();
164+
}
165+
}
166+
167+
private void connectMqttClientIfRequired(MqttConnectOptions options) throws MqttException {
168+
if(!mqttClient.isConnected()) {
169+
mqttClient.connect(options);
170+
}
171+
}
110172

111173
@Override
112174
public void submodelAdded(IReference submodelReference) {
113175
for (IKey key : submodelReference.getKeys()) {
114176
if (key.getType().name().equalsIgnoreCase("Submodel")) {
115177
String id = key.getValue();
116-
sendMqttMessage(MqttAASAPIHelper.TOPIC_ADDSUBMODEL, getCombinedMessage(observedAPI.getAAS().getIdShort(), id));
178+
sendMqttMessage(MqttAASAPIHelper.TOPIC_ADDSUBMODEL, getCombinedMessage(aasIdShort, id));
117179
}
118180
}
119181
}
120182

121183
@Override
122184
public void submodelRemoved(String id) {
123-
sendMqttMessage(MqttAASAPIHelper.TOPIC_REMOVESUBMODEL, getCombinedMessage(observedAPI.getAAS().getIdShort(), id));
185+
sendMqttMessage(MqttAASAPIHelper.TOPIC_REMOVESUBMODEL, getCombinedMessage(aasIdShort, id));
124186
}
125187

126188
public static String getCombinedMessage(String aasId, String idShort) {

src/main/java/org/eclipse/basyx/extensions/aas/api/mqtt/MqttDecoratingAASAPIFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/**
2121
* Factory decorating AASAPI with MQTT events by wrapping an IAASAPIFactory
2222
*
23-
* @author fried
23+
* @author fried, danish
2424
*/
2525
public class MqttDecoratingAASAPIFactory implements IAASAPIFactory {
2626
private IAASAPIFactory apiFactory;
@@ -35,7 +35,8 @@ public MqttDecoratingAASAPIFactory(IAASAPIFactory factoryToBeDecorated, MqttClie
3535
public IAASAPI getAASApi(AssetAdministrationShell aas) {
3636
try {
3737
ObservableAASAPI observedAPI = new ObservableAASAPI(apiFactory.create(aas));
38-
new MqttAASAPIObserver(observedAPI, client);
38+
MqttAASAPIObserver mqttAASAPIObserver = new MqttAASAPIObserver(client, MqttAASAPIHelper.getAASIdShort(observedAPI));
39+
observedAPI.addObserver(mqttAASAPIObserver);
3940
return observedAPI;
4041
} catch (MqttException e) {
4142
throw new ProviderException(e);

0 commit comments

Comments
 (0)