From 44fc124d91f03bc728d5292be87d97241e9d6bdc Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Thu, 27 Jun 2024 10:48:59 +0200 Subject: [PATCH 1/2] feature(chore):985 added filter mechanism to filter for notifiations by contractAgreementId --- .../mapper/ContractFieldMapper.java | 5 +-- ...ntroller.java => ContractsController.java} | 2 +- .../mapper/NotificationFieldMapper.java | 1 + .../support/NotificationApiSupport.java | 16 +++------- ...llerIT.java => ContractsControllerIT.java} | 31 ++++++++++++++++--- ...EdcNotificationContractsControllerIT.java} | 12 +++---- .../notification/EditNotificationIT.java | 15 +++++++-- .../PublisherInvestigationsControllerIT.java | 13 +++++++- 8 files changed, 66 insertions(+), 29 deletions(-) rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/{ContractController.java => ContractsController.java} (99%) rename tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/{ContractControllerIT.java => ContractsControllerIT.java} (81%) rename tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/edc/notificationcontract/{EdcNotificationContractControllerIT.java => EdcNotificationContractsControllerIT.java} (98%) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/mapper/ContractFieldMapper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/mapper/ContractFieldMapper.java index 25bb7b6509..f1f0d3b1fe 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/mapper/ContractFieldMapper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/mapper/ContractFieldMapper.java @@ -28,8 +28,9 @@ public class ContractFieldMapper extends BaseRequestFieldMapper { private static final Map SUPPORTED_CONTRACT_FILTER_FIELDS = Map.ofEntries( Map.entry("created", "created"), Map.entry("id", "id"), - Map.entry("contractId", "contractAgreementId") - ); + Map.entry("contractId", "contractAgreementId"), + Map.entry("contractType", "type") + ); @Override protected Map getSupportedFields() { diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/ContractController.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/ContractsController.java similarity index 99% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/ContractController.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/ContractsController.java index 924e4d1ab8..d79e28cb26 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/ContractController.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/ContractsController.java @@ -44,7 +44,7 @@ @PreAuthorize("hasAnyRole('ROLE_ADMIN', 'ROLE_SUPERVISOR')") @Tag(name = "Contracts") @RequestMapping(path = "/contracts", produces = "application/json", consumes = "application/json") -public class ContractController { +public class ContractsController { private final ContractService contractService; @Operation(operationId = "contracts", diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/application/notification/mapper/NotificationFieldMapper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/application/notification/mapper/NotificationFieldMapper.java index 88e5a07c67..c356a29372 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/application/notification/mapper/NotificationFieldMapper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/application/notification/mapper/NotificationFieldMapper.java @@ -45,6 +45,7 @@ public class NotificationFieldMapper extends BaseRequestFieldMapper { Map.entry("sendToName", "messages_sendToName"), Map.entry("targetDate", "targetDate"), Map.entry("assetId", "assets_id"), + Map.entry("contractAgreementId", "messages_contractAgreementId"), Map.entry("title", "title"), Map.entry("type", "type") diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/NotificationApiSupport.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/NotificationApiSupport.java index 7fc3947c93..2e9ec8f099 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/NotificationApiSupport.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/NotificationApiSupport.java @@ -20,29 +20,20 @@ package org.eclipse.tractusx.traceability.integration.common.support; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import io.restassured.common.mapper.TypeRef; import io.restassured.http.ContentType; import io.restassured.http.Header; import io.restassured.response.Response; -import io.restassured.response.ResponseBody; import lombok.RequiredArgsConstructor; import notification.request.EditNotificationRequest; import notification.request.StartNotificationRequest; import notification.response.NotificationResponse; import org.eclipse.tractusx.traceability.common.model.PageResult; -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.hamcrest.Matchers; import org.springframework.stereotype.Component; -import java.util.Collections; -import java.util.List; - import static io.restassured.RestAssured.given; -import static org.eclipse.tractusx.traceability.common.security.JwtRole.SUPERVISOR; @Component @RequiredArgsConstructor @@ -84,10 +75,10 @@ public void editNotificationRequest(Header authHeader, EditNotificationRequest e .statusCode(expectedStatusCode); } - public PageResult getNotificationsRequest(Header authHeader){ + public PageResult getNotificationsRequest(Header authHeader, PageableFilterRequest pageableFilterRequest) { Response response = given() .header(authHeader) - .body(new PageableFilterRequest(new OwnPageable(0, 10, Collections.emptyList()), new SearchCriteriaRequestParam(List.of("channel,EQUAL,SENDER,AND")))) + .body(pageableFilterRequest) .contentType(ContentType.JSON) .when() .post("/api/notifications/filter") @@ -95,7 +86,8 @@ public PageResult getNotificationsRequest(Header authHeade .statusCode(200) .extract().response(); - return response.as(new TypeRef>() {}); + return response.as(new TypeRef>() { + }); } } diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractControllerIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractsControllerIT.java similarity index 81% rename from tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractControllerIT.java rename to tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractsControllerIT.java index 3a2561f1ff..fff7cbd8c4 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractControllerIT.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractsControllerIT.java @@ -22,25 +22,22 @@ import io.restassured.common.mapper.TypeRef; import io.restassured.http.ContentType; import org.eclipse.tractusx.traceability.common.model.PageResult; -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.EdcSupport; import org.jose4j.lang.JoseException; -import org.junit.Ignore; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import java.util.ArrayList; import java.util.List; import static io.restassured.RestAssured.given; import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.tractusx.traceability.common.security.JwtRole.ADMIN; -class ContractControllerIT extends IntegrationTestSpecification { +class ContractsControllerIT extends IntegrationTestSpecification { @Autowired AssetsSupport assetsSupport; @@ -98,6 +95,32 @@ void shouldReturnOnlyOneContract() throws JoseException { assertThat(contractResponsePageResult.content().get(0).getCounterpartyAddress()).isNotEmpty(); } + @Test + void shouldReturnContractsWithNotificationType() throws JoseException { + //GIVEN + edcSupport.edcWillReturnOnlyOneContractAgreement(); + edcSupport.edcWillReturnContractAgreementNegotiation(); + assetsSupport.defaultAssetsStored(); + + //WHEN + PageResult contractResponsePageResult = given() + .header(oAuth2Support.jwtAuthorization(ADMIN)) + .contentType(ContentType.JSON) + .log().all() + .when() + .body(PageableFilterRequest.builder().searchCriteriaRequestParam(SearchCriteriaRequestParam.builder().filter(List.of("contractType,EQUAL,ASSET_AS_BUILT,AND")).build()).build()) + .post("/api/contracts") + .then() + .log().all() + .statusCode(200) + .extract().body().as(new TypeRef<>() { + }); + //THEN + assertThat(contractResponsePageResult.content()).isNotEmpty(); + assertThat(contractResponsePageResult.content().get(0).getCounterpartyAddress()).isNotEmpty(); + } + + @Test void shouldReturnEmptyIfAssetIdIsUnknown() throws JoseException { //GIVEN diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/edc/notificationcontract/EdcNotificationContractControllerIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/edc/notificationcontract/EdcNotificationContractsControllerIT.java similarity index 98% rename from tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/edc/notificationcontract/EdcNotificationContractControllerIT.java rename to tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/edc/notificationcontract/EdcNotificationContractsControllerIT.java index 89c26de56e..3af135cf9d 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/edc/notificationcontract/EdcNotificationContractControllerIT.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/edc/notificationcontract/EdcNotificationContractsControllerIT.java @@ -40,12 +40,12 @@ import static org.hamcrest.Matchers.not; import static org.junit.jupiter.params.provider.Arguments.arguments; -public class EdcNotificationContractControllerIT extends IntegrationTestSpecification { +public class EdcNotificationContractsControllerIT extends IntegrationTestSpecification { @Autowired EdcSupport edcSupport; -// @Test + // @Test void shouldCreateEdcContract() throws JoseException { // given edcSupport.edcWillCreateNotificationAsset(); @@ -81,7 +81,7 @@ void shouldCreateEdcContract() throws JoseException { edcSupport.verifyDeleteContractDefinitionEndpointCalledTimes(0); } -// @Test + // @Test void shouldNotCreateEdcContractWhenNotificationAssetCreationFailed() throws JoseException { // given edcSupport.edcWillFailToCreateNotificationAsset(); @@ -114,7 +114,7 @@ void shouldNotCreateEdcContractWhenNotificationAssetCreationFailed() throws Jose } -// @Test + // @Test void shouldNotCreateEdcContractAndDoRollbackWhenPolicyDefinitionCreationFailed() throws JoseException { // given edcSupport.edcWillCreateNotificationAsset(); @@ -149,7 +149,7 @@ void shouldNotCreateEdcContractAndDoRollbackWhenPolicyDefinitionCreationFailed() edcSupport.verifyDeleteContractDefinitionEndpointCalledTimes(0); } -// @Test + // @Test void shouldNotCreateEdcContractAndDoRollbackWhenContractDefinitionCreationFailed() throws JoseException { // given edcSupport.edcWillCreateNotificationAsset(); @@ -266,7 +266,7 @@ void shouldNotCreateEdcContractWithInvalidRequest( .statusCode(400); } -// @Test + // @Test void shouldNotCreateEdcContractForQualityAlertBecauseItsNotYetImplemented() throws JoseException { given() .contentType(ContentType.JSON) diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/EditNotificationIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/EditNotificationIT.java index 912781fb1f..34de7a02fd 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/EditNotificationIT.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/EditNotificationIT.java @@ -186,8 +186,14 @@ void shouldUpdateInvestigationFields() throws JsonProcessingException, JoseExcep // then notificationMessageSupport.assertMessageSize(0); + PageableFilterRequest pageableFilterRequest = + new PageableFilterRequest( + new OwnPageable(0, 10, Collections.emptyList()), + new SearchCriteriaRequestParam(List.of("channel,EQUAL,SENDER,AND"))); + PageResult notificationResponsePageResult - = notificationAPISupport.getNotificationsRequest(authHeader); + = notificationAPISupport.getNotificationsRequest(authHeader, pageableFilterRequest); + NotificationResponse notificationResponse = notificationResponsePageResult.content().get(0); assertThat(notificationResponse.getId()).isEqualTo(id); @@ -239,9 +245,12 @@ void shouldNotUpdateInvestigationFields_whenBpnWrongFormatted() throws JoseExcep notificationAPISupport.editNotificationRequest(authHeader, editNotificationRequest, id, 400); // then - + PageableFilterRequest pageableFilterRequest = + new PageableFilterRequest( + new OwnPageable(0, 10, Collections.emptyList()), + new SearchCriteriaRequestParam(List.of("channel,EQUAL,SENDER,AND"))); PageResult notificationResponsePageResult - = notificationAPISupport.getNotificationsRequest(authHeader); + = notificationAPISupport.getNotificationsRequest(authHeader, pageableFilterRequest); NotificationResponse notificationResponse = notificationResponsePageResult.content().get(0); assertThat(notificationResponse.getSendTo()).isEqualTo("BPNL00000003CNKC"); 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 c61ee8788f..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 @@ -30,9 +30,11 @@ import notification.request.StartNotificationRequest; import notification.request.UpdateNotificationStatusRequest; import notification.request.UpdateNotificationStatusTransitionRequest; +import notification.response.NotificationResponse; import org.apache.commons.lang3.RandomStringUtils; import org.eclipse.tractusx.traceability.assets.domain.asbuilt.repository.AssetAsBuiltRepository; import org.eclipse.tractusx.traceability.assets.domain.base.model.AssetBase; +import org.eclipse.tractusx.traceability.common.model.PageResult; import org.eclipse.tractusx.traceability.common.request.OwnPageable; import org.eclipse.tractusx.traceability.common.request.PageableFilterRequest; import org.eclipse.tractusx.traceability.common.request.SearchCriteriaRequestParam; @@ -137,7 +139,6 @@ void shouldReceiveNotification() { @Test void shouldStartInvestigation() throws JoseException, JsonProcessingException { - // given List partIds = List.of( "urn:uuid:fe99da3d-b0de-4e80-81da-882aebcca978", // BPN: BPNL00000003AYRE @@ -426,9 +427,19 @@ void shouldApproveInvestigationStatus() throws JoseException, JsonProcessingExce .body("content", Matchers.hasSize(1)) .body("content[0].sendTo", Matchers.is(Matchers.not(Matchers.blankOrNullString()))); + String contractAgreementId = "NmYxMjk2ZmUtYmRlZS00ZTViLTk0NzktOWU0YmQyYWYyNGQ3:ZDBjZGUzYjktOWEwMS00N2QzLTgwNTgtOTU2MjgyOGY2ZDBm:YjYxMjcxM2MtNjdkNC00N2JlLWI0NjMtNDdjNjk4YTk1Mjky"; + PageableFilterRequest pageableFilterRequest = + new PageableFilterRequest( + new OwnPageable(0, 10, Collections.emptyList()), + new SearchCriteriaRequestParam(List.of("contractAgreementId,EQUAL," + contractAgreementId + ",AND"))); + + PageResult notificationsRequest = + notificationApiSupport.getNotificationsRequest(oAuth2Support.jwtAuthorization(SUPERVISOR), pageableFilterRequest); + assertThat(notificationsRequest.content().get(0).getMessages().get(0).getContractAgreementId()).isEqualTo(contractAgreementId); notificationMessageSupport.assertMessageSize(2); } + @Test void shouldCloseInvestigationStatus() throws JoseException, JsonProcessingException { // given From a3a22d81c617ca432e17e6ce0f7c36db1cc457b7 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Thu, 27 Jun 2024 10:57:40 +0200 Subject: [PATCH 2/2] feature(chore):985 added filter mechanism to filter for notifiations by contractAgreementId --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6c0c70c0c..6cebc56566 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ _**For better traceability add the corresponding GitHub issue number in each cha - XXX updated local deployment documentation - #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 ### Added - #832 added policymanagement list view, creator and editor