diff --git a/CHANGELOG.md b/CHANGELOG.md
index 53bc963204..77cca512ce 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,23 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
_**For better traceability add the corresponding GitHub issue number in each changelog entry, please.**_
## [UNRELEASED - DD.MM.YYYY]
+
+
+## [UNRELEASED - 07.05.2024]
+
+### Added
+- #779 Created new enum type for status
+- #779 Added asset_as_build view to after updating status column type
+- #779 Added new dependency hypersistence-utils-hibernate-63 to map enum to string
+
+### changed
+- #779 feat: reactivate natural sorting order of notification by status
+- #779 updated status column type of notification and notification_message
+
+### Removed
+- #779 Dropped asset_as_build view to update status column type varchar to enum but added again
+
+## [UNRELEASED - DD.MM.YYYY]
### Added
- #844 Validation for BPN to Notification API (Create / Edit), Fixed pagination
- #726 Added @Preauthorize annotation to dashboard controller
diff --git a/pom.xml b/pom.xml
index 97e3d46c16..d3db90c70a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -62,6 +62,7 @@ SPDX-License-Identifier: Apache-2.0
4.0.0-M11
0.2.1
+ 3.7.5
1.5.5
1.1.0
9.37.3
diff --git a/tx-backend/pom.xml b/tx-backend/pom.xml
index 3360e05bb5..31c00a253c 100644
--- a/tx-backend/pom.xml
+++ b/tx-backend/pom.xml
@@ -58,7 +58,11 @@ SPDX-License-Identifier: Apache-2.0
json-schema-validator
${json-schema-validator.version}
-
+
+ io.hypersistence
+ hypersistence-utils-hibernate-63
+ ${hypersistence-utils-hibernate.version}
+
org.eclipse.tractusx.irs
diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/model/NotificationBaseEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/model/NotificationBaseEntity.java
index daa225466f..7f583ea298 100644
--- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/model/NotificationBaseEntity.java
+++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/model/NotificationBaseEntity.java
@@ -28,6 +28,8 @@
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
+import org.hibernate.annotations.JdbcTypeCode;
+import org.hibernate.type.SqlTypes;
import java.time.Instant;
@@ -51,6 +53,8 @@ public class NotificationBaseEntity {
@Enumerated(EnumType.STRING)
private NotificationSideBaseEntity side;
@Enumerated(EnumType.STRING)
+ @Column(columnDefinition = "status")
+ @JdbcTypeCode(SqlTypes.NAMED_ENUM)
private NotificationStatusBaseEntity status;
}
diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/model/NotificationMessageBaseEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/model/NotificationMessageBaseEntity.java
index 837842a4ad..23936842c6 100644
--- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/model/NotificationMessageBaseEntity.java
+++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/model/NotificationMessageBaseEntity.java
@@ -18,15 +18,13 @@
********************************************************************************/
package org.eclipse.tractusx.traceability.notification.infrastructure.notification.model;
-import jakarta.persistence.EnumType;
-import jakarta.persistence.Enumerated;
-import jakarta.persistence.Id;
-import jakarta.persistence.MappedSuperclass;
-import jakarta.persistence.PreUpdate;
+import jakarta.persistence.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationSeverity;
+import org.hibernate.annotations.JdbcTypeCode;
+import org.hibernate.type.SqlTypes;
import java.time.Instant;
import java.time.LocalDateTime;
@@ -52,6 +50,8 @@ public class NotificationMessageBaseEntity {
private LocalDateTime updated;
private String messageId;
@Enumerated(EnumType.STRING)
+ @Column(columnDefinition = "status")
+ @JdbcTypeCode(SqlTypes.NAMED_ENUM)
private NotificationStatusBaseEntity status;
private String errorMessage;
diff --git a/tx-backend/src/main/resources/db/migration/V23__create_status_enum_type.sql b/tx-backend/src/main/resources/db/migration/V23__create_status_enum_type.sql
new file mode 100644
index 0000000000..c057329dcc
--- /dev/null
+++ b/tx-backend/src/main/resources/db/migration/V23__create_status_enum_type.sql
@@ -0,0 +1,77 @@
+DROP VIEW IF EXISTS assets_as_built_view;
+
+CREATE TYPE status AS ENUM ('CREATED', 'SENT', 'RECEIVED', 'ACKNOWLEDGED', 'CANCELED', 'ACCEPTED', 'DECLINED', 'CLOSED');
+
+ALTER TABLE notification ALTER COLUMN "status" TYPE status USING ("status"::status);
+ALTER TABLE notification_message ALTER COLUMN "status" TYPE status USING ("status"::status);
+
+CREATE CAST (varchar AS status) WITH INOUT AS IMPLICIT;
+
+create
+or replace view assets_as_built_view as
+select asset.*,
+ (select count(notification.id)
+ from notification notification
+ join
+ assets_as_built_notifications notification_assets
+ on notification.id = notification_assets.notification_id
+ where (
+ cast(notification.status as text) = 'CREATED'
+ or cast(notification.status as text) = 'SENT'
+ or cast(notification.status as text) = 'RECEIVED'
+ or cast(notification.status as text) = 'ACKNOWLEDGED'
+ or cast(notification.status as text) = 'ACCEPTED'
+ or cast(notification.status as text) = 'DECLINED'
+ )
+ and cast(notification.side as text) = 'RECEIVER'
+ and cast(notification.type as text) = 'ALERT'
+ and notification_assets.asset_id = asset.id) as received_active_alerts,
+ (select count(notification.id)
+ from notification notification
+ join
+ assets_as_built_notifications notification_assets
+ on notification.id = notification_assets.notification_id
+ where (
+ cast(notification.status as text) = 'CREATED'
+ or cast(notification.status as text) = 'SENT'
+ or cast(notification.status as text) = 'RECEIVED'
+ or cast(notification.status as text) = 'ACKNOWLEDGED'
+ or cast(notification.status as text) = 'ACCEPTED'
+ or cast(notification.status as text) = 'DECLINED'
+ )
+ and cast(notification.side as text) = 'SENDER'
+ and cast(notification.type as text) = 'ALERT'
+ and notification_assets.asset_id = asset.id) as sent_active_alerts,
+ (select count(notification.id)
+ from notification notification
+ join
+ assets_as_built_notifications notification_assets
+ on notification.id = notification_assets.notification_id
+ where (
+ cast(notification.status as text) = 'CREATED'
+ or cast(notification.status as text) = 'SENT'
+ or cast(notification.status as text) = 'RECEIVED'
+ or cast(notification.status as text) = 'ACKNOWLEDGED'
+ or cast(notification.status as text) = 'ACCEPTED'
+ or cast(notification.status as text) = 'DECLINED'
+ )
+ and cast(notification.side as text) = 'RECEIVER'
+ and cast(notification.type as text) = 'INVESTIGATION'
+ and notification_assets.asset_id = asset.id) as received_active_investigations,
+ (select count(notification.id)
+ from notification notification
+ join
+ assets_as_built_notifications notification_assets
+ on notification.id = notification_assets.notification_id
+ where (
+ cast(notification.status as text) = 'CREATED'
+ or cast(notification.status as text) = 'SENT'
+ or cast(notification.status as text) = 'RECEIVED'
+ or cast(notification.status as text) = 'ACKNOWLEDGED'
+ or cast(notification.status as text) = 'ACCEPTED'
+ or cast(notification.status as text) = 'DECLINED'
+ )
+ and cast(notification.side as text) = 'SENDER'
+ and cast(notification.type as text) = 'INVESTIGATION'
+ and notification_assets.asset_id = asset.id) as sent_active_investigations
+from assets_as_built as asset;
diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/alert/ReadAlertsControllerIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/alert/ReadAlertsControllerIT.java
index 6a472071b4..69e3275ab6 100644
--- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/alert/ReadAlertsControllerIT.java
+++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/alert/ReadAlertsControllerIT.java
@@ -184,7 +184,7 @@ void givenSortByStatusProvided_whenGetInvestigations_thenReturnInvestigationsPro
.body("pageSize", Matchers.is(10))
.body("totalItems", Matchers.is(8))
.body("content", Matchers.hasSize(8))
- .body("content.status", Matchers.containsInRelativeOrder("ACCEPTED", "ACKNOWLEDGED", "CANCELED", "CLOSED", "CREATED", "DECLINED", "RECEIVED", "SENT"));
+ .body("content.status", Matchers.containsInRelativeOrder("CREATED", "SENT", "RECEIVED", "ACKNOWLEDGED", "CANCELED", "ACCEPTED", "DECLINED", "CLOSED"));
}
@Test
diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/ReadInvestigationsControllerIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/ReadInvestigationsControllerIT.java
index 4dc70ae4c3..a493483d40 100644
--- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/ReadInvestigationsControllerIT.java
+++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/investigation/ReadInvestigationsControllerIT.java
@@ -184,7 +184,7 @@ void givenSortByStatusProvided_whenGetInvestigations_thenReturnInvestigationsPro
.body("pageSize", Matchers.is(10))
.body("totalItems", Matchers.is(8))
.body("content", Matchers.hasSize(8))
- .body("content.status", Matchers.containsInRelativeOrder("ACCEPTED", "ACKNOWLEDGED", "CANCELED", "CLOSED", "CREATED", "DECLINED", "RECEIVED", "SENT"));
+ .body("content.status", Matchers.containsInRelativeOrder("CREATED", "SENT", "RECEIVED", "ACKNOWLEDGED", "CANCELED", "ACCEPTED", "DECLINED", "CLOSED"));
}
@Test