From f4537627df87a62734b34fe0e98a479e27289de4 Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Fri, 10 Nov 2023 08:19:01 +0100 Subject: [PATCH 01/21] Adds skeleton for the AAS Repo Reg Int Signed-off-by: Mohammad Ghazanfar Ali Danish --- .../Readme.md | 8 + .../pom.xml | 61 ++++++ .../RegistryIntegrationAasRepository.java | 192 ++++++++++++++++++ ...IntegrationAasRepositoryConfiguration.java | 48 +++++ ...gistryIntegrationAasRepositoryFactory.java | 49 +++++ ...gistryIntegrationAasRepositoryFeature.java | 74 +++++++ ...yIntegrationAasRepositoryTopicFactory.java | 96 +++++++++ .../mqtt/TestMqttV2AASAggregatorObserver.java | 168 +++++++++++++++ .../src/test/resources/config/moquette.conf | 6 + basyx.aasrepository/pom.xml | 1 + pom.xml | 47 +++-- 11 files changed, 730 insertions(+), 20 deletions(-) create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/Readme.md create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/pom.xml create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryTopicFactory.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestMqttV2AASAggregatorObserver.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/config/moquette.conf diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/Readme.md b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/Readme.md new file mode 100644 index 000000000..630d235d9 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/Readme.md @@ -0,0 +1,8 @@ +# AssetAdministrationShell Repository - MQTT Eventing +This feature provides hierarchical MQTT eventing for a multitude of events: + +| Event |Topic | Payload | +| ----------- | ----------- | --- | +| AAS Created | /aas-repository/\$repoId/shells/created| Created AAS JSON | +| AAS Updated | /aas-repository/\$repoId/shells/updated| Updated AAS JSON| +| AAS Deleted | /aas-repository/\$repoId/shells/deleted| Deleted AAS JSON| \ No newline at end of file diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/pom.xml b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/pom.xml new file mode 100644 index 000000000..694882cf5 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/pom.xml @@ -0,0 +1,61 @@ + + 4.0.0 + + + org.eclipse.digitaltwin.basyx + basyx.aasrepository + ${revision} + + + basyx.aasrepository-feature-registry-integration + + + + org.eclipse.digitaltwin.basyx + basyx.aasregistry-client-native + + + org.eclipse.digitaltwin.basyx + basyx.aasrepository-core + + + org.eclipse.digitaltwin.basyx + basyx.mqttcore + + + org.eclipse.digitaltwin.basyx + basyx.aasrepository-core + tests + test + + + org.eclipse.digitaltwin.basyx + basyx.aasrepository-backend-inmemory + test + + + org.eclipse.digitaltwin.basyx + basyx.aasservice-backend-inmemory + test + + + org.eclipse.digitaltwin.aas4j + dataformat-json + + + org.springframework.boot + spring-boot-starter + + + org.eclipse.paho + org.eclipse.paho.client.mqttv3 + + + io.moquette + moquette-broker + test + + + \ No newline at end of file diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java new file mode 100644 index 000000000..1d9fa1793 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java @@ -0,0 +1,192 @@ +/******************************************************************************* + * Copyright (C) 2021 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import java.util.List; + +import org.eclipse.digitaltwin.aas4j.v3.dataformat.SerializationException; +import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.JsonSerializer; +import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; +import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; +import org.eclipse.digitaltwin.basyx.aasregistry.client.ApiException; +import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor; +import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; +import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException; +import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; +import org.eclipse.digitaltwin.basyx.core.pagination.CursorResult; +import org.eclipse.digitaltwin.basyx.core.pagination.PaginationInfo; +import org.eclipse.paho.client.mqttv3.IMqttClient; +import org.eclipse.paho.client.mqttv3.MqttException; +import org.eclipse.paho.client.mqttv3.MqttMessage; +import org.eclipse.paho.client.mqttv3.MqttPersistenceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Observer for the AASAggregator that triggers MQTT events for different + * operations on the aggregator. + * + * @author haque, jungjan, fischer, siebert + * + */ +public class RegistryIntegrationAasRepository implements AasRepository { + private static Logger logger = LoggerFactory.getLogger(RegistryIntegrationAasRepository.class); + + private AasRepository decorated; + + private RegistryAndDiscoveryInterfaceApi registryApi; + + + public RegistryIntegrationAasRepository(AasRepository decorated, RegistryAndDiscoveryInterfaceApi registryApi) { + this.decorated = decorated; + this.registryApi = registryApi; + } + + @Override + public CursorResult> getAllAas(PaginationInfo pInfo) { + return decorated.getAllAas(pInfo); + } + + @Override + public AssetAdministrationShell getAas(String aasId) throws ElementDoesNotExistException { + return decorated.getAas(aasId); + } + + @Override + public void createAas(AssetAdministrationShell aas) throws CollidingIdentifierException { + decorated.createAas(aas); + + integrateAasWithRegistry(aas); + } + + private void integrateAasWithRegistry(AssetAdministrationShell aas) { + AssetAdministrationShellDescriptor descriptor = new AssetAdministrationShellDescriptor(); + descriptor.idShort(aas.getIdShort()); + aas.getDisplayName(); + descriptor.addDisplayNameItem(null); + + try { + registryApi.postAssetAdministrationShellDescriptor(null); + } catch (ApiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Override + public void updateAas(String aasId, AssetAdministrationShell aas) { + decorated.updateAas(aasId, aas); + aasUpdated(aas, getName()); + } + + @Override + public void deleteAas(String aasId) { + AssetAdministrationShell shell = decorated.getAas(aasId); + decorated.deleteAas(aasId); + aasDeleted(shell, getName()); + } + + @Override + public String getName() { + return decorated.getName(); + } + + @Override + public CursorResult> getSubmodelReferences(String aasId, PaginationInfo pInfo) { + return decorated.getSubmodelReferences(aasId, pInfo); + } + + @Override + public void addSubmodelReference(String aasId, Reference submodelReference) { + decorated.addSubmodelReference(aasId, submodelReference); + } + + @Override + public void removeSubmodelReference(String aasId, String submodelId) { + decorated.removeSubmodelReference(aasId, submodelId); + } + + @Override + public void setAssetInformation(String aasId, AssetInformation aasInfo) throws ElementDoesNotExistException { + decorated.setAssetInformation(aasId, aasInfo); + } + + @Override + public AssetInformation getAssetInformation(String aasId) throws ElementDoesNotExistException { + return decorated.getAssetInformation(aasId); + } + + private void aasCreated(AssetAdministrationShell shell, String repoId) { + sendMqttMessage(topicFactory.createCreateAASTopic(repoId), serializePayload(shell)); + } + + private void aasUpdated(AssetAdministrationShell shell, String repoId) { + sendMqttMessage(topicFactory.createUpdateAASTopic(repoId), serializePayload(shell)); + } + + private void aasDeleted(AssetAdministrationShell shell, String repoId) { + sendMqttMessage(topicFactory.createDeleteAASTopic(repoId), serializePayload(shell)); + } + + private String serializePayload(AssetAdministrationShell shell) { + try { + return new JsonSerializer().write(shell); + } catch (SerializationException e) { + throw new RuntimeException(e); + } + } + + /** + * Sends MQTT message to connected broker + * + * @param topic + * in which the message will be published + * @param payload + * the actual message + */ + private void sendMqttMessage(String topic, String payload) { + MqttMessage msg = createMqttMessage(payload); + + try { + logger.debug("Send MQTT message to " + topic + ": " + payload); + mqttClient.publish(topic, msg); + } catch (MqttPersistenceException e) { + logger.error("Could not persist mqtt message", e); + } catch (MqttException e) { + logger.error("Could not send mqtt message", e); + } + } + + private MqttMessage createMqttMessage(String payload) { + if (payload == null) { + return new MqttMessage(); + } else { + return new MqttMessage(payload.getBytes()); + } + } + +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java new file mode 100644 index 000000000..4029cd1e4 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + + +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; +import org.eclipse.paho.client.mqttv3.MqttException; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.feature.registryintegration:}')") +public class RegistryIntegrationAasRepositoryConfiguration { + + @Bean + @ConditionalOnMissingBean + public RegistryAndDiscoveryInterfaceApi mqttClient(@Value("${basyx.aasrepository.feature.registryintegration}") String registryBasePath) throws MqttException { + + return new RegistryAndDiscoveryInterfaceApi(registryBasePath); + } + +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java new file mode 100644 index 000000000..65f1c8944 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + + +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; +import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; +import org.eclipse.digitaltwin.basyx.aasrepository.AasRepositoryFactory; +import org.eclipse.paho.client.mqttv3.IMqttClient; + +public class RegistryIntegrationAasRepositoryFactory implements AasRepositoryFactory { + + private AasRepositoryFactory decorated; + private RegistryAndDiscoveryInterfaceApi registryApi; + + public RegistryIntegrationAasRepositoryFactory(AasRepositoryFactory decorated, RegistryAndDiscoveryInterfaceApi registryApi) { + this.decorated = decorated; + this.registryApi = registryApi; + } + + @Override + public AasRepository create() { + return new RegistryIntegrationAasRepository(decorated.create(), registryApi); + } + +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java new file mode 100644 index 000000000..d56f74c65 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + + +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; +import org.eclipse.digitaltwin.basyx.aasrepository.AasRepositoryFactory; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.AasRepositoryFeature; +import org.eclipse.digitaltwin.basyx.common.mqttcore.encoding.URLEncoder; +import org.eclipse.paho.client.mqttv3.IMqttClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.stereotype.Component; + +@Component +@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.feature.registryintegration:}')") +public class RegistryIntegrationAasRepositoryFeature implements AasRepositoryFeature { + public final static String FEATURENAME = "basyx.aasrepository.feature.registryintegration"; + + private RegistryAndDiscoveryInterfaceApi registryApi; + + @Autowired + public RegistryIntegrationAasRepositoryFeature(RegistryAndDiscoveryInterfaceApi registryApi) { + this.registryApi = registryApi; + } + + @Override + public AasRepositoryFactory decorate(AasRepositoryFactory aasRepositoryFactory) { + return new RegistryIntegrationAasRepositoryFactory(aasRepositoryFactory, registryApi); + } + + @Override + public void initialize() { + } + + @Override + public void cleanUp() { + + } + + @Override + public String getName() { + return "AasRepository Registry Integration"; + } + + @Override + public boolean isEnabled() { + return true; + } +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryTopicFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryTopicFactory.java new file mode 100644 index 000000000..bb6c3bbe5 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryTopicFactory.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (C) 2021 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import java.util.StringJoiner; + +import org.eclipse.digitaltwin.basyx.common.mqttcore.AbstractMqttTopicFactory; +import org.eclipse.digitaltwin.basyx.common.mqttcore.encoding.Encoder; + +/** + * A helper class containing methods that create topics used by the + * AASAggregator. + * + */ +public class RegistryIntegrationAasRepositoryTopicFactory extends AbstractMqttTopicFactory { + private static final String AASREPOSITORY = "aas-repository"; + private static final String SHELLS = "shells"; + private static final String CREATED = "created"; + private static final String UPDATED = "updated"; + private static final String DELETED = "deleted"; + + /** + * @param encoder + * Used for encoding the aasId/submodelId + */ + public RegistryIntegrationAasRepositoryTopicFactory(Encoder encoder) { + super(encoder); + } + + /** + * Creates the hierarchical topic for the create event + * + * @param repoId + * @return + */ + public String createCreateAASTopic(String repoId) { + return new StringJoiner("/", "", "") + .add(AASREPOSITORY) + .add(repoId) + .add(SHELLS) + .add(CREATED) + .toString(); + } + + /** + * Creates the hierarchical topic for the update event + * + * @param repoId + * @return + */ + public String createUpdateAASTopic(String repoId) { + return new StringJoiner("/", "", "") + .add(AASREPOSITORY) + .add(repoId) + .add(SHELLS) + .add(UPDATED) + .toString(); + } + + /** + * Creates the hierarchical topic for the delete event + * + * @param repoId + * @return + */ + public String createDeleteAASTopic(String repoId) { + return new StringJoiner("/", "", "") + .add(AASREPOSITORY) + .add(repoId) + .add(SHELLS) + .add(DELETED) + .toString(); + } +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestMqttV2AASAggregatorObserver.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestMqttV2AASAggregatorObserver.java new file mode 100644 index 000000000..e9ea1ffe9 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestMqttV2AASAggregatorObserver.java @@ -0,0 +1,168 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.mqtt; + +/******************************************************************************* + * Copyright (C) 2021 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.digitaltwin.aas4j.v3.dataformat.DeserializationException; +import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.JsonDeserializer; +import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetAdministrationShell; +import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; +import org.eclipse.digitaltwin.basyx.aasrepository.AasRepositoryFactory; +import org.eclipse.digitaltwin.basyx.aasrepository.AasRepositorySuite; +import org.eclipse.digitaltwin.basyx.aasrepository.backend.SimpleAasRepositoryFactory; +import org.eclipse.digitaltwin.basyx.aasrepository.backend.inmemory.AasInMemoryBackendProvider; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.RegistryIntegrationAasRepositoryFactory; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.RegistryIntegrationAasRepositoryTopicFactory; +import org.eclipse.digitaltwin.basyx.aasservice.backend.InMemoryAasServiceFactory; +import org.eclipse.digitaltwin.basyx.common.mqttcore.encoding.Base64URLEncoder; +import org.eclipse.digitaltwin.basyx.common.mqttcore.encoding.URLEncoder; +import org.eclipse.digitaltwin.basyx.common.mqttcore.listener.MqttTestListener; +import org.eclipse.paho.client.mqttv3.MqttClient; +import org.eclipse.paho.client.mqttv3.MqttException; +import org.eclipse.paho.client.mqttv3.MqttSecurityException; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import io.moquette.broker.Server; +import io.moquette.broker.config.ClasspathResourceLoader; +import io.moquette.broker.config.IConfig; +import io.moquette.broker.config.IResourceLoader; +import io.moquette.broker.config.ResourceLoaderConfig; + +/** + * Tests events emitting with the MqttAASAggregatorObserver + * + * @author haque, siebert, schnicke, danish + * + */ +public class TestMqttV2AASAggregatorObserver { + private static Server mqttBroker; + private static MqttClient mqttClient; + private static MqttTestListener listener; + private static RegistryIntegrationAasRepositoryTopicFactory topicFactory = new RegistryIntegrationAasRepositoryTopicFactory(new Base64URLEncoder()); + + private static AasRepository aasRepository; + + @BeforeClass + public static void setUpClass() throws MqttException, IOException { + mqttBroker = startBroker(); + + listener = configureInterceptListener(mqttBroker); + + mqttClient = createAndConnectClient(); + + aasRepository = createMqttAasRepository(mqttClient); + } + + @AfterClass + public static void tearDownClass() { + mqttBroker.removeInterceptHandler(listener); + mqttBroker.stopServer(); + } + + @Test + public void createAasEvent() throws DeserializationException { + AssetAdministrationShell shell = createAasDummy("createAasEventId"); + aasRepository.createAas(shell); + + assertEquals(topicFactory.createCreateAASTopic(aasRepository.getName()), listener.lastTopic); + assertEquals(shell, deserializePayload(listener.lastPayload)); + } + + @Test + public void updateAasEvent() throws DeserializationException { + AssetAdministrationShell shell = createAasDummy("updateAasEventId"); + aasRepository.createAas(shell); + + addSubmodelReferenceToAas(shell); + + aasRepository.updateAas(shell.getId(), shell); + + assertEquals(topicFactory.createUpdateAASTopic(aasRepository.getName()), listener.lastTopic); + assertEquals(shell, deserializePayload(listener.lastPayload)); + } + + @Test + public void deleteAasEvent() throws DeserializationException { + AssetAdministrationShell shell = createAasDummy("deleteAasEventId"); + aasRepository.createAas(shell); + aasRepository.deleteAas(shell.getId()); + + assertEquals(topicFactory.createDeleteAASTopic(aasRepository.getName()), listener.lastTopic); + assertEquals(shell, deserializePayload(listener.lastPayload)); + } + + private AssetAdministrationShell deserializePayload(String payload) throws DeserializationException { + return new JsonDeserializer().readReferable(payload, AssetAdministrationShell.class); + } + + private void addSubmodelReferenceToAas(AssetAdministrationShell shell) { + List submodelReferences = Arrays.asList(AasRepositorySuite.createDummyReference("dummySubmodelId1")); + shell.setSubmodels(submodelReferences); + } + + private AssetAdministrationShell createAasDummy(String aasId) { + return new DefaultAssetAdministrationShell.Builder().id(aasId) + .build(); + } + + private static AasRepository createMqttAasRepository(MqttClient client) { + AasRepositoryFactory repoFactory = new SimpleAasRepositoryFactory(new AasInMemoryBackendProvider(), new InMemoryAasServiceFactory()); + + return new RegistryIntegrationAasRepositoryFactory(repoFactory, client, new RegistryIntegrationAasRepositoryTopicFactory(new URLEncoder())).create(); + } + + private static MqttTestListener configureInterceptListener(Server broker) { + MqttTestListener testListener = new MqttTestListener(); + broker.addInterceptHandler(testListener); + + return testListener; + } + + private static MqttClient createAndConnectClient() throws MqttException, MqttSecurityException { + MqttClient client = new MqttClient("tcp://localhost:1884", "testClient"); + client.connect(); + return client; + } + + private static Server startBroker() throws IOException { + Server broker = new Server(); + IResourceLoader classpathLoader = new ClasspathResourceLoader(); + + IConfig classPathConfig = new ResourceLoaderConfig(classpathLoader); + broker.startServer(classPathConfig); + + return broker; + } +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/config/moquette.conf b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/config/moquette.conf new file mode 100644 index 000000000..8511afcd1 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/config/moquette.conf @@ -0,0 +1,6 @@ +# Moquette Java Broker configuration file for testing + +# Do not use the default 1883 port +port 1884 +host 0.0.0.0 +allow_anonymous true \ No newline at end of file diff --git a/basyx.aasrepository/pom.xml b/basyx.aasrepository/pom.xml index 57329c5c3..d628ddf59 100644 --- a/basyx.aasrepository/pom.xml +++ b/basyx.aasrepository/pom.xml @@ -18,6 +18,7 @@ basyx.aasrepository-backend-mongodb basyx.aasrepository-feature-aasxupload basyx.aasrepository-feature-mqtt + basyx.aasrepository-feature-registry-integration basyx.aasrepository-tck basyx.aasrepository.component diff --git a/pom.xml b/pom.xml index ef8775129..74e1abc2b 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ basyx.aasregistry basyx.aasenvironment basyx.conceptdescriptionrepository - basyx.aasxfileserver + basyx.aasxfileserver basyx.aasdiscoveryservice BaSyx Parent @@ -36,7 +36,8 @@ - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. + Fraunhofer-Gesellschaft zur Foerderung der angewandten + Forschung e.V. fschnicke Frank Schnicke frank.schnicke@iese.fraunhofer.de @@ -288,14 +289,14 @@ ${revision} - org.eclipse.digitaltwin.basyx - basyx.submodelservice.component - ${revision} + org.eclipse.digitaltwin.basyx + basyx.submodelservice.component + ${revision} - org.eclipse.digitaltwin.basyx - basyx.submodelservice-http - ${revision} + org.eclipse.digitaltwin.basyx + basyx.submodelservice-http + ${revision} @@ -441,7 +442,7 @@ org.eclipse.digitaltwin.basyx basyx.conceptdescriptionrepository.component ${revision} - + org.eclipse.digitaltwin.basyx @@ -478,7 +479,7 @@ org.eclipse.digitaltwin.basyx basyx.aasxfileserver-core ${revision} - + org.eclipse.digitaltwin.basyx basyx.aasxfileserver-backend-inmemory @@ -489,6 +490,12 @@ basyx.aasxfileserver.component ${revision} + + + org.eclipse.digitaltwin.basyx + basyx.aasregistry-client-native + ${revision} + @@ -518,16 +525,16 @@ tests - org.eclipse.digitaltwin.basyx - basyx.submodelservice.component - ${revision} - tests + org.eclipse.digitaltwin.basyx + basyx.submodelservice.component + ${revision} + tests - org.eclipse.digitaltwin.basyx - basyx.submodelservice-http - ${revision} - tests + org.eclipse.digitaltwin.basyx + basyx.submodelservice-http + ${revision} + tests @@ -695,7 +702,7 @@ basyx.conceptdescriptionrepository.component ${revision} tests - + org.eclipse.digitaltwin.basyx @@ -732,7 +739,7 @@ basyx.aasdiscoveryservice.component ${revision} tests - + org.eclipse.digitaltwin.basyx From f754d49e7efd9970fb703a2b2b3a73e1552d3efc Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Mon, 13 Nov 2023 13:28:19 +0100 Subject: [PATCH 02/21] Implements RegistryLink basic working part in AAS Repository Signed-off-by: Mohammad Ghazanfar Ali Danish --- .../docker-compose/build-images.sh | 4 +- .../docker-compose/docker-compose.yml | 10 +- .../pom.xml | 4 + .../integration/AasDescriptorFactory.java | 54 +++++ .../AasRepositoryRegistryLink.java | 24 +++ .../RegistryIntegrationAasRepository.java | 91 ++------ ...IntegrationAasRepositoryConfiguration.java | 6 +- ...gistryIntegrationAasRepositoryFactory.java | 10 +- ...gistryIntegrationAasRepositoryFeature.java | 10 +- .../mqtt/TestMqttV2AASAggregatorObserver.java | 196 +++++++++--------- .../basyx.aasrepository.component/pom.xml | 4 + .../src/main/resources/application.properties | 4 + pom.xml | 5 + 13 files changed, 238 insertions(+), 184 deletions(-) create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java diff --git a/basyx.aasregistry/docker-compose/build-images.sh b/basyx.aasregistry/docker-compose/build-images.sh index ddfa72baf..b5104f815 100644 --- a/basyx.aasregistry/docker-compose/build-images.sh +++ b/basyx.aasregistry/docker-compose/build-images.sh @@ -4,7 +4,9 @@ trap 'cd $OLD_WORK_DIR' EXIT cd $(dirname "${BASH_SOURCE[0]}")/.. -MAVEN_OPS='-Xmx2048 -Xms1024' mvn clean install -DskipTests -Ddocker.username=aas-registry-test -Ddocker.password="" +MAVEN_OPS='-Xmx2048 -Xms1024' mvn clean install -e -DskipTests -Ddocker.username=mdanish98 -Ddocker.password="@@Danishali1" + +read -p "Press any key to continue... " -n1 -s cd $OLD_WORK_DIR diff --git a/basyx.aasregistry/docker-compose/docker-compose.yml b/basyx.aasregistry/docker-compose/docker-compose.yml index e1e694042..906711c86 100644 --- a/basyx.aasregistry/docker-compose/docker-compose.yml +++ b/basyx.aasregistry/docker-compose/docker-compose.yml @@ -108,7 +108,7 @@ services: - mongodb aas-registry-kafka-mongodb: - image: aas-registry-test/aas-registry-kafka-mongodb:latest + image: mdanish98/aas-registry-kafka-mongodb:latest container_name: aas-registry-kafka-mongodb pull_policy: never ports: @@ -124,7 +124,7 @@ services: - basyx aas-registry-kafka-mongodb-external-conf: - image: aas-registry-test/aas-registry-kafka-mongodb:latest + image: mdanish98/aas-registry-kafka-mongodb:latest container_name: aas-registry-kafka-mongodb-external-conf pull_policy: never ports: @@ -143,7 +143,7 @@ services: - basyx aas-registry-kafka-mem: - image: aas-registry-test/aas-registry-kafka-mem:latest + image: mdanish98/aas-registry-kafka-mem:latest container_name: aas-registry-kafka-mem pull_policy: never ports: @@ -157,7 +157,7 @@ services: - basyx aas-registry-log-mem: - image: aas-registry-test/aas-registry-log-mem:latest + image: mdanish98/aas-registry-log-mem:latest container_name: aas-registry-log-mem pull_policy: never ports: @@ -167,7 +167,7 @@ services: - basyx aas-registry-log-mongodb: - image: aas-registry-test/aas-registry-log-mongodb:latest + image: mdanish98/aas-registry-log-mongodb:latest container_name: aas-registry-log-mongodb pull_policy: never ports: diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/pom.xml b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/pom.xml index 694882cf5..81035d4cb 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/pom.xml +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/pom.xml @@ -24,6 +24,10 @@ org.eclipse.digitaltwin.basyx basyx.mqttcore + + org.eclipse.digitaltwin.basyx + basyx.http + org.eclipse.digitaltwin.basyx basyx.aasrepository-core diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java new file mode 100644 index 000000000..8b5486c4b --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java @@ -0,0 +1,54 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetAdministrationShell; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Endpoint; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ProtocolInformation; +import org.eclipse.digitaltwin.basyx.common.mqttcore.encoding.Base64URLEncoder; +import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; + +public class AasDescriptorFactory { + + private AssetAdministrationShell shell; + private String aasRepositoryURL; + + public AasDescriptorFactory(AssetAdministrationShell shell, String aasRepositoryURL) { + super(); + this.shell = shell; + this.aasRepositoryURL = aasRepositoryURL; + } + + public AssetAdministrationShellDescriptor create() { + + if (shell instanceof DefaultAssetAdministrationShell) + return createDescriptorFromDefaultAas(shell); + + return createDescriptor(shell); + } + + private AssetAdministrationShellDescriptor createDescriptor(AssetAdministrationShell shell) { + return null; + } + + private AssetAdministrationShellDescriptor createDescriptorFromDefaultAas(AssetAdministrationShell shell) { + String endpoint = aasRepositoryURL + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(shell.getId()); + + AssetAdministrationShellDescriptor descriptor = new AssetAdministrationShellDescriptor(); + descriptor.setId(shell.getId()); + descriptor.setIdShort(shell.getIdShort()); +// descriptor.addEndpointsItem(new Endpoint()); + + Endpoint endpoint2 = new Endpoint(); + endpoint2.setInterface(endpoint); + ProtocolInformation protocolInformation = new ProtocolInformation(); + protocolInformation.endpointProtocol("http"); + protocolInformation.setHref("http"); + endpoint2.setProtocolInformation(protocolInformation); + + descriptor.addEndpointsItem(endpoint2); + + return descriptor; + } + +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java new file mode 100644 index 000000000..b42353c41 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java @@ -0,0 +1,24 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; + +public class AasRepositoryRegistryLink { + + private RegistryAndDiscoveryInterfaceApi registryApi; + private String aasRepositoryURL; + + public AasRepositoryRegistryLink(RegistryAndDiscoveryInterfaceApi registryApi, String aasRepositoryURL) { + super(); + this.registryApi = registryApi; + this.aasRepositoryURL = aasRepositoryURL; + } + + public RegistryAndDiscoveryInterfaceApi getRegistryApi() { + return registryApi; + } + + public String getAasRepositoryURL() { + return aasRepositoryURL; + } + +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java index 1d9fa1793..79e1cd8f5 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java @@ -26,8 +26,6 @@ import java.util.List; -import org.eclipse.digitaltwin.aas4j.v3.dataformat.SerializationException; -import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.JsonSerializer; import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation; import org.eclipse.digitaltwin.aas4j.v3.model.Reference; @@ -39,10 +37,6 @@ import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; import org.eclipse.digitaltwin.basyx.core.pagination.CursorResult; import org.eclipse.digitaltwin.basyx.core.pagination.PaginationInfo; -import org.eclipse.paho.client.mqttv3.IMqttClient; -import org.eclipse.paho.client.mqttv3.MqttException; -import org.eclipse.paho.client.mqttv3.MqttMessage; -import org.eclipse.paho.client.mqttv3.MqttPersistenceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,12 +52,11 @@ public class RegistryIntegrationAasRepository implements AasRepository { private AasRepository decorated; - private RegistryAndDiscoveryInterfaceApi registryApi; + private AasRepositoryRegistryLink aasRepositoryRegistryLink; - - public RegistryIntegrationAasRepository(AasRepository decorated, RegistryAndDiscoveryInterfaceApi registryApi) { + public RegistryIntegrationAasRepository(AasRepository decorated, AasRepositoryRegistryLink aasRepositoryRegistryLink) { this.decorated = decorated; - this.registryApi = registryApi; + this.aasRepositoryRegistryLink = aasRepositoryRegistryLink; } @Override @@ -80,19 +73,20 @@ public AssetAdministrationShell getAas(String aasId) throws ElementDoesNotExistE public void createAas(AssetAdministrationShell aas) throws CollidingIdentifierException { decorated.createAas(aas); - integrateAasWithRegistry(aas); + integrateAasWithRegistry(aas, aasRepositoryRegistryLink.getAasRepositoryURL()); } - private void integrateAasWithRegistry(AssetAdministrationShell aas) { - AssetAdministrationShellDescriptor descriptor = new AssetAdministrationShellDescriptor(); - descriptor.idShort(aas.getIdShort()); - aas.getDisplayName(); + private void integrateAasWithRegistry(AssetAdministrationShell shell, String aasRepositoryURL) { + AssetAdministrationShellDescriptor descriptor = new AasDescriptorFactory(shell, aasRepositoryURL).create(); + descriptor.idShort(shell.getIdShort()); + shell.getDisplayName(); descriptor.addDisplayNameItem(null); + RegistryAndDiscoveryInterfaceApi registryApi = aasRepositoryRegistryLink.getRegistryApi(); + try { - registryApi.postAssetAdministrationShellDescriptor(null); + registryApi.postAssetAdministrationShellDescriptor(descriptor); } catch (ApiException e) { - // TODO Auto-generated catch block e.printStackTrace(); } } @@ -100,14 +94,24 @@ private void integrateAasWithRegistry(AssetAdministrationShell aas) { @Override public void updateAas(String aasId, AssetAdministrationShell aas) { decorated.updateAas(aasId, aas); - aasUpdated(aas, getName()); } @Override public void deleteAas(String aasId) { AssetAdministrationShell shell = decorated.getAas(aasId); decorated.deleteAas(aasId); - aasDeleted(shell, getName()); + + deleteFromRegistry(shell.getId()); + } + + private void deleteFromRegistry(String shellId) { + RegistryAndDiscoveryInterfaceApi registryApi = aasRepositoryRegistryLink.getRegistryApi(); + + try { + registryApi.deleteAssetAdministrationShellDescriptorById(shellId); + } catch (ApiException e) { + e.printStackTrace(); + } } @Override @@ -140,53 +144,4 @@ public AssetInformation getAssetInformation(String aasId) throws ElementDoesNotE return decorated.getAssetInformation(aasId); } - private void aasCreated(AssetAdministrationShell shell, String repoId) { - sendMqttMessage(topicFactory.createCreateAASTopic(repoId), serializePayload(shell)); - } - - private void aasUpdated(AssetAdministrationShell shell, String repoId) { - sendMqttMessage(topicFactory.createUpdateAASTopic(repoId), serializePayload(shell)); - } - - private void aasDeleted(AssetAdministrationShell shell, String repoId) { - sendMqttMessage(topicFactory.createDeleteAASTopic(repoId), serializePayload(shell)); - } - - private String serializePayload(AssetAdministrationShell shell) { - try { - return new JsonSerializer().write(shell); - } catch (SerializationException e) { - throw new RuntimeException(e); - } - } - - /** - * Sends MQTT message to connected broker - * - * @param topic - * in which the message will be published - * @param payload - * the actual message - */ - private void sendMqttMessage(String topic, String payload) { - MqttMessage msg = createMqttMessage(payload); - - try { - logger.debug("Send MQTT message to " + topic + ": " + payload); - mqttClient.publish(topic, msg); - } catch (MqttPersistenceException e) { - logger.error("Could not persist mqtt message", e); - } catch (MqttException e) { - logger.error("Could not send mqtt message", e); - } - } - - private MqttMessage createMqttMessage(String payload) { - if (payload == null) { - return new MqttMessage(); - } else { - return new MqttMessage(payload.getBytes()); - } - } - } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java index 4029cd1e4..298c1a23f 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java @@ -35,14 +35,14 @@ import org.springframework.context.annotation.Configuration; @Configuration -@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.feature.registryintegration:}')") +//@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.feature.registryintegration:}') && !T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.externalurl:}')") public class RegistryIntegrationAasRepositoryConfiguration { @Bean @ConditionalOnMissingBean - public RegistryAndDiscoveryInterfaceApi mqttClient(@Value("${basyx.aasrepository.feature.registryintegration}") String registryBasePath) throws MqttException { + public AasRepositoryRegistryLink mqttClient(@Value("${basyx.aasrepository.feature.registryintegration}") String registryBasePath, @Value("${basyx.aasrepository.externalurl}") String aasRepositoryURL) throws MqttException { - return new RegistryAndDiscoveryInterfaceApi(registryBasePath); + return new AasRepositoryRegistryLink(new RegistryAndDiscoveryInterfaceApi(registryBasePath), aasRepositoryURL); } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java index 65f1c8944..ccc64686d 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java @@ -34,16 +34,18 @@ public class RegistryIntegrationAasRepositoryFactory implements AasRepositoryFactory { private AasRepositoryFactory decorated; - private RegistryAndDiscoveryInterfaceApi registryApi; + private AasRepositoryRegistryLink aasRepositoryRegistryLink; + private String aasRepositoryURL; - public RegistryIntegrationAasRepositoryFactory(AasRepositoryFactory decorated, RegistryAndDiscoveryInterfaceApi registryApi) { + public RegistryIntegrationAasRepositoryFactory(AasRepositoryFactory decorated, AasRepositoryRegistryLink aasRepositoryRegistryLink) { this.decorated = decorated; - this.registryApi = registryApi; + this.aasRepositoryRegistryLink = aasRepositoryRegistryLink; + this.aasRepositoryURL = aasRepositoryURL; } @Override public AasRepository create() { - return new RegistryIntegrationAasRepository(decorated.create(), registryApi); + return new RegistryIntegrationAasRepository(decorated.create(), aasRepositoryRegistryLink); } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java index d56f74c65..f2381b97e 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java @@ -37,20 +37,20 @@ import org.springframework.stereotype.Component; @Component -@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.feature.registryintegration:}')") +//@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.feature.registryintegration:}')") public class RegistryIntegrationAasRepositoryFeature implements AasRepositoryFeature { public final static String FEATURENAME = "basyx.aasrepository.feature.registryintegration"; - private RegistryAndDiscoveryInterfaceApi registryApi; + private AasRepositoryRegistryLink aasRepositoryRegistryLink; @Autowired - public RegistryIntegrationAasRepositoryFeature(RegistryAndDiscoveryInterfaceApi registryApi) { - this.registryApi = registryApi; + public RegistryIntegrationAasRepositoryFeature(AasRepositoryRegistryLink aasRepositoryRegistryLink) { + this.aasRepositoryRegistryLink = aasRepositoryRegistryLink; } @Override public AasRepositoryFactory decorate(AasRepositoryFactory aasRepositoryFactory) { - return new RegistryIntegrationAasRepositoryFactory(aasRepositoryFactory, registryApi); + return new RegistryIntegrationAasRepositoryFactory(aasRepositoryFactory, aasRepositoryRegistryLink); } @Override diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestMqttV2AASAggregatorObserver.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestMqttV2AASAggregatorObserver.java index e9ea1ffe9..da4a1b726 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestMqttV2AASAggregatorObserver.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestMqttV2AASAggregatorObserver.java @@ -67,102 +67,102 @@ * */ public class TestMqttV2AASAggregatorObserver { - private static Server mqttBroker; - private static MqttClient mqttClient; - private static MqttTestListener listener; - private static RegistryIntegrationAasRepositoryTopicFactory topicFactory = new RegistryIntegrationAasRepositoryTopicFactory(new Base64URLEncoder()); - - private static AasRepository aasRepository; - - @BeforeClass - public static void setUpClass() throws MqttException, IOException { - mqttBroker = startBroker(); - - listener = configureInterceptListener(mqttBroker); - - mqttClient = createAndConnectClient(); - - aasRepository = createMqttAasRepository(mqttClient); - } - - @AfterClass - public static void tearDownClass() { - mqttBroker.removeInterceptHandler(listener); - mqttBroker.stopServer(); - } - - @Test - public void createAasEvent() throws DeserializationException { - AssetAdministrationShell shell = createAasDummy("createAasEventId"); - aasRepository.createAas(shell); - - assertEquals(topicFactory.createCreateAASTopic(aasRepository.getName()), listener.lastTopic); - assertEquals(shell, deserializePayload(listener.lastPayload)); - } - - @Test - public void updateAasEvent() throws DeserializationException { - AssetAdministrationShell shell = createAasDummy("updateAasEventId"); - aasRepository.createAas(shell); - - addSubmodelReferenceToAas(shell); - - aasRepository.updateAas(shell.getId(), shell); - - assertEquals(topicFactory.createUpdateAASTopic(aasRepository.getName()), listener.lastTopic); - assertEquals(shell, deserializePayload(listener.lastPayload)); - } - - @Test - public void deleteAasEvent() throws DeserializationException { - AssetAdministrationShell shell = createAasDummy("deleteAasEventId"); - aasRepository.createAas(shell); - aasRepository.deleteAas(shell.getId()); - - assertEquals(topicFactory.createDeleteAASTopic(aasRepository.getName()), listener.lastTopic); - assertEquals(shell, deserializePayload(listener.lastPayload)); - } - - private AssetAdministrationShell deserializePayload(String payload) throws DeserializationException { - return new JsonDeserializer().readReferable(payload, AssetAdministrationShell.class); - } - - private void addSubmodelReferenceToAas(AssetAdministrationShell shell) { - List submodelReferences = Arrays.asList(AasRepositorySuite.createDummyReference("dummySubmodelId1")); - shell.setSubmodels(submodelReferences); - } - - private AssetAdministrationShell createAasDummy(String aasId) { - return new DefaultAssetAdministrationShell.Builder().id(aasId) - .build(); - } - - private static AasRepository createMqttAasRepository(MqttClient client) { - AasRepositoryFactory repoFactory = new SimpleAasRepositoryFactory(new AasInMemoryBackendProvider(), new InMemoryAasServiceFactory()); - - return new RegistryIntegrationAasRepositoryFactory(repoFactory, client, new RegistryIntegrationAasRepositoryTopicFactory(new URLEncoder())).create(); - } - - private static MqttTestListener configureInterceptListener(Server broker) { - MqttTestListener testListener = new MqttTestListener(); - broker.addInterceptHandler(testListener); - - return testListener; - } - - private static MqttClient createAndConnectClient() throws MqttException, MqttSecurityException { - MqttClient client = new MqttClient("tcp://localhost:1884", "testClient"); - client.connect(); - return client; - } - - private static Server startBroker() throws IOException { - Server broker = new Server(); - IResourceLoader classpathLoader = new ClasspathResourceLoader(); - - IConfig classPathConfig = new ResourceLoaderConfig(classpathLoader); - broker.startServer(classPathConfig); - - return broker; - } +// private static Server mqttBroker; +// private static MqttClient mqttClient; +// private static MqttTestListener listener; +// private static RegistryIntegrationAasRepositoryTopicFactory topicFactory = new RegistryIntegrationAasRepositoryTopicFactory(new Base64URLEncoder()); +// +// private static AasRepository aasRepository; +// +// @BeforeClass +// public static void setUpClass() throws MqttException, IOException { +// mqttBroker = startBroker(); +// +// listener = configureInterceptListener(mqttBroker); +// +// mqttClient = createAndConnectClient(); +// +// aasRepository = createMqttAasRepository(mqttClient); +// } +// +// @AfterClass +// public static void tearDownClass() { +// mqttBroker.removeInterceptHandler(listener); +// mqttBroker.stopServer(); +// } +// +// @Test +// public void createAasEvent() throws DeserializationException { +// AssetAdministrationShell shell = createAasDummy("createAasEventId"); +// aasRepository.createAas(shell); +// +// assertEquals(topicFactory.createCreateAASTopic(aasRepository.getName()), listener.lastTopic); +// assertEquals(shell, deserializePayload(listener.lastPayload)); +// } +// +// @Test +// public void updateAasEvent() throws DeserializationException { +// AssetAdministrationShell shell = createAasDummy("updateAasEventId"); +// aasRepository.createAas(shell); +// +// addSubmodelReferenceToAas(shell); +// +// aasRepository.updateAas(shell.getId(), shell); +// +// assertEquals(topicFactory.createUpdateAASTopic(aasRepository.getName()), listener.lastTopic); +// assertEquals(shell, deserializePayload(listener.lastPayload)); +// } +// +// @Test +// public void deleteAasEvent() throws DeserializationException { +// AssetAdministrationShell shell = createAasDummy("deleteAasEventId"); +// aasRepository.createAas(shell); +// aasRepository.deleteAas(shell.getId()); +// +// assertEquals(topicFactory.createDeleteAASTopic(aasRepository.getName()), listener.lastTopic); +// assertEquals(shell, deserializePayload(listener.lastPayload)); +// } +// +// private AssetAdministrationShell deserializePayload(String payload) throws DeserializationException { +// return new JsonDeserializer().readReferable(payload, AssetAdministrationShell.class); +// } +// +// private void addSubmodelReferenceToAas(AssetAdministrationShell shell) { +// List submodelReferences = Arrays.asList(AasRepositorySuite.createDummyReference("dummySubmodelId1")); +// shell.setSubmodels(submodelReferences); +// } +// +// private AssetAdministrationShell createAasDummy(String aasId) { +// return new DefaultAssetAdministrationShell.Builder().id(aasId) +// .build(); +// } +// +// private static AasRepository createMqttAasRepository(MqttClient client) { +// AasRepositoryFactory repoFactory = new SimpleAasRepositoryFactory(new AasInMemoryBackendProvider(), new InMemoryAasServiceFactory()); +// +// return new RegistryIntegrationAasRepositoryFactory(repoFactory, client, new RegistryIntegrationAasRepositoryTopicFactory(new URLEncoder())).create(); +// } +// +// private static MqttTestListener configureInterceptListener(Server broker) { +// MqttTestListener testListener = new MqttTestListener(); +// broker.addInterceptHandler(testListener); +// +// return testListener; +// } +// +// private static MqttClient createAndConnectClient() throws MqttException, MqttSecurityException { +// MqttClient client = new MqttClient("tcp://localhost:1884", "testClient"); +// client.connect(); +// return client; +// } +// +// private static Server startBroker() throws IOException { +// Server broker = new Server(); +// IResourceLoader classpathLoader = new ClasspathResourceLoader(); +// +// IConfig classPathConfig = new ResourceLoaderConfig(classpathLoader); +// broker.startServer(classPathConfig); +// +// return broker; +// } } diff --git a/basyx.aasrepository/basyx.aasrepository.component/pom.xml b/basyx.aasrepository/basyx.aasrepository.component/pom.xml index fa3ca06a9..10f0e76d7 100644 --- a/basyx.aasrepository/basyx.aasrepository.component/pom.xml +++ b/basyx.aasrepository/basyx.aasrepository.component/pom.xml @@ -51,6 +51,10 @@ org.eclipse.digitaltwin.basyx basyx.aasrepository-feature-mqtt + + org.eclipse.digitaltwin.basyx + basyx.aasrepository-feature-registry-integration + org.eclipse.digitaltwin.basyx basyx.http diff --git a/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application.properties b/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application.properties index 4e939095a..1aaf4a247 100644 --- a/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application.properties +++ b/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application.properties @@ -6,6 +6,10 @@ basyx.aasrepo.name=aas-repo basyx.backend = InMemory +basyx.aasrepository.feature.registryintegration=http://localhost:8030/api/v3.0 + +basyx.aasrepository.externalurl=http://localhost:8081/shells + #basyx.backend = MongoDB #spring.data.mongodb.host=127.0.0.1 #spring.data.mongodb.port=27017 diff --git a/pom.xml b/pom.xml index 74e1abc2b..14c59ce74 100644 --- a/pom.xml +++ b/pom.xml @@ -391,6 +391,11 @@ basyx.aasrepository-feature-mqtt ${revision} + + org.eclipse.digitaltwin.basyx + basyx.aasrepository-feature-registry-integration + ${revision} + org.eclipse.digitaltwin.basyx basyx.aasrepository.component From de781c791198f4f47532a092fb71f41d2ae92314 Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Mon, 13 Nov 2023 18:34:55 +0100 Subject: [PATCH 03/21] Adds AAS Desc Factory and Clone Factory Signed-off-by: Mohammad Ghazanfar Ali Danish --- .../integration/AasDescriptorFactory.java | 137 +++++++++++++++--- .../registry/integration/AttributeMapper.java | 66 +++++++++ .../registry/integration/CloneFactory.java | 66 +++++++++ .../RegistryIntegrationAasRepository.java | 3 - ...IntegrationAasRepositoryConfiguration.java | 2 +- ...gistryIntegrationAasRepositoryFeature.java | 2 +- ...yIntegrationAasRepositoryTopicFactory.java | 96 ------------ .../mqtt/TestMqttV2AASAggregatorObserver.java | 1 - .../src/main/resources/application.properties | 1 - 9 files changed, 250 insertions(+), 124 deletions(-) create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryTopicFactory.java diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java index 8b5486c4b..f81a7d616 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java @@ -1,15 +1,23 @@ package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; + +import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetAdministrationShell; +import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.Extension; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Endpoint; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ProtocolInformation; -import org.eclipse.digitaltwin.basyx.common.mqttcore.encoding.Base64URLEncoder; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; public class AasDescriptorFactory { + private static final String AAS_INTERFACE = "AAS-3.0"; private AssetAdministrationShell shell; private String aasRepositoryURL; @@ -21,34 +29,121 @@ public AasDescriptorFactory(AssetAdministrationShell shell, String aasRepository public AssetAdministrationShellDescriptor create() { - if (shell instanceof DefaultAssetAdministrationShell) - return createDescriptorFromDefaultAas(shell); + AssetAdministrationShellDescriptor descriptor = new AssetAdministrationShellDescriptor(); + + setId(shell.getId(), descriptor); + + setIdShort(shell.getIdShort(), descriptor); + + setEndpointItem(shell.getId(), descriptor); + + setDescription(shell.getDescription(), descriptor); + + setDisplayName(shell.getDisplayName(), descriptor); - return createDescriptor(shell); + setExtensions(shell.getExtensions(), descriptor); + + setAdministration(shell.getAdministration(), descriptor); + + setAssetKind(shell.getAssetInformation(), descriptor); + + setAssetType(shell.getAssetInformation(), descriptor); + + setGlobalAssetId(shell.getAssetInformation(), descriptor); + + return descriptor; } - private AssetAdministrationShellDescriptor createDescriptor(AssetAdministrationShell shell) { - return null; + private void setDescription(List descriptions, AssetAdministrationShellDescriptor descriptor) { + + if (descriptions == null || descriptions.isEmpty()) + return; + + descriptor.setDescription(new AttributeMapper().mapDescription(descriptions)); + } + + private void setDisplayName(List displayNames, AssetAdministrationShellDescriptor descriptor) { + + if (displayNames == null || displayNames.isEmpty()) + return; + + descriptor.setDisplayName(new AttributeMapper().mapDisplayName(displayNames)); + } + + private void setExtensions(List extensions, AssetAdministrationShellDescriptor descriptor) { + + if (extensions == null || extensions.isEmpty()) + return; + + descriptor.setExtensions(new AttributeMapper().mapExtensions(extensions)); + } + + private void setAdministration(AdministrativeInformation administration, AssetAdministrationShellDescriptor descriptor) { + + if (administration == null) + return; + + descriptor.setAdministration(new AttributeMapper().mapAdministration(administration)); + } + + private void setAssetKind(AssetInformation assetInformation, AssetAdministrationShellDescriptor descriptor) { + + if (assetInformation == null || assetInformation.getAssetKind() == null) + return; + + descriptor.setAssetKind(new AttributeMapper().mapAssetKind(assetInformation.getAssetKind())); + } + + private void setAssetType(AssetInformation assetInformation, AssetAdministrationShellDescriptor descriptor) { + + if (assetInformation == null || assetInformation.getAssetType() == null) + return; + + descriptor.setAssetType(assetInformation.getAssetType()); + } + + private void setGlobalAssetId(AssetInformation assetInformation, AssetAdministrationShellDescriptor descriptor) { + + if (assetInformation == null || assetInformation.getGlobalAssetID() == null) + return; + + descriptor.setGlobalAssetId(assetInformation.getGlobalAssetID()); } - private AssetAdministrationShellDescriptor createDescriptorFromDefaultAas(AssetAdministrationShell shell) { - String endpoint = aasRepositoryURL + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(shell.getId()); + private void setEndpointItem(String shellId, AssetAdministrationShellDescriptor descriptor) { - AssetAdministrationShellDescriptor descriptor = new AssetAdministrationShellDescriptor(); - descriptor.setId(shell.getId()); - descriptor.setIdShort(shell.getIdShort()); -// descriptor.addEndpointsItem(new Endpoint()); + Endpoint endpoint = new Endpoint(); + endpoint.setInterface(AAS_INTERFACE); + ProtocolInformation protocolInformation = createProtocolInformation(shellId); + endpoint.setProtocolInformation(protocolInformation); - Endpoint endpoint2 = new Endpoint(); - endpoint2.setInterface(endpoint); - ProtocolInformation protocolInformation = new ProtocolInformation(); - protocolInformation.endpointProtocol("http"); - protocolInformation.setHref("http"); - endpoint2.setProtocolInformation(protocolInformation); + descriptor.addEndpointsItem(endpoint); + } + + private ProtocolInformation createProtocolInformation(String shellId) { + String href = String.format("%s/%s", aasRepositoryURL, Base64UrlEncodedIdentifier.encodeIdentifier(shellId)); - descriptor.addEndpointsItem(endpoint2); + ProtocolInformation protocolInformation = new ProtocolInformation(); + protocolInformation.endpointProtocol(getProtocol(href)); + protocolInformation.setHref(href); - return descriptor; + return protocolInformation; + } + + private void setIdShort(String idShort, AssetAdministrationShellDescriptor descriptor) { + descriptor.setIdShort(idShort); + } + + private void setId(String shellId, AssetAdministrationShellDescriptor descriptor) { + descriptor.setId(shellId); + } + + private String getProtocol(String endpoint) { + try { + return new URL(endpoint).getProtocol(); + } catch (MalformedURLException e) { + throw new RuntimeException(); + } } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java new file mode 100644 index 000000000..7dac52c10 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java @@ -0,0 +1,66 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import java.util.List; + +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Extension; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; + +public class AttributeMapper { + + public List mapDescription(List langStringTextTypes) { + // String serializedLangString = ""; + // try { + // serializedLangString = mapper.writeValueAsString(langStringTextTypes); + // } catch (JsonProcessingException e) { + // e.printStackTrace(); + // } + // + // List langStringList = new + // ArrayList(); + // + // try { + // langStringList = mapper.readValue(serializedLangString, new + // TypeReference>() { + // }); + // } catch (JsonProcessingException e) { + // e.printStackTrace(); + // } + // + // return langStringList; + + CloneFactory, List> cloneFactory = new CloneFactory<>(langStringTextTypes); + + return cloneFactory.create(); + } + + public List mapDisplayName(List langStringTextTypes) { + CloneFactory, List> cloneFactory = new CloneFactory<>(langStringTextTypes); + + return cloneFactory.create(); + } + + public List mapExtensions(List langStringTextTypes) { + CloneFactory, List> cloneFactory = new CloneFactory<>(langStringTextTypes); + + return cloneFactory.create(); + } + + public AdministrativeInformation mapAdministration(org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation langStringTextTypes) { + CloneFactory cloneFactory = new CloneFactory<>(langStringTextTypes); + + return cloneFactory.create(); + } + + public AssetKind mapAssetKind(org.eclipse.digitaltwin.aas4j.v3.model.AssetKind langStringTextTypes) { + + return AssetKind.valueOf(AssetKind.class, langStringTextTypes.name()); + +// CloneFactory cloneFactory = new CloneFactory<>(langStringTextTypes); +// +// return cloneFactory.create(); + } + +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java new file mode 100644 index 000000000..774a27a82 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java @@ -0,0 +1,66 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class CloneFactory { + + private ObjectMapper mapper = new ObjectMapper(); + + private I input; + + public CloneFactory(I input) { + super(); + this.input = input; + } + + public O create() { + String serializedLangString = ""; + try { + serializedLangString = mapper.writeValueAsString(input); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + +// if (input instanceof List) { +// List langStringList = new ArrayList(); +// +// try { +// langStringList = mapper.readValue(serializedLangString, new TypeReference>() { +// }); +// } catch (JsonProcessingException e) { +// e.printStackTrace(); +// } +// +// return (O) langStringList; +// } +// +// O administrativeInformation = null; +// +// try { +// administrativeInformation = mapper.readValue(serializedLangString, new TypeReference() {}); +// } catch (JsonProcessingException e) { +// e.printStackTrace(); +// } +// +// return administrativeInformation; + + O administrativeInformation = null; + + try { + administrativeInformation = mapper.readValue(serializedLangString, new TypeReference() {}); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + + return administrativeInformation; + } + +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java index 79e1cd8f5..f9da147f2 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java @@ -78,9 +78,6 @@ public void createAas(AssetAdministrationShell aas) throws CollidingIdentifierEx private void integrateAasWithRegistry(AssetAdministrationShell shell, String aasRepositoryURL) { AssetAdministrationShellDescriptor descriptor = new AasDescriptorFactory(shell, aasRepositoryURL).create(); - descriptor.idShort(shell.getIdShort()); - shell.getDisplayName(); - descriptor.addDisplayNameItem(null); RegistryAndDiscoveryInterfaceApi registryApi = aasRepositoryRegistryLink.getRegistryApi(); diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java index 298c1a23f..ad12f0e27 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java @@ -35,7 +35,7 @@ import org.springframework.context.annotation.Configuration; @Configuration -//@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.feature.registryintegration:}') && !T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.externalurl:}')") +@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.feature.registryintegration:}') && !T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.externalurl:}')") public class RegistryIntegrationAasRepositoryConfiguration { @Bean diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java index f2381b97e..538de7ed0 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java @@ -37,7 +37,7 @@ import org.springframework.stereotype.Component; @Component -//@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.feature.registryintegration:}')") +@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.feature.registryintegration:}') && !T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.externalurl:}')") public class RegistryIntegrationAasRepositoryFeature implements AasRepositoryFeature { public final static String FEATURENAME = "basyx.aasrepository.feature.registryintegration"; diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryTopicFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryTopicFactory.java deleted file mode 100644 index bb6c3bbe5..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryTopicFactory.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2021 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; - -import java.util.StringJoiner; - -import org.eclipse.digitaltwin.basyx.common.mqttcore.AbstractMqttTopicFactory; -import org.eclipse.digitaltwin.basyx.common.mqttcore.encoding.Encoder; - -/** - * A helper class containing methods that create topics used by the - * AASAggregator. - * - */ -public class RegistryIntegrationAasRepositoryTopicFactory extends AbstractMqttTopicFactory { - private static final String AASREPOSITORY = "aas-repository"; - private static final String SHELLS = "shells"; - private static final String CREATED = "created"; - private static final String UPDATED = "updated"; - private static final String DELETED = "deleted"; - - /** - * @param encoder - * Used for encoding the aasId/submodelId - */ - public RegistryIntegrationAasRepositoryTopicFactory(Encoder encoder) { - super(encoder); - } - - /** - * Creates the hierarchical topic for the create event - * - * @param repoId - * @return - */ - public String createCreateAASTopic(String repoId) { - return new StringJoiner("/", "", "") - .add(AASREPOSITORY) - .add(repoId) - .add(SHELLS) - .add(CREATED) - .toString(); - } - - /** - * Creates the hierarchical topic for the update event - * - * @param repoId - * @return - */ - public String createUpdateAASTopic(String repoId) { - return new StringJoiner("/", "", "") - .add(AASREPOSITORY) - .add(repoId) - .add(SHELLS) - .add(UPDATED) - .toString(); - } - - /** - * Creates the hierarchical topic for the delete event - * - * @param repoId - * @return - */ - public String createDeleteAASTopic(String repoId) { - return new StringJoiner("/", "", "") - .add(AASREPOSITORY) - .add(repoId) - .add(SHELLS) - .add(DELETED) - .toString(); - } -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestMqttV2AASAggregatorObserver.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestMqttV2AASAggregatorObserver.java index da4a1b726..59b08c06b 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestMqttV2AASAggregatorObserver.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestMqttV2AASAggregatorObserver.java @@ -42,7 +42,6 @@ import org.eclipse.digitaltwin.basyx.aasrepository.backend.SimpleAasRepositoryFactory; import org.eclipse.digitaltwin.basyx.aasrepository.backend.inmemory.AasInMemoryBackendProvider; import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.RegistryIntegrationAasRepositoryFactory; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.RegistryIntegrationAasRepositoryTopicFactory; import org.eclipse.digitaltwin.basyx.aasservice.backend.InMemoryAasServiceFactory; import org.eclipse.digitaltwin.basyx.common.mqttcore.encoding.Base64URLEncoder; import org.eclipse.digitaltwin.basyx.common.mqttcore.encoding.URLEncoder; diff --git a/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application.properties b/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application.properties index 1aaf4a247..f863f549e 100644 --- a/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application.properties +++ b/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application.properties @@ -7,7 +7,6 @@ basyx.aasrepo.name=aas-repo basyx.backend = InMemory basyx.aasrepository.feature.registryintegration=http://localhost:8030/api/v3.0 - basyx.aasrepository.externalurl=http://localhost:8081/shells #basyx.backend = MongoDB From 837a2c09c52b37c06c68254d097ebd58919fc4fc Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Mon, 13 Nov 2023 20:39:48 +0100 Subject: [PATCH 04/21] Fixes LinkedHashMap issue Signed-off-by: Mohammad Ghazanfar Ali Danish --- .../registry/integration/AttributeMapper.java | 62 +++++++------- .../registry/integration/CloneFactory.java | 81 +++++++++++++------ .../mqtt/RegistryIntegrationTestHelper.java | 27 +++++++ .../feature/mqtt/TestAttributeMapper.java | 23 ++++++ 4 files changed, 140 insertions(+), 53 deletions(-) create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java index 7dac52c10..33b9d7f9f 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java @@ -1,5 +1,6 @@ package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; +import java.util.ArrayList; import java.util.List; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation; @@ -8,50 +9,57 @@ import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + public class AttributeMapper { + + private ObjectMapper mapper = new ObjectMapper(); public List mapDescription(List langStringTextTypes) { - // String serializedLangString = ""; - // try { - // serializedLangString = mapper.writeValueAsString(langStringTextTypes); - // } catch (JsonProcessingException e) { - // e.printStackTrace(); - // } - // - // List langStringList = new - // ArrayList(); - // - // try { - // langStringList = mapper.readValue(serializedLangString, new - // TypeReference>() { - // }); - // } catch (JsonProcessingException e) { - // e.printStackTrace(); - // } - // - // return langStringList; +// String serializedLangString = ""; +// try { +// serializedLangString = mapper.writeValueAsString(langStringTextTypes); +// } catch (JsonProcessingException e) { +// e.printStackTrace(); +// } +// +// List langStringList = new +// ArrayList(); +// +// try { +// langStringList = mapper.readValue(serializedLangString, new +// TypeReference>() { +// }); +// } catch (JsonProcessingException e) { +// e.printStackTrace(); +// } +// +// return langStringList; +// mapper.getTypeFactory().constructCollectionType(List.class, LangStringTextType.class); - CloneFactory, List> cloneFactory = new CloneFactory<>(langStringTextTypes); + CloneFactory cloneFactory = new CloneFactory<>(LangStringTextType.class); - return cloneFactory.create(); + return cloneFactory.create(langStringTextTypes); } public List mapDisplayName(List langStringTextTypes) { - CloneFactory, List> cloneFactory = new CloneFactory<>(langStringTextTypes); + CloneFactory cloneFactory = new CloneFactory<>(LangStringNameType.class); - return cloneFactory.create(); + return cloneFactory.create(langStringTextTypes); } public List mapExtensions(List langStringTextTypes) { - CloneFactory, List> cloneFactory = new CloneFactory<>(langStringTextTypes); + CloneFactory cloneFactory = new CloneFactory<>(Extension.class); - return cloneFactory.create(); + return cloneFactory.create(langStringTextTypes); } public AdministrativeInformation mapAdministration(org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation langStringTextTypes) { - CloneFactory cloneFactory = new CloneFactory<>(langStringTextTypes); + CloneFactory cloneFactory = new CloneFactory<>(AdministrativeInformation.class); - return cloneFactory.create(); + return cloneFactory.create(langStringTextTypes); } public AssetKind mapAssetKind(org.eclipse.digitaltwin.aas4j.v3.model.AssetKind langStringTextTypes) { diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java index 774a27a82..c8e1dfd59 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java @@ -1,8 +1,13 @@ package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; import java.util.ArrayList; +import java.util.Collection; import java.util.List; +import org.eclipse.digitaltwin.aas4j.v3.dataformat.SerializationException; +import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.JsonDeserializer; +import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.JsonSerializer; +import org.eclipse.digitaltwin.aas4j.v3.model.Referable; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; @@ -13,35 +18,25 @@ public class CloneFactory { private ObjectMapper mapper = new ObjectMapper(); + private JsonSerializer serializer = new JsonSerializer(); - private I input; + private JsonDeserializer deserializer = new JsonDeserializer(); - public CloneFactory(I input) { + private Class elementType; + + public CloneFactory(Class elementType) { super(); - this.input = input; + this.elementType = elementType; } - public O create() { - String serializedLangString = ""; - try { - serializedLangString = mapper.writeValueAsString(input); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - -// if (input instanceof List) { -// List langStringList = new ArrayList(); -// -// try { -// langStringList = mapper.readValue(serializedLangString, new TypeReference>() { -// }); -// } catch (JsonProcessingException e) { -// e.printStackTrace(); -// } -// -// return (O) langStringList; +// public O create() { +// String serializedLangString = ""; +// try { +// serializedLangString = mapper.writeValueAsString(input); +// } catch (JsonProcessingException e) { +// e.printStackTrace(); // } -// +// // O administrativeInformation = null; // // try { @@ -51,16 +46,50 @@ public O create() { // } // // return administrativeInformation; +// } + + public List create(List input) { + String serializedLangString = ""; + try { + serializedLangString = mapper.writeValueAsString(input); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + + List resultList = null; + + try { + resultList = mapper.readValue(serializedLangString, mapper.getTypeFactory().constructCollectionType(List.class, elementType)); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + + return resultList; + } + + public O create(I input) { + String serializedLangString = ""; + try { + serializedLangString = mapper.writeValueAsString(input); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } - O administrativeInformation = null; +// try { +// resultList = mapper.readValue(serializedLangString, mapper.getTypeFactory().constructCollectionType(List.class, elementType)); +// } catch (JsonProcessingException e) { +// e.printStackTrace(); +// } try { - administrativeInformation = mapper.readValue(serializedLangString, new TypeReference() {}); + return mapper.readValue(serializedLangString, new TypeReference() { + }); } catch (JsonProcessingException e) { e.printStackTrace(); + throw new RuntimeException(); } - return administrativeInformation; +// return resultList; } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java new file mode 100644 index 000000000..29d24dbf6 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java @@ -0,0 +1,27 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.mqtt; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringTextType; + +public class RegistryIntegrationTestHelper { + + // LangStringTextType AAS4J + private static final LangStringTextType aas4jLangStringTextType_1 = new DefaultLangStringTextType.Builder().language("de").text("Ein Beispiel").build(); + private static final LangStringTextType aas4jLangStringTextType_2 = new DefaultLangStringTextType.Builder().language("en").text("An Example").build(); + + // LangStringTextType AasRegistry + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType aasRegLangStringTextType_1 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("de").text("Ein Beispiel"); + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType aasRegLangStringTextType_2 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("en").text("An Example"); + + public static List getAas4jLangStringTextTypes() { + return Arrays.asList(aas4jLangStringTextType_1, aas4jLangStringTextType_2); + } + + public static List getAasRegLangStringTextTypes() { + return Arrays.asList(aasRegLangStringTextType_1, aasRegLangStringTextType_2); + } + +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java new file mode 100644 index 000000000..d11cd27bb --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java @@ -0,0 +1,23 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.mqtt; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.AttributeMapper; +import org.junit.Test; + +public class TestAttributeMapper { + + @Test + public void mapDescriptions() { + List expectedDescriptions = RegistryIntegrationTestHelper.getAasRegLangStringTextTypes(); + + List actualDescriptions = new AttributeMapper().mapDescription(RegistryIntegrationTestHelper.getAas4jLangStringTextTypes()); + + assertEquals(expectedDescriptions.size(), actualDescriptions.size()); + assertEquals(expectedDescriptions, actualDescriptions); + } + +} From 2bd6276d9c4d945f3a16f7079f5efbade2eea339 Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Tue, 14 Nov 2023 08:13:31 +0100 Subject: [PATCH 05/21] Improves attribute mapper Signed-off-by: Mohammad Ghazanfar Ali Danish --- .../registry/integration/CloneFactory.java | 24 ++++----- .../mixin/AdministrativeInformationMixin.java | 9 ++++ .../mqtt/RegistryIntegrationTestHelper.java | 51 ++++++++++++++++--- .../feature/mqtt/TestAttributeMapper.java | 10 ++++ 4 files changed, 74 insertions(+), 20 deletions(-) create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/AdministrativeInformationMixin.java diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java index c8e1dfd59..cbdb45f15 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java @@ -1,34 +1,33 @@ package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; -import java.util.ArrayList; -import java.util.Collection; import java.util.List; -import org.eclipse.digitaltwin.aas4j.v3.dataformat.SerializationException; -import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.JsonDeserializer; -import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.JsonSerializer; -import org.eclipse.digitaltwin.aas4j.v3.model.Referable; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin.AdministrativeInformationMixin; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; public class CloneFactory { private ObjectMapper mapper = new ObjectMapper(); - private JsonSerializer serializer = new JsonSerializer(); - - private JsonDeserializer deserializer = new JsonDeserializer(); private Class elementType; public CloneFactory(Class elementType) { super(); this.elementType = elementType; + + configureMixins(); } + private void configureMixins() { + SimpleModule module = new SimpleModule(); + module.setMixInAnnotation(AdministrativeInformation.class, AdministrativeInformationMixin.class); + mapper.registerModule(module); + } + // public O create() { // String serializedLangString = ""; // try { @@ -82,8 +81,7 @@ public O create(I input) { // } try { - return mapper.readValue(serializedLangString, new TypeReference() { - }); + return mapper.readValue(serializedLangString, elementType); } catch (JsonProcessingException e) { e.printStackTrace(); throw new RuntimeException(); diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/AdministrativeInformationMixin.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/AdministrativeInformationMixin.java new file mode 100644 index 000000000..cc545e1fc --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/AdministrativeInformationMixin.java @@ -0,0 +1,9 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public interface AdministrativeInformationMixin { + + @JsonProperty("templateID") + public String getTemplateId(); +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java index 29d24dbf6..ece683a7b 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java @@ -3,25 +3,62 @@ import java.util.Arrays; import java.util.List; +import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.EmbeddedDataSpecification; +import org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes; import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; +import org.eclipse.digitaltwin.aas4j.v3.model.ReferenceTypes; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultEmbeddedDataSpecification; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultKey; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringTextType; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultReference; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Key; public class RegistryIntegrationTestHelper { - - // LangStringTextType AAS4J + + // LangStringTextType AAS4J private static final LangStringTextType aas4jLangStringTextType_1 = new DefaultLangStringTextType.Builder().language("de").text("Ein Beispiel").build(); private static final LangStringTextType aas4jLangStringTextType_2 = new DefaultLangStringTextType.Builder().language("en").text("An Example").build(); - + // LangStringTextType AasRegistry - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType aasRegLangStringTextType_1 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("de").text("Ein Beispiel"); - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType aasRegLangStringTextType_2 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("en").text("An Example"); - + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType aasRegLangStringTextType_1 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("de") + .text("Ein Beispiel"); + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType aasRegLangStringTextType_2 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("en") + .text("An Example"); + + // Administration AAS4J + private static final Reference aas4jDataSpecification = new DefaultReference.Builder().keys(new DefaultKey.Builder().type(KeyTypes.BLOB).value("BlobValue").build()).type(ReferenceTypes.EXTERNAL_REFERENCE).build(); + private static final EmbeddedDataSpecification AAS4JEMB_EMBEDDED_DATA_SPECIFICATION = new DefaultEmbeddedDataSpecification.Builder().dataSpecification(aas4jDataSpecification).build(); + private static final String aas4jVersion = "1.0.0"; + private static final String aas4jRevision = "3"; + private static final String aas4jTemplateId = "ID2.0"; + + // Administration AAS4J + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.Reference aasRegDataSpecification = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.Reference() + .keys(Arrays.asList(new Key().type(org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes.BLOB).value("BlobValue"))).type(org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes.EXTERNALREFERENCE); + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.EmbeddedDataSpecification AASREG_EMBEDDED_DATA_SPECIFICATION = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.EmbeddedDataSpecification() + .dataSpecification(aasRegDataSpecification); + private static final String aasRegVersion = "1.0.0"; + private static final String aasRegRevision = "3"; + private static final String aasRegTemplateId = "ID2.0"; + public static List getAas4jLangStringTextTypes() { return Arrays.asList(aas4jLangStringTextType_1, aas4jLangStringTextType_2); } - + public static List getAasRegLangStringTextTypes() { return Arrays.asList(aasRegLangStringTextType_1, aasRegLangStringTextType_2); } + public static AdministrativeInformation getAas4jAdministration() { + return new DefaultAdministrativeInformation.Builder().embeddedDataSpecifications(AAS4JEMB_EMBEDDED_DATA_SPECIFICATION).version(aas4jVersion).revision(aas4jRevision).templateID(aas4jTemplateId).build(); + } + + public static org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation getAasRegAdministration() { + return new org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation().embeddedDataSpecifications(Arrays.asList(AASREG_EMBEDDED_DATA_SPECIFICATION)).version(aasRegVersion).revision(aasRegRevision) + .templateId(aasRegTemplateId); + } + } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java index d11cd27bb..4c1cdce97 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java @@ -4,6 +4,7 @@ import java.util.List; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.AttributeMapper; import org.junit.Test; @@ -19,5 +20,14 @@ public void mapDescriptions() { assertEquals(expectedDescriptions.size(), actualDescriptions.size()); assertEquals(expectedDescriptions, actualDescriptions); } + + @Test + public void mapAdministration() { + AdministrativeInformation expectedAdministrativeInformation = RegistryIntegrationTestHelper.getAasRegAdministration(); + + AdministrativeInformation actualAdministrativeInformation = new AttributeMapper().mapAdministration(RegistryIntegrationTestHelper.getAas4jAdministration()); + + assertEquals(expectedAdministrativeInformation, actualAdministrativeInformation); + } } From c027ad9e2aef46c778185e20c53728227da5887f Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Tue, 14 Nov 2023 11:31:55 +0100 Subject: [PATCH 06/21] Ignores Extensions and Admin info in Descriptor Signed-off-by: Mohammad Ghazanfar Ali Danish --- .../integration/AasDescriptorFactory.java | 4 +- .../registry/integration/CloneFactory.java | 20 +++++++++- .../deserializer/KeyTypeDeserializer.java | 30 +++++++++++++++ .../ReferenceTypeDeserializer.java | 32 ++++++++++++++++ .../mixin/AdministrativeInformationMixin.java | 7 +++- .../integration/mixin/ReferenceMixin.java | 14 +++++++ .../mqtt/RegistryIntegrationTestHelper.java | 25 +++++++++++++ .../feature/mqtt/TestAttributeMapper.java | 29 +++++++++++++-- .../feature/mqtt/TestCloneFactory.java | 37 +++++++++++++++++++ .../src/main/resources/application.properties | 4 +- 10 files changed, 191 insertions(+), 11 deletions(-) create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/KeyTypeDeserializer.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/ReferenceTypeDeserializer.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ReferenceMixin.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestCloneFactory.java diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java index f81a7d616..d3eb0ec20 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java @@ -41,9 +41,9 @@ public AssetAdministrationShellDescriptor create() { setDisplayName(shell.getDisplayName(), descriptor); - setExtensions(shell.getExtensions(), descriptor); +// setExtensions(shell.getExtensions(), descriptor); - setAdministration(shell.getAdministration(), descriptor); +// setAdministration(shell.getAdministration(), descriptor); setAssetKind(shell.getAssetInformation(), descriptor); diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java index cbdb45f15..9d77e8309 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java @@ -2,8 +2,14 @@ import java.util.List; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.deserializer.KeyTypeDeserializer; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.deserializer.ReferenceTypeDeserializer; import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin.AdministrativeInformationMixin; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin.ReferenceMixin; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -26,6 +32,18 @@ private void configureMixins() { SimpleModule module = new SimpleModule(); module.setMixInAnnotation(AdministrativeInformation.class, AdministrativeInformationMixin.class); mapper.registerModule(module); + + SimpleModule module2 = new SimpleModule(); + module2.setMixInAnnotation(Reference.class, ReferenceMixin.class); + mapper.registerModule(module2); + + SimpleModule moduleDeser = new SimpleModule(); + moduleDeser.addDeserializer(KeyTypes.class, new KeyTypeDeserializer()); + mapper.registerModule(moduleDeser); + + SimpleModule moduleDeser2 = new SimpleModule(); + moduleDeser2.addDeserializer(ReferenceTypes.class, new ReferenceTypeDeserializer()); + mapper.registerModule(moduleDeser2); } // public O create() { diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/KeyTypeDeserializer.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/KeyTypeDeserializer.java new file mode 100644 index 000000000..aa751b51c --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/KeyTypeDeserializer.java @@ -0,0 +1,30 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.deserializer; + +import java.io.IOException; + +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes; + +import com.fasterxml.jackson.core.JacksonException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; + +public class KeyTypeDeserializer extends JsonDeserializer { + + @Override + public KeyTypes deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { + try { + JsonNode node = p.getCodec().readTree(p); + + String value = node.asText(); + + return KeyTypes.valueOf(KeyTypes.class, value); + + } catch (Exception e) { + throw new RuntimeException("Unable to deserialize the KeyTypes Enum"); + } + } + +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/ReferenceTypeDeserializer.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/ReferenceTypeDeserializer.java new file mode 100644 index 000000000..de3a8748a --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/ReferenceTypeDeserializer.java @@ -0,0 +1,32 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.deserializer; + +import java.io.IOException; + +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes; + +import com.fasterxml.jackson.core.JacksonException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; + +public class ReferenceTypeDeserializer extends JsonDeserializer { + + @Override + public ReferenceTypes deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { + try { + JsonNode node = p.getCodec().readTree(p); + + String value = node.asText(); + +// return ReferenceTypes.valueOf(ReferenceTypes.class, value); + return ReferenceTypes.EXTERNALREFERENCE; + + } catch (Exception e) { + throw new RuntimeException("Unable to deserialize the ReferenceTypes Enum"); + } + } + +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/AdministrativeInformationMixin.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/AdministrativeInformationMixin.java index cc545e1fc..c6aeae391 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/AdministrativeInformationMixin.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/AdministrativeInformationMixin.java @@ -4,6 +4,9 @@ public interface AdministrativeInformationMixin { - @JsonProperty("templateID") - public String getTemplateId(); + @JsonProperty("templateId") + public String getTemplateID(); + + +// public String getTemplateId(); } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ReferenceMixin.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ReferenceMixin.java new file mode 100644 index 000000000..0f933482a --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ReferenceMixin.java @@ -0,0 +1,14 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin; + +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public interface ReferenceMixin { + + @JsonProperty("referredSemanticId") + public Reference getReferredSemanticID(); + + +// public String getTemplateId(); +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java index ece683a7b..732564454 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java @@ -4,14 +4,17 @@ import java.util.List; import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; import org.eclipse.digitaltwin.aas4j.v3.model.EmbeddedDataSpecification; import org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; import org.eclipse.digitaltwin.aas4j.v3.model.Reference; import org.eclipse.digitaltwin.aas4j.v3.model.ReferenceTypes; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAdministrativeInformation; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultEmbeddedDataSpecification; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultKey; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringNameType; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringTextType; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultReference; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Key; @@ -27,6 +30,20 @@ public class RegistryIntegrationTestHelper { .text("Ein Beispiel"); private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType aasRegLangStringTextType_2 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("en") .text("An Example"); + + // LangStringNameType AAS4J + private static final LangStringNameType AAS4J_LANG_STRING_NAME_TYPE_1 = new DefaultLangStringNameType.Builder().language("en").text("Name type string").build(); + private static final LangStringNameType AAS4J_LANG_STRING_NAME_TYPE_2 = new DefaultLangStringNameType.Builder().language("de").text("Namenstypzeichenfolge").build(); + + // LangStringTextType AasRegistry + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType AASREG_LANG_STRING_NAME_TYPE_1 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType().language("en").text("Name type string"); + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType AASREG_LANG_STRING_NAME_TYPE_2 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType().language("de").text("Namenstypzeichenfolge"); + + // AssetKind AAS4J + public static final AssetKind AAS4J_ASSET_KIND = AssetKind.INSTANCE; + + // AssetKind AasRegistry + public static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind AASREG_ASSET_KIND = org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind.INSTANCE; // Administration AAS4J private static final Reference aas4jDataSpecification = new DefaultReference.Builder().keys(new DefaultKey.Builder().type(KeyTypes.BLOB).value("BlobValue").build()).type(ReferenceTypes.EXTERNAL_REFERENCE).build(); @@ -60,5 +77,13 @@ public static org.eclipse.digitaltwin.basyx.aasregistry.client.model.Administrat return new org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation().embeddedDataSpecifications(Arrays.asList(AASREG_EMBEDDED_DATA_SPECIFICATION)).version(aasRegVersion).revision(aasRegRevision) .templateId(aasRegTemplateId); } + + public static List getAas4jLangStringNameTypes() { + return Arrays.asList(AAS4J_LANG_STRING_NAME_TYPE_1, AAS4J_LANG_STRING_NAME_TYPE_2); + } + + public static List getAasRegLangStringNameTypes() { + return Arrays.asList(AASREG_LANG_STRING_NAME_TYPE_1, AASREG_LANG_STRING_NAME_TYPE_2); + } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java index 4c1cdce97..523614ce3 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java @@ -5,6 +5,8 @@ import java.util.List; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.AttributeMapper; import org.junit.Test; @@ -21,13 +23,32 @@ public void mapDescriptions() { assertEquals(expectedDescriptions, actualDescriptions); } +// @Test +// public void mapAdministration() { +// AdministrativeInformation expectedAdministrativeInformation = RegistryIntegrationTestHelper.getAasRegAdministration(); +// +// AdministrativeInformation actualAdministrativeInformation = new AttributeMapper().mapAdministration(RegistryIntegrationTestHelper.getAas4jAdministration()); +// +// assertEquals(expectedAdministrativeInformation, actualAdministrativeInformation); +// } + @Test - public void mapAdministration() { - AdministrativeInformation expectedAdministrativeInformation = RegistryIntegrationTestHelper.getAasRegAdministration(); + public void mapDisplayNames() { + List expectedDisplayNames = RegistryIntegrationTestHelper.getAasRegLangStringNameTypes(); + + List actualDisplayNames = new AttributeMapper().mapDisplayName(RegistryIntegrationTestHelper.getAas4jLangStringNameTypes()); - AdministrativeInformation actualAdministrativeInformation = new AttributeMapper().mapAdministration(RegistryIntegrationTestHelper.getAas4jAdministration()); + assertEquals(expectedDisplayNames.size(), actualDisplayNames.size()); + assertEquals(expectedDisplayNames, actualDisplayNames); + } + + @Test + public void mapAssetKind() { + AssetKind expectedAssetKind = RegistryIntegrationTestHelper.AASREG_ASSET_KIND; - assertEquals(expectedAdministrativeInformation, actualAdministrativeInformation); + AssetKind actualAssetKind = new AttributeMapper().mapAssetKind(RegistryIntegrationTestHelper.AAS4J_ASSET_KIND); + + assertEquals(expectedAssetKind, actualAssetKind); } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestCloneFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestCloneFactory.java new file mode 100644 index 000000000..06bf43a2c --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestCloneFactory.java @@ -0,0 +1,37 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.mqtt; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.AttributeMapper; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.CloneFactory; +import org.junit.Test; + +public class TestCloneFactory { + + @Test + public void createCloneOfListType() { + List expectedDescriptions = RegistryIntegrationTestHelper.getAasRegLangStringTextTypes(); + + CloneFactory cloneFactory = new CloneFactory<>(LangStringTextType.class); + + List actualDescriptions = cloneFactory.create(RegistryIntegrationTestHelper.getAas4jLangStringTextTypes()); + + assertEquals(expectedDescriptions.size(), actualDescriptions.size()); + assertEquals(expectedDescriptions, actualDescriptions); + } + +// @Test +// public void createCloneOfNonListType() { +// AssetKind expectedAssetKind = RegistryIntegrationTestHelper.AASREG_ASSET_KIND; +// +// AssetKind actualAssetKind = new AttributeMapper().mapAssetKind(RegistryIntegrationTestHelper.AAS4J_ASSET_KIND); +// +// assertEquals(expectedAssetKind, actualAssetKind); +// } + +} diff --git a/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application.properties b/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application.properties index f863f549e..a1ec62149 100644 --- a/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application.properties +++ b/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application.properties @@ -1,4 +1,4 @@ -server.port=8081 +server.port=8082 server.error.path=/error spring.application.name=AAS Repository @@ -7,7 +7,7 @@ basyx.aasrepo.name=aas-repo basyx.backend = InMemory basyx.aasrepository.feature.registryintegration=http://localhost:8030/api/v3.0 -basyx.aasrepository.externalurl=http://localhost:8081/shells +basyx.aasrepository.externalurl=http://localhost:8082/shells #basyx.backend = MongoDB #spring.data.mongodb.host=127.0.0.1 From d325b89297767527181a5995ecfba7e41f5c0a03 Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Tue, 14 Nov 2023 11:41:56 +0100 Subject: [PATCH 07/21] Removes unnecessary classes and codes Signed-off-by: Mohammad Ghazanfar Ali Danish --- .../integration/AasDescriptorFactory.java | 22 ------- .../registry/integration/AttributeMapper.java | 46 --------------- .../registry/integration/CloneFactory.java | 58 +------------------ .../deserializer/KeyTypeDeserializer.java | 30 ---------- .../ReferenceTypeDeserializer.java | 32 ---------- .../mixin/AdministrativeInformationMixin.java | 12 ---- .../integration/mixin/ReferenceMixin.java | 14 ----- .../mqtt/RegistryIntegrationTestHelper.java | 35 ----------- .../feature/mqtt/TestAttributeMapper.java | 10 ---- .../feature/mqtt/TestCloneFactory.java | 14 +---- 10 files changed, 2 insertions(+), 271 deletions(-) delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/KeyTypeDeserializer.java delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/ReferenceTypeDeserializer.java delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/AdministrativeInformationMixin.java delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ReferenceMixin.java diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java index d3eb0ec20..ac01d9903 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java @@ -4,10 +4,8 @@ import java.net.URL; import java.util.List; -import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation; -import org.eclipse.digitaltwin.aas4j.v3.model.Extension; import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor; @@ -41,10 +39,6 @@ public AssetAdministrationShellDescriptor create() { setDisplayName(shell.getDisplayName(), descriptor); -// setExtensions(shell.getExtensions(), descriptor); - -// setAdministration(shell.getAdministration(), descriptor); - setAssetKind(shell.getAssetInformation(), descriptor); setAssetType(shell.getAssetInformation(), descriptor); @@ -70,22 +64,6 @@ private void setDisplayName(List displayNames, AssetAdminist descriptor.setDisplayName(new AttributeMapper().mapDisplayName(displayNames)); } - private void setExtensions(List extensions, AssetAdministrationShellDescriptor descriptor) { - - if (extensions == null || extensions.isEmpty()) - return; - - descriptor.setExtensions(new AttributeMapper().mapExtensions(extensions)); - } - - private void setAdministration(AdministrativeInformation administration, AssetAdministrationShellDescriptor descriptor) { - - if (administration == null) - return; - - descriptor.setAdministration(new AttributeMapper().mapAdministration(administration)); - } - private void setAssetKind(AssetInformation assetInformation, AssetAdministrationShellDescriptor descriptor) { if (assetInformation == null || assetInformation.getAssetKind() == null) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java index 33b9d7f9f..19d7641ba 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java @@ -1,44 +1,14 @@ package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; -import java.util.ArrayList; import java.util.List; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Extension; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; - public class AttributeMapper { - - private ObjectMapper mapper = new ObjectMapper(); public List mapDescription(List langStringTextTypes) { -// String serializedLangString = ""; -// try { -// serializedLangString = mapper.writeValueAsString(langStringTextTypes); -// } catch (JsonProcessingException e) { -// e.printStackTrace(); -// } -// -// List langStringList = new -// ArrayList(); -// -// try { -// langStringList = mapper.readValue(serializedLangString, new -// TypeReference>() { -// }); -// } catch (JsonProcessingException e) { -// e.printStackTrace(); -// } -// -// return langStringList; -// mapper.getTypeFactory().constructCollectionType(List.class, LangStringTextType.class); - CloneFactory cloneFactory = new CloneFactory<>(LangStringTextType.class); return cloneFactory.create(langStringTextTypes); @@ -50,25 +20,9 @@ public List mapDisplayName(List mapExtensions(List langStringTextTypes) { - CloneFactory cloneFactory = new CloneFactory<>(Extension.class); - - return cloneFactory.create(langStringTextTypes); - } - - public AdministrativeInformation mapAdministration(org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation langStringTextTypes) { - CloneFactory cloneFactory = new CloneFactory<>(AdministrativeInformation.class); - - return cloneFactory.create(langStringTextTypes); - } - public AssetKind mapAssetKind(org.eclipse.digitaltwin.aas4j.v3.model.AssetKind langStringTextTypes) { return AssetKind.valueOf(AssetKind.class, langStringTextTypes.name()); - -// CloneFactory cloneFactory = new CloneFactory<>(langStringTextTypes); -// -// return cloneFactory.create(); } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java index 9d77e8309..16553bd8e 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java @@ -2,18 +2,8 @@ import java.util.List; -import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; -import org.eclipse.digitaltwin.aas4j.v3.model.Reference; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.deserializer.KeyTypeDeserializer; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.deserializer.ReferenceTypeDeserializer; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin.AdministrativeInformationMixin; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin.ReferenceMixin; - import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.module.SimpleModule; public class CloneFactory { @@ -24,49 +14,11 @@ public class CloneFactory { public CloneFactory(Class elementType) { super(); this.elementType = elementType; - - configureMixins(); } - private void configureMixins() { - SimpleModule module = new SimpleModule(); - module.setMixInAnnotation(AdministrativeInformation.class, AdministrativeInformationMixin.class); - mapper.registerModule(module); - - SimpleModule module2 = new SimpleModule(); - module2.setMixInAnnotation(Reference.class, ReferenceMixin.class); - mapper.registerModule(module2); - - SimpleModule moduleDeser = new SimpleModule(); - moduleDeser.addDeserializer(KeyTypes.class, new KeyTypeDeserializer()); - mapper.registerModule(moduleDeser); - - SimpleModule moduleDeser2 = new SimpleModule(); - moduleDeser2.addDeserializer(ReferenceTypes.class, new ReferenceTypeDeserializer()); - mapper.registerModule(moduleDeser2); - } - -// public O create() { -// String serializedLangString = ""; -// try { -// serializedLangString = mapper.writeValueAsString(input); -// } catch (JsonProcessingException e) { -// e.printStackTrace(); -// } -// -// O administrativeInformation = null; -// -// try { -// administrativeInformation = mapper.readValue(serializedLangString, new TypeReference() {}); -// } catch (JsonProcessingException e) { -// e.printStackTrace(); -// } -// -// return administrativeInformation; -// } - public List create(List input) { String serializedLangString = ""; + try { serializedLangString = mapper.writeValueAsString(input); } catch (JsonProcessingException e) { @@ -92,20 +44,12 @@ public O create(I input) { e.printStackTrace(); } -// try { -// resultList = mapper.readValue(serializedLangString, mapper.getTypeFactory().constructCollectionType(List.class, elementType)); -// } catch (JsonProcessingException e) { -// e.printStackTrace(); -// } - try { return mapper.readValue(serializedLangString, elementType); } catch (JsonProcessingException e) { e.printStackTrace(); throw new RuntimeException(); } - -// return resultList; } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/KeyTypeDeserializer.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/KeyTypeDeserializer.java deleted file mode 100644 index aa751b51c..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/KeyTypeDeserializer.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.deserializer; - -import java.io.IOException; - -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes; - -import com.fasterxml.jackson.core.JacksonException; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; - -public class KeyTypeDeserializer extends JsonDeserializer { - - @Override - public KeyTypes deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { - try { - JsonNode node = p.getCodec().readTree(p); - - String value = node.asText(); - - return KeyTypes.valueOf(KeyTypes.class, value); - - } catch (Exception e) { - throw new RuntimeException("Unable to deserialize the KeyTypes Enum"); - } - } - -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/ReferenceTypeDeserializer.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/ReferenceTypeDeserializer.java deleted file mode 100644 index de3a8748a..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/ReferenceTypeDeserializer.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.deserializer; - -import java.io.IOException; - -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes; - -import com.fasterxml.jackson.core.JacksonException; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; - -public class ReferenceTypeDeserializer extends JsonDeserializer { - - @Override - public ReferenceTypes deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { - try { - JsonNode node = p.getCodec().readTree(p); - - String value = node.asText(); - -// return ReferenceTypes.valueOf(ReferenceTypes.class, value); - return ReferenceTypes.EXTERNALREFERENCE; - - } catch (Exception e) { - throw new RuntimeException("Unable to deserialize the ReferenceTypes Enum"); - } - } - -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/AdministrativeInformationMixin.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/AdministrativeInformationMixin.java deleted file mode 100644 index c6aeae391..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/AdministrativeInformationMixin.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public interface AdministrativeInformationMixin { - - @JsonProperty("templateId") - public String getTemplateID(); - - -// public String getTemplateId(); -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ReferenceMixin.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ReferenceMixin.java deleted file mode 100644 index 0f933482a..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ReferenceMixin.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin; - -import org.eclipse.digitaltwin.aas4j.v3.model.Reference; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public interface ReferenceMixin { - - @JsonProperty("referredSemanticId") - public Reference getReferredSemanticID(); - - -// public String getTemplateId(); -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java index 732564454..4463268a8 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java @@ -3,21 +3,11 @@ import java.util.Arrays; import java.util.List; -import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; -import org.eclipse.digitaltwin.aas4j.v3.model.EmbeddedDataSpecification; -import org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes; import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; -import org.eclipse.digitaltwin.aas4j.v3.model.Reference; -import org.eclipse.digitaltwin.aas4j.v3.model.ReferenceTypes; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAdministrativeInformation; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultEmbeddedDataSpecification; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultKey; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringNameType; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringTextType; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultReference; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Key; public class RegistryIntegrationTestHelper { @@ -45,22 +35,6 @@ public class RegistryIntegrationTestHelper { // AssetKind AasRegistry public static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind AASREG_ASSET_KIND = org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind.INSTANCE; - // Administration AAS4J - private static final Reference aas4jDataSpecification = new DefaultReference.Builder().keys(new DefaultKey.Builder().type(KeyTypes.BLOB).value("BlobValue").build()).type(ReferenceTypes.EXTERNAL_REFERENCE).build(); - private static final EmbeddedDataSpecification AAS4JEMB_EMBEDDED_DATA_SPECIFICATION = new DefaultEmbeddedDataSpecification.Builder().dataSpecification(aas4jDataSpecification).build(); - private static final String aas4jVersion = "1.0.0"; - private static final String aas4jRevision = "3"; - private static final String aas4jTemplateId = "ID2.0"; - - // Administration AAS4J - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.Reference aasRegDataSpecification = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.Reference() - .keys(Arrays.asList(new Key().type(org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes.BLOB).value("BlobValue"))).type(org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes.EXTERNALREFERENCE); - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.EmbeddedDataSpecification AASREG_EMBEDDED_DATA_SPECIFICATION = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.EmbeddedDataSpecification() - .dataSpecification(aasRegDataSpecification); - private static final String aasRegVersion = "1.0.0"; - private static final String aasRegRevision = "3"; - private static final String aasRegTemplateId = "ID2.0"; - public static List getAas4jLangStringTextTypes() { return Arrays.asList(aas4jLangStringTextType_1, aas4jLangStringTextType_2); } @@ -68,15 +42,6 @@ public static List getAas4jLangStringTextTypes() { public static List getAasRegLangStringTextTypes() { return Arrays.asList(aasRegLangStringTextType_1, aasRegLangStringTextType_2); } - - public static AdministrativeInformation getAas4jAdministration() { - return new DefaultAdministrativeInformation.Builder().embeddedDataSpecifications(AAS4JEMB_EMBEDDED_DATA_SPECIFICATION).version(aas4jVersion).revision(aas4jRevision).templateID(aas4jTemplateId).build(); - } - - public static org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation getAasRegAdministration() { - return new org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation().embeddedDataSpecifications(Arrays.asList(AASREG_EMBEDDED_DATA_SPECIFICATION)).version(aasRegVersion).revision(aasRegRevision) - .templateId(aasRegTemplateId); - } public static List getAas4jLangStringNameTypes() { return Arrays.asList(AAS4J_LANG_STRING_NAME_TYPE_1, AAS4J_LANG_STRING_NAME_TYPE_2); diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java index 523614ce3..b747a384c 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java @@ -4,7 +4,6 @@ import java.util.List; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; @@ -23,15 +22,6 @@ public void mapDescriptions() { assertEquals(expectedDescriptions, actualDescriptions); } -// @Test -// public void mapAdministration() { -// AdministrativeInformation expectedAdministrativeInformation = RegistryIntegrationTestHelper.getAasRegAdministration(); -// -// AdministrativeInformation actualAdministrativeInformation = new AttributeMapper().mapAdministration(RegistryIntegrationTestHelper.getAas4jAdministration()); -// -// assertEquals(expectedAdministrativeInformation, actualAdministrativeInformation); -// } - @Test public void mapDisplayNames() { List expectedDisplayNames = RegistryIntegrationTestHelper.getAasRegLangStringNameTypes(); diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestCloneFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestCloneFactory.java index 06bf43a2c..9adfffd05 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestCloneFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestCloneFactory.java @@ -4,17 +4,14 @@ import java.util.List; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.AttributeMapper; import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.CloneFactory; import org.junit.Test; public class TestCloneFactory { @Test - public void createCloneOfListType() { + public void createClone() { List expectedDescriptions = RegistryIntegrationTestHelper.getAasRegLangStringTextTypes(); CloneFactory cloneFactory = new CloneFactory<>(LangStringTextType.class); @@ -24,14 +21,5 @@ public void createCloneOfListType() { assertEquals(expectedDescriptions.size(), actualDescriptions.size()); assertEquals(expectedDescriptions, actualDescriptions); } - -// @Test -// public void createCloneOfNonListType() { -// AssetKind expectedAssetKind = RegistryIntegrationTestHelper.AASREG_ASSET_KIND; -// -// AssetKind actualAssetKind = new AttributeMapper().mapAssetKind(RegistryIntegrationTestHelper.AAS4J_ASSET_KIND); -// -// assertEquals(expectedAssetKind, actualAssetKind); -// } } From 2f96e556b338dd10d9ae7f6dd1c31276ef5c1742 Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Tue, 14 Nov 2023 13:49:02 +0100 Subject: [PATCH 08/21] Aas Repository Feature Ready Signed-off-by: Mohammad Ghazanfar Ali Danish --- .../Readme.md | 11 +- .../pom.xml | 9 - .../integration/AasDescriptorFactory.java | 35 ++++ .../AasRepositoryRegistryLink.java | 31 ++++ .../registry/integration/AttributeMapper.java | 66 ++++++- .../registry/integration/CloneFactory.java | 49 ++++- .../RegistryIntegrationAasRepository.java | 54 +++--- ...IntegrationAasRepositoryConfiguration.java | 8 +- ...gistryIntegrationAasRepositoryFactory.java | 9 +- ...gistryIntegrationAasRepositoryFeature.java | 9 +- .../feature/mqtt/TestCloneFactory.java | 25 --- .../mqtt/TestMqttV2AASAggregatorObserver.java | 167 ------------------ .../RegistryIntegrationTestHelper.java | 32 +++- .../integration}/TestAttributeMapper.java | 32 +++- .../integration/TestCloneFactory.java | 54 ++++++ .../RepositoryRegistryLinkException.java | 47 +++++ 16 files changed, 384 insertions(+), 254 deletions(-) delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestCloneFactory.java delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestMqttV2AASAggregatorObserver.java rename basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/{mqtt => registry/integration}/RegistryIntegrationTestHelper.java (68%) rename basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/{mqtt => registry/integration}/TestAttributeMapper.java (52%) create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestCloneFactory.java create mode 100644 basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/RepositoryRegistryLinkException.java diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/Readme.md b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/Readme.md index 630d235d9..a115b941d 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/Readme.md +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/Readme.md @@ -1,8 +1,3 @@ -# AssetAdministrationShell Repository - MQTT Eventing -This feature provides hierarchical MQTT eventing for a multitude of events: - -| Event |Topic | Payload | -| ----------- | ----------- | --- | -| AAS Created | /aas-repository/\$repoId/shells/created| Created AAS JSON | -| AAS Updated | /aas-repository/\$repoId/shells/updated| Updated AAS JSON| -| AAS Deleted | /aas-repository/\$repoId/shells/deleted| Deleted AAS JSON| \ No newline at end of file +# AssetAdministrationShell Repository - Registry Integration +This feature automatically integrates the Descriptor with the Registry while creation of the Shell at Repository. +It also automatically removes the Descriptor from the Registry when the Shell is removed from the Repository. \ No newline at end of file diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/pom.xml b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/pom.xml index 81035d4cb..bf5e93ca5 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/pom.xml +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/pom.xml @@ -52,14 +52,5 @@ org.springframework.boot spring-boot-starter - - org.eclipse.paho - org.eclipse.paho.client.mqttv3 - - - io.moquette - moquette-broker - test - \ No newline at end of file diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java index ac01d9903..cb3f373e4 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java @@ -1,3 +1,28 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; import java.net.MalformedURLException; @@ -13,6 +38,11 @@ import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ProtocolInformation; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; +/** + * Factory for creating the {@link AssetAdministrationShellDescriptor} + * + * @author danish + */ public class AasDescriptorFactory { private static final String AAS_INTERFACE = "AAS-3.0"; @@ -25,6 +55,11 @@ public AasDescriptorFactory(AssetAdministrationShell shell, String aasRepository this.aasRepositoryURL = aasRepositoryURL; } + /** + * Creates {@link AssetAdministrationShellDescriptor} + * + * @return the created AssetAdministrationShellDescriptor + */ public AssetAdministrationShellDescriptor create() { AssetAdministrationShellDescriptor descriptor = new AssetAdministrationShellDescriptor(); diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java index b42353c41..d13b3e8a3 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java @@ -1,7 +1,38 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; +import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; +/** + * Represents information for linking {@link AasRepository} with AasRegistry + * + * @author danish + */ public class AasRepositoryRegistryLink { private RegistryAndDiscoveryInterfaceApi registryApi; diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java index 19d7641ba..4c05095d6 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java @@ -1,28 +1,80 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; import java.util.List; +import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; +import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; +/** + * Maps the models defined in AasRegistry client to the AAS4J models + * + * @author danish + */ public class AttributeMapper { - public List mapDescription(List langStringTextTypes) { + /** + * Maps {@link AssetAdministrationShell#getDescription()} from AAS4J to + * AasRegistry client + * + * @param descriptions + * @return the mapped descriptions + */ + public List mapDescription(List descriptions) { CloneFactory cloneFactory = new CloneFactory<>(LangStringTextType.class); - return cloneFactory.create(langStringTextTypes); + return cloneFactory.create(descriptions); } - public List mapDisplayName(List langStringTextTypes) { + /** + * Maps {@link AssetAdministrationShell#getDisplayName()} from AAS4J to + * AasRegistry client + * + * @param displayNames + * @return the mapped displayNames + */ + public List mapDisplayName(List displayNames) { CloneFactory cloneFactory = new CloneFactory<>(LangStringNameType.class); - return cloneFactory.create(langStringTextTypes); + return cloneFactory.create(displayNames); } - public AssetKind mapAssetKind(org.eclipse.digitaltwin.aas4j.v3.model.AssetKind langStringTextTypes) { - - return AssetKind.valueOf(AssetKind.class, langStringTextTypes.name()); + /** + * Maps {@link AssetInformation#getAssetKind()} from AAS4J to AasRegistry client + * + * @param assetKind + * @return the mapped assetKind + */ + public AssetKind mapAssetKind(org.eclipse.digitaltwin.aas4j.v3.model.AssetKind assetKind) { + + return AssetKind.valueOf(AssetKind.class, assetKind.name()); } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java index 16553bd8e..941932d34 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java @@ -1,3 +1,28 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; import java.util.List; @@ -5,17 +30,31 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +/** + * Factory for creating clones for the defined Input and Output type + * + * @param the Input type + * @param the Output type + * + * @author danish + */ public class CloneFactory { private ObjectMapper mapper = new ObjectMapper(); private Class elementType; - public CloneFactory(Class elementType) { + public CloneFactory(Class outputElementType) { super(); - this.elementType = elementType; + this.elementType = outputElementType; } + /** + * Creates clone for the provided input of {@link List} type + * + * @param input + * @return the cloned result + */ public List create(List input) { String serializedLangString = ""; @@ -36,6 +75,12 @@ public List create(List input) { return resultList; } + /** + * Creates clone for the provided input + * + * @param input + * @return the cloned result + */ public O create(I input) { String serializedLangString = ""; try { diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java index f9da147f2..e4445e5d8 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java @@ -35,16 +35,16 @@ import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException; import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; +import org.eclipse.digitaltwin.basyx.core.exceptions.RepositoryRegistryLinkException; import org.eclipse.digitaltwin.basyx.core.pagination.CursorResult; import org.eclipse.digitaltwin.basyx.core.pagination.PaginationInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Observer for the AASAggregator that triggers MQTT events for different - * operations on the aggregator. + * Decorator for linking {@link AasRepository} with AasRegistry * - * @author haque, jungjan, fischer, siebert + * @author danish * */ public class RegistryIntegrationAasRepository implements AasRepository { @@ -76,18 +76,6 @@ public void createAas(AssetAdministrationShell aas) throws CollidingIdentifierEx integrateAasWithRegistry(aas, aasRepositoryRegistryLink.getAasRepositoryURL()); } - private void integrateAasWithRegistry(AssetAdministrationShell shell, String aasRepositoryURL) { - AssetAdministrationShellDescriptor descriptor = new AasDescriptorFactory(shell, aasRepositoryURL).create(); - - RegistryAndDiscoveryInterfaceApi registryApi = aasRepositoryRegistryLink.getRegistryApi(); - - try { - registryApi.postAssetAdministrationShellDescriptor(descriptor); - } catch (ApiException e) { - e.printStackTrace(); - } - } - @Override public void updateAas(String aasId, AssetAdministrationShell aas) { decorated.updateAas(aasId, aas); @@ -100,16 +88,6 @@ public void deleteAas(String aasId) { deleteFromRegistry(shell.getId()); } - - private void deleteFromRegistry(String shellId) { - RegistryAndDiscoveryInterfaceApi registryApi = aasRepositoryRegistryLink.getRegistryApi(); - - try { - registryApi.deleteAssetAdministrationShellDescriptorById(shellId); - } catch (ApiException e) { - e.printStackTrace(); - } - } @Override public String getName() { @@ -140,5 +118,31 @@ public void setAssetInformation(String aasId, AssetInformation aasInfo) throws E public AssetInformation getAssetInformation(String aasId) throws ElementDoesNotExistException { return decorated.getAssetInformation(aasId); } + + private void integrateAasWithRegistry(AssetAdministrationShell shell, String aasRepositoryURL) { + AssetAdministrationShellDescriptor descriptor = new AasDescriptorFactory(shell, aasRepositoryURL).create(); + + RegistryAndDiscoveryInterfaceApi registryApi = aasRepositoryRegistryLink.getRegistryApi(); + + try { + registryApi.postAssetAdministrationShellDescriptor(descriptor); + + logger.info("Shell {} is automatically linked with the Registry", shell.getId()); + } catch (ApiException e) { + throw new RepositoryRegistryLinkException(shell.getId()); + } + } + + private void deleteFromRegistry(String shellId) { + RegistryAndDiscoveryInterfaceApi registryApi = aasRepositoryRegistryLink.getRegistryApi(); + + try { + registryApi.deleteAssetAdministrationShellDescriptorById(shellId); + + logger.info("Shell {} is automatically de-registered with the Registry", shellId); + } catch (ApiException e) { + throw new RuntimeException("Automatic deletion of the shell with shellId " + shellId + " from the Registry fails"); + } + } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java index ad12f0e27..6bae6f63a 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java @@ -27,6 +27,7 @@ package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; +import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; import org.eclipse.paho.client.mqttv3.MqttException; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; @@ -34,13 +35,18 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +/** + * Configuration for {@link AasRepository} with AasRegistry + * + * @author danish + */ @Configuration @ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.feature.registryintegration:}') && !T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.externalurl:}')") public class RegistryIntegrationAasRepositoryConfiguration { @Bean @ConditionalOnMissingBean - public AasRepositoryRegistryLink mqttClient(@Value("${basyx.aasrepository.feature.registryintegration}") String registryBasePath, @Value("${basyx.aasrepository.externalurl}") String aasRepositoryURL) throws MqttException { + public AasRepositoryRegistryLink getAasRepositoryRegistryLink(@Value("${basyx.aasrepository.feature.registryintegration}") String registryBasePath, @Value("${basyx.aasrepository.externalurl}") String aasRepositoryURL) throws MqttException { return new AasRepositoryRegistryLink(new RegistryAndDiscoveryInterfaceApi(registryBasePath), aasRepositoryURL); } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java index ccc64686d..d73c65037 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java @@ -26,21 +26,22 @@ package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; -import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; import org.eclipse.digitaltwin.basyx.aasrepository.AasRepositoryFactory; -import org.eclipse.paho.client.mqttv3.IMqttClient; +/** + * Factory for creating {@link RegistryIntegrationAasRepository} + * + * @author danish + */ public class RegistryIntegrationAasRepositoryFactory implements AasRepositoryFactory { private AasRepositoryFactory decorated; private AasRepositoryRegistryLink aasRepositoryRegistryLink; - private String aasRepositoryURL; public RegistryIntegrationAasRepositoryFactory(AasRepositoryFactory decorated, AasRepositoryRegistryLink aasRepositoryRegistryLink) { this.decorated = decorated; this.aasRepositoryRegistryLink = aasRepositoryRegistryLink; - this.aasRepositoryURL = aasRepositoryURL; } @Override diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java index 538de7ed0..0fa430c1f 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java @@ -26,16 +26,17 @@ package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; -import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; import org.eclipse.digitaltwin.basyx.aasrepository.AasRepositoryFactory; import org.eclipse.digitaltwin.basyx.aasrepository.feature.AasRepositoryFeature; -import org.eclipse.digitaltwin.basyx.common.mqttcore.encoding.URLEncoder; -import org.eclipse.paho.client.mqttv3.IMqttClient; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.stereotype.Component; +/** + * Feature for integrating Registry with Aas Repository + * + * @author danish + */ @Component @ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.feature.registryintegration:}') && !T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.externalurl:}')") public class RegistryIntegrationAasRepositoryFeature implements AasRepositoryFeature { diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestCloneFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestCloneFactory.java deleted file mode 100644 index 9adfffd05..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestCloneFactory.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.mqtt; - -import static org.junit.Assert.assertEquals; - -import java.util.List; - -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.CloneFactory; -import org.junit.Test; - -public class TestCloneFactory { - - @Test - public void createClone() { - List expectedDescriptions = RegistryIntegrationTestHelper.getAasRegLangStringTextTypes(); - - CloneFactory cloneFactory = new CloneFactory<>(LangStringTextType.class); - - List actualDescriptions = cloneFactory.create(RegistryIntegrationTestHelper.getAas4jLangStringTextTypes()); - - assertEquals(expectedDescriptions.size(), actualDescriptions.size()); - assertEquals(expectedDescriptions, actualDescriptions); - } - -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestMqttV2AASAggregatorObserver.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestMqttV2AASAggregatorObserver.java deleted file mode 100644 index 59b08c06b..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestMqttV2AASAggregatorObserver.java +++ /dev/null @@ -1,167 +0,0 @@ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.mqtt; - -/******************************************************************************* - * Copyright (C) 2021 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.digitaltwin.aas4j.v3.dataformat.DeserializationException; -import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.JsonDeserializer; -import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; -import org.eclipse.digitaltwin.aas4j.v3.model.Reference; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetAdministrationShell; -import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; -import org.eclipse.digitaltwin.basyx.aasrepository.AasRepositoryFactory; -import org.eclipse.digitaltwin.basyx.aasrepository.AasRepositorySuite; -import org.eclipse.digitaltwin.basyx.aasrepository.backend.SimpleAasRepositoryFactory; -import org.eclipse.digitaltwin.basyx.aasrepository.backend.inmemory.AasInMemoryBackendProvider; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.RegistryIntegrationAasRepositoryFactory; -import org.eclipse.digitaltwin.basyx.aasservice.backend.InMemoryAasServiceFactory; -import org.eclipse.digitaltwin.basyx.common.mqttcore.encoding.Base64URLEncoder; -import org.eclipse.digitaltwin.basyx.common.mqttcore.encoding.URLEncoder; -import org.eclipse.digitaltwin.basyx.common.mqttcore.listener.MqttTestListener; -import org.eclipse.paho.client.mqttv3.MqttClient; -import org.eclipse.paho.client.mqttv3.MqttException; -import org.eclipse.paho.client.mqttv3.MqttSecurityException; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import io.moquette.broker.Server; -import io.moquette.broker.config.ClasspathResourceLoader; -import io.moquette.broker.config.IConfig; -import io.moquette.broker.config.IResourceLoader; -import io.moquette.broker.config.ResourceLoaderConfig; - -/** - * Tests events emitting with the MqttAASAggregatorObserver - * - * @author haque, siebert, schnicke, danish - * - */ -public class TestMqttV2AASAggregatorObserver { -// private static Server mqttBroker; -// private static MqttClient mqttClient; -// private static MqttTestListener listener; -// private static RegistryIntegrationAasRepositoryTopicFactory topicFactory = new RegistryIntegrationAasRepositoryTopicFactory(new Base64URLEncoder()); -// -// private static AasRepository aasRepository; -// -// @BeforeClass -// public static void setUpClass() throws MqttException, IOException { -// mqttBroker = startBroker(); -// -// listener = configureInterceptListener(mqttBroker); -// -// mqttClient = createAndConnectClient(); -// -// aasRepository = createMqttAasRepository(mqttClient); -// } -// -// @AfterClass -// public static void tearDownClass() { -// mqttBroker.removeInterceptHandler(listener); -// mqttBroker.stopServer(); -// } -// -// @Test -// public void createAasEvent() throws DeserializationException { -// AssetAdministrationShell shell = createAasDummy("createAasEventId"); -// aasRepository.createAas(shell); -// -// assertEquals(topicFactory.createCreateAASTopic(aasRepository.getName()), listener.lastTopic); -// assertEquals(shell, deserializePayload(listener.lastPayload)); -// } -// -// @Test -// public void updateAasEvent() throws DeserializationException { -// AssetAdministrationShell shell = createAasDummy("updateAasEventId"); -// aasRepository.createAas(shell); -// -// addSubmodelReferenceToAas(shell); -// -// aasRepository.updateAas(shell.getId(), shell); -// -// assertEquals(topicFactory.createUpdateAASTopic(aasRepository.getName()), listener.lastTopic); -// assertEquals(shell, deserializePayload(listener.lastPayload)); -// } -// -// @Test -// public void deleteAasEvent() throws DeserializationException { -// AssetAdministrationShell shell = createAasDummy("deleteAasEventId"); -// aasRepository.createAas(shell); -// aasRepository.deleteAas(shell.getId()); -// -// assertEquals(topicFactory.createDeleteAASTopic(aasRepository.getName()), listener.lastTopic); -// assertEquals(shell, deserializePayload(listener.lastPayload)); -// } -// -// private AssetAdministrationShell deserializePayload(String payload) throws DeserializationException { -// return new JsonDeserializer().readReferable(payload, AssetAdministrationShell.class); -// } -// -// private void addSubmodelReferenceToAas(AssetAdministrationShell shell) { -// List submodelReferences = Arrays.asList(AasRepositorySuite.createDummyReference("dummySubmodelId1")); -// shell.setSubmodels(submodelReferences); -// } -// -// private AssetAdministrationShell createAasDummy(String aasId) { -// return new DefaultAssetAdministrationShell.Builder().id(aasId) -// .build(); -// } -// -// private static AasRepository createMqttAasRepository(MqttClient client) { -// AasRepositoryFactory repoFactory = new SimpleAasRepositoryFactory(new AasInMemoryBackendProvider(), new InMemoryAasServiceFactory()); -// -// return new RegistryIntegrationAasRepositoryFactory(repoFactory, client, new RegistryIntegrationAasRepositoryTopicFactory(new URLEncoder())).create(); -// } -// -// private static MqttTestListener configureInterceptListener(Server broker) { -// MqttTestListener testListener = new MqttTestListener(); -// broker.addInterceptHandler(testListener); -// -// return testListener; -// } -// -// private static MqttClient createAndConnectClient() throws MqttException, MqttSecurityException { -// MqttClient client = new MqttClient("tcp://localhost:1884", "testClient"); -// client.connect(); -// return client; -// } -// -// private static Server startBroker() throws IOException { -// Server broker = new Server(); -// IResourceLoader classpathLoader = new ClasspathResourceLoader(); -// -// IConfig classPathConfig = new ResourceLoaderConfig(classpathLoader); -// broker.startServer(classPathConfig); -// -// return broker; -// } -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java similarity index 68% rename from basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java rename to basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java index 4463268a8..cdb213063 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java @@ -1,4 +1,29 @@ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.mqtt; +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; import java.util.Arrays; import java.util.List; @@ -9,6 +34,11 @@ import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringNameType; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringTextType; +/** + * Test helper class for Registry integration + * + * @author danish + */ public class RegistryIntegrationTestHelper { // LangStringTextType AAS4J diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAttributeMapper.java similarity index 52% rename from basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java rename to basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAttributeMapper.java index b747a384c..8865ee275 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAttributeMapper.java @@ -1,4 +1,29 @@ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.mqtt; +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; import static org.junit.Assert.assertEquals; @@ -10,6 +35,11 @@ import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.AttributeMapper; import org.junit.Test; +/** + * Test class for {@link AttributeMapper} + * + * @author danish + */ public class TestAttributeMapper { @Test diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestCloneFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestCloneFactory.java new file mode 100644 index 000000000..d931721ba --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestCloneFactory.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; +import org.junit.Test; + +/** + * Test class for {@link CloneFactory} + * + * @author danish + */ +public class TestCloneFactory { + + @Test + public void createClone() { + List expectedDescriptions = RegistryIntegrationTestHelper.getAasRegLangStringTextTypes(); + + CloneFactory cloneFactory = new CloneFactory<>(LangStringTextType.class); + + List actualDescriptions = cloneFactory.create(RegistryIntegrationTestHelper.getAas4jLangStringTextTypes()); + + assertEquals(expectedDescriptions.size(), actualDescriptions.size()); + assertEquals(expectedDescriptions, actualDescriptions); + } + +} diff --git a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/RepositoryRegistryLinkException.java b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/RepositoryRegistryLinkException.java new file mode 100644 index 000000000..cc7bb0ad5 --- /dev/null +++ b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/RepositoryRegistryLinkException.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.core.exceptions; + +/** + * Indicates failure of automatic link between Repository and Registry + * + * @author danish + * + */ +@SuppressWarnings("serial") +public class RepositoryRegistryLinkException extends RuntimeException { + public RepositoryRegistryLinkException() { + } + + public RepositoryRegistryLinkException(String shellIdentifier) { + super(getMessage(shellIdentifier)); + } + + private static String getMessage(String shellIdentifier) { + return "Unable to link shell with id " + shellIdentifier + " with Registry"; + } + +} From e4e692d2075c6258cfc080261be1afc355573f16 Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Tue, 14 Nov 2023 11:31:55 +0100 Subject: [PATCH 09/21] Cherry-pick + submodel reg integ Signed-off-by: Mohammad Ghazanfar Ali Danish --- .../integration/AasDescriptorFactory.java | 4 + .../registry/integration/CloneFactory.java | 46 +++++ .../deserializer/KeyTypeDeserializer.java | 30 ++++ .../ReferenceTypeDeserializer.java | 32 ++++ .../mixin/AdministrativeInformationMixin.java | 12 ++ .../integration/mixin/ReferenceMixin.java | 14 ++ .../mqtt/RegistryIntegrationTestHelper.java | 89 ++++++++++ .../feature/mqtt/TestAttributeMapper.java | 54 ++++++ .../feature/mqtt/TestCloneFactory.java | 37 ++++ .../Readme.md | 3 + .../pom.xml | 56 ++++++ .../integration/AasDescriptorFactory.java | 162 ++++++++++++++++++ .../AasRepositoryRegistryLink.java | 55 ++++++ .../registry/integration/AttributeMapper.java | 80 +++++++++ .../registry/integration/CloneFactory.java | 100 +++++++++++ .../RegistryIntegrationAasRepository.java | 148 ++++++++++++++++ ...IntegrationAasRepositoryConfiguration.java | 54 ++++++ ...gistryIntegrationAasRepositoryFactory.java | 52 ++++++ ...gistryIntegrationAasRepositoryFeature.java | 75 ++++++++ .../RegistryIntegrationTestHelper.java | 84 +++++++++ .../integration/TestAttributeMapper.java | 74 ++++++++ .../integration/TestCloneFactory.java | 54 ++++++ .../src/test/resources/config/moquette.conf | 6 + 23 files changed, 1321 insertions(+) create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/KeyTypeDeserializer.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/ReferenceTypeDeserializer.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/AdministrativeInformationMixin.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ReferenceMixin.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestCloneFactory.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/Readme.md create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/pom.xml create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAttributeMapper.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestCloneFactory.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/resources/config/moquette.conf diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java index cb3f373e4..a50758e75 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java @@ -74,6 +74,10 @@ public AssetAdministrationShellDescriptor create() { setDisplayName(shell.getDisplayName(), descriptor); +// setExtensions(shell.getExtensions(), descriptor); + +// setAdministration(shell.getAdministration(), descriptor); + setAssetKind(shell.getAssetInformation(), descriptor); setAssetType(shell.getAssetInformation(), descriptor); diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java index 941932d34..9b92650ea 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java @@ -27,6 +27,15 @@ import java.util.List; +import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.deserializer.KeyTypeDeserializer; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.deserializer.ReferenceTypeDeserializer; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin.AdministrativeInformationMixin; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin.ReferenceMixin; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -55,6 +64,43 @@ public CloneFactory(Class outputElementType) { * @param input * @return the cloned result */ + private void configureMixins() { + SimpleModule module = new SimpleModule(); + module.setMixInAnnotation(AdministrativeInformation.class, AdministrativeInformationMixin.class); + mapper.registerModule(module); + + SimpleModule module2 = new SimpleModule(); + module2.setMixInAnnotation(Reference.class, ReferenceMixin.class); + mapper.registerModule(module2); + + SimpleModule moduleDeser = new SimpleModule(); + moduleDeser.addDeserializer(KeyTypes.class, new KeyTypeDeserializer()); + mapper.registerModule(moduleDeser); + + SimpleModule moduleDeser2 = new SimpleModule(); + moduleDeser2.addDeserializer(ReferenceTypes.class, new ReferenceTypeDeserializer()); + mapper.registerModule(moduleDeser2); + } + +// public O create() { +// String serializedLangString = ""; +// try { +// serializedLangString = mapper.writeValueAsString(input); +// } catch (JsonProcessingException e) { +// e.printStackTrace(); +// } +// +// O administrativeInformation = null; +// +// try { +// administrativeInformation = mapper.readValue(serializedLangString, new TypeReference() {}); +// } catch (JsonProcessingException e) { +// e.printStackTrace(); +// } +// +// return administrativeInformation; +// } + public List create(List input) { String serializedLangString = ""; diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/KeyTypeDeserializer.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/KeyTypeDeserializer.java new file mode 100644 index 000000000..aa751b51c --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/KeyTypeDeserializer.java @@ -0,0 +1,30 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.deserializer; + +import java.io.IOException; + +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes; + +import com.fasterxml.jackson.core.JacksonException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; + +public class KeyTypeDeserializer extends JsonDeserializer { + + @Override + public KeyTypes deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { + try { + JsonNode node = p.getCodec().readTree(p); + + String value = node.asText(); + + return KeyTypes.valueOf(KeyTypes.class, value); + + } catch (Exception e) { + throw new RuntimeException("Unable to deserialize the KeyTypes Enum"); + } + } + +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/ReferenceTypeDeserializer.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/ReferenceTypeDeserializer.java new file mode 100644 index 000000000..de3a8748a --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/ReferenceTypeDeserializer.java @@ -0,0 +1,32 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.deserializer; + +import java.io.IOException; + +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes; + +import com.fasterxml.jackson.core.JacksonException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; + +public class ReferenceTypeDeserializer extends JsonDeserializer { + + @Override + public ReferenceTypes deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { + try { + JsonNode node = p.getCodec().readTree(p); + + String value = node.asText(); + +// return ReferenceTypes.valueOf(ReferenceTypes.class, value); + return ReferenceTypes.EXTERNALREFERENCE; + + } catch (Exception e) { + throw new RuntimeException("Unable to deserialize the ReferenceTypes Enum"); + } + } + +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/AdministrativeInformationMixin.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/AdministrativeInformationMixin.java new file mode 100644 index 000000000..c6aeae391 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/AdministrativeInformationMixin.java @@ -0,0 +1,12 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public interface AdministrativeInformationMixin { + + @JsonProperty("templateId") + public String getTemplateID(); + + +// public String getTemplateId(); +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ReferenceMixin.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ReferenceMixin.java new file mode 100644 index 000000000..0f933482a --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ReferenceMixin.java @@ -0,0 +1,14 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin; + +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public interface ReferenceMixin { + + @JsonProperty("referredSemanticId") + public Reference getReferredSemanticID(); + + +// public String getTemplateId(); +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java new file mode 100644 index 000000000..732564454 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java @@ -0,0 +1,89 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.mqtt; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; +import org.eclipse.digitaltwin.aas4j.v3.model.EmbeddedDataSpecification; +import org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; +import org.eclipse.digitaltwin.aas4j.v3.model.ReferenceTypes; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultEmbeddedDataSpecification; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultKey; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringNameType; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringTextType; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultReference; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Key; + +public class RegistryIntegrationTestHelper { + + // LangStringTextType AAS4J + private static final LangStringTextType aas4jLangStringTextType_1 = new DefaultLangStringTextType.Builder().language("de").text("Ein Beispiel").build(); + private static final LangStringTextType aas4jLangStringTextType_2 = new DefaultLangStringTextType.Builder().language("en").text("An Example").build(); + + // LangStringTextType AasRegistry + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType aasRegLangStringTextType_1 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("de") + .text("Ein Beispiel"); + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType aasRegLangStringTextType_2 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("en") + .text("An Example"); + + // LangStringNameType AAS4J + private static final LangStringNameType AAS4J_LANG_STRING_NAME_TYPE_1 = new DefaultLangStringNameType.Builder().language("en").text("Name type string").build(); + private static final LangStringNameType AAS4J_LANG_STRING_NAME_TYPE_2 = new DefaultLangStringNameType.Builder().language("de").text("Namenstypzeichenfolge").build(); + + // LangStringTextType AasRegistry + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType AASREG_LANG_STRING_NAME_TYPE_1 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType().language("en").text("Name type string"); + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType AASREG_LANG_STRING_NAME_TYPE_2 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType().language("de").text("Namenstypzeichenfolge"); + + // AssetKind AAS4J + public static final AssetKind AAS4J_ASSET_KIND = AssetKind.INSTANCE; + + // AssetKind AasRegistry + public static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind AASREG_ASSET_KIND = org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind.INSTANCE; + + // Administration AAS4J + private static final Reference aas4jDataSpecification = new DefaultReference.Builder().keys(new DefaultKey.Builder().type(KeyTypes.BLOB).value("BlobValue").build()).type(ReferenceTypes.EXTERNAL_REFERENCE).build(); + private static final EmbeddedDataSpecification AAS4JEMB_EMBEDDED_DATA_SPECIFICATION = new DefaultEmbeddedDataSpecification.Builder().dataSpecification(aas4jDataSpecification).build(); + private static final String aas4jVersion = "1.0.0"; + private static final String aas4jRevision = "3"; + private static final String aas4jTemplateId = "ID2.0"; + + // Administration AAS4J + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.Reference aasRegDataSpecification = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.Reference() + .keys(Arrays.asList(new Key().type(org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes.BLOB).value("BlobValue"))).type(org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes.EXTERNALREFERENCE); + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.EmbeddedDataSpecification AASREG_EMBEDDED_DATA_SPECIFICATION = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.EmbeddedDataSpecification() + .dataSpecification(aasRegDataSpecification); + private static final String aasRegVersion = "1.0.0"; + private static final String aasRegRevision = "3"; + private static final String aasRegTemplateId = "ID2.0"; + + public static List getAas4jLangStringTextTypes() { + return Arrays.asList(aas4jLangStringTextType_1, aas4jLangStringTextType_2); + } + + public static List getAasRegLangStringTextTypes() { + return Arrays.asList(aasRegLangStringTextType_1, aasRegLangStringTextType_2); + } + + public static AdministrativeInformation getAas4jAdministration() { + return new DefaultAdministrativeInformation.Builder().embeddedDataSpecifications(AAS4JEMB_EMBEDDED_DATA_SPECIFICATION).version(aas4jVersion).revision(aas4jRevision).templateID(aas4jTemplateId).build(); + } + + public static org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation getAasRegAdministration() { + return new org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation().embeddedDataSpecifications(Arrays.asList(AASREG_EMBEDDED_DATA_SPECIFICATION)).version(aasRegVersion).revision(aasRegRevision) + .templateId(aasRegTemplateId); + } + + public static List getAas4jLangStringNameTypes() { + return Arrays.asList(AAS4J_LANG_STRING_NAME_TYPE_1, AAS4J_LANG_STRING_NAME_TYPE_2); + } + + public static List getAasRegLangStringNameTypes() { + return Arrays.asList(AASREG_LANG_STRING_NAME_TYPE_1, AASREG_LANG_STRING_NAME_TYPE_2); + } + +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java new file mode 100644 index 000000000..523614ce3 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java @@ -0,0 +1,54 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.mqtt; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.AttributeMapper; +import org.junit.Test; + +public class TestAttributeMapper { + + @Test + public void mapDescriptions() { + List expectedDescriptions = RegistryIntegrationTestHelper.getAasRegLangStringTextTypes(); + + List actualDescriptions = new AttributeMapper().mapDescription(RegistryIntegrationTestHelper.getAas4jLangStringTextTypes()); + + assertEquals(expectedDescriptions.size(), actualDescriptions.size()); + assertEquals(expectedDescriptions, actualDescriptions); + } + +// @Test +// public void mapAdministration() { +// AdministrativeInformation expectedAdministrativeInformation = RegistryIntegrationTestHelper.getAasRegAdministration(); +// +// AdministrativeInformation actualAdministrativeInformation = new AttributeMapper().mapAdministration(RegistryIntegrationTestHelper.getAas4jAdministration()); +// +// assertEquals(expectedAdministrativeInformation, actualAdministrativeInformation); +// } + + @Test + public void mapDisplayNames() { + List expectedDisplayNames = RegistryIntegrationTestHelper.getAasRegLangStringNameTypes(); + + List actualDisplayNames = new AttributeMapper().mapDisplayName(RegistryIntegrationTestHelper.getAas4jLangStringNameTypes()); + + assertEquals(expectedDisplayNames.size(), actualDisplayNames.size()); + assertEquals(expectedDisplayNames, actualDisplayNames); + } + + @Test + public void mapAssetKind() { + AssetKind expectedAssetKind = RegistryIntegrationTestHelper.AASREG_ASSET_KIND; + + AssetKind actualAssetKind = new AttributeMapper().mapAssetKind(RegistryIntegrationTestHelper.AAS4J_ASSET_KIND); + + assertEquals(expectedAssetKind, actualAssetKind); + } + +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestCloneFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestCloneFactory.java new file mode 100644 index 000000000..06bf43a2c --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestCloneFactory.java @@ -0,0 +1,37 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.mqtt; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.AttributeMapper; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.CloneFactory; +import org.junit.Test; + +public class TestCloneFactory { + + @Test + public void createCloneOfListType() { + List expectedDescriptions = RegistryIntegrationTestHelper.getAasRegLangStringTextTypes(); + + CloneFactory cloneFactory = new CloneFactory<>(LangStringTextType.class); + + List actualDescriptions = cloneFactory.create(RegistryIntegrationTestHelper.getAas4jLangStringTextTypes()); + + assertEquals(expectedDescriptions.size(), actualDescriptions.size()); + assertEquals(expectedDescriptions, actualDescriptions); + } + +// @Test +// public void createCloneOfNonListType() { +// AssetKind expectedAssetKind = RegistryIntegrationTestHelper.AASREG_ASSET_KIND; +// +// AssetKind actualAssetKind = new AttributeMapper().mapAssetKind(RegistryIntegrationTestHelper.AAS4J_ASSET_KIND); +// +// assertEquals(expectedAssetKind, actualAssetKind); +// } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/Readme.md b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/Readme.md new file mode 100644 index 000000000..a115b941d --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/Readme.md @@ -0,0 +1,3 @@ +# AssetAdministrationShell Repository - Registry Integration +This feature automatically integrates the Descriptor with the Registry while creation of the Shell at Repository. +It also automatically removes the Descriptor from the Registry when the Shell is removed from the Repository. \ No newline at end of file diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/pom.xml b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/pom.xml new file mode 100644 index 000000000..cfb351e68 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/pom.xml @@ -0,0 +1,56 @@ + + 4.0.0 + + + org.eclipse.digitaltwin.basyx + basyx.submodelrepository + ${revision} + + + basyx.submodelrepository-feature-registry-integration + + + + org.eclipse.digitaltwin.basyx + basyx.submodelregistry-client-native + + + org.eclipse.digitaltwin.basyx + basyx.submodelrepository-core + + + org.eclipse.digitaltwin.basyx + basyx.http + + + org.eclipse.digitaltwin.basyx + basyx.submodelrepository-core + tests + test + + + org.eclipse.digitaltwin.basyx + basyx.submodelrepository-backend-inmemory + test + + + org.eclipse.digitaltwin.basyx + basyx.submodelrepository-backend-inmemory + test + + + org.eclipse.digitaltwin.aas4j + dataformat-json + + + org.springframework.boot + spring-boot-starter + + + org.eclipse.digitaltwin.basyx + basyx.submodelservice-backend-inmemory + + + \ No newline at end of file diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java new file mode 100644 index 000000000..cb3f373e4 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java @@ -0,0 +1,162 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; + +import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; +import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Endpoint; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ProtocolInformation; +import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; + +/** + * Factory for creating the {@link AssetAdministrationShellDescriptor} + * + * @author danish + */ +public class AasDescriptorFactory { + + private static final String AAS_INTERFACE = "AAS-3.0"; + private AssetAdministrationShell shell; + private String aasRepositoryURL; + + public AasDescriptorFactory(AssetAdministrationShell shell, String aasRepositoryURL) { + super(); + this.shell = shell; + this.aasRepositoryURL = aasRepositoryURL; + } + + /** + * Creates {@link AssetAdministrationShellDescriptor} + * + * @return the created AssetAdministrationShellDescriptor + */ + public AssetAdministrationShellDescriptor create() { + + AssetAdministrationShellDescriptor descriptor = new AssetAdministrationShellDescriptor(); + + setId(shell.getId(), descriptor); + + setIdShort(shell.getIdShort(), descriptor); + + setEndpointItem(shell.getId(), descriptor); + + setDescription(shell.getDescription(), descriptor); + + setDisplayName(shell.getDisplayName(), descriptor); + + setAssetKind(shell.getAssetInformation(), descriptor); + + setAssetType(shell.getAssetInformation(), descriptor); + + setGlobalAssetId(shell.getAssetInformation(), descriptor); + + return descriptor; + } + + private void setDescription(List descriptions, AssetAdministrationShellDescriptor descriptor) { + + if (descriptions == null || descriptions.isEmpty()) + return; + + descriptor.setDescription(new AttributeMapper().mapDescription(descriptions)); + } + + private void setDisplayName(List displayNames, AssetAdministrationShellDescriptor descriptor) { + + if (displayNames == null || displayNames.isEmpty()) + return; + + descriptor.setDisplayName(new AttributeMapper().mapDisplayName(displayNames)); + } + + private void setAssetKind(AssetInformation assetInformation, AssetAdministrationShellDescriptor descriptor) { + + if (assetInformation == null || assetInformation.getAssetKind() == null) + return; + + descriptor.setAssetKind(new AttributeMapper().mapAssetKind(assetInformation.getAssetKind())); + } + + private void setAssetType(AssetInformation assetInformation, AssetAdministrationShellDescriptor descriptor) { + + if (assetInformation == null || assetInformation.getAssetType() == null) + return; + + descriptor.setAssetType(assetInformation.getAssetType()); + } + + private void setGlobalAssetId(AssetInformation assetInformation, AssetAdministrationShellDescriptor descriptor) { + + if (assetInformation == null || assetInformation.getGlobalAssetID() == null) + return; + + descriptor.setGlobalAssetId(assetInformation.getGlobalAssetID()); + } + + private void setEndpointItem(String shellId, AssetAdministrationShellDescriptor descriptor) { + + Endpoint endpoint = new Endpoint(); + endpoint.setInterface(AAS_INTERFACE); + ProtocolInformation protocolInformation = createProtocolInformation(shellId); + endpoint.setProtocolInformation(protocolInformation); + + descriptor.addEndpointsItem(endpoint); + } + + private ProtocolInformation createProtocolInformation(String shellId) { + String href = String.format("%s/%s", aasRepositoryURL, Base64UrlEncodedIdentifier.encodeIdentifier(shellId)); + + ProtocolInformation protocolInformation = new ProtocolInformation(); + protocolInformation.endpointProtocol(getProtocol(href)); + protocolInformation.setHref(href); + + return protocolInformation; + } + + private void setIdShort(String idShort, AssetAdministrationShellDescriptor descriptor) { + descriptor.setIdShort(idShort); + } + + private void setId(String shellId, AssetAdministrationShellDescriptor descriptor) { + descriptor.setId(shellId); + } + + private String getProtocol(String endpoint) { + try { + return new URL(endpoint).getProtocol(); + } catch (MalformedURLException e) { + throw new RuntimeException(); + } + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java new file mode 100644 index 000000000..d13b3e8a3 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; +import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; + +/** + * Represents information for linking {@link AasRepository} with AasRegistry + * + * @author danish + */ +public class AasRepositoryRegistryLink { + + private RegistryAndDiscoveryInterfaceApi registryApi; + private String aasRepositoryURL; + + public AasRepositoryRegistryLink(RegistryAndDiscoveryInterfaceApi registryApi, String aasRepositoryURL) { + super(); + this.registryApi = registryApi; + this.aasRepositoryURL = aasRepositoryURL; + } + + public RegistryAndDiscoveryInterfaceApi getRegistryApi() { + return registryApi; + } + + public String getAasRepositoryURL() { + return aasRepositoryURL; + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java new file mode 100644 index 000000000..4c05095d6 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import java.util.List; + +import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; +import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; + +/** + * Maps the models defined in AasRegistry client to the AAS4J models + * + * @author danish + */ +public class AttributeMapper { + + /** + * Maps {@link AssetAdministrationShell#getDescription()} from AAS4J to + * AasRegistry client + * + * @param descriptions + * @return the mapped descriptions + */ + public List mapDescription(List descriptions) { + CloneFactory cloneFactory = new CloneFactory<>(LangStringTextType.class); + + return cloneFactory.create(descriptions); + } + + /** + * Maps {@link AssetAdministrationShell#getDisplayName()} from AAS4J to + * AasRegistry client + * + * @param displayNames + * @return the mapped displayNames + */ + public List mapDisplayName(List displayNames) { + CloneFactory cloneFactory = new CloneFactory<>(LangStringNameType.class); + + return cloneFactory.create(displayNames); + } + + /** + * Maps {@link AssetInformation#getAssetKind()} from AAS4J to AasRegistry client + * + * @param assetKind + * @return the mapped assetKind + */ + public AssetKind mapAssetKind(org.eclipse.digitaltwin.aas4j.v3.model.AssetKind assetKind) { + + return AssetKind.valueOf(AssetKind.class, assetKind.name()); + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java new file mode 100644 index 000000000..941932d34 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import java.util.List; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Factory for creating clones for the defined Input and Output type + * + * @param the Input type + * @param the Output type + * + * @author danish + */ +public class CloneFactory { + + private ObjectMapper mapper = new ObjectMapper(); + + private Class elementType; + + public CloneFactory(Class outputElementType) { + super(); + this.elementType = outputElementType; + } + + /** + * Creates clone for the provided input of {@link List} type + * + * @param input + * @return the cloned result + */ + public List create(List input) { + String serializedLangString = ""; + + try { + serializedLangString = mapper.writeValueAsString(input); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + + List resultList = null; + + try { + resultList = mapper.readValue(serializedLangString, mapper.getTypeFactory().constructCollectionType(List.class, elementType)); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + + return resultList; + } + + /** + * Creates clone for the provided input + * + * @param input + * @return the cloned result + */ + public O create(I input) { + String serializedLangString = ""; + try { + serializedLangString = mapper.writeValueAsString(input); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + + try { + return mapper.readValue(serializedLangString, elementType); + } catch (JsonProcessingException e) { + e.printStackTrace(); + throw new RuntimeException(); + } + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java new file mode 100644 index 000000000..e4445e5d8 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * Copyright (C) 2021 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import java.util.List; + +import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; +import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; +import org.eclipse.digitaltwin.basyx.aasregistry.client.ApiException; +import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor; +import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; +import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException; +import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; +import org.eclipse.digitaltwin.basyx.core.exceptions.RepositoryRegistryLinkException; +import org.eclipse.digitaltwin.basyx.core.pagination.CursorResult; +import org.eclipse.digitaltwin.basyx.core.pagination.PaginationInfo; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Decorator for linking {@link AasRepository} with AasRegistry + * + * @author danish + * + */ +public class RegistryIntegrationAasRepository implements AasRepository { + private static Logger logger = LoggerFactory.getLogger(RegistryIntegrationAasRepository.class); + + private AasRepository decorated; + + private AasRepositoryRegistryLink aasRepositoryRegistryLink; + + public RegistryIntegrationAasRepository(AasRepository decorated, AasRepositoryRegistryLink aasRepositoryRegistryLink) { + this.decorated = decorated; + this.aasRepositoryRegistryLink = aasRepositoryRegistryLink; + } + + @Override + public CursorResult> getAllAas(PaginationInfo pInfo) { + return decorated.getAllAas(pInfo); + } + + @Override + public AssetAdministrationShell getAas(String aasId) throws ElementDoesNotExistException { + return decorated.getAas(aasId); + } + + @Override + public void createAas(AssetAdministrationShell aas) throws CollidingIdentifierException { + decorated.createAas(aas); + + integrateAasWithRegistry(aas, aasRepositoryRegistryLink.getAasRepositoryURL()); + } + + @Override + public void updateAas(String aasId, AssetAdministrationShell aas) { + decorated.updateAas(aasId, aas); + } + + @Override + public void deleteAas(String aasId) { + AssetAdministrationShell shell = decorated.getAas(aasId); + decorated.deleteAas(aasId); + + deleteFromRegistry(shell.getId()); + } + + @Override + public String getName() { + return decorated.getName(); + } + + @Override + public CursorResult> getSubmodelReferences(String aasId, PaginationInfo pInfo) { + return decorated.getSubmodelReferences(aasId, pInfo); + } + + @Override + public void addSubmodelReference(String aasId, Reference submodelReference) { + decorated.addSubmodelReference(aasId, submodelReference); + } + + @Override + public void removeSubmodelReference(String aasId, String submodelId) { + decorated.removeSubmodelReference(aasId, submodelId); + } + + @Override + public void setAssetInformation(String aasId, AssetInformation aasInfo) throws ElementDoesNotExistException { + decorated.setAssetInformation(aasId, aasInfo); + } + + @Override + public AssetInformation getAssetInformation(String aasId) throws ElementDoesNotExistException { + return decorated.getAssetInformation(aasId); + } + + private void integrateAasWithRegistry(AssetAdministrationShell shell, String aasRepositoryURL) { + AssetAdministrationShellDescriptor descriptor = new AasDescriptorFactory(shell, aasRepositoryURL).create(); + + RegistryAndDiscoveryInterfaceApi registryApi = aasRepositoryRegistryLink.getRegistryApi(); + + try { + registryApi.postAssetAdministrationShellDescriptor(descriptor); + + logger.info("Shell {} is automatically linked with the Registry", shell.getId()); + } catch (ApiException e) { + throw new RepositoryRegistryLinkException(shell.getId()); + } + } + + private void deleteFromRegistry(String shellId) { + RegistryAndDiscoveryInterfaceApi registryApi = aasRepositoryRegistryLink.getRegistryApi(); + + try { + registryApi.deleteAssetAdministrationShellDescriptorById(shellId); + + logger.info("Shell {} is automatically de-registered with the Registry", shellId); + } catch (ApiException e) { + throw new RuntimeException("Automatic deletion of the shell with shellId " + shellId + " from the Registry fails"); + } + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java new file mode 100644 index 000000000..6bae6f63a --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + + +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; +import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; +import org.eclipse.paho.client.mqttv3.MqttException; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Configuration for {@link AasRepository} with AasRegistry + * + * @author danish + */ +@Configuration +@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.feature.registryintegration:}') && !T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.externalurl:}')") +public class RegistryIntegrationAasRepositoryConfiguration { + + @Bean + @ConditionalOnMissingBean + public AasRepositoryRegistryLink getAasRepositoryRegistryLink(@Value("${basyx.aasrepository.feature.registryintegration}") String registryBasePath, @Value("${basyx.aasrepository.externalurl}") String aasRepositoryURL) throws MqttException { + + return new AasRepositoryRegistryLink(new RegistryAndDiscoveryInterfaceApi(registryBasePath), aasRepositoryURL); + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java new file mode 100644 index 000000000..d73c65037 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + + +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; +import org.eclipse.digitaltwin.basyx.aasrepository.AasRepositoryFactory; + +/** + * Factory for creating {@link RegistryIntegrationAasRepository} + * + * @author danish + */ +public class RegistryIntegrationAasRepositoryFactory implements AasRepositoryFactory { + + private AasRepositoryFactory decorated; + private AasRepositoryRegistryLink aasRepositoryRegistryLink; + + public RegistryIntegrationAasRepositoryFactory(AasRepositoryFactory decorated, AasRepositoryRegistryLink aasRepositoryRegistryLink) { + this.decorated = decorated; + this.aasRepositoryRegistryLink = aasRepositoryRegistryLink; + } + + @Override + public AasRepository create() { + return new RegistryIntegrationAasRepository(decorated.create(), aasRepositoryRegistryLink); + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java new file mode 100644 index 000000000..0fa430c1f --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + + +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import org.eclipse.digitaltwin.basyx.aasrepository.AasRepositoryFactory; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.AasRepositoryFeature; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.stereotype.Component; + +/** + * Feature for integrating Registry with Aas Repository + * + * @author danish + */ +@Component +@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.feature.registryintegration:}') && !T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.externalurl:}')") +public class RegistryIntegrationAasRepositoryFeature implements AasRepositoryFeature { + public final static String FEATURENAME = "basyx.aasrepository.feature.registryintegration"; + + private AasRepositoryRegistryLink aasRepositoryRegistryLink; + + @Autowired + public RegistryIntegrationAasRepositoryFeature(AasRepositoryRegistryLink aasRepositoryRegistryLink) { + this.aasRepositoryRegistryLink = aasRepositoryRegistryLink; + } + + @Override + public AasRepositoryFactory decorate(AasRepositoryFactory aasRepositoryFactory) { + return new RegistryIntegrationAasRepositoryFactory(aasRepositoryFactory, aasRepositoryRegistryLink); + } + + @Override + public void initialize() { + } + + @Override + public void cleanUp() { + + } + + @Override + public String getName() { + return "AasRepository Registry Integration"; + } + + @Override + public boolean isEnabled() { + return true; + } +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java new file mode 100644 index 000000000..cdb213063 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringNameType; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringTextType; + +/** + * Test helper class for Registry integration + * + * @author danish + */ +public class RegistryIntegrationTestHelper { + + // LangStringTextType AAS4J + private static final LangStringTextType aas4jLangStringTextType_1 = new DefaultLangStringTextType.Builder().language("de").text("Ein Beispiel").build(); + private static final LangStringTextType aas4jLangStringTextType_2 = new DefaultLangStringTextType.Builder().language("en").text("An Example").build(); + + // LangStringTextType AasRegistry + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType aasRegLangStringTextType_1 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("de") + .text("Ein Beispiel"); + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType aasRegLangStringTextType_2 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("en") + .text("An Example"); + + // LangStringNameType AAS4J + private static final LangStringNameType AAS4J_LANG_STRING_NAME_TYPE_1 = new DefaultLangStringNameType.Builder().language("en").text("Name type string").build(); + private static final LangStringNameType AAS4J_LANG_STRING_NAME_TYPE_2 = new DefaultLangStringNameType.Builder().language("de").text("Namenstypzeichenfolge").build(); + + // LangStringTextType AasRegistry + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType AASREG_LANG_STRING_NAME_TYPE_1 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType().language("en").text("Name type string"); + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType AASREG_LANG_STRING_NAME_TYPE_2 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType().language("de").text("Namenstypzeichenfolge"); + + // AssetKind AAS4J + public static final AssetKind AAS4J_ASSET_KIND = AssetKind.INSTANCE; + + // AssetKind AasRegistry + public static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind AASREG_ASSET_KIND = org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind.INSTANCE; + + public static List getAas4jLangStringTextTypes() { + return Arrays.asList(aas4jLangStringTextType_1, aas4jLangStringTextType_2); + } + + public static List getAasRegLangStringTextTypes() { + return Arrays.asList(aasRegLangStringTextType_1, aasRegLangStringTextType_2); + } + + public static List getAas4jLangStringNameTypes() { + return Arrays.asList(AAS4J_LANG_STRING_NAME_TYPE_1, AAS4J_LANG_STRING_NAME_TYPE_2); + } + + public static List getAasRegLangStringNameTypes() { + return Arrays.asList(AASREG_LANG_STRING_NAME_TYPE_1, AASREG_LANG_STRING_NAME_TYPE_2); + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAttributeMapper.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAttributeMapper.java new file mode 100644 index 000000000..8865ee275 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAttributeMapper.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.AttributeMapper; +import org.junit.Test; + +/** + * Test class for {@link AttributeMapper} + * + * @author danish + */ +public class TestAttributeMapper { + + @Test + public void mapDescriptions() { + List expectedDescriptions = RegistryIntegrationTestHelper.getAasRegLangStringTextTypes(); + + List actualDescriptions = new AttributeMapper().mapDescription(RegistryIntegrationTestHelper.getAas4jLangStringTextTypes()); + + assertEquals(expectedDescriptions.size(), actualDescriptions.size()); + assertEquals(expectedDescriptions, actualDescriptions); + } + + @Test + public void mapDisplayNames() { + List expectedDisplayNames = RegistryIntegrationTestHelper.getAasRegLangStringNameTypes(); + + List actualDisplayNames = new AttributeMapper().mapDisplayName(RegistryIntegrationTestHelper.getAas4jLangStringNameTypes()); + + assertEquals(expectedDisplayNames.size(), actualDisplayNames.size()); + assertEquals(expectedDisplayNames, actualDisplayNames); + } + + @Test + public void mapAssetKind() { + AssetKind expectedAssetKind = RegistryIntegrationTestHelper.AASREG_ASSET_KIND; + + AssetKind actualAssetKind = new AttributeMapper().mapAssetKind(RegistryIntegrationTestHelper.AAS4J_ASSET_KIND); + + assertEquals(expectedAssetKind, actualAssetKind); + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestCloneFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestCloneFactory.java new file mode 100644 index 000000000..d931721ba --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestCloneFactory.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; +import org.junit.Test; + +/** + * Test class for {@link CloneFactory} + * + * @author danish + */ +public class TestCloneFactory { + + @Test + public void createClone() { + List expectedDescriptions = RegistryIntegrationTestHelper.getAasRegLangStringTextTypes(); + + CloneFactory cloneFactory = new CloneFactory<>(LangStringTextType.class); + + List actualDescriptions = cloneFactory.create(RegistryIntegrationTestHelper.getAas4jLangStringTextTypes()); + + assertEquals(expectedDescriptions.size(), actualDescriptions.size()); + assertEquals(expectedDescriptions, actualDescriptions); + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/resources/config/moquette.conf b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/resources/config/moquette.conf new file mode 100644 index 000000000..8511afcd1 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/resources/config/moquette.conf @@ -0,0 +1,6 @@ +# Moquette Java Broker configuration file for testing + +# Do not use the default 1883 port +port 1884 +host 0.0.0.0 +allow_anonymous true \ No newline at end of file From 8e4c6e2b21e7c7dc15157f674c49b8f1161611ec Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Tue, 14 Nov 2023 15:57:59 +0100 Subject: [PATCH 10/21] Includes admins info and Extensions Signed-off-by: Mohammad Ghazanfar Ali Danish --- .../integration/AasDescriptorFactory.java | 90 +++++++++++-------- .../registry/integration/AttributeMapper.java | 14 +++ .../registry/integration/CloneFactory.java | 37 ++++---- .../DataTypeDefXsdDeserializer.java | 38 ++++++++ .../ReferenceTypeDeserializer.java | 15 ++-- .../integration/mixin/ExtensionMixin.java | 14 +++ .../mqtt/RegistryIntegrationTestHelper.java | 21 ++++- .../feature/mqtt/TestAttributeMapper.java | 29 ++++-- 8 files changed, 188 insertions(+), 70 deletions(-) create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/DataTypeDefXsdDeserializer.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ExtensionMixin.java diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java index a50758e75..9db1f7873 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java @@ -29,8 +29,10 @@ import java.net.URL; import java.util.List; +import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.Extension; import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor; @@ -44,106 +46,122 @@ * @author danish */ public class AasDescriptorFactory { - + private static final String AAS_INTERFACE = "AAS-3.0"; private AssetAdministrationShell shell; private String aasRepositoryURL; - + public AasDescriptorFactory(AssetAdministrationShell shell, String aasRepositoryURL) { super(); this.shell = shell; this.aasRepositoryURL = aasRepositoryURL; } - + /** - * Creates {@link AssetAdministrationShellDescriptor} + * Creates {@link AssetAdministrationShellDescriptor} * * @return the created AssetAdministrationShellDescriptor */ public AssetAdministrationShellDescriptor create() { - + AssetAdministrationShellDescriptor descriptor = new AssetAdministrationShellDescriptor(); - + setId(shell.getId(), descriptor); - + setIdShort(shell.getIdShort(), descriptor); - + setEndpointItem(shell.getId(), descriptor); - + setDescription(shell.getDescription(), descriptor); - + setDisplayName(shell.getDisplayName(), descriptor); - -// setExtensions(shell.getExtensions(), descriptor); - -// setAdministration(shell.getAdministration(), descriptor); - + + setExtensions(shell.getExtensions(), descriptor); + + setAdministration(shell.getAdministration(), descriptor); + setAssetKind(shell.getAssetInformation(), descriptor); - + setAssetType(shell.getAssetInformation(), descriptor); - + setGlobalAssetId(shell.getAssetInformation(), descriptor); - + return descriptor; } private void setDescription(List descriptions, AssetAdministrationShellDescriptor descriptor) { - + if (descriptions == null || descriptions.isEmpty()) return; - + descriptor.setDescription(new AttributeMapper().mapDescription(descriptions)); } - + private void setDisplayName(List displayNames, AssetAdministrationShellDescriptor descriptor) { - + if (displayNames == null || displayNames.isEmpty()) return; - + descriptor.setDisplayName(new AttributeMapper().mapDisplayName(displayNames)); } - + + private void setExtensions(List extensions, AssetAdministrationShellDescriptor descriptor) { + + if (extensions == null || extensions.isEmpty()) + return; + + descriptor.setExtensions(new AttributeMapper().mapExtensions(extensions)); + } + + private void setAdministration(AdministrativeInformation administration, AssetAdministrationShellDescriptor descriptor) { + + if (administration == null) + return; + + descriptor.setAdministration(new AttributeMapper().mapAdministration(administration)); + } + private void setAssetKind(AssetInformation assetInformation, AssetAdministrationShellDescriptor descriptor) { - + if (assetInformation == null || assetInformation.getAssetKind() == null) return; - + descriptor.setAssetKind(new AttributeMapper().mapAssetKind(assetInformation.getAssetKind())); } - + private void setAssetType(AssetInformation assetInformation, AssetAdministrationShellDescriptor descriptor) { - + if (assetInformation == null || assetInformation.getAssetType() == null) return; - + descriptor.setAssetType(assetInformation.getAssetType()); } - + private void setGlobalAssetId(AssetInformation assetInformation, AssetAdministrationShellDescriptor descriptor) { - + if (assetInformation == null || assetInformation.getGlobalAssetID() == null) return; - + descriptor.setGlobalAssetId(assetInformation.getGlobalAssetID()); } private void setEndpointItem(String shellId, AssetAdministrationShellDescriptor descriptor) { - + Endpoint endpoint = new Endpoint(); endpoint.setInterface(AAS_INTERFACE); ProtocolInformation protocolInformation = createProtocolInformation(shellId); endpoint.setProtocolInformation(protocolInformation); - + descriptor.addEndpointsItem(endpoint); } private ProtocolInformation createProtocolInformation(String shellId) { String href = String.format("%s/%s", aasRepositoryURL, Base64UrlEncodedIdentifier.encodeIdentifier(shellId)); - + ProtocolInformation protocolInformation = new ProtocolInformation(); protocolInformation.endpointProtocol(getProtocol(href)); protocolInformation.setHref(href); - + return protocolInformation; } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java index 4c05095d6..ad698f5ce 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java @@ -29,7 +29,9 @@ import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Extension; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; @@ -66,6 +68,18 @@ public List mapDisplayName(List mapExtensions(List langStringTextTypes) { + CloneFactory cloneFactory = new CloneFactory<>(Extension.class); + + return cloneFactory.create(langStringTextTypes); + } + + public AdministrativeInformation mapAdministration(org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation langStringTextTypes) { + CloneFactory cloneFactory = new CloneFactory<>(AdministrativeInformation.class); + + return cloneFactory.create(langStringTextTypes); + } + /** * Maps {@link AssetInformation#getAssetKind()} from AAS4J to AasRegistry client * diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java index 9b92650ea..e1aece4b3 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java @@ -28,16 +28,22 @@ import java.util.List; import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.Extension; import org.eclipse.digitaltwin.aas4j.v3.model.Reference; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.DataTypeDefXsd; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.deserializer.DataTypeDefXsdDeserializer; import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.deserializer.KeyTypeDeserializer; import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.deserializer.ReferenceTypeDeserializer; import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin.AdministrativeInformationMixin; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin.ExtensionMixin; import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin.ReferenceMixin; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.annotation.JsonInclude; /** * Factory for creating clones for the defined Input and Output type @@ -56,6 +62,8 @@ public class CloneFactory { public CloneFactory(Class outputElementType) { super(); this.elementType = outputElementType; + + configureMixins(); } /** @@ -73,6 +81,10 @@ private void configureMixins() { module2.setMixInAnnotation(Reference.class, ReferenceMixin.class); mapper.registerModule(module2); + SimpleModule module3 = new SimpleModule(); + module3.setMixInAnnotation(Extension.class, ExtensionMixin.class); + mapper.registerModule(module3); + SimpleModule moduleDeser = new SimpleModule(); moduleDeser.addDeserializer(KeyTypes.class, new KeyTypeDeserializer()); mapper.registerModule(moduleDeser); @@ -80,26 +92,13 @@ private void configureMixins() { SimpleModule moduleDeser2 = new SimpleModule(); moduleDeser2.addDeserializer(ReferenceTypes.class, new ReferenceTypeDeserializer()); mapper.registerModule(moduleDeser2); + + SimpleModule moduleDeser3 = new SimpleModule(); + moduleDeser3.addDeserializer(DataTypeDefXsd.class, new DataTypeDefXsdDeserializer()); + mapper.registerModule(moduleDeser3); + + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } - -// public O create() { -// String serializedLangString = ""; -// try { -// serializedLangString = mapper.writeValueAsString(input); -// } catch (JsonProcessingException e) { -// e.printStackTrace(); -// } -// -// O administrativeInformation = null; -// -// try { -// administrativeInformation = mapper.readValue(serializedLangString, new TypeReference() {}); -// } catch (JsonProcessingException e) { -// e.printStackTrace(); -// } -// -// return administrativeInformation; -// } public List create(List input) { String serializedLangString = ""; diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/DataTypeDefXsdDeserializer.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/DataTypeDefXsdDeserializer.java new file mode 100644 index 000000000..445672fdf --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/DataTypeDefXsdDeserializer.java @@ -0,0 +1,38 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.deserializer; + +import java.io.IOException; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.DataTypeDefXsd; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes; + +import com.fasterxml.jackson.core.JacksonException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; + +public class DataTypeDefXsdDeserializer extends JsonDeserializer { + + @Override + public DataTypeDefXsd deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { + try { + JsonNode node = p.getCodec().readTree(p); + + String value = node.asText(); + + String stringWithoutUnderscore = StringUtils.remove(value, '_'); + + return DataTypeDefXsd.valueOf(DataTypeDefXsd.class, stringWithoutUnderscore); + + // return ReferenceTypes.fromValue(value); + // return ReferenceTypes.EXTERNALREFERENCE; + + } catch (Exception e) { + throw new RuntimeException("Unable to deserialize the ReferenceTypes Enum"); + } + } + +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/ReferenceTypeDeserializer.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/ReferenceTypeDeserializer.java index de3a8748a..39802d391 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/ReferenceTypeDeserializer.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/ReferenceTypeDeserializer.java @@ -2,6 +2,7 @@ import java.io.IOException; +import org.apache.commons.lang3.StringUtils; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes; @@ -18,12 +19,16 @@ public class ReferenceTypeDeserializer extends JsonDeserializer public ReferenceTypes deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { try { JsonNode node = p.getCodec().readTree(p); - + String value = node.asText(); - -// return ReferenceTypes.valueOf(ReferenceTypes.class, value); - return ReferenceTypes.EXTERNALREFERENCE; - + + String stringWithoutUnderscore = StringUtils.remove(value, '_'); + + return ReferenceTypes.valueOf(ReferenceTypes.class, stringWithoutUnderscore); + + // return ReferenceTypes.fromValue(value); + // return ReferenceTypes.EXTERNALREFERENCE; + } catch (Exception e) { throw new RuntimeException("Unable to deserialize the ReferenceTypes Enum"); } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ExtensionMixin.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ExtensionMixin.java new file mode 100644 index 000000000..24083994c --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ExtensionMixin.java @@ -0,0 +1,14 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin; + +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public interface ExtensionMixin { + + @JsonProperty("semanticId") + public Reference getSemanticID(); + + +// public String getTemplateId(); +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java index 732564454..954873d3a 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java @@ -1,11 +1,14 @@ package org.eclipse.digitaltwin.basyx.aasrepository.feature.mqtt; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; +import org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXSD; import org.eclipse.digitaltwin.aas4j.v3.model.EmbeddedDataSpecification; +import org.eclipse.digitaltwin.aas4j.v3.model.Extension; import org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes; import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; @@ -13,10 +16,12 @@ import org.eclipse.digitaltwin.aas4j.v3.model.ReferenceTypes; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAdministrativeInformation; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultEmbeddedDataSpecification; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultExtension; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultKey; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringNameType; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringTextType; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultReference; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.DataTypeDefXsd; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Key; public class RegistryIntegrationTestHelper { @@ -52,7 +57,7 @@ public class RegistryIntegrationTestHelper { private static final String aas4jRevision = "3"; private static final String aas4jTemplateId = "ID2.0"; - // Administration AAS4J + // Administration AasRegistry private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.Reference aasRegDataSpecification = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.Reference() .keys(Arrays.asList(new Key().type(org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes.BLOB).value("BlobValue"))).type(org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes.EXTERNALREFERENCE); private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.EmbeddedDataSpecification AASREG_EMBEDDED_DATA_SPECIFICATION = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.EmbeddedDataSpecification() @@ -60,7 +65,13 @@ public class RegistryIntegrationTestHelper { private static final String aasRegVersion = "1.0.0"; private static final String aasRegRevision = "3"; private static final String aasRegTemplateId = "ID2.0"; + + // Extension AAS4J + private static final Extension AAS4J_EXTENSION = new DefaultExtension.Builder().semanticID(aas4jDataSpecification).name("extension").valueType(DataTypeDefXSD.STRING).value("extensionValue").build(); + // Administration AasRegistry + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.Extension AASREG_EXTENSION = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.Extension().semanticId(aasRegDataSpecification).name("extension").valueType(DataTypeDefXsd.STRING).value("extensionValue").supplementalSemanticIds(new ArrayList<>()).refersTo(new ArrayList<>()); + public static List getAas4jLangStringTextTypes() { return Arrays.asList(aas4jLangStringTextType_1, aas4jLangStringTextType_2); } @@ -85,5 +96,13 @@ public static List getAas4jLangStringNameTypes() { public static List getAasRegLangStringNameTypes() { return Arrays.asList(AASREG_LANG_STRING_NAME_TYPE_1, AASREG_LANG_STRING_NAME_TYPE_2); } + + public static List getAas4jExtensions() { + return Arrays.asList(AAS4J_EXTENSION); + } + + public static List getAasRegExtensions() { + return Arrays.asList(AASREG_EXTENSION); + } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java index 523614ce3..3c3fc587b 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java @@ -6,6 +6,7 @@ import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Extension; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.AttributeMapper; @@ -23,15 +24,6 @@ public void mapDescriptions() { assertEquals(expectedDescriptions, actualDescriptions); } -// @Test -// public void mapAdministration() { -// AdministrativeInformation expectedAdministrativeInformation = RegistryIntegrationTestHelper.getAasRegAdministration(); -// -// AdministrativeInformation actualAdministrativeInformation = new AttributeMapper().mapAdministration(RegistryIntegrationTestHelper.getAas4jAdministration()); -// -// assertEquals(expectedAdministrativeInformation, actualAdministrativeInformation); -// } - @Test public void mapDisplayNames() { List expectedDisplayNames = RegistryIntegrationTestHelper.getAasRegLangStringNameTypes(); @@ -42,6 +34,25 @@ public void mapDisplayNames() { assertEquals(expectedDisplayNames, actualDisplayNames); } + @Test + public void mapExtensions() { + List expectedDisplayNames = RegistryIntegrationTestHelper.getAasRegExtensions(); + + List actualDisplayNames = new AttributeMapper().mapExtensions(RegistryIntegrationTestHelper.getAas4jExtensions()); + + assertEquals(expectedDisplayNames.size(), actualDisplayNames.size()); + assertEquals(expectedDisplayNames, actualDisplayNames); + } + + @Test + public void mapAdministration() { + AdministrativeInformation expectedAdministrativeInformation = RegistryIntegrationTestHelper.getAasRegAdministration(); + + AdministrativeInformation actualAdministrativeInformation = new AttributeMapper().mapAdministration(RegistryIntegrationTestHelper.getAas4jAdministration()); + + assertEquals(expectedAdministrativeInformation, actualAdministrativeInformation); + } + @Test public void mapAssetKind() { AssetKind expectedAssetKind = RegistryIntegrationTestHelper.AASREG_ASSET_KIND; From 7f2a0ff5743c439d3c74d3a62cf508dbe6cbd570 Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Tue, 14 Nov 2023 17:52:05 +0100 Subject: [PATCH 11/21] Implements AAS and SM Repo integration with Registries feature Signed-off-by: Mohammad Ghazanfar Ali Danish --- .../http/AasDiscoveryServiceHTTPSuite.java | 6 +- .../integration/BaseIntegrationTest.java | 6 +- ...torAndWasPresent_thenElementIsRemoved.json | 42 +- ...dWasPresent_thenElementIsRemoved_repo.json | 56 +++ .../mongodb/MongoDbAasRegistryStorage.java | 4 +- .../docker-compose/build-images.sh | 4 +- .../docker-compose/docker-compose.yml | 10 +- .../open-api/patch-base-extensions.yaml | 4 +- .../pom.xml | 23 +- .../integration/AasDescriptorFactory.java | 30 +- .../AasRepositoryRegistryLink.java | 10 +- .../registry/integration/CloneFactory.java | 145 ------- .../RegistryIntegrationAasRepository.java | 13 +- ...IntegrationAasRepositoryConfiguration.java | 9 +- ...gistryIntegrationAasRepositoryFactory.java | 1 - ...gistryIntegrationAasRepositoryFeature.java | 5 +- .../DataTypeDefXsdDeserializer.java | 38 -- .../deserializer/KeyTypeDeserializer.java | 30 -- .../ReferenceTypeDeserializer.java | 37 -- .../{ => mapper}/AttributeMapper.java | 71 ++- .../mapper/DefaultAttributeMapperFactory.java | 94 ++++ .../DataTypeDefXsdDeserializer.java | 60 +++ .../deserializer/KeyTypeDeserializer.java | 62 +++ .../ReferenceTypeDeserializer.java | 62 +++ .../AdministrativeInformationMixin.java} | 28 +- .../mapper/mixin/ExtensionMixin.java | 28 +- .../mapper/mixin/ReferenceMixin.java | 28 +- .../mixin/AdministrativeInformationMixin.java | 12 - .../integration/mixin/ExtensionMixin.java | 14 - .../integration/mixin/ReferenceMixin.java | 14 - .../mqtt/RegistryIntegrationTestHelper.java | 108 ----- .../feature/mqtt/TestAttributeMapper.java | 65 --- .../feature/mqtt/TestCloneFactory.java | 37 -- .../AasRepositoryRegistryTestLink.java | 184 ++++++++ ...RepositoryRegistryTestLinkApplication.java | 72 ++++ .../RegistryIntegrationTestHelper.java | 85 +++- .../integration/TestAttributeMapper.java | 40 +- .../src/test/resources/AasSimple_1.json | 9 + .../src/test/resources/config/moquette.conf | 6 - .../http/AasRepositoryHTTPSuite.java | 12 +- .../test/resources/PaginatedAasSimple_1.json | 4 +- .../basyx.aasrepository.component/pom.xml | 39 +- .../application-integration.properties | 26 ++ .../src/main/resources/application.properties | 6 +- .../AASRepositoryRegistryLinkIT.java | 12 + .../RepositoryRegistryLinkException.java | 8 +- .../RepositoryRegistryUnlinkException.java | 47 ++ .../basyx/http/CustomTypeCloneFactory.java | 28 +- .../http/TestCustomTypeCloneFactory.java | 52 ++- .../serialization/BaSyxHttpTestUtils.java | 29 ++ .../CloneFactoryFirstTestModel.java | 83 ++++ .../CloneFactorySecondTestModel.java | 81 ++++ ...ConceptDescriptionRepositoryHTTPSuite.java | 14 +- ...DescriptionWithDataSpecWithPagination.json | 1 - .../open-api/patch-base-extensions.yaml | 6 +- .../Readme.md | 6 +- .../pom.xml | 25 +- .../integration/AasDescriptorFactory.java | 162 ------- .../registry/integration/AttributeMapper.java | 80 ---- .../RegistryIntegrationAasRepository.java | 148 ------- ...RegistryIntegrationSubmodelRepository.java | 192 +++++++++ ...ationSubmodelRepositoryConfiguration.java} | 18 +- ...yIntegrationSubmodelRepositoryFactory.java | 51 +++ ...IntegrationSubmodelRepositoryFeature.java} | 26 +- .../SubmodelDescriptorFactory.java | 190 ++++++++ .../SubmodelRepositoryRegistryLink.java} | 24 +- .../integration/mapper/AttributeMapper.java | 165 +++++++ .../mapper/DefaultAttributeMapperFactory.java | 94 ++++ .../DataTypeDefXsdDeserializer.java | 61 +++ .../deserializer/KeyTypeDeserializer.java | 62 +++ .../ReferenceTypeDeserializer.java | 62 +++ .../mixin/AdministrativeInformationMixin.java | 42 ++ .../mapper/mixin/ExtensionMixin.java | 44 ++ .../mapper/mixin/ReferenceMixin.java | 42 ++ .../RegistryIntegrationTestHelper.java | 84 ---- .../RegistryIntegrationTestHelper.java | 148 +++++++ .../SubmodelRepositoryRegistryTestLink.java | 192 +++++++++ ...RepositoryRegistryTestLinkApplication.java | 73 ++++ .../integration/TestAttributeMapper.java | 114 +++++ .../src/test/resources/SingleSubmodel.json | 404 ++++++++++++++++++ .../src/test/resources/config/moquette.conf | 6 - ...bmodelRepositorySubmodelHTTPTestSuite.java | 17 +- .../TestSubmodelRepositorySubmodelHTTP.java | 16 - .../test/resources/SubmodelsPaginated.json | 1 - .../pom.xml | 51 ++- .../application-integration.properties | 26 ++ .../src/main/resources/application.properties | 3 + .../SubmodelRepositoryRegistryLinkIT.java | 12 + .../src/test/resources/BaSyx-Logo.png | Bin 0 -> 11433 bytes basyx.submodelrepository/pom.xml | 1 + .../submodelservice/DummySubmodelFactory.java | 30 ++ ...lServiceSubmodelElementsTestSuiteHTTP.java | 8 +- .../resources/SubmodelElementsPaginated.json | 1 - docker-compose.yml | 14 + pom.xml | 22 + 95 files changed, 3429 insertions(+), 1288 deletions(-) create mode 100644 basyx.aasregistry/basyx.aasregistry-service-basetests/src/main/resources/org/eclipse/digitaltwin/basyx/aasregistry/service/tests/whenUnregisterSubmodelDescriptorAndWasPresent_thenElementIsRemoved_repo.json delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/DataTypeDefXsdDeserializer.java delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/KeyTypeDeserializer.java delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/ReferenceTypeDeserializer.java rename basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/{ => mapper}/AttributeMapper.java (54%) create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java rename basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/{test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestCloneFactory.java => main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/AdministrativeInformationMixin.java} (63%) rename basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java => basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/ExtensionMixin.java (64%) rename basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestCloneFactory.java => basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/ReferenceMixin.java (63%) delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/AdministrativeInformationMixin.java delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ExtensionMixin.java delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ReferenceMixin.java delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestCloneFactory.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLink.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLinkApplication.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/AasSimple_1.json delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/config/moquette.conf create mode 100644 basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application-integration.properties create mode 100644 basyx.aasrepository/basyx.aasrepository.component/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/component/AASRepositoryRegistryLinkIT.java create mode 100644 basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/RepositoryRegistryUnlinkException.java rename basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java => basyx.common/basyx.http/src/main/java/org/eclipse/digitaltwin/basyx/http/CustomTypeCloneFactory.java (79%) rename basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAttributeMapper.java => basyx.common/basyx.http/src/test/java/org/eclipse/digitaltwin/basyx/http/TestCustomTypeCloneFactory.java (52%) create mode 100644 basyx.common/basyx.http/src/test/java/org/eclipse/digitaltwin/basyx/http/testmodels/CloneFactoryFirstTestModel.java create mode 100644 basyx.common/basyx.http/src/test/java/org/eclipse/digitaltwin/basyx/http/testmodels/CloneFactorySecondTestModel.java delete mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java delete mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java delete mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java rename basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/{aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java => submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryConfiguration.java} (66%) create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFactory.java rename basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/{aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java => submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFeature.java} (61%) create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java rename basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/{aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java => submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLink.java} (66%) create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/AttributeMapper.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/AdministrativeInformationMixin.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/ExtensionMixin.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/ReferenceMixin.java delete mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationTestHelper.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLinkApplication.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/TestAttributeMapper.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/resources/SingleSubmodel.json delete mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/resources/config/moquette.conf create mode 100644 basyx.submodelrepository/basyx.submodelrepository.component/src/main/resources/application-integration.properties create mode 100644 basyx.submodelrepository/basyx.submodelrepository.component/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/component/SubmodelRepositoryRegistryLinkIT.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository.component/src/test/resources/BaSyx-Logo.png diff --git a/basyx.aasdiscoveryservice/basyx.aasdiscoveryservice-http/src/test/java/org/eclipse/digitaltwin/basyx/aasdiscoveryservice/http/AasDiscoveryServiceHTTPSuite.java b/basyx.aasdiscoveryservice/basyx.aasdiscoveryservice-http/src/test/java/org/eclipse/digitaltwin/basyx/aasdiscoveryservice/http/AasDiscoveryServiceHTTPSuite.java index f97298c99..e52e7c048 100644 --- a/basyx.aasdiscoveryservice/basyx.aasdiscoveryservice-http/src/test/java/org/eclipse/digitaltwin/basyx/aasdiscoveryservice/http/AasDiscoveryServiceHTTPSuite.java +++ b/basyx.aasdiscoveryservice/basyx.aasdiscoveryservice-http/src/test/java/org/eclipse/digitaltwin/basyx/aasdiscoveryservice/http/AasDiscoveryServiceHTTPSuite.java @@ -62,7 +62,7 @@ public void getAllAssetAdministrationShellIdsByAssetLink() throws ParseException String actualShellIds = requestAllShellIds(); - BaSyxHttpTestUtils.assertSameJSONContent(expectedShellIds, actualShellIds); + BaSyxHttpTestUtils.assertSameJSONContent(expectedShellIds, getJSONWithoutCursorInfo(actualShellIds)); } @Test @@ -142,6 +142,10 @@ protected String requestAllShellIds() throws IOException, ParseException { protected CloseableHttpResponse requestAllAssetLinks(String shellIdentifier) throws IOException, ParseException { return BaSyxHttpTestUtils.executeGetOnURL(getURL() + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(shellIdentifier)); } + + private String getJSONWithoutCursorInfo(String response) throws JsonMappingException, JsonProcessingException { + return BaSyxHttpTestUtils.removeCursorFromJSON(response); + } private String getNewAssetLinksJSON() throws IOException { return BaSyxHttpTestUtils.readJSONStringFromClasspath("NewAssetLinks.json"); diff --git a/basyx.aasregistry/basyx.aasregistry-service-basetests/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/service/tests/integration/BaseIntegrationTest.java b/basyx.aasregistry/basyx.aasregistry-service-basetests/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/service/tests/integration/BaseIntegrationTest.java index 78601e474..a5c758469 100644 --- a/basyx.aasregistry/basyx.aasregistry-service-basetests/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/service/tests/integration/BaseIntegrationTest.java +++ b/basyx.aasregistry/basyx.aasregistry-service-basetests/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/service/tests/integration/BaseIntegrationTest.java @@ -236,14 +236,14 @@ public void whenDeleteAll_thenAllDescriptorsAreRemoved() throws ApiException { @Test public void whenCreateAndDeleteDescriptors_thenAllDescriptorsAreRemoved() throws IOException, InterruptedException, TimeoutException, ApiException { List deployed = initialize(); - List all = api.getAllAssetAdministrationShellDescriptors(port, null, null, null).getResult(); + List all = api.getAllAssetAdministrationShellDescriptors(null, null, null, null).getResult(); assertThat(all).containsExactlyInAnyOrderElementsOf(deployed); for (AssetAdministrationShellDescriptor eachDescriptor : all) { deleteAdminAssetShellDescriptor(eachDescriptor.getId()); } - all = api.getAllAssetAdministrationShellDescriptors(port, null, null, null).getResult(); + all = api.getAllAssetAdministrationShellDescriptors(null, null, null, null).getResult(); assertThat(all).isEmpty(); queue().assertNoAdditionalMessage(); @@ -252,7 +252,7 @@ public void whenCreateAndDeleteDescriptors_thenAllDescriptorsAreRemoved() throws @Test public void whenRegisterAndUnregisterSubmodel_thenSubmodelIsCreatedAndDeleted() throws IOException, InterruptedException, TimeoutException, ApiException { List deployed = initialize(); - List all = api.getAllAssetAdministrationShellDescriptors(port, null, null, null).getResult(); + List all = api.getAllAssetAdministrationShellDescriptors(null, null, null, null).getResult(); assertThat(all).asList().containsExactlyInAnyOrderElementsOf(deployed); SubmodelDescriptor toRegister = resourceLoader.load(SubmodelDescriptor.class, "toregister"); diff --git a/basyx.aasregistry/basyx.aasregistry-service-basetests/src/main/resources/org/eclipse/digitaltwin/basyx/aasregistry/service/tests/whenUnregisterSubmodelDescriptorAndWasPresent_thenElementIsRemoved.json b/basyx.aasregistry/basyx.aasregistry-service-basetests/src/main/resources/org/eclipse/digitaltwin/basyx/aasregistry/service/tests/whenUnregisterSubmodelDescriptorAndWasPresent_thenElementIsRemoved.json index 856fb06d6..b949df23a 100644 --- a/basyx.aasregistry/basyx.aasregistry-service-basetests/src/main/resources/org/eclipse/digitaltwin/basyx/aasregistry/service/tests/whenUnregisterSubmodelDescriptorAndWasPresent_thenElementIsRemoved.json +++ b/basyx.aasregistry/basyx.aasregistry-service-basetests/src/main/resources/org/eclipse/digitaltwin/basyx/aasregistry/service/tests/whenUnregisterSubmodelDescriptorAndWasPresent_thenElementIsRemoved.json @@ -1,13 +1,49 @@ [ { - "id": "identification_1" + "id": "identification_1", + "endpoints": [ + { + "protocolInformation": { + "endpointProtocolVersion": [ + "1" + ] + } + } + ], + "extensions": [ + { + "name": "COLOR", + "value": "BLUE" + } + ] }, { "id": "identification_2", + "endpoints": [ + { + "protocolInformation": { + "endpointProtocolVersion": [ + "2" + ] + } + } + ], + "extensions": [ + { + "name": "COLOR", + "value": "RED" + } + ], "submodelDescriptors": [ { - "id": "identification_2.1" + "id": "identification_2.1", + "extensions": [ + { + "name": "COLOR", + "value": "RED" + } + ] } ] - } + } ] \ No newline at end of file diff --git a/basyx.aasregistry/basyx.aasregistry-service-basetests/src/main/resources/org/eclipse/digitaltwin/basyx/aasregistry/service/tests/whenUnregisterSubmodelDescriptorAndWasPresent_thenElementIsRemoved_repo.json b/basyx.aasregistry/basyx.aasregistry-service-basetests/src/main/resources/org/eclipse/digitaltwin/basyx/aasregistry/service/tests/whenUnregisterSubmodelDescriptorAndWasPresent_thenElementIsRemoved_repo.json new file mode 100644 index 000000000..e83ab82aa --- /dev/null +++ b/basyx.aasregistry/basyx.aasregistry-service-basetests/src/main/resources/org/eclipse/digitaltwin/basyx/aasregistry/service/tests/whenUnregisterSubmodelDescriptorAndWasPresent_thenElementIsRemoved_repo.json @@ -0,0 +1,56 @@ +[ + { + "id": "identification_1", + "endpoints": [ + { + "protocolInformation": { + "endpointProtocolVersion": [ + "1" + ] + } + } + ], + "extensions": [ + { + "name": "COLOR", + "value": "BLUE" + } + ] + }, + { + "id": "identification_2", + "endpoints": [ + { + "protocolInformation": { + "endpointProtocolVersion": [ + "2" + ] + } + } + ], + "extensions": [ + { + "name": "COLOR", + "value": "RED" + } + ], + "submodelDescriptors": [ + { + "id": "identification_2.1", + "extensions": [ + { + "name": "COLOR", + "value": "RED" + }] + }, + { + "id": "identification_2.2", + "extensions": [ + { + "name": "COLOR", + "value": "RED" + }] + } + ] + } +] \ No newline at end of file diff --git a/basyx.aasregistry/basyx.aasregistry-service-mongodb-storage/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/service/storage/mongodb/MongoDbAasRegistryStorage.java b/basyx.aasregistry/basyx.aasregistry-service-mongodb-storage/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/service/storage/mongodb/MongoDbAasRegistryStorage.java index ee7e30253..df50917e2 100644 --- a/basyx.aasregistry/basyx.aasregistry-service-mongodb-storage/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/service/storage/mongodb/MongoDbAasRegistryStorage.java +++ b/basyx.aasregistry/basyx.aasregistry-service-mongodb-storage/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/service/storage/mongodb/MongoDbAasRegistryStorage.java @@ -62,6 +62,7 @@ import org.springframework.data.mongodb.core.aggregation.ArrayOperators; import org.springframework.data.mongodb.core.aggregation.ComparisonOperators; import org.springframework.data.mongodb.core.aggregation.MatchOperation; +import org.springframework.data.mongodb.core.aggregation.SetOperation; import org.springframework.data.mongodb.core.aggregation.SortOperation; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; @@ -69,6 +70,7 @@ import org.springframework.data.mongodb.core.query.UpdateDefinition; import com.mongodb.ClientSessionOptions; +import com.mongodb.internal.operation.UpdateOperation; import lombok.NonNull; import lombok.RequiredArgsConstructor; @@ -274,7 +276,7 @@ private void assertReplacePerformed(AssetAdministrationShellDescriptor descr, St public void removeSubmodel(@NonNull String aasDescriptorId, @NonNull String submodelId) throws AasDescriptorNotFoundException, SubmodelNotFoundException { AggregationExpression notEquals = ComparisonOperators.valueOf(SUBMODEL_DESCRIPTORS_ID).notEqualToValue(submodelId); AggregationExpression filterArray = ArrayOperators.arrayOf(SUBMODEL_DESCRIPTORS).filter().as(SUBMODEL_DESCRIPTORS).by(notEquals); - AggregationUpdate update = Aggregation.newUpdate(Aggregation.project(SUBMODEL_DESCRIPTORS).and(filterArray).as(SUBMODEL_DESCRIPTORS)); + AggregationUpdate update = AggregationUpdate.update().set(SUBMODEL_DESCRIPTORS).toValue(filterArray); AssetAdministrationShellDescriptor old = template.findAndModify(Query.query(Criteria.where(ID).is(aasDescriptorId)), update, AssetAdministrationShellDescriptor.class); if (old == null) { throw new AasDescriptorNotFoundException(submodelId); diff --git a/basyx.aasregistry/docker-compose/build-images.sh b/basyx.aasregistry/docker-compose/build-images.sh index b5104f815..ddfa72baf 100644 --- a/basyx.aasregistry/docker-compose/build-images.sh +++ b/basyx.aasregistry/docker-compose/build-images.sh @@ -4,9 +4,7 @@ trap 'cd $OLD_WORK_DIR' EXIT cd $(dirname "${BASH_SOURCE[0]}")/.. -MAVEN_OPS='-Xmx2048 -Xms1024' mvn clean install -e -DskipTests -Ddocker.username=mdanish98 -Ddocker.password="@@Danishali1" - -read -p "Press any key to continue... " -n1 -s +MAVEN_OPS='-Xmx2048 -Xms1024' mvn clean install -DskipTests -Ddocker.username=aas-registry-test -Ddocker.password="" cd $OLD_WORK_DIR diff --git a/basyx.aasregistry/docker-compose/docker-compose.yml b/basyx.aasregistry/docker-compose/docker-compose.yml index 906711c86..e1e694042 100644 --- a/basyx.aasregistry/docker-compose/docker-compose.yml +++ b/basyx.aasregistry/docker-compose/docker-compose.yml @@ -108,7 +108,7 @@ services: - mongodb aas-registry-kafka-mongodb: - image: mdanish98/aas-registry-kafka-mongodb:latest + image: aas-registry-test/aas-registry-kafka-mongodb:latest container_name: aas-registry-kafka-mongodb pull_policy: never ports: @@ -124,7 +124,7 @@ services: - basyx aas-registry-kafka-mongodb-external-conf: - image: mdanish98/aas-registry-kafka-mongodb:latest + image: aas-registry-test/aas-registry-kafka-mongodb:latest container_name: aas-registry-kafka-mongodb-external-conf pull_policy: never ports: @@ -143,7 +143,7 @@ services: - basyx aas-registry-kafka-mem: - image: mdanish98/aas-registry-kafka-mem:latest + image: aas-registry-test/aas-registry-kafka-mem:latest container_name: aas-registry-kafka-mem pull_policy: never ports: @@ -157,7 +157,7 @@ services: - basyx aas-registry-log-mem: - image: mdanish98/aas-registry-log-mem:latest + image: aas-registry-test/aas-registry-log-mem:latest container_name: aas-registry-log-mem pull_policy: never ports: @@ -167,7 +167,7 @@ services: - basyx aas-registry-log-mongodb: - image: mdanish98/aas-registry-log-mongodb:latest + image: aas-registry-test/aas-registry-log-mongodb:latest container_name: aas-registry-log-mongodb pull_policy: never ports: diff --git a/basyx.aasregistry/open-api/patch-base-extensions.yaml b/basyx.aasregistry/open-api/patch-base-extensions.yaml index 7a2b96580..37082ee38 100644 --- a/basyx.aasregistry/open-api/patch-base-extensions.yaml +++ b/basyx.aasregistry/open-api/patch-base-extensions.yaml @@ -84,12 +84,12 @@ path: /components/schemas/AdministrativeInformation/allOf/1/properties/version/allOf - op: add path: /components/schemas/AdministrativeInformation/allOf/1/properties/version/pattern - value: "^(0|[1-9][0-9]{1,3})$" + value: "^(0|[1-9][0-9]{0,3})$" - op: remove path: /components/schemas/AdministrativeInformation/allOf/1/properties/revision/allOf - op: add path: /components/schemas/AdministrativeInformation/allOf/1/properties/revision/pattern - value: "^(0|[1-9][0-9]{1,3})$" + value: "^(0|[1-9][0-9]{0,3})$" - op: replace path: /components/schemas/AdministrativeInformation/allOf/1/properties/templateId/pattern value: "^([\\t\\n\\r \\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/pom.xml b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/pom.xml index bf5e93ca5..43dd44f93 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/pom.xml +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/pom.xml @@ -22,7 +22,9 @@ org.eclipse.digitaltwin.basyx - basyx.mqttcore + basyx.http + test + tests org.eclipse.digitaltwin.basyx @@ -30,27 +32,14 @@ org.eclipse.digitaltwin.basyx - basyx.aasrepository-core + basyx.aasrepository-http tests test - org.eclipse.digitaltwin.basyx - basyx.aasrepository-backend-inmemory + org.apache.httpcomponents.client5 + httpclient5 test - - org.eclipse.digitaltwin.basyx - basyx.aasservice-backend-inmemory - test - - - org.eclipse.digitaltwin.aas4j - dataformat-json - - - org.springframework.boot - spring-boot-starter - \ No newline at end of file diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java index 9db1f7873..2a61936af 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java @@ -38,6 +38,8 @@ import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Endpoint; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ProtocolInformation; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.AttributeMapper; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.DefaultAttributeMapperFactory; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; /** @@ -48,13 +50,18 @@ public class AasDescriptorFactory { private static final String AAS_INTERFACE = "AAS-3.0"; + private static final String AAS_REPOSITORY_PATH = "/shells"; + private AssetAdministrationShell shell; private String aasRepositoryURL; - public AasDescriptorFactory(AssetAdministrationShell shell, String aasRepositoryURL) { + private AttributeMapper attributeMapper; + + public AasDescriptorFactory(AssetAdministrationShell shell, String aasRepositoryBaseURL) { super(); this.shell = shell; - this.aasRepositoryURL = aasRepositoryURL; + this.aasRepositoryURL = createAasRepositoryUrl(aasRepositoryBaseURL); + this.attributeMapper = new DefaultAttributeMapperFactory().create(); } /** @@ -94,7 +101,7 @@ private void setDescription(List descriptions, AssetAdminist if (descriptions == null || descriptions.isEmpty()) return; - descriptor.setDescription(new AttributeMapper().mapDescription(descriptions)); + descriptor.setDescription(attributeMapper.mapDescription(descriptions)); } private void setDisplayName(List displayNames, AssetAdministrationShellDescriptor descriptor) { @@ -102,7 +109,7 @@ private void setDisplayName(List displayNames, AssetAdminist if (displayNames == null || displayNames.isEmpty()) return; - descriptor.setDisplayName(new AttributeMapper().mapDisplayName(displayNames)); + descriptor.setDisplayName(attributeMapper.mapDisplayName(displayNames)); } private void setExtensions(List extensions, AssetAdministrationShellDescriptor descriptor) { @@ -110,7 +117,7 @@ private void setExtensions(List extensions, AssetAdministrationShellD if (extensions == null || extensions.isEmpty()) return; - descriptor.setExtensions(new AttributeMapper().mapExtensions(extensions)); + descriptor.setExtensions(attributeMapper.mapExtensions(extensions)); } private void setAdministration(AdministrativeInformation administration, AssetAdministrationShellDescriptor descriptor) { @@ -118,7 +125,7 @@ private void setAdministration(AdministrativeInformation administration, AssetAd if (administration == null) return; - descriptor.setAdministration(new AttributeMapper().mapAdministration(administration)); + descriptor.setAdministration(attributeMapper.mapAdministration(administration)); } private void setAssetKind(AssetInformation assetInformation, AssetAdministrationShellDescriptor descriptor) { @@ -126,7 +133,7 @@ private void setAssetKind(AssetInformation assetInformation, AssetAdministration if (assetInformation == null || assetInformation.getAssetKind() == null) return; - descriptor.setAssetKind(new AttributeMapper().mapAssetKind(assetInformation.getAssetKind())); + descriptor.setAssetKind(attributeMapper.mapAssetKind(assetInformation.getAssetKind())); } private void setAssetType(AssetInformation assetInformation, AssetAdministrationShellDescriptor descriptor) { @@ -181,4 +188,13 @@ private String getProtocol(String endpoint) { } } + private String createAasRepositoryUrl(String aasRepositoryBaseURL) { + + try { + return new URL(new URL(aasRepositoryBaseURL), AAS_REPOSITORY_PATH).toString(); + } catch (MalformedURLException e) { + throw new RuntimeException("The AAS Repository Base url is malformed " + e.getMessage()); + } + } + } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java index d13b3e8a3..9210e24cd 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java @@ -36,20 +36,20 @@ public class AasRepositoryRegistryLink { private RegistryAndDiscoveryInterfaceApi registryApi; - private String aasRepositoryURL; + private String aasRepositoryBaseURL; - public AasRepositoryRegistryLink(RegistryAndDiscoveryInterfaceApi registryApi, String aasRepositoryURL) { + public AasRepositoryRegistryLink(RegistryAndDiscoveryInterfaceApi registryApi, String aasRepositoryBaseURL) { super(); this.registryApi = registryApi; - this.aasRepositoryURL = aasRepositoryURL; + this.aasRepositoryBaseURL = aasRepositoryBaseURL; } public RegistryAndDiscoveryInterfaceApi getRegistryApi() { return registryApi; } - public String getAasRepositoryURL() { - return aasRepositoryURL; + public String getAasRepositoryBaseURL() { + return aasRepositoryBaseURL; } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java deleted file mode 100644 index e1aece4b3..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; - -import java.util.List; - -import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; -import org.eclipse.digitaltwin.aas4j.v3.model.Extension; -import org.eclipse.digitaltwin.aas4j.v3.model.Reference; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.DataTypeDefXsd; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.deserializer.DataTypeDefXsdDeserializer; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.deserializer.KeyTypeDeserializer; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.deserializer.ReferenceTypeDeserializer; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin.AdministrativeInformationMixin; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin.ExtensionMixin; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin.ReferenceMixin; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.annotation.JsonInclude; - -/** - * Factory for creating clones for the defined Input and Output type - * - * @param the Input type - * @param the Output type - * - * @author danish - */ -public class CloneFactory { - - private ObjectMapper mapper = new ObjectMapper(); - - private Class elementType; - - public CloneFactory(Class outputElementType) { - super(); - this.elementType = outputElementType; - - configureMixins(); - } - - /** - * Creates clone for the provided input of {@link List} type - * - * @param input - * @return the cloned result - */ - private void configureMixins() { - SimpleModule module = new SimpleModule(); - module.setMixInAnnotation(AdministrativeInformation.class, AdministrativeInformationMixin.class); - mapper.registerModule(module); - - SimpleModule module2 = new SimpleModule(); - module2.setMixInAnnotation(Reference.class, ReferenceMixin.class); - mapper.registerModule(module2); - - SimpleModule module3 = new SimpleModule(); - module3.setMixInAnnotation(Extension.class, ExtensionMixin.class); - mapper.registerModule(module3); - - SimpleModule moduleDeser = new SimpleModule(); - moduleDeser.addDeserializer(KeyTypes.class, new KeyTypeDeserializer()); - mapper.registerModule(moduleDeser); - - SimpleModule moduleDeser2 = new SimpleModule(); - moduleDeser2.addDeserializer(ReferenceTypes.class, new ReferenceTypeDeserializer()); - mapper.registerModule(moduleDeser2); - - SimpleModule moduleDeser3 = new SimpleModule(); - moduleDeser3.addDeserializer(DataTypeDefXsd.class, new DataTypeDefXsdDeserializer()); - mapper.registerModule(moduleDeser3); - - mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - } - - public List create(List input) { - String serializedLangString = ""; - - try { - serializedLangString = mapper.writeValueAsString(input); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - - List resultList = null; - - try { - resultList = mapper.readValue(serializedLangString, mapper.getTypeFactory().constructCollectionType(List.class, elementType)); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - - return resultList; - } - - /** - * Creates clone for the provided input - * - * @param input - * @return the cloned result - */ - public O create(I input) { - String serializedLangString = ""; - try { - serializedLangString = mapper.writeValueAsString(input); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - - try { - return mapper.readValue(serializedLangString, elementType); - } catch (JsonProcessingException e) { - e.printStackTrace(); - throw new RuntimeException(); - } - } - -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java index e4445e5d8..af7ff4e5c 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java @@ -36,6 +36,7 @@ import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException; import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; import org.eclipse.digitaltwin.basyx.core.exceptions.RepositoryRegistryLinkException; +import org.eclipse.digitaltwin.basyx.core.exceptions.RepositoryRegistryUnlinkException; import org.eclipse.digitaltwin.basyx.core.pagination.CursorResult; import org.eclipse.digitaltwin.basyx.core.pagination.PaginationInfo; import org.slf4j.Logger; @@ -73,7 +74,7 @@ public AssetAdministrationShell getAas(String aasId) throws ElementDoesNotExistE public void createAas(AssetAdministrationShell aas) throws CollidingIdentifierException { decorated.createAas(aas); - integrateAasWithRegistry(aas, aasRepositoryRegistryLink.getAasRepositoryURL()); + integrateAasWithRegistry(aas, aasRepositoryRegistryLink.getAasRepositoryBaseURL()); } @Override @@ -127,8 +128,10 @@ private void integrateAasWithRegistry(AssetAdministrationShell shell, String aas try { registryApi.postAssetAdministrationShellDescriptor(descriptor); - logger.info("Shell {} is automatically linked with the Registry", shell.getId()); + logger.info("Shell {} has been automatically linked with the Registry", shell.getId()); } catch (ApiException e) { + e.printStackTrace(); + throw new RepositoryRegistryLinkException(shell.getId()); } } @@ -139,9 +142,11 @@ private void deleteFromRegistry(String shellId) { try { registryApi.deleteAssetAdministrationShellDescriptorById(shellId); - logger.info("Shell {} is automatically de-registered with the Registry", shellId); + logger.info("Shell {} has been automatically de-registered from the Registry", shellId); } catch (ApiException e) { - throw new RuntimeException("Automatic deletion of the shell with shellId " + shellId + " from the Registry fails"); + e.printStackTrace(); + + throw new RepositoryRegistryUnlinkException(shellId); } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java index 6bae6f63a..706819133 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java @@ -28,7 +28,6 @@ import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; -import org.eclipse.paho.client.mqttv3.MqttException; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -36,19 +35,19 @@ import org.springframework.context.annotation.Configuration; /** - * Configuration for {@link AasRepository} with AasRegistry + * Configuration for integrating {@link AasRepository} with AasRegistry * * @author danish */ @Configuration -@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.feature.registryintegration:}') && !T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.externalurl:}')") +@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.feature.registryintegration:}') && !T(org.springframework.util.StringUtils).isEmpty('${basyx.externalurl:}')") public class RegistryIntegrationAasRepositoryConfiguration { @Bean @ConditionalOnMissingBean - public AasRepositoryRegistryLink getAasRepositoryRegistryLink(@Value("${basyx.aasrepository.feature.registryintegration}") String registryBasePath, @Value("${basyx.aasrepository.externalurl}") String aasRepositoryURL) throws MqttException { + public AasRepositoryRegistryLink getAasRepositoryRegistryLink(@Value("${basyx.aasrepository.feature.registryintegration}") String registryBasePath, @Value("${basyx.externalurl}") String aasRepositoryBaseURL) { - return new AasRepositoryRegistryLink(new RegistryAndDiscoveryInterfaceApi(registryBasePath), aasRepositoryURL); + return new AasRepositoryRegistryLink(new RegistryAndDiscoveryInterfaceApi(registryBasePath), aasRepositoryBaseURL); } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java index d73c65037..fa8681bce 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java @@ -23,7 +23,6 @@ * SPDX-License-Identifier: MIT ******************************************************************************/ - package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java index 0fa430c1f..cee76b9d9 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java @@ -26,6 +26,7 @@ package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; +import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; import org.eclipse.digitaltwin.basyx.aasrepository.AasRepositoryFactory; import org.eclipse.digitaltwin.basyx.aasrepository.feature.AasRepositoryFeature; import org.springframework.beans.factory.annotation.Autowired; @@ -33,12 +34,12 @@ import org.springframework.stereotype.Component; /** - * Feature for integrating Registry with Aas Repository + * Feature for integrating Registry with {@link AasRepository} * * @author danish */ @Component -@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.feature.registryintegration:}') && !T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.externalurl:}')") +@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.feature.registryintegration:}') && !T(org.springframework.util.StringUtils).isEmpty('${basyx.externalurl:}')") public class RegistryIntegrationAasRepositoryFeature implements AasRepositoryFeature { public final static String FEATURENAME = "basyx.aasrepository.feature.registryintegration"; diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/DataTypeDefXsdDeserializer.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/DataTypeDefXsdDeserializer.java deleted file mode 100644 index 445672fdf..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/DataTypeDefXsdDeserializer.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.deserializer; - -import java.io.IOException; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.DataTypeDefXsd; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes; - -import com.fasterxml.jackson.core.JacksonException; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; - -public class DataTypeDefXsdDeserializer extends JsonDeserializer { - - @Override - public DataTypeDefXsd deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { - try { - JsonNode node = p.getCodec().readTree(p); - - String value = node.asText(); - - String stringWithoutUnderscore = StringUtils.remove(value, '_'); - - return DataTypeDefXsd.valueOf(DataTypeDefXsd.class, stringWithoutUnderscore); - - // return ReferenceTypes.fromValue(value); - // return ReferenceTypes.EXTERNALREFERENCE; - - } catch (Exception e) { - throw new RuntimeException("Unable to deserialize the ReferenceTypes Enum"); - } - } - -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/KeyTypeDeserializer.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/KeyTypeDeserializer.java deleted file mode 100644 index aa751b51c..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/KeyTypeDeserializer.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.deserializer; - -import java.io.IOException; - -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes; - -import com.fasterxml.jackson.core.JacksonException; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; - -public class KeyTypeDeserializer extends JsonDeserializer { - - @Override - public KeyTypes deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { - try { - JsonNode node = p.getCodec().readTree(p); - - String value = node.asText(); - - return KeyTypes.valueOf(KeyTypes.class, value); - - } catch (Exception e) { - throw new RuntimeException("Unable to deserialize the KeyTypes Enum"); - } - } - -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/ReferenceTypeDeserializer.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/ReferenceTypeDeserializer.java deleted file mode 100644 index 39802d391..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/deserializer/ReferenceTypeDeserializer.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.deserializer; - -import java.io.IOException; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes; - -import com.fasterxml.jackson.core.JacksonException; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; - -public class ReferenceTypeDeserializer extends JsonDeserializer { - - @Override - public ReferenceTypes deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { - try { - JsonNode node = p.getCodec().readTree(p); - - String value = node.asText(); - - String stringWithoutUnderscore = StringUtils.remove(value, '_'); - - return ReferenceTypes.valueOf(ReferenceTypes.class, stringWithoutUnderscore); - - // return ReferenceTypes.fromValue(value); - // return ReferenceTypes.EXTERNALREFERENCE; - - } catch (Exception e) { - throw new RuntimeException("Unable to deserialize the ReferenceTypes Enum"); - } - } - -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/AttributeMapper.java similarity index 54% rename from basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java rename to basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/AttributeMapper.java index ad698f5ce..89737e6f5 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/AttributeMapper.java @@ -23,7 +23,7 @@ * SPDX-License-Identifier: MIT ******************************************************************************/ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper; import java.util.List; @@ -34,13 +34,26 @@ import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Extension; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; +import org.eclipse.digitaltwin.basyx.http.CustomTypeCloneFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.databind.ObjectMapper; /** - * Maps the models defined in AasRegistry client to the AAS4J models + * Maps the models defined in AAS4J to the AasRegistry client models * * @author danish */ public class AttributeMapper { + + private Logger logger = LoggerFactory.getLogger(AttributeMapper.class); + + private ObjectMapper mapper; + + public AttributeMapper(ObjectMapper mapper) { + this.mapper = mapper; + } /** * Maps {@link AssetAdministrationShell#getDescription()} from AAS4J to @@ -50,9 +63,14 @@ public class AttributeMapper { * @return the mapped descriptions */ public List mapDescription(List descriptions) { - CloneFactory cloneFactory = new CloneFactory<>(LangStringTextType.class); + CustomTypeCloneFactory cloneFactory = new CustomTypeCloneFactory<>(LangStringTextType.class, mapper); + + List mappedDescriptions = cloneFactory.create(descriptions); + + if (mappedDescriptions == null) + logger.error("Descriptions could not be mapped due to a failure"); - return cloneFactory.create(descriptions); + return mappedDescriptions; } /** @@ -63,21 +81,50 @@ public List mapDescription(List mapDisplayName(List displayNames) { - CloneFactory cloneFactory = new CloneFactory<>(LangStringNameType.class); + CustomTypeCloneFactory cloneFactory = new CustomTypeCloneFactory<>(LangStringNameType.class, mapper); + + List mappedDisplayNames = cloneFactory.create(displayNames); + + if (mappedDisplayNames == null) + logger.error("DisplayNames could not be mapped due to a failure"); - return cloneFactory.create(displayNames); + return mappedDisplayNames; } - public List mapExtensions(List langStringTextTypes) { - CloneFactory cloneFactory = new CloneFactory<>(Extension.class); + /** + * Maps {@link AssetAdministrationShell#getExtensions()} from AAS4J to + * AasRegistry client + * + * @param extensions + * @return the mapped extensions + */ + public List mapExtensions(List extensions) { + CustomTypeCloneFactory cloneFactory = new CustomTypeCloneFactory<>(Extension.class, mapper); + + List mappedExtensions = cloneFactory.create(extensions); + + if (mappedExtensions == null) + logger.error("Extensions could not be mapped due to a failure"); - return cloneFactory.create(langStringTextTypes); + return cloneFactory.create(extensions); } - public AdministrativeInformation mapAdministration(org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation langStringTextTypes) { - CloneFactory cloneFactory = new CloneFactory<>(AdministrativeInformation.class); + /** + * Maps {@link AssetAdministrationShell#getAdministration()} from AAS4J to + * AasRegistry client + * + * @param administrativeInformation + * @return the mapped administrativeInformation + */ + public AdministrativeInformation mapAdministration(org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation administrativeInformation) { + CustomTypeCloneFactory cloneFactory = new CustomTypeCloneFactory<>(AdministrativeInformation.class, mapper); + + AdministrativeInformation mappedAdministrativeInformation = cloneFactory.create(administrativeInformation); + + if (mappedAdministrativeInformation == null) + logger.error("AdministrativeInformation could not be mapped due to a failure"); - return cloneFactory.create(langStringTextTypes); + return mappedAdministrativeInformation; } /** diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java new file mode 100644 index 000000000..7488a2605 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper; + +import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.Extension; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.DataTypeDefXsd; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.deserializer.DataTypeDefXsdDeserializer; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.deserializer.KeyTypeDeserializer; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.deserializer.ReferenceTypeDeserializer; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.mixin.AdministrativeInformationMixin; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.mixin.ExtensionMixin; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.mixin.ReferenceMixin; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; + +/** + * Factory for creating {@link AttributeMapper} with default {@link ObjectMapper} configurations + * + * @author danish + */ +public class DefaultAttributeMapperFactory { + + /** + * Creates the {@link AttributeMapper} with default configurations of the {@link ObjectMapper} + * + * @return default attribute mapper + */ + public AttributeMapper create() { + ObjectMapper mapper = new ObjectMapper(); + + SimpleModule adminInfoMixInModule = createMixInModule(AdministrativeInformation.class, AdministrativeInformationMixin.class); + + SimpleModule referenceMixInModule = createMixInModule(Reference.class, ReferenceMixin.class); + + SimpleModule extensionMixInModule = createMixInModule(Extension.class, ExtensionMixin.class); + + SimpleModule keyTypesDeserModule = createDeserializerModule(KeyTypes.class, new KeyTypeDeserializer()); + + SimpleModule refTypesDeserModule = createDeserializerModule(ReferenceTypes.class, new ReferenceTypeDeserializer()); + + SimpleModule dataTypeDeserModule = createDeserializerModule(DataTypeDefXsd.class, new DataTypeDefXsdDeserializer()); + + mapper.registerModules(adminInfoMixInModule, referenceMixInModule, extensionMixInModule, keyTypesDeserModule, refTypesDeserModule, dataTypeDeserModule); + + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + + return new AttributeMapper(mapper); + } + + private SimpleModule createDeserializerModule(Class type, JsonDeserializer deser) { + SimpleModule moduleDeser = new SimpleModule(); + moduleDeser.addDeserializer(type, deser); + + return moduleDeser; + } + + private SimpleModule createMixInModule(Class targetType, Class mixInClass) { + SimpleModule module = new SimpleModule(); + module.setMixInAnnotation(targetType, mixInClass); + + return module; + } + +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java new file mode 100644 index 000000000..f2d4292e8 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.deserializer; + +import java.io.IOException; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.DataTypeDefXsd; +import com.fasterxml.jackson.core.JacksonException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; + +/** + * Custom deserializer for {@link DataTypeDefXsd} + * + * @author danish + */ +public class DataTypeDefXsdDeserializer extends JsonDeserializer { + + @Override + public DataTypeDefXsd deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { + try { + JsonNode node = p.getCodec().readTree(p); + + String value = node.asText(); + + String compatibleEnumValue = StringUtils.remove(value, '_'); + + return DataTypeDefXsd.valueOf(DataTypeDefXsd.class, compatibleEnumValue); + } catch (Exception e) { + throw new RuntimeException("Unable to deserialize the DataTypeDefXsd Enum"); + } + } + +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java new file mode 100644 index 000000000..68b6139ca --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.deserializer; + +import java.io.IOException; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes; + +import com.fasterxml.jackson.core.JacksonException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; + +/** + * Custom deserializer for {@link KeyTypes} + * + * @author danish + */ +public class KeyTypeDeserializer extends JsonDeserializer { + + @Override + public KeyTypes deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { + try { + JsonNode node = p.getCodec().readTree(p); + + String value = node.asText(); + + String compatibleEnumValue = StringUtils.remove(value, '_'); + + return KeyTypes.valueOf(KeyTypes.class, compatibleEnumValue); + + } catch (Exception e) { + throw new RuntimeException("Unable to deserialize the KeyTypes Enum"); + } + } + +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java new file mode 100644 index 000000000..8db4d6387 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.deserializer; + +import java.io.IOException; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes; + +import com.fasterxml.jackson.core.JacksonException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; + +/** + * Custom deserializer for {@link ReferenceTypes} + * + * @author danish + */ +public class ReferenceTypeDeserializer extends JsonDeserializer { + + @Override + public ReferenceTypes deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { + try { + JsonNode node = p.getCodec().readTree(p); + + String value = node.asText(); + + String compatibleEnumValue = StringUtils.remove(value, '_'); + + return ReferenceTypes.valueOf(ReferenceTypes.class, compatibleEnumValue); + + } catch (Exception e) { + throw new RuntimeException("Unable to deserialize the ReferenceTypes Enum"); + } + } + +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestCloneFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/AdministrativeInformationMixin.java similarity index 63% rename from basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestCloneFactory.java rename to basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/AdministrativeInformationMixin.java index d931721ba..c8bd5cf1f 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestCloneFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/AdministrativeInformationMixin.java @@ -23,32 +23,20 @@ * SPDX-License-Identifier: MIT ******************************************************************************/ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.mixin; -import static org.junit.Assert.assertEquals; +import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; -import java.util.List; - -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; -import org.junit.Test; +import com.fasterxml.jackson.annotation.JsonProperty; /** - * Test class for {@link CloneFactory} + * Mixin for {@link AdministrativeInformation} * * @author danish */ -public class TestCloneFactory { +public interface AdministrativeInformationMixin { + + @JsonProperty("templateId") + public String getTemplateID(); - @Test - public void createClone() { - List expectedDescriptions = RegistryIntegrationTestHelper.getAasRegLangStringTextTypes(); - - CloneFactory cloneFactory = new CloneFactory<>(LangStringTextType.class); - - List actualDescriptions = cloneFactory.create(RegistryIntegrationTestHelper.getAas4jLangStringTextTypes()); - - assertEquals(expectedDescriptions.size(), actualDescriptions.size()); - assertEquals(expectedDescriptions, actualDescriptions); - } - } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/ExtensionMixin.java similarity index 64% rename from basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java rename to basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/ExtensionMixin.java index d73c65037..104e1b53f 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/ExtensionMixin.java @@ -23,30 +23,22 @@ * SPDX-License-Identifier: MIT ******************************************************************************/ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.mixin; -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; -import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; -import org.eclipse.digitaltwin.basyx.aasrepository.AasRepositoryFactory; +import org.eclipse.digitaltwin.aas4j.v3.model.Extension; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; + +import com.fasterxml.jackson.annotation.JsonProperty; /** - * Factory for creating {@link RegistryIntegrationAasRepository} + * Mixin for {@link Extension} * * @author danish */ -public class RegistryIntegrationAasRepositoryFactory implements AasRepositoryFactory { - - private AasRepositoryFactory decorated; - private AasRepositoryRegistryLink aasRepositoryRegistryLink; - - public RegistryIntegrationAasRepositoryFactory(AasRepositoryFactory decorated, AasRepositoryRegistryLink aasRepositoryRegistryLink) { - this.decorated = decorated; - this.aasRepositoryRegistryLink = aasRepositoryRegistryLink; - } - - @Override - public AasRepository create() { - return new RegistryIntegrationAasRepository(decorated.create(), aasRepositoryRegistryLink); - } +public interface ExtensionMixin { + + @JsonProperty("semanticId") + public Reference getSemanticID(); } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestCloneFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/ReferenceMixin.java similarity index 63% rename from basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestCloneFactory.java rename to basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/ReferenceMixin.java index d931721ba..94768ab4b 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestCloneFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/ReferenceMixin.java @@ -23,32 +23,20 @@ * SPDX-License-Identifier: MIT ******************************************************************************/ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.mixin; -import static org.junit.Assert.assertEquals; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; -import java.util.List; - -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; -import org.junit.Test; +import com.fasterxml.jackson.annotation.JsonProperty; /** - * Test class for {@link CloneFactory} + * Mixin for {@link Reference} * * @author danish */ -public class TestCloneFactory { +public interface ReferenceMixin { + + @JsonProperty("referredSemanticId") + public Reference getReferredSemanticID(); - @Test - public void createClone() { - List expectedDescriptions = RegistryIntegrationTestHelper.getAasRegLangStringTextTypes(); - - CloneFactory cloneFactory = new CloneFactory<>(LangStringTextType.class); - - List actualDescriptions = cloneFactory.create(RegistryIntegrationTestHelper.getAas4jLangStringTextTypes()); - - assertEquals(expectedDescriptions.size(), actualDescriptions.size()); - assertEquals(expectedDescriptions, actualDescriptions); - } - } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/AdministrativeInformationMixin.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/AdministrativeInformationMixin.java deleted file mode 100644 index c6aeae391..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/AdministrativeInformationMixin.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public interface AdministrativeInformationMixin { - - @JsonProperty("templateId") - public String getTemplateID(); - - -// public String getTemplateId(); -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ExtensionMixin.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ExtensionMixin.java deleted file mode 100644 index 24083994c..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ExtensionMixin.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin; - -import org.eclipse.digitaltwin.aas4j.v3.model.Reference; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public interface ExtensionMixin { - - @JsonProperty("semanticId") - public Reference getSemanticID(); - - -// public String getTemplateId(); -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ReferenceMixin.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ReferenceMixin.java deleted file mode 100644 index 0f933482a..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mixin/ReferenceMixin.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mixin; - -import org.eclipse.digitaltwin.aas4j.v3.model.Reference; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public interface ReferenceMixin { - - @JsonProperty("referredSemanticId") - public Reference getReferredSemanticID(); - - -// public String getTemplateId(); -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java deleted file mode 100644 index 954873d3a..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/RegistryIntegrationTestHelper.java +++ /dev/null @@ -1,108 +0,0 @@ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.mqtt; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; -import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; -import org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXSD; -import org.eclipse.digitaltwin.aas4j.v3.model.EmbeddedDataSpecification; -import org.eclipse.digitaltwin.aas4j.v3.model.Extension; -import org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes; -import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; -import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; -import org.eclipse.digitaltwin.aas4j.v3.model.Reference; -import org.eclipse.digitaltwin.aas4j.v3.model.ReferenceTypes; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAdministrativeInformation; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultEmbeddedDataSpecification; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultExtension; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultKey; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringNameType; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringTextType; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultReference; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.DataTypeDefXsd; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Key; - -public class RegistryIntegrationTestHelper { - - // LangStringTextType AAS4J - private static final LangStringTextType aas4jLangStringTextType_1 = new DefaultLangStringTextType.Builder().language("de").text("Ein Beispiel").build(); - private static final LangStringTextType aas4jLangStringTextType_2 = new DefaultLangStringTextType.Builder().language("en").text("An Example").build(); - - // LangStringTextType AasRegistry - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType aasRegLangStringTextType_1 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("de") - .text("Ein Beispiel"); - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType aasRegLangStringTextType_2 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("en") - .text("An Example"); - - // LangStringNameType AAS4J - private static final LangStringNameType AAS4J_LANG_STRING_NAME_TYPE_1 = new DefaultLangStringNameType.Builder().language("en").text("Name type string").build(); - private static final LangStringNameType AAS4J_LANG_STRING_NAME_TYPE_2 = new DefaultLangStringNameType.Builder().language("de").text("Namenstypzeichenfolge").build(); - - // LangStringTextType AasRegistry - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType AASREG_LANG_STRING_NAME_TYPE_1 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType().language("en").text("Name type string"); - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType AASREG_LANG_STRING_NAME_TYPE_2 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType().language("de").text("Namenstypzeichenfolge"); - - // AssetKind AAS4J - public static final AssetKind AAS4J_ASSET_KIND = AssetKind.INSTANCE; - - // AssetKind AasRegistry - public static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind AASREG_ASSET_KIND = org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind.INSTANCE; - - // Administration AAS4J - private static final Reference aas4jDataSpecification = new DefaultReference.Builder().keys(new DefaultKey.Builder().type(KeyTypes.BLOB).value("BlobValue").build()).type(ReferenceTypes.EXTERNAL_REFERENCE).build(); - private static final EmbeddedDataSpecification AAS4JEMB_EMBEDDED_DATA_SPECIFICATION = new DefaultEmbeddedDataSpecification.Builder().dataSpecification(aas4jDataSpecification).build(); - private static final String aas4jVersion = "1.0.0"; - private static final String aas4jRevision = "3"; - private static final String aas4jTemplateId = "ID2.0"; - - // Administration AasRegistry - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.Reference aasRegDataSpecification = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.Reference() - .keys(Arrays.asList(new Key().type(org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes.BLOB).value("BlobValue"))).type(org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes.EXTERNALREFERENCE); - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.EmbeddedDataSpecification AASREG_EMBEDDED_DATA_SPECIFICATION = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.EmbeddedDataSpecification() - .dataSpecification(aasRegDataSpecification); - private static final String aasRegVersion = "1.0.0"; - private static final String aasRegRevision = "3"; - private static final String aasRegTemplateId = "ID2.0"; - - // Extension AAS4J - private static final Extension AAS4J_EXTENSION = new DefaultExtension.Builder().semanticID(aas4jDataSpecification).name("extension").valueType(DataTypeDefXSD.STRING).value("extensionValue").build(); - - // Administration AasRegistry - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.Extension AASREG_EXTENSION = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.Extension().semanticId(aasRegDataSpecification).name("extension").valueType(DataTypeDefXsd.STRING).value("extensionValue").supplementalSemanticIds(new ArrayList<>()).refersTo(new ArrayList<>()); - - public static List getAas4jLangStringTextTypes() { - return Arrays.asList(aas4jLangStringTextType_1, aas4jLangStringTextType_2); - } - - public static List getAasRegLangStringTextTypes() { - return Arrays.asList(aasRegLangStringTextType_1, aasRegLangStringTextType_2); - } - - public static AdministrativeInformation getAas4jAdministration() { - return new DefaultAdministrativeInformation.Builder().embeddedDataSpecifications(AAS4JEMB_EMBEDDED_DATA_SPECIFICATION).version(aas4jVersion).revision(aas4jRevision).templateID(aas4jTemplateId).build(); - } - - public static org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation getAasRegAdministration() { - return new org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation().embeddedDataSpecifications(Arrays.asList(AASREG_EMBEDDED_DATA_SPECIFICATION)).version(aasRegVersion).revision(aasRegRevision) - .templateId(aasRegTemplateId); - } - - public static List getAas4jLangStringNameTypes() { - return Arrays.asList(AAS4J_LANG_STRING_NAME_TYPE_1, AAS4J_LANG_STRING_NAME_TYPE_2); - } - - public static List getAasRegLangStringNameTypes() { - return Arrays.asList(AASREG_LANG_STRING_NAME_TYPE_1, AASREG_LANG_STRING_NAME_TYPE_2); - } - - public static List getAas4jExtensions() { - return Arrays.asList(AAS4J_EXTENSION); - } - - public static List getAasRegExtensions() { - return Arrays.asList(AASREG_EXTENSION); - } - -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java deleted file mode 100644 index 3c3fc587b..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestAttributeMapper.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.mqtt; - -import static org.junit.Assert.assertEquals; - -import java.util.List; - -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Extension; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.AttributeMapper; -import org.junit.Test; - -public class TestAttributeMapper { - - @Test - public void mapDescriptions() { - List expectedDescriptions = RegistryIntegrationTestHelper.getAasRegLangStringTextTypes(); - - List actualDescriptions = new AttributeMapper().mapDescription(RegistryIntegrationTestHelper.getAas4jLangStringTextTypes()); - - assertEquals(expectedDescriptions.size(), actualDescriptions.size()); - assertEquals(expectedDescriptions, actualDescriptions); - } - - @Test - public void mapDisplayNames() { - List expectedDisplayNames = RegistryIntegrationTestHelper.getAasRegLangStringNameTypes(); - - List actualDisplayNames = new AttributeMapper().mapDisplayName(RegistryIntegrationTestHelper.getAas4jLangStringNameTypes()); - - assertEquals(expectedDisplayNames.size(), actualDisplayNames.size()); - assertEquals(expectedDisplayNames, actualDisplayNames); - } - - @Test - public void mapExtensions() { - List expectedDisplayNames = RegistryIntegrationTestHelper.getAasRegExtensions(); - - List actualDisplayNames = new AttributeMapper().mapExtensions(RegistryIntegrationTestHelper.getAas4jExtensions()); - - assertEquals(expectedDisplayNames.size(), actualDisplayNames.size()); - assertEquals(expectedDisplayNames, actualDisplayNames); - } - - @Test - public void mapAdministration() { - AdministrativeInformation expectedAdministrativeInformation = RegistryIntegrationTestHelper.getAasRegAdministration(); - - AdministrativeInformation actualAdministrativeInformation = new AttributeMapper().mapAdministration(RegistryIntegrationTestHelper.getAas4jAdministration()); - - assertEquals(expectedAdministrativeInformation, actualAdministrativeInformation); - } - - @Test - public void mapAssetKind() { - AssetKind expectedAssetKind = RegistryIntegrationTestHelper.AASREG_ASSET_KIND; - - AssetKind actualAssetKind = new AttributeMapper().mapAssetKind(RegistryIntegrationTestHelper.AAS4J_ASSET_KIND); - - assertEquals(expectedAssetKind, actualAssetKind); - } - -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestCloneFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestCloneFactory.java deleted file mode 100644 index 06bf43a2c..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/mqtt/TestCloneFactory.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.mqtt; - -import static org.junit.Assert.assertEquals; - -import java.util.List; - -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.AttributeMapper; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.CloneFactory; -import org.junit.Test; - -public class TestCloneFactory { - - @Test - public void createCloneOfListType() { - List expectedDescriptions = RegistryIntegrationTestHelper.getAasRegLangStringTextTypes(); - - CloneFactory cloneFactory = new CloneFactory<>(LangStringTextType.class); - - List actualDescriptions = cloneFactory.create(RegistryIntegrationTestHelper.getAas4jLangStringTextTypes()); - - assertEquals(expectedDescriptions.size(), actualDescriptions.size()); - assertEquals(expectedDescriptions, actualDescriptions); - } - -// @Test -// public void createCloneOfNonListType() { -// AssetKind expectedAssetKind = RegistryIntegrationTestHelper.AASREG_ASSET_KIND; -// -// AssetKind actualAssetKind = new AttributeMapper().mapAssetKind(RegistryIntegrationTestHelper.AAS4J_ASSET_KIND); -// -// assertEquals(expectedAssetKind, actualAssetKind); -// } - -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLink.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLink.java new file mode 100644 index 000000000..da06207df --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLink.java @@ -0,0 +1,184 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; + +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.eclipse.digitaltwin.basyx.aasregistry.client.ApiException; +import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Endpoint; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.GetAssetAdministrationShellDescriptorsResult; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ProtocolInformation; +import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; +import org.eclipse.digitaltwin.basyx.http.serialization.BaSyxHttpTestUtils; +import org.junit.Test; +import org.springframework.http.HttpStatus; + +/** + * Integration test for {@link RegistryIntegrationAasRepository} feature + * + * @author danish + */ +public class AasRepositoryRegistryTestLink { + + private static final String AAS_REPOSITORY_PATH = "/shells"; + private static final String DUMMY_GLOBAL_ASSETID = "globalAssetId"; + private static final String DUMMY_IDSHORT = "ExampleMotor"; + private static final String DUMMY_AAS_ID = "customIdentifier"; + + public static String aasRepoBaseUrl = "http://localhost:8081"; + public static String aasRegistryUrl = "http://localhost:8050/api/v3.0"; + + private static final AssetAdministrationShellDescriptor DUMMY_DESCRIPTOR = createExpectedDescriptor(); + + @Test + public void createAas() throws FileNotFoundException, IOException, ApiException { + String aasJsonContent = getAas1JSONString(); + + CloseableHttpResponse creationResponse = createAasOnRepo(aasJsonContent); + assertEquals(HttpStatus.CREATED.value(), creationResponse.getCode()); + + AssetAdministrationShellDescriptor actualDescriptor = retrieveDescriptorFromRegistry(); + + assertEquals(DUMMY_DESCRIPTOR, actualDescriptor); + + resetRepository(); + } + + @Test + public void deleteAas() throws FileNotFoundException, IOException, ApiException { + String aasJsonContent = getAas1JSONString(); + + CloseableHttpResponse creationResponse = createAasOnRepo(aasJsonContent); + assertEquals(HttpStatus.CREATED.value(), creationResponse.getCode()); + + CloseableHttpResponse deleteResponse = deleteAasFromRepo(DUMMY_AAS_ID); + assertEquals(HttpStatus.NO_CONTENT.value(), deleteResponse.getCode()); + + assertDescriptionDeletionAtRegistry(); + } + + private AssetAdministrationShellDescriptor retrieveDescriptorFromRegistry() throws ApiException { + RegistryAndDiscoveryInterfaceApi api = new RegistryAndDiscoveryInterfaceApi(aasRegistryUrl); + + return api.getAssetAdministrationShellDescriptorById(DUMMY_AAS_ID); + } + + private void resetRepository() throws IOException { + CloseableHttpResponse deleteResponse = deleteAasFromRepo(DUMMY_AAS_ID); + + assertEquals(HttpStatus.NO_CONTENT.value(), deleteResponse.getCode()); + } + + private CloseableHttpResponse deleteAasFromRepo(String shellId) throws IOException { + return BaSyxHttpTestUtils.executeDeleteOnURL(getSpecificAasAccessURL(shellId)); + } + + private void assertDescriptionDeletionAtRegistry() throws ApiException { + RegistryAndDiscoveryInterfaceApi api = new RegistryAndDiscoveryInterfaceApi(aasRegistryUrl); + + GetAssetAdministrationShellDescriptorsResult result = api.getAllAssetAdministrationShellDescriptors(null, null, null, null); + + List actualDescriptors = result.getResult(); + + assertTrue(actualDescriptors.isEmpty()); + } + + private String getAas1JSONString() throws FileNotFoundException, IOException { + return BaSyxHttpTestUtils.readJSONStringFromClasspath("AasSimple_1.json"); + } + + private CloseableHttpResponse createAasOnRepo(String aasJsonContent) throws IOException { + return BaSyxHttpTestUtils.executePostOnURL(createAasRepositoryUrl(aasRepoBaseUrl), aasJsonContent); + } + + private String getSpecificAasAccessURL(String aasId) { + return createAasRepositoryUrl(aasRepoBaseUrl) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(aasId); + } + + private static AssetAdministrationShellDescriptor createExpectedDescriptor() { + + AssetAdministrationShellDescriptor descriptor = new AssetAdministrationShellDescriptor(); + + descriptor.setId(DUMMY_AAS_ID); + descriptor.setIdShort(DUMMY_IDSHORT); + descriptor.setAssetKind(AssetKind.INSTANCE); + descriptor.setGlobalAssetId(DUMMY_GLOBAL_ASSETID); + descriptor.addEndpointsItem(createEndpointItem()); + + return descriptor; + } + + private static Endpoint createEndpointItem() { + Endpoint endpoint = new Endpoint(); + endpoint.setInterface("AAS-3.0"); + endpoint.setProtocolInformation(createProtocolInformation()); + + return endpoint; + } + + private static ProtocolInformation createProtocolInformation() { + String href = createHref(); + + ProtocolInformation protocolInformation = new ProtocolInformation(); + protocolInformation.setHref(href); + protocolInformation.endpointProtocol(getProtocol(href)); + + return protocolInformation; + } + + private static String createHref() { + return String.format("%s/%s", createAasRepositoryUrl(aasRepoBaseUrl), Base64UrlEncodedIdentifier.encodeIdentifier(DUMMY_AAS_ID)); + } + + private static String getProtocol(String endpoint) { + try { + return new URL(endpoint).getProtocol(); + } catch (MalformedURLException e) { + throw new RuntimeException(); + } + } + + private static String createAasRepositoryUrl(String aasRepositoryBaseURL) { + + try { + return new URL(new URL(aasRepositoryBaseURL), AAS_REPOSITORY_PATH).toString(); + } catch (MalformedURLException e) { + throw new RuntimeException("The AAS Repository Base url is malformed " + e.getMessage()); + } + } + +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLinkApplication.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLinkApplication.java new file mode 100644 index 000000000..7dbd91dec --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLinkApplication.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import org.junit.internal.TextListener; +import org.junit.runner.JUnitCore; +import org.junit.runner.Result; + +/** + * Application for testing the {@link RegistryIntegrationAasRepository} feature. + * The first argument is the AAS Repository Base URL, the second argument is the AAS + * Registry URL. + * + * @author schnicke, danish + * + */ +public class AasRepositoryRegistryTestLinkApplication { + + public static void main(String[] args) throws Exception { + String aasRepoBaseUrl = getAasRepositoryBaseUrl(args); + String aasRegUrl = getAasRegistryUrl(args); + + Result result = runTests(aasRepoBaseUrl, aasRegUrl); + + printResults(result); + } + + private static void printResults(Result result) { + System.out.println("Finished. Result: Failures: " + result.getFailureCount() + ". Ignored: " + result.getIgnoreCount() + ". Tests run: " + result.getRunCount() + ". Time: " + result.getRunTime() + "ms."); + } + + private static Result runTests(String aasRepoBaseUrl, String aasRegUrl) { + AasRepositoryRegistryTestLink.aasRepoBaseUrl = aasRepoBaseUrl; + AasRepositoryRegistryTestLink.aasRegistryUrl = aasRegUrl; + + JUnitCore junit = new JUnitCore(); + junit.addListener(new TextListener(System.out)); + + return junit.run(AasRepositoryRegistryTestLink.class); + } + + private static String getAasRepositoryBaseUrl(String[] args) { + return args[0]; + } + + private static String getAasRegistryUrl(String[] args) { + return args[1]; + } + +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java index cdb213063..8a5b5d606 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java @@ -25,54 +25,101 @@ package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; +import org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXSD; +import org.eclipse.digitaltwin.aas4j.v3.model.EmbeddedDataSpecification; +import org.eclipse.digitaltwin.aas4j.v3.model.Extension; +import org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes; import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; +import org.eclipse.digitaltwin.aas4j.v3.model.ReferenceTypes; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultEmbeddedDataSpecification; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultExtension; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultKey; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringNameType; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringTextType; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultReference; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.DataTypeDefXsd; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Key; /** - * Test helper class for Registry integration + * A helper class for testing RegistryIntegration feature * * @author danish */ public class RegistryIntegrationTestHelper { // LangStringTextType AAS4J - private static final LangStringTextType aas4jLangStringTextType_1 = new DefaultLangStringTextType.Builder().language("de").text("Ein Beispiel").build(); - private static final LangStringTextType aas4jLangStringTextType_2 = new DefaultLangStringTextType.Builder().language("en").text("An Example").build(); + private static final LangStringTextType AAS4J_LANG_STRING_TEXT_TYPE_1 = new DefaultLangStringTextType.Builder().language("de").text("Ein Beispiel").build(); + private static final LangStringTextType AAS_LANG_STRING_TEXT_TYPE_2 = new DefaultLangStringTextType.Builder().language("en").text("An Example").build(); // LangStringTextType AasRegistry - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType aasRegLangStringTextType_1 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("de") + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType AASREG_LANG_STRING_TEXT_TYPE_1 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("de") .text("Ein Beispiel"); - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType aasRegLangStringTextType_2 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("en") + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType AASREG_LANG_STRING_TEXT_TYPE_2 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("en") .text("An Example"); - + // LangStringNameType AAS4J private static final LangStringNameType AAS4J_LANG_STRING_NAME_TYPE_1 = new DefaultLangStringNameType.Builder().language("en").text("Name type string").build(); private static final LangStringNameType AAS4J_LANG_STRING_NAME_TYPE_2 = new DefaultLangStringNameType.Builder().language("de").text("Namenstypzeichenfolge").build(); - - // LangStringTextType AasRegistry - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType AASREG_LANG_STRING_NAME_TYPE_1 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType().language("en").text("Name type string"); - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType AASREG_LANG_STRING_NAME_TYPE_2 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType().language("de").text("Namenstypzeichenfolge"); - + + // LangStringNameType AasRegistry + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType AASREG_LANG_STRING_NAME_TYPE_1 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType().language("en") + .text("Name type string"); + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType AASREG_LANG_STRING_NAME_TYPE_2 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType().language("de") + .text("Namenstypzeichenfolge"); + // AssetKind AAS4J public static final AssetKind AAS4J_ASSET_KIND = AssetKind.INSTANCE; - + // AssetKind AasRegistry public static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind AASREG_ASSET_KIND = org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind.INSTANCE; + // Administration AAS4J + private static final Reference AAS4J_DATASPECIFICATION = new DefaultReference.Builder().keys(new DefaultKey.Builder().type(KeyTypes.BLOB).value("BlobValue").build()).type(ReferenceTypes.EXTERNAL_REFERENCE).build(); + private static final EmbeddedDataSpecification AAS4JEMB_EMBEDDED_DATA_SPECIFICATION = new DefaultEmbeddedDataSpecification.Builder().dataSpecification(AAS4J_DATASPECIFICATION).build(); + + // Administration AasRegistry + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.Reference AASREG_DATASPECIFICATION = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.Reference() + .keys(Arrays.asList(new Key().type(org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes.BLOB).value("BlobValue"))).type(org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes.EXTERNALREFERENCE); + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.EmbeddedDataSpecification AASREG_EMBEDDED_DATA_SPECIFICATION = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.EmbeddedDataSpecification() + .dataSpecification(AASREG_DATASPECIFICATION); + + private static final String VERSION = "1.0.0"; + private static final String REVISION = "3"; + private static final String TEMPLATE_ID = "ID2.0"; + + // Extension AAS4J + private static final Extension AAS4J_EXTENSION = new DefaultExtension.Builder().semanticID(AAS4J_DATASPECIFICATION).name("extension").valueType(DataTypeDefXSD.STRING).value("extensionValue").build(); + + // Extension AasRegistry + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.Extension AASREG_EXTENSION = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.Extension().semanticId(AASREG_DATASPECIFICATION).name("extension") + .valueType(DataTypeDefXsd.STRING).value("extensionValue").supplementalSemanticIds(new ArrayList<>()).refersTo(new ArrayList<>()); + public static List getAas4jLangStringTextTypes() { - return Arrays.asList(aas4jLangStringTextType_1, aas4jLangStringTextType_2); + return Arrays.asList(AAS4J_LANG_STRING_TEXT_TYPE_1, AAS_LANG_STRING_TEXT_TYPE_2); } public static List getAasRegLangStringTextTypes() { - return Arrays.asList(aasRegLangStringTextType_1, aasRegLangStringTextType_2); + return Arrays.asList(AASREG_LANG_STRING_TEXT_TYPE_1, AASREG_LANG_STRING_TEXT_TYPE_2); } - + + public static AdministrativeInformation getAas4jAdministration() { + return new DefaultAdministrativeInformation.Builder().embeddedDataSpecifications(AAS4JEMB_EMBEDDED_DATA_SPECIFICATION).version(VERSION).revision(REVISION).templateID(TEMPLATE_ID).build(); + } + + public static org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation getAasRegAdministration() { + return new org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation().embeddedDataSpecifications(Arrays.asList(AASREG_EMBEDDED_DATA_SPECIFICATION)).version(VERSION).revision(REVISION) + .templateId(TEMPLATE_ID); + } + public static List getAas4jLangStringNameTypes() { return Arrays.asList(AAS4J_LANG_STRING_NAME_TYPE_1, AAS4J_LANG_STRING_NAME_TYPE_2); } @@ -81,4 +128,12 @@ public static List getAas4jExtensions() { + return Arrays.asList(AAS4J_EXTENSION); + } + + public static List getAasRegExtensions() { + return Arrays.asList(AASREG_EXTENSION); + } + } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAttributeMapper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAttributeMapper.java index 8865ee275..2a6da9a29 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAttributeMapper.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAttributeMapper.java @@ -29,24 +29,35 @@ import java.util.List; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Extension; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.AttributeMapper; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.AttributeMapper; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.DefaultAttributeMapperFactory; +import org.junit.BeforeClass; import org.junit.Test; /** - * Test class for {@link AttributeMapper} + * Unit tests for {@link AttributeMapper} * * @author danish */ public class TestAttributeMapper { + private static AttributeMapper attributeMapper; + + @BeforeClass + public static void setUp() { + attributeMapper = new DefaultAttributeMapperFactory().create(); + } + @Test public void mapDescriptions() { List expectedDescriptions = RegistryIntegrationTestHelper.getAasRegLangStringTextTypes(); - List actualDescriptions = new AttributeMapper().mapDescription(RegistryIntegrationTestHelper.getAas4jLangStringTextTypes()); + List actualDescriptions = attributeMapper.mapDescription(RegistryIntegrationTestHelper.getAas4jLangStringTextTypes()); assertEquals(expectedDescriptions.size(), actualDescriptions.size()); assertEquals(expectedDescriptions, actualDescriptions); @@ -56,17 +67,36 @@ public void mapDescriptions() { public void mapDisplayNames() { List expectedDisplayNames = RegistryIntegrationTestHelper.getAasRegLangStringNameTypes(); - List actualDisplayNames = new AttributeMapper().mapDisplayName(RegistryIntegrationTestHelper.getAas4jLangStringNameTypes()); + List actualDisplayNames = attributeMapper.mapDisplayName(RegistryIntegrationTestHelper.getAas4jLangStringNameTypes()); assertEquals(expectedDisplayNames.size(), actualDisplayNames.size()); assertEquals(expectedDisplayNames, actualDisplayNames); } + @Test + public void mapExtensions() { + List expectedExtensions = RegistryIntegrationTestHelper.getAasRegExtensions(); + + List actualExtensions = attributeMapper.mapExtensions(RegistryIntegrationTestHelper.getAas4jExtensions()); + + assertEquals(expectedExtensions.size(), actualExtensions.size()); + assertEquals(expectedExtensions, actualExtensions); + } + + @Test + public void mapAdministration() { + AdministrativeInformation expectedAdministrativeInformation = RegistryIntegrationTestHelper.getAasRegAdministration(); + + AdministrativeInformation actualAdministrativeInformation = attributeMapper.mapAdministration(RegistryIntegrationTestHelper.getAas4jAdministration()); + + assertEquals(expectedAdministrativeInformation, actualAdministrativeInformation); + } + @Test public void mapAssetKind() { AssetKind expectedAssetKind = RegistryIntegrationTestHelper.AASREG_ASSET_KIND; - AssetKind actualAssetKind = new AttributeMapper().mapAssetKind(RegistryIntegrationTestHelper.AAS4J_ASSET_KIND); + AssetKind actualAssetKind = attributeMapper.mapAssetKind(RegistryIntegrationTestHelper.AAS4J_ASSET_KIND); assertEquals(expectedAssetKind, actualAssetKind); } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/AasSimple_1.json b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/AasSimple_1.json new file mode 100644 index 000000000..16e79e653 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/AasSimple_1.json @@ -0,0 +1,9 @@ +{ + "modelType": "AssetAdministrationShell", + "idShort": "ExampleMotor", + "id": "customIdentifier", + "assetInformation": { + "assetKind": "Instance", + "globalAssetId": "globalAssetId" + } +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/config/moquette.conf b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/config/moquette.conf deleted file mode 100644 index 8511afcd1..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/config/moquette.conf +++ /dev/null @@ -1,6 +0,0 @@ -# Moquette Java Broker configuration file for testing - -# Do not use the default 1883 port -port 1884 -host 0.0.0.0 -allow_anonymous true \ No newline at end of file diff --git a/basyx.aasrepository/basyx.aasrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/http/AasRepositoryHTTPSuite.java b/basyx.aasrepository/basyx.aasrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/http/AasRepositoryHTTPSuite.java index cdab824fe..23e5ce995 100644 --- a/basyx.aasrepository/basyx.aasrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/http/AasRepositoryHTTPSuite.java +++ b/basyx.aasrepository/basyx.aasrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/http/AasRepositoryHTTPSuite.java @@ -121,7 +121,7 @@ public void getAllPaginatedAas() throws IOException, ParseException { String actualJsonFromServer = BaSyxHttpTestUtils.getResponseAsString(retrievalResponse); - BaSyxHttpTestUtils.assertSameJSONContent(getPaginatedAasJSONString(), actualJsonFromServer); + BaSyxHttpTestUtils.assertSameJSONContent(getPaginatedAasJSONString(), getJSONWithoutCursorInfo(actualJsonFromServer)); } @Test @@ -183,7 +183,9 @@ public void removeSubmodelReference() throws FileNotFoundException, IOException, CloseableHttpResponse getResponse = BaSyxHttpTestUtils.executeGetOnURL(getSpecificAasSubmodelRefAccessURL(dummyAasId)); assertEquals(200, deleteResponse.getCode()); - BaSyxHttpTestUtils.assertSameJSONContent(getSMReferenceRemovalJson(), BaSyxHttpTestUtils.getResponseAsString(getResponse)); + + String response = BaSyxHttpTestUtils.getResponseAsString(getResponse); + BaSyxHttpTestUtils.assertSameJSONContent(getSMReferenceRemovalJson(), getJSONWithoutCursorInfo(response)); } @@ -278,12 +280,16 @@ public void paginationResult() throws FileNotFoundException, IOException, ParseE CloseableHttpResponse httpResponse = BaSyxHttpTestUtils.executeGetOnURL(getURL() + "?limit=1&cursor=" + ENCODED_CURSOR); String response = BaSyxHttpTestUtils.getResponseAsString(httpResponse); - BaSyxHttpTestUtils.assertSameJSONContent(getPaginatedAas1JSONString(), response); + BaSyxHttpTestUtils.assertSameJSONContent(getPaginatedAas1JSONString(), getJSONWithoutCursorInfo(response)); } private String getPaginatedAas1JSONString() throws FileNotFoundException, IOException { return BaSyxHttpTestUtils.readJSONStringFromClasspath("PaginatedAasSimple_1.json"); } + + private String getJSONWithoutCursorInfo(String response) throws JsonMappingException, JsonProcessingException { + return BaSyxHttpTestUtils.removeCursorFromJSON(response); + } private CloseableHttpResponse updateSpecificAas(String dummyaasid, String aasJsonContent) throws IOException { return BaSyxHttpTestUtils.executePutOnURL(getSpecificAasAccessURL(dummyaasid), aasJsonContent); diff --git a/basyx.aasrepository/basyx.aasrepository-http/src/test/resources/PaginatedAasSimple_1.json b/basyx.aasrepository/basyx.aasrepository-http/src/test/resources/PaginatedAasSimple_1.json index efa29b99c..f43f94410 100644 --- a/basyx.aasrepository/basyx.aasrepository-http/src/test/resources/PaginatedAasSimple_1.json +++ b/basyx.aasrepository/basyx.aasrepository-http/src/test/resources/PaginatedAasSimple_1.json @@ -1,7 +1,5 @@ { - "paging_metadata": { - "cursor": "Y3VzdG9tSWRlbnRpZmllcg" - }, + "paging_metadata": {}, "result": [ { "modelType": "AssetAdministrationShell", diff --git a/basyx.aasrepository/basyx.aasrepository.component/pom.xml b/basyx.aasrepository/basyx.aasrepository.component/pom.xml index 10f0e76d7..0be146a76 100644 --- a/basyx.aasrepository/basyx.aasrepository.component/pom.xml +++ b/basyx.aasrepository/basyx.aasrepository.component/pom.xml @@ -1,4 +1,6 @@ - + 4.0.0 @@ -11,7 +13,11 @@ aas-repository - http://localhost:${docker.host.port}/shells + aas-registry-log-mem:2.0.0-SNAPSHOT + + http://localhost:${docker.host.port}/shells + + http://localhost:8050/api/v3.0/shell-descriptors @@ -55,6 +61,12 @@ org.eclipse.digitaltwin.basyx basyx.aasrepository-feature-registry-integration + + org.eclipse.digitaltwin.basyx + basyx.aasrepository-feature-registry-integration + tests + test + org.eclipse.digitaltwin.basyx basyx.http @@ -111,7 +123,7 @@ - + @@ -131,12 +143,31 @@ - ${docker.host.port}:${docker.container.port} + + ${docker.host.port}:${docker.container.port} ${docker.container.waitForEndpoint} + + + integration + + + + + aas-registry + + ${docker.username}/${docker.image.aasreg.inmem.name} + + + 8050:8080 + + + ${docker.container.aasreg.inmem.waitForEndpoint} + + diff --git a/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application-integration.properties b/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application-integration.properties new file mode 100644 index 000000000..3221cd8cf --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application-integration.properties @@ -0,0 +1,26 @@ +server.port=8081 +server.error.path=/error + +spring.application.name=AAS Repository +basyx.aasrepo.name=aas-repo + +basyx.backend = InMemory + +basyx.aasrepository.feature.registryintegration=http://host.docker.internal:8050/api/v3.0 +basyx.externalurl=http://localhost:8081 + +#basyx.backend = MongoDB +#spring.data.mongodb.host=127.0.0.1 +#spring.data.mongodb.port=27017 +#spring.data.mongodb.database=aas +#spring.data.mongodb.authentication-database=admin +#spring.data.mongodb.username=mongoAdmin +#spring.data.mongodb.password=mongoPassword + + +# basyx.aasrepository.feature.mqtt.enabled = true +# mqtt.clientId=TestClient +# mqtt.hostname = localhost +# mqtt.port = 1883 + +# basyx.cors.allowed-origins=http://localhost:3000, http://localhost:4000 \ No newline at end of file diff --git a/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application.properties b/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application.properties index a1ec62149..81f2a3530 100644 --- a/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application.properties +++ b/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application.properties @@ -1,4 +1,4 @@ -server.port=8082 +server.port=8081 server.error.path=/error spring.application.name=AAS Repository @@ -6,8 +6,8 @@ basyx.aasrepo.name=aas-repo basyx.backend = InMemory -basyx.aasrepository.feature.registryintegration=http://localhost:8030/api/v3.0 -basyx.aasrepository.externalurl=http://localhost:8082/shells +# basyx.aasrepository.feature.registryintegration=http://localhost:8050/api/v3.0 +# basyx.externalurl=http://localhost:8081 #basyx.backend = MongoDB #spring.data.mongodb.host=127.0.0.1 diff --git a/basyx.aasrepository/basyx.aasrepository.component/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/component/AASRepositoryRegistryLinkIT.java b/basyx.aasrepository/basyx.aasrepository.component/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/component/AASRepositoryRegistryLinkIT.java new file mode 100644 index 000000000..f3e3a6162 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository.component/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/component/AASRepositoryRegistryLinkIT.java @@ -0,0 +1,12 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.component; + +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.AasRepositoryRegistryTestLink; + +/** + * Integration test for the AAS Repository integration with AAS Registry + * + * @author danish + * + */ +public class AASRepositoryRegistryLinkIT extends AasRepositoryRegistryTestLink { +} diff --git a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/RepositoryRegistryLinkException.java b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/RepositoryRegistryLinkException.java index cc7bb0ad5..cb9127368 100644 --- a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/RepositoryRegistryLinkException.java +++ b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/RepositoryRegistryLinkException.java @@ -36,12 +36,12 @@ public class RepositoryRegistryLinkException extends RuntimeException { public RepositoryRegistryLinkException() { } - public RepositoryRegistryLinkException(String shellIdentifier) { - super(getMessage(shellIdentifier)); + public RepositoryRegistryLinkException(String id) { + super(getMessage(id)); } - private static String getMessage(String shellIdentifier) { - return "Unable to link shell with id " + shellIdentifier + " with Registry"; + private static String getMessage(String id) { + return "Unable to link the element with id " + id + " with the Registry"; } } diff --git a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/RepositoryRegistryUnlinkException.java b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/RepositoryRegistryUnlinkException.java new file mode 100644 index 000000000..2ebc53676 --- /dev/null +++ b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/RepositoryRegistryUnlinkException.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.core.exceptions; + +/** + * Indicates failure of automatic unlink between Repository and Registry + * + * @author danish + * + */ +@SuppressWarnings("serial") +public class RepositoryRegistryUnlinkException extends RuntimeException { + public RepositoryRegistryUnlinkException() { + } + + public RepositoryRegistryUnlinkException(String id) { + super(getMessage(id)); + } + + private static String getMessage(String id) { + return "Unable to unlink the element with id " + id + " from the Registry"; + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java b/basyx.common/basyx.http/src/main/java/org/eclipse/digitaltwin/basyx/http/CustomTypeCloneFactory.java similarity index 79% rename from basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java rename to basyx.common/basyx.http/src/main/java/org/eclipse/digitaltwin/basyx/http/CustomTypeCloneFactory.java index 941932d34..e3a8cdf94 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/CloneFactory.java +++ b/basyx.common/basyx.http/src/main/java/org/eclipse/digitaltwin/basyx/http/CustomTypeCloneFactory.java @@ -23,10 +23,13 @@ * SPDX-License-Identifier: MIT ******************************************************************************/ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; +package org.eclipse.digitaltwin.basyx.http; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -38,15 +41,18 @@ * * @author danish */ -public class CloneFactory { +public class CustomTypeCloneFactory { + + private Logger logger = LoggerFactory.getLogger(CustomTypeCloneFactory.class); - private ObjectMapper mapper = new ObjectMapper(); + private ObjectMapper mapper; private Class elementType; - public CloneFactory(Class outputElementType) { + public CustomTypeCloneFactory(Class outputElementType, ObjectMapper mapper) { super(); this.elementType = outputElementType; + this.mapper = mapper; } /** @@ -64,15 +70,16 @@ public List create(List input) { e.printStackTrace(); } - List resultList = null; - try { - resultList = mapper.readValue(serializedLangString, mapper.getTypeFactory().constructCollectionType(List.class, elementType)); + return mapper.readValue(serializedLangString, mapper.getTypeFactory().constructCollectionType(List.class, elementType)); } catch (JsonProcessingException e) { e.printStackTrace(); + + logger.error("Failure occurred while creating the clone"); + + return null; } - return resultList; } /** @@ -93,7 +100,10 @@ public O create(I input) { return mapper.readValue(serializedLangString, elementType); } catch (JsonProcessingException e) { e.printStackTrace(); - throw new RuntimeException(); + + logger.error("Failure occurred while creating the clone"); + + return null; } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAttributeMapper.java b/basyx.common/basyx.http/src/test/java/org/eclipse/digitaltwin/basyx/http/TestCustomTypeCloneFactory.java similarity index 52% rename from basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAttributeMapper.java rename to basyx.common/basyx.http/src/test/java/org/eclipse/digitaltwin/basyx/http/TestCustomTypeCloneFactory.java index 8865ee275..6e496a30c 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAttributeMapper.java +++ b/basyx.common/basyx.http/src/test/java/org/eclipse/digitaltwin/basyx/http/TestCustomTypeCloneFactory.java @@ -23,50 +23,46 @@ * SPDX-License-Identifier: MIT ******************************************************************************/ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; +package org.eclipse.digitaltwin.basyx.http; import static org.junit.Assert.assertEquals; +import java.util.Arrays; import java.util.List; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.AttributeMapper; +import org.eclipse.digitaltwin.basyx.http.CustomTypeCloneFactory; +import org.eclipse.digitaltwin.basyx.http.testmodels.CloneFactoryFirstTestModel; +import org.eclipse.digitaltwin.basyx.http.testmodels.CloneFactorySecondTestModel; import org.junit.Test; +import com.fasterxml.jackson.databind.ObjectMapper; + /** - * Test class for {@link AttributeMapper} + * Unit tests for {@link CustomTypeCloneFactory} * * @author danish */ -public class TestAttributeMapper { - +public class TestCustomTypeCloneFactory { + @Test - public void mapDescriptions() { - List expectedDescriptions = RegistryIntegrationTestHelper.getAasRegLangStringTextTypes(); - - List actualDescriptions = new AttributeMapper().mapDescription(RegistryIntegrationTestHelper.getAas4jLangStringTextTypes()); - + public void createCloneOfListType() { + List expectedDescriptions = Arrays.asList(new CloneFactorySecondTestModel("Java", "Programming Language"), new CloneFactorySecondTestModel("Deutsch", "Language")); + + CustomTypeCloneFactory cloneFactory = new CustomTypeCloneFactory<>(CloneFactorySecondTestModel.class, new ObjectMapper()); + + List actualDescriptions = cloneFactory.create(Arrays.asList(new CloneFactoryFirstTestModel("Java", "Programming Language"), new CloneFactoryFirstTestModel("Deutsch", "Language"))); + assertEquals(expectedDescriptions.size(), actualDescriptions.size()); assertEquals(expectedDescriptions, actualDescriptions); } - - @Test - public void mapDisplayNames() { - List expectedDisplayNames = RegistryIntegrationTestHelper.getAasRegLangStringNameTypes(); - - List actualDisplayNames = new AttributeMapper().mapDisplayName(RegistryIntegrationTestHelper.getAas4jLangStringNameTypes()); - - assertEquals(expectedDisplayNames.size(), actualDisplayNames.size()); - assertEquals(expectedDisplayNames, actualDisplayNames); - } - + @Test - public void mapAssetKind() { - AssetKind expectedAssetKind = RegistryIntegrationTestHelper.AASREG_ASSET_KIND; - - AssetKind actualAssetKind = new AttributeMapper().mapAssetKind(RegistryIntegrationTestHelper.AAS4J_ASSET_KIND); + public void createCloneOfNonListType() { + CloneFactoryFirstTestModel expectedAssetKind = new CloneFactoryFirstTestModel("Deutsch", "Language"); + + CustomTypeCloneFactory cloneFactory = new CustomTypeCloneFactory<>(CloneFactoryFirstTestModel.class, new ObjectMapper()); + + CloneFactoryFirstTestModel actualAssetKind = cloneFactory.create(new CloneFactorySecondTestModel("Deutsch", "Language")); assertEquals(expectedAssetKind, actualAssetKind); } diff --git a/basyx.common/basyx.http/src/test/java/org/eclipse/digitaltwin/basyx/http/serialization/BaSyxHttpTestUtils.java b/basyx.common/basyx.http/src/test/java/org/eclipse/digitaltwin/basyx/http/serialization/BaSyxHttpTestUtils.java index 7d494dd7e..bd54c3db6 100644 --- a/basyx.common/basyx.http/src/test/java/org/eclipse/digitaltwin/basyx/http/serialization/BaSyxHttpTestUtils.java +++ b/basyx.common/basyx.http/src/test/java/org/eclipse/digitaltwin/basyx/http/serialization/BaSyxHttpTestUtils.java @@ -48,7 +48,9 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; /** * Supports the tests working with the HTTP/REST API of AAS, Submodels, etc. @@ -58,6 +60,9 @@ */ public class BaSyxHttpTestUtils { + private static final String CURSOR = "cursor"; + private static final String PAGING_METADATA_KEY = "paging_metadata"; + /** * Reads the JSON String from a JSON file in the classpath * @@ -168,6 +173,30 @@ public static CloseableHttpResponse executePatchOnURL(String url, String content return client.execute(patchRequest); } + + /** + * Removes cursor node from the paging_metadata provided in the JSON + * + * @param inputJSON + * @return + * + * @throws JsonMappingException + * @throws JsonProcessingException + */ + public static String removeCursorFromJSON(String inputJSON) throws JsonMappingException, JsonProcessingException { + ObjectMapper mapper = new ObjectMapper(); + + JsonNode rootNode = mapper.readTree(inputJSON); + + if (rootNode.has(PAGING_METADATA_KEY)) { + ObjectNode pagingMetadata = (ObjectNode) rootNode.get(PAGING_METADATA_KEY); + + if (pagingMetadata.has(CURSOR)) + pagingMetadata.remove(CURSOR); + } + + return mapper.writeValueAsString(rootNode); + } private static HttpPatch createPatchRequestWithHeader(String url, String content) { HttpPatch patchRequest = new HttpPatch(url); diff --git a/basyx.common/basyx.http/src/test/java/org/eclipse/digitaltwin/basyx/http/testmodels/CloneFactoryFirstTestModel.java b/basyx.common/basyx.http/src/test/java/org/eclipse/digitaltwin/basyx/http/testmodels/CloneFactoryFirstTestModel.java new file mode 100644 index 000000000..afd7630af --- /dev/null +++ b/basyx.common/basyx.http/src/test/java/org/eclipse/digitaltwin/basyx/http/testmodels/CloneFactoryFirstTestModel.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.http.testmodels; + +import java.util.Objects; + +import org.eclipse.digitaltwin.basyx.http.CustomTypeCloneFactory; + +/** + * Simple model for testing {@link CustomTypeCloneFactory} + * + * @author danish + */ +public class CloneFactoryFirstTestModel { + + private String name; + private String type; + + public CloneFactoryFirstTestModel() {} + + public CloneFactoryFirstTestModel(String name, String type) { + super(); + this.name = name; + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @Override + public int hashCode() { + return Objects.hash(name, type); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CloneFactoryFirstTestModel other = (CloneFactoryFirstTestModel) obj; + return Objects.equals(name, other.name) && Objects.equals(type, other.type); + } + +} diff --git a/basyx.common/basyx.http/src/test/java/org/eclipse/digitaltwin/basyx/http/testmodels/CloneFactorySecondTestModel.java b/basyx.common/basyx.http/src/test/java/org/eclipse/digitaltwin/basyx/http/testmodels/CloneFactorySecondTestModel.java new file mode 100644 index 000000000..3878eb5e5 --- /dev/null +++ b/basyx.common/basyx.http/src/test/java/org/eclipse/digitaltwin/basyx/http/testmodels/CloneFactorySecondTestModel.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.http.testmodels; + +import java.util.Objects; + +/** + * Simple model for testing {@link CloneFactory} + * + * @author danish + */ +public class CloneFactorySecondTestModel { + + private String name; + private String type; + + public CloneFactorySecondTestModel() {} + + public CloneFactorySecondTestModel(String name, String type) { + super(); + this.name = name; + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @Override + public int hashCode() { + return Objects.hash(name, type); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CloneFactorySecondTestModel other = (CloneFactorySecondTestModel) obj; + return Objects.equals(name, other.name) && Objects.equals(type, other.type); + } + +} diff --git a/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/conceptdescriptionrepository/http/ConceptDescriptionRepositoryHTTPSuite.java b/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/conceptdescriptionrepository/http/ConceptDescriptionRepositoryHTTPSuite.java index 43b46ebb5..97036ac22 100644 --- a/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/conceptdescriptionrepository/http/ConceptDescriptionRepositoryHTTPSuite.java +++ b/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/conceptdescriptionrepository/http/ConceptDescriptionRepositoryHTTPSuite.java @@ -66,28 +66,28 @@ public abstract class ConceptDescriptionRepositoryHTTPSuite { public void getAllConceptDescriptionsPreconfigured() throws IOException, ParseException { String conceptDescriptionsJSON = requestAllConceptDescriptions(); String expectedConceptDescriptionsJSON = getAllConceptDescriptionJSON(); - BaSyxHttpTestUtils.assertSameJSONContent(expectedConceptDescriptionsJSON, conceptDescriptionsJSON); + BaSyxHttpTestUtils.assertSameJSONContent(expectedConceptDescriptionsJSON, getJSONWithoutCursorInfo(conceptDescriptionsJSON)); } @Test public void getAllConceptDescriptionsByIdShortPreconfigured() throws IOException, ParseException { String conceptDescriptionsJSON = getAllConceptDescriptionsByIdShortJSON("ConceptDescription"); String expectedConceptDescriptionsJSON = getConceptDescriptionsWithIdShort(); - BaSyxHttpTestUtils.assertSameJSONContent(expectedConceptDescriptionsJSON, conceptDescriptionsJSON); + BaSyxHttpTestUtils.assertSameJSONContent(expectedConceptDescriptionsJSON, getJSONWithoutCursorInfo(conceptDescriptionsJSON)); } @Test public void getAllConceptDescriptionsByIsCaseOfPreconfigured() throws IOException, ParseException { String conceptDescriptionsJSON = getAllConceptDescriptionsByIsCaseOfJSON(getReferenceJSON()); String expectedConceptDescriptionsJSON = getConceptDescriptionsWithIsCaseOf(); - BaSyxHttpTestUtils.assertSameJSONContent(expectedConceptDescriptionsJSON, conceptDescriptionsJSON); + BaSyxHttpTestUtils.assertSameJSONContent(expectedConceptDescriptionsJSON, getJSONWithoutCursorInfo(conceptDescriptionsJSON)); } @Test public void getAllConceptDescriptionsByDataSpecRefPreconfigured() throws IOException, ParseException { String conceptDescriptionsJSON = getAllConceptDescriptionsByDataSpecRefJSON(getDataSpecReferenceJSON()); String expectedConceptDescriptionsJSON = getAllConceptDescriptionsWithDataSpecRef(); - BaSyxHttpTestUtils.assertSameJSONContent(expectedConceptDescriptionsJSON, conceptDescriptionsJSON); + BaSyxHttpTestUtils.assertSameJSONContent(expectedConceptDescriptionsJSON, getJSONWithoutCursorInfo(conceptDescriptionsJSON)); } @Test @@ -190,7 +190,7 @@ public void paginatedResult() throws ParseException, IOException { String expectedDescriptionJSON = getConceptDescriptionsWithDataSpecRefWithPagination(); - BaSyxHttpTestUtils.assertSameJSONContent(expectedDescriptionJSON, actualConceptDescriptionsJSON); + BaSyxHttpTestUtils.assertSameJSONContent(expectedDescriptionJSON, getJSONWithoutCursorInfo(actualConceptDescriptionsJSON)); } @Test @@ -199,6 +199,10 @@ public void deleteNonExistingConceptDescription() throws IOException { assertEquals(HttpStatus.NOT_FOUND.value(), deletionResponse.getCode()); } + + private String getJSONWithoutCursorInfo(String response) throws JsonMappingException, JsonProcessingException { + return BaSyxHttpTestUtils.removeCursorFromJSON(response); + } private void assertConceptDescriptionCreationReponse(String conceptDescriptionJSON, CloseableHttpResponse creationResponse) throws IOException, ParseException, JsonProcessingException, JsonMappingException { assertEquals(HttpStatus.CREATED.value(), creationResponse.getCode()); diff --git a/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-http/src/test/resources/ConceptDescriptionWithDataSpecWithPagination.json b/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-http/src/test/resources/ConceptDescriptionWithDataSpecWithPagination.json index 23b19ee16..dfbcee15f 100644 --- a/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-http/src/test/resources/ConceptDescriptionWithDataSpecWithPagination.json +++ b/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-http/src/test/resources/ConceptDescriptionWithDataSpecWithPagination.json @@ -1,6 +1,5 @@ { "paging_metadata": { - "cursor": "N0E3MTA0SUhUUkVGTjQzMjI" }, "result": [ { diff --git a/basyx.submodelregistry/open-api/patch-base-extensions.yaml b/basyx.submodelregistry/open-api/patch-base-extensions.yaml index c4c51c5b7..9bf76df17 100644 --- a/basyx.submodelregistry/open-api/patch-base-extensions.yaml +++ b/basyx.submodelregistry/open-api/patch-base-extensions.yaml @@ -89,12 +89,12 @@ path: /components/schemas/AdministrativeInformation/allOf/1/properties/version/allOf - op: add path: /components/schemas/AdministrativeInformation/allOf/1/properties/version/pattern - value: "^(0|[1-9][0-9]{1,3})$" + value: "^(0|[1-9][0-9]{0,3})$" - op: remove path: /components/schemas/AdministrativeInformation/allOf/1/properties/revision/allOf - op: add path: /components/schemas/AdministrativeInformation/allOf/1/properties/revision/pattern - value: "^(0|[1-9][0-9]{1,3})$" + value: "^(0|[1-9][0-9]{0,3})$" - op: replace path: /components/schemas/AdministrativeInformation/allOf/1/properties/templateId/pattern value: "^([\\t\\n\\r \\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" @@ -242,4 +242,4 @@ - op: replace path: /paths/~1description/get/tags value: - - Submodel Registry \ No newline at end of file + - Submodel Registry diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/Readme.md b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/Readme.md index a115b941d..3316b2588 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/Readme.md +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/Readme.md @@ -1,3 +1,3 @@ -# AssetAdministrationShell Repository - Registry Integration -This feature automatically integrates the Descriptor with the Registry while creation of the Shell at Repository. -It also automatically removes the Descriptor from the Registry when the Shell is removed from the Repository. \ No newline at end of file +# Submodel Repository - Registry Integration +This feature automatically integrates the Descriptor with the Registry while creation of the Submodel at the Repository. +It also automatically removes the Descriptor from the Registry when the Submodel is removed from the Repository. \ No newline at end of file diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/pom.xml b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/pom.xml index cfb351e68..8c82786f5 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/pom.xml +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/pom.xml @@ -23,34 +23,23 @@ org.eclipse.digitaltwin.basyx basyx.http - - - org.eclipse.digitaltwin.basyx - basyx.submodelrepository-core - tests test + tests org.eclipse.digitaltwin.basyx - basyx.submodelrepository-backend-inmemory - test + basyx.http org.eclipse.digitaltwin.basyx - basyx.submodelrepository-backend-inmemory + basyx.submodelrepository-http + tests test - org.eclipse.digitaltwin.aas4j - dataformat-json - - - org.springframework.boot - spring-boot-starter - - - org.eclipse.digitaltwin.basyx - basyx.submodelservice-backend-inmemory + org.apache.httpcomponents.client5 + httpclient5 + test \ No newline at end of file diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java deleted file mode 100644 index cb3f373e4..000000000 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.List; - -import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; -import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation; -import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; -import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Endpoint; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ProtocolInformation; -import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; - -/** - * Factory for creating the {@link AssetAdministrationShellDescriptor} - * - * @author danish - */ -public class AasDescriptorFactory { - - private static final String AAS_INTERFACE = "AAS-3.0"; - private AssetAdministrationShell shell; - private String aasRepositoryURL; - - public AasDescriptorFactory(AssetAdministrationShell shell, String aasRepositoryURL) { - super(); - this.shell = shell; - this.aasRepositoryURL = aasRepositoryURL; - } - - /** - * Creates {@link AssetAdministrationShellDescriptor} - * - * @return the created AssetAdministrationShellDescriptor - */ - public AssetAdministrationShellDescriptor create() { - - AssetAdministrationShellDescriptor descriptor = new AssetAdministrationShellDescriptor(); - - setId(shell.getId(), descriptor); - - setIdShort(shell.getIdShort(), descriptor); - - setEndpointItem(shell.getId(), descriptor); - - setDescription(shell.getDescription(), descriptor); - - setDisplayName(shell.getDisplayName(), descriptor); - - setAssetKind(shell.getAssetInformation(), descriptor); - - setAssetType(shell.getAssetInformation(), descriptor); - - setGlobalAssetId(shell.getAssetInformation(), descriptor); - - return descriptor; - } - - private void setDescription(List descriptions, AssetAdministrationShellDescriptor descriptor) { - - if (descriptions == null || descriptions.isEmpty()) - return; - - descriptor.setDescription(new AttributeMapper().mapDescription(descriptions)); - } - - private void setDisplayName(List displayNames, AssetAdministrationShellDescriptor descriptor) { - - if (displayNames == null || displayNames.isEmpty()) - return; - - descriptor.setDisplayName(new AttributeMapper().mapDisplayName(displayNames)); - } - - private void setAssetKind(AssetInformation assetInformation, AssetAdministrationShellDescriptor descriptor) { - - if (assetInformation == null || assetInformation.getAssetKind() == null) - return; - - descriptor.setAssetKind(new AttributeMapper().mapAssetKind(assetInformation.getAssetKind())); - } - - private void setAssetType(AssetInformation assetInformation, AssetAdministrationShellDescriptor descriptor) { - - if (assetInformation == null || assetInformation.getAssetType() == null) - return; - - descriptor.setAssetType(assetInformation.getAssetType()); - } - - private void setGlobalAssetId(AssetInformation assetInformation, AssetAdministrationShellDescriptor descriptor) { - - if (assetInformation == null || assetInformation.getGlobalAssetID() == null) - return; - - descriptor.setGlobalAssetId(assetInformation.getGlobalAssetID()); - } - - private void setEndpointItem(String shellId, AssetAdministrationShellDescriptor descriptor) { - - Endpoint endpoint = new Endpoint(); - endpoint.setInterface(AAS_INTERFACE); - ProtocolInformation protocolInformation = createProtocolInformation(shellId); - endpoint.setProtocolInformation(protocolInformation); - - descriptor.addEndpointsItem(endpoint); - } - - private ProtocolInformation createProtocolInformation(String shellId) { - String href = String.format("%s/%s", aasRepositoryURL, Base64UrlEncodedIdentifier.encodeIdentifier(shellId)); - - ProtocolInformation protocolInformation = new ProtocolInformation(); - protocolInformation.endpointProtocol(getProtocol(href)); - protocolInformation.setHref(href); - - return protocolInformation; - } - - private void setIdShort(String idShort, AssetAdministrationShellDescriptor descriptor) { - descriptor.setIdShort(idShort); - } - - private void setId(String shellId, AssetAdministrationShellDescriptor descriptor) { - descriptor.setId(shellId); - } - - private String getProtocol(String endpoint) { - try { - return new URL(endpoint).getProtocol(); - } catch (MalformedURLException e) { - throw new RuntimeException(); - } - } - -} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java deleted file mode 100644 index 4c05095d6..000000000 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AttributeMapper.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; - -import java.util.List; - -import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; -import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; - -/** - * Maps the models defined in AasRegistry client to the AAS4J models - * - * @author danish - */ -public class AttributeMapper { - - /** - * Maps {@link AssetAdministrationShell#getDescription()} from AAS4J to - * AasRegistry client - * - * @param descriptions - * @return the mapped descriptions - */ - public List mapDescription(List descriptions) { - CloneFactory cloneFactory = new CloneFactory<>(LangStringTextType.class); - - return cloneFactory.create(descriptions); - } - - /** - * Maps {@link AssetAdministrationShell#getDisplayName()} from AAS4J to - * AasRegistry client - * - * @param displayNames - * @return the mapped displayNames - */ - public List mapDisplayName(List displayNames) { - CloneFactory cloneFactory = new CloneFactory<>(LangStringNameType.class); - - return cloneFactory.create(displayNames); - } - - /** - * Maps {@link AssetInformation#getAssetKind()} from AAS4J to AasRegistry client - * - * @param assetKind - * @return the mapped assetKind - */ - public AssetKind mapAssetKind(org.eclipse.digitaltwin.aas4j.v3.model.AssetKind assetKind) { - - return AssetKind.valueOf(AssetKind.class, assetKind.name()); - } - -} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java deleted file mode 100644 index e4445e5d8..000000000 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2021 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; - -import java.util.List; - -import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; -import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation; -import org.eclipse.digitaltwin.aas4j.v3.model.Reference; -import org.eclipse.digitaltwin.basyx.aasregistry.client.ApiException; -import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor; -import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; -import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException; -import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; -import org.eclipse.digitaltwin.basyx.core.exceptions.RepositoryRegistryLinkException; -import org.eclipse.digitaltwin.basyx.core.pagination.CursorResult; -import org.eclipse.digitaltwin.basyx.core.pagination.PaginationInfo; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Decorator for linking {@link AasRepository} with AasRegistry - * - * @author danish - * - */ -public class RegistryIntegrationAasRepository implements AasRepository { - private static Logger logger = LoggerFactory.getLogger(RegistryIntegrationAasRepository.class); - - private AasRepository decorated; - - private AasRepositoryRegistryLink aasRepositoryRegistryLink; - - public RegistryIntegrationAasRepository(AasRepository decorated, AasRepositoryRegistryLink aasRepositoryRegistryLink) { - this.decorated = decorated; - this.aasRepositoryRegistryLink = aasRepositoryRegistryLink; - } - - @Override - public CursorResult> getAllAas(PaginationInfo pInfo) { - return decorated.getAllAas(pInfo); - } - - @Override - public AssetAdministrationShell getAas(String aasId) throws ElementDoesNotExistException { - return decorated.getAas(aasId); - } - - @Override - public void createAas(AssetAdministrationShell aas) throws CollidingIdentifierException { - decorated.createAas(aas); - - integrateAasWithRegistry(aas, aasRepositoryRegistryLink.getAasRepositoryURL()); - } - - @Override - public void updateAas(String aasId, AssetAdministrationShell aas) { - decorated.updateAas(aasId, aas); - } - - @Override - public void deleteAas(String aasId) { - AssetAdministrationShell shell = decorated.getAas(aasId); - decorated.deleteAas(aasId); - - deleteFromRegistry(shell.getId()); - } - - @Override - public String getName() { - return decorated.getName(); - } - - @Override - public CursorResult> getSubmodelReferences(String aasId, PaginationInfo pInfo) { - return decorated.getSubmodelReferences(aasId, pInfo); - } - - @Override - public void addSubmodelReference(String aasId, Reference submodelReference) { - decorated.addSubmodelReference(aasId, submodelReference); - } - - @Override - public void removeSubmodelReference(String aasId, String submodelId) { - decorated.removeSubmodelReference(aasId, submodelId); - } - - @Override - public void setAssetInformation(String aasId, AssetInformation aasInfo) throws ElementDoesNotExistException { - decorated.setAssetInformation(aasId, aasInfo); - } - - @Override - public AssetInformation getAssetInformation(String aasId) throws ElementDoesNotExistException { - return decorated.getAssetInformation(aasId); - } - - private void integrateAasWithRegistry(AssetAdministrationShell shell, String aasRepositoryURL) { - AssetAdministrationShellDescriptor descriptor = new AasDescriptorFactory(shell, aasRepositoryURL).create(); - - RegistryAndDiscoveryInterfaceApi registryApi = aasRepositoryRegistryLink.getRegistryApi(); - - try { - registryApi.postAssetAdministrationShellDescriptor(descriptor); - - logger.info("Shell {} is automatically linked with the Registry", shell.getId()); - } catch (ApiException e) { - throw new RepositoryRegistryLinkException(shell.getId()); - } - } - - private void deleteFromRegistry(String shellId) { - RegistryAndDiscoveryInterfaceApi registryApi = aasRepositoryRegistryLink.getRegistryApi(); - - try { - registryApi.deleteAssetAdministrationShellDescriptorById(shellId); - - logger.info("Shell {} is automatically de-registered with the Registry", shellId); - } catch (ApiException e) { - throw new RuntimeException("Automatic deletion of the shell with shellId " + shellId + " from the Registry fails"); - } - } - -} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java new file mode 100644 index 000000000..28f8862c5 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java @@ -0,0 +1,192 @@ +/******************************************************************************* + * Copyright (C) 2021 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ +package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration; + +import java.io.File; +import java.io.InputStream; +import java.util.List; + +import org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable; +import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; +import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement; +import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException; +import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; +import org.eclipse.digitaltwin.basyx.core.exceptions.ElementNotAFileException; +import org.eclipse.digitaltwin.basyx.core.exceptions.FileDoesNotExistException; +import org.eclipse.digitaltwin.basyx.core.exceptions.RepositoryRegistryLinkException; +import org.eclipse.digitaltwin.basyx.core.exceptions.RepositoryRegistryUnlinkException; +import org.eclipse.digitaltwin.basyx.core.pagination.CursorResult; +import org.eclipse.digitaltwin.basyx.core.pagination.PaginationInfo; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.ApiException; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.api.SubmodelRegistryApi; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.SubmodelDescriptor; +import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepository; +import org.eclipse.digitaltwin.basyx.submodelservice.value.SubmodelElementValue; +import org.eclipse.digitaltwin.basyx.submodelservice.value.SubmodelValueOnly; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Decorator for linking {@link SubmodelRepository} with SubmodelRegistry + * + * @author danish + * + */ +public class RegistryIntegrationSubmodelRepository implements SubmodelRepository { + private static Logger logger = LoggerFactory.getLogger(RegistryIntegrationSubmodelRepository.class); + + private SubmodelRepository decorated; + private SubmodelRepositoryRegistryLink smRepositoryRegistryLink; + + public RegistryIntegrationSubmodelRepository(SubmodelRepository decorated, SubmodelRepositoryRegistryLink smRepositoryRegistryLink) { + this.decorated = decorated; + this.smRepositoryRegistryLink = smRepositoryRegistryLink; + } + + @Override + public CursorResult> getAllSubmodels(PaginationInfo pInfo) { + return decorated.getAllSubmodels(pInfo); + } + + @Override + public Submodel getSubmodel(String submodelId) throws ElementDoesNotExistException { + return decorated.getSubmodel(submodelId); + } + + @Override + public void updateSubmodel(String submodelId, Submodel submodel) throws ElementDoesNotExistException { + decorated.updateSubmodel(submodelId, submodel); + } + + @Override + public void createSubmodel(Submodel submodel) throws CollidingIdentifierException { + decorated.createSubmodel(submodel); + + integrateSubmodelWithRegistry(submodel, smRepositoryRegistryLink.getSubmodelRepositoryBaseURL()); + } + + @Override + public void deleteSubmodel(String submodelId) throws ElementDoesNotExistException { + decorated.deleteSubmodel(submodelId); + + deleteFromRegistry(submodelId); + } + + @Override + public CursorResult> getSubmodelElements(String submodelId, PaginationInfo pInfo) throws ElementDoesNotExistException { + return decorated.getSubmodelElements(submodelId, pInfo); + } + + @Override + public SubmodelElement getSubmodelElement(String submodelId, String smeIdShort) throws ElementDoesNotExistException { + return decorated.getSubmodelElement(submodelId, smeIdShort); + } + + @Override + public SubmodelElementValue getSubmodelElementValue(String submodelId, String smeIdShort) throws ElementDoesNotExistException { + return decorated.getSubmodelElementValue(submodelId, smeIdShort); + } + + @Override + public void setSubmodelElementValue(String submodelId, String idShortPath, SubmodelElementValue value) throws ElementDoesNotExistException { + decorated.setSubmodelElementValue(submodelId, idShortPath, value); + } + + @Override + public void createSubmodelElement(String submodelId, SubmodelElement smElement) { + decorated.createSubmodelElement(submodelId, smElement); + } + + @Override + public void createSubmodelElement(String submodelId, String idShortPath, SubmodelElement smElement) throws ElementDoesNotExistException { + decorated.createSubmodelElement(submodelId, smElement); + } + + @Override + public void deleteSubmodelElement(String submodelId, String idShortPath) throws ElementDoesNotExistException { + decorated.deleteSubmodelElement(submodelId, idShortPath); + } + + @Override + public OperationVariable[] invokeOperation(String submodelId, String idShortPath, OperationVariable[] input) throws ElementDoesNotExistException { + return decorated.invokeOperation(submodelId, idShortPath, input); + } + + @Override + public SubmodelValueOnly getSubmodelByIdValueOnly(String submodelId) throws ElementDoesNotExistException { + return decorated.getSubmodelByIdValueOnly(submodelId); + } + + @Override + public Submodel getSubmodelByIdMetadata(String submodelId) throws ElementDoesNotExistException { + return decorated.getSubmodelByIdMetadata(submodelId); + } + + @Override + public File getFileByPathSubmodel(String submodelId, String idShortPath) throws ElementDoesNotExistException, ElementNotAFileException, FileDoesNotExistException { + return decorated.getFileByPathSubmodel(submodelId, idShortPath); + } + + @Override + public void setFileValue(String submodelId, String idShortPath, String fileName, InputStream inputStream) throws ElementDoesNotExistException, ElementNotAFileException { + decorated.setFileValue(submodelId, idShortPath, fileName, inputStream); + } + + @Override + public void deleteFileValue(String submodelId, String idShortPath) throws ElementDoesNotExistException, ElementNotAFileException, FileDoesNotExistException { + decorated.deleteFileValue(submodelId, idShortPath); + } + + private void integrateSubmodelWithRegistry(Submodel submodel, String aasRepositoryURL) { + SubmodelDescriptor descriptor = new SubmodelDescriptorFactory(submodel, aasRepositoryURL).create(); + + SubmodelRegistryApi registryApi = smRepositoryRegistryLink.getRegistryApi(); + + try { + registryApi.postSubmodelDescriptor(descriptor); + + logger.info("Submodel {} has been automatically linked with the Registry", submodel.getId()); + } catch (ApiException e) { + e.printStackTrace(); + + throw new RepositoryRegistryLinkException(submodel.getId()); + } + } + + private void deleteFromRegistry(String submodelId) { + SubmodelRegistryApi registryApi = smRepositoryRegistryLink.getRegistryApi(); + + try { + registryApi.deleteSubmodelDescriptorById(submodelId); + + logger.info("Submodel {} has been automatically de-registered from the Registry", submodelId); + } catch (ApiException e) { + e.printStackTrace(); + + throw new RepositoryRegistryUnlinkException(submodelId); + } + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryConfiguration.java similarity index 66% rename from basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java rename to basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryConfiguration.java index 6bae6f63a..e29a3e0d2 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryConfiguration.java @@ -23,12 +23,10 @@ * SPDX-License-Identifier: MIT ******************************************************************************/ +package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration; -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; - -import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; -import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; -import org.eclipse.paho.client.mqttv3.MqttException; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.api.SubmodelRegistryApi; +import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepository; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -36,19 +34,19 @@ import org.springframework.context.annotation.Configuration; /** - * Configuration for {@link AasRepository} with AasRegistry + * Configuration for integrating {@link SubmodelRepository} with SubmodelRegistry * * @author danish */ @Configuration -@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.feature.registryintegration:}') && !T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.externalurl:}')") -public class RegistryIntegrationAasRepositoryConfiguration { +@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.submodelrepository.feature.registryintegration:}') && !T(org.springframework.util.StringUtils).isEmpty('${basyx.externalurl:}')") +public class RegistryIntegrationSubmodelRepositoryConfiguration { @Bean @ConditionalOnMissingBean - public AasRepositoryRegistryLink getAasRepositoryRegistryLink(@Value("${basyx.aasrepository.feature.registryintegration}") String registryBasePath, @Value("${basyx.aasrepository.externalurl}") String aasRepositoryURL) throws MqttException { + public SubmodelRepositoryRegistryLink getAasRepositoryRegistryLink(@Value("${basyx.submodelrepository.feature.registryintegration}") String registryBasePath, @Value("${basyx.externalurl}") String smRepositoryBaseURL) { - return new AasRepositoryRegistryLink(new RegistryAndDiscoveryInterfaceApi(registryBasePath), aasRepositoryURL); + return new SubmodelRepositoryRegistryLink(new SubmodelRegistryApi(registryBasePath), smRepositoryBaseURL); } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFactory.java new file mode 100644 index 000000000..4e47830a5 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFactory.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration; + +import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepository; +import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepositoryFactory; + +/** + * Factory for creating {@link RegistryIntegrationSubmodelRepository} + * + * @author danish + */ +public class RegistryIntegrationSubmodelRepositoryFactory implements SubmodelRepositoryFactory { + + private SubmodelRepositoryFactory decorated; + private SubmodelRepositoryRegistryLink smRepositoryRegistryLink; + + public RegistryIntegrationSubmodelRepositoryFactory(SubmodelRepositoryFactory decorated, SubmodelRepositoryRegistryLink smRepositoryRegistryLink) { + this.decorated = decorated; + this.smRepositoryRegistryLink = smRepositoryRegistryLink; + } + + @Override + public SubmodelRepository create() { + return new RegistryIntegrationSubmodelRepository(decorated.create(), smRepositoryRegistryLink); + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFeature.java similarity index 61% rename from basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java rename to basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFeature.java index 0fa430c1f..f4f32a1c0 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFeature.java @@ -24,34 +24,34 @@ ******************************************************************************/ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; +package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration; -import org.eclipse.digitaltwin.basyx.aasrepository.AasRepositoryFactory; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.AasRepositoryFeature; +import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepositoryFactory; +import org.eclipse.digitaltwin.basyx.submodelrepository.feature.SubmodelRepositoryFeature; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.stereotype.Component; /** - * Feature for integrating Registry with Aas Repository + * Feature for integrating Registry with {@link AasRepository} * * @author danish */ @Component -@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.feature.registryintegration:}') && !T(org.springframework.util.StringUtils).isEmpty('${basyx.aasrepository.externalurl:}')") -public class RegistryIntegrationAasRepositoryFeature implements AasRepositoryFeature { - public final static String FEATURENAME = "basyx.aasrepository.feature.registryintegration"; +@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.submodelrepository.feature.registryintegration:}') && !T(org.springframework.util.StringUtils).isEmpty('${basyx.externalurl:}')") +public class RegistryIntegrationSubmodelRepositoryFeature implements SubmodelRepositoryFeature { + public final static String FEATURENAME = "basyx.submodelrepository.feature.registryintegration"; - private AasRepositoryRegistryLink aasRepositoryRegistryLink; + private SubmodelRepositoryRegistryLink smRepositoryRegistryLink; @Autowired - public RegistryIntegrationAasRepositoryFeature(AasRepositoryRegistryLink aasRepositoryRegistryLink) { - this.aasRepositoryRegistryLink = aasRepositoryRegistryLink; + public RegistryIntegrationSubmodelRepositoryFeature(SubmodelRepositoryRegistryLink smRepositoryRegistryLink) { + this.smRepositoryRegistryLink = smRepositoryRegistryLink; } @Override - public AasRepositoryFactory decorate(AasRepositoryFactory aasRepositoryFactory) { - return new RegistryIntegrationAasRepositoryFactory(aasRepositoryFactory, aasRepositoryRegistryLink); + public SubmodelRepositoryFactory decorate(SubmodelRepositoryFactory smRepositoryFactory) { + return new RegistryIntegrationSubmodelRepositoryFactory(smRepositoryFactory, smRepositoryRegistryLink); } @Override @@ -65,7 +65,7 @@ public void cleanUp() { @Override public String getName() { - return "AasRepository Registry Integration"; + return "SubmodelRepository Registry Integration"; } @Override diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java new file mode 100644 index 000000000..439b27bb9 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java @@ -0,0 +1,190 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; + +import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.Extension; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; +import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; +import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Endpoint; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.ProtocolInformation; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.SubmodelDescriptor; +import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.AttributeMapper; +import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.DefaultAttributeMapperFactory; + +/** + * Factory for creating the {@link SubmodelDescriptor} + * + * @author danish + */ +public class SubmodelDescriptorFactory { + + private static final String SUBMODEL_INTERFACE = "SUBMODEL-3.0"; + private static final String SUBMODEL_REPOSITORY_PATH = "/submodels"; + + private Submodel submodel; + private String smRepositoryURL; + + private AttributeMapper attributeMapper; + + public SubmodelDescriptorFactory(Submodel submodel, String smRepositoryBaseURL) { + super(); + this.submodel = submodel; + this.smRepositoryURL = createSubmodelRepositoryUrl(smRepositoryBaseURL); + this.attributeMapper = new DefaultAttributeMapperFactory().create(); + } + + /** + * Creates {@link SubmodelDescriptor} + * + * @return the created {@link SubmodelDescriptor} + */ + public SubmodelDescriptor create() { + + SubmodelDescriptor descriptor = new SubmodelDescriptor(); + + setId(submodel.getId(), descriptor); + + setIdShort(submodel.getIdShort(), descriptor); + + setEndpointItem(submodel.getId(), descriptor); + + setDescription(submodel.getDescription(), descriptor); + + setDisplayName(submodel.getDisplayName(), descriptor); + + setExtensions(submodel.getExtensions(), descriptor); + + setAdministration(submodel.getAdministration(), descriptor); + + setSemanticId(submodel.getSemanticID(), descriptor); + + setSupplementalSemanticId(submodel.getSupplementalSemanticIds(), descriptor); + + return descriptor; + } + + private void setDescription(List descriptions, SubmodelDescriptor descriptor) { + + if (descriptions == null || descriptions.isEmpty()) + return; + + descriptor.setDescription(attributeMapper.mapDescription(descriptions)); + } + + private void setDisplayName(List displayNames, SubmodelDescriptor descriptor) { + + if (displayNames == null || displayNames.isEmpty()) + return; + + descriptor.setDisplayName(attributeMapper.mapDisplayName(displayNames)); + } + + private void setExtensions(List extensions, SubmodelDescriptor descriptor) { + + if (extensions == null || extensions.isEmpty()) + return; + + descriptor.setExtensions(attributeMapper.mapExtensions(extensions)); + } + + private void setAdministration(AdministrativeInformation administration, SubmodelDescriptor descriptor) { + + if (administration == null) + return; + + descriptor.setAdministration(attributeMapper.mapAdministration(administration)); + } + + private void setSemanticId(Reference reference, SubmodelDescriptor descriptor) { + + if (reference == null) + return; + + descriptor.setSemanticId(attributeMapper.mapSemanticId(reference)); + } + + private void setSupplementalSemanticId(List supplementalSemanticIds, SubmodelDescriptor descriptor) { + + if (supplementalSemanticIds == null || supplementalSemanticIds.isEmpty()) + return; + + descriptor.setSupplementalSemanticId(attributeMapper.mapSupplementalSemanticId(supplementalSemanticIds)); + } + + private void setEndpointItem(String shellId, SubmodelDescriptor descriptor) { + + Endpoint endpoint = new Endpoint(); + endpoint.setInterface(SUBMODEL_INTERFACE); + ProtocolInformation protocolInformation = createProtocolInformation(shellId); + endpoint.setProtocolInformation(protocolInformation); + + descriptor.addEndpointsItem(endpoint); + } + + private ProtocolInformation createProtocolInformation(String shellId) { + String href = String.format("%s/%s", smRepositoryURL, Base64UrlEncodedIdentifier.encodeIdentifier(shellId)); + + ProtocolInformation protocolInformation = new ProtocolInformation(); + protocolInformation.endpointProtocol(getProtocol(href)); + protocolInformation.setHref(href); + + return protocolInformation; + } + + private void setIdShort(String idShort, SubmodelDescriptor descriptor) { + descriptor.setIdShort(idShort); + } + + private void setId(String shellId, SubmodelDescriptor descriptor) { + descriptor.setId(shellId); + } + + private String getProtocol(String endpoint) { + try { + return new URL(endpoint).getProtocol(); + } catch (MalformedURLException e) { + throw new RuntimeException(); + } + } + + private String createSubmodelRepositoryUrl(String smRepositoryBaseURL) { + + try { + return new URL(new URL(smRepositoryBaseURL), SUBMODEL_REPOSITORY_PATH).toString(); + } catch (MalformedURLException e) { + throw new RuntimeException("The Submodel Repository Base url is malformed " + e.getMessage()); + } + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLink.java similarity index 66% rename from basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java rename to basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLink.java index d13b3e8a3..83eec3746 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLink.java @@ -23,33 +23,33 @@ * SPDX-License-Identifier: MIT ******************************************************************************/ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; +package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration; -import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; -import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.api.SubmodelRegistryApi; +import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepository; /** - * Represents information for linking {@link AasRepository} with AasRegistry + * Represents information for linking {@link SubmodelRepository} with SubmodelRegistry * * @author danish */ -public class AasRepositoryRegistryLink { +public class SubmodelRepositoryRegistryLink { - private RegistryAndDiscoveryInterfaceApi registryApi; - private String aasRepositoryURL; + private SubmodelRegistryApi registryApi; + private String smRepositoryBaseURL; - public AasRepositoryRegistryLink(RegistryAndDiscoveryInterfaceApi registryApi, String aasRepositoryURL) { + public SubmodelRepositoryRegistryLink(SubmodelRegistryApi registryApi, String smRepositoryBaseURL) { super(); this.registryApi = registryApi; - this.aasRepositoryURL = aasRepositoryURL; + this.smRepositoryBaseURL = smRepositoryBaseURL; } - public RegistryAndDiscoveryInterfaceApi getRegistryApi() { + public SubmodelRegistryApi getRegistryApi() { return registryApi; } - public String getAasRepositoryURL() { - return aasRepositoryURL; + public String getSubmodelRepositoryBaseURL() { + return smRepositoryBaseURL; } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/AttributeMapper.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/AttributeMapper.java new file mode 100644 index 000000000..9a4a62835 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/AttributeMapper.java @@ -0,0 +1,165 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper; + +import java.util.List; + +import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; +import org.eclipse.digitaltwin.basyx.http.CustomTypeCloneFactory; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.AdministrativeInformation; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Extension; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringNameType; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringTextType; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Reference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Maps the models defined in AAS4J to the SubmodelRegistry client models + * + * @author danish + */ +public class AttributeMapper { + + private Logger logger = LoggerFactory.getLogger(AttributeMapper.class); + + private ObjectMapper mapper; + + public AttributeMapper(ObjectMapper mapper) { + this.mapper = mapper; + } + + /** + * Maps {@link Submodel#getDescription()} from AAS4J to + * SubmodelRegistry client + * + * @param descriptions + * @return the mapped descriptions + */ + public List mapDescription(List descriptions) { + CustomTypeCloneFactory cloneFactory = new CustomTypeCloneFactory<>(LangStringTextType.class, mapper); + + List mappedDescriptions = cloneFactory.create(descriptions); + + if (mappedDescriptions == null) + logger.error("Descriptions could not be mapped due to a failure"); + + return mappedDescriptions; + } + + /** + * Maps {@link Submodel#getDisplayName()} from AAS4J to + * SubmodelRegistry client + * + * @param displayNames + * @return the mapped displayNames + */ + public List mapDisplayName(List displayNames) { + CustomTypeCloneFactory cloneFactory = new CustomTypeCloneFactory<>(LangStringNameType.class, mapper); + + List mappedDisplayNames = cloneFactory.create(displayNames); + + if (mappedDisplayNames == null) + logger.error("DisplayNames could not be mapped due to a failure"); + + return mappedDisplayNames; + } + + /** + * Maps {@link Submodel#getExtensions()} from AAS4J to + * SubmodelRegistry client + * + * @param extensions + * @return the mapped extensions + */ + public List mapExtensions(List extensions) { + CustomTypeCloneFactory cloneFactory = new CustomTypeCloneFactory<>(Extension.class, mapper); + + List mappedExtensions = cloneFactory.create(extensions); + + if (mappedExtensions == null) + logger.error("Extensions could not be mapped due to a failure"); + + return cloneFactory.create(extensions); + } + + /** + * Maps {@link Submodel#getAdministration()} from AAS4J to + * SubmodelRegistry client + * + * @param administrativeInformation + * @return the mapped administrativeInformation + */ + public AdministrativeInformation mapAdministration(org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation administrativeInformation) { + CustomTypeCloneFactory cloneFactory = new CustomTypeCloneFactory<>(AdministrativeInformation.class, mapper); + + AdministrativeInformation mappedAdministrativeInformation = cloneFactory.create(administrativeInformation); + + if (mappedAdministrativeInformation == null) + logger.error("AdministrativeInformation could not be mapped due to a failure"); + + return mappedAdministrativeInformation; + } + + /** + * Maps {@link Submodel#getSemanticID()} from AAS4J to + * SubmodelRegistry client + * + * @param semanticId + * @return the mapped semanticId + */ + public Reference mapSemanticId(org.eclipse.digitaltwin.aas4j.v3.model.Reference semanticId) { + CustomTypeCloneFactory cloneFactory = new CustomTypeCloneFactory<>(Reference.class, mapper); + + Reference mappedSemanticId = cloneFactory.create(semanticId); + + if (mappedSemanticId == null) + logger.error("SemanticId could not be mapped due to a failure"); + + return mappedSemanticId; + } + + /** + * Maps {@link Submodel#getSupplementalSemanticIds()} from AAS4J to + * SubmodelRegistry client + * + * @param supplementalSemanticIds + * @return the mapped supplementalSemanticIds + */ + public List mapSupplementalSemanticId(List supplementalSemanticIds) { + CustomTypeCloneFactory cloneFactory = new CustomTypeCloneFactory<>(Reference.class, mapper); + + List mappedSupplementalSemanticId = cloneFactory.create(supplementalSemanticIds); + + if (mappedSupplementalSemanticId == null) + logger.error("SupplementalSemanticId could not be mapped due to a failure"); + + return mappedSupplementalSemanticId; + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java new file mode 100644 index 000000000..0413cb13a --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper; + +import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.Extension; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.DataTypeDefXsd; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.KeyTypes; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.ReferenceTypes; +import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.deserializer.DataTypeDefXsdDeserializer; +import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.deserializer.KeyTypeDeserializer; +import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.deserializer.ReferenceTypeDeserializer; +import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.mixin.AdministrativeInformationMixin; +import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.mixin.ExtensionMixin; +import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.mixin.ReferenceMixin; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; + +/** + * Factory for creating {@link AttributeMapper} with default {@link ObjectMapper} configurations + * + * @author danish + */ +public class DefaultAttributeMapperFactory { + + /** + * Creates the {@link AttributeMapper} with default configurations of the {@link ObjectMapper} + * + * @return default attribute mapper + */ + public AttributeMapper create() { + ObjectMapper mapper = new ObjectMapper(); + + SimpleModule adminInfoMixInModule = createMixInModule(AdministrativeInformation.class, AdministrativeInformationMixin.class); + + SimpleModule referenceMixInModule = createMixInModule(Reference.class, ReferenceMixin.class); + + SimpleModule extensionMixInModule = createMixInModule(Extension.class, ExtensionMixin.class); + + SimpleModule keyTypesDeserModule = createDeserializerModule(KeyTypes.class, new KeyTypeDeserializer()); + + SimpleModule refTypesDeserModule = createDeserializerModule(ReferenceTypes.class, new ReferenceTypeDeserializer()); + + SimpleModule dataTypeDeserModule = createDeserializerModule(DataTypeDefXsd.class, new DataTypeDefXsdDeserializer()); + + mapper.registerModules(adminInfoMixInModule, referenceMixInModule, extensionMixInModule, keyTypesDeserModule, refTypesDeserModule, dataTypeDeserModule); + + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + + return new AttributeMapper(mapper); + } + + private SimpleModule createDeserializerModule(Class type, JsonDeserializer deser) { + SimpleModule moduleDeser = new SimpleModule(); + moduleDeser.addDeserializer(type, deser); + + return moduleDeser; + } + + private SimpleModule createMixInModule(Class targetType, Class mixInClass) { + SimpleModule module = new SimpleModule(); + module.setMixInAnnotation(targetType, mixInClass); + + return module; + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java new file mode 100644 index 000000000..85f2a425a --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.deserializer; + +import java.io.IOException; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.DataTypeDefXsd; + +import com.fasterxml.jackson.core.JacksonException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; + +/** + * Custom deserializer for {@link DataTypeDefXsd} + * + * @author danish + */ +public class DataTypeDefXsdDeserializer extends JsonDeserializer { + + @Override + public DataTypeDefXsd deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { + try { + JsonNode node = p.getCodec().readTree(p); + + String value = node.asText(); + + String compatibleEnumValue = StringUtils.remove(value, '_'); + + return DataTypeDefXsd.valueOf(DataTypeDefXsd.class, compatibleEnumValue); + } catch (Exception e) { + throw new RuntimeException("Unable to deserialize the DataTypeDefXsd Enum"); + } + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java new file mode 100644 index 000000000..9afc5dd05 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.deserializer; + +import java.io.IOException; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.KeyTypes; + +import com.fasterxml.jackson.core.JacksonException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; + +/** + * Custom deserializer for {@link KeyTypes} + * + * @author danish + */ +public class KeyTypeDeserializer extends JsonDeserializer { + + @Override + public KeyTypes deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { + try { + JsonNode node = p.getCodec().readTree(p); + + String value = node.asText(); + + String compatibleEnumValue = StringUtils.remove(value, '_'); + + return KeyTypes.valueOf(KeyTypes.class, compatibleEnumValue); + + } catch (Exception e) { + throw new RuntimeException("Unable to deserialize the KeyTypes Enum"); + } + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java new file mode 100644 index 000000000..565d6e5dd --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.deserializer; + +import java.io.IOException; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.ReferenceTypes; + +import com.fasterxml.jackson.core.JacksonException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; + +/** + * Custom deserializer for {@link ReferenceTypes} + * + * @author danish + */ +public class ReferenceTypeDeserializer extends JsonDeserializer { + + @Override + public ReferenceTypes deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { + try { + JsonNode node = p.getCodec().readTree(p); + + String value = node.asText(); + + String compatibleEnumValue = StringUtils.remove(value, '_'); + + return ReferenceTypes.valueOf(ReferenceTypes.class, compatibleEnumValue); + + } catch (Exception e) { + throw new RuntimeException("Unable to deserialize the ReferenceTypes Enum"); + } + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/AdministrativeInformationMixin.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/AdministrativeInformationMixin.java new file mode 100644 index 000000000..a9342f211 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/AdministrativeInformationMixin.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.mixin; + +import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Mixin for {@link AdministrativeInformation} + * + * @author danish + */ +public interface AdministrativeInformationMixin { + + @JsonProperty("templateId") + public String getTemplateID(); + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/ExtensionMixin.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/ExtensionMixin.java new file mode 100644 index 000000000..b5acb6e18 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/ExtensionMixin.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.mixin; + + +import org.eclipse.digitaltwin.aas4j.v3.model.Extension; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Mixin for {@link Extension} + * + * @author danish + */ +public interface ExtensionMixin { + + @JsonProperty("semanticId") + public Reference getSemanticID(); + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/ReferenceMixin.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/ReferenceMixin.java new file mode 100644 index 000000000..1a239a5db --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/ReferenceMixin.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.mixin; + +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Mixin for {@link Reference} + * + * @author danish + */ +public interface ReferenceMixin { + + @JsonProperty("referredSemanticId") + public Reference getReferredSemanticID(); + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java deleted file mode 100644 index cdb213063..000000000 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; - -import java.util.Arrays; -import java.util.List; - -import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; -import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; -import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringNameType; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringTextType; - -/** - * Test helper class for Registry integration - * - * @author danish - */ -public class RegistryIntegrationTestHelper { - - // LangStringTextType AAS4J - private static final LangStringTextType aas4jLangStringTextType_1 = new DefaultLangStringTextType.Builder().language("de").text("Ein Beispiel").build(); - private static final LangStringTextType aas4jLangStringTextType_2 = new DefaultLangStringTextType.Builder().language("en").text("An Example").build(); - - // LangStringTextType AasRegistry - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType aasRegLangStringTextType_1 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("de") - .text("Ein Beispiel"); - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType aasRegLangStringTextType_2 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("en") - .text("An Example"); - - // LangStringNameType AAS4J - private static final LangStringNameType AAS4J_LANG_STRING_NAME_TYPE_1 = new DefaultLangStringNameType.Builder().language("en").text("Name type string").build(); - private static final LangStringNameType AAS4J_LANG_STRING_NAME_TYPE_2 = new DefaultLangStringNameType.Builder().language("de").text("Namenstypzeichenfolge").build(); - - // LangStringTextType AasRegistry - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType AASREG_LANG_STRING_NAME_TYPE_1 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType().language("en").text("Name type string"); - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType AASREG_LANG_STRING_NAME_TYPE_2 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType().language("de").text("Namenstypzeichenfolge"); - - // AssetKind AAS4J - public static final AssetKind AAS4J_ASSET_KIND = AssetKind.INSTANCE; - - // AssetKind AasRegistry - public static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind AASREG_ASSET_KIND = org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind.INSTANCE; - - public static List getAas4jLangStringTextTypes() { - return Arrays.asList(aas4jLangStringTextType_1, aas4jLangStringTextType_2); - } - - public static List getAasRegLangStringTextTypes() { - return Arrays.asList(aasRegLangStringTextType_1, aasRegLangStringTextType_2); - } - - public static List getAas4jLangStringNameTypes() { - return Arrays.asList(AAS4J_LANG_STRING_NAME_TYPE_1, AAS4J_LANG_STRING_NAME_TYPE_2); - } - - public static List getAasRegLangStringNameTypes() { - return Arrays.asList(AASREG_LANG_STRING_NAME_TYPE_1, AASREG_LANG_STRING_NAME_TYPE_2); - } - -} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationTestHelper.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationTestHelper.java new file mode 100644 index 000000000..0d52c7d1b --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationTestHelper.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXSD; +import org.eclipse.digitaltwin.aas4j.v3.model.EmbeddedDataSpecification; +import org.eclipse.digitaltwin.aas4j.v3.model.Extension; +import org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; +import org.eclipse.digitaltwin.aas4j.v3.model.ReferenceTypes; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultEmbeddedDataSpecification; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultExtension; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultKey; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringNameType; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringTextType; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultReference; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.DataTypeDefXsd; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Key; + +/** + * A helper class for testing RegistryIntegration feature + * + * @author danish + */ +public class RegistryIntegrationTestHelper { + + // LangStringTextType AAS4J + private static final LangStringTextType AAS4J_LANG_STRING_TEXT_TYPE_1 = new DefaultLangStringTextType.Builder().language("de").text("Ein Beispiel").build(); + private static final LangStringTextType AAS4J_LANG_STRING_TEXT_TYPE_2 = new DefaultLangStringTextType.Builder().language("en").text("An Example").build(); + + // LangStringTextType SMRegistry + private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringTextType SMREG_LANG_STRING_TEXT_TYPE_1 = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringTextType().language("de") + .text("Ein Beispiel"); + private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringTextType SMREG_LANG_STRING_TEXT_TYPE_2 = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringTextType().language("en") + .text("An Example"); + + // LangStringNameType AAS4J + private static final LangStringNameType AAS4J_LANG_STRING_NAME_TYPE_1 = new DefaultLangStringNameType.Builder().language("en").text("Name type string").build(); + private static final LangStringNameType AAS4J_LANG_STRING_NAME_TYPE_2 = new DefaultLangStringNameType.Builder().language("de").text("Namenstypzeichenfolge").build(); + + // LangStringNameType SMRegistry + private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringNameType SMREG_LANG_STRING_NAME_TYPE_1 = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringNameType().language("en") + .text("Name type string"); + private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringNameType SMREG_LANG_STRING_NAME_TYPE_2 = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringNameType().language("de") + .text("Namenstypzeichenfolge"); + + // Administration AAS4J + private static final Reference AAS4J_DATASPECIFICATION = new DefaultReference.Builder().keys(new DefaultKey.Builder().type(KeyTypes.BLOB).value("BlobValue").build()).type(ReferenceTypes.EXTERNAL_REFERENCE).build(); + private static final EmbeddedDataSpecification AAS4JEMB_EMBEDDED_DATA_SPECIFICATION = new DefaultEmbeddedDataSpecification.Builder().dataSpecification(AAS4J_DATASPECIFICATION).build(); + + // Administration SMRegistry + private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Reference SMREG__DATASPECIFICATION = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Reference() + .keys(Arrays.asList(new Key().type(org.eclipse.digitaltwin.basyx.submodelregistry.client.model.KeyTypes.BLOB).value("BlobValue"))).type(org.eclipse.digitaltwin.basyx.submodelregistry.client.model.ReferenceTypes.EXTERNALREFERENCE); + private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.EmbeddedDataSpecification SMREG_EMBEDDED_DATA_SPECIFICATION = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.EmbeddedDataSpecification() + .dataSpecification(SMREG__DATASPECIFICATION); + + private static final String VERSION = "1.0.0"; + private static final String REVISION = "3"; + private static final String TEMPLATEID = "ID2.0"; + + // Extension AAS4J + private static final Extension AAS4J_EXTENSION = new DefaultExtension.Builder().semanticID(AAS4J_DATASPECIFICATION).name("extension").valueType(DataTypeDefXSD.STRING).value("extensionValue").build(); + + // Extension SMRegistry + private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Extension SMREG_EXTENSION = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Extension().semanticId(SMREG__DATASPECIFICATION).name("extension") + .valueType(DataTypeDefXsd.STRING).value("extensionValue").supplementalSemanticIds(new ArrayList<>()).refersTo(new ArrayList<>()); + + public static List getAas4jLangStringTextTypes() { + return Arrays.asList(AAS4J_LANG_STRING_TEXT_TYPE_1, AAS4J_LANG_STRING_TEXT_TYPE_2); + } + + public static List getSubmodelRegLangStringTextTypes() { + return Arrays.asList(SMREG_LANG_STRING_TEXT_TYPE_1, SMREG_LANG_STRING_TEXT_TYPE_2); + } + + public static AdministrativeInformation getAas4jAdministration() { + return new DefaultAdministrativeInformation.Builder().embeddedDataSpecifications(AAS4JEMB_EMBEDDED_DATA_SPECIFICATION).version(VERSION).revision(REVISION).templateID(TEMPLATEID).build(); + } + + public static org.eclipse.digitaltwin.basyx.submodelregistry.client.model.AdministrativeInformation getSubmodelRegAdministration() { + return new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.AdministrativeInformation().embeddedDataSpecifications(Arrays.asList(SMREG_EMBEDDED_DATA_SPECIFICATION)).version(VERSION).revision(REVISION) + .templateId(TEMPLATEID); + } + + public static List getAas4jLangStringNameTypes() { + return Arrays.asList(AAS4J_LANG_STRING_NAME_TYPE_1, AAS4J_LANG_STRING_NAME_TYPE_2); + } + + public static List getSubmodelRegLangStringNameTypes() { + return Arrays.asList(SMREG_LANG_STRING_NAME_TYPE_1, SMREG_LANG_STRING_NAME_TYPE_2); + } + + public static List getAas4jExtensions() { + return Arrays.asList(AAS4J_EXTENSION); + } + + public static List getSubmodelRegExtensions() { + return Arrays.asList(SMREG_EXTENSION); + } + + public static Reference getAas4jSemanticId() { + return AAS4J_DATASPECIFICATION; + } + + public static org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Reference getSubmodelRegSemanticId() { + return SMREG__DATASPECIFICATION; + } + + public static List getAas4jSupplementalSemanticIds() { + return Arrays.asList(AAS4J_DATASPECIFICATION, AAS4J_DATASPECIFICATION); + } + + public static List getSubmodelRegSupplementalSemanticIds() { + return Arrays.asList(SMREG__DATASPECIFICATION, SMREG__DATASPECIFICATION); + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java new file mode 100644 index 000000000..df6a1ed21 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java @@ -0,0 +1,192 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Arrays; +import java.util.List; + +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; +import org.eclipse.digitaltwin.basyx.http.serialization.BaSyxHttpTestUtils; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.ApiException; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.api.SubmodelRegistryApi; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Endpoint; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.GetSubmodelDescriptorsResult; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Key; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.KeyTypes; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.ProtocolInformation; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Reference; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.ReferenceTypes; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.SubmodelDescriptor; +import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.RegistryIntegrationSubmodelRepository; +import org.junit.Test; +import org.springframework.http.HttpStatus; + +/** + * Integration test for {@link RegistryIntegrationSubmodelRepository} feature + * + * @author danish + */ +public class SubmodelRepositoryRegistryTestLink { + + private static final String SUBMODEL_REPOSITORY_PATH = "/submodels"; + + private static final String SUMMY_SUBMODEL_IDSHORT = "TechnicalData"; + private static final String DUMMY_SUBMODEL_ID = "7A7104BDAB57E184"; + + public static String submodelRepoBaseUrl = "http://localhost:8081"; + public static String submodelRegistryUrl = "http://localhost:8050/api/v3.0"; + + private static final SubmodelDescriptor DUMMY_DESCRIPTOR = createExpectedDescriptor(); + + @Test + public void createAas() throws FileNotFoundException, IOException, ApiException { + String aasJsonContent = getAas1JSONString(); + + CloseableHttpResponse creationResponse = createAasOnRepo(aasJsonContent); + assertEquals(HttpStatus.CREATED.value(), creationResponse.getCode()); + + SubmodelDescriptor actualDescriptor = retrieveDescriptorFromRegistry(); + + assertEquals(DUMMY_DESCRIPTOR, actualDescriptor); + + resetRepository(); + } + + @Test + public void deleteAas() throws FileNotFoundException, IOException, ApiException { + String aasJsonContent = getAas1JSONString(); + + CloseableHttpResponse creationResponse = createAasOnRepo(aasJsonContent); + assertEquals(HttpStatus.CREATED.value(), creationResponse.getCode()); + + CloseableHttpResponse deleteResponse = deleteAasFromRepo(DUMMY_SUBMODEL_ID); + assertEquals(HttpStatus.NO_CONTENT.value(), deleteResponse.getCode()); + + assertDescriptionDeletionAtRegistry(); + } + + private SubmodelDescriptor retrieveDescriptorFromRegistry() throws ApiException { + SubmodelRegistryApi api = new SubmodelRegistryApi(submodelRegistryUrl); + + return api.getSubmodelDescriptorById(DUMMY_SUBMODEL_ID); + } + + private void resetRepository() throws IOException { + CloseableHttpResponse deleteResponse = deleteAasFromRepo(DUMMY_SUBMODEL_ID); + + assertEquals(HttpStatus.NO_CONTENT.value(), deleteResponse.getCode()); + } + + private CloseableHttpResponse deleteAasFromRepo(String shellId) throws IOException { + return BaSyxHttpTestUtils.executeDeleteOnURL(getSpecificAasAccessURL(shellId)); + } + + private void assertDescriptionDeletionAtRegistry() throws ApiException { + SubmodelRegistryApi api = new SubmodelRegistryApi(submodelRegistryUrl); + + GetSubmodelDescriptorsResult result = api.getAllSubmodelDescriptors(null, null); + + List actualDescriptors = result.getResult(); + + assertTrue(actualDescriptors.isEmpty()); + } + + private String getAas1JSONString() throws FileNotFoundException, IOException { + return BaSyxHttpTestUtils.readJSONStringFromClasspath("SingleSubmodel.json"); + } + + private CloseableHttpResponse createAasOnRepo(String aasJsonContent) throws IOException { + return BaSyxHttpTestUtils.executePostOnURL(createSubmodelRepositoryUrl(submodelRepoBaseUrl), aasJsonContent); + } + + private String getSpecificAasAccessURL(String aasId) { + return createSubmodelRepositoryUrl(submodelRepoBaseUrl) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(aasId); + } + + private static SubmodelDescriptor createExpectedDescriptor() { + + SubmodelDescriptor descriptor = new SubmodelDescriptor(); + + descriptor.setId(DUMMY_SUBMODEL_ID); + descriptor.setIdShort(SUMMY_SUBMODEL_IDSHORT); + descriptor.setSemanticId(createSemanticId()); + descriptor.addEndpointsItem(createEndpointItem()); + + return descriptor; + } + + private static Reference createSemanticId() { + return new Reference().keys(Arrays.asList(new Key().type(KeyTypes.GLOBALREFERENCE).value("0173-1#01-AFZ615#016"))).type(ReferenceTypes.EXTERNALREFERENCE); + } + + private static Endpoint createEndpointItem() { + Endpoint endpoint = new Endpoint(); + endpoint.setInterface("SUBMODEL-3.0"); + endpoint.setProtocolInformation(createProtocolInformation()); + + return endpoint; + } + + private static ProtocolInformation createProtocolInformation() { + String href = createHref(); + + ProtocolInformation protocolInformation = new ProtocolInformation(); + protocolInformation.setHref(href); + protocolInformation.endpointProtocol(getProtocol(href)); + + return protocolInformation; + } + + private static String createHref() { + return String.format("%s/%s", createSubmodelRepositoryUrl(submodelRepoBaseUrl), Base64UrlEncodedIdentifier.encodeIdentifier(DUMMY_SUBMODEL_ID)); + } + + private static String getProtocol(String endpoint) { + try { + return new URL(endpoint).getProtocol(); + } catch (MalformedURLException e) { + throw new RuntimeException(); + } + } + + private static String createSubmodelRepositoryUrl(String smRepositoryBaseURL) { + + try { + return new URL(new URL(smRepositoryBaseURL), SUBMODEL_REPOSITORY_PATH).toString(); + } catch (MalformedURLException e) { + throw new RuntimeException("The Submodel Repository Base url is malformed " + e.getMessage()); + } + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLinkApplication.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLinkApplication.java new file mode 100644 index 000000000..48d91a209 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLinkApplication.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ +package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration; + +import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.RegistryIntegrationSubmodelRepository; +import org.junit.internal.TextListener; +import org.junit.runner.JUnitCore; +import org.junit.runner.Result; + +/** + * Application for testing the {@link RegistryIntegrationSubmodelRepository} feature. + * The first argument is the Submodel Repository Base URL, the second argument is the Submodel + * Registry URL. + * + * @author schnicke, danish + * + */ +public class SubmodelRepositoryRegistryTestLinkApplication { + + public static void main(String[] args) throws Exception { + String smRepoBaseUrl = getSubmodelRepositoryBaseUrl(args); + String smRegUrl = getSubmodelRegistryUrl(args); + + Result result = runTests(smRepoBaseUrl, smRegUrl); + + printResults(result); + } + + private static void printResults(Result result) { + System.out.println("Finished. Result: Failures: " + result.getFailureCount() + ". Ignored: " + result.getIgnoreCount() + ". Tests run: " + result.getRunCount() + ". Time: " + result.getRunTime() + "ms."); + } + + private static Result runTests(String smRepoBaseUrl, String smRegUrl) { + SubmodelRepositoryRegistryTestLink.submodelRepoBaseUrl = smRepoBaseUrl; + SubmodelRepositoryRegistryTestLink.submodelRegistryUrl = smRegUrl; + + JUnitCore junit = new JUnitCore(); + junit.addListener(new TextListener(System.out)); + + return junit.run(SubmodelRepositoryRegistryTestLink.class); + } + + private static String getSubmodelRepositoryBaseUrl(String[] args) { + return args[0]; + } + + private static String getSubmodelRegistryUrl(String[] args) { + return args[1]; + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/TestAttributeMapper.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/TestAttributeMapper.java new file mode 100644 index 000000000..5e1f4e9b8 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/TestAttributeMapper.java @@ -0,0 +1,114 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.AdministrativeInformation; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Extension; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringNameType; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringTextType; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Reference; +import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.AttributeMapper; +import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.DefaultAttributeMapperFactory; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Unit tests for {@link AttributeMapper} + * + * @author danish + */ +public class TestAttributeMapper { + + private static AttributeMapper attributeMapper; + + @BeforeClass + public static void setUp() { + attributeMapper = new DefaultAttributeMapperFactory().create(); + } + + @Test + public void mapDescriptions() { + List expectedDescriptions = RegistryIntegrationTestHelper.getSubmodelRegLangStringTextTypes(); + + List actualDescriptions = attributeMapper.mapDescription(RegistryIntegrationTestHelper.getAas4jLangStringTextTypes()); + + assertEquals(expectedDescriptions.size(), actualDescriptions.size()); + assertEquals(expectedDescriptions, actualDescriptions); + } + + @Test + public void mapDisplayNames() { + List expectedDisplayNames = RegistryIntegrationTestHelper.getSubmodelRegLangStringNameTypes(); + + List actualDisplayNames = attributeMapper.mapDisplayName(RegistryIntegrationTestHelper.getAas4jLangStringNameTypes()); + + assertEquals(expectedDisplayNames.size(), actualDisplayNames.size()); + assertEquals(expectedDisplayNames, actualDisplayNames); + } + + @Test + public void mapExtensions() { + List expectedExtensions = RegistryIntegrationTestHelper.getSubmodelRegExtensions(); + + List actualExtensions = attributeMapper.mapExtensions(RegistryIntegrationTestHelper.getAas4jExtensions()); + + assertEquals(expectedExtensions.size(), actualExtensions.size()); + assertEquals(expectedExtensions, actualExtensions); + } + + @Test + public void mapAdministration() { + AdministrativeInformation expectedAdministrativeInformation = RegistryIntegrationTestHelper.getSubmodelRegAdministration(); + + AdministrativeInformation actualAdministrativeInformation = attributeMapper.mapAdministration(RegistryIntegrationTestHelper.getAas4jAdministration()); + + assertEquals(expectedAdministrativeInformation, actualAdministrativeInformation); + } + + @Test + public void mapSemanticId() { + Reference expectedSemanticId = RegistryIntegrationTestHelper.getSubmodelRegSemanticId(); + + Reference actualSemanticId = attributeMapper.mapSemanticId(RegistryIntegrationTestHelper.getAas4jSemanticId()); + + assertEquals(expectedSemanticId, actualSemanticId); + } + + @Test + public void mapSupplementalSemanticId() { + List expectedSupplementalSemanticId = RegistryIntegrationTestHelper.getSubmodelRegSupplementalSemanticIds(); + + List actualSupplementalSemanticId = attributeMapper.mapSupplementalSemanticId(RegistryIntegrationTestHelper.getAas4jSupplementalSemanticIds()); + + assertEquals(expectedSupplementalSemanticId.size(), actualSupplementalSemanticId.size()); + assertEquals(expectedSupplementalSemanticId, actualSupplementalSemanticId); + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/resources/SingleSubmodel.json b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/resources/SingleSubmodel.json new file mode 100644 index 000000000..8e1e34dfa --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/resources/SingleSubmodel.json @@ -0,0 +1,404 @@ +{ + "modelType": "Submodel", + "id": "7A7104BDAB57E184", + "idShort": "TechnicalData", + "submodelElements": [ + { + "modelType": "Property", + "value": "5000", + "valueType": "xs:integer", + "category": "PARAMETER", + "idShort": "MaxRotationSpeed", + "semanticId": { + "keys": [ + { + "type": "ConceptDescription", + "value": "0173-1#02-BAA120#008" + } + ], + "type": "ExternalReference" + } + }, + { + "modelType": "Range", + "max": "300", + "min": "200", + "valueType": "xs:integer", + "category": "PARAMETER", + "idShort": "RotationSpeedRange", + "semanticId": { + "keys": [ + { + "type": "ConceptDescription", + "value": "0173-1#02-BAA120#008" + } + ], + "type": "ExternalReference" + } + }, + { + "modelType": "MultiLanguageProperty", + "category": "PARAM", + "idShort": "MultiLanguage", + "semanticId": { + "keys": [ + { + "type": "ConceptDescription", + "value": "0173-1#02-BAA120#008" + } + ], + "type": "ExternalReference" + }, + "value": [ + { + "language": "en", + "text": "Hello" + }, + { + "language": "de", + "text": "Hallo" + } + ] + }, + { + "modelType": "File", + "contentType": "application/json", + "value": "testFile.json", + "category": "PARAMETER", + "idShort": "FileData", + "semanticId": { + "keys": [ + { + "type": "ConceptDescription", + "value": "0173-1#02-BAA120#008" + } + ], + "type": "ExternalReference" + } + }, + { + "modelType": "Entity", + "entityType": "CoManagedEntity", + "specificAssetIds": [ + { + "name": "specificAssetIdName", + "value": "specificValue" + } + ], + "statements": [ + { + "modelType": "Property", + "value": "5000", + "valueType": "xs:integer", + "category": "PARAMETER", + "idShort": "MaxRotationSpeed", + "semanticId": { + "keys": [ + { + "type": "ConceptDescription", + "value": "0173-1#02-BAA120#008" + } + ], + "type": "ExternalReference" + } + }, + { + "modelType": "Range", + "max": "300", + "min": "200", + "valueType": "xs:integer", + "category": "PARAMETER", + "idShort": "RotationSpeedRange", + "semanticId": { + "keys": [ + { + "type": "ConceptDescription", + "value": "0173-1#02-BAA120#008" + } + ], + "type": "ExternalReference" + } + } + ], + "category": "Entity", + "idShort": "EntityData", + "globalAssetId": "globalAssetID", + "semanticId": { + "keys": [ + { + "type": "ConceptDescription", + "value": "0173-1#02-BAA120#008" + } + ], + "type": "ExternalReference" + } + }, + { + "modelType": "ReferenceElement", + "category": "PARAMETER", + "idShort": "ReferenceElement", + "value": { + "keys": [ + { + "type": "DataElement", + "value": "DataElement" + } + ], + "type": "ModelReference" + }, + "semanticId": { + "keys": [ + { + "type": "ConceptDescription", + "value": "0173-1#02-BAA120#008" + } + ], + "type": "ExternalReference" + } + }, + { + "modelType": "RelationshipElement", + "category": "PARAMETER", + "idShort": "RelationshipElement", + "first": { + "keys": [ + { + "type": "DataElement", + "value": "DataElement" + } + ], + "type": "ModelReference" + }, + "second": { + "keys": [ + { + "type": "BasicEventElement", + "value": "BasicEventElement" + } + ], + "type": "ExternalReference" + }, + "semanticId": { + "keys": [ + { + "type": "ConceptDescription", + "value": "0173-1#02-BAA120#008" + } + ], + "type": "ExternalReference" + } + }, + { + "modelType": "AnnotatedRelationshipElement", + "category": "PARAMETER", + "idShort": "AnnotatedRelationshipElement", + "first": { + "keys": [ + { + "type": "DataElement", + "value": "DataElement" + } + ], + "type": "ModelReference" + }, + "second": { + "keys": [ + { + "type": "BasicEventElement", + "value": "BasicEventElement" + } + ], + "type": "ExternalReference" + }, + "annotations": [ + { + "modelType": "Property", + "value": "5000", + "valueType": "xs:integer", + "category": "PARAMETER", + "idShort": "MaxRotationSpeed", + "semanticId": { + "keys": [ + { + "type": "ConceptDescription", + "value": "0173-1#02-BAA120#008" + } + ], + "type": "ExternalReference" + } + }, + { + "modelType": "Range", + "max": "300", + "min": "200", + "valueType": "xs:integer", + "category": "PARAMETER", + "idShort": "RotationSpeedRange", + "semanticId": { + "keys": [ + { + "type": "ConceptDescription", + "value": "0173-1#02-BAA120#008" + } + ], + "type": "ExternalReference" + } + } + ], + "semanticId": { + "keys": [ + { + "type": "ConceptDescription", + "value": "0173-1#02-BAA120#008" + } + ], + "type": "ExternalReference" + } + }, + { + "modelType": "Blob", + "contentType": "application/xml", + "value": "VGVzdCBjb250ZW50IG9mIFhNTCBmaWxl", + "category": "PARAMETER", + "idShort": "BlobData", + "semanticId": { + "keys": [ + { + "type": "ConceptDescription", + "value": "0173-1#02-BAA120#008" + } + ], + "type": "ExternalReference" + } + }, + { + "modelType": "SubmodelElementCollection", + "category": "PARAMETER", + "idShort": "SubmodelElementCollection", + "value": [ + { + "modelType": "File", + "contentType": "application/json", + "value": "testFile.json", + "category": "PARAMETER", + "idShort": "FileData", + "semanticId": { + "keys": [ + { + "type": "ConceptDescription", + "value": "0173-1#02-BAA120#008" + } + ], + "type": "ExternalReference" + } + }, + { + "modelType": "Property", + "value": "5000", + "valueType": "xs:integer", + "category": "PARAMETER", + "idShort": "MaxRotationSpeed", + "semanticId": { + "keys": [ + { + "type": "ConceptDescription", + "value": "0173-1#02-BAA120#008" + } + ], + "type": "ExternalReference" + } + } + ], + "semanticId": { + "keys": [ + { + "type": "ConceptDescription", + "value": "0173-1#02-BAA120#008" + } + ], + "type": "ExternalReference" + } + }, + { + "modelType": "SubmodelElementList", + "category": "PARAMETER", + "idShort": "SubmodelElementList", + "orderRelevant": false, + "value": [ + { + "modelType": "Range", + "max": "300", + "min": "200", + "valueType": "xs:integer", + "category": "PARAMETER", + "idShort": "RotationSpeedRange", + "semanticId": { + "keys": [ + { + "type": "ConceptDescription", + "value": "0173-1#02-BAA120#008" + } + ], + "type": "ExternalReference" + } + }, + { + "modelType": "Property", + "value": "5000", + "valueType": "xs:integer", + "category": "PARAMETER", + "idShort": "MaxRotationSpeed", + "semanticId": { + "keys": [ + { + "type": "ConceptDescription", + "value": "0173-1#02-BAA120#008" + } + ], + "type": "ExternalReference" + } + } + ], + "semanticId": { + "keys": [ + { + "type": "ConceptDescription", + "value": "0173-1#02-BAA120#008" + } + ], + "type": "ExternalReference" + } + }, + { + "modelType": "Operation", + "idShort": "square", + "inputVariables": [ + { + "value": { + "modelType": "Property", + "valueType": "xs:int", + "idShort": "input" + } + } + ], + "outputVariables": [ + { + "value": { + "modelType": "Property", + "valueType": "xs:int", + "idShort": "result" + } + } + ] + } + ], + "semanticId": { + "keys": [ + { + "type": "GlobalReference", + "value": "0173-1#01-AFZ615#016" + } + ], + "type": "ExternalReference" + } +} \ No newline at end of file diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/resources/config/moquette.conf b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/resources/config/moquette.conf deleted file mode 100644 index 8511afcd1..000000000 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/resources/config/moquette.conf +++ /dev/null @@ -1,6 +0,0 @@ -# Moquette Java Broker configuration file for testing - -# Do not use the default 1883 port -port 1884 -host 0.0.0.0 -allow_anonymous true \ No newline at end of file diff --git a/basyx.submodelrepository/basyx.submodelrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/http/SubmodelRepositorySubmodelHTTPTestSuite.java b/basyx.submodelrepository/basyx.submodelrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/http/SubmodelRepositorySubmodelHTTPTestSuite.java index 95d0d5524..c7cd4e3bd 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/http/SubmodelRepositorySubmodelHTTPTestSuite.java +++ b/basyx.submodelrepository/basyx.submodelrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/http/SubmodelRepositorySubmodelHTTPTestSuite.java @@ -83,7 +83,8 @@ public abstract class SubmodelRepositorySubmodelHTTPTestSuite { public void getAllSubmodelsPreconfigured() throws IOException, ParseException { String submodelsJSON = BaSyxSubmodelHttpTestUtils.requestAllSubmodels(getURL()); String expectedSubmodelsJSON = getAllSubmodelJSON(); - BaSyxHttpTestUtils.assertSameJSONContent(expectedSubmodelsJSON, submodelsJSON); + + BaSyxHttpTestUtils.assertSameJSONContent(expectedSubmodelsJSON,getJSONWithoutCursorInfo(submodelsJSON)); } @Test @@ -187,7 +188,7 @@ public void getPaginatedSubmodel() throws ParseException, IOException { .requestAllSubmodels(getURL() + "?limit=1&cursor=" + ENCODED_CURSOR); String expected = getSubmodelsPaginatedJson(); - BaSyxHttpTestUtils.assertSameJSONContent(expected, submodelsJSON); + BaSyxHttpTestUtils.assertSameJSONContent(expected, getJSONWithoutCursorInfo(submodelsJSON)); } @Test @@ -240,7 +241,7 @@ public void deleteFileFromNotExistElement() throws FileNotFoundException, Unsupp @Test public void getFile() throws FileNotFoundException, IOException, ParseException { - String fileName = "BaSyx-Logo.png"; + String fileName = DummySubmodelFactory.FILE_NAME; byte[] expectedFile = readBytesFromClasspath(fileName); @@ -269,6 +270,10 @@ public void getFileFromNotExistElement() throws FileNotFoundException, Unsupport assertEquals(HttpStatus.NOT_FOUND.value(), response.getCode()); } + + private String getJSONWithoutCursorInfo(String response) throws JsonMappingException, JsonProcessingException { + return BaSyxHttpTestUtils.removeCursorFromJSON(response); + } private String createSMEFileDeleteURL(String submodelId, String submodelElementIdShort) { return BaSyxSubmodelHttpTestUtils.getSpecificSubmodelAccessPath(getURL(), submodelId) + "/submodel-elements/" + submodelElementIdShort + "/attachment"; @@ -281,9 +286,9 @@ private String createSMEFileGetURL(String submodelId, String submodelElementIdSh private CloseableHttpResponse uploadFileToSubmodelElement(String submodelId, String submodelElementIdShort) throws IOException { CloseableHttpClient client = HttpClients.createDefault(); - String fileName = "BaSyx-Logo.png"; + String fileName = DummySubmodelFactory.FILE_NAME; - java.io.File file = ResourceUtils.getFile("src/test/resources/" + fileName); + java.io.File file = ResourceUtils.getFile("classpath:" + fileName); HttpPut putRequest = createPutRequestWithFile(submodelId, submodelElementIdShort, fileName, file); @@ -382,7 +387,7 @@ private byte[] readBytesFromClasspath(String fileName) throws FileNotFoundExcept } protected List createSubmodels() { - return Arrays.asList(DummySubmodelFactory.createTechnicalDataSubmodel(), DummySubmodelFactory.createOperationalDataSubmodel(), DummySubmodelFactory.createSimpleDataSubmodel()); + return Arrays.asList(DummySubmodelFactory.createTechnicalDataSubmodel(), DummySubmodelFactory.createOperationalDataSubmodel(), DummySubmodelFactory.createSimpleDataSubmodel(), DummySubmodelFactory.createSubmodelWithFileElement()); } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/http/TestSubmodelRepositorySubmodelHTTP.java b/basyx.submodelrepository/basyx.submodelrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/http/TestSubmodelRepositorySubmodelHTTP.java index a60d8deda..0895e19fc 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/http/TestSubmodelRepositorySubmodelHTTP.java +++ b/basyx.submodelrepository/basyx.submodelrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/http/TestSubmodelRepositorySubmodelHTTP.java @@ -25,13 +25,10 @@ package org.eclipse.digitaltwin.basyx.submodelrepository.http; -import java.io.FileNotFoundException; -import java.io.IOException; import java.util.Collection; import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; import org.eclipse.digitaltwin.basyx.core.pagination.PaginationInfo; -import org.eclipse.digitaltwin.basyx.http.serialization.BaSyxHttpTestUtils; import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepository; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -46,7 +43,6 @@ */ public class TestSubmodelRepositorySubmodelHTTP extends SubmodelRepositorySubmodelHTTPTestSuite { private static final PaginationInfo NO_LIMIT_PAGINATION_INFO = new PaginationInfo(0, null); - private static final String SUBMODEL_JSON = "SingleSubmodel4FileTest.json"; private static ConfigurableApplicationContext appContext; @BeforeClass @@ -65,12 +61,6 @@ public void populateRepository() { SubmodelRepository repo = appContext.getBean(SubmodelRepository.class); Collection submodels = createSubmodels(); submodels.forEach(repo::createSubmodel); - try { - createSubmodel4FileTest(); - } catch (IOException e) { - System.out.println("Cannot load " + SUBMODEL_JSON + " for testing file-upload feature."); - e.printStackTrace(); - } } @AfterClass @@ -83,10 +73,4 @@ protected String getURL() { return "http://localhost:8080/submodels"; } - private void createSubmodel4FileTest() throws FileNotFoundException, IOException { - String submodelJSON = BaSyxHttpTestUtils.readJSONStringFromClasspath(SUBMODEL_JSON); - - BaSyxSubmodelHttpTestUtils.createSubmodel(getURL(), submodelJSON); - } - } \ No newline at end of file diff --git a/basyx.submodelrepository/basyx.submodelrepository-http/src/test/resources/SubmodelsPaginated.json b/basyx.submodelrepository/basyx.submodelrepository-http/src/test/resources/SubmodelsPaginated.json index 6fea7de5e..8802a50b3 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-http/src/test/resources/SubmodelsPaginated.json +++ b/basyx.submodelrepository/basyx.submodelrepository-http/src/test/resources/SubmodelsPaginated.json @@ -1,6 +1,5 @@ { "paging_metadata": { - "cursor": "OEE2MzQ0QkRBQjU3RTE4NA" }, "result": [{ "id": "8A6344BDAB57E184", diff --git a/basyx.submodelrepository/basyx.submodelrepository.component/pom.xml b/basyx.submodelrepository/basyx.submodelrepository.component/pom.xml index 16ca9bd9f..a996f2579 100644 --- a/basyx.submodelrepository/basyx.submodelrepository.component/pom.xml +++ b/basyx.submodelrepository/basyx.submodelrepository.component/pom.xml @@ -1,4 +1,6 @@ - + 4.0.0 @@ -8,10 +10,14 @@ basyx.submodelrepository.component - + submodel-repository - http://localhost:${docker.host.port}/submodels + submodel-registry-log-mem:2.0.0-SNAPSHOT + + http://localhost:${docker.host.port}/submodels + + http://localhost:8050/api/v3.0/submodel-descriptors @@ -35,6 +41,16 @@ org.eclipse.digitaltwin.basyx basyx.submodelrepository-feature-mqtt + + org.eclipse.digitaltwin.basyx + basyx.submodelrepository-feature-registry-integration + + + org.eclipse.digitaltwin.basyx + basyx.submodelrepository-feature-registry-integration + tests + test + org.eclipse.digitaltwin.basyx basyx.submodelrepository-http @@ -62,7 +78,7 @@ org.springframework.boot spring-boot-starter-actuator - + org.eclipse.digitaltwin.basyx basyx.submodelservice-core @@ -95,7 +111,6 @@ commons-io commons-io - test com.google.code.gson @@ -114,7 +129,7 @@ - + @@ -134,12 +149,32 @@ - ${docker.host.port}:${docker.container.port} + + ${docker.host.port}:${docker.container.port} ${docker.container.waitForEndpoint} + + + integration + + + + + submodel-registry + + ${docker.username}/${docker.image.smreg.inmem.name} + + + 8050:8080 + + + + ${docker.container.smreg.inmem.waitForEndpoint} + + @@ -172,7 +207,7 @@ - + docker diff --git a/basyx.submodelrepository/basyx.submodelrepository.component/src/main/resources/application-integration.properties b/basyx.submodelrepository/basyx.submodelrepository.component/src/main/resources/application-integration.properties new file mode 100644 index 000000000..322f30647 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository.component/src/main/resources/application-integration.properties @@ -0,0 +1,26 @@ +server.port=8081 +server.error.path=/error + +spring.application.name=AAS Repository +basyx.smrepo.name = sm-repo + +basyx.backend = InMemory + +basyx.submodelrepository.feature.registryintegration=http://host.docker.internal:8050/api/v3.0 +basyx.externalurl=http://localhost:8081 + +#basyx.backend = MongoDB +#spring.data.mongodb.host=mongo +# or spring.data.mongodb.host=127.0.0.1 +#spring.data.mongodb.port=27017 +#spring.data.mongodb.database=submodels +#spring.data.mongodb.authentication-database=admin +#spring.data.mongodb.username=mongoAdmin +#spring.data.mongodb.password=mongoPassword + +# basyx.submodelrepository.feature.mqtt.enabled = true +# mqtt.clientId=TestClient +# mqtt.hostname = localhost +# mqtt.port = 1883 + +# basyx.cors.allowed-origins=http://localhost:3000, http://localhost:4000 \ No newline at end of file diff --git a/basyx.submodelrepository/basyx.submodelrepository.component/src/main/resources/application.properties b/basyx.submodelrepository/basyx.submodelrepository.component/src/main/resources/application.properties index cbbabfbc1..5a6d58449 100644 --- a/basyx.submodelrepository/basyx.submodelrepository.component/src/main/resources/application.properties +++ b/basyx.submodelrepository/basyx.submodelrepository.component/src/main/resources/application.properties @@ -4,6 +4,9 @@ spring.application.name=Submodel Repository basyx.smrepo.name = sm-repo basyx.backend = InMemory +# basyx.submodelrepository.feature.registryintegration=http://localhost:8050/api/v3.0 +# basyx.externalurl=http://localhost:8081 + #basyx.backend = MongoDB #spring.data.mongodb.host=mongo # or spring.data.mongodb.host=127.0.0.1 diff --git a/basyx.submodelrepository/basyx.submodelrepository.component/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/component/SubmodelRepositoryRegistryLinkIT.java b/basyx.submodelrepository/basyx.submodelrepository.component/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/component/SubmodelRepositoryRegistryLinkIT.java new file mode 100644 index 000000000..a0cfaea88 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository.component/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/component/SubmodelRepositoryRegistryLinkIT.java @@ -0,0 +1,12 @@ +package org.eclipse.digitaltwin.basyx.submodelrepository.component; + +import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.SubmodelRepositoryRegistryTestLink; + +/** + * Integration test for the Submodel Repository integration with Submodel Registry + * + * @author danish + * + */ +public class SubmodelRepositoryRegistryLinkIT extends SubmodelRepositoryRegistryTestLink { +} diff --git a/basyx.submodelrepository/basyx.submodelrepository.component/src/test/resources/BaSyx-Logo.png b/basyx.submodelrepository/basyx.submodelrepository.component/src/test/resources/BaSyx-Logo.png new file mode 100644 index 0000000000000000000000000000000000000000..da613e94c07c4fef1b8a454ef927fd2fbf987f66 GIT binary patch literal 11433 zcmaKSbyS<*vS{$&?iSo3SdrpZ9Ewxii-jOXid&&T@gl{G6^G(ZDDG0MSb(BMf;)Zu z?mOqc_s2aqYbD>ecV=eKo|(1x*hg*6SGZVISO5S3S4CMt=lMDG{M81cKmVG#iq}3r zD7_SoymZ~{y?m@Z>;SU1Zq{}n6;~?)g~d_N$jeAWUEIdamDlPY z7+zmj=rc9|AR+AwwX$)x^8#7hIXFTj8Bf}~89|P=l8lDJ8ek2myxm(z<@X+Ty6-jh zY~DNDh}kkqOMxVO#h(ed+Id-ld|h22p5nfejQ>Sf{Q3Q#X+B2Ke}Q;8OEUgnri?VS zLGo@McAyu$U>+MVSO6p<#>@XgNazKa8zcZ00P}%``S=BR_+N;Fg~a(qK>zwMKCk9s zYcH;&p!Bb`o=1|5Z@s*r;(UBQK0drYg1l}X4t)G#Vq$z?0X_i%o@WRiPd|v4l`jv( zlj+|S6zn{0JRG53j&2apKNPL3-QIagGCp(qf4ATY{co}m&wq*OSzvs=R!}~EUhqF# z`Zu74#{UlL>iXZ%o?be3|Bv7Qk+7$pAJmRd$IjF3orle{;_R9JSqdsH?_p=<<>sO1 z=H~KmDQdrU^K$ci>jni0@be0Q*fp$d93lVAaQqjFhK9Hb#M8?PVq>SGAj$YlgxAs0 zRvauKC@8`Y7L->~5aZ`pl$8~eQ&8d;ej%X9F9Mboko`BVf}71dS38K;zj1BWG{BylDpGb2b-0ZlzATf67^m$A+Ma)N&AkWJp3~zUA}g z6zR6kUIyKdn-UK0{{*~5K6wZlr7f*G84rFEJm2YLq5QyLWEJ@tAy=o-gT=)y^E^NU za#hv>tRhLtK$W$<$PuIlMj^GmSl9#xMpj6@{{s3S{%mCiYzh%ZEKf9Xa;3*j?FM6g zKr{q#yvqsT>YufsmOZl-Vry+k5WG%9*CE=q&C2*3YdmzG3GSzuORayHX7<^dSHG!= z%fFQiJB`LH)t4JddAIWYm5;l}d~^Ny*oX)o=veneHOD_F1(xA&1I*O}NN=!)X#h(} z!zx&qR`BT9uFJz$`V(B4`s)muT8&$OBlS|Wu{-n^p7v0wpzKo@5E3YOKL zb4TpCJK-0pHmlntkAaT9b#+)3@V&Ee3tbxu0#M0G&Qu)I`O+mU3wH1+CNYGF&VFEi zz)kpZRs2xLnET^MGM7Pt@%7d~#R6YUoZh9`2!Qg~@w&{1V{jr$A!3%B;pR+x060h! z2Iif!g@vwjgmDQF$Gw~|zWq&o+>}GzG8*L1M=DtA+KVqc%gUQB7=eD)QHd5kx=pm? z;>{2e9tDs^+k&=4%sFY4E!LlGcXfsKj?P!MxpKBqRkokSVIKy9GPQQL#(&Gv53VeLDzDey}XN2*@HokEkR!ZSV%cK3J zK=u~Dd*~MViN(V3ciakV@ETSQvw{RKPWII4nd$ zLKGRWaU-(sle~p)`Aed6&TwhnxH+O70eiU@_Hr#ZBtc`0i{008BP`i}qy104jIxRWrCMbqyD-7=OYyZd^>}N53fgQZ%?^*U+5!a^GNV7E72;9Agf36lo{}2;q`t@Kc$s}IS@b4#i z_l`dJPg_tTY(7P-| zxDSAg79xxOf;7m%cZg!oT6R(0ANapX_m?A(Zladv|y_v#)>Ke%G&zLn44|XpKb-?sM@n4?!XN zU}xV@>(V{}Y!+RBd^E~w6yKF4oOlr#*);iL3UzCvO*wQ(QzgW#<>6y!cmeR9Kvrox zP}RY#&b3@9RgPgHOilmDyS>wxws1IAT>p4HUt|o^w%k@{e|T{*!=}>70u(ZJej;*O z{a}dAq2>`{%_-B`Z}nXth=?+fSapgUNhsbZCSKlEyRIA{9AL)6#*zpEgH8Hx zW?PG-i>ZXr_5Qihqs?Fnw`{gLWm_GzPb@1t3`Q&gCKw5B?A5x1$meqA?$Bp3%5 z|1~%wH+7#rNr-ZOo3FqZ&MZW#At5X1+nqh=qXUc!jYjMBlenmRPw7t8oYjAu$dx4f-F9^pz`;MNia6t_X~WK zMzxK2zR4W7u4C8AuI$97h(ku->hJG|sA#B2`L3lYyD5LG zaC;!cv+wn5T{6z()1#LTlGoK8b?r%%x56R7|5fF9MCuGl9knGcCp-D`N9*yT-qo#5 zl1|9zIPtKUr200B&>&IOgde2L?c45mpMuTwMY>J3r{HVPnXVL6J4|p47GZ;Tha;My z4YmA5o{4%K$>7+lcq(DA`OVVXW_|=iM0GYTJLAA$%&M8~>qn(nCIZAOo>(LRqUqr} zg{PBhoO90P+z~;pUvgu&Aukr1}w0r(;)0J zME4+ea=XbE=~-wlB6=n!*Huq2*eya^K~65fO4Va#cL)&uiU33ss%29e->%A4YT9pUUU<$)*@S6J}td z8eUquyKiJM>CkH8%S$X&S)P4c*RPKDJ1XXUsx+XqiO&b3Q}l`G&{5zpPb+4KiX#3p zKgfTSWX;D3J(t>+7e;%1Lf39uUsSpF`(wrk9Gp468480L(`d_irR#Cdo${v+I5uT$ z1scD`JNR@>u?J+zn{@jWA0tjiPHjR-Obm;x|-XrS8WJ0YSGTB7XLgGvzc)XTLhUxYHPTUrt#gT-ImON8X@ z5b3o&=F=&(+Opje%bp#k3IS)1?Jwrjd}%5zE^(n3u0@eH;!N`X!ZSY>ann)-=lqP4 zAJ0J&<4u=dLHto+eoCC3{(SMqzFzEmX|oS2`_kp};qEN6f6JJZs9n)6qJOx$@csRE z3?a%_e*S6F(32rO|0{zo=FiIW#YM~u0kp0uDJh+o%9nM-JpqE+u!BF;5VY9tzowIh zhKAj1Z-wmhd*w~Oly2`la3Pv6E*cJ!H+x@lJ(J*tCsZ!|cq$VQ_&r%y$3M64SY}o4 zr=c<45AD`M_;n?qDLnZghRPcsk zt)fOXTY$SSJ%g;|%iFnLtj~SHoJLuYPrN|2#^dwUj>}30v&P34LRV^TZm0cIyCqg8 zKVA~V8HbfwNsR0>eC2$fV;HcqJMyIv{*xK2>~&zk*!<6I(OdcaVTFcl6&1|;+TM!_ zosfZnS-X2q{0Cxj3)?94F=e%TpN)>znz(my3Y=nZbo6fS#p)fNUNT5MfsJ~23$!gG z@Vq`L{e^3`AV~~l?Cq6wIJVL&DV2LSHv3c}jii62o?4d%Q-`z~GZH$7C!`D)nT_*Q zsmaRf5`uV}O^~=fQZ!3HAytS1s+T}U@2?Gq7$Nojy+?=2Z5|G);nVkBLtv*R?6dhvqw!mcjx$B$HGSY=err zm3ZN~S$Ps;K>MeFq~ta}rIj#_p%+t#IJt@n2~Wyq7f8uGs0ihvRa(Wkc2X)yrh0`Q+YtzO$ z#(s!&%cR^7o@%u4=CCum4wv!rELp+o&1|F*JQB~+jU zA3oqGdYl)?R~i)!^^EO+imImHD^_}K!%^sw1^1JNbfw$d8*eqW<(V~e4XK;`VT4N( zS%tow04lwdtQI@DhNr}nz!%RpL(57s%TDULMZ(l5(em#nu71dHt6b5LP z>tVv(Tsp;0_(x1{!)a-ca#)n=#lnfd?tQyKn7R{KD4?V~iri#21=pP$zw?=VBN6;f zQ+9dY)P1SB8bkg?HU|@ZWn;3|!tzuHV(Lhen&!t`%hNi?mk=Q1>Qdre(T3YXRr4`- zU5aTh(i)kfZwH7Wpbq_Qdsc)|_;GPz75;G0o69f0x`H(LmA1r@*;yji=LA@L68_r) z`@P9PO*K&}oS)VkKf+JeP)%^Xz}Eo+AJ-aQsKjhMaEkhH1LS1yOj#R}fBj7TEuu<3 z5v<3UghObNlCK!}C+FJRsqt5_QFU%A!QYJmTthQjh{eU@DA(1~s3q9`)OTg0mA>nH zpvVS#B-3O_49rV_y?~J9N6*%2Bm4^Y8)K^I4_(~21*A}?6rF;%avzYx!MrH0%TL=W zjim>4GTY(jK5NiN;rbqJb;c)F@H4_azYv$M0$whP!}bFPvA zAwwwaa0@%=w9T1nA~hE*h)>73*7<{{9$HRsaaDLViZVA_VNV32YYdhyG`t&(FJcXR zR!V(qJ5nZUiRe;D;_>mLr~c?f#JYp){O@w?HULCU8X(_s)X0erZPk6gC6I3r7YgoP zd~9rBRZ9z^*@8{<;S?t+IlG~-raPE}b0l#s(W-t~1=0O#%1+aJ{;4nGCd_8gIY`fN z0TEa@oQ(khyCcyeHt<>=T}WKH2nvx-|=_xJaYszTeQHmsFHtl}J-+j-mX zV89nnexLeTk)vkkiX45u`!MVCHK}gNMdkAH(}H{lVnrcOzi@x_@c7sm!)0e&U_6`u zvA=F-tw-`54=>lF6yV%bJuB+F1&B^XIa->XF!mmwrtamLYLjH3T2!;NT^de`r$EfA($ucTV8^W-XDgWVw)2&@;UH5oJr0F3 zWo=B#>F&dz*a^Z7xmN>Gqq5U2U^whZGun@pY6N!+z1Y8nJjqJd^s@vk5vi8Wj!V0L zztY_6Qvd?+?^a4{9KB{Nqg`BG+sQuDaMye8#66^g%rRe@qpEHwYpVXrOBXpR{+U{o zK!SD4QJWFYtg;06Q?_KFdQpu{0!C!FpgD~xuL}b&jsmNxh8tfVPXCg1Md}k432Ser z3p$C9k9Pvg93AfuPdmM?*AH)Og!APoIE*XQL4mZj6l>7ogMv6`~#2Eb8CSb#APv-AxA+ zoEx%L5|M8;uB?F4IdLjLvohL8{ECDSHJooH4dKMwx78O8QRfj^;-!8+3FV6t#T6XH zJ}9I4n!TviZc+x(QNxlhtWAiYzNfxkM5*CGmH1dsl6~a7)w;~O85UC0j#jxliZBac zSVWmbxu8Wu@Y@tfGdn~k*T zI3_@S7w$a{B2=FQdlLRCR~-kvzbq$}#((DuAed}!d>4QbEJA@(|K*Db?_^%?^|bFK z5K_=kTztvOJI<2LYn$+}5YozO8$rg)ew$TNHs}d zW~wbPoX(RRYQa|=Mp)}k441`H;_I{|xniYC{^lTTOtC(9|9nI%ac)AG_HTFMnfJ40b zIL#0)h`K5K`vlsGrTFk7QFPRGx2&|R^J(8=!P2ZR)#!lI0+Wa`#LCK{2dvP&Xn`BtWC?)KUJN6S!%jzq{- zBGpA1EBaPWqi!Y1oB%n(2z&7uXDr5)1@WXJLIOm1Nkk-6u;N)xeSh-;=xk!yB#xEC zP!kgy1cA(qmbi9B(Vlx+f{{MKY?&rv`UBFn?!?4In&yFXZJ(Y~JV%*3J8AyfDtC8x z>A9k>+pWxD+1CT&Yc5U7Jpx+vG&ExekX>Ty`?$+CXu9oTRM+IY7kKyi(^sHk> zzoSFm4yMj%5NYWw(HQl^12kd{^23)5L+$uf)HKAvoOiT%n|;H&&Ax)~_6UoLA@QF+ z?q`olqAX{0HNM{-r*~a?gCrAA#YY{5B+;j?)zcI>MgbLV<_1aDkVm)G#BWiZNI-`F zG$p!=5|S;-;lQI&ue8JD*?Kn>0Z~Kvcy6~ZeQV93zP;h$R}dpe%)5_JJU~oDevAF$ z96B>QE2T(1!{_TgLBR+u7EF$1JsOo)6?z73h}S^I8q@_Ql$Z6zjhA1h0m!L&K@E2| zfjP7}f5ynvkOf|YZs;|rsHi4AaHoba(U8@#j1ccb^_8B;kzv6moBD=9_gh+0e=tPO zOW!if41e9Y-v%TaPH2+Z275HzE%Jv?3sJ}7Y~1tMAQcrix@HxigO0Z2e)wMI!n~4nm2Ncm?!)>Afi)4 z4nY}(*ZnplLBgwkZor+8?vnM4vDZ zceN;>+y+@A_CCxSpI@-^m?2P6rw)3EF9@n_sKLvne@U*=hB(|7+Z{n~>E;mvr81>OVP5<+Qpl z-#H99J-sfTC2N|F5p9v6?_mIXRG=1yhvVSmsV5N_UG#22Daq?cj0!F6Dz~r_SWQKk z-xQ&%E)eOOel0A-TM!ZQ{Y?3A!4CL{6{L%w&M(x={j1LN`cFPZhfJG*T$x02cJ>9w zyrl~BCfyz=TsmdsW=oQvJz7De$k4J3lidP`cO50~l)!S}P31hZc5ViT74z>i*iFk~ z%ud?;pSqVDPcup?w_UoPU$4kB93wOg0uOJ-;mDFyZS)~**qfiZlKAVY&Pp`=H%w2e zI;>CRb8^i7+&t8!f9iGqCm08|Opxl7^$A#o;5fbOJ3hm*GBJsY8!cvOEt>G|t}b_q z679du1Q$;!%?NyP_ngF}0pbuHhXB^uNawEqG4VD^ebUxbZ1q54w$0>OG`6L&T=Al!A`YUw9iAwPg8? zuEnj^G-Z?G!bq7He*%USJRK4A7*E?S6>##HV2<`z(i_XBkCH+;+@VNi{oEf7`8p0J z>&lV#b_+h6y;M*4#X?7d0UDR&gC6-?qtT~galm61C0SbXL>~|(LhD**lp-5igZtDD zd8@qkYd(l+K(Iv|7xjS;J2FhA`?GrKtm4s9`-$HdIx(z0+AT~^ocNOPjaIwKu94+| z=i_pN>8C@U8+rRGFD83M1n|uj28odigQH^DEWE{LZ?Aw_{j#(#BCA)Cnsvt@G*9+) zpC)SHtOs6wJR0{-sl}=~ylC>xJ}O|pPquoZx;krp^#L|5|0=#ZCwUJl-XChpW#q$V zq_a$kK5ri`+^4t;1Pio1Jamlr6?1&wh!d2L!&+-uTul32)OQWGmtS?2SoMls-JqC& zy?BwkW?N^}(Sdn1_Z-JxPT0Dkq8#&iAKq0gxeR038POmUd{n^TNXBWuV-i?SVw#)m z3H;Osz-Vj_z;6uxE6c!Mx`5BB#CyMG)&i6DC?c4SPBZx>9#rzu3;Lljm>|^x=#C~W zAWhh? zVQ{O+_yIH#-uN&yNT1_puZ^w+-k*fDY_&~Qk_upe{TB59%$vV(-idn! zu6miA-C6w|x^Nt`aCeW<`<{mcRm*zsE#@IR!}G>G=MPv#SIHI?$c_ZskAKovwGQi< z@Sy<+*7_;fZ3%y2;}DIZ^%tKXt(HWg`}kA}h)}J>|4&n;JQz#5v}HjNZkjqV-n ziwyhw2Lg7^9G(Cq=IJF>&zFE^Dc@Q8lXaB?n} zJHf~Co}YvNR0GwzC4?4`ciA7GGg)XNfea$}8J%B0=}{4l_+yRhrkPA+Mf1IHrrJ;0 z2ksl%=@8QEjz?sPLz53RF%#KO@Ln&jIE?qEq_o9leTa!+>e({r7@)yzi^uU)?@dW z+cD2hqXf5C(ewQgE2wE z^QQ?g5EEJ1RsBbW{qNxBy@V!-%4Ng9;RW(lJ_lFLPde@GRbw;OUPLsxvx8I{26{B4 zG%xahWMq6h%RW4uEG6(PGB{ki=JZ0Bmf6V6+&{rMA*L*I`Y-{#=Za&>`eI^`_viA% zhl>%~mp;;`$NuzsD9Q#2=mec>1nxIO)6@-b%*G7sdIM`ix`Sx#W5Af9lYC^cT16$y z=?OljYYo|xsjAynCts{Vr2f~B#ifSz=v>aHxphI#->;G3z9W|4F9&^2 ziw*dCU9Rig$hIiy0!?*J4-2bic4c5?+uhAw{Y*!{;yI2^SrKl))4qMZG3;E-6PfYB zdG3ZmW}{ts#Dq5)KJ_vMGlvkx$C9G!Q_*AxhVAb#cPsKwKhW@MrO@}TZu?`&q?id1 ze;v58Et!xnv1CsLdVaZXDT&P!k-1%FhJWdbEG&quJ*#?Cn{su{Y56se3WqgbcAhvsEh=DA2z-)uoYXpUVAQqzn zZ~TW)rMa8w2bLS)_o1QaM}llErx$x0OmiX)O--v4*n%}EFGe@ND>kdKBohki%+BiI zlafxfcYFK|4USO5u*o}G4u(e#vFp>e*y8@!0)<%0TgwIL`}KEGKKthcpLOE-L?}Cq zE`d-2+5QgzEQIj49@XOl7s3aX$Ym%C-bV!;{7+9?E7^yblM3<@;R0rBRmUGg;I{$J zX&rXA`2bNaO*B~_BHp=hre8oD?k@R$0?bI-3d8CaQgUw5WvtWHS&w=PK>8j%V-m2+ zcyo8Tn|spHIT(-R_mAl4XnSpTl&&I->*hDELfKkYV5*eo5@s)N%;qCNt_u}n=a8|WB9;hB~ol>aeK4x@*#@Pun56G&V z+4nM@+8}Ya&mH&%2laNZSqee3`{|~XX%-b%51K1FU5 ztTPwN;F8>p+)$E}*Sl_?*)=P^des>DvK(p-JBLrEH8wR{@R0zu3!tmtqMWtn{v!9R z;48_f&C<|N=gV%e!1-Q z4>ThHQzPc^pCV_cc1z$L!%%e(Ew>ZZliLS(sW1#9%=P?j&_p$nk`w$#C(w*n1hZ)o zTN_W&pY6>?y$vfcRn?@;@(D#z@tjqkkL9!KrK4k6O|FFgwR5iYFcQuJ`tia&u_T5B zlh5vP47rR2qr7aSItI?&>84_FFqM{t0k_Hf>z7&Uc_?(VW7_1Ot~6C=C)XP*HZvOy zD_e8$C{ud9Oth@!db9km^?8xXEl_e;uk#|L@kHe;5(VvL@NiM*XH`aQlec13$=9SZ z^}$oC&_!BibQ=p-#6gas14hLRjc8*y{< z^C~`GadmaI!kq!7a5`d(pV6X|M64tG(_beNc3n^x&Yw45Bk_wW_^JEABupu)TBRi= z9m4)smE=sRF~^>c2ozjQtj%ObfIzR zAzx9ifkvYf=QW2E4`Ugo02}xbc9jwH48SN0CR~98Fn|Tlo%wZ~$6zvex1b|m_&mhf zt~6|vFP)yc^AL-X9h;z{Q?pqYXtv4^Nca+}+L2P!s_+Q^oSA9UtC$^+@ciJiLQb#pP{zhrFj78te+U3~7N&xfpds$-w;E z5)b2IH##3Dc2>jR99g^IYwrYCnfTw1>vo&JrmV~^tanowwtxa9N0S>vRXY>{=`M)V^BQ(Q4yTu9RLOAblQYJ@G+_&H*>O`6~+6qtU$)JKd?BV>eyq~ZBt zhn!qe2kbK;-ID{YFFzYk;eF@h{hZx;Z}GW4d}w?)Xv5kMWnOI6?zy76+?e%Z#ne>j z#M~0dRKoFioVJj27LxZ#@W|TwtMpRC#sMR=>}euwD~qeKu@rLYOHmhm@u&xZOw7k_ zuTA=WMaKJ?%4>>v|HjGbw(AiiXkm4=b8Y)9nqT1A@u7`m>DMA59rs5wMA+#6&f>~3 zI|$(R#2-t_6!sj5wN4uHu3M4zV>s}EUP`_5xxRRI#%Rj)tW~46M43}m8Y|xi)GJoZ zDLyxn3=h8VET9;)dHV(ObalBvGPLdSD1!Ce$!A?>)MsXP&~Fs?9A&gPy}KSO*_qFR z&1v?-UeZKb=(QnAo+CsN-jdy~OVxJUa>^DK!M#x?O+mowW;Xy)fNOQlAzJA&k(ikA zq?rrc5~+6t?LrZF5*vg0H-v3s7nXriN=H7CbsvRxu9n+IK_C0vNJy^G$5;n>1G$n8 z;ctOAW$6=gRvB?uYN@L)QWxmqnKraI*gW?YQktbasyx.submodelrepository-http basyx.submodelrepository-backend-inmemory basyx.submodelrepository-feature-mqtt + basyx.submodelrepository-feature-registry-integration basyx.submodelrepository-tck basyx.submodelrepository.component basyx.submodelrepository-backend-mongodb diff --git a/basyx.submodelservice/basyx.submodelservice-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/DummySubmodelFactory.java b/basyx.submodelservice/basyx.submodelservice-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/DummySubmodelFactory.java index a2f38af38..15ebd1d82 100644 --- a/basyx.submodelservice/basyx.submodelservice-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/DummySubmodelFactory.java +++ b/basyx.submodelservice/basyx.submodelservice-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/DummySubmodelFactory.java @@ -33,7 +33,9 @@ import java.util.stream.Stream; import org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXSD; +import org.eclipse.digitaltwin.aas4j.v3.model.File; import org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes; +import org.eclipse.digitaltwin.aas4j.v3.model.Property; import org.eclipse.digitaltwin.aas4j.v3.model.ReferenceTypes; import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement; @@ -100,8 +102,10 @@ public class DummySubmodelFactory { //SUBMODEL_FOR_FILE_TEST public static final String SUBMODEL_FOR_FILE_TEST = "8A6344BDAB57E184"; + public static final String SUBMODEL_FOR_FILE_TEST_ID_SHORT = "FileTests"; public static final String SUBMODEL_ELEMENT_FILE_ID_SHORT = "FileData"; public static final String SUBMODEL_ELEMENT_NON_FILE_ID_SHORT = "NonFileParameter"; + public static final String FILE_NAME = "BaSyx-Logo.png"; public static Collection getSubmodels() { return Arrays.asList(createTechnicalDataSubmodel(), createOperationalDataSubmodel(), createSimpleDataSubmodel()); @@ -129,6 +133,18 @@ public static Submodel createTechnicalDataSubmodel() { .submodelElements(SubmodelServiceHelper.getAllSubmodelElements()) .build(); } + + public static Submodel createSubmodelWithFileElement() { + return new DefaultSubmodel.Builder().semanticID(new DefaultReference.Builder().keys(new DefaultKey.Builder().type(KeyTypes.GLOBAL_REFERENCE) + .value(SUBMODEL_TECHNICAL_DATA_SEMANTIC_ID) + .build()) + .type(ReferenceTypes.EXTERNAL_REFERENCE) + .build()) + .idShort(SUBMODEL_FOR_FILE_TEST_ID_SHORT) + .id(SUBMODEL_FOR_FILE_TEST) + .submodelElements(Arrays.asList(createFileElement(), createNonFileElement())) + .build(); + } public static Submodel createOperationalDataSubmodel() { return new DefaultSubmodel.Builder().idShort(SUBMODEL_OPERATIONAL_DATA_ID_SHORT) @@ -254,5 +270,19 @@ private static List createSimpleSubmodelElements() { list.add(createProperty(SUBMODEL_ELEMENT_SIMPLE_DATA_ID_SHORT)); return list; } + + private static Property createNonFileElement() { + Property simpleProperty = SubmodelServiceHelper.createPropertySubmodelElement(); + simpleProperty.setIdShort(SUBMODEL_ELEMENT_NON_FILE_ID_SHORT); + + return simpleProperty; + } + + private static File createFileElement() { + File simpleFile = SubmodelServiceHelper.createFileSubmodelElement(); + simpleFile.setValue(FILE_NAME); + + return simpleFile; + } } diff --git a/basyx.submodelservice/basyx.submodelservice-http/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/http/SubmodelServiceSubmodelElementsTestSuiteHTTP.java b/basyx.submodelservice/basyx.submodelservice-http/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/http/SubmodelServiceSubmodelElementsTestSuiteHTTP.java index 8d0bdfff9..a05f013d6 100644 --- a/basyx.submodelservice/basyx.submodelservice-http/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/http/SubmodelServiceSubmodelElementsTestSuiteHTTP.java +++ b/basyx.submodelservice/basyx.submodelservice-http/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/http/SubmodelServiceSubmodelElementsTestSuiteHTTP.java @@ -66,7 +66,7 @@ public void getSubmodelElements() throws FileNotFoundException, IOException, Par String requestedSubmodelElements = requestSubmodelElementsJSON(); String submodelElementJSON = getSubmodelElementsJSON(); - BaSyxHttpTestUtils.assertSameJSONContent(submodelElementJSON, requestedSubmodelElements); + BaSyxHttpTestUtils.assertSameJSONContent(submodelElementJSON, getJSONWithoutCursorInfo(requestedSubmodelElements)); } @Test @@ -74,7 +74,7 @@ public void getPaginatedSubmodelElements() throws FileNotFoundException, IOExcep String actualPaginatedSubmodelElements = requestPaginatedSubmodelElementsJSON(); String expectedPaginatedSubmodelElementJSON = getPaginatedSubmodelElementsJSON(); - BaSyxHttpTestUtils.assertSameJSONContent(expectedPaginatedSubmodelElementJSON, actualPaginatedSubmodelElements); + BaSyxHttpTestUtils.assertSameJSONContent(expectedPaginatedSubmodelElementJSON, getJSONWithoutCursorInfo(actualPaginatedSubmodelElements)); } @Test @@ -453,6 +453,10 @@ public void invokeOperation() throws FileNotFoundException, IOException, ParseEx BaSyxHttpTestUtils.assertSameJSONContent(expectedValue, BaSyxHttpTestUtils.getResponseAsString(response)); } + + private String getJSONWithoutCursorInfo(String response) throws JsonMappingException, JsonProcessingException { + return BaSyxHttpTestUtils.removeCursorFromJSON(response); + } private CloseableHttpResponse requestOperationInvocation(String operationId, String parameters) throws IOException { return BaSyxHttpTestUtils.executePostOnURL(createSpecificSubmodelElementURL(operationId) + "/invoke", parameters); diff --git a/basyx.submodelservice/basyx.submodelservice-http/src/test/resources/SubmodelElementsPaginated.json b/basyx.submodelservice/basyx.submodelservice-http/src/test/resources/SubmodelElementsPaginated.json index 2b58e8e58..88c35a6ee 100644 --- a/basyx.submodelservice/basyx.submodelservice-http/src/test/resources/SubmodelElementsPaginated.json +++ b/basyx.submodelservice/basyx.submodelservice-http/src/test/resources/SubmodelElementsPaginated.json @@ -1,6 +1,5 @@ { "paging_metadata": { - "cursor": "U2ltcGxlTGlzdA" }, "result": [ { diff --git a/docker-compose.yml b/docker-compose.yml index cfb37a409..b622eeeea 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -73,6 +73,20 @@ services: condition: service_healthy networks: - basyx-java-server-sdk + + aas-registry-log-mongodb: + image: eclipsebasyx/aas-registry-log-mongodb:latest + container_name: aas-registry-log-mongodb + pull_policy: never + ports: + - "8050:8080" + depends_on: + - mongo + restart: always + environment: + SPRING_DATA_MONGODB_URI: mongodb://mongoAdmin:mongoPassword@mongodb:27017 + networks: + - basyx-java-server-sdk networks: basyx-java-server-sdk: diff --git a/pom.xml b/pom.xml index 14c59ce74..76be5264f 100644 --- a/pom.xml +++ b/pom.xml @@ -324,6 +324,11 @@ basyx.submodelrepository-feature-mqtt ${revision} + + org.eclipse.digitaltwin.basyx + basyx.submodelrepository-feature-registry-integration + ${revision} + org.eclipse.digitaltwin.basyx basyx.submodelrepository.component @@ -501,6 +506,11 @@ basyx.aasregistry-client-native ${revision} + + org.eclipse.digitaltwin.basyx + basyx.submodelregistry-client-native + ${revision} + @@ -578,6 +588,12 @@ ${revision} tests + + org.eclipse.digitaltwin.basyx + basyx.submodelrepository-feature-registry-integration + ${revision} + tests + org.eclipse.digitaltwin.basyx @@ -646,6 +662,12 @@ ${revision} tests + + org.eclipse.digitaltwin.basyx + basyx.aasrepository-feature-registry-integration + ${revision} + tests + org.eclipse.digitaltwin.basyx basyx.aasrepository.component From c044262580eed9af95c47c1506e1591ec3a95f05 Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Thu, 16 Nov 2023 12:20:57 +0100 Subject: [PATCH 12/21] Minor fixes related to docker for CI failure Signed-off-by: Mohammad Ghazanfar Ali Danish --- .../RegistryIntegrationAasRepository.java | 2 +- .../basyx.aasrepository.component/pom.xml | 17 ---------------- ...RegistryIntegrationSubmodelRepository.java | 2 +- .../SubmodelRepositoryRegistryTestLink.java | 3 +-- .../pom.xml | 18 ----------------- .../application-integration.properties | 2 +- .../src/main/resources/application.properties | 2 +- docker-compose.yml | 20 ++++++++++++------- 8 files changed, 18 insertions(+), 48 deletions(-) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java index af7ff4e5c..02494b4d0 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java @@ -142,7 +142,7 @@ private void deleteFromRegistry(String shellId) { try { registryApi.deleteAssetAdministrationShellDescriptorById(shellId); - logger.info("Shell {} has been automatically de-registered from the Registry", shellId); + logger.info("Shell {} has been automatically un-linked from the Registry", shellId); } catch (ApiException e) { e.printStackTrace(); diff --git a/basyx.aasrepository/basyx.aasrepository.component/pom.xml b/basyx.aasrepository/basyx.aasrepository.component/pom.xml index 0be146a76..eb586e7fb 100644 --- a/basyx.aasrepository/basyx.aasrepository.component/pom.xml +++ b/basyx.aasrepository/basyx.aasrepository.component/pom.xml @@ -13,11 +13,8 @@ aas-repository - aas-registry-log-mem:2.0.0-SNAPSHOT http://localhost:${docker.host.port}/shells - - http://localhost:8050/api/v3.0/shell-descriptors @@ -156,20 +153,6 @@ - - aas-registry - - ${docker.username}/${docker.image.aasreg.inmem.name} - - - 8050:8080 - - - ${docker.container.aasreg.inmem.waitForEndpoint} - - - - true diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java index 28f8862c5..b6601b60d 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java @@ -181,7 +181,7 @@ private void deleteFromRegistry(String submodelId) { try { registryApi.deleteSubmodelDescriptorById(submodelId); - logger.info("Submodel {} has been automatically de-registered from the Registry", submodelId); + logger.info("Submodel {} has been automatically un-linked from the Registry", submodelId); } catch (ApiException e) { e.printStackTrace(); diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java index df6a1ed21..aad3b9e01 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java @@ -48,7 +48,6 @@ import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Reference; import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.ReferenceTypes; import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.SubmodelDescriptor; -import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.RegistryIntegrationSubmodelRepository; import org.junit.Test; import org.springframework.http.HttpStatus; @@ -65,7 +64,7 @@ public class SubmodelRepositoryRegistryTestLink { private static final String DUMMY_SUBMODEL_ID = "7A7104BDAB57E184"; public static String submodelRepoBaseUrl = "http://localhost:8081"; - public static String submodelRegistryUrl = "http://localhost:8050/api/v3.0"; + public static String submodelRegistryUrl = "http://localhost:8060/api/v3.0"; private static final SubmodelDescriptor DUMMY_DESCRIPTOR = createExpectedDescriptor(); diff --git a/basyx.submodelrepository/basyx.submodelrepository.component/pom.xml b/basyx.submodelrepository/basyx.submodelrepository.component/pom.xml index a996f2579..da656eaa7 100644 --- a/basyx.submodelrepository/basyx.submodelrepository.component/pom.xml +++ b/basyx.submodelrepository/basyx.submodelrepository.component/pom.xml @@ -13,11 +13,8 @@ submodel-repository - submodel-registry-log-mem:2.0.0-SNAPSHOT http://localhost:${docker.host.port}/submodels - - http://localhost:8050/api/v3.0/submodel-descriptors @@ -162,21 +159,6 @@ - - submodel-registry - - ${docker.username}/${docker.image.smreg.inmem.name} - - - 8050:8080 - - - - ${docker.container.smreg.inmem.waitForEndpoint} - - - - true diff --git a/basyx.submodelrepository/basyx.submodelrepository.component/src/main/resources/application-integration.properties b/basyx.submodelrepository/basyx.submodelrepository.component/src/main/resources/application-integration.properties index 322f30647..a9a91780d 100644 --- a/basyx.submodelrepository/basyx.submodelrepository.component/src/main/resources/application-integration.properties +++ b/basyx.submodelrepository/basyx.submodelrepository.component/src/main/resources/application-integration.properties @@ -6,7 +6,7 @@ basyx.smrepo.name = sm-repo basyx.backend = InMemory -basyx.submodelrepository.feature.registryintegration=http://host.docker.internal:8050/api/v3.0 +basyx.submodelrepository.feature.registryintegration=http://host.docker.internal:8060/api/v3.0 basyx.externalurl=http://localhost:8081 #basyx.backend = MongoDB diff --git a/basyx.submodelrepository/basyx.submodelrepository.component/src/main/resources/application.properties b/basyx.submodelrepository/basyx.submodelrepository.component/src/main/resources/application.properties index 5a6d58449..1656e4e7c 100644 --- a/basyx.submodelrepository/basyx.submodelrepository.component/src/main/resources/application.properties +++ b/basyx.submodelrepository/basyx.submodelrepository.component/src/main/resources/application.properties @@ -4,7 +4,7 @@ spring.application.name=Submodel Repository basyx.smrepo.name = sm-repo basyx.backend = InMemory -# basyx.submodelrepository.feature.registryintegration=http://localhost:8050/api/v3.0 +# basyx.submodelrepository.feature.registryintegration=http://localhost:8060/api/v3.0 # basyx.externalurl=http://localhost:8081 #basyx.backend = MongoDB diff --git a/docker-compose.yml b/docker-compose.yml index b622eeeea..dab2a54d4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -74,17 +74,23 @@ services: networks: - basyx-java-server-sdk - aas-registry-log-mongodb: - image: eclipsebasyx/aas-registry-log-mongodb:latest - container_name: aas-registry-log-mongodb + aas-registry-log-mem: + image: eclipsebasyx/aas-registry-log-mem:2.0.0-SNAPSHOT + container_name: aas-registry-log-mem pull_policy: never ports: - "8050:8080" - depends_on: - - mongo restart: always - environment: - SPRING_DATA_MONGODB_URI: mongodb://mongoAdmin:mongoPassword@mongodb:27017 + networks: + - basyx-java-server-sdk + + sm-registry-log-mem: + image: eclipsebasyx/submodel-registry-log-mem:2.0.0-SNAPSHOT + container_name: sm-registry-log-mem + pull_policy: never + ports: + - "8060:8080" + restart: always networks: - basyx-java-server-sdk From 279dc5cedfeb8cc3633a249ca60fdfa22ff5a1fa Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Thu, 16 Nov 2023 12:33:07 +0100 Subject: [PATCH 13/21] Removes pull_policy from the docker-compose Signed-off-by: Mohammad Ghazanfar Ali Danish --- docker-compose.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index dab2a54d4..9408a3afb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -77,7 +77,6 @@ services: aas-registry-log-mem: image: eclipsebasyx/aas-registry-log-mem:2.0.0-SNAPSHOT container_name: aas-registry-log-mem - pull_policy: never ports: - "8050:8080" restart: always @@ -87,7 +86,6 @@ services: sm-registry-log-mem: image: eclipsebasyx/submodel-registry-log-mem:2.0.0-SNAPSHOT container_name: sm-registry-log-mem - pull_policy: never ports: - "8060:8080" restart: always From c58f19e9c22afab26d2618e22b66b68942f6c52a Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Thu, 16 Nov 2023 12:47:34 +0100 Subject: [PATCH 14/21] Updates Readme.md Signed-off-by: Mohammad Ghazanfar Ali Danish --- .../Readme.md | 20 +++++++++++++++++-- .../Readme.md | 20 +++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/Readme.md b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/Readme.md index a115b941d..83ff86f3e 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/Readme.md +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/Readme.md @@ -1,3 +1,19 @@ # AssetAdministrationShell Repository - Registry Integration -This feature automatically integrates the Descriptor with the Registry while creation of the Shell at Repository. -It also automatically removes the Descriptor from the Registry when the Shell is removed from the Repository. \ No newline at end of file +This feature automatically integrates the Descriptor with the Registry while creation of the Shell at Repository.
+It also automatically removes the Descriptor from the Registry when the Shell is removed from the Repository. + +To enable this feature, following two properties should be configured: + +``` +basyx.aasrepository.feature.registryintegration = {AAS-Registry-Base-Url} +basyx.externalurl = {AAS-Repo-Base-Url} +``` + +This feature gets enable automatically when both of the above defined properties are configured, i.e., no external enabled/disabled property is required. + +An example valid configuration: + +``` +basyx.aasrepository.feature.registryintegration = http://localhost:8050/api/v3.0 +basyx.externalurl = http://localhost:8081 +``` \ No newline at end of file diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/Readme.md b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/Readme.md index 3316b2588..a02c92dcb 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/Readme.md +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/Readme.md @@ -1,3 +1,19 @@ # Submodel Repository - Registry Integration -This feature automatically integrates the Descriptor with the Registry while creation of the Submodel at the Repository. -It also automatically removes the Descriptor from the Registry when the Submodel is removed from the Repository. \ No newline at end of file +This feature automatically integrates the Descriptor with the Registry while creation of the Submodel at the Repository.
+It also automatically removes the Descriptor from the Registry when the Submodel is removed from the Repository. + +To enable this feature, following two properties should be configured: + +``` +basyx.submodelrepository.feature.registryintegration = {Submodel-Registry-Base-Url} +basyx.externalurl = {Submodel-Repo-Base-Url} +``` + +This feature gets enable automatically when both of the above defined properties are configured, i.e., no external enabled/disabled property is required. + +An example valid configuration: + +``` +basyx.submodelrepository.feature.registryintegration = http://localhost:8060/api/v3.0 +basyx.externalurl = http://localhost:8081 +``` \ No newline at end of file From 14192f0ee1a1254fd51e585a3ef06dec1560d124 Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Thu, 23 Nov 2023 15:38:09 +0100 Subject: [PATCH 15/21] Sync with the latest changes Signed-off-by: Mohammad Ghazanfar Ali Danish --- .../application-integration.properties | 34 ++++++++++++++ .../integration/AasDescriptorFactory.java | 4 +- .../mapper/DefaultAttributeMapperFactory.java | 22 +--------- .../mixin/AdministrativeInformationMixin.java | 42 ------------------ .../mapper/mixin/ExtensionMixin.java | 44 ------------------- .../mapper/mixin/ReferenceMixin.java | 42 ------------------ .../RegistryIntegrationTestHelper.java | 5 +-- .../SubmodelDescriptorFactory.java | 2 +- .../mapper/DefaultAttributeMapperFactory.java | 22 +--------- .../mixin/AdministrativeInformationMixin.java | 42 ------------------ .../mapper/mixin/ExtensionMixin.java | 44 ------------------- .../mapper/mixin/ReferenceMixin.java | 42 ------------------ .../RegistryIntegrationTestHelper.java | 5 +-- ...RepositoryRegistryTestLinkApplication.java | 1 - .../src/test/resources/SingleSubmodel.json | 3 +- 15 files changed, 45 insertions(+), 309 deletions(-) create mode 100644 basyx.aasenvironment/basyx.aasenvironment.component/src/main/resources/application-integration.properties delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/AdministrativeInformationMixin.java delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/ExtensionMixin.java delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/ReferenceMixin.java delete mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/AdministrativeInformationMixin.java delete mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/ExtensionMixin.java delete mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/ReferenceMixin.java diff --git a/basyx.aasenvironment/basyx.aasenvironment.component/src/main/resources/application-integration.properties b/basyx.aasenvironment/basyx.aasenvironment.component/src/main/resources/application-integration.properties new file mode 100644 index 000000000..343f968a6 --- /dev/null +++ b/basyx.aasenvironment/basyx.aasenvironment.component/src/main/resources/application-integration.properties @@ -0,0 +1,34 @@ +server.port=8081 +spring.application.name=AAS Environment + +basyx.backend = InMemory + +basyx.aasrepository.feature.registryintegration=http://host.docker.internal:8050/api/v3.0 +basyx.submodelrepository.feature.registryintegration=http://host.docker.internal:8060/api/v3.0 +basyx.externalurl=http://localhost:8081 + +#basyx.backend = MongoDB +#spring.data.mongodb.host=mongo +# or spring.data.mongodb.host=127.0.0.1 +#spring.data.mongodb.port=27017 +#spring.data.mongodb.database=aasenvironments +#spring.data.mongodb.authentication-database=admin +#spring.data.mongodb.username=mongoAdmin +#spring.data.mongodb.password=mongoPassword + +# basyx.aasrepository.feature.mqtt.enabled = true +# mqtt.clientId=TestClient +# mqtt.hostname = localhost +# mqtt.port = 1883 + +# basyx.cors.allowed-origins=http://localhost:3000, http://localhost:4000 + +#################################################################################### +# Preconfiguring the Environment; +#################################################################################### +# Comma seperated list that contains Environment files to load on startup +# To load from Classpath (src/main/resources) use classpath:path/to/file.end +# To load from Filesystem ( On your local machine ) use the prefix file: +# +# basyx.environment = classpath:testEnvironment.json,classpath:testEnvironment.xml,file:C:\\Users\\Administrator\\Documents\\01_Festo.aasx,file:/var/www/html/01_Submodel.json +# diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java index 2a61936af..2936ec952 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java @@ -146,10 +146,10 @@ private void setAssetType(AssetInformation assetInformation, AssetAdministration private void setGlobalAssetId(AssetInformation assetInformation, AssetAdministrationShellDescriptor descriptor) { - if (assetInformation == null || assetInformation.getGlobalAssetID() == null) + if (assetInformation == null || assetInformation.getGlobalAssetId() == null) return; - descriptor.setGlobalAssetId(assetInformation.getGlobalAssetID()); + descriptor.setGlobalAssetId(assetInformation.getGlobalAssetId()); } private void setEndpointItem(String shellId, AssetAdministrationShellDescriptor descriptor) { diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java index 7488a2605..6279a8d58 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java @@ -25,19 +25,12 @@ package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper; -import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; -import org.eclipse.digitaltwin.aas4j.v3.model.Extension; -import org.eclipse.digitaltwin.aas4j.v3.model.Reference; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.DataTypeDefXsd; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes; import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.deserializer.DataTypeDefXsdDeserializer; import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.deserializer.KeyTypeDeserializer; import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.deserializer.ReferenceTypeDeserializer; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.mixin.AdministrativeInformationMixin; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.mixin.ExtensionMixin; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.mixin.ReferenceMixin; - import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.ObjectMapper; @@ -57,12 +50,6 @@ public class DefaultAttributeMapperFactory { */ public AttributeMapper create() { ObjectMapper mapper = new ObjectMapper(); - - SimpleModule adminInfoMixInModule = createMixInModule(AdministrativeInformation.class, AdministrativeInformationMixin.class); - - SimpleModule referenceMixInModule = createMixInModule(Reference.class, ReferenceMixin.class); - - SimpleModule extensionMixInModule = createMixInModule(Extension.class, ExtensionMixin.class); SimpleModule keyTypesDeserModule = createDeserializerModule(KeyTypes.class, new KeyTypeDeserializer()); @@ -70,7 +57,7 @@ public AttributeMapper create() { SimpleModule dataTypeDeserModule = createDeserializerModule(DataTypeDefXsd.class, new DataTypeDefXsdDeserializer()); - mapper.registerModules(adminInfoMixInModule, referenceMixInModule, extensionMixInModule, keyTypesDeserModule, refTypesDeserModule, dataTypeDeserModule); + mapper.registerModules(keyTypesDeserModule, refTypesDeserModule, dataTypeDeserModule); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); @@ -84,11 +71,4 @@ private SimpleModule createDeserializerModule(Class type, JsonDeserialize return moduleDeser; } - private SimpleModule createMixInModule(Class targetType, Class mixInClass) { - SimpleModule module = new SimpleModule(); - module.setMixInAnnotation(targetType, mixInClass); - - return module; - } - } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/AdministrativeInformationMixin.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/AdministrativeInformationMixin.java deleted file mode 100644 index c8bd5cf1f..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/AdministrativeInformationMixin.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.mixin; - -import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Mixin for {@link AdministrativeInformation} - * - * @author danish - */ -public interface AdministrativeInformationMixin { - - @JsonProperty("templateId") - public String getTemplateID(); - -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/ExtensionMixin.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/ExtensionMixin.java deleted file mode 100644 index 104e1b53f..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/ExtensionMixin.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.mixin; - - -import org.eclipse.digitaltwin.aas4j.v3.model.Extension; -import org.eclipse.digitaltwin.aas4j.v3.model.Reference; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Mixin for {@link Extension} - * - * @author danish - */ -public interface ExtensionMixin { - - @JsonProperty("semanticId") - public Reference getSemanticID(); - -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/ReferenceMixin.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/ReferenceMixin.java deleted file mode 100644 index 94768ab4b..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/mixin/ReferenceMixin.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.mixin; - -import org.eclipse.digitaltwin.aas4j.v3.model.Reference; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Mixin for {@link Reference} - * - * @author danish - */ -public interface ReferenceMixin { - - @JsonProperty("referredSemanticId") - public Reference getReferredSemanticID(); - -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java index 8a5b5d606..543c5c89e 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java @@ -31,7 +31,6 @@ import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; -import org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXSD; import org.eclipse.digitaltwin.aas4j.v3.model.EmbeddedDataSpecification; import org.eclipse.digitaltwin.aas4j.v3.model.Extension; import org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes; @@ -97,7 +96,7 @@ public class RegistryIntegrationTestHelper { private static final String TEMPLATE_ID = "ID2.0"; // Extension AAS4J - private static final Extension AAS4J_EXTENSION = new DefaultExtension.Builder().semanticID(AAS4J_DATASPECIFICATION).name("extension").valueType(DataTypeDefXSD.STRING).value("extensionValue").build(); + private static final Extension AAS4J_EXTENSION = new DefaultExtension.Builder().semanticId(AAS4J_DATASPECIFICATION).name("extension").valueType(org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd.STRING).value("extensionValue").build(); // Extension AasRegistry private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.Extension AASREG_EXTENSION = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.Extension().semanticId(AASREG_DATASPECIFICATION).name("extension") @@ -112,7 +111,7 @@ public static List SimpleModule createDeserializerModule(Class type, JsonDeserialize return moduleDeser; } - private SimpleModule createMixInModule(Class targetType, Class mixInClass) { - SimpleModule module = new SimpleModule(); - module.setMixInAnnotation(targetType, mixInClass); - - return module; - } - } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/AdministrativeInformationMixin.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/AdministrativeInformationMixin.java deleted file mode 100644 index a9342f211..000000000 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/AdministrativeInformationMixin.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.mixin; - -import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Mixin for {@link AdministrativeInformation} - * - * @author danish - */ -public interface AdministrativeInformationMixin { - - @JsonProperty("templateId") - public String getTemplateID(); - -} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/ExtensionMixin.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/ExtensionMixin.java deleted file mode 100644 index b5acb6e18..000000000 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/ExtensionMixin.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.mixin; - - -import org.eclipse.digitaltwin.aas4j.v3.model.Extension; -import org.eclipse.digitaltwin.aas4j.v3.model.Reference; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Mixin for {@link Extension} - * - * @author danish - */ -public interface ExtensionMixin { - - @JsonProperty("semanticId") - public Reference getSemanticID(); - -} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/ReferenceMixin.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/ReferenceMixin.java deleted file mode 100644 index 1a239a5db..000000000 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/mixin/ReferenceMixin.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.mixin; - -import org.eclipse.digitaltwin.aas4j.v3.model.Reference; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Mixin for {@link Reference} - * - * @author danish - */ -public interface ReferenceMixin { - - @JsonProperty("referredSemanticId") - public Reference getReferredSemanticID(); - -} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationTestHelper.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationTestHelper.java index 0d52c7d1b..720d22c33 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationTestHelper.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationTestHelper.java @@ -30,7 +30,6 @@ import java.util.List; import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; -import org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXSD; import org.eclipse.digitaltwin.aas4j.v3.model.EmbeddedDataSpecification; import org.eclipse.digitaltwin.aas4j.v3.model.Extension; import org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes; @@ -90,7 +89,7 @@ public class RegistryIntegrationTestHelper { private static final String TEMPLATEID = "ID2.0"; // Extension AAS4J - private static final Extension AAS4J_EXTENSION = new DefaultExtension.Builder().semanticID(AAS4J_DATASPECIFICATION).name("extension").valueType(DataTypeDefXSD.STRING).value("extensionValue").build(); + private static final Extension AAS4J_EXTENSION = new DefaultExtension.Builder().semanticId(AAS4J_DATASPECIFICATION).name("extension").valueType(org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd.STRING).value("extensionValue").build(); // Extension SMRegistry private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Extension SMREG_EXTENSION = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Extension().semanticId(SMREG__DATASPECIFICATION).name("extension") @@ -105,7 +104,7 @@ public static List Date: Thu, 23 Nov 2023 15:42:02 +0100 Subject: [PATCH 16/21] Removed unnecessary file Signed-off-by: Mohammad Ghazanfar Ali Danish --- .../application-integration.properties | 34 ------------------- 1 file changed, 34 deletions(-) delete mode 100644 basyx.aasenvironment/basyx.aasenvironment.component/src/main/resources/application-integration.properties diff --git a/basyx.aasenvironment/basyx.aasenvironment.component/src/main/resources/application-integration.properties b/basyx.aasenvironment/basyx.aasenvironment.component/src/main/resources/application-integration.properties deleted file mode 100644 index 343f968a6..000000000 --- a/basyx.aasenvironment/basyx.aasenvironment.component/src/main/resources/application-integration.properties +++ /dev/null @@ -1,34 +0,0 @@ -server.port=8081 -spring.application.name=AAS Environment - -basyx.backend = InMemory - -basyx.aasrepository.feature.registryintegration=http://host.docker.internal:8050/api/v3.0 -basyx.submodelrepository.feature.registryintegration=http://host.docker.internal:8060/api/v3.0 -basyx.externalurl=http://localhost:8081 - -#basyx.backend = MongoDB -#spring.data.mongodb.host=mongo -# or spring.data.mongodb.host=127.0.0.1 -#spring.data.mongodb.port=27017 -#spring.data.mongodb.database=aasenvironments -#spring.data.mongodb.authentication-database=admin -#spring.data.mongodb.username=mongoAdmin -#spring.data.mongodb.password=mongoPassword - -# basyx.aasrepository.feature.mqtt.enabled = true -# mqtt.clientId=TestClient -# mqtt.hostname = localhost -# mqtt.port = 1883 - -# basyx.cors.allowed-origins=http://localhost:3000, http://localhost:4000 - -#################################################################################### -# Preconfiguring the Environment; -#################################################################################### -# Comma seperated list that contains Environment files to load on startup -# To load from Classpath (src/main/resources) use classpath:path/to/file.end -# To load from Filesystem ( On your local machine ) use the prefix file: -# -# basyx.environment = classpath:testEnvironment.json,classpath:testEnvironment.xml,file:C:\\Users\\Administrator\\Documents\\01_Festo.aasx,file:/var/www/html/01_Submodel.json -# From 7ebd7d39393997985e9dab89da5bbaa8f75e8b89 Mon Sep 17 00:00:00 2001 From: Jannis Jung Date: Thu, 23 Nov 2023 18:27:26 +0100 Subject: [PATCH 17/21] Fixes minor typos during review * Establishes compliance with naming guidelines * reunions organization line in parent pom * applies BaSyx formatter Signed-off-by: Jannis Jung --- .../Readme.md | 6 +- .../pom.xml | 2 +- .../integration/AasDescriptorFactory.java | 2 +- .../RegistryIntegrationAasRepository.java | 62 ++++++++--------- .../integration/mapper/AttributeMapper.java | 30 ++++----- .../mapper/DefaultAttributeMapperFactory.java | 4 +- .../DataTypeDefXsdDeserializer.java | 8 ++- .../deserializer/KeyTypeDeserializer.java | 15 +++-- .../ReferenceTypeDeserializer.java | 7 +- .../AasRepositoryRegistryTestLink.java | 6 +- .../RegistryIntegrationTestHelper.java | 24 +++---- .../application-integration.properties | 2 +- .../src/main/resources/application.properties | 2 +- .../RepositoryRegistryLinkException.java | 2 +- .../RepositoryRegistryUnlinkException.java | 2 +- .../Readme.md | 4 +- .../pom.xml | 2 +- ...RegistryIntegrationSubmodelRepository.java | 60 ++++++++--------- ...rationSubmodelRepositoryConfiguration.java | 4 +- ...yIntegrationSubmodelRepositoryFactory.java | 8 +-- ...yIntegrationSubmodelRepositoryFeature.java | 11 ++-- .../SubmodelDescriptorFactory.java | 18 ++--- .../SubmodelRepositoryRegistryLink.java | 8 +-- .../integration/mapper/AttributeMapper.java | 66 +++++++++---------- .../mapper/DefaultAttributeMapperFactory.java | 4 +- .../DataTypeDefXsdDeserializer.java | 7 +- .../deserializer/KeyTypeDeserializer.java | 15 +++-- .../ReferenceTypeDeserializer.java | 7 +- .../RegistryIntegrationTestHelper.java | 28 ++++---- ...RepositoryRegistryTestLinkApplication.java | 18 ++--- .../application-integration.properties | 2 +- pom.xml | 3 +- 32 files changed, 220 insertions(+), 219 deletions(-) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/Readme.md b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/Readme.md index 83ff86f3e..c133b7417 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/Readme.md +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/Readme.md @@ -2,18 +2,18 @@ This feature automatically integrates the Descriptor with the Registry while creation of the Shell at Repository.
It also automatically removes the Descriptor from the Registry when the Shell is removed from the Repository. -To enable this feature, following two properties should be configured: +To enable this feature, the following two properties should be configured: ``` basyx.aasrepository.feature.registryintegration = {AAS-Registry-Base-Url} basyx.externalurl = {AAS-Repo-Base-Url} ``` -This feature gets enable automatically when both of the above defined properties are configured, i.e., no external enabled/disabled property is required. +This feature gets enabled automatically when both of the above defined properties are configured, i.e., no external enabled/disabled property is required. An example valid configuration: ``` basyx.aasrepository.feature.registryintegration = http://localhost:8050/api/v3.0 basyx.externalurl = http://localhost:8081 -``` \ No newline at end of file +``` diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/pom.xml b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/pom.xml index 43dd44f93..b331ff60f 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/pom.xml +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/pom.xml @@ -42,4 +42,4 @@ test
-
\ No newline at end of file +
diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java index 2936ec952..25454a655 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java @@ -193,7 +193,7 @@ private String createAasRepositoryUrl(String aasRepositoryBaseURL) { try { return new URL(new URL(aasRepositoryBaseURL), AAS_REPOSITORY_PATH).toString(); } catch (MalformedURLException e) { - throw new RuntimeException("The AAS Repository Base url is malformed " + e.getMessage()); + throw new RuntimeException("The AAS Repository Base url is malformed.\n" + e.getMessage()); } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java index 02494b4d0..70002915c 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java @@ -66,26 +66,26 @@ public CursorResult> getAllAas(PaginationInfo pIn } @Override - public AssetAdministrationShell getAas(String aasId) throws ElementDoesNotExistException { - return decorated.getAas(aasId); + public AssetAdministrationShell getAas(String shellId) throws ElementDoesNotExistException { + return decorated.getAas(shellId); } @Override - public void createAas(AssetAdministrationShell aas) throws CollidingIdentifierException { - decorated.createAas(aas); - - integrateAasWithRegistry(aas, aasRepositoryRegistryLink.getAasRepositoryBaseURL()); + public void createAas(AssetAdministrationShell shell) throws CollidingIdentifierException { + decorated.createAas(shell); + + integrateAasWithRegistry(shell, aasRepositoryRegistryLink.getAasRepositoryBaseURL()); } @Override - public void updateAas(String aasId, AssetAdministrationShell aas) { - decorated.updateAas(aasId, aas); + public void updateAas(String shellId, AssetAdministrationShell shell) { + decorated.updateAas(shellId, shell); } @Override - public void deleteAas(String aasId) { - AssetAdministrationShell shell = decorated.getAas(aasId); - decorated.deleteAas(aasId); + public void deleteAas(String shellId) { + AssetAdministrationShell shell = decorated.getAas(shellId); + decorated.deleteAas(shellId); deleteFromRegistry(shell.getId()); } @@ -96,56 +96,56 @@ public String getName() { } @Override - public CursorResult> getSubmodelReferences(String aasId, PaginationInfo pInfo) { - return decorated.getSubmodelReferences(aasId, pInfo); + public CursorResult> getSubmodelReferences(String shellId, PaginationInfo paginationInfo) { + return decorated.getSubmodelReferences(shellId, paginationInfo); } @Override - public void addSubmodelReference(String aasId, Reference submodelReference) { - decorated.addSubmodelReference(aasId, submodelReference); + public void addSubmodelReference(String shellId, Reference submodelReference) { + decorated.addSubmodelReference(shellId, submodelReference); } @Override - public void removeSubmodelReference(String aasId, String submodelId) { - decorated.removeSubmodelReference(aasId, submodelId); + public void removeSubmodelReference(String shellId, String submodelId) { + decorated.removeSubmodelReference(shellId, submodelId); } @Override - public void setAssetInformation(String aasId, AssetInformation aasInfo) throws ElementDoesNotExistException { - decorated.setAssetInformation(aasId, aasInfo); + public void setAssetInformation(String shellId, AssetInformation sehllInfo) throws ElementDoesNotExistException { + decorated.setAssetInformation(shellId, sehllInfo); } @Override - public AssetInformation getAssetInformation(String aasId) throws ElementDoesNotExistException { - return decorated.getAssetInformation(aasId); + public AssetInformation getAssetInformation(String shellId) throws ElementDoesNotExistException { + return decorated.getAssetInformation(shellId); } - + private void integrateAasWithRegistry(AssetAdministrationShell shell, String aasRepositoryURL) { AssetAdministrationShellDescriptor descriptor = new AasDescriptorFactory(shell, aasRepositoryURL).create(); - + RegistryAndDiscoveryInterfaceApi registryApi = aasRepositoryRegistryLink.getRegistryApi(); - + try { registryApi.postAssetAdministrationShellDescriptor(descriptor); - + logger.info("Shell {} has been automatically linked with the Registry", shell.getId()); } catch (ApiException e) { e.printStackTrace(); - + throw new RepositoryRegistryLinkException(shell.getId()); } } - + private void deleteFromRegistry(String shellId) { RegistryAndDiscoveryInterfaceApi registryApi = aasRepositoryRegistryLink.getRegistryApi(); - + try { registryApi.deleteAssetAdministrationShellDescriptorById(shellId); - - logger.info("Shell {} has been automatically un-linked from the Registry", shellId); + + logger.info("Shell '{}' has been automatically un-linked from the Registry.", shellId); } catch (ApiException e) { e.printStackTrace(); - + throw new RepositoryRegistryUnlinkException(shellId); } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/AttributeMapper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/AttributeMapper.java index 89737e6f5..f2352601a 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/AttributeMapper.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/AttributeMapper.java @@ -46,11 +46,11 @@ * @author danish */ public class AttributeMapper { - + private Logger logger = LoggerFactory.getLogger(AttributeMapper.class); - + private ObjectMapper mapper; - + public AttributeMapper(ObjectMapper mapper) { this.mapper = mapper; } @@ -64,11 +64,11 @@ public AttributeMapper(ObjectMapper mapper) { */ public List mapDescription(List descriptions) { CustomTypeCloneFactory cloneFactory = new CustomTypeCloneFactory<>(LangStringTextType.class, mapper); - + List mappedDescriptions = cloneFactory.create(descriptions); - + if (mappedDescriptions == null) - logger.error("Descriptions could not be mapped due to a failure"); + logger.error("Descriptions could not be mapped due to a failure."); return mappedDescriptions; } @@ -82,11 +82,11 @@ public List mapDescription(List mapDisplayName(List displayNames) { CustomTypeCloneFactory cloneFactory = new CustomTypeCloneFactory<>(LangStringNameType.class, mapper); - + List mappedDisplayNames = cloneFactory.create(displayNames); - + if (mappedDisplayNames == null) - logger.error("DisplayNames could not be mapped due to a failure"); + logger.error("DisplayNames could not be mapped due to a failure."); return mappedDisplayNames; } @@ -100,11 +100,11 @@ public List mapDisplayName(List mapExtensions(List extensions) { CustomTypeCloneFactory cloneFactory = new CustomTypeCloneFactory<>(Extension.class, mapper); - + List mappedExtensions = cloneFactory.create(extensions); - + if (mappedExtensions == null) - logger.error("Extensions could not be mapped due to a failure"); + logger.error("Extensions could not be mapped due to a failure."); return cloneFactory.create(extensions); } @@ -118,11 +118,11 @@ public List mapExtensions(List cloneFactory = new CustomTypeCloneFactory<>(AdministrativeInformation.class, mapper); - + AdministrativeInformation mappedAdministrativeInformation = cloneFactory.create(administrativeInformation); - + if (mappedAdministrativeInformation == null) - logger.error("AdministrativeInformation could not be mapped due to a failure"); + logger.error("AdministrativeInformation could not be mapped due to a failure."); return mappedAdministrativeInformation; } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java index 6279a8d58..a0c163647 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java @@ -64,9 +64,9 @@ public AttributeMapper create() { return new AttributeMapper(mapper); } - private SimpleModule createDeserializerModule(Class type, JsonDeserializer deser) { + private SimpleModule createDeserializerModule(Class type, JsonDeserializer deserializer) { SimpleModule moduleDeser = new SimpleModule(); - moduleDeser.addDeserializer(type, deser); + moduleDeser.addDeserializer(type, deserializer); return moduleDeser; } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java index f2d4292e8..31f1096b1 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java @@ -29,6 +29,7 @@ import org.apache.commons.lang3.StringUtils; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.DataTypeDefXsd; + import com.fasterxml.jackson.core.JacksonException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; @@ -43,9 +44,10 @@ public class DataTypeDefXsdDeserializer extends JsonDeserializer { @Override - public DataTypeDefXsd deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { + public DataTypeDefXsd deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JacksonException { try { - JsonNode node = p.getCodec().readTree(p); + JsonNode node = parser.getCodec() + .readTree(parser); String value = node.asText(); @@ -53,7 +55,7 @@ public DataTypeDefXsd deserialize(JsonParser p, DeserializationContext ctxt) thr return DataTypeDefXsd.valueOf(DataTypeDefXsd.class, compatibleEnumValue); } catch (Exception e) { - throw new RuntimeException("Unable to deserialize the DataTypeDefXsd Enum"); + throw new RuntimeException("Unable to deserialize the DataTypeDefXsd Enum."); } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java index 68b6139ca..ccb6401e6 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java @@ -44,18 +44,19 @@ public class KeyTypeDeserializer extends JsonDeserializer { @Override - public KeyTypes deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { + public KeyTypes deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JacksonException { try { - JsonNode node = p.getCodec().readTree(p); - + JsonNode node = parser.getCodec() + .readTree(parser); + String value = node.asText(); - + String compatibleEnumValue = StringUtils.remove(value, '_'); - + return KeyTypes.valueOf(KeyTypes.class, compatibleEnumValue); - + } catch (Exception e) { - throw new RuntimeException("Unable to deserialize the KeyTypes Enum"); + throw new RuntimeException("Unable to deserialize the KeyTypes Enum."); } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java index 8db4d6387..789ae7d48 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java @@ -44,9 +44,10 @@ public class ReferenceTypeDeserializer extends JsonDeserializer { @Override - public ReferenceTypes deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { + public ReferenceTypes deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JacksonException { try { - JsonNode node = p.getCodec().readTree(p); + JsonNode node = parser.getCodec() + .readTree(parser); String value = node.asText(); @@ -55,7 +56,7 @@ public ReferenceTypes deserialize(JsonParser p, DeserializationContext ctxt) thr return ReferenceTypes.valueOf(ReferenceTypes.class, compatibleEnumValue); } catch (Exception e) { - throw new RuntimeException("Unable to deserialize the ReferenceTypes Enum"); + throw new RuntimeException("Unable to deserialize the ReferenceTypes Enum."); } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLink.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLink.java index da06207df..521cec341 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLink.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLink.java @@ -90,7 +90,7 @@ public void deleteAas() throws FileNotFoundException, IOException, ApiException assertDescriptionDeletionAtRegistry(); } - + private AssetAdministrationShellDescriptor retrieveDescriptorFromRegistry() throws ApiException { RegistryAndDiscoveryInterfaceApi api = new RegistryAndDiscoveryInterfaceApi(aasRegistryUrl); @@ -171,13 +171,13 @@ private static String getProtocol(String endpoint) { throw new RuntimeException(); } } - + private static String createAasRepositoryUrl(String aasRepositoryBaseURL) { try { return new URL(new URL(aasRepositoryBaseURL), AAS_REPOSITORY_PATH).toString(); } catch (MalformedURLException e) { - throw new RuntimeException("The AAS Repository Base url is malformed " + e.getMessage()); + throw new RuntimeException("The AAS Repository Base url is malformed. " + e.getMessage()); } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java index 543c5c89e..a007fdf64 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java @@ -60,9 +60,9 @@ public class RegistryIntegrationTestHelper { private static final LangStringTextType AAS_LANG_STRING_TEXT_TYPE_2 = new DefaultLangStringTextType.Builder().language("en").text("An Example").build(); // LangStringTextType AasRegistry - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType AASREG_LANG_STRING_TEXT_TYPE_1 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("de") + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType AAS_REG_LANG_STRING_TEXT_TYPE_1 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("de") .text("Ein Beispiel"); - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType AASREG_LANG_STRING_TEXT_TYPE_2 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("en") + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType AAS_REG_LANG_STRING_TEXT_TYPE_2 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType().language("en") .text("An Example"); // LangStringNameType AAS4J @@ -70,9 +70,9 @@ public class RegistryIntegrationTestHelper { private static final LangStringNameType AAS4J_LANG_STRING_NAME_TYPE_2 = new DefaultLangStringNameType.Builder().language("de").text("Namenstypzeichenfolge").build(); // LangStringNameType AasRegistry - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType AASREG_LANG_STRING_NAME_TYPE_1 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType().language("en") + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType AAS_REG_LANG_STRING_NAME_TYPE_1 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType().language("en") .text("Name type string"); - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType AASREG_LANG_STRING_NAME_TYPE_2 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType().language("de") + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType AAS_REG_LANG_STRING_NAME_TYPE_2 = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType().language("de") .text("Namenstypzeichenfolge"); // AssetKind AAS4J @@ -86,10 +86,10 @@ public class RegistryIntegrationTestHelper { private static final EmbeddedDataSpecification AAS4JEMB_EMBEDDED_DATA_SPECIFICATION = new DefaultEmbeddedDataSpecification.Builder().dataSpecification(AAS4J_DATASPECIFICATION).build(); // Administration AasRegistry - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.Reference AASREG_DATASPECIFICATION = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.Reference() + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.Reference AAS_REG_DATASPECIFICATION = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.Reference() .keys(Arrays.asList(new Key().type(org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes.BLOB).value("BlobValue"))).type(org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes.EXTERNALREFERENCE); - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.EmbeddedDataSpecification AASREG_EMBEDDED_DATA_SPECIFICATION = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.EmbeddedDataSpecification() - .dataSpecification(AASREG_DATASPECIFICATION); + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.EmbeddedDataSpecification AAS_REG_EMBEDDED_DATA_SPECIFICATION = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.EmbeddedDataSpecification() + .dataSpecification(AAS_REG_DATASPECIFICATION); private static final String VERSION = "1.0.0"; private static final String REVISION = "3"; @@ -99,7 +99,7 @@ public class RegistryIntegrationTestHelper { private static final Extension AAS4J_EXTENSION = new DefaultExtension.Builder().semanticId(AAS4J_DATASPECIFICATION).name("extension").valueType(org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd.STRING).value("extensionValue").build(); // Extension AasRegistry - private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.Extension AASREG_EXTENSION = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.Extension().semanticId(AASREG_DATASPECIFICATION).name("extension") + private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.Extension AAS_REG_EXTENSION = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.Extension().semanticId(AAS_REG_DATASPECIFICATION).name("extension") .valueType(DataTypeDefXsd.STRING).value("extensionValue").supplementalSemanticIds(new ArrayList<>()).refersTo(new ArrayList<>()); public static List getAas4jLangStringTextTypes() { @@ -107,7 +107,7 @@ public static List getAas4jLangStringTextTypes() { } public static List getAasRegLangStringTextTypes() { - return Arrays.asList(AASREG_LANG_STRING_TEXT_TYPE_1, AASREG_LANG_STRING_TEXT_TYPE_2); + return Arrays.asList(AAS_REG_LANG_STRING_TEXT_TYPE_1, AAS_REG_LANG_STRING_TEXT_TYPE_2); } public static AdministrativeInformation getAas4jAdministration() { @@ -115,7 +115,7 @@ public static AdministrativeInformation getAas4jAdministration() { } public static org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation getAasRegAdministration() { - return new org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation().embeddedDataSpecifications(Arrays.asList(AASREG_EMBEDDED_DATA_SPECIFICATION)).version(VERSION).revision(REVISION) + return new org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation().embeddedDataSpecifications(Arrays.asList(AAS_REG_EMBEDDED_DATA_SPECIFICATION)).version(VERSION).revision(REVISION) .templateId(TEMPLATE_ID); } @@ -124,7 +124,7 @@ public static List getAas4jLangStringNameTypes() { } public static List getAasRegLangStringNameTypes() { - return Arrays.asList(AASREG_LANG_STRING_NAME_TYPE_1, AASREG_LANG_STRING_NAME_TYPE_2); + return Arrays.asList(AAS_REG_LANG_STRING_NAME_TYPE_1, AAS_REG_LANG_STRING_NAME_TYPE_2); } public static List getAas4jExtensions() { @@ -132,7 +132,7 @@ public static List getAas4jExtensions() { } public static List getAasRegExtensions() { - return Arrays.asList(AASREG_EXTENSION); + return Arrays.asList(AAS_REG_EXTENSION); } } diff --git a/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application-integration.properties b/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application-integration.properties index 3221cd8cf..95043a9a8 100644 --- a/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application-integration.properties +++ b/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application-integration.properties @@ -23,4 +23,4 @@ basyx.externalurl=http://localhost:8081 # mqtt.hostname = localhost # mqtt.port = 1883 -# basyx.cors.allowed-origins=http://localhost:3000, http://localhost:4000 \ No newline at end of file +# basyx.cors.allowed-origins=http://localhost:3000, http://localhost:4000 diff --git a/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application.properties b/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application.properties index 81f2a3530..1213f86ad 100644 --- a/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application.properties +++ b/basyx.aasrepository/basyx.aasrepository.component/src/main/resources/application.properties @@ -23,4 +23,4 @@ basyx.backend = InMemory # mqtt.hostname = localhost # mqtt.port = 1883 -# basyx.cors.allowed-origins=http://localhost:3000, http://localhost:4000 \ No newline at end of file +# basyx.cors.allowed-origins=http://localhost:3000, http://localhost:4000 diff --git a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/RepositoryRegistryLinkException.java b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/RepositoryRegistryLinkException.java index cb9127368..83f6f3769 100644 --- a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/RepositoryRegistryLinkException.java +++ b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/RepositoryRegistryLinkException.java @@ -41,7 +41,7 @@ public RepositoryRegistryLinkException(String id) { } private static String getMessage(String id) { - return "Unable to link the element with id " + id + " with the Registry"; + return "Unable to link the element with id '" + id + "' with the Registry."; } } diff --git a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/RepositoryRegistryUnlinkException.java b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/RepositoryRegistryUnlinkException.java index 2ebc53676..8532c3564 100644 --- a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/RepositoryRegistryUnlinkException.java +++ b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/RepositoryRegistryUnlinkException.java @@ -41,7 +41,7 @@ public RepositoryRegistryUnlinkException(String id) { } private static String getMessage(String id) { - return "Unable to unlink the element with id " + id + " from the Registry"; + return "Unable to unlink the element with id '" + id + "' from the Registry."; } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/Readme.md b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/Readme.md index a02c92dcb..a45b2a3b5 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/Readme.md +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/Readme.md @@ -2,7 +2,7 @@ This feature automatically integrates the Descriptor with the Registry while creation of the Submodel at the Repository.
It also automatically removes the Descriptor from the Registry when the Submodel is removed from the Repository. -To enable this feature, following two properties should be configured: +To enable this feature, the following two properties should be configured: ``` basyx.submodelrepository.feature.registryintegration = {Submodel-Registry-Base-Url} @@ -16,4 +16,4 @@ An example valid configuration: ``` basyx.submodelrepository.feature.registryintegration = http://localhost:8060/api/v3.0 basyx.externalurl = http://localhost:8081 -``` \ No newline at end of file +``` diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/pom.xml b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/pom.xml index 8c82786f5..4052ba5ef 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/pom.xml +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/pom.xml @@ -42,4 +42,4 @@ test -
\ No newline at end of file + diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java index b6601b60d..3af3a2f08 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java @@ -58,16 +58,16 @@ public class RegistryIntegrationSubmodelRepository implements SubmodelRepository private static Logger logger = LoggerFactory.getLogger(RegistryIntegrationSubmodelRepository.class); private SubmodelRepository decorated; - private SubmodelRepositoryRegistryLink smRepositoryRegistryLink; + private SubmodelRepositoryRegistryLink submodelRepositoryRegistryLink; - public RegistryIntegrationSubmodelRepository(SubmodelRepository decorated, SubmodelRepositoryRegistryLink smRepositoryRegistryLink) { + public RegistryIntegrationSubmodelRepository(SubmodelRepository decorated, SubmodelRepositoryRegistryLink submodelRepositoryRegistryLink) { this.decorated = decorated; - this.smRepositoryRegistryLink = smRepositoryRegistryLink; + this.submodelRepositoryRegistryLink = submodelRepositoryRegistryLink; } @Override - public CursorResult> getAllSubmodels(PaginationInfo pInfo) { - return decorated.getAllSubmodels(pInfo); + public CursorResult> getAllSubmodels(PaginationInfo paginationInfo) { + return decorated.getAllSubmodels(paginationInfo); } @Override @@ -83,30 +83,30 @@ public void updateSubmodel(String submodelId, Submodel submodel) throws ElementD @Override public void createSubmodel(Submodel submodel) throws CollidingIdentifierException { decorated.createSubmodel(submodel); - - integrateSubmodelWithRegistry(submodel, smRepositoryRegistryLink.getSubmodelRepositoryBaseURL()); + + integrateSubmodelWithRegistry(submodel, submodelRepositoryRegistryLink.getSubmodelRepositoryBaseURL()); } @Override public void deleteSubmodel(String submodelId) throws ElementDoesNotExistException { decorated.deleteSubmodel(submodelId); - + deleteFromRegistry(submodelId); } @Override - public CursorResult> getSubmodelElements(String submodelId, PaginationInfo pInfo) throws ElementDoesNotExistException { - return decorated.getSubmodelElements(submodelId, pInfo); + public CursorResult> getSubmodelElements(String submodelId, PaginationInfo paginationInfo) throws ElementDoesNotExistException { + return decorated.getSubmodelElements(submodelId, paginationInfo); } @Override - public SubmodelElement getSubmodelElement(String submodelId, String smeIdShort) throws ElementDoesNotExistException { - return decorated.getSubmodelElement(submodelId, smeIdShort); + public SubmodelElement getSubmodelElement(String submodelId, String submodelElementIdShort) throws ElementDoesNotExistException { + return decorated.getSubmodelElement(submodelId, submodelElementIdShort); } @Override - public SubmodelElementValue getSubmodelElementValue(String submodelId, String smeIdShort) throws ElementDoesNotExistException { - return decorated.getSubmodelElementValue(submodelId, smeIdShort); + public SubmodelElementValue getSubmodelElementValue(String submodelId, String submodelElementIdShort) throws ElementDoesNotExistException { + return decorated.getSubmodelElementValue(submodelId, submodelElementIdShort); } @Override @@ -115,13 +115,13 @@ public void setSubmodelElementValue(String submodelId, String idShortPath, Submo } @Override - public void createSubmodelElement(String submodelId, SubmodelElement smElement) { - decorated.createSubmodelElement(submodelId, smElement); + public void createSubmodelElement(String submodelId, SubmodelElement submodelElement) { + decorated.createSubmodelElement(submodelId, submodelElement); } @Override - public void createSubmodelElement(String submodelId, String idShortPath, SubmodelElement smElement) throws ElementDoesNotExistException { - decorated.createSubmodelElement(submodelId, smElement); + public void createSubmodelElement(String submodelId, String idShortPath, SubmodelElement submodelElement) throws ElementDoesNotExistException { + decorated.createSubmodelElement(submodelId, submodelElement); } @Override @@ -158,33 +158,33 @@ public void setFileValue(String submodelId, String idShortPath, String fileName, public void deleteFileValue(String submodelId, String idShortPath) throws ElementDoesNotExistException, ElementNotAFileException, FileDoesNotExistException { decorated.deleteFileValue(submodelId, idShortPath); } - + private void integrateSubmodelWithRegistry(Submodel submodel, String aasRepositoryURL) { SubmodelDescriptor descriptor = new SubmodelDescriptorFactory(submodel, aasRepositoryURL).create(); - - SubmodelRegistryApi registryApi = smRepositoryRegistryLink.getRegistryApi(); - + + SubmodelRegistryApi registryApi = submodelRepositoryRegistryLink.getRegistryApi(); + try { registryApi.postSubmodelDescriptor(descriptor); - + logger.info("Submodel {} has been automatically linked with the Registry", submodel.getId()); } catch (ApiException e) { e.printStackTrace(); - + throw new RepositoryRegistryLinkException(submodel.getId()); } } - + private void deleteFromRegistry(String submodelId) { - SubmodelRegistryApi registryApi = smRepositoryRegistryLink.getRegistryApi(); - + SubmodelRegistryApi registryApi = submodelRepositoryRegistryLink.getRegistryApi(); + try { registryApi.deleteSubmodelDescriptorById(submodelId); - - logger.info("Submodel {} has been automatically un-linked from the Registry", submodelId); + + logger.info("Submodel '{}' has been automatically un-linked from the Registry.", submodelId); } catch (ApiException e) { e.printStackTrace(); - + throw new RepositoryRegistryUnlinkException(submodelId); } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryConfiguration.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryConfiguration.java index e29a3e0d2..02eccf036 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryConfiguration.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryConfiguration.java @@ -44,9 +44,9 @@ public class RegistryIntegrationSubmodelRepositoryConfiguration { @Bean @ConditionalOnMissingBean - public SubmodelRepositoryRegistryLink getAasRepositoryRegistryLink(@Value("${basyx.submodelrepository.feature.registryintegration}") String registryBasePath, @Value("${basyx.externalurl}") String smRepositoryBaseURL) { + public SubmodelRepositoryRegistryLink getAasRepositoryRegistryLink(@Value("${basyx.submodelrepository.feature.registryintegration}") String registryBasePath, @Value("${basyx.externalurl}") String submodelRepositoryBaseURL) { - return new SubmodelRepositoryRegistryLink(new SubmodelRegistryApi(registryBasePath), smRepositoryBaseURL); + return new SubmodelRepositoryRegistryLink(new SubmodelRegistryApi(registryBasePath), submodelRepositoryBaseURL); } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFactory.java index 4e47830a5..9a15c9c21 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFactory.java @@ -36,16 +36,16 @@ public class RegistryIntegrationSubmodelRepositoryFactory implements SubmodelRepositoryFactory { private SubmodelRepositoryFactory decorated; - private SubmodelRepositoryRegistryLink smRepositoryRegistryLink; + private SubmodelRepositoryRegistryLink submodelRepositoryRegistryLink; - public RegistryIntegrationSubmodelRepositoryFactory(SubmodelRepositoryFactory decorated, SubmodelRepositoryRegistryLink smRepositoryRegistryLink) { + public RegistryIntegrationSubmodelRepositoryFactory(SubmodelRepositoryFactory decorated, SubmodelRepositoryRegistryLink submodelRepositoryRegistryLink) { this.decorated = decorated; - this.smRepositoryRegistryLink = smRepositoryRegistryLink; + this.submodelRepositoryRegistryLink = submodelRepositoryRegistryLink; } @Override public SubmodelRepository create() { - return new RegistryIntegrationSubmodelRepository(decorated.create(), smRepositoryRegistryLink); + return new RegistryIntegrationSubmodelRepository(decorated.create(), submodelRepositoryRegistryLink); } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFeature.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFeature.java index f4f32a1c0..986ab2073 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFeature.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFeature.java @@ -23,7 +23,6 @@ * SPDX-License-Identifier: MIT ******************************************************************************/ - package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration; import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepositoryFactory; @@ -42,16 +41,16 @@ public class RegistryIntegrationSubmodelRepositoryFeature implements SubmodelRepositoryFeature { public final static String FEATURENAME = "basyx.submodelrepository.feature.registryintegration"; - private SubmodelRepositoryRegistryLink smRepositoryRegistryLink; + private SubmodelRepositoryRegistryLink submodelRepositoryRegistryLink; @Autowired - public RegistryIntegrationSubmodelRepositoryFeature(SubmodelRepositoryRegistryLink smRepositoryRegistryLink) { - this.smRepositoryRegistryLink = smRepositoryRegistryLink; + public RegistryIntegrationSubmodelRepositoryFeature(SubmodelRepositoryRegistryLink submodelRepositoryRegistryLink) { + this.submodelRepositoryRegistryLink = submodelRepositoryRegistryLink; } @Override - public SubmodelRepositoryFactory decorate(SubmodelRepositoryFactory smRepositoryFactory) { - return new RegistryIntegrationSubmodelRepositoryFactory(smRepositoryFactory, smRepositoryRegistryLink); + public SubmodelRepositoryFactory decorate(SubmodelRepositoryFactory submodelRepositoryFactory) { + return new RegistryIntegrationSubmodelRepositoryFactory(submodelRepositoryFactory, submodelRepositoryRegistryLink); } @Override diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java index 2c9612e37..2df2d1a34 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java @@ -51,16 +51,16 @@ public class SubmodelDescriptorFactory { private static final String SUBMODEL_INTERFACE = "SUBMODEL-3.0"; private static final String SUBMODEL_REPOSITORY_PATH = "/submodels"; - + private Submodel submodel; - private String smRepositoryURL; + private String submodelRepositoryURL; private AttributeMapper attributeMapper; - public SubmodelDescriptorFactory(Submodel submodel, String smRepositoryBaseURL) { + public SubmodelDescriptorFactory(Submodel submodel, String submodelRepositoryBaseURL) { super(); this.submodel = submodel; - this.smRepositoryURL = createSubmodelRepositoryUrl(smRepositoryBaseURL); + this.submodelRepositoryURL = createSubmodelRepositoryUrl(submodelRepositoryBaseURL); this.attributeMapper = new DefaultAttributeMapperFactory().create(); } @@ -153,7 +153,7 @@ private void setEndpointItem(String shellId, SubmodelDescriptor descriptor) { } private ProtocolInformation createProtocolInformation(String shellId) { - String href = String.format("%s/%s", smRepositoryURL, Base64UrlEncodedIdentifier.encodeIdentifier(shellId)); + String href = String.format("%s/%s", submodelRepositoryURL, Base64UrlEncodedIdentifier.encodeIdentifier(shellId)); ProtocolInformation protocolInformation = new ProtocolInformation(); protocolInformation.endpointProtocol(getProtocol(href)); @@ -177,13 +177,13 @@ private String getProtocol(String endpoint) { throw new RuntimeException(); } } - - private String createSubmodelRepositoryUrl(String smRepositoryBaseURL) { + + private String createSubmodelRepositoryUrl(String submodelRepositoryBaseURL) { try { - return new URL(new URL(smRepositoryBaseURL), SUBMODEL_REPOSITORY_PATH).toString(); + return new URL(new URL(submodelRepositoryBaseURL), SUBMODEL_REPOSITORY_PATH).toString(); } catch (MalformedURLException e) { - throw new RuntimeException("The Submodel Repository Base url is malformed " + e.getMessage()); + throw new RuntimeException("The Submodel Repository Base url is malformed.\n" + e.getMessage()); } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLink.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLink.java index 83eec3746..56b1198ca 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLink.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLink.java @@ -36,12 +36,12 @@ public class SubmodelRepositoryRegistryLink { private SubmodelRegistryApi registryApi; - private String smRepositoryBaseURL; + private String submodelRepositoryBaseURL; - public SubmodelRepositoryRegistryLink(SubmodelRegistryApi registryApi, String smRepositoryBaseURL) { + public SubmodelRepositoryRegistryLink(SubmodelRegistryApi registryApi, String submodelRepositoryBaseURL) { super(); this.registryApi = registryApi; - this.smRepositoryBaseURL = smRepositoryBaseURL; + this.submodelRepositoryBaseURL = submodelRepositoryBaseURL; } public SubmodelRegistryApi getRegistryApi() { @@ -49,7 +49,7 @@ public SubmodelRegistryApi getRegistryApi() { } public String getSubmodelRepositoryBaseURL() { - return smRepositoryBaseURL; + return submodelRepositoryBaseURL; } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/AttributeMapper.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/AttributeMapper.java index 9a4a62835..baad951d3 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/AttributeMapper.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/AttributeMapper.java @@ -45,105 +45,101 @@ * @author danish */ public class AttributeMapper { - + private Logger logger = LoggerFactory.getLogger(AttributeMapper.class); - + private ObjectMapper mapper; - + public AttributeMapper(ObjectMapper mapper) { this.mapper = mapper; } /** - * Maps {@link Submodel#getDescription()} from AAS4J to - * SubmodelRegistry client + * Maps {@link Submodel#getDescription()} from AAS4J to SubmodelRegistry client * * @param descriptions * @return the mapped descriptions */ public List mapDescription(List descriptions) { CustomTypeCloneFactory cloneFactory = new CustomTypeCloneFactory<>(LangStringTextType.class, mapper); - + List mappedDescriptions = cloneFactory.create(descriptions); - + if (mappedDescriptions == null) - logger.error("Descriptions could not be mapped due to a failure"); + logger.error("Descriptions could not be mapped due to a failure."); return mappedDescriptions; } /** - * Maps {@link Submodel#getDisplayName()} from AAS4J to - * SubmodelRegistry client + * Maps {@link Submodel#getDisplayName()} from AAS4J to SubmodelRegistry client * * @param displayNames * @return the mapped displayNames */ public List mapDisplayName(List displayNames) { CustomTypeCloneFactory cloneFactory = new CustomTypeCloneFactory<>(LangStringNameType.class, mapper); - + List mappedDisplayNames = cloneFactory.create(displayNames); - + if (mappedDisplayNames == null) - logger.error("DisplayNames could not be mapped due to a failure"); + logger.error("DisplayNames could not be mapped due to a failure."); return mappedDisplayNames; } /** - * Maps {@link Submodel#getExtensions()} from AAS4J to - * SubmodelRegistry client + * Maps {@link Submodel#getExtensions()} from AAS4J to SubmodelRegistry client * * @param extensions * @return the mapped extensions */ public List mapExtensions(List extensions) { CustomTypeCloneFactory cloneFactory = new CustomTypeCloneFactory<>(Extension.class, mapper); - + List mappedExtensions = cloneFactory.create(extensions); - + if (mappedExtensions == null) - logger.error("Extensions could not be mapped due to a failure"); + logger.error("Extensions could not be mapped due to a failure."); return cloneFactory.create(extensions); } /** - * Maps {@link Submodel#getAdministration()} from AAS4J to - * SubmodelRegistry client + * Maps {@link Submodel#getAdministration()} from AAS4J to SubmodelRegistry + * client * * @param administrativeInformation * @return the mapped administrativeInformation */ public AdministrativeInformation mapAdministration(org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation administrativeInformation) { CustomTypeCloneFactory cloneFactory = new CustomTypeCloneFactory<>(AdministrativeInformation.class, mapper); - + AdministrativeInformation mappedAdministrativeInformation = cloneFactory.create(administrativeInformation); - + if (mappedAdministrativeInformation == null) - logger.error("AdministrativeInformation could not be mapped due to a failure"); + logger.error("AdministrativeInformation could not be mapped due to a failure."); return mappedAdministrativeInformation; } - + /** - * Maps {@link Submodel#getSemanticID()} from AAS4J to - * SubmodelRegistry client + * Maps {@link Submodel#getSemanticID()} from AAS4J to SubmodelRegistry client * * @param semanticId * @return the mapped semanticId */ public Reference mapSemanticId(org.eclipse.digitaltwin.aas4j.v3.model.Reference semanticId) { CustomTypeCloneFactory cloneFactory = new CustomTypeCloneFactory<>(Reference.class, mapper); - + Reference mappedSemanticId = cloneFactory.create(semanticId); - + if (mappedSemanticId == null) - logger.error("SemanticId could not be mapped due to a failure"); - + logger.error("SemanticId could not be mapped due to a failure."); + return mappedSemanticId; } - + /** * Maps {@link Submodel#getSupplementalSemanticIds()} from AAS4J to * SubmodelRegistry client @@ -153,12 +149,12 @@ public Reference mapSemanticId(org.eclipse.digitaltwin.aas4j.v3.model.Reference */ public List mapSupplementalSemanticId(List supplementalSemanticIds) { CustomTypeCloneFactory cloneFactory = new CustomTypeCloneFactory<>(Reference.class, mapper); - + List mappedSupplementalSemanticId = cloneFactory.create(supplementalSemanticIds); - + if (mappedSupplementalSemanticId == null) - logger.error("SupplementalSemanticId could not be mapped due to a failure"); - + logger.error("SupplementalSemanticId could not be mapped due to a failure."); + return mappedSupplementalSemanticId; } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java index 8fca0f717..36adb40d9 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java @@ -64,9 +64,9 @@ public AttributeMapper create() { return new AttributeMapper(mapper); } - private SimpleModule createDeserializerModule(Class type, JsonDeserializer deser) { + private SimpleModule createDeserializerModule(Class type, JsonDeserializer deserializer) { SimpleModule moduleDeser = new SimpleModule(); - moduleDeser.addDeserializer(type, deser); + moduleDeser.addDeserializer(type, deserializer); return moduleDeser; } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java index 85f2a425a..208b138e7 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java @@ -44,9 +44,10 @@ public class DataTypeDefXsdDeserializer extends JsonDeserializer { @Override - public DataTypeDefXsd deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { + public DataTypeDefXsd deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JacksonException { try { - JsonNode node = p.getCodec().readTree(p); + JsonNode node = parser.getCodec() + .readTree(parser); String value = node.asText(); @@ -54,7 +55,7 @@ public DataTypeDefXsd deserialize(JsonParser p, DeserializationContext ctxt) thr return DataTypeDefXsd.valueOf(DataTypeDefXsd.class, compatibleEnumValue); } catch (Exception e) { - throw new RuntimeException("Unable to deserialize the DataTypeDefXsd Enum"); + throw new RuntimeException("Unable to deserialize the DataTypeDefXsd Enum."); } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java index 9afc5dd05..794c8d08f 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java @@ -44,18 +44,19 @@ public class KeyTypeDeserializer extends JsonDeserializer { @Override - public KeyTypes deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { + public KeyTypes deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JacksonException { try { - JsonNode node = p.getCodec().readTree(p); - + JsonNode node = parser.getCodec() + .readTree(parser); + String value = node.asText(); - + String compatibleEnumValue = StringUtils.remove(value, '_'); - + return KeyTypes.valueOf(KeyTypes.class, compatibleEnumValue); - + } catch (Exception e) { - throw new RuntimeException("Unable to deserialize the KeyTypes Enum"); + throw new RuntimeException("Unable to deserialize the KeyTypes Enum."); } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java index 565d6e5dd..5c853750b 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java @@ -44,9 +44,10 @@ public class ReferenceTypeDeserializer extends JsonDeserializer { @Override - public ReferenceTypes deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { + public ReferenceTypes deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JacksonException { try { - JsonNode node = p.getCodec().readTree(p); + JsonNode node = parser.getCodec() + .readTree(parser); String value = node.asText(); @@ -55,7 +56,7 @@ public ReferenceTypes deserialize(JsonParser p, DeserializationContext ctxt) thr return ReferenceTypes.valueOf(ReferenceTypes.class, compatibleEnumValue); } catch (Exception e) { - throw new RuntimeException("Unable to deserialize the ReferenceTypes Enum"); + throw new RuntimeException("Unable to deserialize the ReferenceTypes Enum."); } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationTestHelper.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationTestHelper.java index 720d22c33..fd048c6b6 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationTestHelper.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationTestHelper.java @@ -59,9 +59,9 @@ public class RegistryIntegrationTestHelper { private static final LangStringTextType AAS4J_LANG_STRING_TEXT_TYPE_2 = new DefaultLangStringTextType.Builder().language("en").text("An Example").build(); // LangStringTextType SMRegistry - private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringTextType SMREG_LANG_STRING_TEXT_TYPE_1 = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringTextType().language("de") + private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringTextType SUBMODEL_REG_LANG_STRING_TEXT_TYPE_1 = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringTextType().language("de") .text("Ein Beispiel"); - private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringTextType SMREG_LANG_STRING_TEXT_TYPE_2 = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringTextType().language("en") + private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringTextType SUBMODEL_REG_LANG_STRING_TEXT_TYPE_2 = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringTextType().language("en") .text("An Example"); // LangStringNameType AAS4J @@ -69,9 +69,9 @@ public class RegistryIntegrationTestHelper { private static final LangStringNameType AAS4J_LANG_STRING_NAME_TYPE_2 = new DefaultLangStringNameType.Builder().language("de").text("Namenstypzeichenfolge").build(); // LangStringNameType SMRegistry - private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringNameType SMREG_LANG_STRING_NAME_TYPE_1 = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringNameType().language("en") + private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringNameType SUBMODEL_REG_LANG_STRING_NAME_TYPE_1 = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringNameType().language("en") .text("Name type string"); - private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringNameType SMREG_LANG_STRING_NAME_TYPE_2 = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringNameType().language("de") + private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringNameType SUBMODEL_REG_LANG_STRING_NAME_TYPE_2 = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringNameType().language("de") .text("Namenstypzeichenfolge"); // Administration AAS4J @@ -79,10 +79,10 @@ public class RegistryIntegrationTestHelper { private static final EmbeddedDataSpecification AAS4JEMB_EMBEDDED_DATA_SPECIFICATION = new DefaultEmbeddedDataSpecification.Builder().dataSpecification(AAS4J_DATASPECIFICATION).build(); // Administration SMRegistry - private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Reference SMREG__DATASPECIFICATION = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Reference() + private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Reference SUBMODEL_REG_DATASPECIFICATION = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Reference() .keys(Arrays.asList(new Key().type(org.eclipse.digitaltwin.basyx.submodelregistry.client.model.KeyTypes.BLOB).value("BlobValue"))).type(org.eclipse.digitaltwin.basyx.submodelregistry.client.model.ReferenceTypes.EXTERNALREFERENCE); - private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.EmbeddedDataSpecification SMREG_EMBEDDED_DATA_SPECIFICATION = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.EmbeddedDataSpecification() - .dataSpecification(SMREG__DATASPECIFICATION); + private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.EmbeddedDataSpecification SUBMODEL_REG_EMBEDDED_DATA_SPECIFICATION = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.EmbeddedDataSpecification() + .dataSpecification(SUBMODEL_REG_DATASPECIFICATION); private static final String VERSION = "1.0.0"; private static final String REVISION = "3"; @@ -92,7 +92,7 @@ public class RegistryIntegrationTestHelper { private static final Extension AAS4J_EXTENSION = new DefaultExtension.Builder().semanticId(AAS4J_DATASPECIFICATION).name("extension").valueType(org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd.STRING).value("extensionValue").build(); // Extension SMRegistry - private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Extension SMREG_EXTENSION = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Extension().semanticId(SMREG__DATASPECIFICATION).name("extension") + private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Extension SUBMODEL_REG_EXTENSION = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Extension().semanticId(SUBMODEL_REG_DATASPECIFICATION).name("extension") .valueType(DataTypeDefXsd.STRING).value("extensionValue").supplementalSemanticIds(new ArrayList<>()).refersTo(new ArrayList<>()); public static List getAas4jLangStringTextTypes() { @@ -100,7 +100,7 @@ public static List getAas4jLangStringTextTypes() { } public static List getSubmodelRegLangStringTextTypes() { - return Arrays.asList(SMREG_LANG_STRING_TEXT_TYPE_1, SMREG_LANG_STRING_TEXT_TYPE_2); + return Arrays.asList(SUBMODEL_REG_LANG_STRING_TEXT_TYPE_1, SUBMODEL_REG_LANG_STRING_TEXT_TYPE_2); } public static AdministrativeInformation getAas4jAdministration() { @@ -108,7 +108,7 @@ public static AdministrativeInformation getAas4jAdministration() { } public static org.eclipse.digitaltwin.basyx.submodelregistry.client.model.AdministrativeInformation getSubmodelRegAdministration() { - return new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.AdministrativeInformation().embeddedDataSpecifications(Arrays.asList(SMREG_EMBEDDED_DATA_SPECIFICATION)).version(VERSION).revision(REVISION) + return new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.AdministrativeInformation().embeddedDataSpecifications(Arrays.asList(SUBMODEL_REG_EMBEDDED_DATA_SPECIFICATION)).version(VERSION).revision(REVISION) .templateId(TEMPLATEID); } @@ -117,7 +117,7 @@ public static List getAas4jLangStringNameTypes() { } public static List getSubmodelRegLangStringNameTypes() { - return Arrays.asList(SMREG_LANG_STRING_NAME_TYPE_1, SMREG_LANG_STRING_NAME_TYPE_2); + return Arrays.asList(SUBMODEL_REG_LANG_STRING_NAME_TYPE_1, SUBMODEL_REG_LANG_STRING_NAME_TYPE_2); } public static List getAas4jExtensions() { @@ -125,7 +125,7 @@ public static List getAas4jExtensions() { } public static List getSubmodelRegExtensions() { - return Arrays.asList(SMREG_EXTENSION); + return Arrays.asList(SUBMODEL_REG_EXTENSION); } public static Reference getAas4jSemanticId() { @@ -133,7 +133,7 @@ public static Reference getAas4jSemanticId() { } public static org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Reference getSubmodelRegSemanticId() { - return SMREG__DATASPECIFICATION; + return SUBMODEL_REG_DATASPECIFICATION; } public static List getAas4jSupplementalSemanticIds() { @@ -141,7 +141,7 @@ public static List getAas4jSupplementalSemanticIds() { } public static List getSubmodelRegSupplementalSemanticIds() { - return Arrays.asList(SMREG__DATASPECIFICATION, SMREG__DATASPECIFICATION); + return Arrays.asList(SUBMODEL_REG_DATASPECIFICATION, SUBMODEL_REG_DATASPECIFICATION); } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLinkApplication.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLinkApplication.java index ca4f6280f..6b1cd2687 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLinkApplication.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLinkApplication.java @@ -29,9 +29,9 @@ import org.junit.runner.Result; /** - * Application for testing the {@link RegistryIntegrationSubmodelRepository} feature. - * The first argument is the Submodel Repository Base URL, the second argument is the Submodel - * Registry URL. + * Application for testing the {@link RegistryIntegrationSubmodelRepository} + * feature. The first argument is the Submodel Repository Base URL, the second + * argument is the Submodel Registry URL. * * @author schnicke, danish * @@ -39,10 +39,10 @@ public class SubmodelRepositoryRegistryTestLinkApplication { public static void main(String[] args) throws Exception { - String smRepoBaseUrl = getSubmodelRepositoryBaseUrl(args); - String smRegUrl = getSubmodelRegistryUrl(args); + String submodelRepoBaseUrl = getSubmodelRepositoryBaseUrl(args); + String submodelRegUrl = getSubmodelRegistryUrl(args); - Result result = runTests(smRepoBaseUrl, smRegUrl); + Result result = runTests(submodelRepoBaseUrl, submodelRegUrl); printResults(result); } @@ -51,9 +51,9 @@ private static void printResults(Result result) { System.out.println("Finished. Result: Failures: " + result.getFailureCount() + ". Ignored: " + result.getIgnoreCount() + ". Tests run: " + result.getRunCount() + ". Time: " + result.getRunTime() + "ms."); } - private static Result runTests(String smRepoBaseUrl, String smRegUrl) { - SubmodelRepositoryRegistryTestLink.submodelRepoBaseUrl = smRepoBaseUrl; - SubmodelRepositoryRegistryTestLink.submodelRegistryUrl = smRegUrl; + private static Result runTests(String submodelRepoBaseUrl, String submodelRegUrl) { + SubmodelRepositoryRegistryTestLink.submodelRepoBaseUrl = submodelRepoBaseUrl; + SubmodelRepositoryRegistryTestLink.submodelRegistryUrl = submodelRegUrl; JUnitCore junit = new JUnitCore(); junit.addListener(new TextListener(System.out)); diff --git a/basyx.submodelrepository/basyx.submodelrepository.component/src/main/resources/application-integration.properties b/basyx.submodelrepository/basyx.submodelrepository.component/src/main/resources/application-integration.properties index a9a91780d..5ae73e3f3 100644 --- a/basyx.submodelrepository/basyx.submodelrepository.component/src/main/resources/application-integration.properties +++ b/basyx.submodelrepository/basyx.submodelrepository.component/src/main/resources/application-integration.properties @@ -23,4 +23,4 @@ basyx.externalurl=http://localhost:8081 # mqtt.hostname = localhost # mqtt.port = 1883 -# basyx.cors.allowed-origins=http://localhost:3000, http://localhost:4000 \ No newline at end of file +# basyx.cors.allowed-origins=http://localhost:3000, http://localhost:4000 diff --git a/pom.xml b/pom.xml index 0ffe7107d..184eceb72 100644 --- a/pom.xml +++ b/pom.xml @@ -36,8 +36,7 @@ - Fraunhofer-Gesellschaft zur Foerderung der angewandten - Forschung e.V. + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. fschnicke Frank Schnicke frank.schnicke@iese.fraunhofer.de From e0dc9b2680c912d98df0385e1bcd954543d49422 Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Fri, 24 Nov 2023 09:10:15 +0100 Subject: [PATCH 18/21] Resolves review remarks Signed-off-by: Mohammad Ghazanfar Ali Danish --- .../RegistryIntegrationAasRepository.java | 4 +-- ...gistryIntegrationAasRepositoryFeature.java | 9 +++++- ...yIntegrationSubmodelRepositoryFeature.java | 11 ++++++-- .../SubmodelRepositoryRegistryTestLink.java | 28 +++++++++---------- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java index 70002915c..39462b7d6 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java @@ -111,8 +111,8 @@ public void removeSubmodelReference(String shellId, String submodelId) { } @Override - public void setAssetInformation(String shellId, AssetInformation sehllInfo) throws ElementDoesNotExistException { - decorated.setAssetInformation(shellId, sehllInfo); + public void setAssetInformation(String shellId, AssetInformation shellInfo) throws ElementDoesNotExistException { + decorated.setAssetInformation(shellId, shellInfo); } @Override diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java index cee76b9d9..17c5c33b8 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java @@ -30,6 +30,7 @@ import org.eclipse.digitaltwin.basyx.aasrepository.AasRepositoryFactory; import org.eclipse.digitaltwin.basyx.aasrepository.feature.AasRepositoryFeature; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.stereotype.Component; @@ -44,6 +45,12 @@ public class RegistryIntegrationAasRepositoryFeature implements AasRepositoryFea public final static String FEATURENAME = "basyx.aasrepository.feature.registryintegration"; private AasRepositoryRegistryLink aasRepositoryRegistryLink; + + @Value("${" + FEATURENAME + ":}") + private String registryBaseURL; + + @Value("${basyx.externalurl:}") + private String submodelRepositoryExternalBaseURL; @Autowired public RegistryIntegrationAasRepositoryFeature(AasRepositoryRegistryLink aasRepositoryRegistryLink) { @@ -71,6 +78,6 @@ public String getName() { @Override public boolean isEnabled() { - return true; + return !registryBaseURL.isBlank() && !submodelRepositoryExternalBaseURL.isBlank(); } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFeature.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFeature.java index 986ab2073..1a56931d3 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFeature.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFeature.java @@ -28,6 +28,7 @@ import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepositoryFactory; import org.eclipse.digitaltwin.basyx.submodelrepository.feature.SubmodelRepositoryFeature; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.stereotype.Component; @@ -39,9 +40,15 @@ @Component @ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${basyx.submodelrepository.feature.registryintegration:}') && !T(org.springframework.util.StringUtils).isEmpty('${basyx.externalurl:}')") public class RegistryIntegrationSubmodelRepositoryFeature implements SubmodelRepositoryFeature { - public final static String FEATURENAME = "basyx.submodelrepository.feature.registryintegration"; + public static final String FEATURENAME = "basyx.submodelrepository.feature.registryintegration"; private SubmodelRepositoryRegistryLink submodelRepositoryRegistryLink; + + @Value("${" + FEATURENAME + ":}") + private String registryBaseURL; + + @Value("${basyx.externalurl:}") + private String aasRepositoryExternalBaseURL; @Autowired public RegistryIntegrationSubmodelRepositoryFeature(SubmodelRepositoryRegistryLink submodelRepositoryRegistryLink) { @@ -69,6 +76,6 @@ public String getName() { @Override public boolean isEnabled() { - return true; + return !registryBaseURL.isBlank() && !aasRepositoryExternalBaseURL.isBlank(); } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java index aad3b9e01..eb8bfe2ae 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java @@ -69,10 +69,10 @@ public class SubmodelRepositoryRegistryTestLink { private static final SubmodelDescriptor DUMMY_DESCRIPTOR = createExpectedDescriptor(); @Test - public void createAas() throws FileNotFoundException, IOException, ApiException { - String aasJsonContent = getAas1JSONString(); + public void createSubmodel() throws FileNotFoundException, IOException, ApiException { + String submodelJsonContent = getSubmodelJSONString(); - CloseableHttpResponse creationResponse = createAasOnRepo(aasJsonContent); + CloseableHttpResponse creationResponse = createSubmodelOnRepo(submodelJsonContent); assertEquals(HttpStatus.CREATED.value(), creationResponse.getCode()); SubmodelDescriptor actualDescriptor = retrieveDescriptorFromRegistry(); @@ -83,13 +83,13 @@ public void createAas() throws FileNotFoundException, IOException, ApiException } @Test - public void deleteAas() throws FileNotFoundException, IOException, ApiException { - String aasJsonContent = getAas1JSONString(); + public void deleteSubmodel() throws FileNotFoundException, IOException, ApiException { + String submodelJsonContent = getSubmodelJSONString(); - CloseableHttpResponse creationResponse = createAasOnRepo(aasJsonContent); + CloseableHttpResponse creationResponse = createSubmodelOnRepo(submodelJsonContent); assertEquals(HttpStatus.CREATED.value(), creationResponse.getCode()); - CloseableHttpResponse deleteResponse = deleteAasFromRepo(DUMMY_SUBMODEL_ID); + CloseableHttpResponse deleteResponse = deleteSubmodelFromRepo(DUMMY_SUBMODEL_ID); assertEquals(HttpStatus.NO_CONTENT.value(), deleteResponse.getCode()); assertDescriptionDeletionAtRegistry(); @@ -102,13 +102,13 @@ private SubmodelDescriptor retrieveDescriptorFromRegistry() throws ApiException } private void resetRepository() throws IOException { - CloseableHttpResponse deleteResponse = deleteAasFromRepo(DUMMY_SUBMODEL_ID); + CloseableHttpResponse deleteResponse = deleteSubmodelFromRepo(DUMMY_SUBMODEL_ID); assertEquals(HttpStatus.NO_CONTENT.value(), deleteResponse.getCode()); } - private CloseableHttpResponse deleteAasFromRepo(String shellId) throws IOException { - return BaSyxHttpTestUtils.executeDeleteOnURL(getSpecificAasAccessURL(shellId)); + private CloseableHttpResponse deleteSubmodelFromRepo(String shellId) throws IOException { + return BaSyxHttpTestUtils.executeDeleteOnURL(getSpecificSubmodelAccessURL(shellId)); } private void assertDescriptionDeletionAtRegistry() throws ApiException { @@ -121,15 +121,15 @@ private void assertDescriptionDeletionAtRegistry() throws ApiException { assertTrue(actualDescriptors.isEmpty()); } - private String getAas1JSONString() throws FileNotFoundException, IOException { + private String getSubmodelJSONString() throws FileNotFoundException, IOException { return BaSyxHttpTestUtils.readJSONStringFromClasspath("SingleSubmodel.json"); } - private CloseableHttpResponse createAasOnRepo(String aasJsonContent) throws IOException { + private CloseableHttpResponse createSubmodelOnRepo(String aasJsonContent) throws IOException { return BaSyxHttpTestUtils.executePostOnURL(createSubmodelRepositoryUrl(submodelRepoBaseUrl), aasJsonContent); } - private String getSpecificAasAccessURL(String aasId) { + private String getSpecificSubmodelAccessURL(String aasId) { return createSubmodelRepositoryUrl(submodelRepoBaseUrl) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(aasId); } @@ -184,7 +184,7 @@ private static String createSubmodelRepositoryUrl(String smRepositoryBaseURL) { try { return new URL(new URL(smRepositoryBaseURL), SUBMODEL_REPOSITORY_PATH).toString(); } catch (MalformedURLException e) { - throw new RuntimeException("The Submodel Repository Base url is malformed " + e.getMessage()); + throw new RuntimeException("The Submodel Repository Base url is malformed.\n " + e.getMessage()); } } From dbc5a89ab3c1aa73bf44d21cdf8b0681f754d526 Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Fri, 24 Nov 2023 09:34:22 +0100 Subject: [PATCH 19/21] Minor refactoring Signed-off-by: Mohammad Ghazanfar Ali Danish --- .../integration/RegistryIntegrationAasRepositoryFeature.java | 4 ++-- .../RegistryIntegrationSubmodelRepositoryFeature.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java index 17c5c33b8..34bdc7437 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java @@ -50,7 +50,7 @@ public class RegistryIntegrationAasRepositoryFeature implements AasRepositoryFea private String registryBaseURL; @Value("${basyx.externalurl:}") - private String submodelRepositoryExternalBaseURL; + private String aasRepositoryExternalBaseURL; @Autowired public RegistryIntegrationAasRepositoryFeature(AasRepositoryRegistryLink aasRepositoryRegistryLink) { @@ -78,6 +78,6 @@ public String getName() { @Override public boolean isEnabled() { - return !registryBaseURL.isBlank() && !submodelRepositoryExternalBaseURL.isBlank(); + return !registryBaseURL.isBlank() && !aasRepositoryExternalBaseURL.isBlank(); } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFeature.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFeature.java index 1a56931d3..6f5102e71 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFeature.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFeature.java @@ -48,7 +48,7 @@ public class RegistryIntegrationSubmodelRepositoryFeature implements SubmodelRep private String registryBaseURL; @Value("${basyx.externalurl:}") - private String aasRepositoryExternalBaseURL; + private String submodelRepositoryExternalBaseURL; @Autowired public RegistryIntegrationSubmodelRepositoryFeature(SubmodelRepositoryRegistryLink submodelRepositoryRegistryLink) { @@ -76,6 +76,6 @@ public String getName() { @Override public boolean isEnabled() { - return !registryBaseURL.isBlank() && !aasRepositoryExternalBaseURL.isBlank(); + return !registryBaseURL.isBlank() && !submodelRepositoryExternalBaseURL.isBlank(); } } From 12471ab7476bb97c61b45be6f539b3fcf83c9cff Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Fri, 24 Nov 2023 15:13:00 +0100 Subject: [PATCH 20/21] Resolved review remarks - Changes related to serialization extension - Refactors RegIntegSMRepo and RegIntegAasRepo to check for descriptor before deletion - Swaps order of deletion from Repo and Registry Signed-off-by: Mohammad Ghazanfar Ali Danish --- .../integration/AasDescriptorFactory.java | 5 +- .../RegistryIntegrationAasRepository.java | 30 ++++++-- ...IntegrationAasRepositoryConfiguration.java | 10 +++ ...gistryIntegrationAasRepositoryFactory.java | 7 +- ...gistryIntegrationAasRepositoryFeature.java | 8 +- .../mapper/DefaultAttributeMapperFactory.java | 74 ------------------- .../DataTypeDefXsdDeserializer.java | 62 ---------------- .../deserializer/KeyTypeDeserializer.java | 63 ---------------- .../ReferenceTypeDeserializer.java | 63 ---------------- .../RegistryIntegrationTestHelper.java | 3 +- .../integration/TestAttributeMapper.java | 21 ++++-- ...RegistryIntegrationSubmodelRepository.java | 29 ++++++-- ...rationSubmodelRepositoryConfiguration.java | 12 ++- ...yIntegrationSubmodelRepositoryFactory.java | 7 +- ...yIntegrationSubmodelRepositoryFeature.java | 8 +- .../SubmodelDescriptorFactory.java | 5 +- .../mapper/DefaultAttributeMapperFactory.java | 74 ------------------- .../DataTypeDefXsdDeserializer.java | 62 ---------------- .../deserializer/KeyTypeDeserializer.java | 63 ---------------- .../ReferenceTypeDeserializer.java | 63 ---------------- .../RegistryIntegrationTestHelper.java | 3 +- .../integration/TestAttributeMapper.java | 21 ++++-- pom.xml | 4 +- 23 files changed, 125 insertions(+), 572 deletions(-) delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java delete mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java delete mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java delete mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java delete mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java index 25454a655..92bf90d47 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java @@ -39,7 +39,6 @@ import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Endpoint; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ProtocolInformation; import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.AttributeMapper; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.DefaultAttributeMapperFactory; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; /** @@ -57,11 +56,11 @@ public class AasDescriptorFactory { private AttributeMapper attributeMapper; - public AasDescriptorFactory(AssetAdministrationShell shell, String aasRepositoryBaseURL) { + public AasDescriptorFactory(AssetAdministrationShell shell, String aasRepositoryBaseURL, AttributeMapper attributeMapper) { super(); this.shell = shell; this.aasRepositoryURL = createAasRepositoryUrl(aasRepositoryBaseURL); - this.attributeMapper = new DefaultAttributeMapperFactory().create(); + this.attributeMapper = attributeMapper; } /** diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java index 39462b7d6..18c73a895 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepository.java @@ -33,6 +33,7 @@ import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor; import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.AttributeMapper; import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException; import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; import org.eclipse.digitaltwin.basyx.core.exceptions.RepositoryRegistryLinkException; @@ -54,10 +55,12 @@ public class RegistryIntegrationAasRepository implements AasRepository { private AasRepository decorated; private AasRepositoryRegistryLink aasRepositoryRegistryLink; + private AttributeMapper attributeMapper; - public RegistryIntegrationAasRepository(AasRepository decorated, AasRepositoryRegistryLink aasRepositoryRegistryLink) { + public RegistryIntegrationAasRepository(AasRepository decorated, AasRepositoryRegistryLink aasRepositoryRegistryLink, AttributeMapper attributeMapper) { this.decorated = decorated; this.aasRepositoryRegistryLink = aasRepositoryRegistryLink; + this.attributeMapper = attributeMapper; } @Override @@ -84,10 +87,9 @@ public void updateAas(String shellId, AssetAdministrationShell shell) { @Override public void deleteAas(String shellId) { - AssetAdministrationShell shell = decorated.getAas(shellId); + deleteFromRegistry(shellId); + decorated.deleteAas(shellId); - - deleteFromRegistry(shell.getId()); } @Override @@ -121,14 +123,14 @@ public AssetInformation getAssetInformation(String shellId) throws ElementDoesNo } private void integrateAasWithRegistry(AssetAdministrationShell shell, String aasRepositoryURL) { - AssetAdministrationShellDescriptor descriptor = new AasDescriptorFactory(shell, aasRepositoryURL).create(); + AssetAdministrationShellDescriptor descriptor = new AasDescriptorFactory(shell, aasRepositoryURL, attributeMapper).create(); RegistryAndDiscoveryInterfaceApi registryApi = aasRepositoryRegistryLink.getRegistryApi(); try { registryApi.postAssetAdministrationShellDescriptor(descriptor); - logger.info("Shell {} has been automatically linked with the Registry", shell.getId()); + logger.info("Shell '{}' has been automatically linked with the Registry", shell.getId()); } catch (ApiException e) { e.printStackTrace(); @@ -138,6 +140,12 @@ private void integrateAasWithRegistry(AssetAdministrationShell shell, String aas private void deleteFromRegistry(String shellId) { RegistryAndDiscoveryInterfaceApi registryApi = aasRepositoryRegistryLink.getRegistryApi(); + + if (!shellExistsOnRegistry(shellId, registryApi)) { + logger.error("Unable to un-link the AAS descriptor '{}' from the Registry because it does not exist on the Registry.", shellId); + + return; + } try { registryApi.deleteAssetAdministrationShellDescriptorById(shellId); @@ -149,5 +157,15 @@ private void deleteFromRegistry(String shellId) { throw new RepositoryRegistryUnlinkException(shellId); } } + + private boolean shellExistsOnRegistry(String shellId, RegistryAndDiscoveryInterfaceApi registryApi) { + try { + registryApi.getAssetAdministrationShellDescriptorById(shellId); + + return true; + } catch (ApiException e) { + return false; + } + } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java index 706819133..c4700498b 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryConfiguration.java @@ -28,12 +28,15 @@ import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.AttributeMapper; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import com.fasterxml.jackson.databind.ObjectMapper; + /** * Configuration for integrating {@link AasRepository} with AasRegistry * @@ -49,5 +52,12 @@ public AasRepositoryRegistryLink getAasRepositoryRegistryLink(@Value("${basyx.aa return new AasRepositoryRegistryLink(new RegistryAndDiscoveryInterfaceApi(registryBasePath), aasRepositoryBaseURL); } + + @Bean + @ConditionalOnMissingBean + public AttributeMapper getAasAttributeMapper(ObjectMapper objectMapper) { + + return new AttributeMapper(objectMapper); + } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java index fa8681bce..4ef1d37dd 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFactory.java @@ -27,6 +27,7 @@ import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; import org.eclipse.digitaltwin.basyx.aasrepository.AasRepositoryFactory; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.AttributeMapper; /** * Factory for creating {@link RegistryIntegrationAasRepository} @@ -37,15 +38,17 @@ public class RegistryIntegrationAasRepositoryFactory implements AasRepositoryFac private AasRepositoryFactory decorated; private AasRepositoryRegistryLink aasRepositoryRegistryLink; + private AttributeMapper attributeMapper; - public RegistryIntegrationAasRepositoryFactory(AasRepositoryFactory decorated, AasRepositoryRegistryLink aasRepositoryRegistryLink) { + public RegistryIntegrationAasRepositoryFactory(AasRepositoryFactory decorated, AasRepositoryRegistryLink aasRepositoryRegistryLink, AttributeMapper attributeMapper) { this.decorated = decorated; this.aasRepositoryRegistryLink = aasRepositoryRegistryLink; + this.attributeMapper = attributeMapper; } @Override public AasRepository create() { - return new RegistryIntegrationAasRepository(decorated.create(), aasRepositoryRegistryLink); + return new RegistryIntegrationAasRepository(decorated.create(), aasRepositoryRegistryLink, attributeMapper); } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java index 34bdc7437..0023d0b59 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationAasRepositoryFeature.java @@ -29,6 +29,7 @@ import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; import org.eclipse.digitaltwin.basyx.aasrepository.AasRepositoryFactory; import org.eclipse.digitaltwin.basyx.aasrepository.feature.AasRepositoryFeature; +import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.AttributeMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; @@ -51,15 +52,18 @@ public class RegistryIntegrationAasRepositoryFeature implements AasRepositoryFea @Value("${basyx.externalurl:}") private String aasRepositoryExternalBaseURL; + + private AttributeMapper attributeMapper; @Autowired - public RegistryIntegrationAasRepositoryFeature(AasRepositoryRegistryLink aasRepositoryRegistryLink) { + public RegistryIntegrationAasRepositoryFeature(AasRepositoryRegistryLink aasRepositoryRegistryLink, AttributeMapper attributeMapper) { this.aasRepositoryRegistryLink = aasRepositoryRegistryLink; + this.attributeMapper = attributeMapper; } @Override public AasRepositoryFactory decorate(AasRepositoryFactory aasRepositoryFactory) { - return new RegistryIntegrationAasRepositoryFactory(aasRepositoryFactory, aasRepositoryRegistryLink); + return new RegistryIntegrationAasRepositoryFactory(aasRepositoryFactory, aasRepositoryRegistryLink, attributeMapper); } @Override diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java deleted file mode 100644 index a0c163647..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper; - -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.DataTypeDefXsd; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.deserializer.DataTypeDefXsdDeserializer; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.deserializer.KeyTypeDeserializer; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.deserializer.ReferenceTypeDeserializer; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.module.SimpleModule; - -/** - * Factory for creating {@link AttributeMapper} with default {@link ObjectMapper} configurations - * - * @author danish - */ -public class DefaultAttributeMapperFactory { - - /** - * Creates the {@link AttributeMapper} with default configurations of the {@link ObjectMapper} - * - * @return default attribute mapper - */ - public AttributeMapper create() { - ObjectMapper mapper = new ObjectMapper(); - - SimpleModule keyTypesDeserModule = createDeserializerModule(KeyTypes.class, new KeyTypeDeserializer()); - - SimpleModule refTypesDeserModule = createDeserializerModule(ReferenceTypes.class, new ReferenceTypeDeserializer()); - - SimpleModule dataTypeDeserModule = createDeserializerModule(DataTypeDefXsd.class, new DataTypeDefXsdDeserializer()); - - mapper.registerModules(keyTypesDeserModule, refTypesDeserModule, dataTypeDeserModule); - - mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - - return new AttributeMapper(mapper); - } - - private SimpleModule createDeserializerModule(Class type, JsonDeserializer deserializer) { - SimpleModule moduleDeser = new SimpleModule(); - moduleDeser.addDeserializer(type, deserializer); - - return moduleDeser; - } - -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java deleted file mode 100644 index 31f1096b1..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.deserializer; - -import java.io.IOException; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.DataTypeDefXsd; - -import com.fasterxml.jackson.core.JacksonException; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; - -/** - * Custom deserializer for {@link DataTypeDefXsd} - * - * @author danish - */ -public class DataTypeDefXsdDeserializer extends JsonDeserializer { - - @Override - public DataTypeDefXsd deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JacksonException { - try { - JsonNode node = parser.getCodec() - .readTree(parser); - - String value = node.asText(); - - String compatibleEnumValue = StringUtils.remove(value, '_'); - - return DataTypeDefXsd.valueOf(DataTypeDefXsd.class, compatibleEnumValue); - } catch (Exception e) { - throw new RuntimeException("Unable to deserialize the DataTypeDefXsd Enum."); - } - } - -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java deleted file mode 100644 index ccb6401e6..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.deserializer; - -import java.io.IOException; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.KeyTypes; - -import com.fasterxml.jackson.core.JacksonException; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; - -/** - * Custom deserializer for {@link KeyTypes} - * - * @author danish - */ -public class KeyTypeDeserializer extends JsonDeserializer { - - @Override - public KeyTypes deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JacksonException { - try { - JsonNode node = parser.getCodec() - .readTree(parser); - - String value = node.asText(); - - String compatibleEnumValue = StringUtils.remove(value, '_'); - - return KeyTypes.valueOf(KeyTypes.class, compatibleEnumValue); - - } catch (Exception e) { - throw new RuntimeException("Unable to deserialize the KeyTypes Enum."); - } - } - -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java deleted file mode 100644 index 789ae7d48..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.deserializer; - -import java.io.IOException; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ReferenceTypes; - -import com.fasterxml.jackson.core.JacksonException; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; - -/** - * Custom deserializer for {@link ReferenceTypes} - * - * @author danish - */ -public class ReferenceTypeDeserializer extends JsonDeserializer { - - @Override - public ReferenceTypes deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JacksonException { - try { - JsonNode node = parser.getCodec() - .readTree(parser); - - String value = node.asText(); - - String compatibleEnumValue = StringUtils.remove(value, '_'); - - return ReferenceTypes.valueOf(ReferenceTypes.class, compatibleEnumValue); - - } catch (Exception e) { - throw new RuntimeException("Unable to deserialize the ReferenceTypes Enum."); - } - } - -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java index a007fdf64..91b5bf930 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/RegistryIntegrationTestHelper.java @@ -25,7 +25,6 @@ package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -100,7 +99,7 @@ public class RegistryIntegrationTestHelper { // Extension AasRegistry private static final org.eclipse.digitaltwin.basyx.aasregistry.client.model.Extension AAS_REG_EXTENSION = new org.eclipse.digitaltwin.basyx.aasregistry.client.model.Extension().semanticId(AAS_REG_DATASPECIFICATION).name("extension") - .valueType(DataTypeDefXsd.STRING).value("extensionValue").supplementalSemanticIds(new ArrayList<>()).refersTo(new ArrayList<>()); + .valueType(DataTypeDefXsd.STRING).value("extensionValue"); public static List getAas4jLangStringTextTypes() { return Arrays.asList(AAS4J_LANG_STRING_TEXT_TYPE_1, AAS_LANG_STRING_TEXT_TYPE_2); diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAttributeMapper.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAttributeMapper.java index 2a6da9a29..6730fec19 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAttributeMapper.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAttributeMapper.java @@ -27,6 +27,7 @@ import static org.junit.Assert.assertEquals; +import java.util.Arrays; import java.util.List; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AdministrativeInformation; @@ -35,10 +36,13 @@ import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringNameType; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.LangStringTextType; import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.AttributeMapper; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.DefaultAttributeMapperFactory; -import org.junit.BeforeClass; +import org.eclipse.digitaltwin.basyx.http.Aas4JHTTPSerializationExtension; +import org.eclipse.digitaltwin.basyx.http.BaSyxHTTPConfiguration; +import org.eclipse.digitaltwin.basyx.http.SerializationExtension; import org.junit.Test; +import com.fasterxml.jackson.databind.ObjectMapper; + /** * Unit tests for {@link AttributeMapper} * @@ -46,12 +50,7 @@ */ public class TestAttributeMapper { - private static AttributeMapper attributeMapper; - - @BeforeClass - public static void setUp() { - attributeMapper = new DefaultAttributeMapperFactory().create(); - } + private static AttributeMapper attributeMapper = new AttributeMapper(configureObjectMapper()); @Test public void mapDescriptions() { @@ -100,5 +99,11 @@ public void mapAssetKind() { assertEquals(expectedAssetKind, actualAssetKind); } + + private static ObjectMapper configureObjectMapper() { + List extensions = Arrays.asList(new Aas4JHTTPSerializationExtension()); + + return new BaSyxHTTPConfiguration().jackson2ObjectMapperBuilder(extensions).build(); + } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java index 3af3a2f08..d413cbf53 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java @@ -43,6 +43,7 @@ import org.eclipse.digitaltwin.basyx.submodelregistry.client.api.SubmodelRegistryApi; import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.SubmodelDescriptor; import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepository; +import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.AttributeMapper; import org.eclipse.digitaltwin.basyx.submodelservice.value.SubmodelElementValue; import org.eclipse.digitaltwin.basyx.submodelservice.value.SubmodelValueOnly; import org.slf4j.Logger; @@ -59,10 +60,12 @@ public class RegistryIntegrationSubmodelRepository implements SubmodelRepository private SubmodelRepository decorated; private SubmodelRepositoryRegistryLink submodelRepositoryRegistryLink; + private AttributeMapper attributeMapper; - public RegistryIntegrationSubmodelRepository(SubmodelRepository decorated, SubmodelRepositoryRegistryLink submodelRepositoryRegistryLink) { + public RegistryIntegrationSubmodelRepository(SubmodelRepository decorated, SubmodelRepositoryRegistryLink submodelRepositoryRegistryLink, AttributeMapper attributeMapper) { this.decorated = decorated; this.submodelRepositoryRegistryLink = submodelRepositoryRegistryLink; + this.attributeMapper = attributeMapper; } @Override @@ -89,9 +92,9 @@ public void createSubmodel(Submodel submodel) throws CollidingIdentifierExceptio @Override public void deleteSubmodel(String submodelId) throws ElementDoesNotExistException { - decorated.deleteSubmodel(submodelId); - deleteFromRegistry(submodelId); + + decorated.deleteSubmodel(submodelId); } @Override @@ -160,14 +163,14 @@ public void deleteFileValue(String submodelId, String idShortPath) throws Elemen } private void integrateSubmodelWithRegistry(Submodel submodel, String aasRepositoryURL) { - SubmodelDescriptor descriptor = new SubmodelDescriptorFactory(submodel, aasRepositoryURL).create(); + SubmodelDescriptor descriptor = new SubmodelDescriptorFactory(submodel, aasRepositoryURL, attributeMapper).create(); SubmodelRegistryApi registryApi = submodelRepositoryRegistryLink.getRegistryApi(); try { registryApi.postSubmodelDescriptor(descriptor); - logger.info("Submodel {} has been automatically linked with the Registry", submodel.getId()); + logger.info("Submodel '{}' has been automatically linked with the Registry", submodel.getId()); } catch (ApiException e) { e.printStackTrace(); @@ -177,6 +180,12 @@ private void integrateSubmodelWithRegistry(Submodel submodel, String aasReposito private void deleteFromRegistry(String submodelId) { SubmodelRegistryApi registryApi = submodelRepositoryRegistryLink.getRegistryApi(); + + if (!submodelExistsOnRegistry(submodelId, registryApi)) { + logger.error("Unable to un-link the Submodel descriptor '{}' from the Registry because it does not exist on the Registry.", submodelId); + + return; + } try { registryApi.deleteSubmodelDescriptorById(submodelId); @@ -188,5 +197,15 @@ private void deleteFromRegistry(String submodelId) { throw new RepositoryRegistryUnlinkException(submodelId); } } + + private boolean submodelExistsOnRegistry(String submodelId, SubmodelRegistryApi registryApi) { + try { + registryApi.getSubmodelDescriptorById(submodelId); + + return true; + } catch (ApiException e) { + return false; + } + } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryConfiguration.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryConfiguration.java index 02eccf036..abb3341e2 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryConfiguration.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryConfiguration.java @@ -27,12 +27,15 @@ import org.eclipse.digitaltwin.basyx.submodelregistry.client.api.SubmodelRegistryApi; import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepository; +import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.AttributeMapper; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import com.fasterxml.jackson.databind.ObjectMapper; + /** * Configuration for integrating {@link SubmodelRepository} with SubmodelRegistry * @@ -44,9 +47,16 @@ public class RegistryIntegrationSubmodelRepositoryConfiguration { @Bean @ConditionalOnMissingBean - public SubmodelRepositoryRegistryLink getAasRepositoryRegistryLink(@Value("${basyx.submodelrepository.feature.registryintegration}") String registryBasePath, @Value("${basyx.externalurl}") String submodelRepositoryBaseURL) { + public SubmodelRepositoryRegistryLink getSubmodelRepositoryRegistryLink(@Value("${basyx.submodelrepository.feature.registryintegration}") String registryBasePath, @Value("${basyx.externalurl}") String submodelRepositoryBaseURL) { return new SubmodelRepositoryRegistryLink(new SubmodelRegistryApi(registryBasePath), submodelRepositoryBaseURL); } + + @Bean + @ConditionalOnMissingBean + public AttributeMapper getSubmodelAttributeMapper(ObjectMapper objectMapper) { + + return new AttributeMapper(objectMapper); + } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFactory.java index 9a15c9c21..7a01eac01 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFactory.java @@ -27,6 +27,7 @@ import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepository; import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepositoryFactory; +import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.AttributeMapper; /** * Factory for creating {@link RegistryIntegrationSubmodelRepository} @@ -37,15 +38,17 @@ public class RegistryIntegrationSubmodelRepositoryFactory implements SubmodelRep private SubmodelRepositoryFactory decorated; private SubmodelRepositoryRegistryLink submodelRepositoryRegistryLink; + private AttributeMapper attributeMapper; - public RegistryIntegrationSubmodelRepositoryFactory(SubmodelRepositoryFactory decorated, SubmodelRepositoryRegistryLink submodelRepositoryRegistryLink) { + public RegistryIntegrationSubmodelRepositoryFactory(SubmodelRepositoryFactory decorated, SubmodelRepositoryRegistryLink submodelRepositoryRegistryLink, AttributeMapper attributeMapper) { this.decorated = decorated; this.submodelRepositoryRegistryLink = submodelRepositoryRegistryLink; + this.attributeMapper = attributeMapper; } @Override public SubmodelRepository create() { - return new RegistryIntegrationSubmodelRepository(decorated.create(), submodelRepositoryRegistryLink); + return new RegistryIntegrationSubmodelRepository(decorated.create(), submodelRepositoryRegistryLink, attributeMapper); } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFeature.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFeature.java index 6f5102e71..bdf50882a 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFeature.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepositoryFeature.java @@ -27,6 +27,7 @@ import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepositoryFactory; import org.eclipse.digitaltwin.basyx.submodelrepository.feature.SubmodelRepositoryFeature; +import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.AttributeMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; @@ -49,15 +50,18 @@ public class RegistryIntegrationSubmodelRepositoryFeature implements SubmodelRep @Value("${basyx.externalurl:}") private String submodelRepositoryExternalBaseURL; + + private AttributeMapper attributeMapper; @Autowired - public RegistryIntegrationSubmodelRepositoryFeature(SubmodelRepositoryRegistryLink submodelRepositoryRegistryLink) { + public RegistryIntegrationSubmodelRepositoryFeature(SubmodelRepositoryRegistryLink submodelRepositoryRegistryLink, AttributeMapper attributeMapper) { this.submodelRepositoryRegistryLink = submodelRepositoryRegistryLink; + this.attributeMapper = attributeMapper; } @Override public SubmodelRepositoryFactory decorate(SubmodelRepositoryFactory submodelRepositoryFactory) { - return new RegistryIntegrationSubmodelRepositoryFactory(submodelRepositoryFactory, submodelRepositoryRegistryLink); + return new RegistryIntegrationSubmodelRepositoryFactory(submodelRepositoryFactory, submodelRepositoryRegistryLink, attributeMapper); } @Override diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java index 2df2d1a34..572fb8e31 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java @@ -40,7 +40,6 @@ import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.ProtocolInformation; import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.SubmodelDescriptor; import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.AttributeMapper; -import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.DefaultAttributeMapperFactory; /** * Factory for creating the {@link SubmodelDescriptor} @@ -57,11 +56,11 @@ public class SubmodelDescriptorFactory { private AttributeMapper attributeMapper; - public SubmodelDescriptorFactory(Submodel submodel, String submodelRepositoryBaseURL) { + public SubmodelDescriptorFactory(Submodel submodel, String submodelRepositoryBaseURL, AttributeMapper attributeMapper) { super(); this.submodel = submodel; this.submodelRepositoryURL = createSubmodelRepositoryUrl(submodelRepositoryBaseURL); - this.attributeMapper = new DefaultAttributeMapperFactory().create(); + this.attributeMapper = attributeMapper; } /** diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java deleted file mode 100644 index 36adb40d9..000000000 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/DefaultAttributeMapperFactory.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper; - -import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.DataTypeDefXsd; -import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.KeyTypes; -import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.ReferenceTypes; -import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.deserializer.DataTypeDefXsdDeserializer; -import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.deserializer.KeyTypeDeserializer; -import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.deserializer.ReferenceTypeDeserializer; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.module.SimpleModule; - -/** - * Factory for creating {@link AttributeMapper} with default {@link ObjectMapper} configurations - * - * @author danish - */ -public class DefaultAttributeMapperFactory { - - /** - * Creates the {@link AttributeMapper} with default configurations of the {@link ObjectMapper} - * - * @return default attribute mapper - */ - public AttributeMapper create() { - ObjectMapper mapper = new ObjectMapper(); - - SimpleModule keyTypesDeserModule = createDeserializerModule(KeyTypes.class, new KeyTypeDeserializer()); - - SimpleModule refTypesDeserModule = createDeserializerModule(ReferenceTypes.class, new ReferenceTypeDeserializer()); - - SimpleModule dataTypeDeserModule = createDeserializerModule(DataTypeDefXsd.class, new DataTypeDefXsdDeserializer()); - - mapper.registerModules(keyTypesDeserModule, refTypesDeserModule, dataTypeDeserModule); - - mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - - return new AttributeMapper(mapper); - } - - private SimpleModule createDeserializerModule(Class type, JsonDeserializer deserializer) { - SimpleModule moduleDeser = new SimpleModule(); - moduleDeser.addDeserializer(type, deserializer); - - return moduleDeser; - } - -} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java deleted file mode 100644 index 208b138e7..000000000 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/DataTypeDefXsdDeserializer.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.deserializer; - -import java.io.IOException; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.DataTypeDefXsd; - -import com.fasterxml.jackson.core.JacksonException; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; - -/** - * Custom deserializer for {@link DataTypeDefXsd} - * - * @author danish - */ -public class DataTypeDefXsdDeserializer extends JsonDeserializer { - - @Override - public DataTypeDefXsd deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JacksonException { - try { - JsonNode node = parser.getCodec() - .readTree(parser); - - String value = node.asText(); - - String compatibleEnumValue = StringUtils.remove(value, '_'); - - return DataTypeDefXsd.valueOf(DataTypeDefXsd.class, compatibleEnumValue); - } catch (Exception e) { - throw new RuntimeException("Unable to deserialize the DataTypeDefXsd Enum."); - } - } - -} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java deleted file mode 100644 index 794c8d08f..000000000 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/KeyTypeDeserializer.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.deserializer; - -import java.io.IOException; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.KeyTypes; - -import com.fasterxml.jackson.core.JacksonException; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; - -/** - * Custom deserializer for {@link KeyTypes} - * - * @author danish - */ -public class KeyTypeDeserializer extends JsonDeserializer { - - @Override - public KeyTypes deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JacksonException { - try { - JsonNode node = parser.getCodec() - .readTree(parser); - - String value = node.asText(); - - String compatibleEnumValue = StringUtils.remove(value, '_'); - - return KeyTypes.valueOf(KeyTypes.class, compatibleEnumValue); - - } catch (Exception e) { - throw new RuntimeException("Unable to deserialize the KeyTypes Enum."); - } - } - -} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java deleted file mode 100644 index 5c853750b..000000000 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/mapper/deserializer/ReferenceTypeDeserializer.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.deserializer; - -import java.io.IOException; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.ReferenceTypes; - -import com.fasterxml.jackson.core.JacksonException; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; - -/** - * Custom deserializer for {@link ReferenceTypes} - * - * @author danish - */ -public class ReferenceTypeDeserializer extends JsonDeserializer { - - @Override - public ReferenceTypes deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JacksonException { - try { - JsonNode node = parser.getCodec() - .readTree(parser); - - String value = node.asText(); - - String compatibleEnumValue = StringUtils.remove(value, '_'); - - return ReferenceTypes.valueOf(ReferenceTypes.class, compatibleEnumValue); - - } catch (Exception e) { - throw new RuntimeException("Unable to deserialize the ReferenceTypes Enum."); - } - } - -} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationTestHelper.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationTestHelper.java index fd048c6b6..fb0de5ec0 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationTestHelper.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationTestHelper.java @@ -25,7 +25,6 @@ package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -93,7 +92,7 @@ public class RegistryIntegrationTestHelper { // Extension SMRegistry private static final org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Extension SUBMODEL_REG_EXTENSION = new org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Extension().semanticId(SUBMODEL_REG_DATASPECIFICATION).name("extension") - .valueType(DataTypeDefXsd.STRING).value("extensionValue").supplementalSemanticIds(new ArrayList<>()).refersTo(new ArrayList<>()); + .valueType(DataTypeDefXsd.STRING).value("extensionValue"); public static List getAas4jLangStringTextTypes() { return Arrays.asList(AAS4J_LANG_STRING_TEXT_TYPE_1, AAS4J_LANG_STRING_TEXT_TYPE_2); diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/TestAttributeMapper.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/TestAttributeMapper.java index 5e1f4e9b8..70c6c24cc 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/TestAttributeMapper.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/TestAttributeMapper.java @@ -27,18 +27,22 @@ import static org.junit.Assert.assertEquals; +import java.util.Arrays; import java.util.List; +import org.eclipse.digitaltwin.basyx.http.Aas4JHTTPSerializationExtension; +import org.eclipse.digitaltwin.basyx.http.BaSyxHTTPConfiguration; +import org.eclipse.digitaltwin.basyx.http.SerializationExtension; import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.AdministrativeInformation; import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Extension; import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringNameType; import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.LangStringTextType; import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Reference; import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.AttributeMapper; -import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.DefaultAttributeMapperFactory; -import org.junit.BeforeClass; import org.junit.Test; +import com.fasterxml.jackson.databind.ObjectMapper; + /** * Unit tests for {@link AttributeMapper} * @@ -46,12 +50,7 @@ */ public class TestAttributeMapper { - private static AttributeMapper attributeMapper; - - @BeforeClass - public static void setUp() { - attributeMapper = new DefaultAttributeMapperFactory().create(); - } + private static AttributeMapper attributeMapper = new AttributeMapper(configureObjectMapper()); @Test public void mapDescriptions() { @@ -110,5 +109,11 @@ public void mapSupplementalSemanticId() { assertEquals(expectedSupplementalSemanticId.size(), actualSupplementalSemanticId.size()); assertEquals(expectedSupplementalSemanticId, actualSupplementalSemanticId); } + + private static ObjectMapper configureObjectMapper() { + List extensions = Arrays.asList(new Aas4JHTTPSerializationExtension()); + + return new BaSyxHTTPConfiguration().jackson2ObjectMapperBuilder(extensions).build(); + } } diff --git a/pom.xml b/pom.xml index 184eceb72..9eaf80e57 100644 --- a/pom.xml +++ b/pom.xml @@ -16,10 +16,10 @@ basyx.common basyx.submodelservice basyx.submodelrepository - basyx.submodelregistry + basyx.aasservice basyx.aasrepository - basyx.aasregistry + basyx.aasenvironment basyx.conceptdescriptionrepository basyx.aasxfileserver From 3930feb31ee63a8e1fdf0e0708453e9298e56fd7 Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Fri, 24 Nov 2023 17:36:30 +0100 Subject: [PATCH 21/21] Minor refactoring Signed-off-by: Mohammad Ghazanfar Ali Danish --- .../integration/RegistryIntegrationSubmodelRepository.java | 4 ++-- pom.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java index d413cbf53..a25b22acf 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java @@ -162,8 +162,8 @@ public void deleteFileValue(String submodelId, String idShortPath) throws Elemen decorated.deleteFileValue(submodelId, idShortPath); } - private void integrateSubmodelWithRegistry(Submodel submodel, String aasRepositoryURL) { - SubmodelDescriptor descriptor = new SubmodelDescriptorFactory(submodel, aasRepositoryURL, attributeMapper).create(); + private void integrateSubmodelWithRegistry(Submodel submodel, String submodelRepositoryURL) { + SubmodelDescriptor descriptor = new SubmodelDescriptorFactory(submodel, submodelRepositoryURL, attributeMapper).create(); SubmodelRegistryApi registryApi = submodelRepositoryRegistryLink.getRegistryApi(); diff --git a/pom.xml b/pom.xml index 9eaf80e57..184eceb72 100644 --- a/pom.xml +++ b/pom.xml @@ -16,10 +16,10 @@ basyx.common basyx.submodelservice basyx.submodelrepository - + basyx.submodelregistry basyx.aasservice basyx.aasrepository - + basyx.aasregistry basyx.aasenvironment basyx.conceptdescriptionrepository basyx.aasxfileserver