Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reactivate natural sorting order of notification by severity #777

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]))));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the new supported field to QualityNotificationFieldMapper and remove the newly created method.

} 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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its kind of confusing adding this logic as sql. It would be cleaner to add the rank of the natural order to the QualityNotificationSeverity Enum and sort its value


@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
Loading