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 7f8b794132..ef90ef1717 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 SortColumn sortColumns; + private List sortColumns; public OperationLogFilters getOperationLogFilters() { return operationLogFilters; } @@ -173,9 +173,9 @@ public class PaginationRequest { this.filter = filter; } - public SortColumn getSortColumns() { return sortColumns; } + public void setSortColumns(List sortColumns) { this.sortColumns = sortColumns; } - public void setSortColumns(SortColumn sortColumns) { this.sortColumns = sortColumns; } + public List getSortColumns() { return sortColumns; } @Override public String toString() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/SortColumn.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/SortColumn.java index 76ba03b332..8e6d4915ea 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/SortColumn.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/SortColumn.java @@ -1,21 +1,4 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * you may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - * * Copyright (c) 2023, Entgra (pvt) Ltd. (https://entgra.io) All Rights Reserved. * * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, @@ -35,32 +18,15 @@ package org.wso2.carbon.device.mgt.common; -import java.util.ArrayList; -import java.util.List; - /** * This class holds required parameters for a querying a sort by column in pagination. * */ public class SortColumn { - List name = new ArrayList<>(); - List type = new ArrayList<>(); - - /** - * SortColumn Constructor with sort field parameter and splitting string into columnName and sortType - * - * @param sort which is separated by a colon(:) and first will be the columnNane and the second will be type ASC or DESC - * - */ - public SortColumn(List sort) { - for (String sortBy: sort) { - String[] sorting = sortBy.split(":"); - name.add(sorting[0]); - type.add(sorting.length >= 2 && (sorting[1].equalsIgnoreCase("desc")) ? types.DESC : types.ASC); - } - } + String name; + SortColumn.types type; - private enum types { + public enum types { ASC, DESC } @@ -68,25 +34,25 @@ public class SortColumn { * ColumnName setter method * @param name of the column */ - public void setName(List name) { this.name = name; } + public void setName(String name) { this.name = name; } /** * get the name of the column * @return name */ - public List getName() { return name; } + public String getName() { return name; } /** * Column sort type * @param type of sort as ASC or DESC */ - public void setType(List type) { this.type = type; } + public void setType(SortColumn.types type) { this.type = type; } /** * get column sort type * @return type of sort */ - public List getType() { return type; } + public SortColumn.types getType() { return type; } @Override public String toString() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java index 65a26d1330..3c733a1510 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java @@ -59,6 +59,7 @@ import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.GroupPaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; +import org.wso2.carbon.device.mgt.common.SortColumn; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.EnrollmentConfiguration; @@ -1284,4 +1285,23 @@ public final class DeviceManagerUtil { + deviceGroup.getGroupId(); } } + + /** + * 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 + * @return sortColumnList as a list of sortColumn + */ + public static List convertToSortColumn(List sortColumns) { + List sortColumnList = new ArrayList<>(); + for (String sortBy: sortColumns) { + SortColumn sortColumn = new SortColumn(); + String[] 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; + } }