Skip to content

Commit

Permalink
fix: change endpoint parsing mechanism of the Aas/Sm DescriptorResolv…
Browse files Browse the repository at this point in the history
…ers to conform with spec
  • Loading branch information
mateusmolina-iese committed Oct 25, 2024
1 parent 4ec6492 commit 84e3365
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -41,6 +42,8 @@
*/
public class AasDescriptorResolver implements DescriptorResolver<AssetAdministrationShellDescriptor, ConnectedAasService> {

static final String SPEC_INTERFACE = "AAS-3.0";

private final EndpointResolver endpointResolver;

/**
Expand All @@ -66,16 +69,7 @@ public ConnectedAasService resolveDescriptor(AssetAdministrationShellDescriptor

public static Optional<URI> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,6 +42,8 @@
*/
public class SubmodelDescriptorResolver implements DescriptorResolver<SubmodelDescriptor, ConnectedSubmodelService> {

static final String SPEC_INTERFACE = "SUBMODEL-3.0";

private final EndpointResolver endpointResolver;

/**
Expand All @@ -67,16 +70,7 @@ public ConnectedSubmodelService resolveDescriptor(SubmodelDescriptor smDescripto

public static Optional<URI> 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();
}
Expand Down

0 comments on commit 84e3365

Please sign in to comment.