Restructure sortColumn in Pagination

pull/48/head
Rushdi Mohamed 2 years ago
parent 8a870167d9
commit d59018a09d

@ -44,7 +44,7 @@ public class PaginationRequest {
private Map<String, Object> property = new HashMap<>(); private Map<String, Object> property = new HashMap<>();
private List<String> statusList = new ArrayList<>(); private List<String> statusList = new ArrayList<>();
private OperationLogFilters operationLogFilters = new OperationLogFilters(); private OperationLogFilters operationLogFilters = new OperationLogFilters();
private List<String> sortColumns; private List<SortColumn> sortColumns = new ArrayList<>();
public OperationLogFilters getOperationLogFilters() { public OperationLogFilters getOperationLogFilters() {
return operationLogFilters; return operationLogFilters;
} }
@ -173,27 +173,31 @@ public class PaginationRequest {
this.filter = filter; this.filter = filter;
} }
public void setSortColumns(List<String> sortColumns) { this.sortColumns = sortColumns; } public void setSortColumns(List<SortColumn> sortColumns) { this.sortColumns = sortColumns; }
public List<String> getSortColumns() { return sortColumns; } public List<SortColumn> getSortColumns() { return sortColumns; }
/** /**
* Convert SortColumns field parameter and splitting string into columnName and sortType * Convert SortColumns field parameter and splitting string into columnName and sortType
* *
* @param sortColumns which is separated by a colon(:) and first will be the columnNane and the second will be type ASC or DESC * @param sortColumns which is separated by a colon(:) and first will be the columnNane and the second will be type ASC or DESC,
* if there is no colon(:) detected, ASC will be default
* (Ex: sort=col1:ASC&sort=col2:DESC, sort=col1&sort=col2:DESC)
* @return sortColumnList as a list of sortColumn * @return sortColumnList as a list of sortColumn
*/ */
public static List<SortColumn> addSortColumn(List<String> sortColumns) { public void addSortColumn(List<String> sortColumns) {
List<SortColumn> sortColumnList = new ArrayList<>(); List<SortColumn> sortColumnList = new ArrayList<>();
SortColumn sortColumn;
String[] sorting;
for (String sortBy: sortColumns) { for (String sortBy: sortColumns) {
SortColumn sortColumn = new SortColumn(); sortColumn = new SortColumn();
String[] sorting = sortBy.split(":"); sorting = sortBy.split(":");
sortColumn.setName(sorting[0]); sortColumn.setName(sorting[0]);
sortColumn.setType(sorting.length >= 2 && (sorting[1].equalsIgnoreCase("desc")) sortColumn.setType(sorting.length >= 2 && (sorting[1].equalsIgnoreCase("desc"))
? SortColumn.types.DESC : SortColumn.types.ASC); ? SortColumn.types.DESC : SortColumn.types.ASC);
sortColumnList.add(sortColumn); sortColumnList.add(sortColumn);
} }
return sortColumnList; setSortColumns(sortColumnList);
} }
@Override @Override

Loading…
Cancel
Save