diff --git a/basyx.aasenvironment/basyx.aasenvironment-client/src/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/ConnectedAasManager.java b/basyx.aasenvironment/basyx.aasenvironment-client/src/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/ConnectedAasManager.java index ab0a5f74d..f71b13014 100644 --- a/basyx.aasenvironment/basyx.aasenvironment-client/src/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/ConnectedAasManager.java +++ b/basyx.aasenvironment/basyx.aasenvironment-client/src/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/ConnectedAasManager.java @@ -45,8 +45,8 @@ import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor; import org.eclipse.digitaltwin.basyx.aasrepository.client.ConnectedAasRepository; import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.AasDescriptorFactory; -import org.eclipse.digitaltwin.basyx.client.internal.resolver.DescriptorResolver; import org.eclipse.digitaltwin.basyx.aasservice.client.ConnectedAasService; +import org.eclipse.digitaltwin.basyx.client.internal.resolver.DescriptorResolver; import org.eclipse.digitaltwin.basyx.submodelregistry.client.api.SubmodelRegistryApi; import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.SubmodelDescriptor; import org.eclipse.digitaltwin.basyx.submodelrepository.client.ConnectedSubmodelRepository; @@ -212,6 +212,8 @@ public void createAas(AssetAdministrationShell aas) { * The Submodel object to create under the specified AAS. */ public void createSubmodelInAas(String aasIdentifier, Submodel submodel) { + AssetAdministrationShell shell = getAasService(aasIdentifier).getAAS(); + smRepository.createSubmodel(submodel); SubmodelDescriptor descriptor = smDescriptorFactory.create(submodel); @@ -221,7 +223,12 @@ public void createSubmodelInAas(String aasIdentifier, Submodel submodel) { throw new RegistryHttpRequestException(aasIdentifier, e); } - aasRepository.addSubmodelReference(aasIdentifier, AasUtils.toReference(submodel)); + Reference smRef = AasUtils.toReference(AasUtils.toReference(shell), submodel); + + // TODO See https://github.com/eclipse-aas4j/aas4j/issues/308 + smRef.setReferredSemanticId(submodel.getSemanticId()); + + aasRepository.addSubmodelReference(aasIdentifier, smRef); } private String extractSubmodelIdentifierFromReference(Reference submodelReference) { diff --git a/basyx.aasenvironment/basyx.aasenvironment-client/src/test/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/TestConnectedAasManager.java b/basyx.aasenvironment/basyx.aasenvironment-client/src/test/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/TestConnectedAasManager.java index 5263c68e6..446c8ac26 100644 --- a/basyx.aasenvironment/basyx.aasenvironment-client/src/test/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/TestConnectedAasManager.java +++ b/basyx.aasenvironment/basyx.aasenvironment-client/src/test/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/TestConnectedAasManager.java @@ -35,9 +35,11 @@ import java.util.Arrays; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; import org.eclipse.digitaltwin.basyx.aasenvironment.client.exceptions.NoValidEndpointFoundException; import org.eclipse.digitaltwin.basyx.aasenvironment.client.resolvers.AasDescriptorResolver; @@ -73,16 +75,16 @@ * */ public class TestConnectedAasManager { - protected final static String AAS_REPOSITORY_BASE_PATH = "http://localhost:8081"; - protected final static String SM_REPOSITORY_BASE_PATH = "http://localhost:8081"; - protected final static String AAS_REGISTRY_BASE_PATH = "http://localhost:8050"; - protected final static String SM_REGISTRY_BASE_PATH = "http://localhost:8060"; + protected static final String AAS_REPOSITORY_BASE_PATH = "http://localhost:8081"; + protected static final String SM_REPOSITORY_BASE_PATH = "http://localhost:8081"; + protected static final String AAS_REGISTRY_BASE_PATH = "http://localhost:8050"; + protected static final String SM_REGISTRY_BASE_PATH = "http://localhost:8060"; protected static ConfigurableApplicationContext appContext; protected static AasRepository aasRepository; protected static SubmodelRepository smRepository; - protected final static TestFixture FIXTURE = new TestFixture(AAS_REPOSITORY_BASE_PATH, SM_REPOSITORY_BASE_PATH); + protected static final TestFixture FIXTURE = new TestFixture(AAS_REPOSITORY_BASE_PATH, SM_REPOSITORY_BASE_PATH); protected static ConnectedAasRepository connectedAasRepository; protected static ConnectedSubmodelRepository connectedSmRepository; @@ -146,20 +148,19 @@ public void createAas() throws ApiException { public void createSubmodelInAas() throws Exception { Submodel expectedSm = FIXTURE.buildSmPos1(); SubmodelDescriptor expectedDescriptor = FIXTURE.buildSmPos1Descriptor(); + Reference expectedRef = FIXTURE.buildSmPos1Ref(); aasManager.createSubmodelInAas(TestFixture.AAS_PRE1_ID, expectedSm); InOrder inOrder = inOrder(connectedSmRepository, smRegistryApi, connectedAasRepository); - inOrder.verify(connectedSmRepository, times(1)) - .createSubmodel(expectedSm); - inOrder.verify(smRegistryApi, times(1)) - .postSubmodelDescriptor(expectedDescriptor); - inOrder.verify(connectedAasRepository, times(1)) - .addSubmodelReference(eq(TestFixture.AAS_PRE1_ID), any()); + inOrder.verify(connectedSmRepository, times(1)).createSubmodel(expectedSm); + inOrder.verify(smRegistryApi, times(1)).postSubmodelDescriptor(expectedDescriptor); + inOrder.verify(connectedAasRepository, times(1)).addSubmodelReference(eq(TestFixture.AAS_PRE1_ID), any()); assertEquals(expectedSm, getSubmodelFromRepo(TestFixture.SM_POS1_ID)); assertEquals(expectedDescriptor, getDescriptorFromSubmodelRegistry(TestFixture.SM_POS1_ID)); + assertEquals(expectedRef, getSubmodelRefFromAasRepository(TestFixture.AAS_PRE1_ID, TestFixture.SM_POS1_ID).get()); } @Test @@ -195,7 +196,7 @@ public void deleteSubmodelOfAas() throws Exception { } @Test - public void getAas() throws ApiException, NoValidEndpointFoundException { + public void getAas() throws NoValidEndpointFoundException { AssetAdministrationShell expectedAas = FIXTURE.buildAasPre1(); AssetAdministrationShell actualAas = aasManager.getAasService(TestFixture.AAS_PRE1_ID) @@ -205,7 +206,7 @@ public void getAas() throws ApiException, NoValidEndpointFoundException { } @Test - public void getSubmodel() throws Exception { + public void getSubmodel() { Submodel expectedSm = FIXTURE.buildSmPre1(); Submodel actualSm = aasManager.getSubmodelService(TestFixture.SM_PRE1_ID) @@ -340,4 +341,14 @@ protected void cleanUpRepositories() { } } + private Optional getSubmodelRefFromAasRepository(String aasId, String smId) { + return aasManager.getAasService(aasId) + .getAAS() + .getSubmodels() + .stream() + .filter(ref -> ref.getKeys().stream() + .anyMatch(key -> key.getValue().equals(smId))) + .findAny(); + } + } diff --git a/basyx.aasenvironment/basyx.aasenvironment-client/src/test/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/TestFixture.java b/basyx.aasenvironment/basyx.aasenvironment-client/src/test/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/TestFixture.java index 1947c78e0..359b5eb9b 100644 --- a/basyx.aasenvironment/basyx.aasenvironment-client/src/test/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/TestFixture.java +++ b/basyx.aasenvironment/basyx.aasenvironment-client/src/test/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/TestFixture.java @@ -42,6 +42,7 @@ import org.eclipse.digitaltwin.basyx.http.Base64UrlEncoder; import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.SubmodelDescriptor; import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.DummySubmodelDescriptorFactory; +import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.AttributeMapper; /** * Test fixture for {@link ConnectedAasManager} and related Components @@ -68,6 +69,7 @@ public class TestFixture { public static final String SM_POS1_ID = "smPos1"; public static final String SM_POS1_ID_ENCODED = Base64UrlEncoder.encode(SM_POS1_ID); public static final String SM_POS1_IDSHORT = "smPos1IdShort"; + public static final String SM_POS1_SEMANTICID = "smPos1SemanticId"; private final String aasRepositoryBasePath; private final String smRepositoryBasePath; @@ -114,11 +116,19 @@ public AssetAdministrationShellDescriptor buildAasPos1Descriptor() { } public SubmodelDescriptor buildSmPos1Descriptor() { - return DummySubmodelDescriptorFactory.createDummyDescriptor(SM_POS1_ID, SM_POS1_IDSHORT, smRepositoryBasePath, null); + return DummySubmodelDescriptorFactory.createDummyDescriptor(SM_POS1_ID, SM_POS1_IDSHORT, smRepositoryBasePath, new AttributeMapper(ConnectedAasManagerHelper.buildObjectMapper()).mapSemanticId(buildSmPos1SemanticId())); + } + + public Reference buildSmPos1SemanticId() { + return new DefaultReference.Builder().type(ReferenceTypes.EXTERNAL_REFERENCE).keys(new DefaultKey.Builder().type(KeyTypes.GLOBAL_REFERENCE).value("https://admin-shell.io/aas/3/0/CustomDataSpecification").build()).build(); } public Submodel buildSmPos1() { - return new DefaultSubmodel.Builder().id(SM_POS1_ID).idShort(SM_POS1_IDSHORT).build(); + return new DefaultSubmodel.Builder().id(SM_POS1_ID).idShort(SM_POS1_IDSHORT).semanticId(buildSmPos1SemanticId()).build(); + } + + public Reference buildSmPos1Ref() { + return new DefaultReference.Builder().type(ReferenceTypes.MODEL_REFERENCE).referredSemanticId(buildSmPos1SemanticId()).keys(new DefaultKey.Builder().type(KeyTypes.SUBMODEL).value(SM_POS1_ID).build()).build(); } }