diff --git a/CHANGELOG.md b/CHANGELOG.md index 13f70eb7bf..695419aa27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - DEPENDENCIES_FRONTEND, SECURITY.md, NOTICE.md, LICENSE file to frontend docker image - Added a step-by-step guide to register a server in pgAdmin in the database dump README - Documentation about technical users +- new filtering capabilities ( receivedQualityAlertIdsInStatusActive, sentQualityAlertIdsInStatusActive, receivedQualityInvestigationIdsInStatusActive, sentQualityInvestigationIdsInStatusActive ) ### Changed - Fixed helm repository path for backend & frontend (wrong prefix) @@ -19,6 +20,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Removed - apk upgrade in docker image built as requested by TRG 4.02 +- removed asset filters ( qualityInvestigationIdsInStatusActive, qualityInvestigationIdsInStatusActive ) ## [9.0.0-rc2 - 15.11.2023] ### Added diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltFieldMapper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltFieldMapper.java index 550c9e007a..0db5c4b341 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltFieldMapper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltFieldMapper.java @@ -50,8 +50,10 @@ public class AssetAsBuiltFieldMapper extends BaseRequestFieldMapper { Map.entry("van", "van"), Map.entry("businessPartner", "manufacturerId"), Map.entry("alerts", "alerts"), - Map.entry("qualityAlertIdsInStatusActive", "activeAlertsCount"), - Map.entry("qualityInvestigationIdsInStatusActive", "activeInvestigationsCount") + Map.entry("sentQualityAlertIdsInStatusActive", "sentActiveAlertsCount"), + Map.entry("sentQualityInvestigationIdsInStatusActive", "sentActiveInvestigationsCount"), + Map.entry("receivedQualityAlertIdsInStatusActive", "receivedActiveAlertsCount"), + Map.entry("receivedQualityInvestigationIdsInStatusActive", "receivedActiveInvestigationsCount") ); @Override diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/repository/AssetAsBuildSpecification.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/repository/AssetAsBuildSpecification.java index d7aeff40ca..dd6b4b2676 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/repository/AssetAsBuildSpecification.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/repository/AssetAsBuildSpecification.java @@ -33,6 +33,7 @@ import org.eclipse.tractusx.traceability.qualitynotification.domain.base.model.QualityNotificationStatus; import org.eclipse.tractusx.traceability.qualitynotification.infrastructure.alert.model.AlertEntity; import org.eclipse.tractusx.traceability.qualitynotification.infrastructure.investigation.model.InvestigationEntity; +import org.eclipse.tractusx.traceability.qualitynotification.infrastructure.model.NotificationSideBaseEntity; import org.jetbrains.annotations.NotNull; import org.springframework.data.jpa.domain.Specification; @@ -57,14 +58,28 @@ public Predicate toPredicate(@NotNull Root root, @NotNull Cr private static Predicate activeNotificationCountEqualPredicate(SearchCriteriaFilter criteria, Root root, CriteriaBuilder builder, String expectedFieldValue) { String joinTableName; Class notificationClass; + NotificationSideBaseEntity side; switch (criteria.getKey()) { - case "activeAlertsCount" -> { + case "sentActiveAlertsCount" -> { notificationClass = AlertEntity.class; joinTableName = "alerts"; + side = NotificationSideBaseEntity.SENDER; } - case "activeInvestigationsCount" -> { + case "sentActiveInvestigationsCount" -> { notificationClass = InvestigationEntity.class; joinTableName = "investigations"; + side = NotificationSideBaseEntity.SENDER; + } + case "receivedActiveAlertsCount" -> { + notificationClass = AlertEntity.class; + joinTableName = "alerts"; + side = NotificationSideBaseEntity.RECEIVER; + + } + case "receivedActiveInvestigationsCount" -> { + notificationClass = InvestigationEntity.class; + joinTableName = "investigations"; + side = NotificationSideBaseEntity.RECEIVER; } default -> throw new UnsupportedOperationException(); } @@ -81,6 +96,7 @@ private static Predicate activeNotificationCountEqualPredicate(SearchCriteriaFil builder.or( activeNotificationPredicates(builder, subRoot) ), + notificationSidePredicate(builder, subRoot, side), builder.equal(assetJoin.get("id"), root.get("id"))) ); @@ -94,4 +110,8 @@ private static Predicate[] activeNotificationPredicates(CriteriaBuilder builder, return predicates.toArray(new Predicate[0]); } + + private static Predicate notificationSidePredicate(CriteriaBuilder builder, Root root, NotificationSideBaseEntity side) { + return builder.equal(root.get("side").as(String.class), side.name()); + } } diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/assets/AssetAsBuiltControllerFilteringIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/assets/AssetAsBuiltControllerFilteringIT.java index f1a90cae8c..951fe3cec9 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/assets/AssetAsBuiltControllerFilteringIT.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/assets/AssetAsBuiltControllerFilteringIT.java @@ -26,6 +26,7 @@ import org.eclipse.tractusx.traceability.integration.common.support.AlertsSupport; import org.eclipse.tractusx.traceability.integration.common.support.AssetsSupport; import org.eclipse.tractusx.traceability.integration.common.support.InvestigationsSupport; +import org.eclipse.tractusx.traceability.qualitynotification.infrastructure.model.NotificationSideBaseEntity; import org.jose4j.lang.JoseException; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -34,6 +35,8 @@ import static io.restassured.RestAssured.given; import static org.eclipse.tractusx.traceability.common.security.JwtRole.ADMIN; +import static org.eclipse.tractusx.traceability.qualitynotification.infrastructure.model.NotificationSideBaseEntity.RECEIVER; +import static org.eclipse.tractusx.traceability.qualitynotification.infrastructure.model.NotificationSideBaseEntity.SENDER; import static org.eclipse.tractusx.traceability.qualitynotification.infrastructure.model.NotificationStatusBaseEntity.ACCEPTED; import static org.eclipse.tractusx.traceability.qualitynotification.infrastructure.model.NotificationStatusBaseEntity.ACKNOWLEDGED; import static org.eclipse.tractusx.traceability.qualitynotification.infrastructure.model.NotificationStatusBaseEntity.CANCELED; @@ -353,7 +356,7 @@ void givenAssetsWithAlerts_whenGetAssetsWithActiveAlertCountFilter_thenReturnPro alertsSupport.storeAlertWithStatusAndAssets(CANCELED, List.of(assetAsBuilt), null); alertsSupport.storeAlertWithStatusAndAssets(CLOSED, List.of(assetAsBuilt), null); - final String filter = "qualityAlertIdsInStatusActive,NOTIFICATION_COUNT_EQUAL,6,AND"; + final String filter = "receivedQualityAlertIdsInStatusActive,NOTIFICATION_COUNT_EQUAL,6,AND"; // When given() @@ -385,7 +388,7 @@ void givenAssetsWithAlerts_whenGetAssetsWithActiveAlertCountFilter2_thenReturnPr alertsSupport.storeAlertWithStatusAndAssets(CANCELED, List.of(assetAsBuilt), null); alertsSupport.storeAlertWithStatusAndAssets(CLOSED, List.of(assetAsBuilt), null); - final String filter = "qualityAlertIdsInStatusActive,NOTIFICATION_COUNT_EQUAL,2,AND"; + final String filter = "receivedQualityAlertIdsInStatusActive,NOTIFICATION_COUNT_EQUAL,2,AND"; // When given() @@ -402,20 +405,60 @@ void givenAssetsWithAlerts_whenGetAssetsWithActiveAlertCountFilter2_thenReturnPr } @Test - void givenAssetsWithInvestigations_whenGetAssetsWithActiveInvestigationCountFilter_thenReturnProperAssets() throws JoseException { + void givenAssetsWithInvestigations_whenGetAssetsWithActiveSentInvestigationCountFilter_thenReturnProperAssets() throws JoseException { // Given assetsSupport.defaultAssetsStored(); AssetAsBuiltEntity assetAsBuilt = jpaAssetAsBuiltRepository.findById("urn:uuid:d387fa8e-603c-42bd-98c3-4d87fef8d2bb").orElseThrow(); - investigationsSupport.storeInvestigationWithStatusAndAssets(CREATED, List.of(assetAsBuilt), null); - investigationsSupport.storeInvestigationWithStatusAndAssets(SENT, List.of(assetAsBuilt), null); - investigationsSupport.storeInvestigationWithStatusAndAssets(RECEIVED, List.of(assetAsBuilt), null); - investigationsSupport.storeInvestigationWithStatusAndAssets(ACKNOWLEDGED, List.of(assetAsBuilt), null); - investigationsSupport.storeInvestigationWithStatusAndAssets(ACCEPTED, List.of(assetAsBuilt), null); - investigationsSupport.storeInvestigationWithStatusAndAssets(DECLINED, List.of(assetAsBuilt), null); - investigationsSupport.storeInvestigationWithStatusAndAssets(CANCELED, List.of(assetAsBuilt), null); - investigationsSupport.storeInvestigationWithStatusAndAssets(CLOSED, List.of(assetAsBuilt), null); + investigationsSupport.storeInvestigationWithStatusAndAssets(CREATED, List.of(assetAsBuilt), null, SENDER); + investigationsSupport.storeInvestigationWithStatusAndAssets(SENT, List.of(assetAsBuilt), null, SENDER); + investigationsSupport.storeInvestigationWithStatusAndAssets(RECEIVED, List.of(assetAsBuilt), null, SENDER); + investigationsSupport.storeInvestigationWithStatusAndAssets(ACKNOWLEDGED, List.of(assetAsBuilt), null, SENDER); + investigationsSupport.storeInvestigationWithStatusAndAssets(ACCEPTED, List.of(assetAsBuilt), null, SENDER); + investigationsSupport.storeInvestigationWithStatusAndAssets(DECLINED, List.of(assetAsBuilt), null, SENDER); + investigationsSupport.storeInvestigationWithStatusAndAssets(CANCELED, List.of(assetAsBuilt), null, SENDER); + investigationsSupport.storeInvestigationWithStatusAndAssets(CLOSED, List.of(assetAsBuilt), null, SENDER); + investigationsSupport.storeInvestigationWithStatusAndAssets(CREATED, List.of(assetAsBuilt), null, RECEIVER); + + final String filter = "sentQualityInvestigationIdsInStatusActive,NOTIFICATION_COUNT_EQUAL,6,AND"; + + + // When + given() + .header(oAuth2Support.jwtAuthorization(ADMIN)) + .contentType(ContentType.JSON) + .when() + .param("filter", filter) + .get("/api/assets/as-built") + .then() + .statusCode(200) + .assertThat() + .body("totalItems", equalTo(1)); + } - final String filter = "qualityInvestigationIdsInStatusActive,NOTIFICATION_COUNT_EQUAL,6,AND"; + @Test + void givenAssetsWithInvestigations_whenGetAssetsWithActiveReceivedInvestigationCountFilter_thenReturnProperAssets() throws JoseException { + // Given + assetsSupport.defaultAssetsStored(); + AssetAsBuiltEntity assetAsBuilt = jpaAssetAsBuiltRepository.findById("urn:uuid:d387fa8e-603c-42bd-98c3-4d87fef8d2bb").orElseThrow(); + investigationsSupport.storeInvestigationWithStatusAndAssets(CREATED, List.of(assetAsBuilt), null, SENDER); + investigationsSupport.storeInvestigationWithStatusAndAssets(SENT, List.of(assetAsBuilt), null, SENDER); + investigationsSupport.storeInvestigationWithStatusAndAssets(RECEIVED, List.of(assetAsBuilt), null, SENDER); + investigationsSupport.storeInvestigationWithStatusAndAssets(ACKNOWLEDGED, List.of(assetAsBuilt), null, SENDER); + investigationsSupport.storeInvestigationWithStatusAndAssets(ACCEPTED, List.of(assetAsBuilt), null, RECEIVER); + investigationsSupport.storeInvestigationWithStatusAndAssets(DECLINED, List.of(assetAsBuilt), null, SENDER); + investigationsSupport.storeInvestigationWithStatusAndAssets(CANCELED, List.of(assetAsBuilt), null, SENDER); + investigationsSupport.storeInvestigationWithStatusAndAssets(CLOSED, List.of(assetAsBuilt), null, SENDER); + + investigationsSupport.storeInvestigationWithStatusAndAssets(CREATED, List.of(assetAsBuilt), null, RECEIVER); + investigationsSupport.storeInvestigationWithStatusAndAssets(SENT, List.of(assetAsBuilt), null, RECEIVER); + investigationsSupport.storeInvestigationWithStatusAndAssets(RECEIVED, List.of(assetAsBuilt), null, RECEIVER); + investigationsSupport.storeInvestigationWithStatusAndAssets(ACKNOWLEDGED, List.of(assetAsBuilt), null, RECEIVER); + investigationsSupport.storeInvestigationWithStatusAndAssets(ACCEPTED, List.of(assetAsBuilt), null, RECEIVER); + investigationsSupport.storeInvestigationWithStatusAndAssets(DECLINED, List.of(assetAsBuilt), null, RECEIVER); + investigationsSupport.storeInvestigationWithStatusAndAssets(CANCELED, List.of(assetAsBuilt), null, RECEIVER); + investigationsSupport.storeInvestigationWithStatusAndAssets(CLOSED, List.of(assetAsBuilt), null, RECEIVER); + + final String filter = "receivedQualityInvestigationIdsInStatusActive,NOTIFICATION_COUNT_EQUAL,7,AND"; // When @@ -447,7 +490,7 @@ void givenAssetsWithInvestigations_whenGetAssetsWithActiveInvestigationCountFilt investigationsSupport.storeInvestigationWithStatusAndAssets(CANCELED, List.of(assetAsBuilt), null); investigationsSupport.storeInvestigationWithStatusAndAssets(CLOSED, List.of(assetAsBuilt), null); - final String filter = "qualityInvestigationIdsInStatusActive,NOTIFICATION_COUNT_EQUAL,2,AND"; + final String filter = "receivedQualityInvestigationIdsInStatusActive,NOTIFICATION_COUNT_EQUAL,2,AND"; // When @@ -479,7 +522,7 @@ void givenAssetsWithInvestigations_whenGetAssetsWithActiveInvestigationCountFilt investigationsSupport.storeInvestigationWithStatusAndAssets(CANCELED, List.of(assetAsBuilt), null); investigationsSupport.storeInvestigationWithStatusAndAssets(CLOSED, List.of(assetAsBuilt), null); - final String filter = "qualityInvestigationIdsInStatusActive,NOTIFICATION_COUNT_EQUAL,0,AND"; + final String filter = "receivedQualityInvestigationIdsInStatusActive,NOTIFICATION_COUNT_EQUAL,0,AND"; // When @@ -511,7 +554,7 @@ void givenAssetsWithInvestigations_whenGetAssetsWithActiveInvestigationCountFilt investigationsSupport.storeInvestigationWithStatusAndAssets(CANCELED, List.of(assetAsBuilt), null); investigationsSupport.storeInvestigationWithStatusAndAssets(CLOSED, List.of(assetAsBuilt), null); - final String filter = "qualityAlertIdsInStatusActive,NOTIFICATION_COUNT_EQUAL,0,AND"; + final String filter = "receivedQualityAlertIdsInStatusActive,NOTIFICATION_COUNT_EQUAL,0,AND"; // When @@ -543,9 +586,52 @@ void givenAssetsWithInvestigations_whenGetAssetsWithActiveInvestigationCountFilt investigationsSupport.storeInvestigationWithStatusAndAssets(CANCELED, List.of(assetAsBuilt), null); investigationsSupport.storeInvestigationWithStatusAndAssets(CLOSED, List.of(assetAsBuilt), null); - final String filter1 = "qualityAlertIdsInStatusActive,NOTIFICATION_COUNT_EQUAL,0,AND"; - final String filter2 = "qualityInvestigationIdsInStatusActive,NOTIFICATION_COUNT_EQUAL,2,AND"; + final String filter1 = "receivedQualityAlertIdsInStatusActive,NOTIFICATION_COUNT_EQUAL,0,AND"; + final String filter2 = "receivedQualityInvestigationIdsInStatusActive,NOTIFICATION_COUNT_EQUAL,2,AND"; + + + // When + given() + .header(oAuth2Support.jwtAuthorization(ADMIN)) + .contentType(ContentType.JSON) + .when() + .param("filter", filter1) + .param("filter", filter2) + .get("/api/assets/as-built") + .then() + .statusCode(200) + .assertThat() + .body("totalItems", equalTo(1)); + } + + @Test + void givenAssetsWithInvestigations_whenGetAssetsWithActiveInvestigationCountFilter6_thenReturnProperAssets() throws JoseException { + // Given + assetsSupport.defaultAssetsStored(); + AssetAsBuiltEntity assetAsBuilt = jpaAssetAsBuiltRepository.findById("urn:uuid:d387fa8e-603c-42bd-98c3-4d87fef8d2bb").orElseThrow(); + AssetAsBuiltEntity assetAsBuilt1 = jpaAssetAsBuiltRepository.findById("urn:uuid:7fa65f10-9dc1-49fe-818a-09c7313a4562").orElseThrow(); + + alertsSupport.storeAlertWithStatusAndAssets(CREATED, List.of(assetAsBuilt, assetAsBuilt1), null, SENDER); + alertsSupport.storeAlertWithStatusAndAssets(SENT, List.of(assetAsBuilt1), null, SENDER); + + investigationsSupport.storeInvestigationWithStatusAndAssets(CREATED, List.of(assetAsBuilt, assetAsBuilt1), null, SENDER); + investigationsSupport.storeInvestigationWithStatusAndAssets(CREATED, List.of(assetAsBuilt, assetAsBuilt1), null, SENDER); + investigationsSupport.storeInvestigationWithStatusAndAssets(SENT, List.of(assetAsBuilt1), null, SENDER); + + alertsSupport.storeAlertWithStatusAndAssets(CREATED, List.of(assetAsBuilt, assetAsBuilt1), null, RECEIVER); + alertsSupport.storeAlertWithStatusAndAssets(SENT, List.of(assetAsBuilt), null, RECEIVER); + alertsSupport.storeAlertWithStatusAndAssets(SENT, List.of(assetAsBuilt), null, RECEIVER); + + investigationsSupport.storeInvestigationWithStatusAndAssets(CREATED, List.of(assetAsBuilt, assetAsBuilt1), null, RECEIVER); + investigationsSupport.storeInvestigationWithStatusAndAssets(CREATED, List.of(assetAsBuilt, assetAsBuilt1), null, RECEIVER); + investigationsSupport.storeInvestigationWithStatusAndAssets(SENT, List.of(assetAsBuilt), null, RECEIVER); + investigationsSupport.storeInvestigationWithStatusAndAssets(SENT, List.of(assetAsBuilt), null, RECEIVER); + + final String filter1 = "receivedQualityAlertIdsInStatusActive,NOTIFICATION_COUNT_EQUAL,3,AND"; + final String filter2 = "receivedQualityInvestigationIdsInStatusActive,NOTIFICATION_COUNT_EQUAL,4,AND"; + final String filter3 = "sentQualityAlertIdsInStatusActive,NOTIFICATION_COUNT_EQUAL,1,AND"; + final String filter4 = "sentQualityInvestigationIdsInStatusActive,NOTIFICATION_COUNT_EQUAL,2,AND"; // When given() @@ -554,6 +640,8 @@ void givenAssetsWithInvestigations_whenGetAssetsWithActiveInvestigationCountFilt .when() .param("filter", filter1) .param("filter", filter2) + .param("filter", filter3) + .param("filter", filter4) .get("/api/assets/as-built") .then() .statusCode(200) diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/AlertsSupport.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/AlertsSupport.java index a19cf40f2d..10a2f2b20a 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/AlertsSupport.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/AlertsSupport.java @@ -60,11 +60,15 @@ public Long defaultReceivedAlertStored() { } public Long storeAlertWithStatusAndAssets(NotificationStatusBaseEntity status, List assetsAsBuilt, List assetsAsPlanned) { + return storeAlertWithStatusAndAssets(status, assetsAsBuilt, assetsAsPlanned, NotificationSideBaseEntity.RECEIVER); + } + + public Long storeAlertWithStatusAndAssets(NotificationStatusBaseEntity status, List assetsAsBuilt, List assetsAsPlanned, NotificationSideBaseEntity side) { AlertEntity entity = AlertEntity.builder() .assets(Collections.emptyList()) .bpn("BPNL00000003AXS3") .status(status) - .side(NotificationSideBaseEntity.RECEIVER) + .side(side) .createdDate(Instant.now()) .build(); Long alertId = storedAlert(entity); diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/InvestigationsSupport.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/InvestigationsSupport.java index e1fb906b3c..55c18e7a36 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/InvestigationsSupport.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/InvestigationsSupport.java @@ -56,11 +56,15 @@ public Long defaultReceivedInvestigationStored() { } public Long storeInvestigationWithStatusAndAssets(NotificationStatusBaseEntity status, List assetsAsBuilt, List assetsAsPlanned) { + return storeInvestigationWithStatusAndAssets(status, assetsAsBuilt, assetsAsPlanned, NotificationSideBaseEntity.RECEIVER); + } + + public Long storeInvestigationWithStatusAndAssets(NotificationStatusBaseEntity status, List assetsAsBuilt, List assetsAsPlanned, NotificationSideBaseEntity side) { InvestigationEntity entity = InvestigationEntity.builder() .assets(Collections.emptyList()) .bpn("BPNL00000003AXS3") .status(status) - .side(NotificationSideBaseEntity.RECEIVER) + .side(side) .createdDate(Instant.now()) .build(); Long alertId = storedInvestigation(entity);