Add SortColumn Object

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

@ -44,8 +44,7 @@ public class PaginationRequest {
private Map<String, Object> property = new HashMap<>();
private List<String> statusList = new ArrayList<>();
private OperationLogFilters operationLogFilters = new OperationLogFilters();
private List<String> sortColumnList = new ArrayList<>();
private List<String> sortTypeList = new ArrayList<>();
private SortColumn sortColumns;
public OperationLogFilters getOperationLogFilters() {
return operationLogFilters;
}
@ -174,20 +173,15 @@ public class PaginationRequest {
this.filter = filter;
}
public List<String> getSortColumnList() { return sortColumnList; }
public SortColumn getSortColumns() { return sortColumns; }
public void setSortColumnList(List<String> sortColumnList) { this.sortColumnList = sortColumnList; }
public List<String> getSortTypeList() { return sortTypeList; }
public void setSortTypeList(List<String> sortTypeList) { this.sortTypeList = sortTypeList; }
public void setSortColumns(SortColumn sortColumns) { this.sortColumns = sortColumns; }
@Override
public String toString() {
return "Device type '" + this.deviceType + "' Device Name '" + this.deviceName + "' row count: " + this.rowCount
+ " Owner role '" + this.ownerRole + "' owner pattern '" + this.ownerPattern + "' ownership "
+ this.ownership + "' Status '" + this.statusList + "' owner '" + this.owner + "' groupId: " + this.groupId
+ " start index: " + this.startIndex + "' SortColumnList '" + this.sortColumnList + "' SortTypeList '"
+ this.sortTypeList;
+ " start index: " + this.startIndex + ", SortColumns: " + this.sortColumns;
}
}

@ -0,0 +1,96 @@
/*
* 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,
* 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.
*/
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);
}
}
private enum types {
ASC, DESC
}
/**
* ColumnName setter method
* @param name of the column
*/
public void setName(List<String> name) { this.name = name; }
/**
* get the name of the column
* @return name
*/
public List<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; }
/**
* get column sort type
* @return type of sort
*/
public List<SortColumn.types> getType() { return type; }
@Override
public String toString() {
return "Column Name - " + this.name + ", Type - " + this.type ;
}
}
Loading…
Cancel
Save