Restructure sortColumn

pull/48/head
Rushdi Mohamed 2 years ago
parent b0ae09515f
commit ce911b1d26

@ -44,7 +44,7 @@ public class PaginationRequest {
private Map<String, Object> property = new HashMap<>();
private List<String> statusList = new ArrayList<>();
private OperationLogFilters operationLogFilters = new OperationLogFilters();
private SortColumn sortColumns;
private List<String> 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<String> sortColumns) { this.sortColumns = sortColumns; }
public void setSortColumns(SortColumn sortColumns) { this.sortColumns = sortColumns; }
public List<String> getSortColumns() { return sortColumns; }
@Override
public String toString() {

@ -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<String> name = new ArrayList<>();
List<SortColumn.types> 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<String> 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<String> name) { this.name = name; }
public void setName(String name) { this.name = name; }
/**
* get the name of the column
* @return name
*/
public List<String> getName() { return name; }
public String getName() { return name; }
/**
* Column sort type
* @param type of sort as ASC or DESC
*/
public void setType(List<SortColumn.types> type) { this.type = type; }
public void setType(SortColumn.types type) { this.type = type; }
/**
* get column sort type
* @return type of sort
*/
public List<SortColumn.types> getType() { return type; }
public SortColumn.types getType() { return type; }
@Override
public String toString() {

@ -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<SortColumn> convertToSortColumn(List<String> sortColumns) {
List<SortColumn> 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;
}
}

Loading…
Cancel
Save