From ab6679058fb3134cb297c90b87dba91f9357a939 Mon Sep 17 00:00:00 2001 From: ds-lcapellino Date: Wed, 6 Mar 2024 17:02:01 +0100 Subject: [PATCH 1/2] feature: 420 fix filterExpression; refactor --- .../contract/service/EdcContractAgreementService.java | 9 ++++----- .../service/EdcContractAgreementServiceTest.java | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementService.java index 85677c578a..d0b82407ba 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementService.java @@ -19,7 +19,6 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.edc.client.contract.service; -import java.util.Arrays; import java.util.List; import lombok.extern.slf4j.Slf4j; @@ -48,7 +47,7 @@ public class EdcContractAgreementService { public static final String EDC_REQUEST_SUFFIX = "/request"; - public static final String EDC_CONTRACT_AGREEMENT_ID = "https://w3id.org/edc/v0.0.1/ns/id"; + public static final String EDC_CONTRACT_AGREEMENT_ID = "id"; private final EdcConfiguration config; private final RestTemplate edcRestTemplate; @@ -58,7 +57,7 @@ public EdcContractAgreementService(final EdcConfiguration config, this.edcRestTemplate = edcRestTemplate; } - public List getContractAgreements(final String... contractAgreementIds) + public List getContractAgreements(final List contractAgreementIds) throws ContractAgreementException { final EdcContractAgreementRequest edcContractAgreementRequest = buildContractAgreementRequest( @@ -89,9 +88,9 @@ public EdcContractAgreementNegotiationResponse getContractAgreementNegotiation(f return contractNegotiationResponseEntity.getBody(); } - private EdcContractAgreementRequest buildContractAgreementRequest(final String... contractAgreementIds) { + private EdcContractAgreementRequest buildContractAgreementRequest(final List contractAgreementIds) { - final List list = Arrays.stream(contractAgreementIds) + final List list = contractAgreementIds.stream() .map(s -> new EdcContractAgreementFilterExpression( EDC_CONTRACT_AGREEMENT_ID, "=", s)) .toList(); diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementServiceTest.java index d6e5245db8..7af50f54a5 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementServiceTest.java @@ -66,7 +66,7 @@ void setUp() { @Test void shouldReturnContractAgreements() throws ContractAgreementException { //GIVEN - String[] contractAgreementIds = { "contractAgreementId" }; + List contractAgreementIds = List.of("contractAgreementId"); final EdcContractAgreementsResponse[] edcContractAgreementsResponse = new EdcContractAgreementsResponse[1]; edcContractAgreementsResponse[0] = EdcContractAgreementsResponse.builder().contractAgreementId("id") @@ -93,7 +93,7 @@ void shouldReturnContractAgreements() throws ContractAgreementException { @Test void shouldThrowContractAgreementExceptionWhenResponseBodyIsEmtpy() { //GIVEN - String[] contractAgreementIds = { "contractAgreementId" }; + List contractAgreementIds = List.of("contractAgreementId"); when(restTemplate.exchange(anyString(), any(), any(), eq(EdcContractAgreementsResponse[].class))).thenReturn( ResponseEntity.ok(new EdcContractAgreementsResponse[0])); From a6eb57b09506f83b7014943daf395022b481a940 Mon Sep 17 00:00:00 2001 From: ds-lcapellino Date: Thu, 7 Mar 2024 10:08:36 +0100 Subject: [PATCH 2/2] feature: 420 fix filterExpression --- .../contract/model/EdcContractAgreementRequest.java | 4 ++-- .../contract/service/EdcContractAgreementService.java | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractAgreementRequest.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractAgreementRequest.java index fd6e9f9319..cef9e6aece 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractAgreementRequest.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractAgreementRequest.java @@ -27,7 +27,7 @@ * EdcContractAgreementRequest represents the request to management/v2/contractagreements/request */ public record EdcContractAgreementRequest(@JsonProperty( - "https://w3id.org/edc/v0.0.1/ns/filterExpression") List edcContractAgreementFilterExpressions) { + "https://w3id.org/edc/v0.0.1/ns/filterExpression") EdcContractAgreementFilterExpression edcContractAgreementFilterExpressions) { /** * EdcContractAgreementFilterExpression represents the filterExpression * for EdcContractAgreementRequest @@ -35,7 +35,7 @@ public record EdcContractAgreementRequest(@JsonProperty( public record EdcContractAgreementFilterExpression( @JsonProperty("https://w3id.org/edc/v0.0.1/ns/operandLeft") String operandLeft, @JsonProperty("https://w3id.org/edc/v0.0.1/ns/operator") String operator, - @JsonProperty("https://w3id.org/edc/v0.0.1/ns/operandRight") String operandRight) { + @JsonProperty("https://w3id.org/edc/v0.0.1/ns/operandRight") List operandRight) { } } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementService.java index d0b82407ba..149f9debaf 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementService.java @@ -90,12 +90,10 @@ public EdcContractAgreementNegotiationResponse getContractAgreementNegotiation(f private EdcContractAgreementRequest buildContractAgreementRequest(final List contractAgreementIds) { - final List list = contractAgreementIds.stream() - .map(s -> new EdcContractAgreementFilterExpression( - EDC_CONTRACT_AGREEMENT_ID, "=", s)) - .toList(); + final EdcContractAgreementFilterExpression edcContractAgreementFilterExpression = new EdcContractAgreementFilterExpression( + EDC_CONTRACT_AGREEMENT_ID, "in", contractAgreementIds); - return new EdcContractAgreementRequest(list); + return new EdcContractAgreementRequest(edcContractAgreementFilterExpression); } private HttpHeaders headers() {