Skip to content

Commit 135cff2

Browse files
Merge pull request #257 from eclipse-basyx/release/1.3.1
Release/1.3.1
2 parents 2351106 + a794df5 commit 135cff2

File tree

26 files changed

+197
-110
lines changed

26 files changed

+197
-110
lines changed

basyx.components/basyx.components.docker/basyx.components.AASServer/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
FROM openjdk:11-slim-bullseye
22

3-
# Install dependency for wait-for-it-env.sh
3+
# Install dependency for wait-for-it-env.sh & wget for health check
44
RUN apt update && apt install -y jq && apt clean
5+
RUN apt install -y wget
56

67
# Copy built jar to image using the jar name specified in the pom.xml (JAR_FILE)
78
ARG JAR_FILE
@@ -18,6 +19,7 @@ COPY target/${JAR_FILE} /usr/share/basyxExecutable.jar
1819
COPY target/lib /usr/share/lib
1920
COPY src/main/resources/aas.properties /usr/share/config/aas.properties
2021
COPY src/main/resources/context.properties /usr/share/config/context.properties
22+
COPY src/main/resources/mqtt.properties /usr/share/config/mqtt.properties
2123
COPY src/test/resources/dockerMongodb.properties /usr/share/config/mongodb.properties
2224

2325
# Expose the appropriate port. In case of Tomcat, this is 8080.

basyx.components/basyx.components.docker/basyx.components.AASServer/pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.eclipse.basyx</groupId>
99
<artifactId>basyx.components.docker</artifactId>
10-
<version>1.3.0</version>
10+
<version>1.3.1</version>
1111
</parent>
1212

1313
<artifactId>basyx.components.AASServer</artifactId>
@@ -80,14 +80,14 @@
8080
<dependency>
8181
<groupId>org.mongodb</groupId>
8282
<artifactId>mongodb-driver-sync</artifactId>
83-
<version>4.8.1</version>
83+
<version>4.8.2</version>
8484
</dependency>
8585

8686
<!-- Use Spring Data MongoDB for db data management -->
8787
<dependency>
8888
<groupId>org.springframework.data</groupId>
8989
<artifactId>spring-data-mongodb</artifactId>
90-
<version>3.4.6</version>
90+
<version>3.4.7</version>
9191
</dependency>
9292

9393
<!-- Adds additional classes of the BaSys SDK for tests -->
@@ -108,7 +108,7 @@
108108
<dependency>
109109
<groupId>io.moquette</groupId>
110110
<artifactId>moquette-broker</artifactId>
111-
<version>0.15</version>
111+
<version>0.16</version>
112112
<scope>test</scope>
113113
<exclusions>
114114
<exclusion>
@@ -121,14 +121,14 @@
121121
<dependency>
122122
<groupId>org.eclipse.basyx</groupId>
123123
<artifactId>basyx.components.registry</artifactId>
124-
<version>1.3.0</version>
124+
<version>1.3.1</version>
125125
<scope>test</scope>
126126
</dependency>
127127
<dependency>
128128
<groupId>com.tngtech.keycloakmock</groupId>
129129
<artifactId>mock</artifactId>
130130
<scope>test</scope>
131-
<version>0.12.0</version>
131+
<version>0.13.0</version>
132132
</dependency>
133133

134134
<dependency>

