My service is returning a page of elements, and I want to be able to sort it by many fields. So far I can sort it by all fields except this enumeration field:
enum ActionStatusEnum {
TO_DO("ToDo"),
ROUGH_DRAFT("Brouillon"),
WAITING_FOR_VALIDATION("En attente de validation"),
VALIDATED("Validée"),
......
private String label;
ActionStatusEnum(String value) {
label = value;
}
public String getLabel() {
return label;
}
So far my sort looks like that (status being the enumeration field)
for (String sort : sorts) {
switch(sort) {
case "createDate":
s = new Sort(Sort.Direction.DESC, "creationDate");
mySort = mySort == null ? s : mySort.and(s);
break;
case "rubric":
s = new Sort(Sort.Direction.ASC, "task.rubric");
mySort = mySort == null ? s : mySort.and(s);
break;
........ // other cases
case "status":
s = new Sort(Sort.Direction.DESC, "status");
break;
default :
s = new Sort(Sort.Direction.DESC, "submissionDate");
mySort = mySort == null ? s : mySort.and(s);
break;
}
}
As you expect whenever I sort by status, it gets sorted by alphabetic order; while I need to order it as it is declared in the enumeration (TO_DO then ROUGH_DRAFT then WAITING_FOR_VALIDATION ....) . Is there any solution to that, like making my custom enumeration ordering or something that way. Thank you in advance