Skip to content

Commit

Permalink
[Feature] Replaced descriptors with AAS4J classes (#855)
Browse files Browse the repository at this point in the history
Replaced descriptors with AAS4J classes
  • Loading branch information
fvolz authored Aug 28, 2024
1 parent 5d5b07a commit 883be69
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 1,352 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public interface Endpoint<T extends EndpointConfig> extends Configurable<T> {
* @param aasId the id of the AAS
* @return a list of endpoint information where this AAS can be accessed
*/
public default List<de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.Endpoint> getAasEndpointInformation(String aasId) {
public default List<org.eclipse.digitaltwin.aas4j.v3.model.Endpoint> getAasEndpointInformation(String aasId) {
return List.of();
}

Expand All @@ -60,7 +60,7 @@ public default List<de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.Endpo
* @param submodelId the id of the submodel
* @return a list of endpoint information where this submodel can be accessed
*/
public default List<de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.Endpoint> getSubmodelEndpointInformation(String submodelId) {
public default List<org.eclipse.digitaltwin.aas4j.v3.model.Endpoint> getSubmodelEndpointInformation(String submodelId) {
return List.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier;
import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page;
import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.PagingInfo;
import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.AssetAdministrationShellDescriptor;
import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor;
import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultAssetAdministrationShellDescriptor;
import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultSubmodelDescriptor;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ResourceNotFoundException;
import de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionInfo;
import de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementChangeEventMessage;
Expand Down Expand Up @@ -58,10 +54,14 @@
import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell;
import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShellDescriptor;
import org.eclipse.digitaltwin.aas4j.v3.model.Key;
import org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes;
import org.eclipse.digitaltwin.aas4j.v3.model.SecurityAttributeObject;
import org.eclipse.digitaltwin.aas4j.v3.model.Submodel;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelDescriptor;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetAdministrationShellDescriptor;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelDescriptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -406,9 +406,18 @@ private void unregister(List<String> registries, String path, Object payload, St


private AssetAdministrationShellDescriptor asDescriptor(AssetAdministrationShell aas) {
return DefaultAssetAdministrationShellDescriptor.builder()
.from(aas)
.submodels(aas.getSubmodels().stream()
return new DefaultAssetAdministrationShellDescriptor.Builder()
.administration(aas.getAdministration())
.id(aas.getId())
.idShort(aas.getIdShort())
.description(aas.getDescription())
.displayName(aas.getDisplayName())
.extensions(aas.getExtensions())
.assetKind(Objects.isNull(aas.getAssetInformation()) ? null : aas.getAssetInformation().getAssetKind())
.assetType(Objects.isNull(aas.getAssetInformation()) ? null : aas.getAssetInformation().getAssetType())
.globalAssetId(Objects.isNull(aas.getAssetInformation()) ? null : aas.getAssetInformation().getGlobalAssetId())
.specificAssetIds(Objects.isNull(aas.getAssetInformation()) ? null : aas.getAssetInformation().getSpecificAssetIds())
.submodelDescriptors(aas.getSubmodels().stream()
.map(x -> ReferenceHelper.findFirstKeyType(x, KeyTypes.SUBMODEL))
.filter(persistence::submodelExists)
.map(LambdaExceptionHelper.wrapFunction(x -> persistence.getSubmodel(x, QueryModifier.MINIMAL)))
Expand All @@ -422,8 +431,15 @@ private AssetAdministrationShellDescriptor asDescriptor(AssetAdministrationShell


private SubmodelDescriptor asDescriptor(Submodel submodel) {
return DefaultSubmodelDescriptor.builder()
.from(submodel)
return new DefaultSubmodelDescriptor.Builder()
.administration(submodel.getAdministration())
.id(submodel.getId())
.idShort(submodel.getIdShort())
.description(submodel.getDescription())
.semanticId(submodel.getSemanticId())
.supplementalSemanticId(submodel.getSupplementalSemanticIds())
.displayName(submodel.getDisplayName())
.extensions(submodel.getExtensions())
.endpoints(endpoints.stream()
.flatMap(x -> x.getSubmodelEndpointInformation(submodel.getId()).stream())
.toList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@
import de.fraunhofer.iosb.ilt.faaast.service.model.AASFull;
import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier;
import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page;
import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor;
import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultAssetAdministrationShellDescriptor;
import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultProtocolInformation;
import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultSubmodelDescriptor;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ResourceNotFoundException;
import de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementCreateEventMessage;
import de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementDeleteEventMessage;
Expand All @@ -59,7 +55,11 @@
import org.eclipse.digitaltwin.aas4j.v3.model.SecurityAttributeObject;
import org.eclipse.digitaltwin.aas4j.v3.model.SecurityTypeEnum;
import org.eclipse.digitaltwin.aas4j.v3.model.Submodel;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelDescriptor;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetAdministrationShellDescriptor;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultProtocolInformation;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSecurityAttributeObject;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelDescriptor;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
Expand Down Expand Up @@ -210,26 +210,26 @@ private void mockEndpoint() {
doAnswer((InvocationOnMock invocation) -> {
String aasId = invocation.getArgument(0);
return List.of(
de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultEndpoint.builder()
new org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultEndpoint.Builder()
._interface("AAS-REPOSITORY-3.0")
.protocolInformation(DefaultProtocolInformation.builder()
.protocolInformation(new DefaultProtocolInformation.Builder()
.href(serviceUri.toASCIIString())
.endpointProtocol("HTTP")
.endpointProtocolVersion("1.1")
.securityAttribute(new DefaultSecurityAttributeObject.Builder()
.securityAttributes(new DefaultSecurityAttributeObject.Builder()
.type(SecurityTypeEnum.NONE)
.key("")
.value("")
.build())
.build())
.build(),
de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultEndpoint.builder()
new org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultEndpoint.Builder()
._interface("AAS-3.0")
.protocolInformation(DefaultProtocolInformation.builder()
.protocolInformation(new DefaultProtocolInformation.Builder()
.href(serviceUri.toASCIIString() + "/shells/" + EncodingHelper.base64UrlEncode(aasId))
.endpointProtocol("HTTP")
.endpointProtocolVersion("1.1")
.securityAttribute(new DefaultSecurityAttributeObject.Builder()
.securityAttributes(new DefaultSecurityAttributeObject.Builder()
.type(SecurityTypeEnum.NONE)
.key("")
.value("")
Expand All @@ -241,26 +241,26 @@ private void mockEndpoint() {
doAnswer((InvocationOnMock invocation) -> {
String submodelId = invocation.getArgument(0);
return List.of(
de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultEndpoint.builder()
new org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultEndpoint.Builder()
._interface("SUBMODEL-REPOSITORY-3.0")
.protocolInformation(DefaultProtocolInformation.builder()
.protocolInformation(new DefaultProtocolInformation.Builder()
.href(serviceUri.toASCIIString())
.endpointProtocol("HTTP")
.endpointProtocolVersion("1.1")
.securityAttribute(new DefaultSecurityAttributeObject.Builder()
.securityAttributes(new DefaultSecurityAttributeObject.Builder()
.type(SecurityTypeEnum.NONE)
.key("")
.value("")
.build())
.build())
.build(),
de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultEndpoint.builder()
new org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultEndpoint.Builder()
._interface("SUBMODEL-3.0")
.protocolInformation(DefaultProtocolInformation.builder()
.protocolInformation(new DefaultProtocolInformation.Builder()
.href(serviceUri.toASCIIString() + "/submodels/" + EncodingHelper.base64UrlEncode(submodelId))
.endpointProtocol("HTTP")
.endpointProtocolVersion("1.1")
.securityAttribute(new DefaultSecurityAttributeObject.Builder()
.securityAttributes(new DefaultSecurityAttributeObject.Builder()
.type(SecurityTypeEnum.NONE)
.key("")
.value("")
Expand Down Expand Up @@ -345,17 +345,32 @@ private void mockPersistence() throws ResourceNotFoundException {


private String getAasDescriptorBody(AssetAdministrationShell aas) throws JsonProcessingException {
return mapper.writeValueAsString(DefaultAssetAdministrationShellDescriptor.builder()
.from(aas)
return mapper.writeValueAsString(new DefaultAssetAdministrationShellDescriptor.Builder()
.administration(aas.getAdministration())
.id(aas.getId())
.idShort(aas.getIdShort())
.description(aas.getDescription())
.globalAssetId(aas.getAssetInformation().getGlobalAssetId())
.assetType(aas.getAssetInformation().getAssetType())
.assetKind(aas.getAssetInformation().getAssetKind())
.displayName(aas.getDisplayName())
.extensions(aas.getExtensions())
.endpoints(endpoint.getAasEndpointInformation(aas.getId()))
.submodels(getSubmodelDescriptorsFromAas(aas))
.submodelDescriptors(getSubmodelDescriptorsFromAas(aas))
.build());
}


private String getSubmodelDescriptorBody(Submodel submodel) throws JsonProcessingException {
return mapper.writeValueAsString(DefaultSubmodelDescriptor.builder()
.from(submodel)
return mapper.writeValueAsString(new DefaultSubmodelDescriptor.Builder()
.administration(submodel.getAdministration())
.id(submodel.getId())
.idShort(submodel.getIdShort())
.description(submodel.getDescription())
.semanticId(submodel.getSemanticId())
.supplementalSemanticId(submodel.getSupplementalSemanticIds())
.displayName(submodel.getDisplayName())
.extensions(submodel.getExtensions())
.endpoints(endpoint.getSubmodelEndpointInformation(submodel.getId()))
.build());
}
Expand All @@ -366,8 +381,15 @@ private List<SubmodelDescriptor> getSubmodelDescriptorsFromAas(AssetAdministrati
.map(x -> ReferenceHelper.findFirstKeyType(x, KeyTypes.SUBMODEL))
.filter(persistence::submodelExists)
.map(LambdaExceptionHelper.wrapFunction(x -> persistence.getSubmodel(x, QueryModifier.MINIMAL)))
.map(x -> DefaultSubmodelDescriptor.builder()
.from(x)
.map(x -> new DefaultSubmodelDescriptor.Builder()
.administration(x.getAdministration())
.id(x.getId())
.idShort(x.getIdShort())
.description(x.getDescription())
.semanticId(x.getSemanticId())
.supplementalSemanticId(x.getSupplementalSemanticIds())
.displayName(x.getDisplayName())
.extensions(x.getExtensions())
.endpoints(endpoint.getSubmodelEndpointInformation(x.getId()))
.build())
.map(SubmodelDescriptor.class::cast)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import de.fraunhofer.iosb.ilt.faaast.service.endpoint.Endpoint;
import de.fraunhofer.iosb.ilt.faaast.service.exception.EndpointException;
import de.fraunhofer.iosb.ilt.faaast.service.model.Version;
import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultProtocolInformation;
import de.fraunhofer.iosb.ilt.faaast.service.util.EncodingHelper;
import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure;
import java.io.File;
Expand All @@ -39,6 +38,8 @@
import java.util.List;
import java.util.Objects;
import org.eclipse.digitaltwin.aas4j.v3.model.SecurityTypeEnum;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultEndpoint;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultProtocolInformation;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSecurityAttributeObject;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HttpConfiguration;
Expand Down Expand Up @@ -212,7 +213,7 @@ public void stop() {


@Override
public List<de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.Endpoint> getAasEndpointInformation(String aasId) {
public List<org.eclipse.digitaltwin.aas4j.v3.model.Endpoint> getAasEndpointInformation(String aasId) {
if (Objects.isNull(server)) {
return List.of();
}
Expand All @@ -223,7 +224,7 @@ public List<de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.Endpoint> get


@Override
public List<de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.Endpoint> getSubmodelEndpointInformation(String submodelId) {
public List<org.eclipse.digitaltwin.aas4j.v3.model.Endpoint> getSubmodelEndpointInformation(String submodelId) {
if (Objects.isNull(server)) {
return List.of();
}
Expand All @@ -233,14 +234,14 @@ public List<de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.Endpoint> get
}


private de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.Endpoint endpointFor(String interfaceName, String path) {
return de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultEndpoint.builder()
private org.eclipse.digitaltwin.aas4j.v3.model.Endpoint endpointFor(String interfaceName, String path) {
return new DefaultEndpoint.Builder()
._interface(interfaceName)
.protocolInformation(DefaultProtocolInformation.builder()
.protocolInformation(new DefaultProtocolInformation.Builder()
.href(getEndpointUri().resolve(getVersionPrefix() + path).toASCIIString())
.endpointProtocol(ENDPOINT_PROTOCOL)
.endpointProtocolVersion(ENDPOINT_PROTOCOL_VERSION)
.securityAttribute(new DefaultSecurityAttributeObject.Builder()
.securityAttributes(new DefaultSecurityAttributeObject.Builder()
.type(SecurityTypeEnum.NONE)
.key("")
.value("")
Expand Down
Loading

0 comments on commit 883be69

Please sign in to comment.