Skip to content

Commit

Permalink
Merge branch 'main' into op-fork/jakarta-contribution
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgordtop committed Nov 30, 2023
2 parents b8c4c7b + 3029208 commit 42ed13e
Show file tree
Hide file tree
Showing 46 changed files with 3,773 additions and 7 deletions.
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, the following two properties should be configured:

```
basyx.aasrepository.feature.registryintegration = {AAS-Registry-Base-Url}
basyx.externalurl = {AAS-Repo-Base-Url}
```

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
```
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,199 @@
/*******************************************************************************
* 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.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, AttributeMapper attributeMapper) {
super();
this.shell = shell;
this.aasRepositoryURL = createAasRepositoryUrl(aasRepositoryBaseURL);
this.attributeMapper = attributeMapper;
}

/**
* 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.\n" + 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

0 comments on commit 42ed13e

Please sign in to comment.