Skip to content

Commit

Permalink
Merge branch 'eclipse-basyx:main' into buildImprovement
Browse files Browse the repository at this point in the history
  • Loading branch information
FriedJannik authored Aug 28, 2024
2 parents a5fc976 + b34d232 commit 1321775
Show file tree
Hide file tree
Showing 71 changed files with 1,744 additions and 419 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,99 +27,63 @@

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.StreamSupport;

import org.eclipse.digitaltwin.aas4j.v3.model.SpecificAssetId;
import org.eclipse.digitaltwin.basyx.aasdiscoveryservice.backend.AasDiscoveryDocument;
import org.eclipse.digitaltwin.basyx.aasdiscoveryservice.core.model.AssetLink;
import org.springframework.data.repository.CrudRepository;
import org.springframework.lang.NonNull;

/**
* In-memory implementation of the {@link CrudRepository} for the AAS Discovery
*
* @author zielstor, fried
* @author zielstor, fried, mateusmolina
*/
public class AasDiscoveryInMemoryCrudRepository implements CrudRepository<AasDiscoveryDocument, String> {

private final Map<String, Set<AssetLink>> assetLinks = new LinkedHashMap<>();
private final Map<String, List<SpecificAssetId>> assetIds = new LinkedHashMap<>();
private final ConcurrentMap<String, Set<AssetLink>> assetLinks = new ConcurrentHashMap<>();
private final ConcurrentMap<String, List<SpecificAssetId>> assetIds = new ConcurrentHashMap<>();

@Override
public <S extends AasDiscoveryDocument> S save(S entity) {
Set<AssetLink> assetLinks = entity.getAssetLinks();
List<SpecificAssetId> assetIds = entity.getSpecificAssetIds();
public synchronized @NonNull <S extends AasDiscoveryDocument> S save(@NonNull S entity) {
String shellId = entity.getShellIdentifier();

this.assetLinks.put(shellId, assetLinks);
this.assetIds.put(shellId, assetIds);
this.assetLinks.put(shellId, entity.getAssetLinks());
this.assetIds.put(shellId, entity.getSpecificAssetIds());

return entity;
}

@Override
public <S extends AasDiscoveryDocument> Iterable<S> saveAll(Iterable<S> entities) {
for (S entity : entities) {
this.save(entity);
}
public @NonNull <S extends AasDiscoveryDocument> Iterable<S> saveAll(@NonNull Iterable<S> entities) {
entities.forEach(this::save);
return entities;
}

@Override
public Optional<AasDiscoveryDocument> findById(String id) {
Set<AssetLink> assetLinks = this.assetLinks.get(id);
List<SpecificAssetId> assetIds = this.assetIds.get(id);
if (assetIds == null) {
assetIds = new ArrayList<>();
}

if (assetLinks == null) {
assetLinks = new HashSet<>();
}
return Optional.of(new AasDiscoveryDocument(id, assetLinks, assetIds));
public @NonNull Optional<AasDiscoveryDocument> findById(@NonNull String id) {
return Optional.ofNullable(buildAasDiscoveryDocument(id));
}

@Override
public boolean existsById(String id) {
public boolean existsById(@NonNull String id) {
return this.assetLinks.containsKey(id);
}

@Override
public Iterable<AasDiscoveryDocument> findAll() {
List<AasDiscoveryDocument> result = new ArrayList<>();
for (String shellId : this.assetLinks.keySet()) {
Set<AssetLink> assetLinks = this.assetLinks.get(shellId);
List<SpecificAssetId> assetIds = this.assetIds.get(shellId);
if (assetIds == null) {
assetIds = new ArrayList<>();
}

if (assetLinks == null) {
assetLinks = new HashSet<>();
}
result.add(new AasDiscoveryDocument(shellId, assetLinks, assetIds));
}
return result;
public @NonNull Iterable<AasDiscoveryDocument> findAll() {
return assetLinks.keySet().stream().map(this::buildAasDiscoveryDocument).toList();
}

@Override
public Iterable<AasDiscoveryDocument> findAllById(Iterable<String> ids) {
List<AasDiscoveryDocument> result = new ArrayList<>();
for (String id : ids) {
Set<AssetLink> assetLinks = this.assetLinks.get(id);
List<SpecificAssetId> assetIds = this.assetIds.get(id);
if (assetIds == null) {
assetIds = new ArrayList<>();
}

if (assetLinks == null) {
assetLinks = new HashSet<>();
}
result.add(new AasDiscoveryDocument(id, assetLinks, assetIds));
}
return result;
public @NonNull Iterable<AasDiscoveryDocument> findAllById(@NonNull Iterable<String> ids) {
return StreamSupport.stream(ids.spliterator(), false).map(this::buildAasDiscoveryDocument).toList();
}

@Override
Expand All @@ -128,34 +92,47 @@ public long count() {
}

@Override
public void deleteById(String id) {
public synchronized void deleteById(@NonNull String id) {
this.assetLinks.remove(id);
this.assetIds.remove(id);
}

@Override
public void delete(AasDiscoveryDocument entity) {
public void delete(@NonNull AasDiscoveryDocument entity) {
this.deleteById(entity.getShellIdentifier());
}

@Override
public void deleteAllById(Iterable<? extends String> ids) {
public void deleteAllById(@NonNull Iterable<? extends String> ids) {
for (String id : ids) {
this.deleteById(id);
}
}

@Override
public void deleteAll(Iterable<? extends AasDiscoveryDocument> entities) {
public void deleteAll(@NonNull Iterable<? extends AasDiscoveryDocument> entities) {
for (AasDiscoveryDocument entity : entities) {
this.deleteById(entity.getShellIdentifier());
}
}

@Override
public void deleteAll() {
public synchronized void deleteAll() {
this.assetLinks.clear();
this.assetIds.clear();
}

private synchronized AasDiscoveryDocument buildAasDiscoveryDocument(String shellId) {
Set<AssetLink> assetLinksSet = assetLinks.get(shellId);
List<SpecificAssetId> assetIdsList = assetIds.get(shellId);

if (assetIdsList == null)
assetIdsList = new ArrayList<>();

if (assetLinksSet == null)
assetLinksSet = new HashSet<>();

return new AasDiscoveryDocument(shellId, assetLinksSet, assetIdsList);
}

}
22 changes: 7 additions & 15 deletions basyx.aasenvironment/basyx.aasenvironment-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +34,33 @@
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.aasrepository-feature-registry-integration</artifactId>
<artifactId>basyx.submodelrepository-client</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.aasrepository-feature-registry-integration</artifactId>
<artifactId>basyx.aasenvironment-core</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.submodelrepository-client</artifactId>
<artifactId>basyx.aasregistry-client-native</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.submodelrepository-feature-registry-integration</artifactId>
<artifactId>basyx.submodelregistry-client-native</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.submodelrepository-feature-registry-integration</artifactId>
<classifier>tests</classifier>
<artifactId>basyx.aasregistry-client-native</artifactId>
<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>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
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.aasregistry.main.client.factory.AasDescriptorFactory;
import org.eclipse.digitaltwin.basyx.aasrepository.client.ConnectedAasRepository;
import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.AasDescriptorFactory;
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.factory.SubmodelDescriptorFactory;
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;
import org.eclipse.digitaltwin.basyx.submodelservice.client.ConnectedSubmodelService;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
package org.eclipse.digitaltwin.basyx.aasenvironment.client;


import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.AasDescriptorFactory;
import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.AttributeMapper;
import java.util.List;

import org.eclipse.digitaltwin.basyx.aasregistry.main.client.factory.AasDescriptorFactory;
import org.eclipse.digitaltwin.basyx.aasregistry.main.client.mapper.AttributeMapper;
import org.eclipse.digitaltwin.basyx.http.Aas4JHTTPSerializationExtension;
import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.SubmodelDescriptorFactory;
import org.eclipse.digitaltwin.basyx.submodelregistry.client.factory.SubmodelDescriptorFactory;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

import com.fasterxml.jackson.annotation.JsonInclude;
Expand All @@ -55,16 +57,16 @@ static ObjectMapper buildObjectMapper() {
return builder.build();
}

static AasDescriptorFactory buildAasDescriptorFactory(String aasRepositoryBaseUrl) {
static AasDescriptorFactory buildAasDescriptorFactory(String... aasRepositoryBaseUrls) {
AttributeMapper attributeMapper = new AttributeMapper(objectMapper);

return new AasDescriptorFactory(null, aasRepositoryBaseUrl, attributeMapper);
return new AasDescriptorFactory(null, List.of(aasRepositoryBaseUrls), attributeMapper);
}

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(
static SubmodelDescriptorFactory buildSmDescriptorFactory(String... aasRepositoryBaseUrls) {
org.eclipse.digitaltwin.basyx.submodelregistry.client.mapper.AttributeMapper attributeMapperSm = new org.eclipse.digitaltwin.basyx.submodelregistry.client.mapper.AttributeMapper(
objectMapper);
return new SubmodelDescriptorFactory(null, aasRepositoryBaseUrl, attributeMapperSm);
return new SubmodelDescriptorFactory(null, List.of(aasRepositoryBaseUrls), attributeMapperSm);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultReference;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodel;
import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor;
import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.DummyAasDescriptorFactory;
import org.eclipse.digitaltwin.basyx.aasregistry.main.client.mapper.DummyAasDescriptorFactory;
import org.eclipse.digitaltwin.basyx.http.Base64UrlEncoder;
import org.eclipse.digitaltwin.basyx.submodelregistry.client.mapper.AttributeMapper;
import org.eclipse.digitaltwin.basyx.submodelregistry.client.mapper.DummySubmodelDescriptorFactory;
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
Expand Down
4 changes: 2 additions & 2 deletions basyx.aasregistry/basyx.aasregistry-client-native/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ This is the generated java openAPI client (based on native java with jackson par
To use the client in your maven projects define the following dependency:
```xml
<dependency>
<groupId>org.eclipse.digitaltwin.basyx.aasregistry</groupId>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.aasregistry-client-native</artifactId>
</dependency>
```

If you also want to use the search API we highly recommend that you also include the search path builder class:
```xml
<dependency>
<groupId>dorg.eclipse.digitaltwin.basyx.aasregistry</groupId>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.aasregistry-paths</artifactId>
</dependency>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
* SPDX-License-Identifier: MIT
******************************************************************************/

package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration;
package org.eclipse.digitaltwin.basyx.aasregistry.main.client.factory;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation;
Expand All @@ -38,7 +39,7 @@
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.aasregistry.main.client.mapper.AttributeMapper;
import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier;

/**
Expand All @@ -50,16 +51,15 @@ 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 List<String> aasRepositoryURLs;

private AttributeMapper attributeMapper;

public AasDescriptorFactory(AssetAdministrationShell shell, String aasRepositoryBaseURL, AttributeMapper attributeMapper) {
super();
public AasDescriptorFactory(AssetAdministrationShell shell, List<String> aasRepositoryBaseURLs, AttributeMapper attributeMapper) {
this.shell = shell;
this.aasRepositoryURL = createAasRepositoryUrl(aasRepositoryBaseURL);
this.aasRepositoryURLs = createAasRepositoryUrls(aasRepositoryBaseURLs);
this.attributeMapper = attributeMapper;
}

Expand Down Expand Up @@ -157,17 +157,18 @@ private void setGlobalAssetId(AssetInformation assetInformation, AssetAdministra
}

private void setEndpointItem(String shellId, AssetAdministrationShellDescriptor descriptor) {
for (String eachUrl : aasRepositoryURLs) {
Endpoint endpoint = new Endpoint();
endpoint.setInterface(AAS_INTERFACE);
ProtocolInformation protocolInformation = createProtocolInformation(shellId, eachUrl);
endpoint.setProtocolInformation(protocolInformation);

Endpoint endpoint = new Endpoint();
endpoint.setInterface(AAS_INTERFACE);
ProtocolInformation protocolInformation = createProtocolInformation(shellId);
endpoint.setProtocolInformation(protocolInformation);

descriptor.addEndpointsItem(endpoint);
descriptor.addEndpointsItem(endpoint);
}
}

private ProtocolInformation createProtocolInformation(String shellId) {
String href = String.format("%s/%s", aasRepositoryURL, Base64UrlEncodedIdentifier.encodeIdentifier(shellId));
private ProtocolInformation createProtocolInformation(String shellId, String url) {
String href = String.format("%s/%s", url, Base64UrlEncodedIdentifier.encodeIdentifier(shellId));

ProtocolInformation protocolInformation = new ProtocolInformation();
protocolInformation.endpointProtocol(getProtocol(href));
Expand All @@ -192,6 +193,14 @@ private String getProtocol(String endpoint) {
}
}

private List<String> createAasRepositoryUrls(List<String> aasRepositoryBaseURLs) {
List<String> toReturn = new ArrayList<>(aasRepositoryBaseURLs.size());
for (String eachUrl : aasRepositoryBaseURLs) {
toReturn.add(createAasRepositoryUrl(eachUrl));
}
return toReturn;
}

private String createAasRepositoryUrl(String aasRepositoryBaseURL) {

try {
Expand Down
Loading

0 comments on commit 1321775

Please sign in to comment.