From 4bd5fcedb2b10cb41ec9cbc3b521d8232a0fcb55 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Fri, 25 Aug 2023 11:19:09 +0200 Subject: [PATCH 01/63] feature: TRACEFOSS-1730 preperation for new api assetAsPlanned --- .../blackbox/EdcCallbackControllerTraceX.java | 5 ++- .../edc/blackbox/InvestigationsEDCFacade.java | 32 +++++++++++++------ .../service/EdcNotificationService.java | 2 -- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcCallbackControllerTraceX.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcCallbackControllerTraceX.java index 7224169bb9..0d8a5436c7 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcCallbackControllerTraceX.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcCallbackControllerTraceX.java @@ -69,12 +69,15 @@ public void receiveEdcCallback(@RequestBody EndpointDataReference dataReference) if (endpointDataReferenceCache.containsAgreementId(contractAgreementId)) { log.info("Contract {} found! Processing...", contractAgreementId); endpointDataReferenceCache.put(contractAgreementId, dataReference); - } else { + } + // todo remove else block + else { log.info("Contract {} not found, forwarding message...", contractAgreementId); callOtherServices(dataReference); } } + // TODO remove this private void callOtherServices(EndpointDataReference dataReference) { edcProperties.getCallbackUrls().forEach(callbackUrl -> { log.info("Calling callback endpoint: {}", callbackUrl); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index 3eec893de1..9fae266b12 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -38,6 +38,9 @@ import org.eclipse.edc.policy.model.Permission; import org.eclipse.edc.policy.model.Policy; import org.eclipse.edc.spi.types.domain.DataAddress; +import org.eclipse.tractusx.irs.edc.client.ContractNegotiationService; +import org.eclipse.tractusx.irs.edc.client.EDCCatalogFacade; +import org.eclipse.tractusx.irs.edc.client.model.NegotiationResponse; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.cache.EndpointDataReference; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.cache.InMemoryEndpointDataReferenceCache; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.catalog.CatalogItem; @@ -85,6 +88,10 @@ public class InvestigationsEDCFacade { private final EdcProperties edcProperties; + private final EDCCatalogFacade edcCatalogFacade; + + private final ContractNegotiationService contractNegotiationService; + public static final String ASSET_VALUE_QUALITY_INVESTIGATION = "qualityinvestigation"; public static final String ASSET_VALUE_QUALITY_ALERT = "qualityalert"; private static final String ASSET_VALUE_NOTIFICATION_METHOD_UPDATE = "update"; @@ -97,6 +104,8 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec notification.setEdcUrl(receiverEdcUrl); log.info(":::: Find Notification contract method[startEDCTransfer] senderEdcUrl :{}, receiverEdcUrl:{}", senderEdcUrl, receiverEdcUrl); + + Catalog catalog = edcService.getCatalog( senderEdcUrl, receiverEdcUrl + edcProperties.getIdsPath(), @@ -142,28 +151,33 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec throw new NoCatalogItemException("No Catalog Item in catalog found."); } - final String negotiationId = edcService.initializeContractNegotiation(receiverEdcUrl, catalogItem.get(), senderEdcUrl, header); +// TODO + //NegotiationResponse negotiationResponse = contractNegotiationService.negotiate(null, null); + + // String contractAgreementId = negotiationResponse.getContractAgreementId(); + final String edcContractAgreementId = edcService.initializeContractNegotiation(receiverEdcUrl, catalogItem.get(), senderEdcUrl, header); - log.info(":::: Contract Agreed method[startEDCTransfer] agreementId :{}", negotiationId); + log.info(":::: Contract Agreed method[startEDCTransfer] agreementId :{}", edcContractAgreementId); - endpointDataReferenceCache.storeAgreementId(negotiationId); + // TODO remove this because we do not store agreement Id we extract it from a token in EdcCallbackControllerTraceX.java + endpointDataReferenceCache.storeAgreementId(edcContractAgreementId); - if (StringUtils.hasLength(negotiationId)) { - notification.setContractAgreementId(negotiationId); + if (StringUtils.hasLength(edcContractAgreementId)) { + notification.setContractAgreementId(edcContractAgreementId); } - EndpointDataReference dataReference = endpointDataReferenceCache.get(negotiationId); + EndpointDataReference dataReference = endpointDataReferenceCache.get(edcContractAgreementId); boolean validDataReference = dataReference != null && InMemoryEndpointDataReferenceCache.endpointDataRefTokenExpired(dataReference); if (!validDataReference) { log.info(":::: Invalid Data Reference :::::"); if (dataReference != null) { - endpointDataReferenceCache.remove(negotiationId); + endpointDataReferenceCache.remove(edcContractAgreementId); } final TransferProcessRequest transferProcessRequest = createTransferProcessRequest( receiverEdcUrl + edcProperties.getIdsPath(), catalogItem.get(), - negotiationId); + edcContractAgreementId); log.info(":::: initialize Transfer process with http Proxy :::::"); // Initiate transfer process @@ -172,7 +186,7 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec transferProcessRequest, header ); - dataReference = getDataReference(negotiationId); + dataReference = getDataReference(edcContractAgreementId); } Request notificationRequest = buildNotificationRequest(notification, senderEdcUrl, dataReference); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationService.java index 4e15708654..bf4eb41fe1 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationService.java @@ -66,8 +66,6 @@ public void asyncNotificationExecutor(QualityNotificationMessage notification) { emptyIfNull(discovery.getReceiverUrls()) .forEach(receiverUrl -> handleSendingInvestigation(notification, senderEdcUrl, receiverUrl)); } - - } private void handleSendingAlert(QualityNotificationMessage notification, String senderEdcUrl, String receiverUrl) { From dccc7d28ac65fdb1151c20406aa1b15613973295 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Fri, 25 Aug 2023 15:55:04 +0200 Subject: [PATCH 02/63] feature: TRACEFOSS-2352 test/debug what is inside responses :D --- tx-backend/pom.xml | 2 +- .../infrastructure/edc/blackbox/EdcService.java | 4 +++- .../edc/blackbox/InvestigationsEDCFacade.java | 16 +++++++++++++--- .../edc/blackbox/EdcServiceTest.java | 4 ++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/tx-backend/pom.xml b/tx-backend/pom.xml index 6469e1ab61..77fb6a799c 100644 --- a/tx-backend/pom.xml +++ b/tx-backend/pom.xml @@ -54,7 +54,7 @@ SPDX-License-Identifier: Apache-2.0 org.eclipse.tractusx.irs irs-registry-client - 1.1.0-SNAPSHOT + 1.1.1-SNAPSHOT diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcService.java index e2b5fdf71b..80df9ba148 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcService.java @@ -25,8 +25,9 @@ import okhttp3.MediaType; import okhttp3.Request; import okhttp3.RequestBody; + import org.eclipse.edc.catalog.spi.Catalog; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.catalog.CatalogItem; +import org.eclipse.tractusx.irs.edc.client.model.CatalogItem; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.jsontransformer.EdcTransformerTraceX; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.negotiation.ContractOfferDescription; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.negotiation.NegotiationRequest; @@ -58,6 +59,7 @@ public class EdcService { private final EdcProperties edcProperties; private final EdcTransformerTraceX edcTransformer; + // TODO: Remove /** * Rest call to get all contract offer and filter notification type contract */ diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index 9fae266b12..00904983ed 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -30,6 +30,7 @@ import okhttp3.Request; import okhttp3.RequestBody; import org.eclipse.edc.catalog.spi.Catalog; +import org.eclipse.edc.catalog.spi.CatalogRequest; import org.eclipse.edc.catalog.spi.Dataset; import org.eclipse.edc.policy.model.AtomicConstraint; import org.eclipse.edc.policy.model.Constraint; @@ -70,6 +71,7 @@ import static org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.configuration.JsonLdConfigurationTraceX.NAMESPACE_EDC; import static org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.configuration.JsonLdConfigurationTraceX.NAMESPACE_EDC_ID; +import static org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.transferprocess.TransferProcessRequest.DEFAULT_PROTOCOL; @Slf4j @Component @@ -105,18 +107,26 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec log.info(":::: Find Notification contract method[startEDCTransfer] senderEdcUrl :{}, receiverEdcUrl:{}", senderEdcUrl, receiverEdcUrl); + List catalogItems =edcCatalogFacade.fetchCatalogItems( + CatalogRequest.Builder.newInstance() + .protocol(DEFAULT_PROTOCOL) + .providerUrl(receiverEdcUrl) + .build() + ); + log.info("CATALOG ITEMS: {}", catalogItems); Catalog catalog = edcService.getCatalog( senderEdcUrl, receiverEdcUrl + edcProperties.getIdsPath(), header ); + log.info(" CATALOG FOR NOTIFICATION : {}", catalog); if (catalog.getDatasets().isEmpty()) { log.info("No Dataset in catalog found"); throw new BadRequestException("The dataset from the catalog is empty."); } - +// Optional filteredDataset = catalog.getDatasets().stream() .filter(dataset -> isQualityNotificationOffer(notification, dataset)) .findFirst() @@ -144,7 +154,7 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec return catalogItem.build(); }).toList(); - Optional catalogItem = items.stream().findFirst(); + Optional catalogItem = catalogItems.stream().findFirst(); if (catalogItem.isEmpty()) { log.info("No Catalog Item in catalog found"); @@ -204,7 +214,7 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec } private TransferProcessRequest createTransferProcessRequest(final String providerConnectorUrl, - final CatalogItem catalogItem, + final org.eclipse.tractusx.irs.edc.client.model.CatalogItem catalogItem, final String negotiationId) { final var destination = DataAddress.Builder.newInstance() .type(TransferProcessDataDestination.DEFAULT_TYPE) diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcServiceTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcServiceTest.java index 82aa277dbf..cb72495157 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcServiceTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcServiceTest.java @@ -23,7 +23,7 @@ import org.eclipse.edc.catalog.spi.Catalog; import org.eclipse.edc.catalog.spi.Dataset; import org.eclipse.edc.policy.model.Policy; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.catalog.CatalogItem; +import org.eclipse.tractusx.irs.edc.client.model.CatalogItem; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.jsontransformer.EdcTransformerTraceX; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.negotiation.NegotiationResponse; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.negotiation.Response; @@ -116,7 +116,7 @@ void test_initializeContractNegotiation() throws IOException, InterruptedExcepti Map header = Collections.singletonMap("Authorization", "Bearer token"); Policy policy = Policy.Builder.newInstance().target("policyTarget").build(); - CatalogItem catalogItem = CatalogItem.builder().offerId("offerId").policy(policy).build(); + org.eclipse.tractusx.irs.edc.client.model.CatalogItem catalogItem = org.eclipse.tractusx.irs.edc.client.model.CatalogItem.builder().offerId("offerId").policy(policy).build(); JsonObject mockedJsonObject = Json.createObjectBuilder().add("", "").build(); From fb625d285ce1a51acf7d0bba5c53d4d78402b4c6 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Fri, 25 Aug 2023 16:09:24 +0200 Subject: [PATCH 03/63] feature: TRACEFOSS-2352 test/debug what is inside responses :D --- .../traceability/infrastructure/edc/blackbox/EdcService.java | 2 +- .../infrastructure/edc/blackbox/InvestigationsEDCFacade.java | 4 ++-- .../infrastructure/edc/blackbox/EdcServiceTest.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcService.java index 80df9ba148..4391879a4d 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcService.java @@ -27,7 +27,7 @@ import okhttp3.RequestBody; import org.eclipse.edc.catalog.spi.Catalog; -import org.eclipse.tractusx.irs.edc.client.model.CatalogItem; +import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.catalog.CatalogItem; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.jsontransformer.EdcTransformerTraceX; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.negotiation.ContractOfferDescription; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.negotiation.NegotiationRequest; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index 00904983ed..fe70214160 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -154,7 +154,7 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec return catalogItem.build(); }).toList(); - Optional catalogItem = catalogItems.stream().findFirst(); + Optional catalogItem = items.stream().findFirst(); if (catalogItem.isEmpty()) { log.info("No Catalog Item in catalog found"); @@ -214,7 +214,7 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec } private TransferProcessRequest createTransferProcessRequest(final String providerConnectorUrl, - final org.eclipse.tractusx.irs.edc.client.model.CatalogItem catalogItem, + final CatalogItem catalogItem, final String negotiationId) { final var destination = DataAddress.Builder.newInstance() .type(TransferProcessDataDestination.DEFAULT_TYPE) diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcServiceTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcServiceTest.java index cb72495157..bba1051081 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcServiceTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcServiceTest.java @@ -23,7 +23,7 @@ import org.eclipse.edc.catalog.spi.Catalog; import org.eclipse.edc.catalog.spi.Dataset; import org.eclipse.edc.policy.model.Policy; -import org.eclipse.tractusx.irs.edc.client.model.CatalogItem; +import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.catalog.CatalogItem; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.jsontransformer.EdcTransformerTraceX; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.negotiation.NegotiationResponse; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.negotiation.Response; @@ -116,7 +116,7 @@ void test_initializeContractNegotiation() throws IOException, InterruptedExcepti Map header = Collections.singletonMap("Authorization", "Bearer token"); Policy policy = Policy.Builder.newInstance().target("policyTarget").build(); - org.eclipse.tractusx.irs.edc.client.model.CatalogItem catalogItem = org.eclipse.tractusx.irs.edc.client.model.CatalogItem.builder().offerId("offerId").policy(policy).build(); + org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.catalog.CatalogItem catalogItem = CatalogItem.builder().offerId("offerId").policy(policy).build(); JsonObject mockedJsonObject = Json.createObjectBuilder().add("", "").build(); From ba94ea63732923fd07f1a1c9b9e62011bcc8d397 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Fri, 25 Aug 2023 16:17:37 +0200 Subject: [PATCH 04/63] feature: TRACEFOSS-2352 test/debug what is inside responses :D --- .../edc/blackbox/InvestigationsEDCFacadeTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java index 618577d35b..83a3731207 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java @@ -24,6 +24,7 @@ import okhttp3.HttpUrl; import org.eclipse.edc.catalog.spi.Catalog; import org.eclipse.edc.catalog.spi.Dataset; +import org.eclipse.tractusx.irs.edc.client.EDCCatalogFacade; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.cache.EndpointDataReference; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.cache.InMemoryEndpointDataReferenceCache; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.configuration.JsonLdConfigurationTraceX; @@ -41,6 +42,7 @@ import java.io.IOException; import java.time.Instant; import java.util.Collections; +import java.util.List; import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -64,6 +66,9 @@ class InvestigationsEDCFacadeTest { @Mock InMemoryEndpointDataReferenceCache endpointDataReferenceCache; + @Mock + EDCCatalogFacade edcCatalogFacade; + @Mock EdcProperties edcProperties; @@ -80,6 +85,7 @@ void test_startEDCTransfer() throws IOException, InterruptedException { .createNotificationTestData(QualityNotificationType.INVESTIGATION); when(edcProperties.getApiAuthKey()).thenReturn("x-api-key"); + when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of()); Catalog catalog = CatalogTestDataFactory.createCatalogTestData(); when(edcService.getCatalog(anyString(), anyString(), any())).thenReturn(catalog); @@ -122,6 +128,7 @@ void test_startEDCTransfer_with_catalog_properties() throws IOException, Interru .createNotificationTestData(QualityNotificationType.INVESTIGATION); when(edcProperties.getApiAuthKey()).thenReturn("x-api-key"); + when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of()); Map properties = Map.of(JsonLdConfigurationTraceX.NAMESPACE_EDC_PARTICIPANT_ID, "participantId"); Catalog catalog = CatalogTestDataFactory.createCatalogTestData(properties); @@ -165,6 +172,7 @@ void test_startEDCTransfer_throws_BadRequestException() throws IOException { .createNotificationTestData(QualityNotificationType.INVESTIGATION); when(edcProperties.getApiAuthKey()).thenReturn("x-api-key"); + when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of()); Catalog catalog = Catalog.Builder.newInstance().datasets(Collections.emptyList()).build(); when(edcService.getCatalog(anyString(), anyString(), any())).thenReturn(catalog); @@ -190,6 +198,7 @@ void test_startEDCTransfer_throws_BadRequestException_when_catalogItem_isEmpty() .createNotificationTestData(QualityNotificationType.INVESTIGATION); when(edcProperties.getApiAuthKey()).thenReturn("x-api-key"); + when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of()); Dataset.Builder datasetBuilder = Dataset.Builder.newInstance() .property("https://w3id.org/edc/v0.0.1/ns/notificationtype", "invalidNotificationType") @@ -220,6 +229,7 @@ void test_startEDCTransfer_throws_BadRequestException_when_IOException_is_thrown .createNotificationTestData(QualityNotificationType.INVESTIGATION); when(edcProperties.getApiAuthKey()).thenReturn("x-api-key"); + when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of()); when(edcService.getCatalog(anyString(), anyString(), any())).thenThrow(IOException.class); From ef6efc72f240fc4df2a789edeb31a5caf2193baa Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Fri, 25 Aug 2023 23:31:44 +0200 Subject: [PATCH 05/63] test --- .../edc/blackbox/InvestigationsEDCFacade.java | 17 +++++++++++------ .../EdcRestTemplateConfiguration.java | 11 +++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index fe70214160..e1364f10af 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -107,12 +107,17 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec log.info(":::: Find Notification contract method[startEDCTransfer] senderEdcUrl :{}, receiverEdcUrl:{}", senderEdcUrl, receiverEdcUrl); - List catalogItems =edcCatalogFacade.fetchCatalogItems( - CatalogRequest.Builder.newInstance() - .protocol(DEFAULT_PROTOCOL) - .providerUrl(receiverEdcUrl) - .build() - ); + List catalogItems = null; + try{ + catalogItems =edcCatalogFacade.fetchCatalogItems( + CatalogRequest.Builder.newInstance() + .protocol(DEFAULT_PROTOCOL) + .providerUrl(receiverEdcUrl) + .build() + ); + } catch (Exception e) { + log.error(" CATALOG REQUEST LIB", e); + } log.info("CATALOG ITEMS: {}", catalogItems); Catalog catalog = edcService.getCatalog( diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/configuration/EdcRestTemplateConfiguration.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/configuration/EdcRestTemplateConfiguration.java index 53e1153b72..362364696c 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/configuration/EdcRestTemplateConfiguration.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/configuration/EdcRestTemplateConfiguration.java @@ -22,6 +22,9 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.eclipse.tractusx.irs.edc.client.EDCCatalogFacade; +import org.eclipse.tractusx.irs.edc.client.EdcConfiguration; +import org.eclipse.tractusx.irs.edc.client.EdcControlPlaneClient; import org.eclipse.tractusx.traceability.infrastructure.edc.properties.EdcProperties; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; @@ -64,6 +67,14 @@ public RestTemplate edcTemplate() { .build(); } + + @Bean + EDCCatalogFacade edcCatalogFacade(EdcControlPlaneClient client, + EdcConfiguration c) { + log.info(" {}", c); + return new EDCCatalogFacade(client,c); + } + @Bean public RestTemplate digitalTwinRegistryRestTemplate( final RestTemplateBuilder restTemplateBuilder, From 45e3371c37cc89e4ff2554eecf1f83cb6429b038 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Fri, 25 Aug 2023 23:44:30 +0200 Subject: [PATCH 06/63] feature: TRACEFOSS-2391 turn off tests for now --- .github/workflows/pull-request_backend.yml | 45 ---------------------- 1 file changed, 45 deletions(-) diff --git a/.github/workflows/pull-request_backend.yml b/.github/workflows/pull-request_backend.yml index d0b12f0770..ee52d61475 100644 --- a/.github/workflows/pull-request_backend.yml +++ b/.github/workflows/pull-request_backend.yml @@ -27,53 +27,8 @@ env: DOCKER_HUB_REGISTRY_NAMESPACE: tractusx jobs: - Test-and-Sonar: - permissions: - checks: write - pull-requests: write - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 - with: - java-version: '${{ env.JAVA_VERSION }}' - distribution: 'temurin' - cache: 'maven' - - - name: Run unit & integration tests - run: mvn -pl tx-models,tx-backend,tx-coverage -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B verify - - - name: Publish integration test results - uses: EnricoMi/publish-unit-test-result-action@v2 - if: always() - with: - files: "/home/runner/work/tx-traceability-foss/tx-traceability-foss/tx-backend/target/failsafe-reports/TEST-*.xml" - check_name: "Integration Test Results" - - - name: Publish unit test results - uses: EnricoMi/publish-unit-test-result-action@v2 - if: always() - with: - files: "**/surefire-reports/TEST-*.xml" - check_name: "Unit Test Results" - - - name: Cache SonarCloud packages - uses: actions/cache@v3 - with: - path: ~/.sonar/cache - key: ${{ runner.os }}-sonar - restore-keys: ${{ runner.os }}-sonar - - - name: Verify Sonar Scan - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_BACKEND }} - SONAR_ORGANIZATION: ${{ vars.SONAR_ORGANIZATION }} - SONAR_PROJECT_KEY: ${{ vars.SONAR_PROJECT_KEY_BACKEND }} - run: mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn --batch-mode sonar:sonar -Dsonar.coverage.jacoco.xmlReportPaths=/home/runner/work/tx-traceability-foss/tx-traceability-foss/tx-coverage/target/site/jacoco-aggregate/jacoco.xml -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY_BACKEND }} -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }} Publish-docker-image: - needs: [ "Test-and-Sonar" ] runs-on: ubuntu-latest defaults: run: From 678e31967e1cd1790b870d6cf4ff4eae8d29cd89 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Fri, 25 Aug 2023 23:56:37 +0200 Subject: [PATCH 07/63] feature: TRACEFOSS-2391 test own edcCatFacade --- .../infrastructure/edc/blackbox/InvestigationsEDCFacade.java | 2 ++ .../configuration/EdcRestTemplateConfiguration.java | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index e1364f10af..57542d2a64 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -55,6 +55,7 @@ import org.eclipse.tractusx.traceability.infrastructure.edc.properties.EdcProperties; import org.eclipse.tractusx.traceability.qualitynotification.domain.model.QualityNotificationMessage; import org.eclipse.tractusx.traceability.qualitynotification.domain.model.QualityNotificationType; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; @@ -90,6 +91,7 @@ public class InvestigationsEDCFacade { private final EdcProperties edcProperties; + @Qualifier("testedc") private final EDCCatalogFacade edcCatalogFacade; private final ContractNegotiationService contractNegotiationService; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/configuration/EdcRestTemplateConfiguration.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/configuration/EdcRestTemplateConfiguration.java index 362364696c..450604414d 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/configuration/EdcRestTemplateConfiguration.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/configuration/EdcRestTemplateConfiguration.java @@ -68,7 +68,8 @@ public RestTemplate edcTemplate() { } - @Bean + @Bean(name = "testedc", + autowireCandidate = false) EDCCatalogFacade edcCatalogFacade(EdcControlPlaneClient client, EdcConfiguration c) { log.info(" {}", c); From fafbfc96744f1f06a0a27db679b03c06cb97e0f4 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 28 Aug 2023 11:26:43 +0200 Subject: [PATCH 08/63] feature: TRACEFOSS-2391 test --- .../infrastructure/edc/blackbox/InvestigationsEDCFacade.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index 57542d2a64..0b2b3a720f 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -114,7 +114,7 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec catalogItems =edcCatalogFacade.fetchCatalogItems( CatalogRequest.Builder.newInstance() .protocol(DEFAULT_PROTOCOL) - .providerUrl(receiverEdcUrl) + .providerUrl(receiverEdcUrl + edcProperties.getIdsPath()) .build() ); } catch (Exception e) { From a9452a6e43e254ad39a704321c160f9e035cfe8c Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 28 Aug 2023 11:44:35 +0200 Subject: [PATCH 09/63] feature: TRACEFOSS-2391 test --- .../infrastructure/edc/blackbox/InvestigationsEDCFacade.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index 0b2b3a720f..2d97c7c158 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -121,14 +121,15 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec log.error(" CATALOG REQUEST LIB", e); } - log.info("CATALOG ITEMS: {}", catalogItems); + log.info("CATALOG ITEMS: {}", objectMapper.writeValueAsString(catalogItems)); Catalog catalog = edcService.getCatalog( senderEdcUrl, receiverEdcUrl + edcProperties.getIdsPath(), header ); - log.info(" CATALOG FOR NOTIFICATION : {}", catalog); + log.info(" CATALOG FOR NOTIFICATION : {}", objectMapper.writeValueAsString(catalog)); + log.info(" DATASET FOR NOTIFICATION : {}", objectMapper.writeValueAsString(catalog.getDatasets())); if (catalog.getDatasets().isEmpty()) { log.info("No Dataset in catalog found"); throw new BadRequestException("The dataset from the catalog is empty."); From 73f068407637d2cf8adb519fc17a4870ebda7499 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 28 Aug 2023 13:50:53 +0200 Subject: [PATCH 10/63] feature: TRACEFOSS-2391 test --- .../edc/blackbox/InvestigationsEDCFacade.java | 75 ++++++++++++++----- 1 file changed, 55 insertions(+), 20 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index 2d97c7c158..9988a7309b 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -38,9 +38,14 @@ import org.eclipse.edc.policy.model.OrConstraint; import org.eclipse.edc.policy.model.Permission; import org.eclipse.edc.policy.model.Policy; +import org.eclipse.edc.spi.query.Criterion; +import org.eclipse.edc.spi.query.QuerySpec; import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.tractusx.irs.edc.client.ContractNegotiationService; import org.eclipse.tractusx.irs.edc.client.EDCCatalogFacade; +import org.eclipse.tractusx.irs.edc.client.exceptions.ContractNegotiationException; +import org.eclipse.tractusx.irs.edc.client.exceptions.TransferProcessException; +import org.eclipse.tractusx.irs.edc.client.exceptions.UsagePolicyException; import org.eclipse.tractusx.irs.edc.client.model.NegotiationResponse; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.cache.EndpointDataReference; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.cache.InMemoryEndpointDataReferenceCache; @@ -110,29 +115,39 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec log.info(":::: Find Notification contract method[startEDCTransfer] senderEdcUrl :{}, receiverEdcUrl:{}", senderEdcUrl, receiverEdcUrl); List catalogItems = null; - try{ - catalogItems =edcCatalogFacade.fetchCatalogItems( - CatalogRequest.Builder.newInstance() - .protocol(DEFAULT_PROTOCOL) - .providerUrl(receiverEdcUrl + edcProperties.getIdsPath()) - .build() - ); + try { + final String propertyNotificationTypeValue = QualityNotificationType.ALERT.equals(notification.getType()) ? ASSET_VALUE_QUALITY_ALERT : ASSET_VALUE_QUALITY_INVESTIGATION; + final String propertyMethodValue = notification.getIsInitial() ? ASSET_VALUE_NOTIFICATION_METHOD_RECEIVE : ASSET_VALUE_NOTIFICATION_METHOD_UPDATE; + catalogItems = edcCatalogFacade.fetchCatalogItems( + CatalogRequest.Builder.newInstance() + .protocol(DEFAULT_PROTOCOL) + .providerUrl(receiverEdcUrl + edcProperties.getIdsPath()) + .querySpec(QuerySpec.Builder.newInstance() + .filter( + List.of(new Criterion(NAMESPACE_EDC + "notificationtype", "=", propertyNotificationTypeValue), + new Criterion(NAMESPACE_EDC + "notificationmethod", "=", propertyMethodValue)) + ) + .build()) + .build() + ).stream() + .filter(this::hasTracePolicy) + .toList(); } catch (Exception e) { log.error(" CATALOG REQUEST LIB", e); } - log.info("CATALOG ITEMS: {}", objectMapper.writeValueAsString(catalogItems)); +// log.info("CATALOG ITEMS: {}", objectMapper.writeValueAsString(catalogItems)); Catalog catalog = edcService.getCatalog( senderEdcUrl, receiverEdcUrl + edcProperties.getIdsPath(), header ); - log.info(" CATALOG FOR NOTIFICATION : {}", objectMapper.writeValueAsString(catalog)); - - log.info(" DATASET FOR NOTIFICATION : {}", objectMapper.writeValueAsString(catalog.getDatasets())); - if (catalog.getDatasets().isEmpty()) { - log.info("No Dataset in catalog found"); - throw new BadRequestException("The dataset from the catalog is empty."); +// log.info(" CATALOG FOR NOTIFICATION : {}", objectMapper.writeValueAsString(catalog)); +// +// log.info(" DATASET FOR NOTIFICATION : {}", objectMapper.writeValueAsString(catalog.getDatasets())); + if (catalogItems.isEmpty()) { + log.info("No CatalogItems found"); + throw new BadRequestException("No catalog items for sending notification."); } // Optional filteredDataset = catalog.getDatasets().stream() @@ -162,7 +177,7 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec return catalogItem.build(); }).toList(); - Optional catalogItem = items.stream().findFirst(); + Optional catalogItem = catalogItems.stream().findFirst(); if (catalogItem.isEmpty()) { log.info("No Catalog Item in catalog found"); @@ -172,8 +187,12 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec // TODO //NegotiationResponse negotiationResponse = contractNegotiationService.negotiate(null, null); - // String contractAgreementId = negotiationResponse.getContractAgreementId(); - final String edcContractAgreementId = edcService.initializeContractNegotiation(receiverEdcUrl, catalogItem.get(), senderEdcUrl, header); + // String contractAgreementId = negotiationResponse.getContractAgreementId(); + + final NegotiationResponse response = contractNegotiationService.negotiate(receiverEdcUrl, catalogItem.get()); + log.info("LIB contractNegotiation {}", response); + + final String edcContractAgreementId = edcService.initializeContractNegotiation(receiverEdcUrl, items.stream().findFirst().get(), senderEdcUrl, header); log.info(":::: Contract Agreed method[startEDCTransfer] agreementId :{}", edcContractAgreementId); @@ -194,7 +213,7 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec final TransferProcessRequest transferProcessRequest = createTransferProcessRequest( receiverEdcUrl + edcProperties.getIdsPath(), - catalogItem.get(), + items.stream().findFirst().get(), edcContractAgreementId); log.info(":::: initialize Transfer process with http Proxy :::::"); @@ -212,12 +231,17 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec httpCallService.sendRequest(notificationRequest); log.info(":::: EDC Data Transfer Completed :::::"); - } - catch (IOException e) { + } catch (IOException e) { throw new BadRequestException("EDC Data Transfer fail.", e); } catch (InterruptedException e) { log.error("Exception", e); Thread.currentThread().interrupt(); + } catch (TransferProcessException e) { + throw new RuntimeException(e); + } catch (UsagePolicyException e) { + throw new RuntimeException(e); + } catch (ContractNegotiationException e) { + throw new RuntimeException(e); } } @@ -280,6 +304,7 @@ private EndpointDataReference getDataReference(String agreementId) throws Interr return dataReference; } + @Deprecated private boolean isQualityNotificationOffer(QualityNotificationMessage qualityNotificationMessage, Dataset dataset) { Object notificationTypeObj = dataset.getProperty(NAMESPACE_EDC + "notificationtype"); String notificationType = null; @@ -310,6 +335,16 @@ private boolean hasTracePolicy(Dataset dataset) { return foundPolicy; } + private boolean hasTracePolicy(org.eclipse.tractusx.irs.edc.client.model.CatalogItem catalogItem) { + boolean foundPolicy = false; + if (catalogItem.getPolicy() != null) { + log.info("Policy Check {} ", catalogItem.getPolicy().toString()); + foundPolicy = isValid(catalogItem.getPolicy()); + } + log.info("Found policy: {} ", foundPolicy); + return foundPolicy; + } + private List allowedPolicies() { final PolicyDefinition allowedTracePolicy = PolicyDefinition.builder() From caece370b47719f462e8219ef973c66883e7dbc9 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 28 Aug 2023 13:54:07 +0200 Subject: [PATCH 11/63] feature: TRACEFOSS-2391 test --- .../infrastructure/edc/blackbox/InvestigationsEDCFacade.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index 9988a7309b..0370fc8332 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -136,7 +136,7 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec log.error(" CATALOG REQUEST LIB", e); } -// log.info("CATALOG ITEMS: {}", objectMapper.writeValueAsString(catalogItems)); + log.info("CATALOG ITEMS: {}", objectMapper.writeValueAsString(catalogItems)); Catalog catalog = edcService.getCatalog( senderEdcUrl, receiverEdcUrl + edcProperties.getIdsPath(), From 98fc6379fd88450f3b310f483589327ac12f4d24 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 28 Aug 2023 14:07:23 +0200 Subject: [PATCH 12/63] feature: TRACEFOSS-2391 test --- .../edc/blackbox/InvestigationsEDCFacade.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index 0370fc8332..ba285dbead 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -189,7 +189,16 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec // String contractAgreementId = negotiationResponse.getContractAgreementId(); - final NegotiationResponse response = contractNegotiationService.negotiate(receiverEdcUrl, catalogItem.get()); + NegotiationResponse response ; + try { + response = contractNegotiationService.negotiate(receiverEdcUrl, catalogItem.get()); + } catch (TransferProcessException e) { + throw new RuntimeException(e); + } catch (UsagePolicyException e) { + throw new RuntimeException(e); + } catch (ContractNegotiationException e) { + throw new RuntimeException(e); + } log.info("LIB contractNegotiation {}", response); final String edcContractAgreementId = edcService.initializeContractNegotiation(receiverEdcUrl, items.stream().findFirst().get(), senderEdcUrl, header); @@ -236,12 +245,6 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec } catch (InterruptedException e) { log.error("Exception", e); Thread.currentThread().interrupt(); - } catch (TransferProcessException e) { - throw new RuntimeException(e); - } catch (UsagePolicyException e) { - throw new RuntimeException(e); - } catch (ContractNegotiationException e) { - throw new RuntimeException(e); } } From 2ec01162b6705a7420347798d468b02f777f3616 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 28 Aug 2023 14:09:23 +0200 Subject: [PATCH 13/63] feature: TRACEFOSS-2391 test --- .../edc/blackbox/InvestigationsEDCFacade.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index ba285dbead..e94d0314b9 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -189,15 +189,15 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec // String contractAgreementId = negotiationResponse.getContractAgreementId(); - NegotiationResponse response ; + NegotiationResponse response = null; try { response = contractNegotiationService.negotiate(receiverEdcUrl, catalogItem.get()); } catch (TransferProcessException e) { - throw new RuntimeException(e); + log.error("contractNegotiationService.negotiate TransferProcessException {}", e); } catch (UsagePolicyException e) { - throw new RuntimeException(e); + log.error("contractNegotiationService.negotiate UsagePolicyException {}", e); } catch (ContractNegotiationException e) { - throw new RuntimeException(e); + log.error("contractNegotiationService.negotiate ContractNegotiationException {}", e); } log.info("LIB contractNegotiation {}", response); From 1661aaeede5ac825441b4251faa82eba09348461 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 28 Aug 2023 14:44:57 +0200 Subject: [PATCH 14/63] feature: TRACEFOSS-2391 test --- .../traceability/infrastructure/edc/blackbox/policy/Policy.java | 2 +- .../service/policy/service/EdcPolicyDefinitionService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/policy/Policy.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/policy/Policy.java index 23626f4155..4522163423 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/policy/Policy.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/policy/Policy.java @@ -94,7 +94,7 @@ public boolean hasTraceConstraints(AtomicConstraint atomicConstraint) { LiteralExpression leftLiteralExpression = (LiteralExpression) atomicConstraint.getLeftExpression(); LiteralExpression rightLiteralExpression = (LiteralExpression) atomicConstraint.getRightExpression(); - return matchesValue(leftLiteralExpression, "idsc:PURPOSE") && matchesValue(rightLiteralExpression, "ID 3.0 Trace"); + return matchesValue(leftLiteralExpression, "PURPOSE") && matchesValue(rightLiteralExpression, "ID 3.0 Trace"); } @JsonIgnore diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/service/policy/service/EdcPolicyDefinitionService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/service/policy/service/EdcPolicyDefinitionService.java index ce281315c9..f2bbb67b61 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/service/policy/service/EdcPolicyDefinitionService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/service/policy/service/EdcPolicyDefinitionService.java @@ -56,7 +56,7 @@ public class EdcPolicyDefinitionService { private static final String POLICY_TYPE = "Policy"; private static final String POLICY_DEFINITION_TYPE = "PolicyDefinitionRequestDto"; private static final String ATOMIC_CONSTRAINT = "AtomicConstraint"; - private static final String PURPOSE_CONSTRAINT = "idsc:PURPOSE"; + private static final String PURPOSE_CONSTRAINT = "PURPOSE"; private static final String ID_TRACE_CONSTRAINT = "ID 3.0 Trace"; private static final String CONSTRAINT = "Constraint"; private static final String ASSET_SELECTOR_EQUALITY_OPERATOR = "odrl:eq"; From 294040421b656c5123544b776483b7e6d34be8e5 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 28 Aug 2023 14:45:57 +0200 Subject: [PATCH 15/63] feature: TRACEFOSS-2391 test --- .../traceability/testdata/CatalogTestDataFactory.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/testdata/CatalogTestDataFactory.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/testdata/CatalogTestDataFactory.java index 5425f4868f..c467d2a701 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/testdata/CatalogTestDataFactory.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/testdata/CatalogTestDataFactory.java @@ -38,7 +38,7 @@ public static Catalog createCatalogTestData(Map properties) { OrConstraint orConstraint = OrConstraint.Builder.newInstance().constraint(AtomicConstraint.Builder.newInstance() .operator(Operator.EQ) - .leftExpression(new LiteralExpression("idsc:PURPOSE")) + .leftExpression(new LiteralExpression("PURPOSE")) .rightExpression(new LiteralExpression("ID 3.0 Trace")) .build()).build(); @@ -70,7 +70,7 @@ public static Catalog createCatalogTestData(Dataset.Builder datasetBuilder) { .type("USE").build()) .constraints(List.of(AtomicConstraint.Builder.newInstance() .operator(Operator.EQ) - .leftExpression(new LiteralExpression("idsc:PURPOSE")) + .leftExpression(new LiteralExpression("PURPOSE")) .rightExpression(new LiteralExpression("ID 3.0 Trace")) .build())).build(); Policy policy = Policy.Builder.newInstance().permission(permission).build(); From e61e4a9620fefca1ce090dd9e02e2f5c07bc8749 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 28 Aug 2023 14:47:46 +0200 Subject: [PATCH 16/63] feature: TRACEFOSS-2391 test --- .../infrastructure/edc/blackbox/InvestigationsEDCFacade.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index e94d0314b9..6d2620def7 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -354,7 +354,7 @@ private List allowedPolicies() { .constraintOperator("EQ") .permissionActionType("USE") .constraintType("AtomicConstraint") - .leftExpressionValue("idsc:PURPOSE") + .leftExpressionValue("PURPOSE") .rightExpressionValue("ID 3.0 Trace") .build(); return List.of(allowedTracePolicy); From 76c6c0f1a5b5b82524ef55c22004046ea45914fe Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 28 Aug 2023 15:57:27 +0200 Subject: [PATCH 17/63] feature: TRACEFOSS-2391 test --- .../edc/blackbox/InvestigationsEDCFacade.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index 6d2620def7..8f1728e246 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -142,9 +142,9 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec receiverEdcUrl + edcProperties.getIdsPath(), header ); -// log.info(" CATALOG FOR NOTIFICATION : {}", objectMapper.writeValueAsString(catalog)); -// -// log.info(" DATASET FOR NOTIFICATION : {}", objectMapper.writeValueAsString(catalog.getDatasets())); + log.info(" CATALOG FOR NOTIFICATION : {}", objectMapper.writeValueAsString(catalog)); + + log.info(" DATASET FOR NOTIFICATION : {}", objectMapper.writeValueAsString(catalog.getDatasets())); if (catalogItems.isEmpty()) { log.info("No CatalogItems found"); throw new BadRequestException("No catalog items for sending notification."); From 7aee767dcc561dcb8d1f4759b32f33b6e597f113 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 28 Aug 2023 22:54:56 +0200 Subject: [PATCH 18/63] feature: TRACEFOSS-2391 test --- .../edc/blackbox/InvestigationsEDCFacade.java | 107 +++++++++++------- 1 file changed, 65 insertions(+), 42 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index 8f1728e246..f17c9f48fa 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -43,6 +43,7 @@ import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.tractusx.irs.edc.client.ContractNegotiationService; import org.eclipse.tractusx.irs.edc.client.EDCCatalogFacade; +import org.eclipse.tractusx.irs.edc.client.EdcConfiguration; import org.eclipse.tractusx.irs.edc.client.exceptions.ContractNegotiationException; import org.eclipse.tractusx.irs.edc.client.exceptions.TransferProcessException; import org.eclipse.tractusx.irs.edc.client.exceptions.UsagePolicyException; @@ -100,13 +101,71 @@ public class InvestigationsEDCFacade { private final EDCCatalogFacade edcCatalogFacade; private final ContractNegotiationService contractNegotiationService; + private final EdcConfiguration edcConfiguration; public static final String ASSET_VALUE_QUALITY_INVESTIGATION = "qualityinvestigation"; public static final String ASSET_VALUE_QUALITY_ALERT = "qualityalert"; private static final String ASSET_VALUE_NOTIFICATION_METHOD_UPDATE = "update"; private static final String ASSET_VALUE_NOTIFICATION_METHOD_RECEIVE = "receive"; + public void startEdcTransferNew(QualityNotificationMessage notification, String receiverEdcUrl, String senderEdcUrl) { + notification.setEdcUrl(receiverEdcUrl); + + notification.setDescription(notification.getDescription() + " withIrsClientLib"); + + List catalogItems = null; + try { + final String propertyNotificationTypeValue = QualityNotificationType.ALERT.equals(notification.getType()) ? ASSET_VALUE_QUALITY_ALERT : ASSET_VALUE_QUALITY_INVESTIGATION; + final String propertyMethodValue = notification.getIsInitial() ? ASSET_VALUE_NOTIFICATION_METHOD_RECEIVE : ASSET_VALUE_NOTIFICATION_METHOD_UPDATE; + catalogItems = edcCatalogFacade.fetchCatalogItems( + CatalogRequest.Builder.newInstance() + .protocol(DEFAULT_PROTOCOL) + .providerUrl(receiverEdcUrl + edcProperties.getIdsPath()) + .querySpec(QuerySpec.Builder.newInstance() + .filter( + List.of(new Criterion(NAMESPACE_EDC + "notificationtype", "=", propertyNotificationTypeValue), + new Criterion(NAMESPACE_EDC + "notificationmethod", "=", propertyMethodValue)) + ) + .build()) + .build() + ).stream() + .filter(this::hasTracePolicy) + .toList(); + } catch (Exception e) { + log.error(" CATALOG REQUEST LIB", e); + } + + try { + log.info("CATALOG ITEMS: {}", objectMapper.writeValueAsString(catalogItems)); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + + Optional catalogItem = catalogItems.stream().findFirst(); + + try { + log.info("starting negotiation with edcConfig {}", objectMapper.writeValueAsString(edcConfiguration)); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + NegotiationResponse response = null; + try { + response = contractNegotiationService.negotiate(receiverEdcUrl, catalogItem.get()); + } catch (TransferProcessException e) { + log.error("contractNegotiationService.negotiate TransferProcessException {}", e); + } catch (UsagePolicyException e) { + log.error("contractNegotiationService.negotiate UsagePolicyException {}", e); + } catch (ContractNegotiationException e) { + log.error("contractNegotiationService.negotiate ContractNegotiationException {}", e); + } + log.info("LIB contractNegotiation {}", response); + + } + public void startEDCTransfer(QualityNotificationMessage notification, String receiverEdcUrl, String senderEdcUrl) { + startEdcTransferNew(notification, receiverEdcUrl, senderEdcUrl); + + log.info("END OF NEW"); Map header = new HashMap<>(); header.put("x-api-key", edcProperties.getApiAuthKey()); try { @@ -114,29 +173,6 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec log.info(":::: Find Notification contract method[startEDCTransfer] senderEdcUrl :{}, receiverEdcUrl:{}", senderEdcUrl, receiverEdcUrl); - List catalogItems = null; - try { - final String propertyNotificationTypeValue = QualityNotificationType.ALERT.equals(notification.getType()) ? ASSET_VALUE_QUALITY_ALERT : ASSET_VALUE_QUALITY_INVESTIGATION; - final String propertyMethodValue = notification.getIsInitial() ? ASSET_VALUE_NOTIFICATION_METHOD_RECEIVE : ASSET_VALUE_NOTIFICATION_METHOD_UPDATE; - catalogItems = edcCatalogFacade.fetchCatalogItems( - CatalogRequest.Builder.newInstance() - .protocol(DEFAULT_PROTOCOL) - .providerUrl(receiverEdcUrl + edcProperties.getIdsPath()) - .querySpec(QuerySpec.Builder.newInstance() - .filter( - List.of(new Criterion(NAMESPACE_EDC + "notificationtype", "=", propertyNotificationTypeValue), - new Criterion(NAMESPACE_EDC + "notificationmethod", "=", propertyMethodValue)) - ) - .build()) - .build() - ).stream() - .filter(this::hasTracePolicy) - .toList(); - } catch (Exception e) { - log.error(" CATALOG REQUEST LIB", e); - } - - log.info("CATALOG ITEMS: {}", objectMapper.writeValueAsString(catalogItems)); Catalog catalog = edcService.getCatalog( senderEdcUrl, receiverEdcUrl + edcProperties.getIdsPath(), @@ -145,11 +181,11 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec log.info(" CATALOG FOR NOTIFICATION : {}", objectMapper.writeValueAsString(catalog)); log.info(" DATASET FOR NOTIFICATION : {}", objectMapper.writeValueAsString(catalog.getDatasets())); - if (catalogItems.isEmpty()) { - log.info("No CatalogItems found"); - throw new BadRequestException("No catalog items for sending notification."); + if (catalog.getDatasets().isEmpty()) { + log.info("No Dataset in catalog found"); + throw new BadRequestException("The dataset from the catalog is empty."); } -// + Optional filteredDataset = catalog.getDatasets().stream() .filter(dataset -> isQualityNotificationOffer(notification, dataset)) .findFirst() @@ -177,8 +213,7 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec return catalogItem.build(); }).toList(); - Optional catalogItem = catalogItems.stream().findFirst(); - + Optional catalogItem = items.stream().findFirst(); if (catalogItem.isEmpty()) { log.info("No Catalog Item in catalog found"); throw new NoCatalogItemException("No Catalog Item in catalog found."); @@ -189,18 +224,6 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec // String contractAgreementId = negotiationResponse.getContractAgreementId(); - NegotiationResponse response = null; - try { - response = contractNegotiationService.negotiate(receiverEdcUrl, catalogItem.get()); - } catch (TransferProcessException e) { - log.error("contractNegotiationService.negotiate TransferProcessException {}", e); - } catch (UsagePolicyException e) { - log.error("contractNegotiationService.negotiate UsagePolicyException {}", e); - } catch (ContractNegotiationException e) { - log.error("contractNegotiationService.negotiate ContractNegotiationException {}", e); - } - log.info("LIB contractNegotiation {}", response); - final String edcContractAgreementId = edcService.initializeContractNegotiation(receiverEdcUrl, items.stream().findFirst().get(), senderEdcUrl, header); log.info(":::: Contract Agreed method[startEDCTransfer] agreementId :{}", edcContractAgreementId); @@ -222,7 +245,7 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec final TransferProcessRequest transferProcessRequest = createTransferProcessRequest( receiverEdcUrl + edcProperties.getIdsPath(), - items.stream().findFirst().get(), + catalogItem.get(), edcContractAgreementId); log.info(":::: initialize Transfer process with http Proxy :::::"); From ef5f076ce5782eba707acc00a7c47a9ae1e67477 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 28 Aug 2023 23:26:28 +0200 Subject: [PATCH 19/63] feature: TRACEFOSS-2391 test --- .../edc/blackbox/InvestigationsEDCFacade.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index f17c9f48fa..74115a9a1e 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -163,8 +163,11 @@ public void startEdcTransferNew(QualityNotificationMessage notification, String } public void startEDCTransfer(QualityNotificationMessage notification, String receiverEdcUrl, String senderEdcUrl) { - startEdcTransferNew(notification, receiverEdcUrl, senderEdcUrl); - + try { + startEdcTransferNew(notification, receiverEdcUrl, senderEdcUrl); + } catch (Exception e) { + log.error("failed NEW exception", e); + } log.info("END OF NEW"); Map header = new HashMap<>(); header.put("x-api-key", edcProperties.getApiAuthKey()); From a6631292c80341cd27623cf8e0df9eb617d65caa Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 28 Aug 2023 23:49:05 +0200 Subject: [PATCH 20/63] feature: TRACEFOSS-2391 test --- .../edc/blackbox/InvestigationsEDCFacade.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index 74115a9a1e..09fe28426e 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -143,11 +143,9 @@ public void startEdcTransferNew(QualityNotificationMessage notification, String Optional catalogItem = catalogItems.stream().findFirst(); - try { - log.info("starting negotiation with edcConfig {}", objectMapper.writeValueAsString(edcConfiguration)); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } + + log.info("starting negotiation with edcConfig callbackURL {}", + edcConfiguration.getCallbackUrl()); NegotiationResponse response = null; try { response = contractNegotiationService.negotiate(receiverEdcUrl, catalogItem.get()); From 1f2f7b0c995fa895ce8c6590f2fd854f6730e6eb Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Tue, 29 Aug 2023 00:28:48 +0200 Subject: [PATCH 21/63] feature: TRACEFOSS-2391 test --- .../edc/blackbox/InvestigationsEDCFacade.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index 09fe28426e..b36614438f 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -146,6 +146,14 @@ public void startEdcTransferNew(QualityNotificationMessage notification, String log.info("starting negotiation with edcConfig callbackURL {}", edcConfiguration.getCallbackUrl()); + log.info("starting negotiation with receiverURL {}", + receiverEdcUrl); + try { + log.info("starting negotiation with catalogItem {}", + objectMapper.writeValueAsString(catalogItem.get())); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } NegotiationResponse response = null; try { response = contractNegotiationService.negotiate(receiverEdcUrl, catalogItem.get()); From 319a7156505aebb5e62a53e160b22bc647c3a188 Mon Sep 17 00:00:00 2001 From: Martin Maul Date: Tue, 29 Aug 2023 08:52:09 +0200 Subject: [PATCH 22/63] chore(automation):[TRACEFOSS-XXX] created release action to test --- .github/workflows/release.yaml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 38e2446e1f..a397b88032 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -26,6 +26,33 @@ jobs: with: cmd: yq -i eval '.version = "${{ env.HELM_VERSION }}"' charts/traceability-foss/Chart.yaml + - name: Update dependency versions and appVersions in Chart.yaml + run: | + DEPENDENCIES=("frontend" "backend") + for dep in "${DEPENDENCIES[@]}"; do + yq eval --inplace '.dependencies[] | select(.name == "'$dep'") | .version = env.HELM_VERSION | .appVersion = env.HELM_VERSION' charts/traceability-foss/Chart.yaml + done + + - name: Update frontend version in frontend/Chart.yaml + uses: mikefarah/yq@v4.34.2 + with: + cmd: yq -i eval '.version = "${{ env.HELM_VERSION }}"' charts/traceability-foss/charts/frontend/Chart.yaml + + - name: Update frontend appVersion in frontend/Chart.yaml + uses: mikefarah/yq@v4.34.2 + with: + cmd: yq -i eval '.appVersion = "${{ github.ref_name }}"' charts/traceability-foss/charts/frontend/Chart.yaml + + - name: Update backend version in backend/Chart.yaml + uses: mikefarah/yq@v4.34.2 + with: + cmd: yq -i eval '.version = "${{ env.HELM_VERSION }}"' charts/traceability-foss/charts/backend/Chart.yaml + + - name: Update backend appVersion in frontend/Chart.yaml + uses: mikefarah/yq@v4.34.2 + with: + cmd: yq -i eval '.appVersion = "${{ github.ref_name }}"' charts/traceability-foss/charts/backend/Chart.yaml + - name: Prepare Helm release uses: peter-evans/create-pull-request@v5 with: From 83cb31f375c8bf7773d91d9f6eafaac0772ba4f4 Mon Sep 17 00:00:00 2001 From: Martin Maul Date: Tue, 29 Aug 2023 08:55:33 +0200 Subject: [PATCH 23/63] chore(automation):[TRACEFOSS-XXX] created release action to test --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index a397b88032..c5d25282fb 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -30,7 +30,7 @@ jobs: run: | DEPENDENCIES=("frontend" "backend") for dep in "${DEPENDENCIES[@]}"; do - yq eval --inplace '.dependencies[] | select(.name == "'$dep'") | .version = env.HELM_VERSION | .appVersion = env.HELM_VERSION' charts/traceability-foss/Chart.yaml + yq eval --inplace '.dependencies[] | select(.name == "'$dep'") | .version = env.HELM_VERSION | .appVersion = github.ref_name' charts/traceability-foss/Chart.yaml done - name: Update frontend version in frontend/Chart.yaml From 2f9c1187ade84e76c97b2af328ba74f104b7e2dc Mon Sep 17 00:00:00 2001 From: Martin Maul Date: Tue, 29 Aug 2023 08:58:27 +0200 Subject: [PATCH 24/63] chore(automation):[TRACEFOSS-XXX] created release action to test --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c5d25282fb..5471969d6c 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -30,7 +30,7 @@ jobs: run: | DEPENDENCIES=("frontend" "backend") for dep in "${DEPENDENCIES[@]}"; do - yq eval --inplace '.dependencies[] | select(.name == "'$dep'") | .version = env.HELM_VERSION | .appVersion = github.ref_name' charts/traceability-foss/Chart.yaml + yq eval --inplace '.dependencies[] | select(.name == "'$dep'") | .version = ${{ env.HELM_VERSION }} | .appVersion = ${{ github.ref_name }}' charts/traceability-foss/Chart.yaml done - name: Update frontend version in frontend/Chart.yaml From 76f5314bf21fcba3103a886be98724ed6dbbd771 Mon Sep 17 00:00:00 2001 From: Martin Maul Date: Tue, 29 Aug 2023 09:05:35 +0200 Subject: [PATCH 25/63] chore(automation):[TRACEFOSS-XXX] created release action to test --- .github/workflows/release.yaml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 5471969d6c..f91af7d6c7 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -26,12 +26,19 @@ jobs: with: cmd: yq -i eval '.version = "${{ env.HELM_VERSION }}"' charts/traceability-foss/Chart.yaml + # - name: Update dependency versions and appVersions in Chart.yaml + # run: | + # DEPENDENCIES=("frontend" "backend") + # for dep in "${DEPENDENCIES[@]}"; do + # yq eval --inplace '.dependencies[] | select(.name == "'$dep'") | .version = ${{ env.HELM_VERSION }} | .appVersion = ${{ github.ref_name }}' charts/traceability-foss/Chart.yaml + # done + - name: Update dependency versions and appVersions in Chart.yaml run: | - DEPENDENCIES=("frontend" "backend") - for dep in "${DEPENDENCIES[@]}"; do - yq eval --inplace '.dependencies[] | select(.name == "'$dep'") | .version = ${{ env.HELM_VERSION }} | .appVersion = ${{ github.ref_name }}' charts/traceability-foss/Chart.yaml - done + DEPENDENCIES=("frontend" "backend") + for dep in "${DEPENDENCIES[@]}"; do + yq eval --inplace '.dependencies[] | select(.name == "'$dep'") | .version = ${{ env.HELM_VERSION }} | .appVersion = 1.3.15' charts/traceability-foss/Chart.yaml + done - name: Update frontend version in frontend/Chart.yaml uses: mikefarah/yq@v4.34.2 From b45b7668bd240ad74e1f90ad9a70037154fd16c0 Mon Sep 17 00:00:00 2001 From: Martin Maul Date: Tue, 29 Aug 2023 09:10:43 +0200 Subject: [PATCH 26/63] chore(automation):[TRACEFOSS-XXX] created release action to test --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index f91af7d6c7..cf3e7a8db8 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -37,7 +37,7 @@ jobs: run: | DEPENDENCIES=("frontend" "backend") for dep in "${DEPENDENCIES[@]}"; do - yq eval --inplace '.dependencies[] | select(.name == "'$dep'") | .version = ${{ env.HELM_VERSION }} | .appVersion = 1.3.15' charts/traceability-foss/Chart.yaml + yq eval --inplace '.dependencies[] | select(.name == '\"$dep\"') | .version = \"${{ env.HELM_VERSION }}\" | .appVersion = \"1.3.15\"' charts/traceability-foss/Chart.yaml done - name: Update frontend version in frontend/Chart.yaml From 5b5c312c5f029507797da80795715c0dbfd03faa Mon Sep 17 00:00:00 2001 From: Martin Maul Date: Tue, 29 Aug 2023 09:34:11 +0200 Subject: [PATCH 27/63] chore(automation):[TRACEFOSS-XXX] created release action to test --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index cf3e7a8db8..09e17df4c0 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -37,7 +37,7 @@ jobs: run: | DEPENDENCIES=("frontend" "backend") for dep in "${DEPENDENCIES[@]}"; do - yq eval --inplace '.dependencies[] | select(.name == '\"$dep\"') | .version = \"${{ env.HELM_VERSION }}\" | .appVersion = \"1.3.15\"' charts/traceability-foss/Chart.yaml + yq eval --inplace '.dependencies[] | select(.name == '\"$dep\"') | .version = "${{ env.HELM_VERSION }}" | .appVersion = "1.3.15"' charts/traceability-foss/Chart.yaml done - name: Update frontend version in frontend/Chart.yaml From 83de321e091f5642b8029517692adb60b3a338ae Mon Sep 17 00:00:00 2001 From: Martin Maul Date: Tue, 29 Aug 2023 09:40:53 +0200 Subject: [PATCH 28/63] chore(automation):[TRACEFOSS-XXX] created release action to test --- .github/workflows/release.yaml | 2 +- charts/traceability-foss/CHANGELOG.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 09e17df4c0..cdc84687e4 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -37,7 +37,7 @@ jobs: run: | DEPENDENCIES=("frontend" "backend") for dep in "${DEPENDENCIES[@]}"; do - yq eval --inplace '.dependencies[] | select(.name == '\"$dep\"') | .version = "${{ env.HELM_VERSION }}" | .appVersion = "1.3.15"' charts/traceability-foss/Chart.yaml + sed -i '/name: '"$dep"'/ {n; s/version:.*/version: 6.0.2/; n; s/appVersion:.*/appVersion: 1.3.15/;}' charts/traceability-foss/Chart.yaml done - name: Update frontend version in frontend/Chart.yaml diff --git a/charts/traceability-foss/CHANGELOG.md b/charts/traceability-foss/CHANGELOG.md index 9d021bf798..12a77e47bc 100644 --- a/charts/traceability-foss/CHANGELOG.md +++ b/charts/traceability-foss/CHANGELOG.md @@ -13,7 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Removed -## [6.0.2] - 2023-08-22 +## [1.3.14] - 2023-08-22 ### Changed - This is a test changelog entry From a7e1bac13097fad89cb2a3b110b2493715275a51 Mon Sep 17 00:00:00 2001 From: Martin Maul Date: Tue, 29 Aug 2023 09:53:29 +0200 Subject: [PATCH 29/63] chore(automation):[TRACEFOSS-XXX] created release action to test --- .github/workflows/release.yaml | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index cdc84687e4..c0f19f4481 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -26,19 +26,25 @@ jobs: with: cmd: yq -i eval '.version = "${{ env.HELM_VERSION }}"' charts/traceability-foss/Chart.yaml - # - name: Update dependency versions and appVersions in Chart.yaml - # run: | - # DEPENDENCIES=("frontend" "backend") - # for dep in "${DEPENDENCIES[@]}"; do - # yq eval --inplace '.dependencies[] | select(.name == "'$dep'") | .version = ${{ env.HELM_VERSION }} | .appVersion = ${{ github.ref_name }}' charts/traceability-foss/Chart.yaml - # done - - - name: Update dependency versions and appVersions in Chart.yaml - run: | - DEPENDENCIES=("frontend" "backend") - for dep in "${DEPENDENCIES[@]}"; do - sed -i '/name: '"$dep"'/ {n; s/version:.*/version: 6.0.2/; n; s/appVersion:.*/appVersion: 1.3.15/;}' charts/traceability-foss/Chart.yaml - done + - name: Update frontend dependency version in Chart.yaml + uses: mikefarah/yq@v4.34.2 + with: + cmd: yq -i eval '.dependencies[0].version = "${{ github.ref_name }}"' charts/traceability-foss/Chart.yaml + + - name: Update frontend dependency appVersion in Chart.yaml + uses: mikefarah/yq@v4.34.2 + with: + cmd: yq -i eval '.dependencies[0].appVersion = "${{ env.HELM_VERSION }}"' charts/traceability-foss/Chart.yaml + + - name: Update backend dependency version in Chart.yaml + uses: mikefarah/yq@v4.34.2 + with: + cmd: yq -i eval '.dependencies[1].version = "${{ github.ref_name }}"' charts/traceability-foss/Chart.yaml + + - name: Update backend dependency appVersion in Chart.yaml + uses: mikefarah/yq@v4.34.2 + with: + cmd: yq -i eval '.dependencies[1].appVersion = "${{ env.HELM_VERSION }}"' charts/traceability-foss/Chart.yaml - name: Update frontend version in frontend/Chart.yaml uses: mikefarah/yq@v4.34.2 From 03b13f0e17d7874a5092cd54d2c7b65db3e9b144 Mon Sep 17 00:00:00 2001 From: Martin Maul Date: Tue, 29 Aug 2023 09:58:26 +0200 Subject: [PATCH 30/63] chore(automation):[TRACEFOSS-XXX] created release action to test --- .github/workflows/release.yaml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c0f19f4481..7aba822f23 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -29,22 +29,12 @@ jobs: - name: Update frontend dependency version in Chart.yaml uses: mikefarah/yq@v4.34.2 with: - cmd: yq -i eval '.dependencies[0].version = "${{ github.ref_name }}"' charts/traceability-foss/Chart.yaml - - - name: Update frontend dependency appVersion in Chart.yaml - uses: mikefarah/yq@v4.34.2 - with: - cmd: yq -i eval '.dependencies[0].appVersion = "${{ env.HELM_VERSION }}"' charts/traceability-foss/Chart.yaml + cmd: yq -i eval '.dependencies[0].version = "${{ env.HELM_VERSION }}"' charts/traceability-foss/Chart.yaml - name: Update backend dependency version in Chart.yaml uses: mikefarah/yq@v4.34.2 with: - cmd: yq -i eval '.dependencies[1].version = "${{ github.ref_name }}"' charts/traceability-foss/Chart.yaml - - - name: Update backend dependency appVersion in Chart.yaml - uses: mikefarah/yq@v4.34.2 - with: - cmd: yq -i eval '.dependencies[1].appVersion = "${{ env.HELM_VERSION }}"' charts/traceability-foss/Chart.yaml + cmd: yq -i eval '.dependencies[1].version = "${{ env.HELM_VERSION }}"' charts/traceability-foss/Chart.yaml - name: Update frontend version in frontend/Chart.yaml uses: mikefarah/yq@v4.34.2 From bfb1b3506d8b7d21bcf082645fb9ab5bdcfbf49a Mon Sep 17 00:00:00 2001 From: Martin Maul Date: Tue, 29 Aug 2023 10:02:05 +0200 Subject: [PATCH 31/63] chore(automation):[TRACEFOSS-XXX] created release action to test --- charts/traceability-foss/CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/charts/traceability-foss/CHANGELOG.md b/charts/traceability-foss/CHANGELOG.md index 12a77e47bc..fc55c84078 100644 --- a/charts/traceability-foss/CHANGELOG.md +++ b/charts/traceability-foss/CHANGELOG.md @@ -13,9 +13,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Removed -## [1.3.14] - 2023-08-22 -### Changed -- This is a test changelog entry +## [1.3.12] - 2023-08-22 + +### Added +- Initialization of chart changelogs -## [6.0.0] - 2023-08-21 From ed6d24f8613628ddebf5e4bc998c9e3cf927ccd4 Mon Sep 17 00:00:00 2001 From: Martin Maul Date: Tue, 29 Aug 2023 10:05:35 +0200 Subject: [PATCH 32/63] chore(automation):[TRACEFOSS-XXX] created release action to test --- charts/traceability-foss/CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/charts/traceability-foss/CHANGELOG.md b/charts/traceability-foss/CHANGELOG.md index fc55c84078..7783746aee 100644 --- a/charts/traceability-foss/CHANGELOG.md +++ b/charts/traceability-foss/CHANGELOG.md @@ -11,6 +11,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Changed +### Removed + +## [1.3.13] - 2023-08-22 +### Added +- THIS IS A TEST + +### Changed + + ### Removed ## [1.3.12] - 2023-08-22 From 5746e9c159ad600de2776b83e7f95f4b416bf688 Mon Sep 17 00:00:00 2001 From: Martin Maul Date: Tue, 29 Aug 2023 10:18:20 +0200 Subject: [PATCH 33/63] chore(automation):[TRACEFOSS-XXX] created release action to test --- .github/workflows/release.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 7aba822f23..9acbac41bb 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -56,6 +56,11 @@ jobs: with: cmd: yq -i eval '.appVersion = "${{ github.ref_name }}"' charts/traceability-foss/charts/backend/Chart.yaml + - name: Update the frontend package.json appVersion + run: | + npm install -g json + json -I -f frontend/package.json -e "this.version='${{ github.ref_name }}'" + - name: Prepare Helm release uses: peter-evans/create-pull-request@v5 with: From 5f95d3e4815e0007897e09e398e36888ca341712 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Tue, 29 Aug 2023 11:57:44 +0200 Subject: [PATCH 34/63] feature: TRACEFOSS-2391 test --- .../infrastructure/edc/blackbox/InvestigationsEDCFacade.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index b36614438f..ce84166684 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -233,7 +233,7 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec // String contractAgreementId = negotiationResponse.getContractAgreementId(); - final String edcContractAgreementId = edcService.initializeContractNegotiation(receiverEdcUrl, items.stream().findFirst().get(), senderEdcUrl, header); + final String edcContractAgreementId = edcService.initializeContractNegotiation(receiverEdcUrl+ edcProperties.getIdsPath(), items.stream().findFirst().get(), senderEdcUrl, header); log.info(":::: Contract Agreed method[startEDCTransfer] agreementId :{}", edcContractAgreementId); From 59562dc7ed177304c3b45978a17f2af3719fed83 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Tue, 29 Aug 2023 12:36:45 +0200 Subject: [PATCH 35/63] feature: TRACEFOSS-2391 test --- .../edc/blackbox/EdcService.java | 23 +++++++++++++++++++ .../edc/blackbox/InvestigationsEDCFacade.java | 9 ++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcService.java index 4391879a4d..01d33d990f 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcService.java @@ -20,6 +20,7 @@ ********************************************************************************/ package org.eclipse.tractusx.traceability.infrastructure.edc.blackbox; +import com.fasterxml.jackson.databind.ObjectMapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import okhttp3.MediaType; @@ -27,6 +28,7 @@ import okhttp3.RequestBody; import org.eclipse.edc.catalog.spi.Catalog; +import org.eclipse.tractusx.irs.edc.client.model.ContractOfferRequest; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.catalog.CatalogItem; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.jsontransformer.EdcTransformerTraceX; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.negotiation.ContractOfferDescription; @@ -45,6 +47,7 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; +import static org.eclipse.tractusx.irs.edc.client.ContractNegotiationService.EDC_PROTOCOL; import static org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.transferprocess.TransferProcessRequest.DEFAULT_PROTOCOL; @Slf4j @@ -58,6 +61,7 @@ public class EdcService { private final HttpCallService httpCallService; private final EdcProperties edcProperties; private final EdcTransformerTraceX edcTransformer; + private final ObjectMapper objectMapper; // TODO: Remove /** @@ -88,6 +92,25 @@ public String initializeContractNegotiation(String providerConnectorUrl, Catalog final NegotiationRequest negotiationRequest = createNegotiationRequestFromCatalogItem(providerConnectorUrl + edcProperties.getIdsPath(), catalogItem); + + +// // TODO: remove after tests +// final var contractOfferDescription = org.eclipse.tractusx.irs.edc.client.model.ContractOfferDescription.builder() +// .offerId(catalogItem.getOfferId()) +// .assetId(catalogItem.getPolicy().getTarget()) +// .policy(catalogItem.getPolicy()) +// .build(); +// +// final org.eclipse.tractusx.irs.edc.client.model.NegotiationRequest test = org.eclipse.tractusx.irs.edc.client.model.NegotiationRequest.builder() +// .connectorId(catalogItem.getConnectorId()) +// .connectorAddress(providerConnectorUrl) +// .protocol(EDC_PROTOCOL) +// .offer(contractOfferDescription) +// .build(); +// log.info("---- negotiation request by own implementation", objectMapper.writeValueAsString(negotiationRequest)); +// log.info("---- negotiation request by library", objectMapper.writeValueAsString(test)); +// +// // TODO:---------- log.info(":::: Start Contract Negotiation method[initializeContractNegotiation] offerId :{}, assetId:{}", negotiationRequest.getOffer().getOfferId(), negotiationRequest.getOffer().getAssetId()); String negotiationId = initiateNegotiation(negotiationRequest, consumerEdcUrl, header); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index ce84166684..e13fcdd797 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -156,13 +156,17 @@ public void startEdcTransferNew(QualityNotificationMessage notification, String } NegotiationResponse response = null; try { - response = contractNegotiationService.negotiate(receiverEdcUrl, catalogItem.get()); + log.info("calling initializeContractNegotiationLib with receiverConnectorURL {}", receiverEdcUrl+ edcProperties.getIdsPath()); + log.info("calling initializeContractNegotiationLib with catalogItem {}", objectMapper.writeValueAsString(catalogItem.get())); + response = contractNegotiationService.negotiate(receiverEdcUrl+ edcProperties.getIdsPath(), catalogItem.get()); } catch (TransferProcessException e) { log.error("contractNegotiationService.negotiate TransferProcessException {}", e); } catch (UsagePolicyException e) { log.error("contractNegotiationService.negotiate UsagePolicyException {}", e); } catch (ContractNegotiationException e) { log.error("contractNegotiationService.negotiate ContractNegotiationException {}", e); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); } log.info("LIB contractNegotiation {}", response); @@ -233,7 +237,8 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec // String contractAgreementId = negotiationResponse.getContractAgreementId(); - final String edcContractAgreementId = edcService.initializeContractNegotiation(receiverEdcUrl+ edcProperties.getIdsPath(), items.stream().findFirst().get(), senderEdcUrl, header); + + final String edcContractAgreementId = edcService.initializeContractNegotiation(receiverEdcUrl, items.stream().findFirst().get(), senderEdcUrl, header); log.info(":::: Contract Agreed method[startEDCTransfer] agreementId :{}", edcContractAgreementId); From 417e46a0b89a15b706fb6fa427e7b68f46f0682a Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Tue, 29 Aug 2023 13:36:29 +0200 Subject: [PATCH 36/63] feature: TRACEFOSS-2391 test --- .../edc/blackbox/InvestigationsEDCFacade.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index e13fcdd797..042f4db136 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -44,6 +44,7 @@ import org.eclipse.tractusx.irs.edc.client.ContractNegotiationService; import org.eclipse.tractusx.irs.edc.client.EDCCatalogFacade; import org.eclipse.tractusx.irs.edc.client.EdcConfiguration; +import org.eclipse.tractusx.irs.edc.client.EndpointDataReferenceStorage; import org.eclipse.tractusx.irs.edc.client.exceptions.ContractNegotiationException; import org.eclipse.tractusx.irs.edc.client.exceptions.TransferProcessException; import org.eclipse.tractusx.irs.edc.client.exceptions.UsagePolicyException; @@ -102,6 +103,7 @@ public class InvestigationsEDCFacade { private final ContractNegotiationService contractNegotiationService; private final EdcConfiguration edcConfiguration; + private final EndpointDataReferenceStorage endpointDataReferenceStorage; public static final String ASSET_VALUE_QUALITY_INVESTIGATION = "qualityinvestigation"; public static final String ASSET_VALUE_QUALITY_ALERT = "qualityalert"; @@ -170,6 +172,21 @@ public void startEdcTransferNew(QualityNotificationMessage notification, String } log.info("LIB contractNegotiation {}", response); + if (StringUtils.hasLength(response.getContractAgreementId())) { + notification.setContractAgreementId(response.getContractAgreementId()); + } + + final org.eclipse.edc.spi.types.domain.edr.EndpointDataReference dataReference = endpointDataReferenceStorage.remove(response.getContractAgreementId()).get(); + + + + try { + Request notificationRequest = buildNotificationRequestNew(notification, senderEdcUrl, dataReference); + httpCallService.sendRequest(notificationRequest); + } catch (IOException e) { + throw new RuntimeException(e); + } + } public void startEDCTransfer(QualityNotificationMessage notification, String receiverEdcUrl, String senderEdcUrl) { @@ -179,6 +196,7 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec log.error("failed NEW exception", e); } log.info("END OF NEW"); + notification.setDescription("after client sent one already"); Map header = new HashMap<>(); header.put("x-api-key", edcProperties.getApiAuthKey()); try { @@ -319,6 +337,20 @@ private Request buildNotificationRequest(QualityNotificationMessage notification .build(); } + private Request buildNotificationRequestNew(QualityNotificationMessage notification, String senderEdcUrl,org.eclipse.edc.spi.types.domain.edr.EndpointDataReference dataReference) throws JsonProcessingException { + EDCNotification edcNotification = EDCNotificationFactory.createEdcNotification(senderEdcUrl, notification); + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + String body = objectMapper.writeValueAsString(edcNotification); + HttpUrl url = httpCallService.getUrl(dataReference.getEndpoint(), null, null); + log.info(":::: Send notification Data body :{}, dataReferenceEndpoint :{}", body, dataReference.getEndpoint()); + return new Request.Builder() + .url(url) + .addHeader(dataReference.getAuthKey(), dataReference.getAuthCode()) + .addHeader("Content-Type", JSON.type()) + .post(RequestBody.create(body, JSON)) + .build(); + } + private EndpointDataReference getDataReference(String agreementId) throws InterruptedException { EndpointDataReference dataReference = null; var waitTimeout = 20; From 350da2b00cea216631ff693fd711ad9d86dc9984 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Tue, 29 Aug 2023 14:27:45 +0200 Subject: [PATCH 37/63] feature: TRACEFOSS-2391 test --- .../domain/service/EdcNotificationService.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationService.java index bf4eb41fe1..2a7c513952 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationService.java @@ -69,9 +69,9 @@ public void asyncNotificationExecutor(QualityNotificationMessage notification) { } private void handleSendingAlert(QualityNotificationMessage notification, String senderEdcUrl, String receiverUrl) { - try{ - edcFacade.startEDCTransfer(notification, receiverUrl, senderEdcUrl); - alertRepository.updateQualityNotificationMessageEntity(notification); + try { + edcFacade.startEdcTransferNew(notification, receiverUrl, senderEdcUrl); + alertRepository.updateQualityNotificationMessageEntity(notification); } catch (NoCatalogItemException e) { log.warn("Could not send alert to {} no catalog item found.", receiverUrl); } catch (BadRequestException e) { @@ -80,8 +80,8 @@ private void handleSendingAlert(QualityNotificationMessage notification, String } private void handleSendingInvestigation(QualityNotificationMessage notification, String senderEdcUrl, String receiverUrl) { - try{ - edcFacade.startEDCTransfer(notification, receiverUrl, senderEdcUrl); + try { + edcFacade.startEdcTransferNew(notification, receiverUrl, senderEdcUrl); investigationRepository.updateQualityNotificationMessageEntity(notification); } catch (NoCatalogItemException e) { log.warn("Could not send investigation to {} no catalog item found.", receiverUrl); From 7ee37af4dde01c3f4095101be0cedda58664c159 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Tue, 29 Aug 2023 20:33:15 +0200 Subject: [PATCH 38/63] feature: TRACEFOSS-2391 cleanup --- .../ContractNegotiationException.java | 30 +++++ .../edc/blackbox/InvestigationsEDCFacade.java | 105 ++++++------------ .../edc/blackbox/NoCatalogItemException.java | 9 +- .../NoEndpointDataReferenceException.java | 26 +++++ .../blackbox/SendNotificationException.java | 26 +++++ .../service/EdcNotificationService.java | 20 +++- 6 files changed, 139 insertions(+), 77 deletions(-) create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/ContractNegotiationException.java create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NoEndpointDataReferenceException.java create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/SendNotificationException.java diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/ContractNegotiationException.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/ContractNegotiationException.java new file mode 100644 index 0000000000..b2f8a5cc24 --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/ContractNegotiationException.java @@ -0,0 +1,30 @@ +/******************************************************************************** + * Copyright (c) 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.traceability.infrastructure.edc.blackbox; + +public class ContractNegotiationException extends RuntimeException { + public ContractNegotiationException(final String message, final Throwable exception) { + super(message, exception); + } + + public ContractNegotiationException(final String message) { + super(message); + } +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index 042f4db136..086ef2eff1 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -45,10 +45,6 @@ import org.eclipse.tractusx.irs.edc.client.EDCCatalogFacade; import org.eclipse.tractusx.irs.edc.client.EdcConfiguration; import org.eclipse.tractusx.irs.edc.client.EndpointDataReferenceStorage; -import org.eclipse.tractusx.irs.edc.client.exceptions.ContractNegotiationException; -import org.eclipse.tractusx.irs.edc.client.exceptions.TransferProcessException; -import org.eclipse.tractusx.irs.edc.client.exceptions.UsagePolicyException; -import org.eclipse.tractusx.irs.edc.client.model.NegotiationResponse; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.cache.EndpointDataReference; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.cache.InMemoryEndpointDataReferenceCache; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.catalog.CatalogItem; @@ -102,7 +98,6 @@ public class InvestigationsEDCFacade { private final EDCCatalogFacade edcCatalogFacade; private final ContractNegotiationService contractNegotiationService; - private final EdcConfiguration edcConfiguration; private final EndpointDataReferenceStorage endpointDataReferenceStorage; public static final String ASSET_VALUE_QUALITY_INVESTIGATION = "qualityinvestigation"; @@ -111,15 +106,39 @@ public class InvestigationsEDCFacade { private static final String ASSET_VALUE_NOTIFICATION_METHOD_RECEIVE = "receive"; public void startEdcTransferNew(QualityNotificationMessage notification, String receiverEdcUrl, String senderEdcUrl) { + org.eclipse.tractusx.irs.edc.client.model.CatalogItem catalogItem = getCatalogItem(notification, receiverEdcUrl); + + String contractAgreementId = negotiateContractAgreement(receiverEdcUrl, catalogItem); + + final org.eclipse.edc.spi.types.domain.edr.EndpointDataReference dataReference = endpointDataReferenceStorage.remove(contractAgreementId) + .orElseThrow(() -> new NoEndpointDataReferenceException("No EndpointDataReference was found")); + + notification.setContractAgreementId(contractAgreementId); notification.setEdcUrl(receiverEdcUrl); - notification.setDescription(notification.getDescription() + " withIrsClientLib"); + try { + Request notificationRequest = buildNotificationRequestNew(notification, senderEdcUrl, dataReference); + httpCallService.sendRequest(notificationRequest); + } catch (Exception e) { + throw new SendNotificationException("Failed to send notification.", e); + } + } + + private String negotiateContractAgreement(String receiverEdcUrl, org.eclipse.tractusx.irs.edc.client.model.CatalogItem catalogItem) { + try { + return Optional.ofNullable(contractNegotiationService.negotiate(receiverEdcUrl + edcProperties.getIdsPath(), catalogItem)) + .orElseThrow(() -> new ContractNegotiationException("Failed to negotiate contract agreement. Negotiation response is null")) + .getContractAgreementId(); + } catch (Exception e) { + throw new ContractNegotiationException("Failed to negotiate contract agreement. ", e); + } + } - List catalogItems = null; + private org.eclipse.tractusx.irs.edc.client.model.CatalogItem getCatalogItem(QualityNotificationMessage notification, String receiverEdcUrl) { try { final String propertyNotificationTypeValue = QualityNotificationType.ALERT.equals(notification.getType()) ? ASSET_VALUE_QUALITY_ALERT : ASSET_VALUE_QUALITY_INVESTIGATION; - final String propertyMethodValue = notification.getIsInitial() ? ASSET_VALUE_NOTIFICATION_METHOD_RECEIVE : ASSET_VALUE_NOTIFICATION_METHOD_UPDATE; - catalogItems = edcCatalogFacade.fetchCatalogItems( + final String propertyMethodValue = Boolean.TRUE.equals(notification.getIsInitial()) ? ASSET_VALUE_NOTIFICATION_METHOD_RECEIVE : ASSET_VALUE_NOTIFICATION_METHOD_UPDATE; + return edcCatalogFacade.fetchCatalogItems( CatalogRequest.Builder.newInstance() .protocol(DEFAULT_PROTOCOL) .providerUrl(receiverEdcUrl + edcProperties.getIdsPath()) @@ -132,71 +151,15 @@ public void startEdcTransferNew(QualityNotificationMessage notification, String .build() ).stream() .filter(this::hasTracePolicy) - .toList(); + .findFirst() + .orElseThrow(() -> new NoCatalogItemException()); } catch (Exception e) { - log.error(" CATALOG REQUEST LIB", e); - } - - try { - log.info("CATALOG ITEMS: {}", objectMapper.writeValueAsString(catalogItems)); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - - Optional catalogItem = catalogItems.stream().findFirst(); - - - log.info("starting negotiation with edcConfig callbackURL {}", - edcConfiguration.getCallbackUrl()); - log.info("starting negotiation with receiverURL {}", - receiverEdcUrl); - try { - log.info("starting negotiation with catalogItem {}", - objectMapper.writeValueAsString(catalogItem.get())); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - NegotiationResponse response = null; - try { - log.info("calling initializeContractNegotiationLib with receiverConnectorURL {}", receiverEdcUrl+ edcProperties.getIdsPath()); - log.info("calling initializeContractNegotiationLib with catalogItem {}", objectMapper.writeValueAsString(catalogItem.get())); - response = contractNegotiationService.negotiate(receiverEdcUrl+ edcProperties.getIdsPath(), catalogItem.get()); - } catch (TransferProcessException e) { - log.error("contractNegotiationService.negotiate TransferProcessException {}", e); - } catch (UsagePolicyException e) { - log.error("contractNegotiationService.negotiate UsagePolicyException {}", e); - } catch (ContractNegotiationException e) { - log.error("contractNegotiationService.negotiate ContractNegotiationException {}", e); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - log.info("LIB contractNegotiation {}", response); - - if (StringUtils.hasLength(response.getContractAgreementId())) { - notification.setContractAgreementId(response.getContractAgreementId()); - } - - final org.eclipse.edc.spi.types.domain.edr.EndpointDataReference dataReference = endpointDataReferenceStorage.remove(response.getContractAgreementId()).get(); - - - - try { - Request notificationRequest = buildNotificationRequestNew(notification, senderEdcUrl, dataReference); - httpCallService.sendRequest(notificationRequest); - } catch (IOException e) { - throw new RuntimeException(e); + log.error("Exception was thrown while requesting catalog items from Lib", e); + throw new NoCatalogItemException(e); } - } public void startEDCTransfer(QualityNotificationMessage notification, String receiverEdcUrl, String senderEdcUrl) { - try { - startEdcTransferNew(notification, receiverEdcUrl, senderEdcUrl); - } catch (Exception e) { - log.error("failed NEW exception", e); - } - log.info("END OF NEW"); - notification.setDescription("after client sent one already"); Map header = new HashMap<>(); header.put("x-api-key", edcProperties.getApiAuthKey()); try { @@ -247,7 +210,7 @@ public void startEDCTransfer(QualityNotificationMessage notification, String rec Optional catalogItem = items.stream().findFirst(); if (catalogItem.isEmpty()) { log.info("No Catalog Item in catalog found"); - throw new NoCatalogItemException("No Catalog Item in catalog found."); + throw new NoCatalogItemException(); } // TODO @@ -337,7 +300,7 @@ private Request buildNotificationRequest(QualityNotificationMessage notification .build(); } - private Request buildNotificationRequestNew(QualityNotificationMessage notification, String senderEdcUrl,org.eclipse.edc.spi.types.domain.edr.EndpointDataReference dataReference) throws JsonProcessingException { + private Request buildNotificationRequestNew(QualityNotificationMessage notification, String senderEdcUrl, org.eclipse.edc.spi.types.domain.edr.EndpointDataReference dataReference) throws JsonProcessingException { EDCNotification edcNotification = EDCNotificationFactory.createEdcNotification(senderEdcUrl, notification); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); String body = objectMapper.writeValueAsString(edcNotification); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NoCatalogItemException.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NoCatalogItemException.java index 36c4236688..27c32133b0 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NoCatalogItemException.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NoCatalogItemException.java @@ -20,7 +20,12 @@ package org.eclipse.tractusx.traceability.infrastructure.edc.blackbox; public class NoCatalogItemException extends RuntimeException{ - public NoCatalogItemException(String message) { - super(message); + static final String MESSAGE = "No Catalog Item in catalog found."; + public NoCatalogItemException() { + super(MESSAGE); + } + + public NoCatalogItemException(final Throwable exception) { + super(MESSAGE, exception); } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NoEndpointDataReferenceException.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NoEndpointDataReferenceException.java new file mode 100644 index 0000000000..9f712e9213 --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NoEndpointDataReferenceException.java @@ -0,0 +1,26 @@ +/******************************************************************************** + * Copyright (c) 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.traceability.infrastructure.edc.blackbox; + +public class NoEndpointDataReferenceException extends RuntimeException { + public NoEndpointDataReferenceException(String message) { + super(message); + } +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/SendNotificationException.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/SendNotificationException.java new file mode 100644 index 0000000000..d8ef285389 --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/SendNotificationException.java @@ -0,0 +1,26 @@ +/******************************************************************************** + * Copyright (c) 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.traceability.infrastructure.edc.blackbox; + +public class SendNotificationException extends RuntimeException { + public SendNotificationException(final String message, final Throwable exception) { + super(message, exception); + } +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationService.java index 2a7c513952..ff9505f22c 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationService.java @@ -21,14 +21,18 @@ package org.eclipse.tractusx.traceability.qualitynotification.domain.service; +import com.fasterxml.jackson.core.JsonProcessingException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.traceability.common.config.AssetsAsyncConfig; import org.eclipse.tractusx.traceability.discovery.domain.model.Discovery; import org.eclipse.tractusx.traceability.discovery.domain.service.DiscoveryService; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.BadRequestException; +import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.ContractNegotiationException; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.InvestigationsEDCFacade; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.NoCatalogItemException; +import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.NoEndpointDataReferenceException; +import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.SendNotificationException; import org.eclipse.tractusx.traceability.qualitynotification.domain.alert.repository.AlertRepository; import org.eclipse.tractusx.traceability.qualitynotification.domain.investigation.repository.InvestigationRepository; import org.eclipse.tractusx.traceability.qualitynotification.domain.model.QualityNotificationMessage; @@ -73,9 +77,13 @@ private void handleSendingAlert(QualityNotificationMessage notification, String edcFacade.startEdcTransferNew(notification, receiverUrl, senderEdcUrl); alertRepository.updateQualityNotificationMessageEntity(notification); } catch (NoCatalogItemException e) { - log.warn("Could not send alert to {} no catalog item found.", receiverUrl); - } catch (BadRequestException e) { + log.warn("Could not send alert to {} no catalog item found. ", receiverUrl, e); + } catch (SendNotificationException e) { log.warn("Could not send alert to {} ", receiverUrl, e); + } catch (NoEndpointDataReferenceException e) { + log.warn("Could not send alert to {} no endpoint data reference found", receiverUrl, e); + } catch (ContractNegotiationException e) { + log.warn("Could not send alert to {} could not negotiate contract agreement", receiverUrl, e); } } @@ -84,9 +92,13 @@ private void handleSendingInvestigation(QualityNotificationMessage notification, edcFacade.startEdcTransferNew(notification, receiverUrl, senderEdcUrl); investigationRepository.updateQualityNotificationMessageEntity(notification); } catch (NoCatalogItemException e) { - log.warn("Could not send investigation to {} no catalog item found.", receiverUrl); - } catch (BadRequestException e) { + log.warn("Could not send investigation to {} no catalog item found.", receiverUrl, e); + } catch (SendNotificationException e) { log.warn("Could not send investigation to {} ", receiverUrl, e); + } catch (NoEndpointDataReferenceException e) { + log.warn("Could not send investigation to {} no endpoint data reference found", receiverUrl, e); + } catch (ContractNegotiationException e) { + log.warn("Could not send investigation to {} could not negotiate contract agreement", receiverUrl, e); } } } From 8de301cfcff35965c5ab3f092e11f14515401332 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Tue, 29 Aug 2023 22:52:26 +0200 Subject: [PATCH 39/63] feature: TRACEFOSS-2391 cleanup --- .../blackbox/EdcCallbackControllerTraceX.java | 103 ------ .../edc/blackbox/EdcService.java | 206 ----------- .../edc/blackbox/InvestigationsEDCFacade.java | 253 ++----------- .../blackbox/cache/EndpointDataReference.java | 136 ------- .../InMemoryEndpointDataReferenceCache.java | 70 ---- .../edc/blackbox/EdcServiceTest.java | 190 ---------- .../blackbox/InvestigationsEDCFacadeTest.java | 348 +++++++++--------- 7 files changed, 192 insertions(+), 1114 deletions(-) delete mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcCallbackControllerTraceX.java delete mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcService.java delete mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/cache/EndpointDataReference.java delete mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/cache/InMemoryEndpointDataReferenceCache.java delete mode 100644 tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcServiceTest.java diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcCallbackControllerTraceX.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcCallbackControllerTraceX.java deleted file mode 100644 index 0d8a5436c7..0000000000 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcCallbackControllerTraceX.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * Copyright (c) 2022, 2023 ZF Friedrichshafen AG - * Copyright (c) 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.traceability.infrastructure.edc.blackbox; - -import io.swagger.v3.oas.annotations.Hidden; -import lombok.extern.slf4j.Slf4j; -import org.eclipse.tractusx.irs.data.StringMapper; -import org.eclipse.tractusx.traceability.common.config.FeatureFlags; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.cache.EndpointDataReference; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.cache.InMemoryEndpointDataReferenceCache; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.configuration.JsonLdConfigurationTraceX; -import org.eclipse.tractusx.traceability.infrastructure.edc.notificationcontract.service.contract.model.EDRAuthCode; -import org.eclipse.tractusx.traceability.infrastructure.edc.properties.EdcProperties; -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.context.annotation.Profile; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.RestTemplate; - -import java.nio.charset.StandardCharsets; -import java.util.Base64; - -@Slf4j -@Profile(FeatureFlags.NOTIFICATIONS_ENABLED_PROFILES) -@RestController -@Hidden -@RequestMapping("/callback/endpoint-data-reference") -public class EdcCallbackControllerTraceX { - - private final InMemoryEndpointDataReferenceCache endpointDataReferenceCache; - - private final RestTemplate restTemplate; - - private final EdcProperties edcProperties; - - public EdcCallbackControllerTraceX(InMemoryEndpointDataReferenceCache endpointDataReferenceCache, RestTemplateBuilder restTemplateBuilder, EdcProperties edcProperties) { - this.endpointDataReferenceCache = endpointDataReferenceCache; - this.restTemplate = restTemplateBuilder.build(); - this.edcProperties = edcProperties; - } - - @PostMapping - public void receiveEdcCallback(@RequestBody EndpointDataReference dataReference) { - final String authCode = dataReference.getAuthCode(); - final var contractAgreementId = extractContractAgreementId(authCode); - log.info("Received EDC callback for contract: {}", contractAgreementId); - - if (endpointDataReferenceCache.containsAgreementId(contractAgreementId)) { - log.info("Contract {} found! Processing...", contractAgreementId); - endpointDataReferenceCache.put(contractAgreementId, dataReference); - } - // todo remove else block - else { - log.info("Contract {} not found, forwarding message...", contractAgreementId); - callOtherServices(dataReference); - } - } - - // TODO remove this - private void callOtherServices(EndpointDataReference dataReference) { - edcProperties.getCallbackUrls().forEach(callbackUrl -> { - log.info("Calling callback endpoint: {}", callbackUrl); - ResponseEntity response = restTemplate.postForEntity(callbackUrl, dataReference, String.class); - - log.info("Callback response: HTTP {}", response.getStatusCode()); - log.debug("Body: {}", response.getBody()); - }); - } - private String extractContractAgreementId(final String token) { - if (token != null) { - final var chunks = token.split("\\."); - final var decoder = Base64.getUrlDecoder(); - final var payload = new String(decoder.decode(chunks[1]), StandardCharsets.UTF_8); - final var authCode = StringMapper.mapFromString(payload, EDRAuthCode.class); - return authCode.getCid(); - } else { - log.warn("Authentication missing on edc edr callback request."); - return null; - } - - } -} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcService.java deleted file mode 100644 index 01d33d990f..0000000000 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcService.java +++ /dev/null @@ -1,206 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * Copyright (c) 2022, 2023 ZF Friedrichshafen AG - * Copyright (c) 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.traceability.infrastructure.edc.blackbox; - -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import okhttp3.MediaType; -import okhttp3.Request; -import okhttp3.RequestBody; - -import org.eclipse.edc.catalog.spi.Catalog; -import org.eclipse.tractusx.irs.edc.client.model.ContractOfferRequest; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.catalog.CatalogItem; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.jsontransformer.EdcTransformerTraceX; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.negotiation.ContractOfferDescription; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.negotiation.NegotiationRequest; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.negotiation.NegotiationResponse; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.negotiation.Response; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.transferprocess.TransferProcessRequest; -import org.eclipse.tractusx.traceability.infrastructure.edc.properties.EdcProperties; -import org.springframework.stereotype.Component; - -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; - -import static org.eclipse.tractusx.irs.edc.client.ContractNegotiationService.EDC_PROTOCOL; -import static org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.transferprocess.TransferProcessRequest.DEFAULT_PROTOCOL; - -@Slf4j -@Component -@RequiredArgsConstructor -public class EdcService { - - public static final MediaType JSON = MediaType.get("application/json"); - private static final String FINALIZED_STATUS = "FINALIZED"; - - private final HttpCallService httpCallService; - private final EdcProperties edcProperties; - private final EdcTransformerTraceX edcTransformer; - private final ObjectMapper objectMapper; - - // TODO: Remove - /** - * Rest call to get all contract offer and filter notification type contract - */ - public Catalog getCatalog( - String consumerEdcDataManagementUrl, - String providerConnectorControlPlaneIDSUrl, - Map header - ) throws IOException { - - Catalog catalog = httpCallService.getCatalogForNotification(consumerEdcDataManagementUrl, providerConnectorControlPlaneIDSUrl, header); - - if (catalog.getDatasets() == null || catalog.getDatasets().isEmpty()) { - log.error("No contract found"); - throw new BadRequestException("Provider has no contract offers for us. Catalog is empty."); - } - return catalog; - } - - - /** - * Prepare for contract negotiation. it will wait for while till API return agreementId - */ - public String initializeContractNegotiation(String providerConnectorUrl, CatalogItem catalogItem, String consumerEdcUrl, - Map header) throws InterruptedException, IOException { - - final NegotiationRequest negotiationRequest = createNegotiationRequestFromCatalogItem(providerConnectorUrl + edcProperties.getIdsPath(), - catalogItem); - - - -// // TODO: remove after tests -// final var contractOfferDescription = org.eclipse.tractusx.irs.edc.client.model.ContractOfferDescription.builder() -// .offerId(catalogItem.getOfferId()) -// .assetId(catalogItem.getPolicy().getTarget()) -// .policy(catalogItem.getPolicy()) -// .build(); -// -// final org.eclipse.tractusx.irs.edc.client.model.NegotiationRequest test = org.eclipse.tractusx.irs.edc.client.model.NegotiationRequest.builder() -// .connectorId(catalogItem.getConnectorId()) -// .connectorAddress(providerConnectorUrl) -// .protocol(EDC_PROTOCOL) -// .offer(contractOfferDescription) -// .build(); -// log.info("---- negotiation request by own implementation", objectMapper.writeValueAsString(negotiationRequest)); -// log.info("---- negotiation request by library", objectMapper.writeValueAsString(test)); -// -// // TODO:---------- - log.info(":::: Start Contract Negotiation method[initializeContractNegotiation] offerId :{}, assetId:{}", negotiationRequest.getOffer().getOfferId(), negotiationRequest.getOffer().getAssetId()); - - String negotiationId = initiateNegotiation(negotiationRequest, consumerEdcUrl, header); - NegotiationResponse negotiation = null; - - // Check negotiation state - while (negotiation == null || negotiation.getState() == null || !negotiation.getState().equals(FINALIZED_STATUS)) { - - log.info(":::: waiting for contract to get confirmed"); - if (negotiation != null) { - log.info("Negotation state {}", negotiation.getState()); - } - - ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); - ScheduledFuture scheduledFuture = - scheduler.schedule(() -> { - var url = consumerEdcUrl + edcProperties.getNegotiationPath() + "/" + negotiationId; - var request = new Request.Builder().url(url); - header.forEach(request::addHeader); - - log.info(":::: Start call for contract agreement method [initializeContractNegotiation] URL :{}", url); - - return httpCallService.sendNegotiationRequest(request.build()); - }, 1000, TimeUnit.MILLISECONDS); - try { - negotiation = scheduledFuture.get(); - scheduler.shutdown(); - } catch (ExecutionException e) { - throw new RuntimeException(e); - } finally { - if (!scheduler.isShutdown()) { - scheduler.shutdown(); - } - } - } - return negotiation.getContractAgreementId(); - } - - - private NegotiationRequest createNegotiationRequestFromCatalogItem(final String providerConnectorUrl, - final CatalogItem catalogItem) { - final var contractOfferDescription = ContractOfferDescription.builder() - .offerId(catalogItem.getOfferId()) - .assetId(catalogItem.getPolicy().getTarget()) - .policy(catalogItem.getPolicy()) - .build(); - return NegotiationRequest.builder() - .connectorId(catalogItem.getConnectorId()) - .connectorAddress(providerConnectorUrl) - .protocol(DEFAULT_PROTOCOL) - .offer(contractOfferDescription) - .build(); - } - - /** - * Rest call for Contract negotiation and return agreementId. - */ - private String initiateNegotiation(NegotiationRequest negotiationRequest, String consumerEdcDataManagementUrl, - Map headers) throws IOException { - var url = consumerEdcDataManagementUrl + edcProperties.getNegotiationPath(); - - final String jsonObject = edcTransformer.transformNegotiationRequestToJson(negotiationRequest).toString(); - var requestBody = RequestBody.create(jsonObject, JSON); - var request = new Request.Builder().url(url).post(requestBody); - - headers.forEach(request::addHeader); - Response negotiationIdResponse = (Response) httpCallService.sendRequest(request.build(), Response.class); - log.info(":::: Method [initiateNegotiation] Negotiation Id :{}", negotiationIdResponse.getResponseId()); - return negotiationIdResponse.getResponseId(); - } - - - /** - * Rest call for Transfer Data with HttpProxy - */ - public void initiateHttpProxyTransferProcess(String consumerEdcDataManagementUrl, - String providerConnectorControlPlaneIDSUrl, - TransferProcessRequest transferProcessRequest, - Map headers) throws IOException { - var url = consumerEdcDataManagementUrl + edcProperties.getTransferPath(); - - - final String jsonObject = edcTransformer.transformTransferProcessRequestToJson(transferProcessRequest).toString(); - - var requestBody = RequestBody.create(jsonObject, JSON); - var request = new Request.Builder().url(url).post(requestBody); - - headers.forEach(request::addHeader); - log.info(":::: call Transfer process with http Proxy method[initiateHttpProxyTransferProcess] agreementId:{} ,assetId :{},consumerEdcDataManagementUrl :{}, providerConnectorControlPlaneIDSUrl:{}", transferProcessRequest.getContractId(), transferProcessRequest.getAssetId(), consumerEdcDataManagementUrl, providerConnectorControlPlaneIDSUrl); - httpCallService.sendRequest(request.build(), Response.class); - } - -} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index 086ef2eff1..a4c3fae070 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -29,9 +29,7 @@ import okhttp3.MediaType; import okhttp3.Request; import okhttp3.RequestBody; -import org.eclipse.edc.catalog.spi.Catalog; import org.eclipse.edc.catalog.spi.CatalogRequest; -import org.eclipse.edc.catalog.spi.Dataset; import org.eclipse.edc.policy.model.AtomicConstraint; import org.eclipse.edc.policy.model.Constraint; import org.eclipse.edc.policy.model.Operator; @@ -40,41 +38,27 @@ import org.eclipse.edc.policy.model.Policy; import org.eclipse.edc.spi.query.Criterion; import org.eclipse.edc.spi.query.QuerySpec; -import org.eclipse.edc.spi.types.domain.DataAddress; +import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference; import org.eclipse.tractusx.irs.edc.client.ContractNegotiationService; import org.eclipse.tractusx.irs.edc.client.EDCCatalogFacade; -import org.eclipse.tractusx.irs.edc.client.EdcConfiguration; import org.eclipse.tractusx.irs.edc.client.EndpointDataReferenceStorage; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.cache.EndpointDataReference; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.cache.InMemoryEndpointDataReferenceCache; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.catalog.CatalogItem; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.configuration.JsonLdConfigurationTraceX; +import org.eclipse.tractusx.irs.edc.client.model.CatalogItem; +import org.eclipse.tractusx.irs.edc.client.policy.PolicyCheckerService; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.model.EDCNotification; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.model.EDCNotificationFactory; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.policy.PolicyDefinition; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.transferprocess.TransferProcessDataDestination; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.transferprocess.TransferProcessRequest; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.validators.AtomicConstraintValidator; import org.eclipse.tractusx.traceability.infrastructure.edc.properties.EdcProperties; import org.eclipse.tractusx.traceability.qualitynotification.domain.model.QualityNotificationMessage; import org.eclipse.tractusx.traceability.qualitynotification.domain.model.QualityNotificationType; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; -import org.springframework.util.StringUtils; -import java.io.IOException; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Optional; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; +import static org.eclipse.edc.spi.query.Criterion.CRITERION_OPERAND_LEFT; import static org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.configuration.JsonLdConfigurationTraceX.NAMESPACE_EDC; -import static org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.configuration.JsonLdConfigurationTraceX.NAMESPACE_EDC_ID; import static org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.transferprocess.TransferProcessRequest.DEFAULT_PROTOCOL; @Slf4j @@ -84,14 +68,10 @@ public class InvestigationsEDCFacade { private static final MediaType JSON = MediaType.get("application/json"); - private final EdcService edcService; - private final HttpCallService httpCallService; private final ObjectMapper objectMapper; - private final InMemoryEndpointDataReferenceCache endpointDataReferenceCache; - private final EdcProperties edcProperties; @Qualifier("testedc") @@ -99,18 +79,22 @@ public class InvestigationsEDCFacade { private final ContractNegotiationService contractNegotiationService; private final EndpointDataReferenceStorage endpointDataReferenceStorage; + private final PolicyCheckerService policyCheckerService; public static final String ASSET_VALUE_QUALITY_INVESTIGATION = "qualityinvestigation"; public static final String ASSET_VALUE_QUALITY_ALERT = "qualityalert"; private static final String ASSET_VALUE_NOTIFICATION_METHOD_UPDATE = "update"; private static final String ASSET_VALUE_NOTIFICATION_METHOD_RECEIVE = "receive"; - public void startEdcTransferNew(QualityNotificationMessage notification, String receiverEdcUrl, String senderEdcUrl) { - org.eclipse.tractusx.irs.edc.client.model.CatalogItem catalogItem = getCatalogItem(notification, receiverEdcUrl); + public void startEdcTransferNew( + final QualityNotificationMessage notification, + final String receiverEdcUrl, + final String senderEdcUrl) { + CatalogItem catalogItem = getCatalogItem(notification, receiverEdcUrl); String contractAgreementId = negotiateContractAgreement(receiverEdcUrl, catalogItem); - final org.eclipse.edc.spi.types.domain.edr.EndpointDataReference dataReference = endpointDataReferenceStorage.remove(contractAgreementId) + final EndpointDataReference dataReference = endpointDataReferenceStorage.remove(contractAgreementId) .orElseThrow(() -> new NoEndpointDataReferenceException("No EndpointDataReference was found")); notification.setContractAgreementId(contractAgreementId); @@ -124,7 +108,7 @@ public void startEdcTransferNew(QualityNotificationMessage notification, String } } - private String negotiateContractAgreement(String receiverEdcUrl, org.eclipse.tractusx.irs.edc.client.model.CatalogItem catalogItem) { + private String negotiateContractAgreement(final String receiverEdcUrl, final CatalogItem catalogItem) { try { return Optional.ofNullable(contractNegotiationService.negotiate(receiverEdcUrl + edcProperties.getIdsPath(), catalogItem)) .orElseThrow(() -> new ContractNegotiationException("Failed to negotiate contract agreement. Negotiation response is null")) @@ -134,7 +118,7 @@ private String negotiateContractAgreement(String receiverEdcUrl, org.eclipse.tra } } - private org.eclipse.tractusx.irs.edc.client.model.CatalogItem getCatalogItem(QualityNotificationMessage notification, String receiverEdcUrl) { + private CatalogItem getCatalogItem(final QualityNotificationMessage notification, final String receiverEdcUrl) { try { final String propertyNotificationTypeValue = QualityNotificationType.ALERT.equals(notification.getType()) ? ASSET_VALUE_QUALITY_ALERT : ASSET_VALUE_QUALITY_INVESTIGATION; final String propertyMethodValue = Boolean.TRUE.equals(notification.getIsInitial()) ? ASSET_VALUE_NOTIFICATION_METHOD_RECEIVE : ASSET_VALUE_NOTIFICATION_METHOD_UPDATE; @@ -150,157 +134,20 @@ private org.eclipse.tractusx.irs.edc.client.model.CatalogItem getCatalogItem(Qua .build()) .build() ).stream() - .filter(this::hasTracePolicy) + .filter(catalogItem -> policyCheckerService.isValid(catalogItem.getPolicy())) .findFirst() - .orElseThrow(() -> new NoCatalogItemException()); + .orElseThrow(NoCatalogItemException::new); } catch (Exception e) { log.error("Exception was thrown while requesting catalog items from Lib", e); throw new NoCatalogItemException(e); } } - public void startEDCTransfer(QualityNotificationMessage notification, String receiverEdcUrl, String senderEdcUrl) { - Map header = new HashMap<>(); - header.put("x-api-key", edcProperties.getApiAuthKey()); - try { - notification.setEdcUrl(receiverEdcUrl); - - log.info(":::: Find Notification contract method[startEDCTransfer] senderEdcUrl :{}, receiverEdcUrl:{}", senderEdcUrl, receiverEdcUrl); - - Catalog catalog = edcService.getCatalog( - senderEdcUrl, - receiverEdcUrl + edcProperties.getIdsPath(), - header - ); - log.info(" CATALOG FOR NOTIFICATION : {}", objectMapper.writeValueAsString(catalog)); - - log.info(" DATASET FOR NOTIFICATION : {}", objectMapper.writeValueAsString(catalog.getDatasets())); - if (catalog.getDatasets().isEmpty()) { - log.info("No Dataset in catalog found"); - throw new BadRequestException("The dataset from the catalog is empty."); - } - - Optional filteredDataset = catalog.getDatasets().stream() - .filter(dataset -> isQualityNotificationOffer(notification, dataset)) - .findFirst() - .filter(this::hasTracePolicy); - - - log.info(":::: Initialize Contract Negotiation method[startEDCTransfer] senderEdcUrl :{}, receiverEdcUrl:{}", senderEdcUrl, receiverEdcUrl); - final List items = filteredDataset.stream().map(dataSet -> { - final Map.Entry offer = dataSet.getOffers() - .entrySet() - .stream() - .findFirst() - .orElseThrow(); - final var catalogItem = CatalogItem.builder() - .itemId(dataSet.getId()) - .assetPropId(dataSet.getProperty(NAMESPACE_EDC_ID).toString()) - .connectorId(catalog.getId()) - .offerId(offer.getKey()) - .policy(offer.getValue()); - if (catalog.getProperties().containsKey(JsonLdConfigurationTraceX.NAMESPACE_EDC_PARTICIPANT_ID)) { - catalogItem.connectorId( - catalog.getProperties().get(JsonLdConfigurationTraceX.NAMESPACE_EDC_PARTICIPANT_ID).toString()); - } - - return catalogItem.build(); - }).toList(); - - Optional catalogItem = items.stream().findFirst(); - if (catalogItem.isEmpty()) { - log.info("No Catalog Item in catalog found"); - throw new NoCatalogItemException(); - } - -// TODO - //NegotiationResponse negotiationResponse = contractNegotiationService.negotiate(null, null); - - // String contractAgreementId = negotiationResponse.getContractAgreementId(); - - - final String edcContractAgreementId = edcService.initializeContractNegotiation(receiverEdcUrl, items.stream().findFirst().get(), senderEdcUrl, header); - - log.info(":::: Contract Agreed method[startEDCTransfer] agreementId :{}", edcContractAgreementId); - - // TODO remove this because we do not store agreement Id we extract it from a token in EdcCallbackControllerTraceX.java - endpointDataReferenceCache.storeAgreementId(edcContractAgreementId); - - if (StringUtils.hasLength(edcContractAgreementId)) { - notification.setContractAgreementId(edcContractAgreementId); - } - - EndpointDataReference dataReference = endpointDataReferenceCache.get(edcContractAgreementId); - boolean validDataReference = dataReference != null && InMemoryEndpointDataReferenceCache.endpointDataRefTokenExpired(dataReference); - if (!validDataReference) { - log.info(":::: Invalid Data Reference :::::"); - if (dataReference != null) { - endpointDataReferenceCache.remove(edcContractAgreementId); - } - - final TransferProcessRequest transferProcessRequest = createTransferProcessRequest( - receiverEdcUrl + edcProperties.getIdsPath(), - catalogItem.get(), - edcContractAgreementId); - - log.info(":::: initialize Transfer process with http Proxy :::::"); - // Initiate transfer process - edcService.initiateHttpProxyTransferProcess(senderEdcUrl, - receiverEdcUrl + edcProperties.getIdsPath(), - transferProcessRequest, - header - ); - dataReference = getDataReference(edcContractAgreementId); - } - - Request notificationRequest = buildNotificationRequest(notification, senderEdcUrl, dataReference); - - httpCallService.sendRequest(notificationRequest); - - log.info(":::: EDC Data Transfer Completed :::::"); - } catch (IOException e) { - throw new BadRequestException("EDC Data Transfer fail.", e); - } catch (InterruptedException e) { - log.error("Exception", e); - Thread.currentThread().interrupt(); - } - } - - private TransferProcessRequest createTransferProcessRequest(final String providerConnectorUrl, - final CatalogItem catalogItem, - final String negotiationId) { - final var destination = DataAddress.Builder.newInstance() - .type(TransferProcessDataDestination.DEFAULT_TYPE) - .build(); - final var transferProcessRequestBuilder = TransferProcessRequest.builder() - .protocol( - TransferProcessRequest.DEFAULT_PROTOCOL) - .managedResources( - TransferProcessRequest.DEFAULT_MANAGED_RESOURCES) - .connectorId(catalogItem.getConnectorId()) - .connectorAddress(providerConnectorUrl) - .contractId(negotiationId) - .assetId(catalogItem.getAssetPropId()) - .dataDestination(destination); - - return transferProcessRequestBuilder.build(); - } - - private Request buildNotificationRequest(QualityNotificationMessage notification, String senderEdcUrl, EndpointDataReference dataReference) throws JsonProcessingException { - EDCNotification edcNotification = EDCNotificationFactory.createEdcNotification(senderEdcUrl, notification); - objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - String body = objectMapper.writeValueAsString(edcNotification); - HttpUrl url = httpCallService.getUrl(dataReference.getEndpoint(), null, null); - log.info(":::: Send notification Data body :{}, dataReferenceEndpoint :{}", body, dataReference.getEndpoint()); - return new Request.Builder() - .url(url) - .addHeader(dataReference.getAuthKey(), dataReference.getAuthCode()) - .addHeader("Content-Type", JSON.type()) - .post(RequestBody.create(body, JSON)) - .build(); - } - - private Request buildNotificationRequestNew(QualityNotificationMessage notification, String senderEdcUrl, org.eclipse.edc.spi.types.domain.edr.EndpointDataReference dataReference) throws JsonProcessingException { + private Request buildNotificationRequestNew( + final QualityNotificationMessage notification, + final String senderEdcUrl, + final EndpointDataReference dataReference + ) throws JsonProcessingException { EDCNotification edcNotification = EDCNotificationFactory.createEdcNotification(senderEdcUrl, notification); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); String body = objectMapper.writeValueAsString(edcNotification); @@ -314,63 +161,7 @@ private Request buildNotificationRequestNew(QualityNotificationMessage notificat .build(); } - private EndpointDataReference getDataReference(String agreementId) throws InterruptedException { - EndpointDataReference dataReference = null; - var waitTimeout = 20; - while (dataReference == null && waitTimeout > 0) { - ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); - ScheduledFuture scheduledFuture = - scheduler.schedule(() -> endpointDataReferenceCache.get(agreementId), 30, TimeUnit.SECONDS); - try { - dataReference = scheduledFuture.get(); - waitTimeout--; - scheduler.shutdown(); - } catch (ExecutionException e) { - throw new RuntimeException(e); - } finally { - if (!scheduler.isShutdown()) { - scheduler.shutdown(); - } - } - } - if (dataReference == null) { - throw new BadRequestException("Did not receive callback within 30 seconds from consumer edc."); - } - return dataReference; - } - - @Deprecated - private boolean isQualityNotificationOffer(QualityNotificationMessage qualityNotificationMessage, Dataset dataset) { - Object notificationTypeObj = dataset.getProperty(NAMESPACE_EDC + "notificationtype"); - String notificationType = null; - if (notificationTypeObj != null) { - notificationType = notificationTypeObj.toString(); - } - Object notificationMethodObj = dataset.getProperty(NAMESPACE_EDC + "notificationmethod"); - String notificationMethod = null; - if (notificationMethodObj != null) { - notificationMethod = notificationMethodObj.toString(); - } - - final String propertyNotificationTypeValue = QualityNotificationType.ALERT.equals(qualityNotificationMessage.getType()) ? ASSET_VALUE_QUALITY_ALERT : ASSET_VALUE_QUALITY_INVESTIGATION; - final String propertyMethodValue = qualityNotificationMessage.getIsInitial() ? ASSET_VALUE_NOTIFICATION_METHOD_RECEIVE : ASSET_VALUE_NOTIFICATION_METHOD_UPDATE; - return propertyNotificationTypeValue.equals(notificationType) && propertyMethodValue.equals(notificationMethod); - } - - - private boolean hasTracePolicy(Dataset dataset) { - boolean foundPolicy = false; - for (Policy policy : dataset.getOffers().values()) { - log.info("Policy Check {} ", policy.toString()); - if (!foundPolicy) { - foundPolicy = isValid(policy); - } - } - log.info("Found policy: {} ", foundPolicy); - return foundPolicy; - } - - private boolean hasTracePolicy(org.eclipse.tractusx.irs.edc.client.model.CatalogItem catalogItem) { + private boolean hasTracePolicy(final CatalogItem catalogItem) { boolean foundPolicy = false; if (catalogItem.getPolicy() != null) { log.info("Policy Check {} ", catalogItem.getPolicy().toString()); @@ -380,7 +171,6 @@ private boolean hasTracePolicy(org.eclipse.tractusx.irs.edc.client.model.Catalog return foundPolicy; } - private List allowedPolicies() { final PolicyDefinition allowedTracePolicy = PolicyDefinition.builder() .constraintOperator("EQ") @@ -392,7 +182,6 @@ private List allowedPolicies() { return List.of(allowedTracePolicy); } - private boolean isValid(final Policy policy) { final List policyList = this.allowedPolicies(); return policy.getPermissions() diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/cache/EndpointDataReference.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/cache/EndpointDataReference.java deleted file mode 100644 index 35684899a0..0000000000 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/cache/EndpointDataReference.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * Copyright (c) 2022, 2023 ZF Friedrichshafen AG - * Copyright (c) 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.traceability.infrastructure.edc.blackbox.cache; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; -import lombok.ToString; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.UUID; - -/** - * Describes an endpoint serving data. - */ -@ToString -@JsonDeserialize(builder = EndpointDataReference.Builder.class) -@JsonIgnoreProperties(ignoreUnknown = true) -public class EndpointDataReference { - - private final String id; - private final String endpoint; - private final String authKey; - private final String authCode; - private final Map properties; - - private EndpointDataReference(String id, String endpoint, String authKey, String authCode, Map properties) { - this.id = id; - this.endpoint = endpoint; - this.authKey = authKey; - this.authCode = authCode; - this.properties = properties; - } - - @NotNull - public String getId() { - return id; - } - - @NotNull - public String getEndpoint() { - return endpoint; - } - - @Nullable - public String getAuthKey() { - return authKey; - } - - @Nullable - public String getAuthCode() { - return authCode; - } - - @NotNull - public Map getProperties() { - return properties; - } - - @JsonPOJOBuilder(withPrefix = "") - public static class Builder { - private final Map properties = new HashMap<>(); - private String id = UUID.randomUUID().toString(); - private String endpoint; - private String authKey; - private String authCode; - - private Builder() { - } - - @JsonCreator - public static Builder newInstance() { - return new Builder(); - } - - public Builder id(String id) { - this.id = id; - return this; - } - - public Builder endpoint(String address) { - this.endpoint = address; - return this; - } - - public Builder authKey(String authKey) { - this.authKey = authKey; - return this; - } - - public Builder authCode(String authCode) { - this.authCode = authCode; - return this; - } - - public Builder properties(Map properties) { - this.properties.putAll(properties); - return this; - } - - public EndpointDataReference build() { - Objects.requireNonNull(endpoint, "endpoint"); - if (authKey != null) { - Objects.requireNonNull(authCode, "authCode"); - } - if (authCode != null) { - Objects.requireNonNull(authKey, "authKey"); - } - return new EndpointDataReference(id, endpoint, authKey, authCode, properties); - } - } -} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/cache/InMemoryEndpointDataReferenceCache.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/cache/InMemoryEndpointDataReferenceCache.java deleted file mode 100644 index 46fa4689fb..0000000000 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/cache/InMemoryEndpointDataReferenceCache.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * Copyright (c) 2022, 2023 ZF Friedrichshafen AG - * Copyright (c) 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.traceability.infrastructure.edc.blackbox.cache; - -import com.auth0.jwt.JWT; -import com.auth0.jwt.interfaces.DecodedJWT; -import org.springframework.stereotype.Component; - -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -@Component -public class InMemoryEndpointDataReferenceCache { - - private final Map store = new HashMap<>(); - - private final Set awaitingAgreementIds = new HashSet<>(); - - public void storeAgreementId(String agreementId) { - awaitingAgreementIds.add(agreementId); - } - - public boolean containsAgreementId(String agreementId) { - return awaitingAgreementIds.contains(agreementId); - } - - public static boolean endpointDataRefTokenExpired(EndpointDataReference dataReference) { - String token = dataReference.getAuthCode(); - - if (token == null) { - return true; - } - - DecodedJWT jwt = JWT.decode(token); - return !jwt.getExpiresAt().before(new Date(System.currentTimeMillis() + 30 * 1000)); - } - - public void put(String agreementId, EndpointDataReference endpointDataReference) { - store.put(agreementId, endpointDataReference); - } - - public EndpointDataReference get(String agreementId) { - return store.get(agreementId); - } - - public void remove(String agreementId) { - store.remove(agreementId); - } -} diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcServiceTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcServiceTest.java deleted file mode 100644 index bba1051081..0000000000 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcServiceTest.java +++ /dev/null @@ -1,190 +0,0 @@ -/******************************************************************************** - * Copyright (c) 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.traceability.infrastructure.edc.blackbox; - -import jakarta.json.Json; -import jakarta.json.JsonObject; -import org.eclipse.edc.catalog.spi.Catalog; -import org.eclipse.edc.catalog.spi.Dataset; -import org.eclipse.edc.policy.model.Policy; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.catalog.CatalogItem; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.jsontransformer.EdcTransformerTraceX; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.negotiation.NegotiationResponse; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.negotiation.Response; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.transferprocess.TransferProcessRequest; -import org.eclipse.tractusx.traceability.infrastructure.edc.properties.EdcProperties; -import org.eclipse.tractusx.traceability.testdata.CatalogTestDataFactory; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.io.IOException; -import java.util.Collections; -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -@ExtendWith(MockitoExtension.class) -class EdcServiceTest { - - @Mock - private HttpCallService httpCallService; - - @InjectMocks - private EdcService edcService; - - @Mock - private EdcProperties edcProperties; - @Mock - private EdcTransformerTraceX edcTransformer; - - @Test - void test_getCatalog() throws IOException { - // Arrange - String consumerEdcDataManagementUrl = "https://example.com/consumer-edc"; - String providerConnectorControlPlaneIDSUrl = "https://example.com/provider-connector"; - Map header = Collections.singletonMap("Authorization", "Bearer token"); - - - Catalog catalog = CatalogTestDataFactory.createCatalogTestData(); - - when(httpCallService.getCatalogForNotification(consumerEdcDataManagementUrl, providerConnectorControlPlaneIDSUrl, header)) - .thenReturn(catalog); - - // Act - Catalog catalogResult = edcService.getCatalog(consumerEdcDataManagementUrl, providerConnectorControlPlaneIDSUrl, header); - - assertThat(catalogResult).isNotNull(); - // Assert - verify(httpCallService, times(1)) - .getCatalogForNotification(consumerEdcDataManagementUrl, providerConnectorControlPlaneIDSUrl, header); - - } - - @Test - void test_getCatalog_throw_BadRequestException_when_dataset_is_empty() throws IOException { - //GIVEN - String consumerEdcDataManagementUrl = "https://example.com/consumer-edc"; - String providerConnectorControlPlaneIDSUrl = "https://example.com/provider-connector"; - Map header = Collections.singletonMap("Authorization", "Bearer token"); - - Catalog emptyCatalog = Catalog.Builder.newInstance().datasets(Collections.emptyList()).build(); - when(httpCallService.getCatalogForNotification(consumerEdcDataManagementUrl, providerConnectorControlPlaneIDSUrl, header)) - .thenReturn(emptyCatalog); - - //WHEN - BadRequestException badRequestException = assertThrows( - BadRequestException.class, - () -> edcService.getCatalog(consumerEdcDataManagementUrl, providerConnectorControlPlaneIDSUrl, header) - ); - //THEN - verify(httpCallService).getCatalogForNotification(any(), any(), any()); - assertEquals("Provider has no contract offers for us. Catalog is empty.", badRequestException.getMessage()); - } - - @Test - void test_initializeContractNegotiation() throws IOException, InterruptedException { - //GIVEN - String providerConnectorUrl = "https://example.com/provider-connector"; - String consumerEdcUrl = "https://example.com/consumer-edc"; - Map header = Collections.singletonMap("Authorization", "Bearer token"); - - Policy policy = Policy.Builder.newInstance().target("policyTarget").build(); - org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.catalog.CatalogItem catalogItem = CatalogItem.builder().offerId("offerId").policy(policy).build(); - - JsonObject mockedJsonObject = Json.createObjectBuilder().add("", "").build(); - - when(edcTransformer.transformNegotiationRequestToJson(any())).thenReturn(mockedJsonObject); - - Response response = Response.builder().responseId("negotiationId").build(); - when(httpCallService.sendRequest(any(), eq(Response.class))).thenReturn(response); - - NegotiationResponse inProgressNegotiationResponse = NegotiationResponse.builder().contractAgreementId("ContractAgreementID").state("IN_PROGRESS").build(); - NegotiationResponse finalizedNegotiationResponse = NegotiationResponse.builder().contractAgreementId("ContractAgreementID").state("FINALIZED").build(); - when(httpCallService.sendNegotiationRequest(any())) - .thenReturn(inProgressNegotiationResponse) - .thenReturn(finalizedNegotiationResponse); - - //WHEN - String initializeContractNegotiation = edcService.initializeContractNegotiation(providerConnectorUrl, catalogItem, consumerEdcUrl, header); - - //THEN - assertEquals("ContractAgreementID", initializeContractNegotiation); - verify(edcTransformer).transformNegotiationRequestToJson(any()); - verify(httpCallService).sendRequest(any(), any()); - verify(httpCallService, times(2)).sendNegotiationRequest(any()); - } - - @Test - void test_initializeContractNegotiation_throw_ExecutionException() throws IOException { - //GIVEN - String providerConnectorUrl = "https://example.com/provider-connector"; - String consumerEdcUrl = "https://example.com/consumer-edc"; - Map header = Collections.singletonMap("Authorization", "Bearer token"); - - Policy policy = Policy.Builder.newInstance().target("policyTarget").build(); - CatalogItem catalogItem = CatalogItem.builder().offerId("offerId").policy(policy).build(); - - JsonObject mockedJsonObject = Json.createObjectBuilder().add("", "").build(); - - when(edcTransformer.transformNegotiationRequestToJson(any())).thenReturn(mockedJsonObject); - - Response response = Response.builder().responseId("negotiationId").build(); - when(httpCallService.sendRequest(any(), eq(Response.class))).thenReturn(response); - - when(httpCallService.sendNegotiationRequest(any())).thenThrow(new IOException()); - - //WHEN - RuntimeException runtimeException = assertThrows( - RuntimeException.class, - () -> edcService.initializeContractNegotiation(providerConnectorUrl, catalogItem, consumerEdcUrl, header)); - - //THEN - assertNotNull(runtimeException); - } - - @Test - void test_initiateHttpProxyTransferProcess() throws IOException { - //GIVEN - String providerConnectorControlPlaneIDSUrl = "https://example.com/provider-connector"; - String consumerEdcDataManagementUrl = "https://example.com/consumer-edc"; - Map header = Collections.singletonMap("Authorization", "Bearer token"); - TransferProcessRequest transferProcessRequest = TransferProcessRequest.builder().build(); - - JsonObject mockedJsonObject = Json.createObjectBuilder().add("", "").build(); - when(edcTransformer.transformTransferProcessRequestToJson(any())).thenReturn(mockedJsonObject); - - //WHEN - edcService.initiateHttpProxyTransferProcess(consumerEdcDataManagementUrl, providerConnectorControlPlaneIDSUrl - , transferProcessRequest, header); - //THEN - verify(edcTransformer).transformTransferProcessRequestToJson(any()); - verify(httpCallService).sendRequest(any(), eq(Response.class)); - } -} diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java index 83a3731207..08919a60b6 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java @@ -25,8 +25,6 @@ import org.eclipse.edc.catalog.spi.Catalog; import org.eclipse.edc.catalog.spi.Dataset; import org.eclipse.tractusx.irs.edc.client.EDCCatalogFacade; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.cache.EndpointDataReference; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.cache.InMemoryEndpointDataReferenceCache; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.configuration.JsonLdConfigurationTraceX; import org.eclipse.tractusx.traceability.infrastructure.edc.properties.EdcProperties; import org.eclipse.tractusx.traceability.qualitynotification.domain.model.QualityNotificationMessage; @@ -49,23 +47,19 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class InvestigationsEDCFacadeTest { - @Mock - EdcService edcService; - @Mock HttpCallService httpCallService; @Mock ObjectMapper objectMapper; - @Mock - InMemoryEndpointDataReferenceCache endpointDataReferenceCache; - @Mock EDCCatalogFacade edcCatalogFacade; @@ -74,172 +68,172 @@ class InvestigationsEDCFacadeTest { @InjectMocks InvestigationsEDCFacade investigationsEDCFacade; - - @Test - void test_startEDCTransfer() throws IOException, InterruptedException { - //GIVEN - String receiverEdcUrl = "https://example.com/receiver-edcUrl"; - String senderEdcUrl = "https://example.com/sender-edcUrl"; - - QualityNotificationMessage qualityNotificationMessage = NotificationTestDataFactory - .createNotificationTestData(QualityNotificationType.INVESTIGATION); - - when(edcProperties.getApiAuthKey()).thenReturn("x-api-key"); - when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of()); - - Catalog catalog = CatalogTestDataFactory.createCatalogTestData(); - when(edcService.getCatalog(anyString(), anyString(), any())).thenReturn(catalog); - - when(edcService.initializeContractNegotiation(anyString(), any(), anyString(), any())) - .thenReturn("negotiationId"); - - Algorithm algorithm = Algorithm.HMAC256("Catena-X"); - String jwtToken = JWT.create().withExpiresAt(Instant.now()).sign(algorithm); - EndpointDataReference endpointDataReference = EndpointDataReference.Builder.newInstance() - .endpoint("") - .authCode(jwtToken) - .authKey("authKey") - .build(); - when(endpointDataReferenceCache.get(anyString())).thenReturn(endpointDataReference); - - when(objectMapper.writeValueAsString(any())).thenReturn("someValidJson"); - - when(httpCallService.getUrl(any(), any(), any())).thenReturn(HttpUrl.get("https://w3id.org")); - - //WHEN - investigationsEDCFacade.startEDCTransfer(qualityNotificationMessage, receiverEdcUrl, senderEdcUrl); - - //THEN - verify(edcProperties).getApiAuthKey(); - verify(edcService).getCatalog(anyString(), anyString(), any()); - verify(edcService).initializeContractNegotiation(anyString(), any(), anyString(), any()); - verify(endpointDataReferenceCache, times(2)).get(anyString()); - verify(objectMapper).writeValueAsString(any()); - verify(httpCallService).getUrl(any(), any(), any()); - } - - @Test - void test_startEDCTransfer_with_catalog_properties() throws IOException, InterruptedException { - //GIVEN - String receiverEdcUrl = "https://example.com/receiver-edcUrl"; - String senderEdcUrl = "https://example.com/sender-edcUrl"; - - QualityNotificationMessage qualityNotificationMessage = NotificationTestDataFactory - .createNotificationTestData(QualityNotificationType.INVESTIGATION); - - when(edcProperties.getApiAuthKey()).thenReturn("x-api-key"); - when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of()); - - Map properties = Map.of(JsonLdConfigurationTraceX.NAMESPACE_EDC_PARTICIPANT_ID, "participantId"); - Catalog catalog = CatalogTestDataFactory.createCatalogTestData(properties); - when(edcService.getCatalog(anyString(), anyString(), any())).thenReturn(catalog); - - when(edcService.initializeContractNegotiation(anyString(), any(), anyString(), any())) - .thenReturn("negotiationId"); - - Algorithm algorithm = Algorithm.HMAC256("Catena-X"); - String jwtToken = JWT.create().withExpiresAt(Instant.now()).sign(algorithm); - EndpointDataReference endpointDataReference = EndpointDataReference.Builder.newInstance() - .endpoint("") - .authCode(jwtToken) - .authKey("authKey") - .build(); - when(endpointDataReferenceCache.get(anyString())).thenReturn(endpointDataReference); - - when(objectMapper.writeValueAsString(any())).thenReturn("someValidJson"); - - when(httpCallService.getUrl(any(), any(), any())).thenReturn(HttpUrl.get("https://w3id.org")); - - //WHEN - investigationsEDCFacade.startEDCTransfer(qualityNotificationMessage, receiverEdcUrl, senderEdcUrl); - - //THEN - verify(edcProperties).getApiAuthKey(); - verify(edcService).getCatalog(anyString(), anyString(), any()); - verify(edcService).initializeContractNegotiation(anyString(), any(), anyString(), any()); - verify(endpointDataReferenceCache, times(2)).get(anyString()); - verify(objectMapper).writeValueAsString(any()); - verify(httpCallService).getUrl(any(), any(), any()); - } - - @Test - void test_startEDCTransfer_throws_BadRequestException() throws IOException { - //GIVEN - String receiverEdcUrl = "https://example.com/receiver-edcUrl"; - String senderEdcUrl = "https://example.com/sender-edcUrl"; - - QualityNotificationMessage qualityNotificationMessage = NotificationTestDataFactory - .createNotificationTestData(QualityNotificationType.INVESTIGATION); - - when(edcProperties.getApiAuthKey()).thenReturn("x-api-key"); - when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of()); - - Catalog catalog = Catalog.Builder.newInstance().datasets(Collections.emptyList()).build(); - when(edcService.getCatalog(anyString(), anyString(), any())).thenReturn(catalog); - - //WHEN - BadRequestException badRequestException = assertThrows( - BadRequestException.class, - () -> investigationsEDCFacade.startEDCTransfer(qualityNotificationMessage, receiverEdcUrl, senderEdcUrl)); - - //THEN - verify(edcProperties).getApiAuthKey(); - verify(edcService).getCatalog(anyString(), anyString(), any()); - assertEquals("The dataset from the catalog is empty.", badRequestException.getMessage()); - } - - @Test - void test_startEDCTransfer_throws_BadRequestException_when_catalogItem_isEmpty() throws IOException { - //GIVEN - String receiverEdcUrl = "https://example.com/receiver-edcUrl"; - String senderEdcUrl = "https://example.com/sender-edcUrl"; - - QualityNotificationMessage qualityNotificationMessage = NotificationTestDataFactory - .createNotificationTestData(QualityNotificationType.INVESTIGATION); - - when(edcProperties.getApiAuthKey()).thenReturn("x-api-key"); - when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of()); - - Dataset.Builder datasetBuilder = Dataset.Builder.newInstance() - .property("https://w3id.org/edc/v0.0.1/ns/notificationtype", "invalidNotificationType") - .property("https://w3id.org/edc/v0.0.1/ns/notificationmethod", "invalidNotificationMethod") - .property("https://w3id.org/edc/v0.0.1/ns/id", "id"); - - Catalog catalog = CatalogTestDataFactory.createCatalogTestData(datasetBuilder); - when(edcService.getCatalog(anyString(), anyString(), any())).thenReturn(catalog); - - //WHEN - NoCatalogItemException badRequestException = assertThrows(NoCatalogItemException.class, - () -> investigationsEDCFacade.startEDCTransfer(qualityNotificationMessage, receiverEdcUrl, senderEdcUrl)); - - //THEN - verify(edcProperties).getApiAuthKey(); - verify(edcService).getCatalog(anyString(), anyString(), any()); - assertEquals("No Catalog Item in catalog found.", badRequestException.getMessage()); - - } - - @Test - void test_startEDCTransfer_throws_BadRequestException_when_IOException_is_thrown() throws IOException { - //GIVEN - String receiverEdcUrl = "https://example.com/receiver-edcUrl"; - String senderEdcUrl = "https://example.com/sender-edcUrl"; - - QualityNotificationMessage qualityNotificationMessage = NotificationTestDataFactory - .createNotificationTestData(QualityNotificationType.INVESTIGATION); - - when(edcProperties.getApiAuthKey()).thenReturn("x-api-key"); - when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of()); - - when(edcService.getCatalog(anyString(), anyString(), any())).thenThrow(IOException.class); - - //WHEN - BadRequestException badRequestException = assertThrows(BadRequestException.class, - () -> investigationsEDCFacade.startEDCTransfer(qualityNotificationMessage, receiverEdcUrl, senderEdcUrl)); - - //THEN - verify(edcProperties).getApiAuthKey(); - verify(edcService).getCatalog(anyString(), anyString(), any()); - assertEquals("EDC Data Transfer fail.", badRequestException.getMessage()); - } +// +// @Test +// void test_startEDCTransfer() throws IOException, InterruptedException { +// //GIVEN +// String receiverEdcUrl = "https://example.com/receiver-edcUrl"; +// String senderEdcUrl = "https://example.com/sender-edcUrl"; +// +// QualityNotificationMessage qualityNotificationMessage = NotificationTestDataFactory +// .createNotificationTestData(QualityNotificationType.INVESTIGATION); +// +// when(edcProperties.getApiAuthKey()).thenReturn("x-api-key"); +// when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of()); +// +// Catalog catalog = CatalogTestDataFactory.createCatalogTestData(); +// when(edcService.getCatalog(anyString(), anyString(), any())).thenReturn(catalog); +// +// when(edcService.initializeContractNegotiation(anyString(), any(), anyString(), any())) +// .thenReturn("negotiationId"); +// +// Algorithm algorithm = Algorithm.HMAC256("Catena-X"); +// String jwtToken = JWT.create().withExpiresAt(Instant.now()).sign(algorithm); +// EndpointDataReference endpointDataReference = EndpointDataReference.Builder.newInstance() +// .endpoint("") +// .authCode(jwtToken) +// .authKey("authKey") +// .build(); +// when(endpointDataReferenceCache.get(anyString())).thenReturn(endpointDataReference); +// +// when(objectMapper.writeValueAsString(any())).thenReturn("someValidJson"); +// +// when(httpCallService.getUrl(any(), any(), any())).thenReturn(HttpUrl.get("https://w3id.org")); +// +// //WHEN +// investigationsEDCFacade.startEDCTransfer(qualityNotificationMessage, receiverEdcUrl, senderEdcUrl); +// +// //THEN +// verify(edcProperties).getApiAuthKey(); +// verify(edcService).getCatalog(anyString(), anyString(), any()); +// verify(edcService).initializeContractNegotiation(anyString(), any(), anyString(), any()); +// verify(endpointDataReferenceCache, times(2)).get(anyString()); +// verify(objectMapper).writeValueAsString(any()); +// verify(httpCallService).getUrl(any(), any(), any()); +// } +// +// @Test +// void test_startEDCTransfer_with_catalog_properties() throws IOException, InterruptedException { +// //GIVEN +// String receiverEdcUrl = "https://example.com/receiver-edcUrl"; +// String senderEdcUrl = "https://example.com/sender-edcUrl"; +// +// QualityNotificationMessage qualityNotificationMessage = NotificationTestDataFactory +// .createNotificationTestData(QualityNotificationType.INVESTIGATION); +// +// when(edcProperties.getApiAuthKey()).thenReturn("x-api-key"); +// when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of()); +// +// Map properties = Map.of(JsonLdConfigurationTraceX.NAMESPACE_EDC_PARTICIPANT_ID, "participantId"); +// Catalog catalog = CatalogTestDataFactory.createCatalogTestData(properties); +// when(edcService.getCatalog(anyString(), anyString(), any())).thenReturn(catalog); +// +// when(edcService.initializeContractNegotiation(anyString(), any(), anyString(), any())) +// .thenReturn("negotiationId"); +// +// Algorithm algorithm = Algorithm.HMAC256("Catena-X"); +// String jwtToken = JWT.create().withExpiresAt(Instant.now()).sign(algorithm); +// EndpointDataReference endpointDataReference = EndpointDataReference.Builder.newInstance() +// .endpoint("") +// .authCode(jwtToken) +// .authKey("authKey") +// .build(); +// when(endpointDataReferenceCache.get(anyString())).thenReturn(endpointDataReference); +// +// when(objectMapper.writeValueAsString(any())).thenReturn("someValidJson"); +// +// when(httpCallService.getUrl(any(), any(), any())).thenReturn(HttpUrl.get("https://w3id.org")); +// +// //WHEN +// investigationsEDCFacade.startEDCTransfer(qualityNotificationMessage, receiverEdcUrl, senderEdcUrl); +// +// //THEN +// verify(edcProperties).getApiAuthKey(); +// verify(edcService).getCatalog(anyString(), anyString(), any()); +// verify(edcService).initializeContractNegotiation(anyString(), any(), anyString(), any()); +// verify(endpointDataReferenceCache, times(2)).get(anyString()); +// verify(objectMapper).writeValueAsString(any()); +// verify(httpCallService).getUrl(any(), any(), any()); +// } +// +// @Test +// void test_startEDCTransfer_throws_BadRequestException() throws IOException { +// //GIVEN +// String receiverEdcUrl = "https://example.com/receiver-edcUrl"; +// String senderEdcUrl = "https://example.com/sender-edcUrl"; +// +// QualityNotificationMessage qualityNotificationMessage = NotificationTestDataFactory +// .createNotificationTestData(QualityNotificationType.INVESTIGATION); +// +// when(edcProperties.getApiAuthKey()).thenReturn("x-api-key"); +// when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of()); +// +// Catalog catalog = Catalog.Builder.newInstance().datasets(Collections.emptyList()).build(); +// when(edcService.getCatalog(anyString(), anyString(), any())).thenReturn(catalog); +// +// //WHEN +// BadRequestException badRequestException = assertThrows( +// BadRequestException.class, +// () -> investigationsEDCFacade.startEDCTransfer(qualityNotificationMessage, receiverEdcUrl, senderEdcUrl)); +// +// //THEN +// verify(edcProperties).getApiAuthKey(); +// verify(edcService).getCatalog(anyString(), anyString(), any()); +// assertEquals("The dataset from the catalog is empty.", badRequestException.getMessage()); +// } +// +// @Test +// void test_startEDCTransfer_throws_BadRequestException_when_catalogItem_isEmpty() throws IOException { +// //GIVEN +// String receiverEdcUrl = "https://example.com/receiver-edcUrl"; +// String senderEdcUrl = "https://example.com/sender-edcUrl"; +// +// QualityNotificationMessage qualityNotificationMessage = NotificationTestDataFactory +// .createNotificationTestData(QualityNotificationType.INVESTIGATION); +// +// when(edcProperties.getApiAuthKey()).thenReturn("x-api-key"); +// when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of()); +// +// Dataset.Builder datasetBuilder = Dataset.Builder.newInstance() +// .property("https://w3id.org/edc/v0.0.1/ns/notificationtype", "invalidNotificationType") +// .property("https://w3id.org/edc/v0.0.1/ns/notificationmethod", "invalidNotificationMethod") +// .property("https://w3id.org/edc/v0.0.1/ns/id", "id"); +// +// Catalog catalog = CatalogTestDataFactory.createCatalogTestData(datasetBuilder); +// when(edcService.getCatalog(anyString(), anyString(), any())).thenReturn(catalog); +// +// //WHEN +// NoCatalogItemException badRequestException = assertThrows(NoCatalogItemException.class, +// () -> investigationsEDCFacade.startEDCTransfer(qualityNotificationMessage, receiverEdcUrl, senderEdcUrl)); +// +// //THEN +// verify(edcProperties).getApiAuthKey(); +// verify(edcService).getCatalog(anyString(), anyString(), any()); +// assertEquals("No Catalog Item in catalog found.", badRequestException.getMessage()); +// +// } +// +// @Test +// void test_startEDCTransfer_throws_BadRequestException_when_IOException_is_thrown() throws IOException { +// //GIVEN +// String receiverEdcUrl = "https://example.com/receiver-edcUrl"; +// String senderEdcUrl = "https://example.com/sender-edcUrl"; +// +// QualityNotificationMessage qualityNotificationMessage = NotificationTestDataFactory +// .createNotificationTestData(QualityNotificationType.INVESTIGATION); +// +// when(edcProperties.getApiAuthKey()).thenReturn("x-api-key"); +// when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of()); +// +// when(edcService.getCatalog(anyString(), anyString(), any())).thenThrow(IOException.class); +// +// //WHEN +// BadRequestException badRequestException = assertThrows(BadRequestException.class, +// () -> investigationsEDCFacade.startEDCTransfer(qualityNotificationMessage, receiverEdcUrl, senderEdcUrl)); +// +// //THEN +// verify(edcProperties).getApiAuthKey(); +// verify(edcService).getCatalog(anyString(), anyString(), any()); +// assertEquals("EDC Data Transfer fail.", badRequestException.getMessage()); +// } } From 68b1686cbb2d3e5f7476f26140e8b5e230bfd6e3 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Tue, 29 Aug 2023 23:13:37 +0200 Subject: [PATCH 40/63] feature: TRACEFOSS-2391 cleanup --- .../EdcCallbackControllerTraceXIT.groovy | 139 ------------------ .../cache/EndpointDataReferenceTest.java | 80 ---------- .../service/EdcNotificationServiceTest.java | 4 +- 3 files changed, 2 insertions(+), 221 deletions(-) delete mode 100644 tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcCallbackControllerTraceXIT.groovy delete mode 100644 tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/cache/EndpointDataReferenceTest.java diff --git a/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcCallbackControllerTraceXIT.groovy b/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcCallbackControllerTraceXIT.groovy deleted file mode 100644 index 7ac236a662..0000000000 --- a/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcCallbackControllerTraceXIT.groovy +++ /dev/null @@ -1,139 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * Copyright (c) 2022, 2023 ZF Friedrichshafen AG - * Copyright (c) 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.traceability.infrastructure.edc.blackbox - -import io.restassured.http.ContentType -import org.eclipse.tractusx.traceability.IntegrationSpecification -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.cache.InMemoryEndpointDataReferenceCache -import org.eclipse.tractusx.traceability.infrastructure.edc.properties.EdcProperties -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.context.TestConfiguration -import org.springframework.boot.web.client.RestTemplateBuilder -import org.springframework.context.annotation.Bean -import spock.lang.Ignore - -import static com.xebialabs.restito.builder.stub.StubHttp.whenHttp -import static com.xebialabs.restito.builder.verify.VerifyHttp.verifyHttp -import static com.xebialabs.restito.semantics.Action.ok -import static com.xebialabs.restito.semantics.Condition.post -import static io.restassured.RestAssured.given -import static org.eclipse.tractusx.traceability.common.security.JwtRole.ADMIN - -class EdcCallbackControllerTraceXIT extends IntegrationSpecification { - - @Autowired - InMemoryEndpointDataReferenceCache endpointDataReferenceCache - - @Ignore - def "should execute callback"() { - given: - String contractAgreementId = "contractAgreementId" - thereIsRedirectionEndpoint() - endpointDataReferenceCache.storeAgreementId(contractAgreementId) - - when: - given() - .contentType(ContentType.JSON) - .body( - asJson( - [ - id : "urn:uuid:d387fa8e-603c-42bd-98c3-4d87fef8d2bb", - endpoint : "endpoint", - authKey : "authKey", - authCode : "test.eyJleHAiOjU1NSwiZGFkIjoiZGFkIiwiY2lkIjoiY2lkIn0=", - properties: [ - "https://w3id.org/edc/v0.0.1/ns/cid": contractAgreementId - ] - ] - ) - ) - .header(jwtAuthorization(ADMIN)) - .when() - .post("/api/callback/endpoint-data-reference") - .then() - .statusCode(200) - - then: - endpointDataReferenceCache.get(contractAgreementId) - verifyRedirectionNotCalled() - } - - def "should redirect callback when no contract agreement exists"() { - given: - String contractAgreementId = "contractAgreementId2"; - thereIsRedirectionEndpoint() - - when: - given() - .contentType(ContentType.JSON) - .body( - asJson( - [ - id: "urn:uuid:d387fa8e-603c-42bd-98c3-4d87fef8d2bb", - endpoint: "endpoint", - authKey: "authKey", - authCode: "test.eyJleHAiOjU1NSwiZGFkIjoiZGFkIiwiY2lkIjoiY2lkIn0=", - properties: [ - "cid": contractAgreementId - ] - ] - ) - ) - .header(jwtAuthorization(ADMIN)) - .when() - .post("/api/callback/endpoint-data-reference") - .then() - .statusCode(200) - - then: - endpointDataReferenceCache.get(contractAgreementId) == null - verifyRedirectionCalledOnce() - } - - private void thereIsRedirectionEndpoint() { - whenHttp(stubServer()).match( - post("/callback/redirect") - ) - .then(ok()) - } - - private void verifyRedirectionNotCalled() { - verifyHttp(stubServer()).never( - post("/callback/redirect") - ) - } - - private void verifyRedirectionCalledOnce() { - verifyHttp(stubServer()).once( - post("/callback/redirect") - ) - } - - @TestConfiguration - static class EdcTestConfig { - -// @Bean -// EdcCallbackControllerTraceX edcCallbackController(InMemoryEndpointDataReferenceCache endpointDataReferenceCache, RestTemplateBuilder restTemplateBuilder, EdcProperties edcProperties) { -// return new EdcCallbackControllerTraceX(endpointDataReferenceCache, restTemplateBuilder, edcProperties) -// } - } - -} diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/cache/EndpointDataReferenceTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/cache/EndpointDataReferenceTest.java deleted file mode 100644 index b0d4b77dfa..0000000000 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/cache/EndpointDataReferenceTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * Copyright (c) 2022, 2023 ZF Friedrichshafen AG - * Copyright (c) 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.traceability.infrastructure.edc.blackbox.cache; - -import java.util.HashMap; -import java.util.Map; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.junit.jupiter.MockitoExtension; - -import static org.junit.jupiter.api.Assertions.*; - -@ExtendWith(MockitoExtension.class) -class EndpointDataReferenceTest { - - private static final String endpoint = "endpoint"; - private static final String id = "id"; - private static final String authkey = "authkey"; - private static final String authcode = "authcode"; - private static final Map properties = new HashMap<>(); - private EndpointDataReference endpointDataReference; - - @BeforeEach - void setUp() { - properties.put("key0", "value0"); - endpointDataReference = EndpointDataReference.Builder.newInstance() - .id(id) - .endpoint(endpoint) - .authKey(authkey) - .authCode(authcode) - .properties(properties) - .build(); - } - - @Test - void getId() { - assertEquals(id, endpointDataReference.getId()); - } - - @Test - void getEndpoint() { - assertEquals(endpoint, endpointDataReference.getEndpoint()); - } - - @Test - void getAuthKey() { - assertEquals(authkey, endpointDataReference.getAuthKey()); - } - - @Test - void getAuthCode() { - assertEquals(authcode, endpointDataReference.getAuthCode()); - } - - @Test - void getProperties() { - assertEquals(properties.keySet().size(), endpointDataReference.getProperties().keySet().size()); - } - -} diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationServiceTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationServiceTest.java index 5a17f3f149..149a2b1f6c 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationServiceTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationServiceTest.java @@ -83,7 +83,7 @@ void testNotificationsServiceUpdateAsync() { notificationsService.asyncNotificationExecutor(notification); // then - verify(edcFacade).startEDCTransfer(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); + verify(edcFacade).startEdcTransferNew(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); verify(investigationRepository).updateQualityNotificationMessageEntity(notification); verifyNoInteractions(alertRepository); } @@ -111,7 +111,7 @@ void testNotificationsServiceAlertNotificationUpdateAsync() { notificationsService.asyncNotificationExecutor(notification); // then - verify(edcFacade).startEDCTransfer(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); + verify(edcFacade).startEdcTransferNew(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); verify(alertRepository).updateQualityNotificationMessageEntity(notification); verifyNoInteractions(investigationRepository); } From cc112779f38a613dae7d6339796cabc175a5efde Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Tue, 29 Aug 2023 23:48:59 +0200 Subject: [PATCH 41/63] feature: TRACEFOSS-2391 cleanup --- .../edc/blackbox/BadRequestException.java | 6 -- .../edc/blackbox/HttpCallService.java | 84 +------------------ .../edc/blackbox/InvestigationsEDCFacade.java | 64 +------------- .../edc/blackbox/catalog/CatalogItem.java | 44 ---------- .../edc/blackbox/policy/PolicyDefinition.java | 42 ---------- .../validators/AtomicConstraintValidator.java | 57 ------------- 6 files changed, 2 insertions(+), 295 deletions(-) delete mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/catalog/CatalogItem.java delete mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/policy/PolicyDefinition.java delete mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/validators/AtomicConstraintValidator.java diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/BadRequestException.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/BadRequestException.java index b551c053bd..67dd3b1801 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/BadRequestException.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/BadRequestException.java @@ -26,10 +26,4 @@ public class BadRequestException extends RuntimeException { public BadRequestException(String message) { super(message); } - - public BadRequestException(String message, Throwable cause) { - super(message, cause); - } - - } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/HttpCallService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/HttpCallService.java index 7489c3c2ed..b281ca6032 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/HttpCallService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/HttpCallService.java @@ -24,43 +24,28 @@ import jakarta.ws.rs.core.MultivaluedMap; import lombok.extern.slf4j.Slf4j; import okhttp3.HttpUrl; -import okhttp3.MediaType; import okhttp3.OkHttpClient; import okhttp3.Request; -import okhttp3.RequestBody; -import org.eclipse.edc.catalog.spi.Catalog; -import org.eclipse.edc.catalog.spi.CatalogRequest; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.jsontransformer.EdcTransformerTraceX; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.negotiation.NegotiationResponse; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.policy.AtomicConstraint; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.policy.LiteralExpression; -import org.eclipse.tractusx.traceability.infrastructure.edc.properties.EdcProperties; import org.springframework.stereotype.Component; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.TimeUnit; import static java.lang.String.format; -import static org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.transferprocess.TransferProcessRequest.DEFAULT_PROTOCOL; @Slf4j @Component public class HttpCallService { private final OkHttpClient httpClient; - private final ObjectMapper objectMapper; - private final EdcProperties edcProperties; - private final EdcTransformerTraceX edcTransformer; - public HttpCallService(OkHttpClient httpClient, ObjectMapper objectMapper, EdcProperties edcProperties, EdcTransformerTraceX edcTransformer) { + public HttpCallService(OkHttpClient httpClient, ObjectMapper objectMapper) { this.httpClient = withIncreasedTimeout(httpClient); - this.objectMapper = objectMapper; - this.edcProperties = edcProperties; - this.edcTransformer = edcTransformer; objectMapper.registerSubtypes(AtomicConstraint.class, LiteralExpression.class); } @@ -72,73 +57,6 @@ private static OkHttpClient withIncreasedTimeout(OkHttpClient httpClient) { .build(); } - public Catalog getCatalogForNotification( - String consumerEdcDataManagementUrl, - String providerConnectorControlPlaneIDSUrl, - Map headers - ) throws IOException { - var url = consumerEdcDataManagementUrl + edcProperties.getCatalogPath(); - MediaType mediaType = MediaType.parse("application/json"); - - // TODO instead of filtering with java logic after the call of this method we could add a filter to the .querySpec within CatalogRequest object. Max W. - CatalogRequest catalogRequestDTO = CatalogRequest.Builder.newInstance() - .protocol(DEFAULT_PROTOCOL) - .providerUrl(providerConnectorControlPlaneIDSUrl) - .build(); - - final String requestJson = edcTransformer.transformCatalogRequestToJson(catalogRequestDTO).toString(); - var request = new Request.Builder().url(url).post(RequestBody.create(mediaType, requestJson)); - headers.forEach(request::addHeader); - return sendCatalogRequest(request.build()); - } - - public Catalog sendCatalogRequest(Request request) throws IOException { - log.info("Requesting {} {}...", request.method(), request.url()); - try (var response = httpClient.newCall(request).execute()) { - var body = response.body(); - - if (!response.isSuccessful() || body == null) { - throw new BadRequestException(format("Control plane responded with: %s %s", response.code(), body != null ? body.string() : "")); - } - - String res = body.string(); - return edcTransformer.transformCatalog(res, StandardCharsets.UTF_8); - } catch (Exception e) { - throw e; - } - } - - public NegotiationResponse sendNegotiationRequest(Request request) throws IOException { - log.info("Requesting {} {}...", request.method(), request.url()); - try (var response = httpClient.newCall(request).execute()) { - var body = response.body(); - - if (!response.isSuccessful() || body == null) { - throw new BadRequestException(format("Control plane responded with: %s %s", response.code(), body != null ? body.string() : "")); - } - - String res = body.string(); - return edcTransformer.transformJsonToNegotiationResponse(res, StandardCharsets.UTF_8); - } catch (Exception e) { - throw e; - } - } - - public Object sendRequest(Request request, Class responseObject) throws IOException { - log.info("Requesting {} {}...", request.method(), request.url()); - try (var response = httpClient.newCall(request).execute()) { - var body = response.body(); - - if (!response.isSuccessful() || body == null) { - throw new BadRequestException(format("Control plane responded with: %s %s", response.code(), body != null ? body.string() : "")); - } - - String res = body.string(); - return objectMapper.readValue(res, responseObject); - } catch (Exception e) { - throw e; - } - } public void sendRequest(Request request) throws IOException { try (var response = httpClient.newCall(request).execute()) { diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index a4c3fae070..006e3ca074 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -30,12 +30,6 @@ import okhttp3.Request; import okhttp3.RequestBody; import org.eclipse.edc.catalog.spi.CatalogRequest; -import org.eclipse.edc.policy.model.AtomicConstraint; -import org.eclipse.edc.policy.model.Constraint; -import org.eclipse.edc.policy.model.Operator; -import org.eclipse.edc.policy.model.OrConstraint; -import org.eclipse.edc.policy.model.Permission; -import org.eclipse.edc.policy.model.Policy; import org.eclipse.edc.spi.query.Criterion; import org.eclipse.edc.spi.query.QuerySpec; import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference; @@ -46,8 +40,6 @@ import org.eclipse.tractusx.irs.edc.client.policy.PolicyCheckerService; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.model.EDCNotification; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.model.EDCNotificationFactory; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.policy.PolicyDefinition; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.validators.AtomicConstraintValidator; import org.eclipse.tractusx.traceability.infrastructure.edc.properties.EdcProperties; import org.eclipse.tractusx.traceability.qualitynotification.domain.model.QualityNotificationMessage; import org.eclipse.tractusx.traceability.qualitynotification.domain.model.QualityNotificationType; @@ -57,7 +49,6 @@ import java.util.List; import java.util.Optional; -import static org.eclipse.edc.spi.query.Criterion.CRITERION_OPERAND_LEFT; import static org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.configuration.JsonLdConfigurationTraceX.NAMESPACE_EDC; import static org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.transferprocess.TransferProcessRequest.DEFAULT_PROTOCOL; @@ -90,6 +81,7 @@ public void startEdcTransferNew( final QualityNotificationMessage notification, final String receiverEdcUrl, final String senderEdcUrl) { + CatalogItem catalogItem = getCatalogItem(notification, receiverEdcUrl); String contractAgreementId = negotiateContractAgreement(receiverEdcUrl, catalogItem); @@ -161,58 +153,4 @@ private Request buildNotificationRequestNew( .build(); } - private boolean hasTracePolicy(final CatalogItem catalogItem) { - boolean foundPolicy = false; - if (catalogItem.getPolicy() != null) { - log.info("Policy Check {} ", catalogItem.getPolicy().toString()); - foundPolicy = isValid(catalogItem.getPolicy()); - } - log.info("Found policy: {} ", foundPolicy); - return foundPolicy; - } - - private List allowedPolicies() { - final PolicyDefinition allowedTracePolicy = PolicyDefinition.builder() - .constraintOperator("EQ") - .permissionActionType("USE") - .constraintType("AtomicConstraint") - .leftExpressionValue("PURPOSE") - .rightExpressionValue("ID 3.0 Trace") - .build(); - return List.of(allowedTracePolicy); - } - - private boolean isValid(final Policy policy) { - final List policyList = this.allowedPolicies(); - return policy.getPermissions() - .stream() - .anyMatch(permission -> policyList.stream() - .anyMatch(allowedPolicy -> isValid(permission, allowedPolicy))); - } - - private boolean isValid(final Permission permission, final PolicyDefinition policyDefinition) { - return permission.getAction().getType().equals(policyDefinition.getPermissionActionType()) - && permission.getConstraints() - .stream() - .anyMatch(constraint -> isValid(constraint, policyDefinition)); - } - - private boolean isValid(final Constraint constraint, final PolicyDefinition policyDefinition) { - if (constraint instanceof AtomicConstraint atomicConstraint) { - return AtomicConstraintValidator.builder() - .atomicConstraint(atomicConstraint) - .leftExpressionValue(policyDefinition.getLeftExpressionValue()) - .rightExpressionValue(policyDefinition.getRightExpressionValue()) - .expectedOperator( - Operator.valueOf(policyDefinition.getConstraintOperator())) - .build() - .isValid(); - } else if (constraint instanceof OrConstraint orConstraint) { - return orConstraint.getConstraints() - .stream() - .anyMatch(constraint1 -> isValid(constraint1, policyDefinition)); - } - return false; - } - } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/catalog/CatalogItem.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/catalog/CatalogItem.java deleted file mode 100644 index dd593704dd..0000000000 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/catalog/CatalogItem.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************** - * 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.traceability.infrastructure.edc.blackbox.catalog; - -import lombok.Builder; -import lombok.Data; -import org.eclipse.edc.policy.model.Policy; - -import java.time.Instant; - -/** - * Catalog Item as it is stored in the cache and used by {@link org.eclipse.edc.connector.spi.contractnegotiation.ContractNegotiationService}. - */ -@Builder -@Data -public class CatalogItem { - private String assetPropId; - private String itemId; - private Policy policy; - private String connectorId; - private String offerId; - private Instant validUntil; - -} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/policy/PolicyDefinition.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/policy/PolicyDefinition.java deleted file mode 100644 index d680945bc4..0000000000 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/policy/PolicyDefinition.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************** - * 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.traceability.infrastructure.edc.blackbox.policy; - -import lombok.Builder; -import lombok.Data; - -/** - * Policy Definition that is accepted by IRS. - */ -@Builder -@Data -public class PolicyDefinition { - - private String permissionActionType; - private String constraintType; - private String leftExpressionValue; - private String rightExpressionValue; - private String constraintOperator; - - -} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/validators/AtomicConstraintValidator.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/validators/AtomicConstraintValidator.java deleted file mode 100644 index 8ed4fe3847..0000000000 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/validators/AtomicConstraintValidator.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************** - * 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.traceability.infrastructure.edc.blackbox.validators; - -import lombok.Builder; -import org.eclipse.edc.policy.model.AtomicConstraint; -import org.eclipse.edc.policy.model.Expression; -import org.eclipse.edc.policy.model.LiteralExpression; -import org.eclipse.edc.policy.model.Operator; - -/** - * Check and validate AtomicConstraint as a part of Policy in Catalog fetch from EDC providers. - */ -@Builder -public class AtomicConstraintValidator { - - private AtomicConstraint atomicConstraint; - private String leftExpressionValue; - private String rightExpressionValue; - private Operator expectedOperator; - - public boolean isValid() { - return isExpressionValid(atomicConstraint.getLeftExpression(), - leftExpressionValue) && isExpressionValid( - atomicConstraint.getRightExpression(), rightExpressionValue) - && expectedOperator.equals(atomicConstraint.getOperator()); - } - - private boolean isExpressionValid(final Expression expression, final String value) { - if (expression instanceof LiteralExpression literalExpression) { - return literalExpression.asString().equals(value); - } - return false; - } - - -} From f58e997cb444df640c8352f5c0b75540f3f3d046 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Wed, 30 Aug 2023 08:38:29 +0200 Subject: [PATCH 42/63] feature: TRACEFOSS-2391 turn on tests and watch the world crumble --- .github/workflows/pull-request_backend.yml | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/.github/workflows/pull-request_backend.yml b/.github/workflows/pull-request_backend.yml index ee52d61475..d0b12f0770 100644 --- a/.github/workflows/pull-request_backend.yml +++ b/.github/workflows/pull-request_backend.yml @@ -27,8 +27,53 @@ env: DOCKER_HUB_REGISTRY_NAMESPACE: tractusx jobs: + Test-and-Sonar: + permissions: + checks: write + pull-requests: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + java-version: '${{ env.JAVA_VERSION }}' + distribution: 'temurin' + cache: 'maven' + + - name: Run unit & integration tests + run: mvn -pl tx-models,tx-backend,tx-coverage -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B verify + + - name: Publish integration test results + uses: EnricoMi/publish-unit-test-result-action@v2 + if: always() + with: + files: "/home/runner/work/tx-traceability-foss/tx-traceability-foss/tx-backend/target/failsafe-reports/TEST-*.xml" + check_name: "Integration Test Results" + + - name: Publish unit test results + uses: EnricoMi/publish-unit-test-result-action@v2 + if: always() + with: + files: "**/surefire-reports/TEST-*.xml" + check_name: "Unit Test Results" + + - name: Cache SonarCloud packages + uses: actions/cache@v3 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + + - name: Verify Sonar Scan + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_BACKEND }} + SONAR_ORGANIZATION: ${{ vars.SONAR_ORGANIZATION }} + SONAR_PROJECT_KEY: ${{ vars.SONAR_PROJECT_KEY_BACKEND }} + run: mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn --batch-mode sonar:sonar -Dsonar.coverage.jacoco.xmlReportPaths=/home/runner/work/tx-traceability-foss/tx-traceability-foss/tx-coverage/target/site/jacoco-aggregate/jacoco.xml -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY_BACKEND }} -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }} Publish-docker-image: + needs: [ "Test-and-Sonar" ] runs-on: ubuntu-latest defaults: run: From 02675693435c3087a3af284115e35b6acb8e1635 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Wed, 30 Aug 2023 09:13:40 +0200 Subject: [PATCH 43/63] feature: TRACEFOSS-2391 test unneded bean creation --- .github/workflows/pull-request_backend.yml | 46 ------------------- .../IntegrationSpecification.groovy | 4 ++ .../EdcRestTemplateConfiguration.java | 14 +----- 3 files changed, 5 insertions(+), 59 deletions(-) diff --git a/.github/workflows/pull-request_backend.yml b/.github/workflows/pull-request_backend.yml index d0b12f0770..663567e3e7 100644 --- a/.github/workflows/pull-request_backend.yml +++ b/.github/workflows/pull-request_backend.yml @@ -27,53 +27,7 @@ env: DOCKER_HUB_REGISTRY_NAMESPACE: tractusx jobs: - Test-and-Sonar: - permissions: - checks: write - pull-requests: write - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 - with: - java-version: '${{ env.JAVA_VERSION }}' - distribution: 'temurin' - cache: 'maven' - - - name: Run unit & integration tests - run: mvn -pl tx-models,tx-backend,tx-coverage -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B verify - - - name: Publish integration test results - uses: EnricoMi/publish-unit-test-result-action@v2 - if: always() - with: - files: "/home/runner/work/tx-traceability-foss/tx-traceability-foss/tx-backend/target/failsafe-reports/TEST-*.xml" - check_name: "Integration Test Results" - - - name: Publish unit test results - uses: EnricoMi/publish-unit-test-result-action@v2 - if: always() - with: - files: "**/surefire-reports/TEST-*.xml" - check_name: "Unit Test Results" - - - name: Cache SonarCloud packages - uses: actions/cache@v3 - with: - path: ~/.sonar/cache - key: ${{ runner.os }}-sonar - restore-keys: ${{ runner.os }}-sonar - - - name: Verify Sonar Scan - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_BACKEND }} - SONAR_ORGANIZATION: ${{ vars.SONAR_ORGANIZATION }} - SONAR_PROJECT_KEY: ${{ vars.SONAR_PROJECT_KEY_BACKEND }} - run: mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn --batch-mode sonar:sonar -Dsonar.coverage.jacoco.xmlReportPaths=/home/runner/work/tx-traceability-foss/tx-traceability-foss/tx-coverage/target/site/jacoco-aggregate/jacoco.xml -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY_BACKEND }} -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }} - Publish-docker-image: - needs: [ "Test-and-Sonar" ] runs-on: ubuntu-latest defaults: run: diff --git a/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/IntegrationSpecification.groovy b/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/IntegrationSpecification.groovy index 8eab7603e1..a9416d1c72 100644 --- a/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/IntegrationSpecification.groovy +++ b/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/IntegrationSpecification.groovy @@ -23,6 +23,7 @@ package org.eclipse.tractusx.traceability import com.xebialabs.restito.server.StubServer import groovy.json.JsonBuilder +import org.eclipse.tractusx.irs.edc.client.EDCCatalogFacade import org.eclipse.tractusx.traceability.assets.domain.asbuilt.repository.AssetAsBuiltRepository import org.eclipse.tractusx.traceability.assets.domain.asplanned.repository.AssetAsPlannedRepository import org.eclipse.tractusx.traceability.assets.domain.base.BpnRepository @@ -89,6 +90,9 @@ abstract class IntegrationSpecification extends Specification @Autowired private JdbcTemplate jdbcTemplate + @Autowired + private EDCCatalogFacade edcCatalogFacade + def setup() { oauth2ApiReturnsJwkCerts(jwk()) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/configuration/EdcRestTemplateConfiguration.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/configuration/EdcRestTemplateConfiguration.java index 450604414d..f698ed91e2 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/configuration/EdcRestTemplateConfiguration.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/configuration/EdcRestTemplateConfiguration.java @@ -22,9 +22,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.eclipse.tractusx.irs.edc.client.EDCCatalogFacade; -import org.eclipse.tractusx.irs.edc.client.EdcConfiguration; -import org.eclipse.tractusx.irs.edc.client.EdcControlPlaneClient; import org.eclipse.tractusx.traceability.infrastructure.edc.properties.EdcProperties; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; @@ -67,15 +64,6 @@ public RestTemplate edcTemplate() { .build(); } - - @Bean(name = "testedc", - autowireCandidate = false) - EDCCatalogFacade edcCatalogFacade(EdcControlPlaneClient client, - EdcConfiguration c) { - log.info(" {}", c); - return new EDCCatalogFacade(client,c); - } - @Bean public RestTemplate digitalTwinRegistryRestTemplate( final RestTemplateBuilder restTemplateBuilder, @@ -100,7 +88,7 @@ private RestTemplateBuilder oAuthRestTemplate(final RestTemplateBuilder restTemp new OAuthClientCredentialsRestTemplateInterceptor(authorizedClientManager(), clientRegistration)); } - /* package */ OAuth2AuthorizedClientManager authorizedClientManager() { + /* package */ OAuth2AuthorizedClientManager authorizedClientManager() { final var authorizedClientProvider = OAuth2AuthorizedClientProviderBuilder.builder() .clientCredentials() .build(); From 8e4534a5df9c47d0eaac1af47848eaae611db920 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 30 Aug 2023 10:00:51 +0200 Subject: [PATCH 44/63] chore: TRACEFOSS-2607 rename workflows --- .github/workflows/e2e-tests-xray_frontend.yml | 2 +- .github/workflows/kics.yml | 2 +- .github/workflows/publish-documentation.yaml | 2 +- .github/workflows/pull-request_backend.yml | 2 +- .github/workflows/quality-checks.yaml | 2 +- .github/workflows/release.yaml | 2 +- .github/workflows/sonar-scan-backend.yml | 2 +- .github/workflows/sonar-scan-frontend.yml | 2 +- .github/workflows/spotbugs.yml | 2 +- .github/workflows/trivy.yml | 2 +- .github/workflows/unit-test_frontend.yml | 2 +- .github/workflows/update-helm-environment.yml | 2 +- .github/workflows/veracode_backend.yml | 2 +- .github/workflows/veracode_frontend.yml | 2 +- .github/workflows/xray-cucumber.yaml | 9 +++------ 15 files changed, 17 insertions(+), 20 deletions(-) diff --git a/.github/workflows/e2e-tests-xray_frontend.yml b/.github/workflows/e2e-tests-xray_frontend.yml index 79e001a1e9..13806ca572 100644 --- a/.github/workflows/e2e-tests-xray_frontend.yml +++ b/.github/workflows/e2e-tests-xray_frontend.yml @@ -18,7 +18,7 @@ # Require to set secrets: # - ORG_IRS_JIRA_USERNAME # - ORG_IRS_JIRA_PASSWORD -name: E2E Tests - Xray +name: [FE][TEST][E2E]- Cypress on: # triggered manually by Test Manager diff --git a/.github/workflows/kics.yml b/.github/workflows/kics.yml index a96958b204..a82d2976b7 100644 --- a/.github/workflows/kics.yml +++ b/.github/workflows/kics.yml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: "KICS" +name: [BE][FE][SECURITY] Kics on: push: diff --git a/.github/workflows/publish-documentation.yaml b/.github/workflows/publish-documentation.yaml index 930fbee591..9d2cfe7ec3 100644 --- a/.github/workflows/publish-documentation.yaml +++ b/.github/workflows/publish-documentation.yaml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: Publish documentation +name: [BE][FE][DOCUMENTATION] Publish documentation on: workflow_dispatch: # Trigger manually diff --git a/.github/workflows/pull-request_backend.yml b/.github/workflows/pull-request_backend.yml index d0b12f0770..e219e62d4c 100644 --- a/.github/workflows/pull-request_backend.yml +++ b/.github/workflows/pull-request_backend.yml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: "Pull request Backend" +name: [BE][BUILT][DEPLOYMENT] Pull request on: workflow_dispatch: # Trigger manually diff --git a/.github/workflows/quality-checks.yaml b/.github/workflows/quality-checks.yaml index 430fd57e2a..49ccded39a 100644 --- a/.github/workflows/quality-checks.yaml +++ b/.github/workflows/quality-checks.yaml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: "Quality Checks (Release Guidelines)" +name: [BE][FE][SECURITY] TRG Checks on: workflow_dispatch: # Trigger manually diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 9acbac41bb..30fca628c6 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,4 +1,4 @@ -name: Release Trace-X +name: [BE][FE] Release on: workflow_dispatch: diff --git a/.github/workflows/sonar-scan-backend.yml b/.github/workflows/sonar-scan-backend.yml index 3e6e5491a7..a005160774 100644 --- a/.github/workflows/sonar-scan-backend.yml +++ b/.github/workflows/sonar-scan-backend.yml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: "Sonar Cloud Analyze" +name: [BE][SECURITY] Sonar on: workflow_dispatch: push: diff --git a/.github/workflows/sonar-scan-frontend.yml b/.github/workflows/sonar-scan-frontend.yml index f0d8e6c4e7..db714381e2 100644 --- a/.github/workflows/sonar-scan-frontend.yml +++ b/.github/workflows/sonar-scan-frontend.yml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: Sonar Frontend +name: [FE][SECURITY] Sonar on: push: diff --git a/.github/workflows/spotbugs.yml b/.github/workflows/spotbugs.yml index 92c68cb213..b5a6d749b1 100644 --- a/.github/workflows/spotbugs.yml +++ b/.github/workflows/spotbugs.yml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: "Spotbugs bug detection" +name: [BE][SECURITY] Spotbugs on: push: diff --git a/.github/workflows/trivy.yml b/.github/workflows/trivy.yml index f240b100d3..4841d87c8e 100644 --- a/.github/workflows/trivy.yml +++ b/.github/workflows/trivy.yml @@ -20,7 +20,7 @@ # separate terms of service, privacy policy, and support # documentation. -name: Trivy +name: [BE][FE][SECURITY] Trivy on: pull_request: diff --git a/.github/workflows/unit-test_frontend.yml b/.github/workflows/unit-test_frontend.yml index a92f8e6af2..b91f0db059 100644 --- a/.github/workflows/unit-test_frontend.yml +++ b/.github/workflows/unit-test_frontend.yml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: Unit Tests Frontend +name: [FE][TEST] Unit Tests on: push: diff --git a/.github/workflows/update-helm-environment.yml b/.github/workflows/update-helm-environment.yml index b0eeeaba24..fba749ec75 100644 --- a/.github/workflows/update-helm-environment.yml +++ b/.github/workflows/update-helm-environment.yml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: Update helm environments branch +name: [BE][FE][DEPLOYMENT] Update helm environments branch on: push: branches: main diff --git a/.github/workflows/veracode_backend.yml b/.github/workflows/veracode_backend.yml index 042ebd74c4..9f945dfbc0 100644 --- a/.github/workflows/veracode_backend.yml +++ b/.github/workflows/veracode_backend.yml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: "Veracode upload and scan" +name: [BE][SECURITY] Trivy on: workflow_dispatch: diff --git a/.github/workflows/veracode_frontend.yml b/.github/workflows/veracode_frontend.yml index ced8f0e2c4..a22b55e690 100644 --- a/.github/workflows/veracode_frontend.yml +++ b/.github/workflows/veracode_frontend.yml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: "Veracode upload and scan - Frontend" +name: [FE][SECURITY] Trivy on: workflow_dispatch: diff --git a/.github/workflows/xray-cucumber.yaml b/.github/workflows/xray-cucumber.yaml index e6d68011a0..173f214bb7 100644 --- a/.github/workflows/xray-cucumber.yaml +++ b/.github/workflows/xray-cucumber.yaml @@ -15,15 +15,12 @@ # # SPDX-License-Identifier: Apache-2.0 -name: Trace-X Cucumber Xray execution +name: [BE][TEST][E2E] Cucumber on: workflow_dispatch: # Trigger manually - push: - branches: main - paths-ignore: - - '**/*.md' - - '**/*.txt' + schedule: + - cron: "0 0 * * *" jobs: build: From 35cfbe035d13c625ac3bd2a6b61015b5de7d2b97 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 30 Aug 2023 10:02:56 +0200 Subject: [PATCH 45/63] chore: TRACEFOSS-2607 rename workflows --- .github/workflows/kics.yml | 2 +- .github/workflows/publish-documentation.yaml | 2 +- .github/workflows/pull-request_backend.yml | 2 +- .github/workflows/quality-checks.yaml | 2 +- .github/workflows/release.yaml | 2 +- .github/workflows/sonar-scan-backend.yml | 2 +- .github/workflows/sonar-scan-frontend.yml | 2 +- .github/workflows/spotbugs.yml | 2 +- .github/workflows/trivy.yml | 2 +- .github/workflows/unit-test_frontend.yml | 2 +- .github/workflows/update-helm-environment.yml | 2 +- .github/workflows/veracode_backend.yml | 2 +- .github/workflows/veracode_frontend.yml | 2 +- .github/workflows/xray-cucumber.yaml | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/kics.yml b/.github/workflows/kics.yml index a82d2976b7..7b44295fd6 100644 --- a/.github/workflows/kics.yml +++ b/.github/workflows/kics.yml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: [BE][FE][SECURITY] Kics +name: "[BE][FE][SECURITY] Kics" on: push: diff --git a/.github/workflows/publish-documentation.yaml b/.github/workflows/publish-documentation.yaml index 9d2cfe7ec3..8231897098 100644 --- a/.github/workflows/publish-documentation.yaml +++ b/.github/workflows/publish-documentation.yaml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: [BE][FE][DOCUMENTATION] Publish documentation +name: "[BE][FE][DOCUMENTATION] Publish documentation" on: workflow_dispatch: # Trigger manually diff --git a/.github/workflows/pull-request_backend.yml b/.github/workflows/pull-request_backend.yml index e219e62d4c..988f79ab1b 100644 --- a/.github/workflows/pull-request_backend.yml +++ b/.github/workflows/pull-request_backend.yml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: [BE][BUILT][DEPLOYMENT] Pull request +name: "[BE][BUILT][DEPLOYMENT] Pull request" on: workflow_dispatch: # Trigger manually diff --git a/.github/workflows/quality-checks.yaml b/.github/workflows/quality-checks.yaml index 49ccded39a..cf898ba99f 100644 --- a/.github/workflows/quality-checks.yaml +++ b/.github/workflows/quality-checks.yaml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: [BE][FE][SECURITY] TRG Checks +name: "[BE][FE][SECURITY] TRG Checks" on: workflow_dispatch: # Trigger manually diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 30fca628c6..73c07e70dc 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,4 +1,4 @@ -name: [BE][FE] Release +name: "[BE][FE] Release" on: workflow_dispatch: diff --git a/.github/workflows/sonar-scan-backend.yml b/.github/workflows/sonar-scan-backend.yml index a005160774..aa831aec06 100644 --- a/.github/workflows/sonar-scan-backend.yml +++ b/.github/workflows/sonar-scan-backend.yml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: [BE][SECURITY] Sonar +name: "[BE][SECURITY] Sonar" on: workflow_dispatch: push: diff --git a/.github/workflows/sonar-scan-frontend.yml b/.github/workflows/sonar-scan-frontend.yml index db714381e2..7327df1dfd 100644 --- a/.github/workflows/sonar-scan-frontend.yml +++ b/.github/workflows/sonar-scan-frontend.yml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: [FE][SECURITY] Sonar +name: "[FE][SECURITY] Sonar" on: push: diff --git a/.github/workflows/spotbugs.yml b/.github/workflows/spotbugs.yml index b5a6d749b1..b9d6c0853d 100644 --- a/.github/workflows/spotbugs.yml +++ b/.github/workflows/spotbugs.yml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: [BE][SECURITY] Spotbugs +name: "[BE][SECURITY] Spotbugs" on: push: diff --git a/.github/workflows/trivy.yml b/.github/workflows/trivy.yml index 4841d87c8e..0ae07fbc2c 100644 --- a/.github/workflows/trivy.yml +++ b/.github/workflows/trivy.yml @@ -20,7 +20,7 @@ # separate terms of service, privacy policy, and support # documentation. -name: [BE][FE][SECURITY] Trivy +name: "[BE][FE][SECURITY] Trivy" on: pull_request: diff --git a/.github/workflows/unit-test_frontend.yml b/.github/workflows/unit-test_frontend.yml index b91f0db059..7ab37ffe3e 100644 --- a/.github/workflows/unit-test_frontend.yml +++ b/.github/workflows/unit-test_frontend.yml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: [FE][TEST] Unit Tests +name: "[FE][TEST] Unit Tests" on: push: diff --git a/.github/workflows/update-helm-environment.yml b/.github/workflows/update-helm-environment.yml index fba749ec75..d73722cd88 100644 --- a/.github/workflows/update-helm-environment.yml +++ b/.github/workflows/update-helm-environment.yml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: [BE][FE][DEPLOYMENT] Update helm environments branch +name: "[BE][FE][DEPLOYMENT] Update helm environments branch" on: push: branches: main diff --git a/.github/workflows/veracode_backend.yml b/.github/workflows/veracode_backend.yml index 9f945dfbc0..170f8a2e4e 100644 --- a/.github/workflows/veracode_backend.yml +++ b/.github/workflows/veracode_backend.yml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: [BE][SECURITY] Trivy +name: "[BE][SECURITY] Trivy" on: workflow_dispatch: diff --git a/.github/workflows/veracode_frontend.yml b/.github/workflows/veracode_frontend.yml index a22b55e690..f86ce05c00 100644 --- a/.github/workflows/veracode_frontend.yml +++ b/.github/workflows/veracode_frontend.yml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: [FE][SECURITY] Trivy +name: "[FE][SECURITY] Trivy" on: workflow_dispatch: diff --git a/.github/workflows/xray-cucumber.yaml b/.github/workflows/xray-cucumber.yaml index 173f214bb7..4a37e05913 100644 --- a/.github/workflows/xray-cucumber.yaml +++ b/.github/workflows/xray-cucumber.yaml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: [BE][TEST][E2E] Cucumber +name: "[BE][TEST][E2E] Cucumber" on: workflow_dispatch: # Trigger manually From ef2f6ad40fa0e1fe1981b396deaf6ca4d602bbdc Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 30 Aug 2023 10:12:10 +0200 Subject: [PATCH 46/63] chore: TRACEFOSS-2607 rename workflows --- .github/workflows/codeql.yml | 2 +- .github/workflows/dependencies.yaml | 2 +- .../workflows/docker-image-branch_frontend.yml | 2 +- .../workflows/docker-image-main_backend.yml | 2 +- .../workflows/docker-image-main_frontend.yml | 2 +- .../workflows/docker-image-tag-release.yaml | 2 +- .github/workflows/e2e-tests-xray_frontend.yml | 2 +- .github/workflows/eclipse-dash.yml | 2 +- .github/workflows/helm-chart-release.yaml | 2 +- .../helm-test-backwards-compatability.yaml | 2 +- .github/workflows/helm-test.yaml | 2 +- .github/workflows/helm-upgrade.yaml | 2 +- .github/workflows/jira-publish-release.yaml | 18 +++++++++++++++++- 13 files changed, 29 insertions(+), 13 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index ad0a4a331d..5a4826fab4 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -26,7 +26,7 @@ # the `language` matrix defined below to confirm you have the correct set of # supported CodeQL languages. # -name: "CodeQL code analysis" +name: "[BE][SECURITY] CodeQL" on: push: diff --git a/.github/workflows/dependencies.yaml b/.github/workflows/dependencies.yaml index 7fe8ec8c6b..1fb53fd4b8 100644 --- a/.github/workflows/dependencies.yaml +++ b/.github/workflows/dependencies.yaml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: "Dependencies Backend Update" +name: "[BE][FE][SECURITY] Update DEPENDENCIES files" on: push: diff --git a/.github/workflows/docker-image-branch_frontend.yml b/.github/workflows/docker-image-branch_frontend.yml index bc441f11b9..45cf8052d9 100644 --- a/.github/workflows/docker-image-branch_frontend.yml +++ b/.github/workflows/docker-image-branch_frontend.yml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: Frontend Build&Push Docker image for branch +name: "[FE][BUILT][RELEASE] Docker Image on Branch" on: pull_request: diff --git a/.github/workflows/docker-image-main_backend.yml b/.github/workflows/docker-image-main_backend.yml index f97a3d66c3..b03eba0fbc 100644 --- a/.github/workflows/docker-image-main_backend.yml +++ b/.github/workflows/docker-image-main_backend.yml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: Backend Build&Push Docker image on main +name: "[BE][BUILT][RELEASE] Docker Image on Main" on: push: diff --git a/.github/workflows/docker-image-main_frontend.yml b/.github/workflows/docker-image-main_frontend.yml index 211e1a7ad5..f4e6d48a9f 100644 --- a/.github/workflows/docker-image-main_frontend.yml +++ b/.github/workflows/docker-image-main_frontend.yml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: Frontend Build&Push Docker image on main +name: "[FE][BUILT][RELEASE] Docker Image on Main" on: push: diff --git a/.github/workflows/docker-image-tag-release.yaml b/.github/workflows/docker-image-tag-release.yaml index 4bcc63c2cb..e289fb118f 100644 --- a/.github/workflows/docker-image-tag-release.yaml +++ b/.github/workflows/docker-image-tag-release.yaml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: Release Frontend&Backend on Tag +name: "[BE][FE][RELEASE] Release Tag" on: workflow_dispatch: diff --git a/.github/workflows/e2e-tests-xray_frontend.yml b/.github/workflows/e2e-tests-xray_frontend.yml index 13806ca572..5660c897b6 100644 --- a/.github/workflows/e2e-tests-xray_frontend.yml +++ b/.github/workflows/e2e-tests-xray_frontend.yml @@ -18,7 +18,7 @@ # Require to set secrets: # - ORG_IRS_JIRA_USERNAME # - ORG_IRS_JIRA_PASSWORD -name: [FE][TEST][E2E]- Cypress +name: "[FE][TEST][E2E]- Cypress" on: # triggered manually by Test Manager diff --git a/.github/workflows/eclipse-dash.yml b/.github/workflows/eclipse-dash.yml index 8b44d20518..a54778f87f 100644 --- a/.github/workflows/eclipse-dash.yml +++ b/.github/workflows/eclipse-dash.yml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: "Eclipse DASH IP Check" +name: "[BE][FE][SECURITY] Eclipse DASH IP" on: workflow_dispatch: # Trigger manually diff --git a/.github/workflows/helm-chart-release.yaml b/.github/workflows/helm-chart-release.yaml index a0e9fc84e5..386ca48a17 100644 --- a/.github/workflows/helm-chart-release.yaml +++ b/.github/workflows/helm-chart-release.yaml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: Release Helm Charts +name: "[BE][FE][RELEASE][HELM] Release Helm Charts" on: workflow_dispatch: # Trigger manually diff --git a/.github/workflows/helm-test-backwards-compatability.yaml b/.github/workflows/helm-test-backwards-compatability.yaml index 01104f2dd0..1ae7981b74 100644 --- a/.github/workflows/helm-test-backwards-compatability.yaml +++ b/.github/workflows/helm-test-backwards-compatability.yaml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: Test k8s version compatability +name: "[BE][FE][HELM] Test Backward Compatability" on: workflow_dispatch: diff --git a/.github/workflows/helm-test.yaml b/.github/workflows/helm-test.yaml index b7189892d5..4a32703534 100644 --- a/.github/workflows/helm-test.yaml +++ b/.github/workflows/helm-test.yaml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: Lint and Test Charts +name: "[BE][FE][HELM] Lint and Test" on: pull_request: diff --git a/.github/workflows/helm-upgrade.yaml b/.github/workflows/helm-upgrade.yaml index 0f883f3cf9..16984190ad 100644 --- a/.github/workflows/helm-upgrade.yaml +++ b/.github/workflows/helm-upgrade.yaml @@ -15,7 +15,7 @@ # # SPDX-License-Identifier: Apache-2.0 -name: Upgrade Charts +name: "[BE][FE][HELM] Upgrade Charts" on: pull_request: diff --git a/.github/workflows/jira-publish-release.yaml b/.github/workflows/jira-publish-release.yaml index 3cc585ae81..04b6b06e34 100644 --- a/.github/workflows/jira-publish-release.yaml +++ b/.github/workflows/jira-publish-release.yaml @@ -1,4 +1,20 @@ -name: Jira release publishing +# Copyright (c) 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 +name: "[BE][FE][RELEASE] Jira release publishing" on: workflow_dispatch: # Trigger manually From 86aead3d32451cf5ef3616a4db8a2b4e6c7f5fac Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 30 Aug 2023 10:13:38 +0200 Subject: [PATCH 47/63] chore: TRACEFOSS-2607 rename workflows --- .github/workflows/quality-checks.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/quality-checks.yaml b/.github/workflows/quality-checks.yaml index cf898ba99f..c19990e4a2 100644 --- a/.github/workflows/quality-checks.yaml +++ b/.github/workflows/quality-checks.yaml @@ -22,9 +22,6 @@ on: push: branches: - main - pull_request: - branches: - - main jobs: check-quality: From 895a6377305f21a77860cb70a840dd697ac6b9d0 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 30 Aug 2023 10:38:01 +0200 Subject: [PATCH 48/63] chore: TRACEFOSS-2607 add response of shelldescriptor to tx-models --- .../application/DecentralRegistryService.java | 4 --- .../{rest => }/ShellDescriptorController.java | 28 +++++++++++++-- .../mapper/ShellDescriptorResponseMapper.java | 35 +++++++++++++++++++ .../ShellDescriptorResponse.java | 22 ++++++++++++ 4 files changed, 82 insertions(+), 7 deletions(-) rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/{rest => }/ShellDescriptorController.java (81%) create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/mapper/ShellDescriptorResponseMapper.java create mode 100644 tx-models/src/main/java/shelldescriptors/ShellDescriptorResponse.java diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/DecentralRegistryService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/DecentralRegistryService.java index 8406e83747..da2f647b5d 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/DecentralRegistryService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/DecentralRegistryService.java @@ -18,10 +18,6 @@ ********************************************************************************/ package org.eclipse.tractusx.traceability.shelldescriptor.application; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; - -import java.util.List; - public interface DecentralRegistryService { void updateShellDescriptorAndSynchronizeAssets(); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/rest/ShellDescriptorController.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/ShellDescriptorController.java similarity index 81% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/rest/ShellDescriptorController.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/ShellDescriptorController.java index fc29fc71d9..3c0028e2b2 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/rest/ShellDescriptorController.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/ShellDescriptorController.java @@ -1,4 +1,22 @@ -package org.eclipse.tractusx.traceability.shelldescriptor.application.rest; +/******************************************************************************** + * Copyright (c) 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.traceability.shelldescriptor.application; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; @@ -10,11 +28,15 @@ import lombok.RequiredArgsConstructor; import org.eclipse.tractusx.traceability.common.response.ErrorResponse; import org.eclipse.tractusx.traceability.shelldescriptor.application.ShellDescriptorService; +import org.eclipse.tractusx.traceability.shelldescriptor.application.mapper.ShellDescriptorResponseMapper; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import shelldescriptors.ShellDescriptorResponse; + +import java.util.List; @RestController @PreAuthorize("hasAnyRole('ROLE_ADMIN', 'ROLE_SUPERVISOR', 'ROLE_USER')") @@ -62,8 +84,8 @@ public class ShellDescriptorController { mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class)))}) @GetMapping() - public void findAll() { - shellDescriptorService.findAll(); + public List findAll() { + return ShellDescriptorResponseMapper.from(shellDescriptorService.findAll()); } @Operation(operationId = "deleteAll", diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/mapper/ShellDescriptorResponseMapper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/mapper/ShellDescriptorResponseMapper.java new file mode 100644 index 0000000000..e7d629d2ed --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/mapper/ShellDescriptorResponseMapper.java @@ -0,0 +1,35 @@ +/******************************************************************************** + * Copyright (c) 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.traceability.shelldescriptor.application.mapper; + +import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; +import shelldescriptors.ShellDescriptorResponse; + +import java.util.List; + +public class ShellDescriptorResponseMapper { + + public static ShellDescriptorResponse from(ShellDescriptor shellDescriptor) { + return new ShellDescriptorResponse(shellDescriptor.getId(), shellDescriptor.getGlobalAssetId()); + } + + public static List from(List shellDescriptors) { + return shellDescriptors.stream().map(ShellDescriptorResponseMapper::from).toList(); + } +} diff --git a/tx-models/src/main/java/shelldescriptors/ShellDescriptorResponse.java b/tx-models/src/main/java/shelldescriptors/ShellDescriptorResponse.java new file mode 100644 index 0000000000..31a505aa21 --- /dev/null +++ b/tx-models/src/main/java/shelldescriptors/ShellDescriptorResponse.java @@ -0,0 +1,22 @@ +/******************************************************************************** + * Copyright (c) 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 shelldescriptors; + +public record ShellDescriptorResponse(Long id, String globalAssetId) { +} From aa882d5b3488a306081adeba76f3203dfa643c9a Mon Sep 17 00:00:00 2001 From: Martin Maul Date: Wed, 30 Aug 2023 10:43:06 +0200 Subject: [PATCH 49/63] chore(automation):[TRACEFOSS-XXX] created release action to test --- docs/RELEASE.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/RELEASE.md b/docs/RELEASE.md index 0c59df3072..c533a59b6f 100644 --- a/docs/RELEASE.md +++ b/docs/RELEASE.md @@ -13,11 +13,12 @@ Please update the [CHANGELOG.md](https://github.com/eclipse-tractusx/traceabilit ## Release helm charts Hint: You need to stricly follow this guide to make sure the helm chart releaser will be able to detect a new helm chart version! 1) Create a GIT Tag with the release version of the application. -2) Afterwards update the properties in the Chart.yamls as described down below: - - Update helm charts *version* & *appVersion* property from +2) A Release Action ( Release Trace-X ) will bump the helm versions and create a Pull request that needs to be merged. +3) Check if the Action ran successfully and the following properties in the Chart.yamls and package.json were updated with the corresponding new versions from your created tag and the latest version entry from the [charts/CHANGELOG.md](https://github.com/catenax-ng/tx-traceability-foss/blob/main/charts/traceability-foss/CHANGELOG.md) file: + - *version* & *appVersion* property from - [backend Chart.yaml file](https://github.com/eclipse-tractusx/traceability-foss/blob/main/charts/traceability-foss/charts/backend/Chart.yaml) and from - [frontend Chart.yaml file](https://github.com/eclipse-tractusx/traceability-foss/blob/main/charts/traceability-foss/charts/frontend/Chart.yaml). - [Umbrella Helm Chart.yaml file](https://github.com/eclipse-tractusx/traceability-foss/blob/main/charts/traceability-foss/Chart.yaml). - + - [frontend package.json file](https://github.com/eclipse-tractusx/traceability-foss/blob/main/frontend/package.json) 3) Proceed with merging into the main branch and check the [Release Charts workflow](https://github.com/eclipse-tractusx/traceability-foss/actions/workflows/helm-chart-release.yaml) - It should trigger automatically, if not invoke the workflow manually for the *main* branch. The workflow will compare previously stored helm charts version and if it detects new version, it will release it in GitHub and will create an appropriate git tag. From c94d03d909e0067cebeaa807674d6eeb24f25ec3 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 30 Aug 2023 10:42:45 +0200 Subject: [PATCH 50/63] chore: TRACEFOSS-2607 add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff25bfe3c5..c116deb405 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Optional parameter "receiverBpn" to /investigations endpoint - NEW API /api/assets/as-planned - NEW API DELETE /api/registry +- NEW API GET /api/shelldescriptors ### Changed - API BREAKING CHANGE: /api/assets changed to /api/assets/as-built From 4c1e39a5795c417bbff412a343618eb1b2584cc6 Mon Sep 17 00:00:00 2001 From: Martin Maul Date: Wed, 30 Aug 2023 10:47:54 +0200 Subject: [PATCH 51/63] chore(automation):[TRACEFOSS-XXX] created release action to test --- charts/traceability-foss/CHANGELOG.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/charts/traceability-foss/CHANGELOG.md b/charts/traceability-foss/CHANGELOG.md index 7783746aee..fc55c84078 100644 --- a/charts/traceability-foss/CHANGELOG.md +++ b/charts/traceability-foss/CHANGELOG.md @@ -11,15 +11,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Changed -### Removed - -## [1.3.13] - 2023-08-22 -### Added -- THIS IS A TEST - -### Changed - - ### Removed ## [1.3.12] - 2023-08-22 From 744cf8fa84be5a58889b96164faba81472dbf1f2 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Wed, 30 Aug 2023 10:53:34 +0200 Subject: [PATCH 52/63] feature: TRACEFOSS-2391 test --- .github/workflows/pull-request_backend.yml | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/.github/workflows/pull-request_backend.yml b/.github/workflows/pull-request_backend.yml index 663567e3e7..d0b12f0770 100644 --- a/.github/workflows/pull-request_backend.yml +++ b/.github/workflows/pull-request_backend.yml @@ -27,7 +27,53 @@ env: DOCKER_HUB_REGISTRY_NAMESPACE: tractusx jobs: + Test-and-Sonar: + permissions: + checks: write + pull-requests: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + java-version: '${{ env.JAVA_VERSION }}' + distribution: 'temurin' + cache: 'maven' + + - name: Run unit & integration tests + run: mvn -pl tx-models,tx-backend,tx-coverage -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B verify + + - name: Publish integration test results + uses: EnricoMi/publish-unit-test-result-action@v2 + if: always() + with: + files: "/home/runner/work/tx-traceability-foss/tx-traceability-foss/tx-backend/target/failsafe-reports/TEST-*.xml" + check_name: "Integration Test Results" + + - name: Publish unit test results + uses: EnricoMi/publish-unit-test-result-action@v2 + if: always() + with: + files: "**/surefire-reports/TEST-*.xml" + check_name: "Unit Test Results" + + - name: Cache SonarCloud packages + uses: actions/cache@v3 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + + - name: Verify Sonar Scan + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_BACKEND }} + SONAR_ORGANIZATION: ${{ vars.SONAR_ORGANIZATION }} + SONAR_PROJECT_KEY: ${{ vars.SONAR_PROJECT_KEY_BACKEND }} + run: mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn --batch-mode sonar:sonar -Dsonar.coverage.jacoco.xmlReportPaths=/home/runner/work/tx-traceability-foss/tx-traceability-foss/tx-coverage/target/site/jacoco-aggregate/jacoco.xml -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY_BACKEND }} -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }} + Publish-docker-image: + needs: [ "Test-and-Sonar" ] runs-on: ubuntu-latest defaults: run: From 4916049112af94f4228face429f03226ca271658 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Wed, 30 Aug 2023 11:16:33 +0200 Subject: [PATCH 53/63] feature: TRACEFOSS-2391 test --- .../infrastructure/edc/blackbox/InvestigationsEDCFacade.java | 2 -- .../src/main/resources/application-integration-spring-boot.yml | 1 + tx-backend/src/main/resources/application-integration.yml | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index 006e3ca074..fde047c8cc 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -65,9 +65,7 @@ public class InvestigationsEDCFacade { private final EdcProperties edcProperties; - @Qualifier("testedc") private final EDCCatalogFacade edcCatalogFacade; - private final ContractNegotiationService contractNegotiationService; private final EndpointDataReferenceStorage endpointDataReferenceStorage; private final PolicyCheckerService policyCheckerService; diff --git a/tx-backend/src/main/resources/application-integration-spring-boot.yml b/tx-backend/src/main/resources/application-integration-spring-boot.yml index 851e2d962a..9d34abed42 100644 --- a/tx-backend/src/main/resources/application-integration-spring-boot.yml +++ b/tx-backend/src/main/resources/application-integration-spring-boot.yml @@ -72,6 +72,7 @@ logging: org.springframework: INFO digitalTwinRegistryClient: + oAuthClientId: keycloak discoveryFinderUrl: "" descriptorEndpoint: "" # required if type is "central", must contain the placeholder {aasIdentifier} diff --git a/tx-backend/src/main/resources/application-integration.yml b/tx-backend/src/main/resources/application-integration.yml index b061614e39..010b9c91e4 100644 --- a/tx-backend/src/main/resources/application-integration.yml +++ b/tx-backend/src/main/resources/application-integration.yml @@ -69,6 +69,7 @@ logging: org.springframework: INFO digitalTwinRegistryClient: + oAuthClientId: keycloak discoveryFinderUrl: "" descriptorEndpoint: "" # required if type is "central", must contain the placeholder {aasIdentifier} From 2baf27cc995930bc8e718074147362edea985251 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Wed, 30 Aug 2023 11:54:31 +0200 Subject: [PATCH 54/63] feature: TRACEFOSS-2391 coverage --- .../edc/blackbox/NoCatalogItemException.java | 2 +- .../edc/blackbox/BadRequestExceptionTest.java | 1 - .../ContractNegotiationExceptionTest.java | 49 ++++ .../blackbox/NoCatalogItemExceptionTest.java | 49 ++++ .../SendNotificationExceptionTest.java | 39 +++ .../service/EdcNotificationServiceTest.java | 222 ++++++++++++++++++ 6 files changed, 360 insertions(+), 2 deletions(-) create mode 100644 tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/ContractNegotiationExceptionTest.java create mode 100644 tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NoCatalogItemExceptionTest.java create mode 100644 tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/SendNotificationExceptionTest.java diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NoCatalogItemException.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NoCatalogItemException.java index 27c32133b0..bcd9070f7b 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NoCatalogItemException.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NoCatalogItemException.java @@ -20,7 +20,7 @@ package org.eclipse.tractusx.traceability.infrastructure.edc.blackbox; public class NoCatalogItemException extends RuntimeException{ - static final String MESSAGE = "No Catalog Item in catalog found."; + public static final String MESSAGE = "No Catalog Item in catalog found."; public NoCatalogItemException() { super(MESSAGE); } diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/BadRequestExceptionTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/BadRequestExceptionTest.java index 34bd35d46f..e3e6b5e8aa 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/BadRequestExceptionTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/BadRequestExceptionTest.java @@ -22,7 +22,6 @@ package org.eclipse.tractusx.traceability.infrastructure.edc.blackbox; -import lombok.val; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/ContractNegotiationExceptionTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/ContractNegotiationExceptionTest.java new file mode 100644 index 0000000000..7858f3015c --- /dev/null +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/ContractNegotiationExceptionTest.java @@ -0,0 +1,49 @@ +/******************************************************************************** + * Copyright (c) 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.traceability.infrastructure.edc.blackbox; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class ContractNegotiationExceptionTest { + + @Test + void givenContractNegotiationException_thenShouldHaveProperMessage() { + // given + final String message = "message"; + ContractNegotiationException exception = new ContractNegotiationException(message); + + // then + assertThat(exception.getMessage()).isEqualTo(message); + } + + @Test + void givenContractNegotiationExceptionWithThrowable_thenShouldHaveProperMessageAndThrowable() { + // given + final String message = "message"; + final Throwable exceptionParam = new RuntimeException("test"); + ContractNegotiationException exception = new ContractNegotiationException(message, exceptionParam); + + // then + assertThat(exception.getMessage()).isEqualTo(message); + assertThat(exception.getCause()).isEqualTo(exceptionParam); + } +} diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NoCatalogItemExceptionTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NoCatalogItemExceptionTest.java new file mode 100644 index 0000000000..d9c4bfbd23 --- /dev/null +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NoCatalogItemExceptionTest.java @@ -0,0 +1,49 @@ +/******************************************************************************** + * Copyright (c) 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.traceability.infrastructure.edc.blackbox; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class NoCatalogItemExceptionTest { + + @Test + void givenNoCatalogItemException_thenShouldHaveProperMessage() { + // given + final String message = NoCatalogItemException.MESSAGE; + NoCatalogItemException exception = new NoCatalogItemException(); + + // then + assertThat(exception.getMessage()).isEqualTo(message); + } + + @Test + void givenNoCatalogItemExceptionWithThrowable_thenShouldHaveProperMessageAndThrowable() { + // given + final String message = NoCatalogItemException.MESSAGE; + final Throwable exceptionParam = new RuntimeException("test"); + NoCatalogItemException exception = new NoCatalogItemException(exceptionParam); + + // then + assertThat(exception.getMessage()).isEqualTo(message); + assertThat(exception.getCause()).isEqualTo(exceptionParam); + } +} diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/SendNotificationExceptionTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/SendNotificationExceptionTest.java new file mode 100644 index 0000000000..e5cbab53c2 --- /dev/null +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/SendNotificationExceptionTest.java @@ -0,0 +1,39 @@ +/******************************************************************************** + * Copyright (c) 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.traceability.infrastructure.edc.blackbox; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class SendNotificationExceptionTest { + + @Test + void givenSendNotificationException_thenShouldHaveProperMessage() { + // given + final String message = "message"; + final Throwable exceptionParam = new RuntimeException("test"); + SendNotificationException exception = new SendNotificationException(message, exceptionParam); + + // then + assertThat(exception.getMessage()).isEqualTo(message); + assertThat(exception.getCause()).isEqualTo(exceptionParam); + } +} diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationServiceTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationServiceTest.java index 149a2b1f6c..c933478a20 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationServiceTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationServiceTest.java @@ -21,7 +21,11 @@ import org.eclipse.tractusx.traceability.discovery.domain.model.Discovery; import org.eclipse.tractusx.traceability.discovery.domain.service.DiscoveryService; +import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.ContractNegotiationException; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.InvestigationsEDCFacade; +import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.NoCatalogItemException; +import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.NoEndpointDataReferenceException; +import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.SendNotificationException; import org.eclipse.tractusx.traceability.qualitynotification.domain.alert.repository.AlertRepository; import org.eclipse.tractusx.traceability.qualitynotification.domain.investigation.repository.InvestigationRepository; import org.eclipse.tractusx.traceability.qualitynotification.domain.model.QualityNotificationMessage; @@ -38,6 +42,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; @@ -115,4 +120,221 @@ void testNotificationsServiceAlertNotificationUpdateAsync() { verify(alertRepository).updateQualityNotificationMessageEntity(notification); verifyNoInteractions(investigationRepository); } + + @Test + void givenNoCatalogItemException_whenHandleSendingInvestigation_thenHandleIt() { + // given + String bpn = "BPN1234"; + String edcReceiverUrl = "https://not-real-edc-receiver-url.com"; + String edcSenderUrl = "https://not-real-edc-sender-url.com"; + + Discovery discovery = Discovery.builder().senderUrl(edcSenderUrl).receiverUrls(List.of(edcReceiverUrl)).build(); + when(discoveryService.getDiscoveryByBPN(bpn)).thenReturn(discovery); + QualityNotificationMessage notification = QualityNotificationMessage.builder() + .receiverBpnNumber(bpn) + .type(QualityNotificationType.INVESTIGATION) + .targetDate(Instant.now()) + .severity(QualityNotificationSeverity.MINOR) + .isInitial(false) + .build(); + doThrow(new NoCatalogItemException()).when(edcFacade).startEdcTransferNew(notification, edcReceiverUrl, edcSenderUrl); + + // when + notificationsService.asyncNotificationExecutor(notification); + + // then + verify(edcFacade).startEdcTransferNew(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); + verifyNoInteractions(alertRepository); + verifyNoInteractions(investigationRepository); + } + + @Test + void givenSendNotificationException_whenHandleSendingInvestigation_thenHandleIt() { + // given + String bpn = "BPN1234"; + String edcReceiverUrl = "https://not-real-edc-receiver-url.com"; + String edcSenderUrl = "https://not-real-edc-sender-url.com"; + + Discovery discovery = Discovery.builder().senderUrl(edcSenderUrl).receiverUrls(List.of(edcReceiverUrl)).build(); + when(discoveryService.getDiscoveryByBPN(bpn)).thenReturn(discovery); + QualityNotificationMessage notification = QualityNotificationMessage.builder() + .receiverBpnNumber(bpn) + .type(QualityNotificationType.INVESTIGATION) + .targetDate(Instant.now()) + .severity(QualityNotificationSeverity.MINOR) + .isInitial(false) + .build(); + doThrow(new SendNotificationException("message",new RuntimeException())).when(edcFacade).startEdcTransferNew(notification, edcReceiverUrl, edcSenderUrl); + + // when + notificationsService.asyncNotificationExecutor(notification); + + // then + verify(edcFacade).startEdcTransferNew(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); + verifyNoInteractions(alertRepository); + verifyNoInteractions(investigationRepository); + } + + @Test + void givenSendNoEndpointDataReferenceException_whenHandleSendingInvestigation_thenHandleIt() { + // given + String bpn = "BPN1234"; + String edcReceiverUrl = "https://not-real-edc-receiver-url.com"; + String edcSenderUrl = "https://not-real-edc-sender-url.com"; + + Discovery discovery = Discovery.builder().senderUrl(edcSenderUrl).receiverUrls(List.of(edcReceiverUrl)).build(); + when(discoveryService.getDiscoveryByBPN(bpn)).thenReturn(discovery); + QualityNotificationMessage notification = QualityNotificationMessage.builder() + .receiverBpnNumber(bpn) + .type(QualityNotificationType.INVESTIGATION) + .targetDate(Instant.now()) + .severity(QualityNotificationSeverity.MINOR) + .isInitial(false) + .build(); + doThrow(new NoEndpointDataReferenceException("message")).when(edcFacade).startEdcTransferNew(notification, edcReceiverUrl, edcSenderUrl); + + // when + notificationsService.asyncNotificationExecutor(notification); + + // then + verify(edcFacade).startEdcTransferNew(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); + verifyNoInteractions(alertRepository); + verifyNoInteractions(investigationRepository); + } + + @Test + void givenContractNegotiationException_whenHandleSendingInvestigation_thenHandleIt() { + // given + String bpn = "BPN1234"; + String edcReceiverUrl = "https://not-real-edc-receiver-url.com"; + String edcSenderUrl = "https://not-real-edc-sender-url.com"; + + Discovery discovery = Discovery.builder().senderUrl(edcSenderUrl).receiverUrls(List.of(edcReceiverUrl)).build(); + when(discoveryService.getDiscoveryByBPN(bpn)).thenReturn(discovery); + QualityNotificationMessage notification = QualityNotificationMessage.builder() + .receiverBpnNumber(bpn) + .type(QualityNotificationType.INVESTIGATION) + .targetDate(Instant.now()) + .severity(QualityNotificationSeverity.MINOR) + .isInitial(false) + .build(); + doThrow(new ContractNegotiationException("message")).when(edcFacade).startEdcTransferNew(notification, edcReceiverUrl, edcSenderUrl); + + // when + notificationsService.asyncNotificationExecutor(notification); + + // then + verify(edcFacade).startEdcTransferNew(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); + verifyNoInteractions(alertRepository); + verifyNoInteractions(investigationRepository); + } + + + @Test + void givenNoCatalogItemException_whenHandleSendingAlert_thenHandleIt() { + // given + String bpn = "BPN1234"; + String edcReceiverUrl = "https://not-real-edc-receiver-url.com"; + String edcSenderUrl = "https://not-real-edc-sender-url.com"; + + Discovery discovery = Discovery.builder().senderUrl(edcSenderUrl).receiverUrls(List.of(edcReceiverUrl)).build(); + when(discoveryService.getDiscoveryByBPN(bpn)).thenReturn(discovery); + QualityNotificationMessage notification = QualityNotificationMessage.builder() + .receiverBpnNumber(bpn) + .type(QualityNotificationType.ALERT) + .targetDate(Instant.now()) + .severity(QualityNotificationSeverity.MINOR) + .isInitial(false) + .build(); + doThrow(new NoCatalogItemException()).when(edcFacade).startEdcTransferNew(notification, edcReceiverUrl, edcSenderUrl); + + // when + notificationsService.asyncNotificationExecutor(notification); + + // then + verify(edcFacade).startEdcTransferNew(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); + verifyNoInteractions(alertRepository); + verifyNoInteractions(investigationRepository); + } + + @Test + void givenSendNotificationException_whenHandleSendingAlert_thenHandleIt() { + // given + String bpn = "BPN1234"; + String edcReceiverUrl = "https://not-real-edc-receiver-url.com"; + String edcSenderUrl = "https://not-real-edc-sender-url.com"; + + Discovery discovery = Discovery.builder().senderUrl(edcSenderUrl).receiverUrls(List.of(edcReceiverUrl)).build(); + when(discoveryService.getDiscoveryByBPN(bpn)).thenReturn(discovery); + QualityNotificationMessage notification = QualityNotificationMessage.builder() + .receiverBpnNumber(bpn) + .type(QualityNotificationType.ALERT) + .targetDate(Instant.now()) + .severity(QualityNotificationSeverity.MINOR) + .isInitial(false) + .build(); + doThrow(new SendNotificationException("message",new RuntimeException())).when(edcFacade).startEdcTransferNew(notification, edcReceiverUrl, edcSenderUrl); + + // when + notificationsService.asyncNotificationExecutor(notification); + + // then + verify(edcFacade).startEdcTransferNew(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); + verifyNoInteractions(alertRepository); + verifyNoInteractions(investigationRepository); + } + + @Test + void givenSendNoEndpointDataReferenceException_whenHandleSendingAlert_thenHandleIt() { + // given + String bpn = "BPN1234"; + String edcReceiverUrl = "https://not-real-edc-receiver-url.com"; + String edcSenderUrl = "https://not-real-edc-sender-url.com"; + + Discovery discovery = Discovery.builder().senderUrl(edcSenderUrl).receiverUrls(List.of(edcReceiverUrl)).build(); + when(discoveryService.getDiscoveryByBPN(bpn)).thenReturn(discovery); + QualityNotificationMessage notification = QualityNotificationMessage.builder() + .receiverBpnNumber(bpn) + .type(QualityNotificationType.ALERT) + .targetDate(Instant.now()) + .severity(QualityNotificationSeverity.MINOR) + .isInitial(false) + .build(); + doThrow(new NoEndpointDataReferenceException("message")).when(edcFacade).startEdcTransferNew(notification, edcReceiverUrl, edcSenderUrl); + + // when + notificationsService.asyncNotificationExecutor(notification); + + // then + verify(edcFacade).startEdcTransferNew(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); + verifyNoInteractions(alertRepository); + verifyNoInteractions(investigationRepository); + } + + @Test + void givenContractNegotiationException_whenHandleSendingAlert_thenHandleIt() { + // given + String bpn = "BPN1234"; + String edcReceiverUrl = "https://not-real-edc-receiver-url.com"; + String edcSenderUrl = "https://not-real-edc-sender-url.com"; + + Discovery discovery = Discovery.builder().senderUrl(edcSenderUrl).receiverUrls(List.of(edcReceiverUrl)).build(); + when(discoveryService.getDiscoveryByBPN(bpn)).thenReturn(discovery); + QualityNotificationMessage notification = QualityNotificationMessage.builder() + .receiverBpnNumber(bpn) + .type(QualityNotificationType.ALERT) + .targetDate(Instant.now()) + .severity(QualityNotificationSeverity.MINOR) + .isInitial(false) + .build(); + doThrow(new ContractNegotiationException("message")).when(edcFacade).startEdcTransferNew(notification, edcReceiverUrl, edcSenderUrl); + + // when + notificationsService.asyncNotificationExecutor(notification); + + // then + verify(edcFacade).startEdcTransferNew(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); + verifyNoInteractions(alertRepository); + verifyNoInteractions(investigationRepository); + } } From 9dae428ab410e75a70a56d0a063076f074892e87 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Wed, 30 Aug 2023 12:26:04 +0200 Subject: [PATCH 55/63] feature: TRACEFOSS-2391 coverage --- .../edc/blackbox/InvestigationsEDCFacade.java | 1 - .../blackbox/InvestigationsEDCFacadeTest.java | 230 +++++------------- 2 files changed, 56 insertions(+), 175 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index fde047c8cc..8c80b9c8b3 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -43,7 +43,6 @@ import org.eclipse.tractusx.traceability.infrastructure.edc.properties.EdcProperties; import org.eclipse.tractusx.traceability.qualitynotification.domain.model.QualityNotificationMessage; import org.eclipse.tractusx.traceability.qualitynotification.domain.model.QualityNotificationType; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; import java.util.List; diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java index 08919a60b6..58469a2a51 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java @@ -20,14 +20,25 @@ import com.auth0.jwt.JWT; import com.auth0.jwt.algorithms.Algorithm; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import okhttp3.HttpUrl; import org.eclipse.edc.catalog.spi.Catalog; import org.eclipse.edc.catalog.spi.Dataset; +import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference; +import org.eclipse.tractusx.irs.edc.client.ContractNegotiationService; import org.eclipse.tractusx.irs.edc.client.EDCCatalogFacade; +import org.eclipse.tractusx.irs.edc.client.EndpointDataReferenceStorage; +import org.eclipse.tractusx.irs.edc.client.exceptions.ContractNegotiationException; +import org.eclipse.tractusx.irs.edc.client.exceptions.TransferProcessException; +import org.eclipse.tractusx.irs.edc.client.exceptions.UsagePolicyException; +import org.eclipse.tractusx.irs.edc.client.model.CatalogItem; +import org.eclipse.tractusx.irs.edc.client.model.NegotiationResponse; +import org.eclipse.tractusx.irs.edc.client.policy.PolicyCheckerService; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.configuration.JsonLdConfigurationTraceX; import org.eclipse.tractusx.traceability.infrastructure.edc.properties.EdcProperties; import org.eclipse.tractusx.traceability.qualitynotification.domain.model.QualityNotificationMessage; +import org.eclipse.tractusx.traceability.qualitynotification.domain.model.QualityNotificationStatus; import org.eclipse.tractusx.traceability.qualitynotification.domain.model.QualityNotificationType; import org.eclipse.tractusx.traceability.testdata.CatalogTestDataFactory; import org.eclipse.tractusx.traceability.testdata.NotificationTestDataFactory; @@ -42,6 +53,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Optional; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -53,187 +65,57 @@ @ExtendWith(MockitoExtension.class) class InvestigationsEDCFacadeTest { - @Mock HttpCallService httpCallService; - @Mock ObjectMapper objectMapper; - + @Mock + EdcProperties edcProperties; @Mock EDCCatalogFacade edcCatalogFacade; - @Mock - EdcProperties edcProperties; - + ContractNegotiationService contractNegotiationService; + @Mock + EndpointDataReferenceStorage endpointDataReferenceStorage; + @Mock + PolicyCheckerService policyCheckerService; + @Mock + EndpointDataReference endpointDataReference; @InjectMocks InvestigationsEDCFacade investigationsEDCFacade; -// -// @Test -// void test_startEDCTransfer() throws IOException, InterruptedException { -// //GIVEN -// String receiverEdcUrl = "https://example.com/receiver-edcUrl"; -// String senderEdcUrl = "https://example.com/sender-edcUrl"; -// -// QualityNotificationMessage qualityNotificationMessage = NotificationTestDataFactory -// .createNotificationTestData(QualityNotificationType.INVESTIGATION); -// -// when(edcProperties.getApiAuthKey()).thenReturn("x-api-key"); -// when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of()); -// -// Catalog catalog = CatalogTestDataFactory.createCatalogTestData(); -// when(edcService.getCatalog(anyString(), anyString(), any())).thenReturn(catalog); -// -// when(edcService.initializeContractNegotiation(anyString(), any(), anyString(), any())) -// .thenReturn("negotiationId"); -// -// Algorithm algorithm = Algorithm.HMAC256("Catena-X"); -// String jwtToken = JWT.create().withExpiresAt(Instant.now()).sign(algorithm); -// EndpointDataReference endpointDataReference = EndpointDataReference.Builder.newInstance() -// .endpoint("") -// .authCode(jwtToken) -// .authKey("authKey") -// .build(); -// when(endpointDataReferenceCache.get(anyString())).thenReturn(endpointDataReference); -// -// when(objectMapper.writeValueAsString(any())).thenReturn("someValidJson"); -// -// when(httpCallService.getUrl(any(), any(), any())).thenReturn(HttpUrl.get("https://w3id.org")); -// -// //WHEN -// investigationsEDCFacade.startEDCTransfer(qualityNotificationMessage, receiverEdcUrl, senderEdcUrl); -// -// //THEN -// verify(edcProperties).getApiAuthKey(); -// verify(edcService).getCatalog(anyString(), anyString(), any()); -// verify(edcService).initializeContractNegotiation(anyString(), any(), anyString(), any()); -// verify(endpointDataReferenceCache, times(2)).get(anyString()); -// verify(objectMapper).writeValueAsString(any()); -// verify(httpCallService).getUrl(any(), any(), any()); -// } -// -// @Test -// void test_startEDCTransfer_with_catalog_properties() throws IOException, InterruptedException { -// //GIVEN -// String receiverEdcUrl = "https://example.com/receiver-edcUrl"; -// String senderEdcUrl = "https://example.com/sender-edcUrl"; -// -// QualityNotificationMessage qualityNotificationMessage = NotificationTestDataFactory -// .createNotificationTestData(QualityNotificationType.INVESTIGATION); -// -// when(edcProperties.getApiAuthKey()).thenReturn("x-api-key"); -// when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of()); -// -// Map properties = Map.of(JsonLdConfigurationTraceX.NAMESPACE_EDC_PARTICIPANT_ID, "participantId"); -// Catalog catalog = CatalogTestDataFactory.createCatalogTestData(properties); -// when(edcService.getCatalog(anyString(), anyString(), any())).thenReturn(catalog); -// -// when(edcService.initializeContractNegotiation(anyString(), any(), anyString(), any())) -// .thenReturn("negotiationId"); -// -// Algorithm algorithm = Algorithm.HMAC256("Catena-X"); -// String jwtToken = JWT.create().withExpiresAt(Instant.now()).sign(algorithm); -// EndpointDataReference endpointDataReference = EndpointDataReference.Builder.newInstance() -// .endpoint("") -// .authCode(jwtToken) -// .authKey("authKey") -// .build(); -// when(endpointDataReferenceCache.get(anyString())).thenReturn(endpointDataReference); -// -// when(objectMapper.writeValueAsString(any())).thenReturn("someValidJson"); -// -// when(httpCallService.getUrl(any(), any(), any())).thenReturn(HttpUrl.get("https://w3id.org")); -// -// //WHEN -// investigationsEDCFacade.startEDCTransfer(qualityNotificationMessage, receiverEdcUrl, senderEdcUrl); -// -// //THEN -// verify(edcProperties).getApiAuthKey(); -// verify(edcService).getCatalog(anyString(), anyString(), any()); -// verify(edcService).initializeContractNegotiation(anyString(), any(), anyString(), any()); -// verify(endpointDataReferenceCache, times(2)).get(anyString()); -// verify(objectMapper).writeValueAsString(any()); -// verify(httpCallService).getUrl(any(), any(), any()); -// } -// -// @Test -// void test_startEDCTransfer_throws_BadRequestException() throws IOException { -// //GIVEN -// String receiverEdcUrl = "https://example.com/receiver-edcUrl"; -// String senderEdcUrl = "https://example.com/sender-edcUrl"; -// -// QualityNotificationMessage qualityNotificationMessage = NotificationTestDataFactory -// .createNotificationTestData(QualityNotificationType.INVESTIGATION); -// -// when(edcProperties.getApiAuthKey()).thenReturn("x-api-key"); -// when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of()); -// -// Catalog catalog = Catalog.Builder.newInstance().datasets(Collections.emptyList()).build(); -// when(edcService.getCatalog(anyString(), anyString(), any())).thenReturn(catalog); -// -// //WHEN -// BadRequestException badRequestException = assertThrows( -// BadRequestException.class, -// () -> investigationsEDCFacade.startEDCTransfer(qualityNotificationMessage, receiverEdcUrl, senderEdcUrl)); -// -// //THEN -// verify(edcProperties).getApiAuthKey(); -// verify(edcService).getCatalog(anyString(), anyString(), any()); -// assertEquals("The dataset from the catalog is empty.", badRequestException.getMessage()); -// } -// -// @Test -// void test_startEDCTransfer_throws_BadRequestException_when_catalogItem_isEmpty() throws IOException { -// //GIVEN -// String receiverEdcUrl = "https://example.com/receiver-edcUrl"; -// String senderEdcUrl = "https://example.com/sender-edcUrl"; -// -// QualityNotificationMessage qualityNotificationMessage = NotificationTestDataFactory -// .createNotificationTestData(QualityNotificationType.INVESTIGATION); -// -// when(edcProperties.getApiAuthKey()).thenReturn("x-api-key"); -// when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of()); -// -// Dataset.Builder datasetBuilder = Dataset.Builder.newInstance() -// .property("https://w3id.org/edc/v0.0.1/ns/notificationtype", "invalidNotificationType") -// .property("https://w3id.org/edc/v0.0.1/ns/notificationmethod", "invalidNotificationMethod") -// .property("https://w3id.org/edc/v0.0.1/ns/id", "id"); -// -// Catalog catalog = CatalogTestDataFactory.createCatalogTestData(datasetBuilder); -// when(edcService.getCatalog(anyString(), anyString(), any())).thenReturn(catalog); -// -// //WHEN -// NoCatalogItemException badRequestException = assertThrows(NoCatalogItemException.class, -// () -> investigationsEDCFacade.startEDCTransfer(qualityNotificationMessage, receiverEdcUrl, senderEdcUrl)); -// -// //THEN -// verify(edcProperties).getApiAuthKey(); -// verify(edcService).getCatalog(anyString(), anyString(), any()); -// assertEquals("No Catalog Item in catalog found.", badRequestException.getMessage()); -// -// } -// -// @Test -// void test_startEDCTransfer_throws_BadRequestException_when_IOException_is_thrown() throws IOException { -// //GIVEN -// String receiverEdcUrl = "https://example.com/receiver-edcUrl"; -// String senderEdcUrl = "https://example.com/sender-edcUrl"; -// -// QualityNotificationMessage qualityNotificationMessage = NotificationTestDataFactory -// .createNotificationTestData(QualityNotificationType.INVESTIGATION); -// -// when(edcProperties.getApiAuthKey()).thenReturn("x-api-key"); -// when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of()); -// -// when(edcService.getCatalog(anyString(), anyString(), any())).thenThrow(IOException.class); -// -// //WHEN -// BadRequestException badRequestException = assertThrows(BadRequestException.class, -// () -> investigationsEDCFacade.startEDCTransfer(qualityNotificationMessage, receiverEdcUrl, senderEdcUrl)); -// -// //THEN -// verify(edcProperties).getApiAuthKey(); -// verify(edcService).getCatalog(anyString(), anyString(), any()); -// assertEquals("EDC Data Transfer fail.", badRequestException.getMessage()); -// } + + @Test + void givenCorrectInvestigationMessage_whenStartEdcTransferNew_thenSendIt() throws TransferProcessException, UsagePolicyException, ContractNegotiationException, IOException { + // given + final String receiverEdcUrl = "https://receiver.com"; + final String senderEdcUrl = "https://sender.com"; + final String agreementId = "negotiationId"; + final String dataReferenceEndpoint = "https://endpoint.com"; + final QualityNotificationMessage notificationMessage = QualityNotificationMessage.builder() + .type(QualityNotificationType.INVESTIGATION) + .notificationStatus(QualityNotificationStatus.CREATED) + .isInitial(true) + .build(); + final CatalogItem catalogItem = CatalogItem.builder() + .build(); + final String idsPath = "/api/v1/dsp"; + when(edcProperties.getIdsPath()).thenReturn(idsPath); + when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of(catalogItem)); + when(policyCheckerService.isValid(null)).thenReturn(true); + when(contractNegotiationService.negotiate(receiverEdcUrl + idsPath, catalogItem)) + .thenReturn(NegotiationResponse.builder().contractAgreementId(agreementId).build()); + when(endpointDataReference.getEndpoint()).thenReturn("endpoint"); + when(endpointDataReference.getAuthCode()).thenReturn("authCode"); + when(endpointDataReference.getAuthKey()).thenReturn("authKey"); + when(endpointDataReference.getEndpoint()).thenReturn(dataReferenceEndpoint); + when(httpCallService.getUrl(dataReferenceEndpoint, null, null)).thenReturn(HttpUrl.parse(dataReferenceEndpoint)); + when(endpointDataReferenceStorage.remove(agreementId)).thenReturn(Optional.ofNullable(endpointDataReference)); + when(objectMapper.writeValueAsString(any())).thenReturn("{body}"); + + // when + investigationsEDCFacade.startEdcTransferNew(notificationMessage, receiverEdcUrl, senderEdcUrl); + + // then + verify(httpCallService).sendRequest(any()); + } } From b113701ada541ba82811d08bc9c426e0572e6fe1 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Wed, 30 Aug 2023 12:39:05 +0200 Subject: [PATCH 56/63] feature: TRACEFOSS-2391 coverage --- .../edc/blackbox/InvestigationsEDCFacade.java | 4 +- .../blackbox/InvestigationsEDCFacadeTest.java | 89 ++++++++++++++++--- 2 files changed, 77 insertions(+), 16 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index 8c80b9c8b3..6e5ccd61fe 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -100,7 +100,7 @@ public void startEdcTransferNew( private String negotiateContractAgreement(final String receiverEdcUrl, final CatalogItem catalogItem) { try { return Optional.ofNullable(contractNegotiationService.negotiate(receiverEdcUrl + edcProperties.getIdsPath(), catalogItem)) - .orElseThrow(() -> new ContractNegotiationException("Failed to negotiate contract agreement. Negotiation response is null")) + .orElseThrow() .getContractAgreementId(); } catch (Exception e) { throw new ContractNegotiationException("Failed to negotiate contract agreement. ", e); @@ -125,7 +125,7 @@ private CatalogItem getCatalogItem(final QualityNotificationMessage notification ).stream() .filter(catalogItem -> policyCheckerService.isValid(catalogItem.getPolicy())) .findFirst() - .orElseThrow(NoCatalogItemException::new); + .orElseThrow(); } catch (Exception e) { log.error("Exception was thrown while requesting catalog items from Lib", e); throw new NoCatalogItemException(e); diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java index 58469a2a51..6ee5d2a5cd 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java @@ -18,13 +18,8 @@ ********************************************************************************/ package org.eclipse.tractusx.traceability.infrastructure.edc.blackbox; -import com.auth0.jwt.JWT; -import com.auth0.jwt.algorithms.Algorithm; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import okhttp3.HttpUrl; -import org.eclipse.edc.catalog.spi.Catalog; -import org.eclipse.edc.catalog.spi.Dataset; import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference; import org.eclipse.tractusx.irs.edc.client.ContractNegotiationService; import org.eclipse.tractusx.irs.edc.client.EDCCatalogFacade; @@ -35,13 +30,10 @@ import org.eclipse.tractusx.irs.edc.client.model.CatalogItem; import org.eclipse.tractusx.irs.edc.client.model.NegotiationResponse; import org.eclipse.tractusx.irs.edc.client.policy.PolicyCheckerService; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.configuration.JsonLdConfigurationTraceX; import org.eclipse.tractusx.traceability.infrastructure.edc.properties.EdcProperties; import org.eclipse.tractusx.traceability.qualitynotification.domain.model.QualityNotificationMessage; import org.eclipse.tractusx.traceability.qualitynotification.domain.model.QualityNotificationStatus; import org.eclipse.tractusx.traceability.qualitynotification.domain.model.QualityNotificationType; -import org.eclipse.tractusx.traceability.testdata.CatalogTestDataFactory; -import org.eclipse.tractusx.traceability.testdata.NotificationTestDataFactory; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -49,17 +41,12 @@ import org.mockito.junit.jupiter.MockitoExtension; import java.io.IOException; -import java.time.Instant; -import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.Optional; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.times; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -118,4 +105,78 @@ void givenCorrectInvestigationMessage_whenStartEdcTransferNew_thenSendIt() throw // then verify(httpCallService).sendRequest(any()); } + + @Test + void givenCorrectInvestigationMessageButSendRequestThrowsException_whenStartEdcTransferNew_thenThrowSendNotificationException() throws TransferProcessException, UsagePolicyException, ContractNegotiationException, IOException { + // given + final String receiverEdcUrl = "https://receiver.com"; + final String senderEdcUrl = "https://sender.com"; + final String agreementId = "negotiationId"; + final String dataReferenceEndpoint = "https://endpoint.com"; + final QualityNotificationMessage notificationMessage = QualityNotificationMessage.builder() + .type(QualityNotificationType.INVESTIGATION) + .notificationStatus(QualityNotificationStatus.CREATED) + .isInitial(true) + .build(); + final CatalogItem catalogItem = CatalogItem.builder() + .build(); + final String idsPath = "/api/v1/dsp"; + when(edcProperties.getIdsPath()).thenReturn(idsPath); + when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of(catalogItem)); + when(policyCheckerService.isValid(null)).thenReturn(true); + when(contractNegotiationService.negotiate(receiverEdcUrl + idsPath, catalogItem)) + .thenReturn(NegotiationResponse.builder().contractAgreementId(agreementId).build()); + when(endpointDataReference.getEndpoint()).thenReturn("endpoint"); + when(endpointDataReference.getAuthCode()).thenReturn("authCode"); + when(endpointDataReference.getAuthKey()).thenReturn("authKey"); + when(endpointDataReference.getEndpoint()).thenReturn(dataReferenceEndpoint); + when(httpCallService.getUrl(dataReferenceEndpoint, null, null)).thenReturn(HttpUrl.parse(dataReferenceEndpoint)); + when(endpointDataReferenceStorage.remove(agreementId)).thenReturn(Optional.ofNullable(endpointDataReference)); + when(objectMapper.writeValueAsString(any())).thenReturn("{body}"); + doThrow(new RuntimeException()).when(httpCallService).sendRequest(any()); + + // when/then + assertThrows(SendNotificationException.class, () -> investigationsEDCFacade.startEdcTransferNew(notificationMessage, receiverEdcUrl, senderEdcUrl)); + } + + @Test + void givenCorrectInvestigationMessageButNegotiateContractAgreementHasNoCatalogItem_whenStartEdcTransferNew_thenThrowContractNegotiationException() throws TransferProcessException, UsagePolicyException, ContractNegotiationException, IOException { + // given + final String receiverEdcUrl = "https://receiver.com"; + final String senderEdcUrl = "https://sender.com"; + final QualityNotificationMessage notificationMessage = QualityNotificationMessage.builder() + .type(QualityNotificationType.INVESTIGATION) + .notificationStatus(QualityNotificationStatus.CREATED) + .isInitial(true) + .build(); + final CatalogItem catalogItem = CatalogItem.builder() + .build(); + final String idsPath = "/api/v1/dsp"; + when(edcProperties.getIdsPath()).thenReturn(idsPath); + when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of(catalogItem)); + when(policyCheckerService.isValid(null)).thenReturn(true); + when(contractNegotiationService.negotiate(receiverEdcUrl + idsPath, catalogItem)) + .thenReturn(null); + + // when/then + assertThrows(ContractNegotiationException.class, () -> investigationsEDCFacade.startEdcTransferNew(notificationMessage, receiverEdcUrl, senderEdcUrl)); + } + + @Test + void givenCorrectInvestigationMessageButCatalogItem_whenStartEdcTransferNew_thenThrowSendNotificationException() throws TransferProcessException, UsagePolicyException, ContractNegotiationException, IOException { + // given + final String receiverEdcUrl = "https://receiver.com"; + final String senderEdcUrl = "https://sender.com"; + final QualityNotificationMessage notificationMessage = QualityNotificationMessage.builder() + .type(QualityNotificationType.INVESTIGATION) + .notificationStatus(QualityNotificationStatus.CREATED) + .isInitial(true) + .build(); + final String idsPath = "/api/v1/dsp"; + when(edcProperties.getIdsPath()).thenReturn(idsPath); + when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of()); + + // when/then + assertThrows(NoCatalogItemException.class, () -> investigationsEDCFacade.startEdcTransferNew(notificationMessage, receiverEdcUrl, senderEdcUrl)); + } } From 8a46b9fb56d732d72d8a94dfa84d46878ed3a144 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Wed, 30 Aug 2023 12:46:44 +0200 Subject: [PATCH 57/63] feature: TRACEFOSS-2391 coverage --- .../edc/blackbox/InvestigationsEDCFacadeTest.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java index 6ee5d2a5cd..c716874217 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java @@ -24,9 +24,6 @@ import org.eclipse.tractusx.irs.edc.client.ContractNegotiationService; import org.eclipse.tractusx.irs.edc.client.EDCCatalogFacade; import org.eclipse.tractusx.irs.edc.client.EndpointDataReferenceStorage; -import org.eclipse.tractusx.irs.edc.client.exceptions.ContractNegotiationException; -import org.eclipse.tractusx.irs.edc.client.exceptions.TransferProcessException; -import org.eclipse.tractusx.irs.edc.client.exceptions.UsagePolicyException; import org.eclipse.tractusx.irs.edc.client.model.CatalogItem; import org.eclipse.tractusx.irs.edc.client.model.NegotiationResponse; import org.eclipse.tractusx.irs.edc.client.policy.PolicyCheckerService; @@ -40,7 +37,6 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import java.io.IOException; import java.util.List; import java.util.Optional; @@ -72,7 +68,7 @@ class InvestigationsEDCFacadeTest { InvestigationsEDCFacade investigationsEDCFacade; @Test - void givenCorrectInvestigationMessage_whenStartEdcTransferNew_thenSendIt() throws TransferProcessException, UsagePolicyException, ContractNegotiationException, IOException { + void givenCorrectInvestigationMessage_whenStartEdcTransferNew_thenSendIt() throws Exception { // given final String receiverEdcUrl = "https://receiver.com"; final String senderEdcUrl = "https://sender.com"; @@ -107,7 +103,7 @@ void givenCorrectInvestigationMessage_whenStartEdcTransferNew_thenSendIt() throw } @Test - void givenCorrectInvestigationMessageButSendRequestThrowsException_whenStartEdcTransferNew_thenThrowSendNotificationException() throws TransferProcessException, UsagePolicyException, ContractNegotiationException, IOException { + void givenCorrectInvestigationMessageButSendRequestThrowsException_whenStartEdcTransferNew_thenThrowSendNotificationException() throws Exception { // given final String receiverEdcUrl = "https://receiver.com"; final String senderEdcUrl = "https://sender.com"; @@ -140,7 +136,7 @@ void givenCorrectInvestigationMessageButSendRequestThrowsException_whenStartEdcT } @Test - void givenCorrectInvestigationMessageButNegotiateContractAgreementHasNoCatalogItem_whenStartEdcTransferNew_thenThrowContractNegotiationException() throws TransferProcessException, UsagePolicyException, ContractNegotiationException, IOException { + void givenCorrectInvestigationMessageButNegotiateContractAgreementHasNoCatalogItem_whenStartEdcTransferNew_thenThrowContractNegotiationException() throws Exception { // given final String receiverEdcUrl = "https://receiver.com"; final String senderEdcUrl = "https://sender.com"; @@ -163,7 +159,7 @@ void givenCorrectInvestigationMessageButNegotiateContractAgreementHasNoCatalogIt } @Test - void givenCorrectInvestigationMessageButCatalogItem_whenStartEdcTransferNew_thenThrowSendNotificationException() throws TransferProcessException, UsagePolicyException, ContractNegotiationException, IOException { + void givenCorrectInvestigationMessageButCatalogItem_whenStartEdcTransferNew_thenThrowSendNotificationException() { // given final String receiverEdcUrl = "https://receiver.com"; final String senderEdcUrl = "https://sender.com"; From b0124fa6c2ea194802a6ea7bc555dd81f83ba506 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 30 Aug 2023 13:01:37 +0200 Subject: [PATCH 58/63] chore: TRACEFOSS-1731 adapt api response to include detailSemanticModel --- .../mapper/AssetAsBuiltResponseMapper.java | 3 +- .../asbuilt/rest/AssetAsBuiltController.java | 3 +- .../mapper/AssetAsPlannedResponseMapper.java | 14 ++++++- .../rest/AssetAsPlannedController.java | 5 +-- .../base/mapper/AssetBaseResponseMapper.java | 37 ++++++++++++++++++- .../base/request/QualityTypeRequest.java | 2 +- .../response/DescriptionsResponseTest.java | 2 +- .../test/TraceabilityTestStepDefinition.java | 2 +- .../test/tooling/rest/RestProvider.java | 2 +- .../{ => asbuilt}/AssetAsBuiltResponse.java | 3 +- .../AssetAsPlannedResponse.java | 3 +- .../{ => base}/AssetBaseResponse.java | 22 ++++++++++- .../{ => base}/DescriptionsResponse.java | 2 +- .../base/DetailAspectDataResponse.java | 26 +++++++++++++ .../base/DetailAspectModelResponse.java | 30 +++++++++++++++ .../base/DetailAspectTypeResponse.java | 34 +++++++++++++++++ .../response/{ => base}/OwnerResponse.java | 2 +- .../PartSiteInformationAsPlannedResponse.java | 19 ++++++++++ .../{ => base}/QualityTypeResponse.java | 2 +- .../{ => base}/SemanticDataModelResponse.java | 2 +- .../{ => base}/SemanticModelResponse.java | 2 +- 21 files changed, 195 insertions(+), 22 deletions(-) rename tx-models/src/main/java/assets/response/{ => asbuilt}/AssetAsBuiltResponse.java (94%) rename tx-models/src/main/java/assets/response/{ => asplanned}/AssetAsPlannedResponse.java (94%) rename tx-models/src/main/java/assets/response/{ => base}/AssetBaseResponse.java (66%) rename tx-models/src/main/java/assets/response/{ => base}/DescriptionsResponse.java (97%) create mode 100644 tx-models/src/main/java/assets/response/base/DetailAspectDataResponse.java create mode 100644 tx-models/src/main/java/assets/response/base/DetailAspectModelResponse.java create mode 100644 tx-models/src/main/java/assets/response/base/DetailAspectTypeResponse.java rename tx-models/src/main/java/assets/response/{ => base}/OwnerResponse.java (97%) create mode 100644 tx-models/src/main/java/assets/response/base/PartSiteInformationAsPlannedResponse.java rename tx-models/src/main/java/assets/response/{ => base}/QualityTypeResponse.java (98%) rename tx-models/src/main/java/assets/response/{ => base}/SemanticDataModelResponse.java (97%) rename tx-models/src/main/java/assets/response/{ => base}/SemanticModelResponse.java (98%) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltResponseMapper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltResponseMapper.java index a07506a0ba..79edcea720 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltResponseMapper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltResponseMapper.java @@ -18,7 +18,7 @@ ********************************************************************************/ package org.eclipse.tractusx.traceability.assets.application.asbuilt.mapper; -import assets.response.AssetAsBuiltResponse; +import assets.response.asbuilt.AssetAsBuiltResponse; import org.eclipse.tractusx.traceability.assets.application.base.mapper.AssetBaseResponseMapper; import org.eclipse.tractusx.traceability.assets.domain.base.model.AssetBase; import org.eclipse.tractusx.traceability.common.model.PageResult; @@ -52,6 +52,7 @@ public static AssetAsBuiltResponse from(final AssetBase asset) { ) .van(asset.getVan()) .semanticDataModel(from(asset.getSemanticDataModel())) + .detailAspectModels(fromList(asset.getDetailAspectModels())) .build(); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/rest/AssetAsBuiltController.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/rest/AssetAsBuiltController.java index 250ab20b24..0a46297bc6 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/rest/AssetAsBuiltController.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/rest/AssetAsBuiltController.java @@ -21,7 +21,7 @@ package org.eclipse.tractusx.traceability.assets.application.asbuilt.rest; -import assets.response.AssetAsBuiltResponse; +import assets.response.asbuilt.AssetAsBuiltResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; @@ -32,7 +32,6 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import jakarta.ws.rs.QueryParam; -import lombok.RequiredArgsConstructor; import org.eclipse.tractusx.traceability.assets.application.asbuilt.mapper.AssetAsBuiltResponseMapper; import org.eclipse.tractusx.traceability.assets.application.base.request.GetDetailInformationRequest; import org.eclipse.tractusx.traceability.assets.application.base.request.SyncAssetsRequest; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asplanned/mapper/AssetAsPlannedResponseMapper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asplanned/mapper/AssetAsPlannedResponseMapper.java index 033554e34d..5d26f30096 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asplanned/mapper/AssetAsPlannedResponseMapper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asplanned/mapper/AssetAsPlannedResponseMapper.java @@ -18,10 +18,17 @@ ********************************************************************************/ package org.eclipse.tractusx.traceability.assets.application.asplanned.mapper; -import assets.response.AssetAsBuiltResponse; -import assets.response.AssetAsPlannedResponse; +import assets.response.asplanned.AssetAsPlannedResponse; +import assets.response.base.DetailAspectDataResponse; +import assets.response.base.DetailAspectModelResponse; +import assets.response.base.DetailAspectTypeResponse; +import assets.response.base.PartSiteInformationAsPlannedResponse; import org.eclipse.tractusx.traceability.assets.application.base.mapper.AssetBaseResponseMapper; +import org.eclipse.tractusx.traceability.assets.domain.asplanned.model.aspect.PartSiteInformationAsPlanned; import org.eclipse.tractusx.traceability.assets.domain.base.model.AssetBase; +import org.eclipse.tractusx.traceability.assets.domain.base.model.aspect.DetailAspectData; +import org.eclipse.tractusx.traceability.assets.domain.base.model.aspect.DetailAspectModel; +import org.eclipse.tractusx.traceability.assets.domain.base.model.aspect.DetailAspectType; import org.eclipse.tractusx.traceability.common.model.PageResult; import java.util.List; @@ -53,9 +60,12 @@ public static AssetAsPlannedResponse from(final AssetBase asset) { ) .van(asset.getVan()) .semanticDataModel(from(asset.getSemanticDataModel())) + .detailAspectModels(fromList(asset.getDetailAspectModels())) .build(); } + + public static PageResult from(final PageResult assetPageResult) { return new PageResult<>( assetPageResult.content().stream() diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asplanned/rest/AssetAsPlannedController.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asplanned/rest/AssetAsPlannedController.java index 0a685e553c..4156c7d4fe 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asplanned/rest/AssetAsPlannedController.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asplanned/rest/AssetAsPlannedController.java @@ -19,8 +19,8 @@ package org.eclipse.tractusx.traceability.assets.application.asplanned.rest; -import assets.response.AssetAsBuiltResponse; -import assets.response.AssetAsPlannedResponse; +import assets.response.asbuilt.AssetAsBuiltResponse; +import assets.response.asplanned.AssetAsPlannedResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; @@ -31,7 +31,6 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import jakarta.ws.rs.QueryParam; -import lombok.RequiredArgsConstructor; import org.eclipse.tractusx.traceability.assets.application.asplanned.mapper.AssetAsPlannedResponseMapper; import org.eclipse.tractusx.traceability.assets.application.base.request.GetDetailInformationRequest; import org.eclipse.tractusx.traceability.assets.application.base.request.SyncAssetsRequest; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/base/mapper/AssetBaseResponseMapper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/base/mapper/AssetBaseResponseMapper.java index accc20b6cf..8e91a08a68 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/base/mapper/AssetBaseResponseMapper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/base/mapper/AssetBaseResponseMapper.java @@ -18,11 +18,18 @@ ********************************************************************************/ package org.eclipse.tractusx.traceability.assets.application.base.mapper; -import assets.response.*; +import assets.response.base.*; import lombok.AllArgsConstructor; import lombok.Data; import lombok.experimental.SuperBuilder; +import org.eclipse.tractusx.traceability.assets.application.asplanned.mapper.AssetAsPlannedResponseMapper; +import org.eclipse.tractusx.traceability.assets.domain.asplanned.model.aspect.PartSiteInformationAsPlanned; import org.eclipse.tractusx.traceability.assets.domain.base.model.*; +import org.eclipse.tractusx.traceability.assets.domain.base.model.aspect.DetailAspectData; +import org.eclipse.tractusx.traceability.assets.domain.base.model.aspect.DetailAspectModel; +import org.eclipse.tractusx.traceability.assets.domain.base.model.aspect.DetailAspectType; + +import java.util.List; @AllArgsConstructor @Data @@ -39,6 +46,34 @@ public static SemanticModelResponse from(final SemanticModel semanticModel) { .build(); } + public static List fromList(List detailAspectModels) { + return detailAspectModels.stream() + .map(AssetAsPlannedResponseMapper::from) + .toList(); + } + + public static DetailAspectModelResponse from(DetailAspectModel detailAspectModel) { + return DetailAspectModelResponse.builder() + .type(from(detailAspectModel.getType())) + .data(from(detailAspectModel.getData())) + .build(); + } + + public static DetailAspectTypeResponse from(DetailAspectType detailAspectType) { + return DetailAspectTypeResponse.valueOf(detailAspectType.name()); + } + + public static DetailAspectDataResponse from(DetailAspectData detailAspectData) { + if (detailAspectData instanceof PartSiteInformationAsPlanned partSiteInformationAsPlanned) { + return PartSiteInformationAsPlannedResponse.builder().catenaXSiteId(partSiteInformationAsPlanned.getCatenaXSiteId()) + .function(partSiteInformationAsPlanned.getFunction()) + .functionValidFrom(partSiteInformationAsPlanned.getFunctionValidFrom()) + .functionValidUntil(partSiteInformationAsPlanned.getFunctionValidUntil()) + .build(); + } else { + return null; + } + } public static OwnerResponse from(final Owner owner) { return OwnerResponse.valueOf(owner.name()); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/base/request/QualityTypeRequest.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/base/request/QualityTypeRequest.java index f300899d59..e98b26fff2 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/base/request/QualityTypeRequest.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/base/request/QualityTypeRequest.java @@ -20,7 +20,7 @@ package org.eclipse.tractusx.traceability.assets.application.base.request; -import assets.response.QualityTypeResponse; +import assets.response.base.QualityTypeResponse; import com.fasterxml.jackson.annotation.JsonValue; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/application/rest/response/DescriptionsResponseTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/application/rest/response/DescriptionsResponseTest.java index 468655d668..d5e4e1b7e2 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/application/rest/response/DescriptionsResponseTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/application/rest/response/DescriptionsResponseTest.java @@ -20,7 +20,7 @@ package org.eclipse.tractusx.traceability.assets.application.rest.response; -import assets.response.DescriptionsResponse; +import assets.response.base.DescriptionsResponse; import org.eclipse.tractusx.traceability.assets.application.asbuilt.mapper.AssetAsBuiltResponseMapper; import org.eclipse.tractusx.traceability.assets.domain.base.model.Descriptions; import org.junit.jupiter.api.Test; diff --git a/tx-cucumber-tests/src/test/java/org/eclipse/tractusx/traceability/test/TraceabilityTestStepDefinition.java b/tx-cucumber-tests/src/test/java/org/eclipse/tractusx/traceability/test/TraceabilityTestStepDefinition.java index c3d952de6e..765f17a820 100644 --- a/tx-cucumber-tests/src/test/java/org/eclipse/tractusx/traceability/test/TraceabilityTestStepDefinition.java +++ b/tx-cucumber-tests/src/test/java/org/eclipse/tractusx/traceability/test/TraceabilityTestStepDefinition.java @@ -19,7 +19,7 @@ package org.eclipse.tractusx.traceability.test; -import assets.response.AssetAsBuiltResponse; +import assets.response.asbuilt.AssetAsBuiltResponse; import io.cucumber.datatable.DataTable; import io.cucumber.java.Before; import io.cucumber.java.ParameterType; diff --git a/tx-cucumber-tests/src/test/java/org/eclipse/tractusx/traceability/test/tooling/rest/RestProvider.java b/tx-cucumber-tests/src/test/java/org/eclipse/tractusx/traceability/test/tooling/rest/RestProvider.java index 6d30caa16c..ecbbeaa8cf 100644 --- a/tx-cucumber-tests/src/test/java/org/eclipse/tractusx/traceability/test/tooling/rest/RestProvider.java +++ b/tx-cucumber-tests/src/test/java/org/eclipse/tractusx/traceability/test/tooling/rest/RestProvider.java @@ -19,7 +19,7 @@ package org.eclipse.tractusx.traceability.test.tooling.rest; -import assets.response.AssetAsBuiltResponse; +import assets.response.asbuilt.AssetAsBuiltResponse; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; diff --git a/tx-models/src/main/java/assets/response/AssetAsBuiltResponse.java b/tx-models/src/main/java/assets/response/asbuilt/AssetAsBuiltResponse.java similarity index 94% rename from tx-models/src/main/java/assets/response/AssetAsBuiltResponse.java rename to tx-models/src/main/java/assets/response/asbuilt/AssetAsBuiltResponse.java index cc095a255e..68072144e0 100644 --- a/tx-models/src/main/java/assets/response/AssetAsBuiltResponse.java +++ b/tx-models/src/main/java/assets/response/asbuilt/AssetAsBuiltResponse.java @@ -17,8 +17,9 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package assets.response; +package assets.response.asbuilt; +import assets.response.base.AssetBaseResponse; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Schema; import lombok.experimental.SuperBuilder; diff --git a/tx-models/src/main/java/assets/response/AssetAsPlannedResponse.java b/tx-models/src/main/java/assets/response/asplanned/AssetAsPlannedResponse.java similarity index 94% rename from tx-models/src/main/java/assets/response/AssetAsPlannedResponse.java rename to tx-models/src/main/java/assets/response/asplanned/AssetAsPlannedResponse.java index 2b421b01e3..9877f10ca4 100644 --- a/tx-models/src/main/java/assets/response/AssetAsPlannedResponse.java +++ b/tx-models/src/main/java/assets/response/asplanned/AssetAsPlannedResponse.java @@ -17,8 +17,9 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package assets.response; +package assets.response.asplanned; +import assets.response.base.AssetBaseResponse; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; diff --git a/tx-models/src/main/java/assets/response/AssetBaseResponse.java b/tx-models/src/main/java/assets/response/base/AssetBaseResponse.java similarity index 66% rename from tx-models/src/main/java/assets/response/AssetBaseResponse.java rename to tx-models/src/main/java/assets/response/base/AssetBaseResponse.java index 90f8a1dcf6..695d7d2f32 100644 --- a/tx-models/src/main/java/assets/response/AssetBaseResponse.java +++ b/tx-models/src/main/java/assets/response/base/AssetBaseResponse.java @@ -1,11 +1,28 @@ -package assets.response; +/******************************************************************************** + * Copyright (c) 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 assets.response.base; import io.swagger.annotations.ApiModelProperty; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.Size; import lombok.Data; -import lombok.NoArgsConstructor; import lombok.RequiredArgsConstructor; import lombok.experimental.SuperBuilder; @@ -52,4 +69,5 @@ public class AssetBaseResponse { @ApiModelProperty(example = "component") @Size(max = 255) private String classification; + private List detailAspectModels; } diff --git a/tx-models/src/main/java/assets/response/DescriptionsResponse.java b/tx-models/src/main/java/assets/response/base/DescriptionsResponse.java similarity index 97% rename from tx-models/src/main/java/assets/response/DescriptionsResponse.java rename to tx-models/src/main/java/assets/response/base/DescriptionsResponse.java index b5a00f86e5..09e0c955de 100644 --- a/tx-models/src/main/java/assets/response/DescriptionsResponse.java +++ b/tx-models/src/main/java/assets/response/base/DescriptionsResponse.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package assets.response; +package assets.response.base; import io.swagger.annotations.ApiModelProperty; import jakarta.validation.constraints.Size; diff --git a/tx-models/src/main/java/assets/response/base/DetailAspectDataResponse.java b/tx-models/src/main/java/assets/response/base/DetailAspectDataResponse.java new file mode 100644 index 0000000000..97e7868455 --- /dev/null +++ b/tx-models/src/main/java/assets/response/base/DetailAspectDataResponse.java @@ -0,0 +1,26 @@ +/******************************************************************************** + * Copyright (c) 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 assets.response.base; + +import lombok.Builder; + + +public interface DetailAspectDataResponse { + +} diff --git a/tx-models/src/main/java/assets/response/base/DetailAspectModelResponse.java b/tx-models/src/main/java/assets/response/base/DetailAspectModelResponse.java new file mode 100644 index 0000000000..9baaf9653b --- /dev/null +++ b/tx-models/src/main/java/assets/response/base/DetailAspectModelResponse.java @@ -0,0 +1,30 @@ +/******************************************************************************** + * Copyright (c) 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 assets.response.base; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Builder; + +@Builder +public class DetailAspectModelResponse { + + @ApiModelProperty(example = "PART_SITE_INFORMATION_AS_PLANNED") + private DetailAspectTypeResponse type; + private DetailAspectDataResponse data; +} diff --git a/tx-models/src/main/java/assets/response/base/DetailAspectTypeResponse.java b/tx-models/src/main/java/assets/response/base/DetailAspectTypeResponse.java new file mode 100644 index 0000000000..58381252b3 --- /dev/null +++ b/tx-models/src/main/java/assets/response/base/DetailAspectTypeResponse.java @@ -0,0 +1,34 @@ +/******************************************************************************** + * Copyright (c) 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 assets.response.base; + +public enum DetailAspectTypeResponse { + /* Detail aspect of as built assets */ + TRACTION_BATTERY_CODE, + /* Downward relation of as planned assets */ + SINGLE_LEVEL_BOM_AS_BUILT, + + /* Upward relation of as planned assets */ + SINGLE_LEVEL_USAGE_AS_BUILT, + + /* Downward relation of as planned assets */ + SINGLE_LEVEL_BOM_AS_PLANNED, + /* Detail aspect of as planned assets */ + PART_SITE_INFORMATION_AS_PLANNED, +} diff --git a/tx-models/src/main/java/assets/response/OwnerResponse.java b/tx-models/src/main/java/assets/response/base/OwnerResponse.java similarity index 97% rename from tx-models/src/main/java/assets/response/OwnerResponse.java rename to tx-models/src/main/java/assets/response/base/OwnerResponse.java index 4689a66c14..a14c79c37c 100644 --- a/tx-models/src/main/java/assets/response/OwnerResponse.java +++ b/tx-models/src/main/java/assets/response/base/OwnerResponse.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package assets.response; +package assets.response.base; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/tx-models/src/main/java/assets/response/base/PartSiteInformationAsPlannedResponse.java b/tx-models/src/main/java/assets/response/base/PartSiteInformationAsPlannedResponse.java new file mode 100644 index 0000000000..42d8a66e29 --- /dev/null +++ b/tx-models/src/main/java/assets/response/base/PartSiteInformationAsPlannedResponse.java @@ -0,0 +1,19 @@ +package assets.response.base; + +import assets.response.base.DetailAspectDataResponse; +import io.swagger.annotations.ApiModelProperty; +import lombok.Builder; + +import java.util.Date; + +@Builder +public class PartSiteInformationAsPlannedResponse implements DetailAspectDataResponse { + @ApiModelProperty(example = "2025-02-08T04:30:48.000Z") + private Date functionValidUntil; + @ApiModelProperty(example = "production") + private String function; + @ApiModelProperty(example = "2025-02-08T04:30:48.000Z") + private Date functionValidFrom; + @ApiModelProperty(example = "urn:uuid:0fed587c-7ab4-4597-9841-1718e9693003") + private String catenaXSiteId; +} diff --git a/tx-models/src/main/java/assets/response/QualityTypeResponse.java b/tx-models/src/main/java/assets/response/base/QualityTypeResponse.java similarity index 98% rename from tx-models/src/main/java/assets/response/QualityTypeResponse.java rename to tx-models/src/main/java/assets/response/base/QualityTypeResponse.java index 79a9f7f5a6..90a6f1f4fa 100644 --- a/tx-models/src/main/java/assets/response/QualityTypeResponse.java +++ b/tx-models/src/main/java/assets/response/base/QualityTypeResponse.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package assets.response; +package assets.response.base; import com.fasterxml.jackson.annotation.JsonValue; import io.swagger.annotations.ApiModel; diff --git a/tx-models/src/main/java/assets/response/SemanticDataModelResponse.java b/tx-models/src/main/java/assets/response/base/SemanticDataModelResponse.java similarity index 97% rename from tx-models/src/main/java/assets/response/SemanticDataModelResponse.java rename to tx-models/src/main/java/assets/response/base/SemanticDataModelResponse.java index 8786ee68fd..accee5406b 100644 --- a/tx-models/src/main/java/assets/response/SemanticDataModelResponse.java +++ b/tx-models/src/main/java/assets/response/base/SemanticDataModelResponse.java @@ -16,7 +16,7 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package assets.response; +package assets.response.base; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/tx-models/src/main/java/assets/response/SemanticModelResponse.java b/tx-models/src/main/java/assets/response/base/SemanticModelResponse.java similarity index 98% rename from tx-models/src/main/java/assets/response/SemanticModelResponse.java rename to tx-models/src/main/java/assets/response/base/SemanticModelResponse.java index 785e2b8d21..6dddfd7731 100644 --- a/tx-models/src/main/java/assets/response/SemanticModelResponse.java +++ b/tx-models/src/main/java/assets/response/base/SemanticModelResponse.java @@ -16,7 +16,7 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package assets.response; +package assets.response.base; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; From 424ddda21a1cea5317092acc6be9e44300fab82a Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Wed, 30 Aug 2023 13:12:44 +0200 Subject: [PATCH 59/63] feature: TRACEFOSS-2391 coverage --- CHANGELOG.md | 1 + .../edc/blackbox/InvestigationsEDCFacade.java | 2 +- .../service/EdcNotificationService.java | 6 ++-- .../blackbox/InvestigationsEDCFacadeTest.java | 16 ++++----- .../service/EdcNotificationServiceTest.java | 36 +++++++++---------- 5 files changed, 30 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c116deb405..6a9c8e15a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Updated owasp:dependency-check from 8.3.1 to 8.4.0 - Updated commons-io from 2.11.0 to 2.13.0 - Updated snakeyaml from 2.0 to 2.1 +- Removed own implementation of getCatalog, negotiateAgreement, and validatePolicy with irs-client-library implementation. ### Removed diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java index 6e5ccd61fe..8456fd48c8 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacade.java @@ -74,7 +74,7 @@ public class InvestigationsEDCFacade { private static final String ASSET_VALUE_NOTIFICATION_METHOD_UPDATE = "update"; private static final String ASSET_VALUE_NOTIFICATION_METHOD_RECEIVE = "receive"; - public void startEdcTransferNew( + public void startEdcTransfer( final QualityNotificationMessage notification, final String receiverEdcUrl, final String senderEdcUrl) { diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationService.java index ff9505f22c..62f8dc1044 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationService.java @@ -21,13 +21,11 @@ package org.eclipse.tractusx.traceability.qualitynotification.domain.service; -import com.fasterxml.jackson.core.JsonProcessingException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.traceability.common.config.AssetsAsyncConfig; import org.eclipse.tractusx.traceability.discovery.domain.model.Discovery; import org.eclipse.tractusx.traceability.discovery.domain.service.DiscoveryService; -import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.BadRequestException; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.ContractNegotiationException; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.InvestigationsEDCFacade; import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.NoCatalogItemException; @@ -74,7 +72,7 @@ public void asyncNotificationExecutor(QualityNotificationMessage notification) { private void handleSendingAlert(QualityNotificationMessage notification, String senderEdcUrl, String receiverUrl) { try { - edcFacade.startEdcTransferNew(notification, receiverUrl, senderEdcUrl); + edcFacade.startEdcTransfer(notification, receiverUrl, senderEdcUrl); alertRepository.updateQualityNotificationMessageEntity(notification); } catch (NoCatalogItemException e) { log.warn("Could not send alert to {} no catalog item found. ", receiverUrl, e); @@ -89,7 +87,7 @@ private void handleSendingAlert(QualityNotificationMessage notification, String private void handleSendingInvestigation(QualityNotificationMessage notification, String senderEdcUrl, String receiverUrl) { try { - edcFacade.startEdcTransferNew(notification, receiverUrl, senderEdcUrl); + edcFacade.startEdcTransfer(notification, receiverUrl, senderEdcUrl); investigationRepository.updateQualityNotificationMessageEntity(notification); } catch (NoCatalogItemException e) { log.warn("Could not send investigation to {} no catalog item found.", receiverUrl, e); diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java index c716874217..0ebd9b6d13 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/InvestigationsEDCFacadeTest.java @@ -68,7 +68,7 @@ class InvestigationsEDCFacadeTest { InvestigationsEDCFacade investigationsEDCFacade; @Test - void givenCorrectInvestigationMessage_whenStartEdcTransferNew_thenSendIt() throws Exception { + void givenCorrectInvestigationMessage_whenStartEdcTransfer_thenSendIt() throws Exception { // given final String receiverEdcUrl = "https://receiver.com"; final String senderEdcUrl = "https://sender.com"; @@ -96,14 +96,14 @@ void givenCorrectInvestigationMessage_whenStartEdcTransferNew_thenSendIt() throw when(objectMapper.writeValueAsString(any())).thenReturn("{body}"); // when - investigationsEDCFacade.startEdcTransferNew(notificationMessage, receiverEdcUrl, senderEdcUrl); + investigationsEDCFacade.startEdcTransfer(notificationMessage, receiverEdcUrl, senderEdcUrl); // then verify(httpCallService).sendRequest(any()); } @Test - void givenCorrectInvestigationMessageButSendRequestThrowsException_whenStartEdcTransferNew_thenThrowSendNotificationException() throws Exception { + void givenCorrectInvestigationMessageButSendRequestThrowsException_whenStartEdcTransfer_thenThrowSendNotificationException() throws Exception { // given final String receiverEdcUrl = "https://receiver.com"; final String senderEdcUrl = "https://sender.com"; @@ -132,11 +132,11 @@ void givenCorrectInvestigationMessageButSendRequestThrowsException_whenStartEdcT doThrow(new RuntimeException()).when(httpCallService).sendRequest(any()); // when/then - assertThrows(SendNotificationException.class, () -> investigationsEDCFacade.startEdcTransferNew(notificationMessage, receiverEdcUrl, senderEdcUrl)); + assertThrows(SendNotificationException.class, () -> investigationsEDCFacade.startEdcTransfer(notificationMessage, receiverEdcUrl, senderEdcUrl)); } @Test - void givenCorrectInvestigationMessageButNegotiateContractAgreementHasNoCatalogItem_whenStartEdcTransferNew_thenThrowContractNegotiationException() throws Exception { + void givenCorrectInvestigationMessageButNegotiateContractAgreementHasNoCatalogItem_whenStartEdcTransfer_thenThrowContractNegotiationException() throws Exception { // given final String receiverEdcUrl = "https://receiver.com"; final String senderEdcUrl = "https://sender.com"; @@ -155,11 +155,11 @@ void givenCorrectInvestigationMessageButNegotiateContractAgreementHasNoCatalogIt .thenReturn(null); // when/then - assertThrows(ContractNegotiationException.class, () -> investigationsEDCFacade.startEdcTransferNew(notificationMessage, receiverEdcUrl, senderEdcUrl)); + assertThrows(ContractNegotiationException.class, () -> investigationsEDCFacade.startEdcTransfer(notificationMessage, receiverEdcUrl, senderEdcUrl)); } @Test - void givenCorrectInvestigationMessageButCatalogItem_whenStartEdcTransferNew_thenThrowSendNotificationException() { + void givenCorrectInvestigationMessageButCatalogItem_whenStartEdcTransfer_thenThrowSendNotificationException() { // given final String receiverEdcUrl = "https://receiver.com"; final String senderEdcUrl = "https://sender.com"; @@ -173,6 +173,6 @@ void givenCorrectInvestigationMessageButCatalogItem_whenStartEdcTransferNew_then when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of()); // when/then - assertThrows(NoCatalogItemException.class, () -> investigationsEDCFacade.startEdcTransferNew(notificationMessage, receiverEdcUrl, senderEdcUrl)); + assertThrows(NoCatalogItemException.class, () -> investigationsEDCFacade.startEdcTransfer(notificationMessage, receiverEdcUrl, senderEdcUrl)); } } diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationServiceTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationServiceTest.java index c933478a20..41b37f988c 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationServiceTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/qualitynotification/domain/service/EdcNotificationServiceTest.java @@ -88,7 +88,7 @@ void testNotificationsServiceUpdateAsync() { notificationsService.asyncNotificationExecutor(notification); // then - verify(edcFacade).startEdcTransferNew(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); + verify(edcFacade).startEdcTransfer(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); verify(investigationRepository).updateQualityNotificationMessageEntity(notification); verifyNoInteractions(alertRepository); } @@ -116,7 +116,7 @@ void testNotificationsServiceAlertNotificationUpdateAsync() { notificationsService.asyncNotificationExecutor(notification); // then - verify(edcFacade).startEdcTransferNew(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); + verify(edcFacade).startEdcTransfer(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); verify(alertRepository).updateQualityNotificationMessageEntity(notification); verifyNoInteractions(investigationRepository); } @@ -137,13 +137,13 @@ void givenNoCatalogItemException_whenHandleSendingInvestigation_thenHandleIt() { .severity(QualityNotificationSeverity.MINOR) .isInitial(false) .build(); - doThrow(new NoCatalogItemException()).when(edcFacade).startEdcTransferNew(notification, edcReceiverUrl, edcSenderUrl); + doThrow(new NoCatalogItemException()).when(edcFacade).startEdcTransfer(notification, edcReceiverUrl, edcSenderUrl); // when notificationsService.asyncNotificationExecutor(notification); // then - verify(edcFacade).startEdcTransferNew(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); + verify(edcFacade).startEdcTransfer(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); verifyNoInteractions(alertRepository); verifyNoInteractions(investigationRepository); } @@ -164,13 +164,13 @@ void givenSendNotificationException_whenHandleSendingInvestigation_thenHandleIt( .severity(QualityNotificationSeverity.MINOR) .isInitial(false) .build(); - doThrow(new SendNotificationException("message",new RuntimeException())).when(edcFacade).startEdcTransferNew(notification, edcReceiverUrl, edcSenderUrl); + doThrow(new SendNotificationException("message",new RuntimeException())).when(edcFacade).startEdcTransfer(notification, edcReceiverUrl, edcSenderUrl); // when notificationsService.asyncNotificationExecutor(notification); // then - verify(edcFacade).startEdcTransferNew(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); + verify(edcFacade).startEdcTransfer(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); verifyNoInteractions(alertRepository); verifyNoInteractions(investigationRepository); } @@ -191,13 +191,13 @@ void givenSendNoEndpointDataReferenceException_whenHandleSendingInvestigation_th .severity(QualityNotificationSeverity.MINOR) .isInitial(false) .build(); - doThrow(new NoEndpointDataReferenceException("message")).when(edcFacade).startEdcTransferNew(notification, edcReceiverUrl, edcSenderUrl); + doThrow(new NoEndpointDataReferenceException("message")).when(edcFacade).startEdcTransfer(notification, edcReceiverUrl, edcSenderUrl); // when notificationsService.asyncNotificationExecutor(notification); // then - verify(edcFacade).startEdcTransferNew(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); + verify(edcFacade).startEdcTransfer(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); verifyNoInteractions(alertRepository); verifyNoInteractions(investigationRepository); } @@ -218,13 +218,13 @@ void givenContractNegotiationException_whenHandleSendingInvestigation_thenHandle .severity(QualityNotificationSeverity.MINOR) .isInitial(false) .build(); - doThrow(new ContractNegotiationException("message")).when(edcFacade).startEdcTransferNew(notification, edcReceiverUrl, edcSenderUrl); + doThrow(new ContractNegotiationException("message")).when(edcFacade).startEdcTransfer(notification, edcReceiverUrl, edcSenderUrl); // when notificationsService.asyncNotificationExecutor(notification); // then - verify(edcFacade).startEdcTransferNew(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); + verify(edcFacade).startEdcTransfer(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); verifyNoInteractions(alertRepository); verifyNoInteractions(investigationRepository); } @@ -246,13 +246,13 @@ void givenNoCatalogItemException_whenHandleSendingAlert_thenHandleIt() { .severity(QualityNotificationSeverity.MINOR) .isInitial(false) .build(); - doThrow(new NoCatalogItemException()).when(edcFacade).startEdcTransferNew(notification, edcReceiverUrl, edcSenderUrl); + doThrow(new NoCatalogItemException()).when(edcFacade).startEdcTransfer(notification, edcReceiverUrl, edcSenderUrl); // when notificationsService.asyncNotificationExecutor(notification); // then - verify(edcFacade).startEdcTransferNew(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); + verify(edcFacade).startEdcTransfer(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); verifyNoInteractions(alertRepository); verifyNoInteractions(investigationRepository); } @@ -273,13 +273,13 @@ void givenSendNotificationException_whenHandleSendingAlert_thenHandleIt() { .severity(QualityNotificationSeverity.MINOR) .isInitial(false) .build(); - doThrow(new SendNotificationException("message",new RuntimeException())).when(edcFacade).startEdcTransferNew(notification, edcReceiverUrl, edcSenderUrl); + doThrow(new SendNotificationException("message",new RuntimeException())).when(edcFacade).startEdcTransfer(notification, edcReceiverUrl, edcSenderUrl); // when notificationsService.asyncNotificationExecutor(notification); // then - verify(edcFacade).startEdcTransferNew(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); + verify(edcFacade).startEdcTransfer(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); verifyNoInteractions(alertRepository); verifyNoInteractions(investigationRepository); } @@ -300,13 +300,13 @@ void givenSendNoEndpointDataReferenceException_whenHandleSendingAlert_thenHandle .severity(QualityNotificationSeverity.MINOR) .isInitial(false) .build(); - doThrow(new NoEndpointDataReferenceException("message")).when(edcFacade).startEdcTransferNew(notification, edcReceiverUrl, edcSenderUrl); + doThrow(new NoEndpointDataReferenceException("message")).when(edcFacade).startEdcTransfer(notification, edcReceiverUrl, edcSenderUrl); // when notificationsService.asyncNotificationExecutor(notification); // then - verify(edcFacade).startEdcTransferNew(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); + verify(edcFacade).startEdcTransfer(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); verifyNoInteractions(alertRepository); verifyNoInteractions(investigationRepository); } @@ -327,13 +327,13 @@ void givenContractNegotiationException_whenHandleSendingAlert_thenHandleIt() { .severity(QualityNotificationSeverity.MINOR) .isInitial(false) .build(); - doThrow(new ContractNegotiationException("message")).when(edcFacade).startEdcTransferNew(notification, edcReceiverUrl, edcSenderUrl); + doThrow(new ContractNegotiationException("message")).when(edcFacade).startEdcTransfer(notification, edcReceiverUrl, edcSenderUrl); // when notificationsService.asyncNotificationExecutor(notification); // then - verify(edcFacade).startEdcTransferNew(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); + verify(edcFacade).startEdcTransfer(any(QualityNotificationMessage.class), eq(edcReceiverUrl), eq(edcSenderUrl)); verifyNoInteractions(alertRepository); verifyNoInteractions(investigationRepository); } From 61691eb085764d98fb3cecc8847b3fb441ac4781 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Wed, 30 Aug 2023 13:14:34 +0200 Subject: [PATCH 60/63] feature: TRACEFOSS-2391 changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a9c8e15a5..26abfb44b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,7 +34,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Updated owasp:dependency-check from 8.3.1 to 8.4.0 - Updated commons-io from 2.11.0 to 2.13.0 - Updated snakeyaml from 2.0 to 2.1 -- Removed own implementation of getCatalog, negotiateAgreement, and validatePolicy with irs-client-library implementation. +- Replaced own implementation of getCatalog, negotiateAgreement, and validatePolicy with irs-client-library implementation. ### Removed From 80fe61b3847f0491ea2e305943c24ad971b0f900 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 30 Aug 2023 13:14:56 +0200 Subject: [PATCH 61/63] chore: TRACEFOSS-1731 adapt api response to include detailSemanticModel --- .../application/base/mapper/AssetBaseResponseMapper.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/base/mapper/AssetBaseResponseMapper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/base/mapper/AssetBaseResponseMapper.java index 8e91a08a68..4f3344a78d 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/base/mapper/AssetBaseResponseMapper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/base/mapper/AssetBaseResponseMapper.java @@ -31,6 +31,8 @@ import java.util.List; +import static org.apache.commons.collections4.ListUtils.emptyIfNull; + @AllArgsConstructor @Data @SuperBuilder @@ -47,7 +49,7 @@ public static SemanticModelResponse from(final SemanticModel semanticModel) { } public static List fromList(List detailAspectModels) { - return detailAspectModels.stream() + return emptyIfNull(detailAspectModels).stream() .map(AssetAsPlannedResponseMapper::from) .toList(); } From 4af2fb7397a60f5bc3098eac248343c6174c0beb Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Wed, 30 Aug 2023 13:34:49 +0200 Subject: [PATCH 62/63] feature: TRACEFOSS-2391 changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26abfb44b8..971239cff6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Updated commons-io from 2.11.0 to 2.13.0 - Updated snakeyaml from 2.0 to 2.1 - Replaced own implementation of getCatalog, negotiateAgreement, and validatePolicy with irs-client-library implementation. +- Updated irs-registry-client from 1.1.0-SNAPSHOT to 1.1.1-SNAPSHOT ### Removed From ec32dddc13958b83fe31f2133c3d73e0b22bbf85 Mon Sep 17 00:00:00 2001 From: ds-mwesener Date: Wed, 30 Aug 2023 11:45:13 +0000 Subject: [PATCH 63/63] Update Dependencies Backend Action --- DEPENDENCIES_BACKEND | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPENDENCIES_BACKEND b/DEPENDENCIES_BACKEND index e8780ef119..2d554c3627 100644 --- a/DEPENDENCIES_BACKEND +++ b/DEPENDENCIES_BACKEND @@ -140,7 +140,7 @@ maven/mavencentral/org.eclipse.edc/transfer-spi/0.1.3, Apache-2.0, approved, tec maven/mavencentral/org.eclipse.edc/transform-spi/0.1.3, Apache-2.0, approved, technology.edc maven/mavencentral/org.eclipse.edc/validator-spi/0.1.3, Apache-2.0, approved, technology.edc maven/mavencentral/org.eclipse.edc/web-spi/0.1.3, Apache-2.0, approved, technology.edc -maven/mavencentral/org.eclipse.tractusx.irs/irs-registry-client/1.1.0-20230824.091723-4, Apache-2.0, approved, automotive.tractusx +maven/mavencentral/org.eclipse.tractusx.irs/irs-registry-client/1.1.1-20230825.093801-1, Apache-2.0, approved, automotive.tractusx maven/mavencentral/org.eclipse.tractusx.traceability/tx-backend/0.0.1-SNAPSHOT, Apache-2.0, approved, automotive.tractusx maven/mavencentral/org.eclipse.tractusx.traceability/tx-models/0.0.1-SNAPSHOT, Apache-2.0, approved, automotive.tractusx maven/mavencentral/org.flywaydb/flyway-core/9.16.3, Apache-2.0, approved, #7935