From 4c7bd0664d936921313f0ff45e7d8d57c23543e1 Mon Sep 17 00:00:00 2001 From: Milan Perera Date: Wed, 19 Sep 2018 16:30:41 +0530 Subject: [PATCH] Fix issue in order of get pending operations --- .../device/mgt/core/operation/mgt/OperationManagerImpl.java | 4 ++-- .../operation/mgt/dao/impl/GenericOperationDAOImpl.java | 6 ++++-- ...CreateTimeComparator.java => OperationIdComparator.java} | 6 ++---- 3 files changed, 8 insertions(+), 8 deletions(-) rename components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/util/{OperationCreateTimeComparator.java => OperationIdComparator.java} (74%) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 816948ea61..0e5306f6c2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -57,7 +57,7 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOF import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationMappingDAO; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.util.OperationDAOUtil; import org.wso2.carbon.device.mgt.core.operation.mgt.util.DeviceIDHolder; -import org.wso2.carbon.device.mgt.core.operation.mgt.util.OperationCreateTimeComparator; +import org.wso2.carbon.device.mgt.core.operation.mgt.util.OperationIdComparator; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager; import org.wso2.carbon.device.mgt.core.task.impl.DeviceTaskManagerImpl; @@ -521,7 +521,7 @@ public class OperationManagerImpl implements OperationManager { operation = OperationDAOUtil.convertOperation(dtoOperation); operations.add(operation); } - Collections.sort(operations, new OperationCreateTimeComparator()); + Collections.sort(operations, new OperationIdComparator()); } catch (OperationManagementDAOException e) { throw new OperationManagementException("Error occurred while retrieving the list of " + "pending operations assigned for '" + deviceId.getType() + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java index 6725ca232b..900c41cf96 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java @@ -1272,7 +1272,8 @@ public class GenericOperationDAOImpl implements OperationDAO { String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " + "OPERATION_CODE, om.STATUS, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + - "WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC"; + "WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID " + + "ORDER BY o.CREATED_TIMESTAMP DESC, o.ID DESC"; stmt = conn.prepareStatement(sql); stmt.setInt(1, enrolmentId); rs = stmt.executeQuery(); @@ -1313,7 +1314,8 @@ public class GenericOperationDAOImpl implements OperationDAO { String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " + "OPERATION_CODE, om.STATUS, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + - "WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC LIMIT ?,?"; + "WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID " + + "ORDER BY o.CREATED_TIMESTAMP DESC, o.ID DESC LIMIT ?,?"; stmt = conn.prepareStatement(sql); stmt.setInt(1, enrolmentId); stmt.setInt(2, request.getStartIndex()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/util/OperationCreateTimeComparator.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/util/OperationIdComparator.java similarity index 74% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/util/OperationCreateTimeComparator.java rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/util/OperationIdComparator.java index 5f7e1a9eac..bbb565c3ef 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/util/OperationCreateTimeComparator.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/util/OperationIdComparator.java @@ -23,13 +23,11 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import java.io.Serializable; import java.util.Comparator; -public class OperationCreateTimeComparator implements Comparator, Serializable { +public class OperationIdComparator implements Comparator, Serializable { @Override public int compare(Operation o1, Operation o2) { - long createdTime1 = java.sql.Timestamp.valueOf(o1.getCreatedTimeStamp()).getTime(); - long createdTime2 = java.sql.Timestamp.valueOf(o1.getCreatedTimeStamp()).getTime(); - return (int) (createdTime1 - createdTime2); + return o1.getId() - o2.getId(); } }