From b0ae09515f65ec6ca1f883d50f7901e0b673462b Mon Sep 17 00:00:00 2001 From: Rushdi Date: Tue, 24 Jan 2023 17:48:08 +0530 Subject: [PATCH] Add SortColumn Object --- .../device/mgt/common/PaginationRequest.java | 14 +-- .../carbon/device/mgt/common/SortColumn.java | 96 +++++++++++++++++++ 2 files changed, 100 insertions(+), 10 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/SortColumn.java 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 4967d66e37..7f8b794132 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,8 +44,7 @@ public class PaginationRequest { private Map property = new HashMap<>(); private List statusList = new ArrayList<>(); private OperationLogFilters operationLogFilters = new OperationLogFilters(); - private List sortColumnList = new ArrayList<>(); - private List sortTypeList = new ArrayList<>(); + private SortColumn sortColumns; public OperationLogFilters getOperationLogFilters() { return operationLogFilters; } @@ -174,20 +173,15 @@ public class PaginationRequest { this.filter = filter; } - public List getSortColumnList() { return sortColumnList; } + public SortColumn getSortColumns() { return sortColumns; } - public void setSortColumnList(List sortColumnList) { this.sortColumnList = sortColumnList; } - - public List getSortTypeList() { return sortTypeList; } - - public void setSortTypeList(List 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; } } 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 new file mode 100644 index 0000000000..76ba03b332 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/SortColumn.java @@ -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 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); + } + } + + private enum types { + ASC, DESC + } + + /** + * ColumnName setter method + * @param name of the column + */ + public void setName(List name) { this.name = name; } + + /** + * get the name of the column + * @return name + */ + public List getName() { return name; } + + /** + * Column sort type + * @param type of sort as ASC or DESC + */ + public void setType(List type) { this.type = type; } + + /** + * get column sort type + * @return type of sort + */ + public List getType() { return type; } + + @Override + public String toString() { + return "Column Name - " + this.name + ", Type - " + this.type ; + } + +}