Skip to content

Commit

Permalink
chore: [TRX-96] Adapt-Discovery-flow (bpnl) (#12)
Browse files Browse the repository at this point in the history
(cherry picked from commit 5ae81f4a3946f760ff2cc085154dc1eb04585418)
  • Loading branch information
pathaniaaviX authored and ds-mwesener committed Oct 4, 2024
1 parent d05116c commit d712e3e
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ _**For better traceability add the corresponding GitHub issue number in each cha

## [Unreleased]

### Changed

- Added the discovery type configurable, with a default value of bpnl in (ConnectorEndpointsService) (#12)

## [5.4.1] - 2024-08-19

### Fixed
Expand Down
4 changes: 4 additions & 0 deletions charts/item-relationship-service/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Added the discovery type configurable (discovery.type) default value as bpnl. (#12).

## [7.4.1] - 2024-08-19

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ data:
discovery:
oAuthClientId: {{ .Values.discovery.oAuthClientId | default "discovery" }} # ID of the OAuth2 client registration to use, see config spring.security.oauth2.client
discoveryFinderUrl: {{ tpl (.Values.discovery.discoveryFinderUrl | default "") . | quote }} # The endpoint to discover EDC endpoints to a particular BPN.
type: {{ .Values.discovery.type | default "bpnl" }} # Type to discover EDC of type "bpnl".
semanticshub:
url: {{ tpl (.Values.semanticshub.url | default "") . | quote }}
Expand Down
1 change: 1 addition & 0 deletions charts/item-relationship-service/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ digitalTwinRegistry:
discovery:
oAuthClientId: discovery # ID of the OAuth2 client registration to use, see config spring.security.oauth2.client
discoveryFinderUrl: # "https://<discovery-finder-url>
type: "bpnl" # discovery type to find bpnl type in EDC discovery

semanticshub:
url: # https://<semantics-hub-url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ public DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService(
@Bean
public ConnectorEndpointsService connectorEndpointsService(
@Qualifier(RestTemplateConfig.DTR_REST_TEMPLATE) final RestTemplate dtrRestTemplate,
@Value("${digitalTwinRegistry.discovery.discoveryFinderUrl:}") final String finderUrl) {
return new ConnectorEndpointsService(discoveryFinderClient(dtrRestTemplate, finderUrl));
@Value("${digitalTwinRegistry.discovery.discoveryFinderUrl:}") final String finderUrl,
@Value("${digitalTwinRegistry.discovery.type:}") final String discoveryType) {
return new ConnectorEndpointsService(discoveryFinderClient(dtrRestTemplate, finderUrl), discoveryType);
}


@Bean
public DiscoveryFinderClient discoveryFinderClient(
@Qualifier(RestTemplateConfig.DTR_REST_TEMPLATE) final RestTemplate dtrRestTemplate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ public DiscoveryFinderClient discoveryFinderClient(

@Bean
@ConditionalOnProperty(prefix = CONFIG_PREFIX, name = CONFIG_FIELD_TYPE, havingValue = CONFIG_VALUE_DECENTRAL)
public ConnectorEndpointsService connectorEndpointsService(final DiscoveryFinderClient discoveryFinderClient) {
return new ConnectorEndpointsService(discoveryFinderClient);
public ConnectorEndpointsService connectorEndpointsService(final DiscoveryFinderClient discoveryFinderClient,
@Value("${digitalTwinRegistryClient.discovery.type:}") final String discoveryType) {
return new ConnectorEndpointsService(discoveryFinderClient, discoveryType);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class ConnectorEndpointsService {

private final DiscoveryFinderClient discoveryFinderClient;
private static final String CONNECTOR_ENDPOINT_SERVICE_CACHE_NAME = "connector_endpoint_service_cache";
private final String discoveryType;

/**
* Get EDCs for BPN.
Expand All @@ -60,7 +61,7 @@ public List<String> fetchConnectorEndpoints(final String bpn) {

log.info("Requesting connector endpoints for BPN {}", bpn);

final var onlyBpn = new DiscoveryFinderRequest(List.of("bpn"));
final var onlyBpn = new DiscoveryFinderRequest(List.of(discoveryType));
final var discoveryEndpoints = discoveryFinderClient.findDiscoveryEndpoints(onlyBpn).endpoints();
final var endpoints = discoveryEndpoints.stream()
.flatMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void centralDigitalTwinRegistryService() {
void decentralDigitalTwinRegistryService() {
final EdcSubmodelFacade facadeMock = mock(EdcSubmodelFacade.class);
final var service = testee.decentralDigitalTwinRegistryService(
testee.connectorEndpointsService(testee.discoveryFinderClient(new RestTemplate(), "finder")),
testee.connectorEndpointsService(testee.discoveryFinderClient(new RestTemplate(), "finder"), "bpnl"),
testee.endpointDataForConnectorsService(facadeMock),
testee.decentralDigitalTwinRegistryClient(new RestTemplate(), descriptorTemplate, shellLookupTemplate),
edcConfiguration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void setUp(WireMockRuntimeInfo wireMockRuntimeInfo) {
final RestTemplate restTemplate = restTemplateProxy(PROXY_SERVER_HOST, wireMockRuntimeInfo.getHttpPort());

final var discoveryFinderClient = new DiscoveryFinderClientImpl(DISCOVERY_FINDER_URL, restTemplate);
final var connectorEndpointsService = new ConnectorEndpointsService(discoveryFinderClient);
final var connectorEndpointsService = new ConnectorEndpointsService(discoveryFinderClient, "bpnl");
final var endpointDataForConnectorsService = new EndpointDataForConnectorsService(
edcEndpointReferenceRetrieverMock);
final var decentralDigitalTwinRegistryClient = new DecentralDigitalTwinRegistryClient(restTemplate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
class ConnectorEndpointsServiceTest {

private final DiscoveryFinderClient essDiscoveryFinderClient = Mockito.mock(DiscoveryFinderClient.class);
private final ConnectorEndpointsService service = new ConnectorEndpointsService(essDiscoveryFinderClient);
private final ConnectorEndpointsService service = new ConnectorEndpointsService(essDiscoveryFinderClient, "bpnl" );

@Test
void shouldFindConnectorEndpoints() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void findDiscoveryEndpoints_shouldReturnResponseFromRestRequest() {
final DiscoveryResponse mockResponse = new DiscoveryResponse(
List.of(new DiscoveryEndpoint("test-endpoint", "desc", "test-endpoint-addr", "docs", "resId")));

final var request = new DiscoveryFinderRequest(List.of("bpn"));
final var request = new DiscoveryFinderRequest(List.of("bpnl"));
when(restTemplate.postForObject(DISCOVERY_FINDER_URL, request, DiscoveryResponse.class)).thenReturn(
mockResponse);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ data:
bpn_discovery_service_response.json: |-
{
"bpns": [
{"type": "bpn","key": ".*","value": "BPNL00000000BJTL","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"},
{"type": "bpn","key": ".*","value": "BPNL00000003AVTH","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"},
{"type": "bpn","key": ".*","value": "BPNL00000003AXS3","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"},
{"type": "bpn","key": ".*","value": "BPNL00000003AYRE","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"},
{"type": "bpn","key": ".*","value": "BPNL00000003AZQP","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"},
{"type": "bpn","key": ".*","value": "BPNL00000003B0Q0","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"},
{"type": "bpn","key": ".*","value": "BPNL00000003B2OM","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"},
{"type": "bpn","key": ".*","value": "BPNL00000003B3NX","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"},
{"type": "bpn","key": ".*","value": "BPNL00000003B5MJ","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"},
{"type": "bpn","key": ".*","value": "BPNL00000003B5MJ","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"},
{"type": "bpn","key": ".*","value": "BPNL00000003CSGV","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"}
{"type": "bpnl","key": ".*","value": "BPNL00000000BJTL","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"},
{"type": "bpnl","key": ".*","value": "BPNL00000003AVTH","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"},
{"type": "bpnl","key": ".*","value": "BPNL00000003AXS3","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"},
{"type": "bpnl","key": ".*","value": "BPNL00000003AYRE","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"},
{"type": "bpnl","key": ".*","value": "BPNL00000003AZQP","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"},
{"type": "bpnl","key": ".*","value": "BPNL00000003B0Q0","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"},
{"type": "bpnl","key": ".*","value": "BPNL00000003B2OM","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"},
{"type": "bpnl","key": ".*","value": "BPNL00000003B3NX","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"},
{"type": "bpnl","key": ".*","value": "BPNL00000003B5MJ","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"},
{"type": "bpnl","key": ".*","value": "BPNL00000003B5MJ","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"},
{"type": "bpnl","key": ".*","value": "BPNL00000003CSGV","resourceId": "1ca6f9b5-8e1d-422a-8541-9bb2cf5fe485"}
]
}

0 comments on commit d712e3e

Please sign in to comment.