Skip to content

Commit

Permalink
[Feature/Issue/701]: Reactivate natural sorting order of notification…
Browse files Browse the repository at this point in the history
…s by severity

[Summary]:
This commit reverts the sorting order of notifications (alerts and investigations) to follow a natural sorting order based on severity. Previously, the sorting method was sorted alphabetically

[Changes Made]:
- Modified/Added the SQL query responsible for sorting notifications by severity.
- Utilized a formula for natural sorting order based on severity.

[Context/Reasoning]:
Natural sorting by severity provides a more intuitive and user-friendly display of notifications, ensuring that higher severity issues are prioritized appropriately.
  • Loading branch information
poojapatel23 committed Mar 21, 2024
1 parent c73c29e commit 0ec57bc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private static Sort toDomainSort(final List<String> sorts, BaseRequestFieldMappe
try {
String[] sortParams = sort.split(",");
orders.add(new Sort.Order(Sort.Direction.valueOf(sortParams[1].toUpperCase()),
fieldMapper.mapRequestFieldName(sortParams[0])));
handleEnumColumns(fieldMapper.mapRequestFieldName(sortParams[0]))));
} catch (UnsupportedSearchCriteriaFieldException exception) {
throw exception;
} catch (Exception exception) {
Expand All @@ -86,4 +86,11 @@ private static Sort toDomainSort(final List<String> sorts, BaseRequestFieldMappe
}
return Sort.by(orders);
}

private static String handleEnumColumns(final String column) {
return switch (column) {
case "notifications_severity" -> "severityRank";
default -> column;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.eclipse.tractusx.traceability.qualitynotification.infrastructure.model.NotificationBaseEntity;
import org.eclipse.tractusx.traceability.qualitynotification.infrastructure.model.NotificationSideBaseEntity;
import org.eclipse.tractusx.traceability.qualitynotification.infrastructure.model.NotificationStatusBaseEntity;
import org.hibernate.annotations.Formula;

import java.util.List;

Expand All @@ -62,6 +63,13 @@ public class AlertEntity extends NotificationBaseEntity {
)
public List<AssetAsBuiltEntity> assets;

@Formula("(SELECT CASE " +
"WHEN A.severity = 'MINOR' THEN 0 " +
"WHEN A.severity = 'MAJOR' THEN 1 " +
"WHEN A.severity = 'CRITICAL' THEN 2 " +
"WHEN A.severity = 'LIFE_THREATENING' THEN 3 " +
"ELSE -1 END FROM alert_notification A WHERE A.alert_id = id LIMIT 1)")
private Integer severityRank;

@OneToMany(mappedBy = "alert")
private List<AlertNotificationEntity> notifications;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.eclipse.tractusx.traceability.qualitynotification.infrastructure.model.NotificationBaseEntity;
import org.eclipse.tractusx.traceability.qualitynotification.infrastructure.model.NotificationSideBaseEntity;
import org.eclipse.tractusx.traceability.qualitynotification.infrastructure.model.NotificationStatusBaseEntity;
import org.hibernate.annotations.Formula;

import java.util.List;

Expand All @@ -64,6 +65,13 @@ public class InvestigationEntity extends NotificationBaseEntity {
)
private List<AssetAsBuiltEntity> assets;

@Formula("(SELECT CASE " +
"WHEN A.severity = 'MINOR' THEN 0 " +
"WHEN A.severity = 'MAJOR' THEN 1 " +
"WHEN A.severity = 'CRITICAL' THEN 2 " +
"WHEN A.severity = 'LIFE_THREATENING' THEN 3 " +
"ELSE -1 END FROM alert_notification A WHERE A.alert_id = id LIMIT 1)")
private Integer severityRank;

@OneToMany(mappedBy = "investigation")
private List<InvestigationNotificationEntity> notifications;
Expand Down

0 comments on commit 0ec57bc

Please sign in to comment.