forked from eclipse-basyx/basyx-java-server-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement ConnectedAASManager in AASEnvironment (eclipse-basyx#278)
* wip: Add infrastructure for ConnectedAasManager * wip: Add resolvers for descriptors and Refine test for ConnectedAasManager * Implement ConnectedAasManager; Add resolver for references * Refactor dummy Descriptors creation * Add impl and tests for Resolvers * Clean up exception handling in ConnectedAasManager * Implement Reference Resolver * wip: Refactor main test as IntTest; Simplify constructor of ConnectedAasManager * Fix Test fixture and Test cases * Improve assertions in base test * Remove interface for AasManager
- Loading branch information
1 parent
fb89b35
commit ad41d18
Showing
25 changed files
with
1,678 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.eclipse.digitaltwin.basyx</groupId> | ||
<artifactId>basyx.aasenvironment</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
|
||
<name>BaSyx AAS Environment Client</name> | ||
<description>BaSyx AAS Environment Client</description> | ||
|
||
<artifactId>basyx.aasenvironment-client</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.digitaltwin.basyx</groupId> | ||
<artifactId>basyx.client</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.digitaltwin.basyx</groupId> | ||
<artifactId>basyx.aasenvironment-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.digitaltwin.basyx</groupId> | ||
<artifactId>basyx.aasrepository-client</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.digitaltwin.basyx</groupId> | ||
<artifactId>basyx.aasservice-client</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.digitaltwin.basyx</groupId> | ||
<artifactId>basyx.aasrepository-feature-registry-integration</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.digitaltwin.basyx</groupId> | ||
<artifactId>basyx.aasrepository-feature-registry-integration</artifactId> | ||
<classifier>tests</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.digitaltwin.basyx</groupId> | ||
<artifactId>basyx.submodelrepository-client</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.digitaltwin.basyx</groupId> | ||
<artifactId>basyx.submodelrepository-feature-registry-integration</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.digitaltwin.basyx</groupId> | ||
<artifactId>basyx.submodelrepository-feature-registry-integration</artifactId> | ||
<classifier>tests</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.digitaltwin.basyx</groupId> | ||
<artifactId>basyx.aasenvironment-core</artifactId> | ||
<classifier>tests</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.digitaltwin.basyx</groupId> | ||
<artifactId>basyx.aasregistry-client-native</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.digitaltwin.basyx</groupId> | ||
<artifactId>basyx.submodelregistry-client-native</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
200 changes: 200 additions & 0 deletions
200
...rc/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/ConnectedAasManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
/******************************************************************************* | ||
* Copyright (C) 2024 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.aasenvironment.client; | ||
|
||
import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.util.AasUtils; | ||
import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; | ||
import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; | ||
import org.eclipse.digitaltwin.basyx.aasenvironment.client.exceptions.NoValidEndpointFoundException; | ||
import org.eclipse.digitaltwin.basyx.aasenvironment.client.exceptions.RegistryHttpRequestException; | ||
import org.eclipse.digitaltwin.basyx.aasenvironment.client.resolvers.AasDescriptorResolver; | ||
import org.eclipse.digitaltwin.basyx.aasenvironment.client.resolvers.SubmodelDescriptorResolver; | ||
import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; | ||
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.submodelregistry.client.api.SubmodelRegistryApi; | ||
import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.SubmodelDescriptor; | ||
import org.eclipse.digitaltwin.basyx.submodelrepository.client.ConnectedSubmodelRepository; | ||
import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.SubmodelDescriptorFactory; | ||
|
||
/** | ||
* Client component for executing consolidated Repository and Registry requests | ||
* | ||
* @author mateusmolina | ||
* | ||
*/ | ||
public class ConnectedAasManager { | ||
|
||
private final ConnectedAasRepository aasRepository; | ||
private final ConnectedSubmodelRepository smRepository; | ||
|
||
private final RegistryAndDiscoveryInterfaceApi aasRegistryApi; | ||
private final SubmodelRegistryApi smRegistryApi; | ||
|
||
private final AasDescriptorResolver aasDescriptorResolver; | ||
private final AasDescriptorFactory aasDescriptorFactory; | ||
|
||
private final SubmodelDescriptorResolver smDescriptorResolver; | ||
private final SubmodelDescriptorFactory smDescriptorFactory; | ||
|
||
/** | ||
* Default constructor for a {@link ConnectedAasManager} instance | ||
* | ||
* @param aasRegistryBaseUrl | ||
* @param aasRepositoryBaseUrl | ||
* @param submodelRegistryBaseUrl | ||
* @param submodelBaseRepositoryUrl | ||
*/ | ||
public ConnectedAasManager(String aasRegistryBaseUrl, String aasRepositoryBaseUrl, String submodelRegistryBaseUrl, String submodelBaseRepositoryUrl) { | ||
this(new RegistryAndDiscoveryInterfaceApi(aasRegistryBaseUrl), new ConnectedAasRepository(aasRepositoryBaseUrl), aasRepositoryBaseUrl, new SubmodelRegistryApi(submodelRegistryBaseUrl), | ||
new ConnectedSubmodelRepository(submodelBaseRepositoryUrl), submodelBaseRepositoryUrl); | ||
} | ||
|
||
ConnectedAasManager(RegistryAndDiscoveryInterfaceApi aasRegistryApi, ConnectedAasRepository aasRepository, String aasRepositoryBaseUrl, SubmodelRegistryApi smRegistryApi, ConnectedSubmodelRepository smRepository, | ||
String submodelBaseRepositoryUrl) { | ||
this.aasRepository = aasRepository; | ||
this.aasRegistryApi = aasRegistryApi; | ||
this.smRepository = smRepository; | ||
this.smRegistryApi = smRegistryApi; | ||
this.aasDescriptorResolver = ConnectedAasManagerHelper.buildAasDescriptorResolver(); | ||
this.aasDescriptorFactory = ConnectedAasManagerHelper.buildAasDescriptorFactory(aasRepositoryBaseUrl); | ||
this.smDescriptorResolver = ConnectedAasManagerHelper.buildSubmodelDescriptorResolver(); | ||
this.smDescriptorFactory = ConnectedAasManagerHelper.buildSmDescriptorFactory(submodelBaseRepositoryUrl); | ||
} | ||
|
||
/** | ||
* Retrieves an AAS in an AAS registry by its identifier. | ||
* | ||
* @param identifier | ||
* The identifier of the AAS to retrieve. | ||
* @return The retrieved AAS object. | ||
*/ | ||
public AssetAdministrationShell getAas(String identifier) throws NoValidEndpointFoundException { | ||
AssetAdministrationShellDescriptor descriptor; | ||
|
||
try { | ||
descriptor = aasRegistryApi.getAssetAdministrationShellDescriptorById(identifier); | ||
} catch (Exception e) { | ||
throw new RegistryHttpRequestException(identifier, e); | ||
} | ||
return aasDescriptorResolver.resolveAasDescriptor(descriptor); | ||
} | ||
|
||
/** | ||
* Retrieves a Submodel in a Submodel registry by its identifier. | ||
* | ||
* @param identifier | ||
* The identifier of the submodel to retrieve. | ||
* @return The retrieved Submodel object. | ||
*/ | ||
public Submodel getSubmodel(String identifier) { | ||
SubmodelDescriptor descriptor; | ||
|
||
try { | ||
descriptor = smRegistryApi.getSubmodelDescriptorById(identifier); | ||
} catch (Exception e) { | ||
throw new RegistryHttpRequestException(identifier, e); | ||
} | ||
|
||
return smDescriptorResolver.resolveSubmodelDescriptor(descriptor); | ||
} | ||
|
||
/** | ||
* Deletes an AAS by its identifier. | ||
* | ||
* @param identifier | ||
* The identifier of the AAS to delete. | ||
*/ | ||
public void deleteAas(String identifier) { | ||
try { | ||
aasRegistryApi.deleteAssetAdministrationShellDescriptorById(identifier); | ||
} catch (Exception e) { | ||
throw new RegistryHttpRequestException(identifier, e); | ||
} | ||
|
||
aasRepository.deleteAas(identifier); | ||
} | ||
|
||
/** | ||
* Deletes a submodel associated with a specified AAS. | ||
* | ||
* @param aasIdentifier | ||
* The identifier of the AAS. | ||
* @param smIdentifier | ||
* The identifier of the submodel to delete. | ||
*/ | ||
public void deleteSubmodelOfAas(String aasIdentifier, String smIdentifier) { | ||
try { | ||
smRegistryApi.deleteSubmodelDescriptorById(smIdentifier); | ||
} catch (Exception e) { | ||
throw new RegistryHttpRequestException(aasIdentifier, e); | ||
} | ||
|
||
aasRepository.removeSubmodelReference(aasIdentifier, smIdentifier); | ||
smRepository.deleteSubmodel(smIdentifier); | ||
} | ||
|
||
/** | ||
* Creates a new AAS | ||
* | ||
* @param aas | ||
* The AAS object to create. | ||
*/ | ||
public void createAas(AssetAdministrationShell aas) { | ||
aasRepository.createAas(aas); | ||
AssetAdministrationShellDescriptor descriptor = aasDescriptorFactory.create(aas); | ||
|
||
try { | ||
aasRegistryApi.postAssetAdministrationShellDescriptor(descriptor); | ||
} catch (Exception e) { | ||
throw new RegistryHttpRequestException(aas.getId(), e); | ||
} | ||
} | ||
|
||
/** | ||
* Creates a submodel under a specified AAS. | ||
* | ||
* @param aasIdentifier | ||
* The identifier of the AAS. | ||
* @param submodel | ||
* The Submodel object to create under the specified AAS. | ||
*/ | ||
public void createSubmodelInAas(String aasIdentifier, Submodel submodel) { | ||
smRepository.createSubmodel(submodel); | ||
SubmodelDescriptor descriptor = smDescriptorFactory.create(submodel); | ||
|
||
try { | ||
smRegistryApi.postSubmodelDescriptor(descriptor); | ||
} catch (Exception e) { | ||
throw new RegistryHttpRequestException(aasIdentifier, e); | ||
} | ||
|
||
aasRepository.addSubmodelReference(aasIdentifier, AasUtils.toReference(submodel)); | ||
} | ||
|
||
} | ||
|
83 changes: 83 additions & 0 deletions
83
...n/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/ConnectedAasManagerHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/******************************************************************************* | ||
* Copyright (C) 2024 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.aasenvironment.client; | ||
|
||
|
||
import org.eclipse.digitaltwin.basyx.aasenvironment.client.resolvers.AasDescriptorResolver; | ||
import org.eclipse.digitaltwin.basyx.aasenvironment.client.resolvers.EndpointResolver; | ||
import org.eclipse.digitaltwin.basyx.aasenvironment.client.resolvers.SubmodelDescriptorResolver; | ||
import org.eclipse.digitaltwin.basyx.aasenvironment.client.resolvers.parsers.AasRegistryEndpointURIParser; | ||
import org.eclipse.digitaltwin.basyx.aasenvironment.client.resolvers.parsers.SubmodelRegistryEndpointURIParser; | ||
import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.AasDescriptorFactory; | ||
import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.AttributeMapper; | ||
import org.eclipse.digitaltwin.basyx.http.Aas4JHTTPSerializationExtension; | ||
import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.SubmodelDescriptorFactory; | ||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
/** | ||
* Provides builder methods for {@link ConnectedAasManager} dependencies | ||
* | ||
* @author mateusmolina | ||
* | ||
*/ | ||
class ConnectedAasManagerHelper { | ||
|
||
public static final ObjectMapper objectMapper = buildObjectMapper(); | ||
|
||
private ConnectedAasManagerHelper() { | ||
} | ||
|
||
public static ObjectMapper buildObjectMapper() { | ||
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder().serializationInclusion(JsonInclude.Include.NON_NULL); | ||
Aas4JHTTPSerializationExtension extension = new Aas4JHTTPSerializationExtension(); | ||
extension.extend(builder); | ||
return builder.build(); | ||
} | ||
|
||
public static AasDescriptorResolver buildAasDescriptorResolver() { | ||
return new AasDescriptorResolver(new EndpointResolver<>(new AasRegistryEndpointURIParser())); | ||
} | ||
|
||
public static SubmodelDescriptorResolver buildSubmodelDescriptorResolver() { | ||
return new SubmodelDescriptorResolver(new EndpointResolver<>(new SubmodelRegistryEndpointURIParser())); | ||
} | ||
|
||
public static AasDescriptorFactory buildAasDescriptorFactory(String aasRepositoryBaseUrl) { | ||
AttributeMapper attributeMapper = new AttributeMapper(objectMapper); | ||
|
||
return new AasDescriptorFactory(null, aasRepositoryBaseUrl, attributeMapper); | ||
} | ||
|
||
public static SubmodelDescriptorFactory buildSmDescriptorFactory(String aasRepositoryBaseUrl) { | ||
org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.AttributeMapper attributeMapperSm = new org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.mapper.AttributeMapper( | ||
objectMapper); | ||
return new SubmodelDescriptorFactory(null, aasRepositoryBaseUrl, attributeMapperSm); | ||
} | ||
|
||
} |
Oops, something went wrong.