From 84e3365adb1b5bb11c5372ccfdb18a1ff2cb186b Mon Sep 17 00:00:00 2001 From: mateusmolina Date: Fri, 25 Oct 2024 12:33:28 +0200 Subject: [PATCH] fix: change endpoint parsing mechanism of the Aas/Sm DescriptorResolvers to conform with spec --- .../client/resolvers/AasDescriptorResolver.java | 14 ++++---------- .../resolvers/SubmodelDescriptorResolver.java | 14 ++++---------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/basyx.aasenvironment/basyx.aasenvironment-client/src/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/resolvers/AasDescriptorResolver.java b/basyx.aasenvironment/basyx.aasenvironment-client/src/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/resolvers/AasDescriptorResolver.java index 6e743a8e1..dcbc614f2 100644 --- a/basyx.aasenvironment/basyx.aasenvironment-client/src/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/resolvers/AasDescriptorResolver.java +++ b/basyx.aasenvironment/basyx.aasenvironment-client/src/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/resolvers/AasDescriptorResolver.java @@ -30,6 +30,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.aasservice.client.ConnectedAasService; import org.eclipse.digitaltwin.basyx.client.internal.resolver.DescriptorResolver; @@ -41,6 +42,8 @@ */ public class AasDescriptorResolver implements DescriptorResolver { + static final String SPEC_INTERFACE = "AAS-3.0"; + private final EndpointResolver endpointResolver; /** @@ -66,16 +69,7 @@ public ConnectedAasService resolveDescriptor(AssetAdministrationShellDescriptor public static Optional parseEndpoint(Endpoint endpoint) { try { - if (endpoint == null || endpoint.getProtocolInformation() == null || endpoint.getProtocolInformation() - .getHref() == null) - return Optional.empty(); - - String baseHref = endpoint.getProtocolInformation() - .getHref(); - // TODO not working: String queryString = "?" + endpoint.toUrlQueryString(); - String queryString = ""; - URI uri = new URI(baseHref + queryString); - return Optional.of(uri); + return Optional.ofNullable(endpoint).filter(ep -> ep.getInterface().equals(SPEC_INTERFACE)).map(Endpoint::getProtocolInformation).map(ProtocolInformation::getHref).map(URI::create); } catch (Exception e) { return Optional.empty(); } diff --git a/basyx.aasenvironment/basyx.aasenvironment-client/src/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/resolvers/SubmodelDescriptorResolver.java b/basyx.aasenvironment/basyx.aasenvironment-client/src/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/resolvers/SubmodelDescriptorResolver.java index 5ddc10d72..4d7014577 100644 --- a/basyx.aasenvironment/basyx.aasenvironment-client/src/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/resolvers/SubmodelDescriptorResolver.java +++ b/basyx.aasenvironment/basyx.aasenvironment-client/src/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/client/resolvers/SubmodelDescriptorResolver.java @@ -25,6 +25,7 @@ package org.eclipse.digitaltwin.basyx.aasenvironment.client.resolvers; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.ProtocolInformation; import org.eclipse.digitaltwin.basyx.client.internal.resolver.DescriptorResolver; import java.net.URI; import java.util.Optional; @@ -41,6 +42,8 @@ */ public class SubmodelDescriptorResolver implements DescriptorResolver { + static final String SPEC_INTERFACE = "SUBMODEL-3.0"; + private final EndpointResolver endpointResolver; /** @@ -67,16 +70,7 @@ public ConnectedSubmodelService resolveDescriptor(SubmodelDescriptor smDescripto public static Optional parseEndpoint(Endpoint endpoint) { try { - if (endpoint == null || endpoint.getProtocolInformation() == null || endpoint.getProtocolInformation() - .getHref() == null) - return Optional.empty(); - - String baseHref = endpoint.getProtocolInformation() - .getHref(); - // TODO not working: String queryString = "?" + endpoint.toUrlQueryString(); - String queryString = ""; - URI uri = new URI(baseHref + queryString); - return Optional.of(uri); + return Optional.ofNullable(endpoint).filter(ep -> ep.getInterface().equals(SPEC_INTERFACE)).map(Endpoint::getProtocolInformation).map(ProtocolInformation::getHref).map(URI::create); } catch (Exception e) { return Optional.empty(); }