From 3b6739f3f236777c0ce0676082d0c09502b20e7e Mon Sep 17 00:00:00 2001 From: ds-lcapellino Date: Tue, 11 Jun 2024 13:46:54 +0200 Subject: [PATCH 01/14] feature: #639 update irs-lib --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2f1625aac1..bfb2fc5d3d 100644 --- a/pom.xml +++ b/pom.xml @@ -90,7 +90,7 @@ SPDX-License-Identifier: Apache-2.0 5.10.2 4.2.1 - 2.0.5 + 2.1.0-SNAPSHOT 5.4.0 jacoco From 88b7fd57c6ab260e809bbc94e5ae97d9ee3ef02a Mon Sep 17 00:00:00 2001 From: ds-lcapellino Date: Mon, 17 Jun 2024 09:11:33 +0200 Subject: [PATCH 02/14] feature: #639 adapt integration tests --- .../ContractNegotiationException.java | 1 + .../base/service/NotificationsEDCFacade.java | 2 +- .../InvestigationPolicyExpirationIT.java | 144 ++++++++++++++++++ .../PublisherInvestigationsControllerIT.java | 1 - 4 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyExpirationIT.java diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/exception/ContractNegotiationException.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/exception/ContractNegotiationException.java index d1eac30166..0b210b77c7 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/exception/ContractNegotiationException.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/exception/ContractNegotiationException.java @@ -20,6 +20,7 @@ package org.eclipse.tractusx.traceability.notification.domain.base.exception; public class ContractNegotiationException extends RuntimeException { + public ContractNegotiationException(final String message, final Throwable exception) { super(message, exception); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationsEDCFacade.java index c917bbedce..a06fa3278c 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationsEDCFacade.java @@ -119,7 +119,7 @@ private String negotiateContractAgreement(final String receiverEdcUrl, final Cat .orElseThrow() .getContractAgreementId(); } catch (Exception e) { - throw new ContractNegotiationException("Failed to negotiate contract agreement. ", e); + throw new ContractNegotiationException("Failed to negotiate contract agreement: " + e.getMessage(), e); } } diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyExpirationIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyExpirationIT.java new file mode 100644 index 0000000000..6a4e11c4c4 --- /dev/null +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyExpirationIT.java @@ -0,0 +1,144 @@ +/******************************************************************************** + * Copyright (c) 2024 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.integration.notification.investigation; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.restassured.http.ContentType; +import lombok.val; +import notification.request.NotificationSeverityRequest; +import notification.request.NotificationTypeRequest; +import notification.request.StartNotificationRequest; +import org.eclipse.tractusx.traceability.assets.domain.asbuilt.repository.AssetAsBuiltRepository; +import org.eclipse.tractusx.traceability.common.request.OwnPageable; +import org.eclipse.tractusx.traceability.common.request.PageableFilterRequest; +import org.eclipse.tractusx.traceability.common.request.SearchCriteriaRequestParam; +import org.eclipse.tractusx.traceability.integration.IntegrationTestSpecification; +import org.eclipse.tractusx.traceability.integration.common.support.AssetsSupport; +import org.eclipse.tractusx.traceability.integration.common.support.DiscoveryFinderSupport; +import org.eclipse.tractusx.traceability.integration.common.support.EdcSupport; +import org.eclipse.tractusx.traceability.integration.common.support.IrsApiSupport; +import org.eclipse.tractusx.traceability.integration.common.support.NotificationApiSupport; +import org.eclipse.tractusx.traceability.integration.common.support.NotificationMessageSupport; +import org.eclipse.tractusx.traceability.integration.common.support.NotificationSupport; +import org.eclipse.tractusx.traceability.integration.common.support.OAuth2ApiSupport; +import org.eclipse.tractusx.traceability.notification.domain.notification.service.NotificationReceiverService; +import org.hamcrest.Matchers; +import org.jose4j.lang.JoseException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.TestPropertySource; + +import java.util.Collections; +import java.util.List; + +import static io.restassured.RestAssured.given; +import static org.eclipse.tractusx.traceability.common.security.JwtRole.SUPERVISOR; + +@TestPropertySource(properties = "traceability.validUntil=2020-07-04T16:01:05.309Z") +public class InvestigationPolicyExpirationIT extends IntegrationTestSpecification { + @Autowired + NotificationReceiverService notificationReceiverService; + @Autowired + AssetsSupport assetsSupport; + @Autowired + NotificationMessageSupport notificationMessageSupport; + @Autowired + NotificationSupport notificationSupport; + @Autowired + AssetAsBuiltRepository assetAsBuiltRepository; + @Autowired + NotificationApiSupport notificationApiSupport; + @Autowired + EdcSupport edcSupport; + + @Autowired + DiscoveryFinderSupport discoveryFinderSupport; + + @Autowired + OAuth2ApiSupport oauth2ApiSupport; + + @Autowired + IrsApiSupport irsApiSupport; + + ObjectMapper objectMapper; + + @BeforeEach + void setUp() { + objectMapper = new ObjectMapper(); + } + + @Test + void shouldNotApproveInvestigationStatus_whenPolicyIsExpired() throws JoseException, com.fasterxml.jackson.core.JsonProcessingException { + // given + irsApiSupport.irsApiReturnsPolicies(); + discoveryFinderSupport.discoveryFinderWillReturnEndpointAddress(); + discoveryFinderSupport.discoveryFinderWillReturnConnectorEndpoints(); + oauth2ApiSupport.oauth2ApiReturnsDtrToken(); + edcSupport.performSupportActionsForAsyncNotificationMessageExecutor(); + List partIds = List.of( + "urn:uuid:fe99da3d-b0de-4e80-81da-882aebcca978", // BPN: BPNL00000003AYRE + "urn:uuid:0ce83951-bc18-4e8f-892d-48bad4eb67ef" // BPN: BPNL00000003AXS3 + ); + String description = "at least 15 characters long investigation description"; + + assetsSupport.defaultAssetsStored(); + val startInvestigationRequest = StartNotificationRequest.builder() + .affectedPartIds(partIds) + .description(description) + .severity(NotificationSeverityRequest.MINOR) + .type(NotificationTypeRequest.INVESTIGATION) + .receiverBpn("BPNL00000003CNKC") + .build(); + + // when + val investigationId = notificationApiSupport.createNotificationRequest_withDefaultAssetsStored(oAuth2Support.jwtAuthorization(SUPERVISOR), startInvestigationRequest, 201); + + + notificationSupport.assertInvestigationsSize(1); + + given() + .contentType(ContentType.JSON) + .header(oAuth2Support.jwtAuthorization(SUPERVISOR)) + .when() + .post("/api/notifications/{investigationId}/approve", investigationId) + .then() + .log().all() + .statusCode(503); + + // then + given() + .header(oAuth2Support.jwtAuthorization(SUPERVISOR)) + .body(new PageableFilterRequest(new OwnPageable(0, 10, Collections.emptyList()), new SearchCriteriaRequestParam(List.of("channel,EQUAL,SENDER,AND")))) + .contentType(ContentType.JSON) + .when() + .post("/api/notifications/filter") + .then() + .log().all() + .statusCode(200) + .body("page", Matchers.is(0)) + .body("pageSize", Matchers.is(10)) + .body("content", Matchers.hasSize(1)) + .body("content[0].sendTo", Matchers.is(Matchers.not(Matchers.blankOrNullString()))) + .body("content[0].messages[0].errorMessage", Matchers.is("Failed to negotiate contract agreement: Consumption of asset '40276218-e31b-4c35-a7c8-017e8edb702e' is not permitted as the required catalog offer policies are expired.")) + .body("content[0].messages[1].errorMessage", Matchers.is("Failed to negotiate contract agreement: Consumption of asset '40276218-e31b-4c35-a7c8-017e8edb702e' is not permitted as the required catalog offer policies are expired.")); + + notificationMessageSupport.assertMessageSize(2); + } +} diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/PublisherInvestigationsControllerIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/PublisherInvestigationsControllerIT.java index 7dbad99cbb..fea882340a 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/PublisherInvestigationsControllerIT.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/PublisherInvestigationsControllerIT.java @@ -578,5 +578,4 @@ void shouldBeCreatedBySender() throws JoseException, JsonProcessingException { .body("pageSize", Matchers.is(10)) .body("content", Matchers.hasSize(1)); } - } From e292065be0464e2eed807163f2a1c496eec9d7dc Mon Sep 17 00:00:00 2001 From: ds-lcapellino Date: Mon, 17 Jun 2024 13:57:35 +0200 Subject: [PATCH 03/14] feature: #639 adapt integration tests --- .../resources/application-integration-spring-boot.yml | 2 -- .../integration/IntegrationTestSpecification.java | 8 +++++++- .../investigation/InvestigationPolicyExpirationIT.java | 10 ++++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) 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 01de3c8a48..0539cfd984 100644 --- a/tx-backend/src/main/resources/application-integration-spring-boot.yml +++ b/tx-backend/src/main/resources/application-integration-spring-boot.yml @@ -68,8 +68,6 @@ spring: jwt: resource-client: "Integration-Test" -server: - port: 9998 management: server: port: 8082 diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/IntegrationTestSpecification.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/IntegrationTestSpecification.java index 176e60bd98..5ba9019da4 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/IntegrationTestSpecification.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/IntegrationTestSpecification.java @@ -19,6 +19,7 @@ package org.eclipse.tractusx.traceability.integration; import groovy.json.JsonBuilder; +import io.restassured.RestAssured; import org.awaitility.Awaitility; import org.eclipse.tractusx.traceability.integration.common.config.PostgreSQLConfig; import org.eclipse.tractusx.traceability.integration.common.config.RestAssuredConfig; @@ -33,6 +34,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; @@ -42,7 +44,7 @@ import static org.awaitility.Awaitility.await; @ActiveProfiles("integration-spring-boot") -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @AutoConfigureMockMvc @ContextConfiguration(initializers = {PostgreSQLConfig.Initializer.class, RestitoConfig.Initializer.class}, classes = {RestAssuredConfig.class}) public class IntegrationTestSpecification { @@ -56,8 +58,12 @@ public class IntegrationTestSpecification { @Autowired DatabaseSupport databaseSupport; + @LocalServerPort + private Integer port; + @BeforeEach void beforeEach() throws JoseException { + RestAssured.port = port; oAuth2ApiSupport.oauth2ApiReturnsTechnicalUserToken(); oAuth2ApiSupport.oauth2ApiReturnsJwkCerts(oAuth2Support.jwk()); } diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyExpirationIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyExpirationIT.java index 6a4e11c4c4..047bf30731 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyExpirationIT.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyExpirationIT.java @@ -43,7 +43,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; import java.util.Collections; import java.util.List; @@ -51,7 +52,6 @@ import static io.restassured.RestAssured.given; import static org.eclipse.tractusx.traceability.common.security.JwtRole.SUPERVISOR; -@TestPropertySource(properties = "traceability.validUntil=2020-07-04T16:01:05.309Z") public class InvestigationPolicyExpirationIT extends IntegrationTestSpecification { @Autowired NotificationReceiverService notificationReceiverService; @@ -79,6 +79,12 @@ public class InvestigationPolicyExpirationIT extends IntegrationTestSpecificatio ObjectMapper objectMapper; + + @DynamicPropertySource + static void dynamicProperties(DynamicPropertyRegistry registry) { + registry.add("traceability.validUntil", () -> "2020-07-04T16:01:05.309Z"); + } + @BeforeEach void setUp() { objectMapper = new ObjectMapper(); From e1eb275abbaeebe2440695d2b616231c42af3a79 Mon Sep 17 00:00:00 2001 From: ds-lcapellino Date: Tue, 18 Jun 2024 11:22:23 +0200 Subject: [PATCH 04/14] feature: #639 fix integration tests --- .../src/main/resources/application-integration-spring-boot.yml | 2 ++ .../traceability/integration/IntegrationTestSpecification.java | 2 +- .../investigation/InvestigationPolicyExpirationIT.java | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) 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 0539cfd984..01de3c8a48 100644 --- a/tx-backend/src/main/resources/application-integration-spring-boot.yml +++ b/tx-backend/src/main/resources/application-integration-spring-boot.yml @@ -68,6 +68,8 @@ spring: jwt: resource-client: "Integration-Test" +server: + port: 9998 management: server: port: 8082 diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/IntegrationTestSpecification.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/IntegrationTestSpecification.java index 5ba9019da4..48318e10d4 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/IntegrationTestSpecification.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/IntegrationTestSpecification.java @@ -44,7 +44,7 @@ import static org.awaitility.Awaitility.await; @ActiveProfiles("integration-spring-boot") -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @AutoConfigureMockMvc @ContextConfiguration(initializers = {PostgreSQLConfig.Initializer.class, RestitoConfig.Initializer.class}, classes = {RestAssuredConfig.class}) public class IntegrationTestSpecification { diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyExpirationIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyExpirationIT.java index 047bf30731..3a16136d44 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyExpirationIT.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyExpirationIT.java @@ -83,6 +83,8 @@ public class InvestigationPolicyExpirationIT extends IntegrationTestSpecificatio @DynamicPropertySource static void dynamicProperties(DynamicPropertyRegistry registry) { registry.add("traceability.validUntil", () -> "2020-07-04T16:01:05.309Z"); + registry.add("server.port", () -> "9997"); + registry.add("management.server.port", () -> "8083"); } @BeforeEach From 81d839a91a346f74c9ff9056193dc8ed07d560e8 Mon Sep 17 00:00:00 2001 From: ds-lcapellino Date: Tue, 18 Jun 2024 11:28:13 +0200 Subject: [PATCH 05/14] feature: #639 remove PolicyCheckerService.isValid() check --- .../domain/base/service/NotificationsEDCFacade.java | 8 -------- .../edc/blackbox/NotificationsEDCFacadeTest.java | 2 -- 2 files changed, 10 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationsEDCFacade.java index a06fa3278c..0795523948 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationsEDCFacade.java @@ -154,14 +154,6 @@ private CatalogItem getCatalogItem(final NotificationMessage notification, final .build()) .build() ).stream() - .filter(catalogItem -> { - log.info("-- catalog item check --"); - log.info("Item {}: {}", catalogItem.getItemId(), catalogItem); - boolean isValid = policyCheckerService.isValid(catalogItem.getPolicy(), notification.getSendTo() - ); - log.info("IsValid : {}", isValid); - return isValid; - }) .findFirst() .orElseThrow(); } catch (Exception e) { diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NotificationsEDCFacadeTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NotificationsEDCFacadeTest.java index ce1a91d3e8..a1b10b2206 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NotificationsEDCFacadeTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NotificationsEDCFacadeTest.java @@ -82,7 +82,6 @@ void givenCorrectInvestigationMessageButSendRequestThrowsException_whenStartEdcT final String idsPath = "/api/v1/dsp"; when(edcProperties.getIdsPath()).thenReturn(idsPath); when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of(catalogItem)); - when(policyCheckerService.isValid(null, null)).thenReturn(true); when(contractNegotiationService.negotiate(receiverEdcUrl + idsPath, catalogItem, null, null)) .thenReturn(NegotiationResponse.builder().contractAgreementId(agreementId).build()); when(endpointDataReference.getEndpoint()).thenReturn("endpoint"); @@ -111,7 +110,6 @@ void givenCorrectInvestigationMessageButNegotiateContractAgreementHasNoCatalogIt final String idsPath = "/api/v1/dsp"; when(edcProperties.getIdsPath()).thenReturn(idsPath); when(edcCatalogFacade.fetchCatalogItems(any())).thenReturn(List.of(catalogItem)); - when(policyCheckerService.isValid(null, null)).thenReturn(true); when(contractNegotiationService.negotiate(receiverEdcUrl + idsPath, catalogItem, null, null)) .thenReturn(null); From 32536c82f5b7291911c9a3db2c96b860a628056d Mon Sep 17 00:00:00 2001 From: ds-lcapellino Date: Fri, 28 Jun 2024 13:26:11 +0200 Subject: [PATCH 06/14] feature: #639 test --- CHANGELOG.md | 18 +-- .../PartSiteInformationAsPlannedMapper.java | 2 +- .../service/EdcNotificationServiceImpl.java | 23 ++- .../service/NotificationPublisherService.java | 7 +- .../repository/NotificationRepository.java | 3 +- .../JpaNotificationMessageRepository.java | 5 + .../NotificationRepositoryImpl.java | 18 +-- tx-backend/src/main/resources/application.yml | 2 +- .../InvestigationPolicyNotSupportedIT.java | 152 ++++++++++++++++++ .../InvestigationsRepositoryImplTest.java | 4 +- .../NotificationRepositoryImplTest.java | 4 +- 11 files changed, 193 insertions(+), 45 deletions(-) create mode 100644 tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyNotSupportedIT.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cebc56566..dd86630ef0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ _**For better traceability add the corresponding GitHub issue number in each cha - #1037 extended autocomplete api by contractAgreementId - #985 Added function to save Contracts based on notification contractAgreementIds into the database - #985 Added function to filter notifications for contractAgreementIds +- XXX updated JsonSchemaTest now the test pulls the latest version of the json file +- XXX deactivated a test class in tx-backend which behaved undesirably +- #1017 updated contributing, notice, and readme files for TRG 7 +- #639 handle expired or incorrect policies when sending notifications ### Added - #832 added policymanagement list view, creator and editor @@ -24,25 +28,13 @@ _**For better traceability add the corresponding GitHub issue number in each cha - XXX Added interceptor to EdcRestTemplates to log requests - #915 Added section to documentation: EDC-BPN configuration - #1037 Added link from contracts view to the corresponding filtered part table view +- #1017 added file for CC BY 4.0 license for TRG 7 ### Removed - XXX Removed EdcNotifiactionMockServiceImpl class and replaced with mocks - #1033 removed action jira-publish-release workflow -### Changed - -- XXX updated JsonSchemaTest now the test pulls the latest version of the json file -- XXX deactivated a test class in tx-backend which behaved undesirably - -### Added - -- #1017 added file for CC BY 4.0 license for TRG 7 - -### Changed - -- #1017 updated contributing, notice, and readme files for TRG 7 - ## [11.0.2 - 29.05.2024] ### Added - #1010 Made submodel path configurable diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/mapping/submodel/PartSiteInformationAsPlannedMapper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/mapping/submodel/PartSiteInformationAsPlannedMapper.java index 35212cbb4a..1a6cf2fe2e 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/mapping/submodel/PartSiteInformationAsPlannedMapper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/mapping/submodel/PartSiteInformationAsPlannedMapper.java @@ -55,7 +55,7 @@ private static List extractDetailAspectModelsPartSiteInformat List detailAspectModels = new ArrayList<>(); emptyIfNull(sites).forEach(site -> { DetailAspectDataPartSiteInformationAsPlanned detailAspectDataPartSiteInformationAsPlanned = DetailAspectDataPartSiteInformationAsPlanned.builder() - .catenaXSiteId(site.catenaXSiteId()) + .catenaXSiteId(site.catenaXsiteId()) .functionValidFrom(site.functionValidFrom().toOffsetDateTime()) .function(site.function()) .functionValidUntil(site.functionValidUntil().toOffsetDateTime()) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/EdcNotificationServiceImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/EdcNotificationServiceImpl.java index c688f8ef00..83e0aa012b 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/EdcNotificationServiceImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/EdcNotificationServiceImpl.java @@ -86,7 +86,7 @@ public CompletableFuture asyncNotificationMessageExecutor(N return CompletableFuture.completedFuture(null); } catch (DiscoveryFinderException discoveryFinderException) { - enrichNotificationByError(discoveryFinderException, notification); + enrichNotificationByError(discoveryFinderException, notification, message); return CompletableFuture.completedFuture(null); } } @@ -97,30 +97,25 @@ private boolean handleSendingNotification(NotificationMessage message, String se return true; } catch (NoCatalogItemException e) { log.warn("Could not send message to {} no catalog item found. ", receiverUrl, e); - enrichNotificationByError(e, notification); + enrichNotificationByError(e, notification, message); } catch (SendNotificationException e) { log.warn("Could not send message to {} ", receiverUrl, e); - enrichNotificationByError(e, notification); + enrichNotificationByError(e, notification, message); } catch (NoEndpointDataReferenceException e) { log.warn("Could not send message to {} no endpoint data reference found", receiverUrl, e); - enrichNotificationByError(e, notification); + enrichNotificationByError(e, notification, message); } catch (ContractNegotiationException e) { log.warn("Could not send message to {} could not negotiate contract agreement", receiverUrl, e); - enrichNotificationByError(e, notification); + enrichNotificationByError(e, notification, message); } return false; } - private void enrichNotificationByError(Exception e, Notification notification) { + private void enrichNotificationByError(Exception e, Notification notification, NotificationMessage message) { - log.info("Notification for error message enrichment {}", notification); - notification.getNotifications().forEach(message1 -> log.info("Message found {}", message1)); - notification.secondLatestNotifications().forEach(qmMessage -> { - log.info("Message from second latest notification {}", qmMessage); - qmMessage.setErrorMessage(e.getMessage()); - }); - - notificationRepository.updateErrorMessage(notification); + log.info("Notification for error message enrichment {}", message); + message.setErrorMessage(e.getMessage()); + notificationRepository.updateErrorMessage(notification, message); } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationPublisherService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationPublisherService.java index 61d93f15eb..4d8fdfd447 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationPublisherService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationPublisherService.java @@ -36,7 +36,9 @@ import org.eclipse.tractusx.traceability.notification.domain.base.model.exception.NotificationIllegalUpdate; import org.eclipse.tractusx.traceability.notification.domain.notification.exception.NotificationNotFoundException; import org.eclipse.tractusx.traceability.notification.domain.notification.model.StartNotification; +import org.eclipse.tractusx.traceability.notification.domain.notification.repository.NotificationRepository; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.time.Clock; import java.util.List; @@ -56,6 +58,7 @@ public class NotificationPublisherService { private final AssetAsBuiltRepository assetAsBuiltRepository; private final BpnRepository bpnRepository; private final Clock clock; + private final NotificationRepository notificationRepository; public Notification startNotification(StartNotification startNotification) { @@ -63,7 +66,8 @@ public Notification startNotification(StartNotification startNotification) { return Notification.startNotification(startNotification.getTitle(), clock.instant(), applicationBPN, startNotification.getDescription(), startNotification.getType(), startNotification.getSeverity(), startNotification.getTargetDate(), startNotification.getAffectedPartIds(), List.of(startNotification.getReceiverBpn()), startNotification.getReceiverBpn()); } - private void createMessages(Notification notification, BPN applicationBPN, AssetAsBuiltRepository assetAsBuiltRepository) { + @Transactional + public void createMessages(Notification notification, BPN applicationBPN, AssetAsBuiltRepository assetAsBuiltRepository) { Map> assetsAsBuiltBPNMap = assetAsBuiltRepository .getAssetsById(notification.getAffectedPartIds()) @@ -90,6 +94,7 @@ private void createMessages(Notification notification, BPN applicationBPN, Asset sendToName); }) .forEach(notification::addNotificationMessage); + notificationRepository.updateNotificationAndMessage(notification); } private String getManufacturerNameByBpn(String bpn) { diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/notification/repository/NotificationRepository.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/notification/repository/NotificationRepository.java index 2ad016bbd6..3607540683 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/notification/repository/NotificationRepository.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/notification/repository/NotificationRepository.java @@ -26,6 +26,7 @@ import org.eclipse.tractusx.traceability.common.model.SearchCriteria; import org.eclipse.tractusx.traceability.notification.domain.base.model.Notification; import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationId; +import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationMessage; import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationSide; import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationType; import org.springframework.data.domain.Pageable; @@ -53,7 +54,7 @@ public interface NotificationRepository { List getDistinctFieldValues(String fieldName, String startWith, Integer resultLimit, NotificationSide owner); - void updateErrorMessage(Notification investigation); + void updateErrorMessage(Notification notification, NotificationMessage message); void deleteByIdIn(List messageIds); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/repository/JpaNotificationMessageRepository.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/repository/JpaNotificationMessageRepository.java index e7d01e536f..7b609f0755 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/repository/JpaNotificationMessageRepository.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/repository/JpaNotificationMessageRepository.java @@ -22,7 +22,12 @@ import org.eclipse.tractusx.traceability.notification.infrastructure.notification.model.NotificationMessageEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; @Repository public interface JpaNotificationMessageRepository extends JpaRepository { + @Transactional + default NotificationMessageEntity updateOrInsert(NotificationMessageEntity notificationMessageEntity) { + return save(notificationMessageEntity); + } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/repository/NotificationRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/repository/NotificationRepositoryImpl.java index 0268b78681..61cd89e7fe 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/repository/NotificationRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/repository/NotificationRepositoryImpl.java @@ -21,7 +21,6 @@ import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; -import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.traceability.assets.domain.base.model.Owner; @@ -48,6 +47,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; import java.time.Clock; import java.time.LocalDateTime; @@ -163,19 +163,17 @@ public List getDistinctFieldValues(String fieldName, String startWith, I } @Override - public void updateErrorMessage(Notification notification) { + public void updateErrorMessage(Notification notification, NotificationMessage message) { log.info("Starting update of error message with notification {}", notification); NotificationEntity notificationEntity = jpaNotificationRepository.findById(notification.getNotificationId().value()) .orElseThrow(() -> new IllegalArgumentException(String.format("Notification with id %s not found!", notification.getNotificationId().value()))); - for (NotificationMessage notificationMessage : notification.getNotifications()) { - List assetEntitiesByNotification = getAssetEntitiesByNotification(notification); - NotificationMessageEntity notificationMessageEntity = toNotificationMessageEntity(notificationEntity, notificationMessage, assetEntitiesByNotification); - notificationMessageEntity.setErrorMessage(notificationMessage.getErrorMessage()); - notificationMessageEntity.setUpdated(LocalDateTime.ofInstant(clock.instant(), clock.getZone())); - jpaNotificationMessageRepository.save(notificationMessageEntity); - } - jpaNotificationRepository.save(notificationEntity); + + List assetEntitiesByNotification = getAssetEntitiesByNotification(notification); + NotificationMessageEntity notificationMessageEntity = toNotificationMessageEntity(notificationEntity, message, assetEntitiesByNotification); + notificationMessageEntity.setErrorMessage(message.getErrorMessage()); + notificationMessageEntity.setUpdated(LocalDateTime.ofInstant(clock.instant(), clock.getZone())); + jpaNotificationMessageRepository.updateOrInsert(notificationMessageEntity); } @Override diff --git a/tx-backend/src/main/resources/application.yml b/tx-backend/src/main/resources/application.yml index a153ddb0e2..bf10c993ea 100644 --- a/tx-backend/src/main/resources/application.yml +++ b/tx-backend/src/main/resources/application.yml @@ -102,7 +102,7 @@ management: spring: jpa: - show-sql: false + show-sql: true properties: hibernate: format_sql: true diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyNotSupportedIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyNotSupportedIT.java new file mode 100644 index 0000000000..7bfcffd6b2 --- /dev/null +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyNotSupportedIT.java @@ -0,0 +1,152 @@ +/******************************************************************************** + * Copyright (c) 2024 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.integration.notification.investigation; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.restassured.http.ContentType; +import lombok.val; +import notification.request.NotificationSeverityRequest; +import notification.request.NotificationTypeRequest; +import notification.request.StartNotificationRequest; +import org.eclipse.tractusx.traceability.assets.domain.asbuilt.repository.AssetAsBuiltRepository; +import org.eclipse.tractusx.traceability.common.request.OwnPageable; +import org.eclipse.tractusx.traceability.common.request.PageableFilterRequest; +import org.eclipse.tractusx.traceability.common.request.SearchCriteriaRequestParam; +import org.eclipse.tractusx.traceability.integration.IntegrationTestSpecification; +import org.eclipse.tractusx.traceability.integration.common.support.AssetsSupport; +import org.eclipse.tractusx.traceability.integration.common.support.DiscoveryFinderSupport; +import org.eclipse.tractusx.traceability.integration.common.support.EdcSupport; +import org.eclipse.tractusx.traceability.integration.common.support.IrsApiSupport; +import org.eclipse.tractusx.traceability.integration.common.support.NotificationApiSupport; +import org.eclipse.tractusx.traceability.integration.common.support.NotificationMessageSupport; +import org.eclipse.tractusx.traceability.integration.common.support.NotificationSupport; +import org.eclipse.tractusx.traceability.integration.common.support.OAuth2ApiSupport; +import org.eclipse.tractusx.traceability.notification.domain.notification.service.NotificationReceiverService; +import org.hamcrest.Matchers; +import org.jose4j.lang.JoseException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; + +import java.util.Collections; +import java.util.List; + +import static io.restassured.RestAssured.given; +import static org.eclipse.tractusx.traceability.common.security.JwtRole.SUPERVISOR; + +public class InvestigationPolicyNotSupportedIT extends IntegrationTestSpecification { + @Autowired + NotificationReceiverService notificationReceiverService; + @Autowired + AssetsSupport assetsSupport; + @Autowired + NotificationMessageSupport notificationMessageSupport; + @Autowired + NotificationSupport notificationSupport; + @Autowired + AssetAsBuiltRepository assetAsBuiltRepository; + @Autowired + NotificationApiSupport notificationApiSupport; + @Autowired + EdcSupport edcSupport; + + @Autowired + DiscoveryFinderSupport discoveryFinderSupport; + + @Autowired + OAuth2ApiSupport oauth2ApiSupport; + + @Autowired + IrsApiSupport irsApiSupport; + + ObjectMapper objectMapper; + + + @DynamicPropertySource + static void dynamicProperties(DynamicPropertyRegistry registry) { + registry.add("traceability.leftOperand", () -> "unsopperted operand"); + registry.add("server.port", () -> "9996"); + registry.add("management.server.port", () -> "8084"); + } + + @BeforeEach + void setUp() { + objectMapper = new ObjectMapper(); + } + + @Test + void shouldNotApproveInvestigationStatus_whenPolicyDoesNotComply() throws JoseException, com.fasterxml.jackson.core.JsonProcessingException { + // given + irsApiSupport.irsApiReturnsPolicies(); + discoveryFinderSupport.discoveryFinderWillReturnEndpointAddress(); + discoveryFinderSupport.discoveryFinderWillReturnConnectorEndpoints(); + oauth2ApiSupport.oauth2ApiReturnsDtrToken(); + edcSupport.performSupportActionsForAsyncNotificationMessageExecutor(); + List partIds = List.of( + "urn:uuid:fe99da3d-b0de-4e80-81da-882aebcca978", // BPN: BPNL00000003AYRE + "urn:uuid:0ce83951-bc18-4e8f-892d-48bad4eb67ef" // BPN: BPNL00000003AXS3 + ); + String description = "at least 15 characters long investigation description"; + + assetsSupport.defaultAssetsStored(); + val startInvestigationRequest = StartNotificationRequest.builder() + .affectedPartIds(partIds) + .description(description) + .severity(NotificationSeverityRequest.MINOR) + .type(NotificationTypeRequest.INVESTIGATION) + .receiverBpn("BPNL00000003CNKC") + .build(); + + // when + val investigationId = notificationApiSupport.createNotificationRequest_withDefaultAssetsStored(oAuth2Support.jwtAuthorization(SUPERVISOR), startInvestigationRequest, 201); + + + notificationSupport.assertInvestigationsSize(1); + + given() + .contentType(ContentType.JSON) + .header(oAuth2Support.jwtAuthorization(SUPERVISOR)) + .when() + .post("/api/notifications/{investigationId}/approve", investigationId) + .then() + .log().all() + .statusCode(503); + + // then + given() + .header(oAuth2Support.jwtAuthorization(SUPERVISOR)) + .body(new PageableFilterRequest(new OwnPageable(0, 10, Collections.emptyList()), new SearchCriteriaRequestParam(List.of("channel,EQUAL,SENDER,AND")))) + .contentType(ContentType.JSON) + .when() + .post("/api/notifications/filter") + .then() + .log().all() + .statusCode(200) + .body("page", Matchers.is(0)) + .body("pageSize", Matchers.is(10)) + .body("content", Matchers.hasSize(1)) + .body("content[0].sendTo", Matchers.is(Matchers.not(Matchers.blankOrNullString()))) + .body("content[0].messages[0].errorMessage", Matchers.is("Failed to negotiate contract agreement: Consumption of asset '40276218-e31b-4c35-a7c8-017e8edb702e' is not permitted as the required catalog offer policies do not comply with defined policies.")) + .body("content[0].messages[1].errorMessage", Matchers.is("Failed to negotiate contract agreement: Consumption of asset '40276218-e31b-4c35-a7c8-017e8edb702e' is not permitted as the required catalog offer policies do not comply with defined policies.")); + + notificationMessageSupport.assertMessageSize(2); + } +} diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/notification/infrastructure/investigation/repository/InvestigationsRepositoryImplTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/notification/infrastructure/investigation/repository/InvestigationsRepositoryImplTest.java index 6d2c18df08..979af1cda0 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/notification/infrastructure/investigation/repository/InvestigationsRepositoryImplTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/notification/infrastructure/investigation/repository/InvestigationsRepositoryImplTest.java @@ -78,9 +78,9 @@ void updateErrorMessage() { when(clock.instant()).thenReturn(Instant.now()); when(clock.getZone()).thenReturn(ZoneId.systemDefault()); // When - investigationsRepository.updateErrorMessage(notification); + investigationsRepository.updateErrorMessage(notification, message); // Then - verify(jpaNotificationMessageRepository, times(1)).save(any()); + verify(jpaNotificationMessageRepository, times(1)).updateOrInsert(any()); } } diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/notification/infrastructure/investigation/repository/NotificationRepositoryImplTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/notification/infrastructure/investigation/repository/NotificationRepositoryImplTest.java index a40606cf15..4699938753 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/notification/infrastructure/investigation/repository/NotificationRepositoryImplTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/notification/infrastructure/investigation/repository/NotificationRepositoryImplTest.java @@ -78,9 +78,9 @@ void updateErrorMessage() { when(clock.instant()).thenReturn(Instant.now()); when(clock.getZone()).thenReturn(ZoneId.systemDefault()); // When - notificationRepository.updateErrorMessage(notification); + notificationRepository.updateErrorMessage(notification, message); // Then - verify(jpaNotificationMessageRepository, times(1)).save(any()); + verify(jpaNotificationMessageRepository, times(1)).updateOrInsert(any()); } } From e86bfbad1b90cbf1e280fdff5a22479baf02d6eb Mon Sep 17 00:00:00 2001 From: ds-lcapellino Date: Fri, 28 Jun 2024 13:28:15 +0200 Subject: [PATCH 07/14] feature: #639 test --- .../domain/base/exception/ContractNegotiationException.java | 1 - .../investigation/PublisherInvestigationsControllerIT.java | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/exception/ContractNegotiationException.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/exception/ContractNegotiationException.java index 0b210b77c7..d1eac30166 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/exception/ContractNegotiationException.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/exception/ContractNegotiationException.java @@ -20,7 +20,6 @@ package org.eclipse.tractusx.traceability.notification.domain.base.exception; public class ContractNegotiationException extends RuntimeException { - public ContractNegotiationException(final String message, final Throwable exception) { super(message, exception); } diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/PublisherInvestigationsControllerIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/PublisherInvestigationsControllerIT.java index 8738005e7b..62b1a927c3 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/PublisherInvestigationsControllerIT.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/PublisherInvestigationsControllerIT.java @@ -591,4 +591,5 @@ void shouldBeCreatedBySender() throws JoseException, JsonProcessingException { .body("pageSize", Matchers.is(10)) .body("content", Matchers.hasSize(1)); } + } From 19fc8e9db45415349c43000c36f0933451331ef2 Mon Sep 17 00:00:00 2001 From: ds-lcapellino Date: Fri, 28 Jun 2024 14:08:54 +0200 Subject: [PATCH 08/14] feature: #639 test --- .../infrastructure/repository/ContractRepositoryImpl.java | 2 ++ .../domain/base/service/NotificationPublisherService.java | 5 ----- .../notification/repository/NotificationRepositoryImpl.java | 1 - 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImpl.java index 32bcc62aae..c545522a5b 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImpl.java @@ -39,6 +39,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; import java.time.Instant; import java.time.OffsetDateTime; @@ -88,6 +89,7 @@ public PageResult getContractsByPageable(Pageable pageable, SearchCrit } @Override + @Transactional public void saveAllContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException { List contractAgreementEntities = contractAgreementIds.stream() diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationPublisherService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationPublisherService.java index 4d8fdfd447..65649437f8 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationPublisherService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationPublisherService.java @@ -36,9 +36,7 @@ import org.eclipse.tractusx.traceability.notification.domain.base.model.exception.NotificationIllegalUpdate; import org.eclipse.tractusx.traceability.notification.domain.notification.exception.NotificationNotFoundException; import org.eclipse.tractusx.traceability.notification.domain.notification.model.StartNotification; -import org.eclipse.tractusx.traceability.notification.domain.notification.repository.NotificationRepository; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import java.time.Clock; import java.util.List; @@ -58,7 +56,6 @@ public class NotificationPublisherService { private final AssetAsBuiltRepository assetAsBuiltRepository; private final BpnRepository bpnRepository; private final Clock clock; - private final NotificationRepository notificationRepository; public Notification startNotification(StartNotification startNotification) { @@ -66,7 +63,6 @@ public Notification startNotification(StartNotification startNotification) { return Notification.startNotification(startNotification.getTitle(), clock.instant(), applicationBPN, startNotification.getDescription(), startNotification.getType(), startNotification.getSeverity(), startNotification.getTargetDate(), startNotification.getAffectedPartIds(), List.of(startNotification.getReceiverBpn()), startNotification.getReceiverBpn()); } - @Transactional public void createMessages(Notification notification, BPN applicationBPN, AssetAsBuiltRepository assetAsBuiltRepository) { Map> assetsAsBuiltBPNMap = assetAsBuiltRepository @@ -94,7 +90,6 @@ public void createMessages(Notification notification, BPN applicationBPN, AssetA sendToName); }) .forEach(notification::addNotificationMessage); - notificationRepository.updateNotificationAndMessage(notification); } private String getManufacturerNameByBpn(String bpn) { diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/repository/NotificationRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/repository/NotificationRepositoryImpl.java index 61cd89e7fe..7ceae9ac47 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/repository/NotificationRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/repository/NotificationRepositoryImpl.java @@ -168,7 +168,6 @@ public void updateErrorMessage(Notification notification, NotificationMessage me NotificationEntity notificationEntity = jpaNotificationRepository.findById(notification.getNotificationId().value()) .orElseThrow(() -> new IllegalArgumentException(String.format("Notification with id %s not found!", notification.getNotificationId().value()))); - List assetEntitiesByNotification = getAssetEntitiesByNotification(notification); NotificationMessageEntity notificationMessageEntity = toNotificationMessageEntity(notificationEntity, message, assetEntitiesByNotification); notificationMessageEntity.setErrorMessage(message.getErrorMessage()); From 5568cbf768871dd865debf5c4b8ca9d44683deae Mon Sep 17 00:00:00 2001 From: ds-lcapellino Date: Fri, 28 Jun 2024 14:32:08 +0200 Subject: [PATCH 09/14] feature: #639 fix integration tests --- pom.xml | 2 +- .../infrastructure/repository/ContractRepositoryImpl.java | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 5e57f56977..6311f125bc 100644 --- a/pom.xml +++ b/pom.xml @@ -90,7 +90,7 @@ SPDX-License-Identifier: Apache-2.0 5.10.2 4.2.1 - 2.1.0-SNAPSHOT + 2.1.0 5.4.0 jacoco diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImpl.java index c545522a5b..32bcc62aae 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImpl.java @@ -39,7 +39,6 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; import java.time.Instant; import java.time.OffsetDateTime; @@ -89,7 +88,6 @@ public PageResult getContractsByPageable(Pageable pageable, SearchCrit } @Override - @Transactional public void saveAllContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException { List contractAgreementEntities = contractAgreementIds.stream() From fa8349b8c407184e3f95e180711779008d92a0ad Mon Sep 17 00:00:00 2001 From: ds-lcapellino Date: Fri, 28 Jun 2024 14:40:29 +0200 Subject: [PATCH 10/14] feature: #639 don't show sql --- tx-backend/src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tx-backend/src/main/resources/application.yml b/tx-backend/src/main/resources/application.yml index bf10c993ea..a153ddb0e2 100644 --- a/tx-backend/src/main/resources/application.yml +++ b/tx-backend/src/main/resources/application.yml @@ -102,7 +102,7 @@ management: spring: jpa: - show-sql: true + show-sql: false properties: hibernate: format_sql: true From bf9db9f1914925412a46f9700d2819cf75c631cd Mon Sep 17 00:00:00 2001 From: ds-lcapellino Date: Mon, 1 Jul 2024 09:30:41 +0200 Subject: [PATCH 11/14] feature: #639 refactor --- .../domain/base/service/AbstractNotificationService.java | 2 +- .../domain/base/service/NotificationPublisherService.java | 2 +- .../edc/blackbox/NotificationsEDCFacadeTest.java | 4 ---- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/AbstractNotificationService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/AbstractNotificationService.java index 27c081763d..de46d594dc 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/AbstractNotificationService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/AbstractNotificationService.java @@ -156,7 +156,7 @@ public void approve(Long notificationId) { approvedInvestigation = notificationPublisherService.approveNotification(notification); } catch (SendNotificationException exception) { log.info("Notification status rollback", exception); - throw new SendNotificationException(exception.getMessage()); + throw new SendNotificationException(exception.getMessage(), exception); } getNotificationRepository().updateNotification(approvedInvestigation); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationPublisherService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationPublisherService.java index 65649437f8..61d93f15eb 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationPublisherService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationPublisherService.java @@ -63,7 +63,7 @@ public Notification startNotification(StartNotification startNotification) { return Notification.startNotification(startNotification.getTitle(), clock.instant(), applicationBPN, startNotification.getDescription(), startNotification.getType(), startNotification.getSeverity(), startNotification.getTargetDate(), startNotification.getAffectedPartIds(), List.of(startNotification.getReceiverBpn()), startNotification.getReceiverBpn()); } - public void createMessages(Notification notification, BPN applicationBPN, AssetAsBuiltRepository assetAsBuiltRepository) { + private void createMessages(Notification notification, BPN applicationBPN, AssetAsBuiltRepository assetAsBuiltRepository) { Map> assetsAsBuiltBPNMap = assetAsBuiltRepository .getAssetsById(notification.getAffectedPartIds()) diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NotificationsEDCFacadeTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NotificationsEDCFacadeTest.java index 9bfee5f24e..a74104197b 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NotificationsEDCFacadeTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/NotificationsEDCFacadeTest.java @@ -63,12 +63,8 @@ class NotificationsEDCFacadeTest { @Mock EndpointDataReferenceStorage endpointDataReferenceStorage; @Mock - PolicyCheckerService policyCheckerService; - @Mock EndpointDataReference endpointDataReference; @Mock - NotificationRepository notificationRepository; - @Mock Notification notification; @InjectMocks NotificationsEDCFacade notificationsEDCFacade; From 8e229fd3707dbaee91d32a6ba232cc9fe39c6099 Mon Sep 17 00:00:00 2001 From: ds-lcapellino Date: Mon, 1 Jul 2024 15:46:17 +0200 Subject: [PATCH 12/14] feature: #639 update irs-client-lib.version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6311f125bc..a6a0a63547 100644 --- a/pom.xml +++ b/pom.xml @@ -90,7 +90,7 @@ SPDX-License-Identifier: Apache-2.0 5.10.2 4.2.1 - 2.1.0 + 2.1.1-SNAPSHOT 5.4.0 jacoco From 1d7215eae17f014e7d1c1dccfa3c8184bb3c782f Mon Sep 17 00:00:00 2001 From: ds-lcapellino Date: Tue, 2 Jul 2024 12:47:31 +0200 Subject: [PATCH 13/14] feature: #639 update irs-client-lib.version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a6a0a63547..d3dede946f 100644 --- a/pom.xml +++ b/pom.xml @@ -90,7 +90,7 @@ SPDX-License-Identifier: Apache-2.0 5.10.2 4.2.1 - 2.1.1-SNAPSHOT + 2.1.1 5.4.0 jacoco From 5659c08180ca3997255d92de489c4110a0420dff Mon Sep 17 00:00:00 2001 From: ds-lcapellino Date: Tue, 2 Jul 2024 13:03:25 +0200 Subject: [PATCH 14/14] feature: #639 fix integration tests --- .../investigation/InvestigationPolicyExpirationIT.java | 4 ++-- .../investigation/InvestigationPolicyNotSupportedIT.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyExpirationIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyExpirationIT.java index 3a16136d44..9b8c3ea1e6 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyExpirationIT.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyExpirationIT.java @@ -144,8 +144,8 @@ void shouldNotApproveInvestigationStatus_whenPolicyIsExpired() throws JoseExcept .body("pageSize", Matchers.is(10)) .body("content", Matchers.hasSize(1)) .body("content[0].sendTo", Matchers.is(Matchers.not(Matchers.blankOrNullString()))) - .body("content[0].messages[0].errorMessage", Matchers.is("Failed to negotiate contract agreement: Consumption of asset '40276218-e31b-4c35-a7c8-017e8edb702e' is not permitted as the required catalog offer policies are expired.")) - .body("content[0].messages[1].errorMessage", Matchers.is("Failed to negotiate contract agreement: Consumption of asset '40276218-e31b-4c35-a7c8-017e8edb702e' is not permitted as the required catalog offer policies are expired.")); + .body("content[0].messages[0].errorMessage", Matchers.is("Failed to negotiate contract agreement: Policy from BPNL00000003CNKC has expired.")) + .body("content[0].messages[1].errorMessage", Matchers.is("Failed to negotiate contract agreement: Policy from BPNL00000003CNKC has expired.")); notificationMessageSupport.assertMessageSize(2); } diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyNotSupportedIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyNotSupportedIT.java index 7bfcffd6b2..335210a109 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyNotSupportedIT.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/InvestigationPolicyNotSupportedIT.java @@ -144,8 +144,8 @@ void shouldNotApproveInvestigationStatus_whenPolicyDoesNotComply() throws JoseEx .body("pageSize", Matchers.is(10)) .body("content", Matchers.hasSize(1)) .body("content[0].sendTo", Matchers.is(Matchers.not(Matchers.blankOrNullString()))) - .body("content[0].messages[0].errorMessage", Matchers.is("Failed to negotiate contract agreement: Consumption of asset '40276218-e31b-4c35-a7c8-017e8edb702e' is not permitted as the required catalog offer policies do not comply with defined policies.")) - .body("content[0].messages[1].errorMessage", Matchers.is("Failed to negotiate contract agreement: Consumption of asset '40276218-e31b-4c35-a7c8-017e8edb702e' is not permitted as the required catalog offer policies do not comply with defined policies.")); + .body("content[0].messages[0].errorMessage", Matchers.endsWith("did not match with policy from BPNL00000003CNKC.")) + .body("content[0].messages[1].errorMessage", Matchers.endsWith("did not match with policy from BPNL00000003CNKC.")); notificationMessageSupport.assertMessageSize(2); }