basyx.components/basyx.components.docker/basyx.components.AASServer/src/main/java/org/eclipse/basyx/components/aas/AASServerComponent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,9 @@ private VABHTTPInterface<?> createAggregatorServlet() {
540540

541541
private IAASAggregator createAASAggregator() {
542542
if (isMongoDBBackend()) {
543-
return new MongoDBAASServerComponentFactory(createMongoDbConfiguration(), createAASServerDecoratorList(), registry).create();
543+
try (final var ignored = ElevatedCodeAuthentication.enterElevatedCodeAuthenticationArea()) {
544+
return new MongoDBAASServerComponentFactory(createMongoDbConfiguration(), createAASServerDecoratorList(), registry).create();
545+
}
544546
}
545547
return new InMemoryAASServerComponentFactory(createAASServerDecoratorList(), registry).create();
546548
}

basyx.components/basyx.components.docker/basyx.components.AASServer/src/main/java/org/eclipse/basyx/components/aas/mongodb/MongoDBAASAPI.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ public void setAAS(AssetAdministrationShell aas) {
161161
if (replaced == null) {
162162
mongoOps.insert(aas, collection);
163163
}
164+
// Remove mongoDB-specific map attribute from AAS.
165+
// mongoOps modify aas on save - thus _id has to be removed here...
166+
aas.remove("_id");
164167
}
165168

166169
@Override
@@ -170,7 +173,7 @@ public IAssetAdministrationShell getAAS() {
170173
if (aas == null) {
171174
throw new ResourceNotFoundException("The AAS " + aasId + " could not be found in the database.");
172175
}
173-
// Remove mongoDB-specific map attribute from AASDescriptor
176+
// Remove mongoDB-specific map attribute from AAS
174177
aas.remove("_id");
175178
return aas;
176179
}

basyx.components/basyx.components.docker/basyx.components.AASServer/src/main/java/org/eclipse/basyx/components/aas/mongodb/MongoDBSubmodelAPI.java

Lines changed: 38 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import org.eclipse.basyx.vab.exception.provider.ResourceNotFoundException;
5454
import org.eclipse.basyx.vab.modelprovider.VABPathTools;
5555
import org.eclipse.basyx.vab.modelprovider.api.IModelProvider;
56+
import org.eclipse.basyx.vab.modelprovider.lambda.VABLambdaProvider;
5657
import org.eclipse.basyx.vab.modelprovider.map.VABMapProvider;
5758
import org.eclipse.basyx.vab.protocol.http.connector.HTTPConnectorFactory;
5859
import org.springframework.data.mongodb.core.MongoOperations;
@@ -205,12 +206,12 @@ public void setSubmodel(Submodel sm) {
205206
String id = sm.getIdentification().getId();
206207
this.setSubmodelId(id);
207208

208-
Query hasId = query(where(SMIDPATH).is(smId));
209-
Object replaced = mongoOps.findAndReplace(hasId, sm, collection);
209+
Submodel replaced = writeSubmodelInDB(sm);
210210
if (replaced == null) {
211211
mongoOps.insert(sm, collection);
212212
}
213-
213+
// Remove mongoDB-specific map attribute from SM
214+
// mongoOps modify sm on save - thus _id has to be removed here...
214215
sm.remove("_id");
215216
}
216217

@@ -249,9 +250,7 @@ public void addSubmodelElement(ISubmodelElement elem) {
249250
Submodel sm = (Submodel) getSubmodel();
250251
// Add element
251252
sm.addSubmodelElement(elem);
252-
// Replace db entry
253-
Query hasId = query(where(SMIDPATH).is(smId));
254-
mongoOps.findAndReplace(hasId, sm, collection);
253+
writeSubmodelInDB(sm);
255254
}
256255

257256
private ISubmodelElement getTopLevelSubmodelElement(String idShort) {
@@ -278,9 +277,7 @@ private void deleteTopLevelSubmodelElement(String idShort) {
278277
Submodel sm = (Submodel) getSubmodel();
279278
// Remove element
280279
sm.getSubmodelElements().remove(idShort);
281-
// Replace db entry
282-
Query hasId = query(where(SMIDPATH).is(smId));
283-
mongoOps.findAndReplace(hasId, sm, collection);
280+
writeSubmodelInDB(sm);
284281
}
285282

286283
@Override
@@ -298,16 +295,12 @@ private void addNestedSubmodelElement(List<String> idShorts, ISubmodelElement el
298295
ISubmodelElement parentElement = getNestedSubmodelElement(sm, idShorts);
299296
if (parentElement instanceof SubmodelElementCollection) {
300297
((SubmodelElementCollection) parentElement).addSubmodelElement(elem);
301-
// Replace db entry
302-
Query hasId = query(where(SMIDPATH).is(smId));
303-
mongoOps.findAndReplace(hasId, sm, collection);
298+
writeSubmodelInDB(sm);
304299
}
305300
} else {
306301
// else => directly add it to the submodel
307302
sm.addSubmodelElement(elem);
308-
// Replace db entry
309-
Query hasId = query(where(SMIDPATH).is(smId));
310-
mongoOps.findAndReplace(hasId, sm, collection);
303+
writeSubmodelInDB(sm);
311304
}
312305
}
313306

@@ -317,33 +310,20 @@ public Collection<ISubmodelElement> getSubmodelElements() {
317310
return sm.getSubmodelElements().values();
318311
}
319312

320-
private void updateTopLevelSubmodelElement(String idShort, Object newValue) {
321-
// Get sm from db
322-
Submodel sm = (Submodel) getSubmodel();
323-
// Unwrap value
324-
newValue = unwrapParameter(newValue);
325-
// Get and update property value
326-
getElementProvider(sm, idShort).setValue(Property.VALUE, newValue);
327-
// Replace db entry
328-
Query hasId = query(where(SMIDPATH).is(smId));
329-
mongoOps.findAndReplace(hasId, sm, collection);
330-
}
331-
332313
@SuppressWarnings("unchecked")
333-
private void updateNestedSubmodelElement(List<String> idShorts, Object newValue) {
314+
private void updateSubmodelElementInDB(List<String> idShorts, Object newValue) {
334315
Submodel sm = (Submodel) getSubmodel();
335-
336-
// Get parent SM element
337316
ISubmodelElement element = getNestedSubmodelElement(sm, idShorts);
338317

339-
// Update value
340-
IModelProvider mapProvider = new VABMapProvider((Map<String, Object>) element);
341-
IModelProvider elemProvider = SubmodelElementProvider.getElementProvider(mapProvider);
342-
elemProvider.setValue(Property.VALUE, newValue);
318+
IModelProvider mapProvider = new VABLambdaProvider((Map<String, Object>) element);
319+
SubmodelElementProvider smeProvider = new SubmodelElementProvider(mapProvider);
343320

344-
// Replace db entry
345-
Query hasId = query(where(SMIDPATH).is(smId));
346-
mongoOps.findAndReplace(hasId, sm, collection);
321+
smeProvider.setValue(Property.VALUE, newValue);
322+
ISubmodelElement updatedElement = SubmodelElementFacadeFactory.createSubmodelElement((Map<String, Object>) smeProvider.getValue(""));
323+
324+
sm.addSubmodelElement(updatedElement);
325+
326+
writeSubmodelInDB(sm);
347327
}
348328

349329
private Object getTopLevelSubmodelElementValue(String idShort) {
@@ -354,8 +334,8 @@ private Object getTopLevelSubmodelElementValue(String idShort) {
354334
@SuppressWarnings("unchecked")
355335
private Object getNestedSubmodelElementValue(List<String> idShorts) {
356336
ISubmodelElement lastElement = getNestedSubmodelElement(idShorts);
357-
IModelProvider mapProvider = new VABMapProvider((Map<String, Object>) lastElement);
358-
return SubmodelElementProvider.getElementProvider(mapProvider).getValue("/value");
337+
IModelProvider mapProvider = new VABLambdaProvider((Map<String, Object>) lastElement);
338+
return new SubmodelElementProvider(mapProvider).getValue("/value");
359339
}
360340

361341
@SuppressWarnings("unchecked")
@@ -373,10 +353,10 @@ protected Object unwrapParameter(Object parameter) {
373353
}
374354

375355
@SuppressWarnings("unchecked")
376-
private IModelProvider getElementProvider(Submodel sm, String idShortPath) {
377-
ISubmodelElement elem = sm.getSubmodelElement(idShortPath);
356+
private static SubmodelElementProvider getElementProvider(Submodel sm, String idShort) {
357+
ISubmodelElement elem = sm.getSubmodelElement(idShort);
378358
IModelProvider mapProvider = new VABMapProvider((Map<String, Object>) elem);
379-
return SubmodelElementProvider.getElementProvider(mapProvider);
359+
return new SubmodelElementProvider(mapProvider);
380360
}
381361

382362
private ISubmodelElement getNestedSubmodelElement(Submodel sm, List<String> idShorts) {
@@ -419,9 +399,7 @@ private void deleteNestedSubmodelElement(List<String> idShorts) {
419399
// Remove element
420400
SubmodelElementCollection coll = (SubmodelElementCollection) parentElement;
421401
coll.deleteSubmodelElement(idShorts.get(idShorts.size() - 1));
422-
// Replace db entry
423-
Query hasId = query(where(SMIDPATH).is(smId));
424-
mongoOps.findAndReplace(hasId, sm, collection);
402+
writeSubmodelInDB(sm);
425403
}
426404

427405
private Object invokeNestedOperationAsync(List<String> idShorts, Object... params) {
@@ -459,13 +437,20 @@ public void deleteSubmodelElement(String idShortPath) {
459437

460438
@Override
461439
public void updateSubmodelElement(String idShortPath, Object newValue) {
462-
if (idShortPath.contains("/")) {
463-
String[] splitted = VABPathTools.splitPath(idShortPath);
464-
List<String> idShorts = Arrays.asList(splitted);
465-
updateNestedSubmodelElement(idShorts, newValue);
466-
} else {
467-
updateTopLevelSubmodelElement(idShortPath, newValue);
468-
}
440+
String[] splitted = VABPathTools.splitPath(idShortPath);
441+
List<String> idShorts = Arrays.asList(splitted);
442+
updateSubmodelElementInDB(idShorts, newValue);
443+
}
444+
445+
/**
446+
* Returns the updated Submodel or null if not found
447+
*
448+
* @param sm
449+
* @return
450+
*/
451+
private Submodel writeSubmodelInDB(Submodel sm) {
452+
Query hasId = query(where(SMIDPATH).is(smId));
453+
return mongoOps.findAndReplace(hasId, sm, collection);
469454
}
470455

471456
@Override
@@ -482,10 +467,7 @@ public Object getSubmodelElementValue(String idShortPath) {
482467
@SuppressWarnings("unchecked")
483468
@Override
484469
public Object invokeOperation(String idShortPath, Object... params) {
485-
486-
String elementPath = VABPathTools.getParentPath(idShortPath);
487-
488-
Operation operation = (Operation) SubmodelElementFacadeFactory.createSubmodelElement((Map<String, Object>) getSubmodelElement(elementPath));
470+
Operation operation = (Operation) SubmodelElementFacadeFactory.createSubmodelElement((Map<String, Object>) getSubmodelElement(idShortPath));
489471
if (!DelegatedInvocationManager.isDelegatingOperation(operation)) {
490472
throw new MalformedRequestException("This backend supports only delegating operations.");
491473
}

basyx.components/basyx.components.docker/basyx.components.AASServer/src/main/java/org/eclipse/basyx/components/aas/mqtt/MqttAASServerFeature.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public void initialize() {
6666

6767
protected MqttConnectOptions createMqttConnectOptions() {
6868
MqttConnectOptions options = new MqttConnectOptions();
69+
options.setAutomaticReconnect(true);
6970
if (!Strings.isNullOrEmpty(mqttConfig.getUser())) {
7071
options.setUserName(mqttConfig.getUser());
7172
options.setPassword(mqttConfig.getPass().toCharArray());

basyx.components/basyx.components.docker/basyx.components.AASServer/src/main/resources/mqtt.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ server=tcp://localhost:1883
4141
# ##################
4242
# Whitelist for filtering mqtt events for specific submodels / submodelelements
4343

44-
whitelist.patientTemplate=true
45-
whitelist.element.patientTemplate.active=true
4644
# whitelist.element.{mySmIdentifier}.{elementIdShort}=true
4745

4846
# ##################

basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/MqttAASServerSuite.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import static org.junit.Assert.assertEquals;
2828
import static org.junit.Assert.assertTrue;
2929
import static org.junit.Assert.fail;
30+
3031
import java.io.IOException;
32+
3133
import org.eclipse.basyx.aas.metamodel.map.AssetAdministrationShell;
3234
import org.eclipse.basyx.aas.metamodel.map.descriptor.CustomId;
3335
import org.eclipse.basyx.components.aas.AASServerComponent;
@@ -47,6 +49,7 @@
4749
import org.junit.AfterClass;
4850
import org.junit.Before;
4951
import org.junit.Test;
52+
5053
import io.moquette.broker.Server;
5154
import io.moquette.broker.config.ClasspathResourceLoader;
5255
import io.moquette.broker.config.IConfig;
@@ -113,7 +116,7 @@ public void shellLifeCycle() {
113116
}
114117

115118
@Test
116-
public void submodelLifeCycle() {
119+
public void submodelLifeCycle() throws InterruptedException {
117120
IIdentifier shellIdentifierForSubmodel = new CustomId("shellSubmodelId");
118121
AssetAdministrationShell shell = createShell(shellIdentifierForSubmodel.getId(), shellIdentifierForSubmodel);
119122
manager.createAAS(shell, getURL());
@@ -128,6 +131,8 @@ public void submodelLifeCycle() {
128131

129132
manager.deleteSubmodel(shellIdentifierForSubmodel, submodelIdentifier);
130133

134+
waitForPropagation();
135+
131136
assertTrue(listener.getTopics().stream().anyMatch(t -> t.equals(MqttAASAPIHelper.TOPIC_REMOVESUBMODEL)));
132137
assertTrue(listener.getTopics().stream().anyMatch(t -> t.equals(MqttSubmodelAggregatorHelper.TOPIC_DELETESUBMODEL)));
133138
try {
@@ -139,6 +144,10 @@ public void submodelLifeCycle() {
139144
manager.deleteAAS(shellIdentifierForSubmodel);
140145
}
141146

147+
private void waitForPropagation() throws InterruptedException {
148+
Thread.sleep(1000);
149+
}
150+
142151
protected static BaSyxContextConfiguration createBaSyxContextConfiguration() {
143152
BaSyxContextConfiguration config = new BaSyxContextConfiguration();
144153
config.loadFromResource(BaSyxContextConfiguration.DEFAULT_CONFIG_PATH);

0 commit comments

Comments
 (0)