Skip to content

Commit 8661965

Browse files
committed
FIX sort on some attributes
1 parent 9c25d27 commit 8661965

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main/java/com/airbus_cyber_security/graylog/wizard/alert/rest/AlertRuleResource.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ public class AlertRuleResource extends RestResource implements PluginRestResourc
118118
private static final EntityDefaults settings = EntityDefaults.builder()
119119
.sort(Sorting.create(DEFAULT_SORT_FIELD, Sorting.Direction.valueOf(DEFAULT_SORT_DIRECTION.toUpperCase(Locale.ROOT))))
120120
.build();
121+
private static final ImmutableMap<String, String> SORT_FIELD_MAP = ImmutableMap.<String, String>builder()
122+
.put("title", "title")
123+
.put("user", "creator_user_id")
124+
.put("created", "created_at")
125+
.put("lastModified", "last_modified")
126+
.build();
121127

122128
// TODO try to remove this field => move it down in business
123129
private final AlertWizardConfigurationService configurationService;
@@ -647,7 +653,7 @@ public PageListResponse<GetDataAlertRule> getPage(@ApiParam(name = "page") @Quer
647653
@ApiParam(name = "sort",
648654
value = "The field to sort the result on",
649655
required = true,
650-
allowableValues = "title,description,priority")
656+
allowableValues = "title,user,created,lastModified")
651657
@DefaultValue(DEFAULT_SORT_FIELD) @QueryParam("sort") String sort,
652658
@ApiParam(name = "order", value = "The sort direction", allowableValues = "asc, desc")
653659
@DefaultValue(DEFAULT_SORT_DIRECTION) @QueryParam("order") SortOrder order) {
@@ -658,10 +664,11 @@ public PageListResponse<GetDataAlertRule> getPage(@ApiParam(name = "page") @Quer
658664
} catch (IllegalArgumentException e) {
659665
throw new BadRequestException("Invalid argument in search query: " + e.getMessage());
660666
}
667+
String sortAttr = SORT_FIELD_MAP.getOrDefault(sort, sort);
661668
final PaginatedList<AlertRule> result = this.alertRuleService.searchPaginated(
662669
searchQuery,
663670
alertRule -> true,
664-
order.toBsonSort(sort),
671+
order.toBsonSort(sortAttr),
665672
page,
666673
perPage);
667674

0 commit comments

Comments
 (0)