diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationRequest.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationRequest.java index 1681eb7ba6..7d50ea22a8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationRequest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationRequest.java @@ -44,7 +44,7 @@ public class PaginationRequest { private Map property = new HashMap<>(); private List statusList = new ArrayList<>(); private OperationLogFilters operationLogFilters = new OperationLogFilters(); - private List sortColumns; + private List sortColumns = new ArrayList<>(); public OperationLogFilters getOperationLogFilters() { return operationLogFilters; } @@ -173,27 +173,31 @@ public class PaginationRequest { this.filter = filter; } - public void setSortColumns(List sortColumns) { this.sortColumns = sortColumns; } + public void setSortColumns(List sortColumns) { this.sortColumns = sortColumns; } - public List getSortColumns() { return sortColumns; } + public List getSortColumns() { return sortColumns; } /** * 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 */ - public static List addSortColumn(List sortColumns) { + public void addSortColumn(List sortColumns) { List sortColumnList = new ArrayList<>(); + SortColumn sortColumn; + String[] sorting; for (String sortBy: sortColumns) { - SortColumn sortColumn = new SortColumn(); - String[] sorting = sortBy.split(":"); + sortColumn = new SortColumn(); + sorting = sortBy.split(":"); sortColumn.setName(sorting[0]); sortColumn.setType(sorting.length >= 2 && (sorting[1].equalsIgnoreCase("desc")) ? SortColumn.types.DESC : SortColumn.types.ASC); sortColumnList.add(sortColumn); } - return sortColumnList; + setSortColumns(sortColumnList); } @Override