Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements AAS and SM Repo integration with Registries feature #140

Merged
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f453762
Adds skeleton for the AAS Repo Reg Int
mdanish98 Nov 10, 2023
969ce9e
Merge branch 'main' of https://github.com/eclipse-basyx/basyx-java-se…
mdanish98 Nov 10, 2023
f754d49
Implements RegistryLink basic working part in AAS Repository
mdanish98 Nov 13, 2023
de781c7
Adds AAS Desc Factory and Clone Factory
mdanish98 Nov 13, 2023
837a2c0
Fixes LinkedHashMap issue
mdanish98 Nov 13, 2023
2bd6276
Improves attribute mapper
mdanish98 Nov 14, 2023
c027ad9
Ignores Extensions and Admin info in Descriptor
mdanish98 Nov 14, 2023
d325b89
Removes unnecessary classes and codes
mdanish98 Nov 14, 2023
2f96e55
Aas Repository Feature Ready
mdanish98 Nov 14, 2023
e4e692d
Cherry-pick + submodel reg integ
mdanish98 Nov 14, 2023
8e4c6e2
Includes admins info and Extensions
mdanish98 Nov 14, 2023
7f2a0ff
Implements AAS and SM Repo integration with Registries feature
mdanish98 Nov 14, 2023
3023197
Merge remote-tracking branch 'upstream/main' into feature/registry-in…
mdanish98 Nov 16, 2023
c044262
Minor fixes related to docker for CI failure
mdanish98 Nov 16, 2023
279dc5c
Removes pull_policy from the docker-compose
mdanish98 Nov 16, 2023
c58f19e
Updates Readme.md
mdanish98 Nov 16, 2023
e97796c
Merge remote-tracking branch 'upstream/main' into feature/registry-in…
mdanish98 Nov 23, 2023
14192f0
Sync with the latest changes
mdanish98 Nov 23, 2023
9207c8f
Removed unnecessary file
mdanish98 Nov 23, 2023
7ebd7d3
Fixes minor typos during review
jannisjung Nov 23, 2023
e0dc9b2
Resolves review remarks
mdanish98 Nov 24, 2023
dbc5a89
Minor refactoring
mdanish98 Nov 24, 2023
12471ab
Resolved review remarks
mdanish98 Nov 24, 2023
3930feb
Minor refactoring
mdanish98 Nov 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# AssetAdministrationShell Repository - Registry Integration
This feature automatically integrates the Descriptor with the Registry while creation of the Shell at Repository. <br>
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
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<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.aasrepository</artifactId>
<version>${revision}</version>
</parent>

<artifactId>basyx.aasrepository-feature-registry-integration</artifactId>

<dependencies>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.aasregistry-client-native</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.aasrepository-core</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.http</artifactId>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.http</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.aasrepository-http</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
/*******************************************************************************
* 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.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;
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;

/**
* Factory for creating the {@link AssetAdministrationShellDescriptor}
*
* @author danish
*/
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;

private AttributeMapper attributeMapper;

public AasDescriptorFactory(AssetAdministrationShell shell, String aasRepositoryBaseURL) {
super();
this.shell = shell;
this.aasRepositoryURL = createAasRepositoryUrl(aasRepositoryBaseURL);
this.attributeMapper = new DefaultAttributeMapperFactory().create();
}

/**
* 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);

setAssetKind(shell.getAssetInformation(), descriptor);

setAssetType(shell.getAssetInformation(), descriptor);

setGlobalAssetId(shell.getAssetInformation(), descriptor);

return descriptor;
}

private void setDescription(List<LangStringTextType> descriptions, AssetAdministrationShellDescriptor descriptor) {

if (descriptions == null || descriptions.isEmpty())
return;

descriptor.setDescription(attributeMapper.mapDescription(descriptions));
}

private void setDisplayName(List<LangStringNameType> displayNames, AssetAdministrationShellDescriptor descriptor) {

if (displayNames == null || displayNames.isEmpty())
return;

descriptor.setDisplayName(attributeMapper.mapDisplayName(displayNames));
}

private void setExtensions(List<Extension> extensions, AssetAdministrationShellDescriptor descriptor) {

if (extensions == null || extensions.isEmpty())
return;

descriptor.setExtensions(attributeMapper.mapExtensions(extensions));
}

private void setAdministration(AdministrativeInformation administration, AssetAdministrationShellDescriptor descriptor) {

if (administration == null)
return;

descriptor.setAdministration(attributeMapper.mapAdministration(administration));
}

private void setAssetKind(AssetInformation assetInformation, AssetAdministrationShellDescriptor descriptor) {

if (assetInformation == null || assetInformation.getAssetKind() == null)
return;

descriptor.setAssetKind(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();
}
}

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());
}
}

}
Original file line number Diff line number Diff line change
@@ -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 aasRepositoryBaseURL;

public AasRepositoryRegistryLink(RegistryAndDiscoveryInterfaceApi registryApi, String aasRepositoryBaseURL) {
super();
this.registryApi = registryApi;
this.aasRepositoryBaseURL = aasRepositoryBaseURL;
}

public RegistryAndDiscoveryInterfaceApi getRegistryApi() {
return registryApi;
}

public String getAasRepositoryBaseURL() {
return aasRepositoryBaseURL;
}

}
Loading