Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(irs-api): Fix DiscoveryResponse #359

Merged
merged 9 commits into from
Jun 14, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
********************************************************************************/
package org.eclipse.tractusx.irs.aaswrapper.registry.domain;

import java.util.Arrays;
import java.util.List;

import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -50,19 +51,19 @@ public AssetAdministrationShellDescriptor getAAShellDescriptor(final DigitalTwin
log.info("Retrieved AAS Identification for DigitalTwinRegistryKey: {}", key);
final DiscoveryFinderRequest onlyBpn = new DiscoveryFinderRequest(List.of("bpn"));
final List<String> providedBpn = List.of(key.bpn());
final List<DiscoveryEndpoint> discoveryEndpoints = discoveryFinderClient.findDiscoveryEndpoints(onlyBpn);
final List<String> connectorEndpoints = discoveryEndpoints.stream()
.map(discoveryEndpoint -> discoveryFinderClient.findConnectorEndpoints(
final DiscoveryEndpoint[] discoveryEndpoints = discoveryFinderClient.findDiscoveryEndpoints(onlyBpn).endpoints();
final List<String> connectorEndpoints = Arrays.stream(discoveryEndpoints)
.map(discoveryEndpoint -> discoveryFinderClient.findConnectorEndpoints(
discoveryEndpoint.endpointAddress(),
providedBpn)
.stream()
.filter(edcDiscoveryResult -> edcDiscoveryResult.bpn()
.equals(key.bpn()))
.map(EdcDiscoveryResult::connectorEndpoint)
.toList())
.flatMap(List::stream)
.flatMap(List::stream)
.toList();
.flatMap(List::stream)
.flatMap(List::stream)
.toList();
// take first
final EndpointDataReference endpointDataReference = endpointDataForConnectorsService.findEndpointDataForConnectors(
connectorEndpoints).stream().findFirst().orElseThrow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
package org.eclipse.tractusx.irs.aaswrapper.registry.domain;

/**
* A result of finding Discovery Endpoint
* A single Discovery Endpoint.
*/
public record DiscoveryEndpoint(String type, String description, String endpointAddress, String documentation,
String resourceId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
*/
public interface DiscoveryFinderClient {

List<DiscoveryEndpoint> findDiscoveryEndpoints(DiscoveryFinderRequest request);
DiscoveryResponse findDiscoveryEndpoints(DiscoveryFinderRequest request);

List<EdcDiscoveryResult> findConnectorEndpoints(String endpointAddress, List<String> bpns);

}
Expand All @@ -61,14 +62,16 @@ class DiscoveryFinderClientImpl implements DiscoveryFinderClient {

@Override
@Retry(name = "registry")
public List<DiscoveryEndpoint> findDiscoveryEndpoints(final DiscoveryFinderRequest request) {
return restTemplate.postForObject(discoveryFinderUrl, request, List.class);
public DiscoveryResponse findDiscoveryEndpoints(final DiscoveryFinderRequest request) {
return restTemplate.postForObject(discoveryFinderUrl, request, DiscoveryResponse.class);
}

@Override
@Retry(name = "registry")
public List<EdcDiscoveryResult> findConnectorEndpoints(final String endpointAddress,
final List<String> bpns) {
return restTemplate.postForObject(endpointAddress, bpns, List.class);
public List<EdcDiscoveryResult> findConnectorEndpoints(final String endpointAddress, final List<String> bpns) {
final EdcDiscoveryResult[] edcDiscoveryResults = restTemplate.postForObject(endpointAddress, bpns,
EdcDiscoveryResult[].class);

return edcDiscoveryResults == null ? List.of() : List.of(edcDiscoveryResults);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/********************************************************************************
* Copyright (c) 2021,2022,2023
* 2022: ZF Friedrichshafen AG
* 2022: ISTOS GmbH
* 2022,2023: Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* 2022,2023: BOSCH AG
* Copyright (c) 2021,2022,2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0. *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.irs.aaswrapper.registry.domain;

/**
* The result of searching Discovery Endpoints.
* @param endpoints the list of {@link DiscoveryEndpoint}s
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
*/
public record DiscoveryResponse(DiscoveryEndpoint[] endpoints) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,29 @@ class DecentralDigitalTwinRegistryServiceTest {
private final DecentralDigitalTwinRegistryClient decentralDigitalTwinRegistryClient = mock(
DecentralDigitalTwinRegistryClient.class);

private final DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService = new DecentralDigitalTwinRegistryService(discoveryFinderClient,
endpointDataForConnectorsService, decentralDigitalTwinRegistryClient);
private final DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService = new DecentralDigitalTwinRegistryService(
discoveryFinderClient, endpointDataForConnectorsService, decentralDigitalTwinRegistryClient);

@Test
void shouldReturnExpectedShell() {
// given
final DigitalTwinRegistryKey digitalTwinRegistryKey = new DigitalTwinRegistryKey("urn:uuid:4132cd2b-cbe7-4881-a6b4-39fdc31cca2b", "bpn");
final DigitalTwinRegistryKey digitalTwinRegistryKey = new DigitalTwinRegistryKey(
"urn:uuid:4132cd2b-cbe7-4881-a6b4-39fdc31cca2b", "bpn");
final AssetAdministrationShellDescriptor expectedShell = shellDescriptor(Collections.emptyList());
EndpointDataReference endpointDataReference = EndpointDataReference.Builder.newInstance().endpoint("url.to.host").build();
EndpointDataReference endpointDataReference = EndpointDataReference.Builder.newInstance()
.endpoint("url.to.host")
.build();
final DiscoveryEndpoint[] discoveryEndpoints = { new DiscoveryEndpoint("type", "desc", "address", "doc",
"resId")
};
when(discoveryFinderClient.findDiscoveryEndpoints(any(DiscoveryFinderRequest.class))).thenReturn(
Collections.singletonList(new DiscoveryEndpoint("type", "desc", "address", "doc", "resId")));
when(endpointDataForConnectorsService.findEndpointDataForConnectors(anyList())).thenReturn(List.of(endpointDataReference));
when(decentralDigitalTwinRegistryClient.getAllAssetAdministrationShellIdsByAssetLink(any(), anyList())).thenReturn(Collections.emptyList());
when(decentralDigitalTwinRegistryClient.getAssetAdministrationShellDescriptor(any(), any())).thenReturn(expectedShell);
new DiscoveryResponse(discoveryEndpoints));
when(endpointDataForConnectorsService.findEndpointDataForConnectors(anyList())).thenReturn(
List.of(endpointDataReference));
when(decentralDigitalTwinRegistryClient.getAllAssetAdministrationShellIdsByAssetLink(any(),
anyList())).thenReturn(Collections.emptyList());
when(decentralDigitalTwinRegistryClient.getAssetAdministrationShellDescriptor(any(), any())).thenReturn(
expectedShell);

// when
final AssetAdministrationShellDescriptor actualShell = decentralDigitalTwinRegistryService.getAAShellDescriptor(
Expand Down