From ee95c8aca1a96b3fb64f5f8cf2e3b39e352aec39 Mon Sep 17 00:00:00 2001 From: Pahansith Date: Wed, 25 Aug 2021 15:09:55 +0530 Subject: [PATCH] Fix location update timestamp overwrite issue --- .../details/mgt/dao/impl/DeviceDetailsDAOImpl.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java index 04eda09d86..d00cb1d1ed 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java @@ -286,7 +286,11 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { stmt.setString(8, deviceLocation.getState()); stmt.setString(9, deviceLocation.getCountry()); stmt.setString(10, GeoHashGenerator.encodeGeohash(deviceLocation)); - stmt.setLong(11, System.currentTimeMillis()); + if (deviceLocation.getUpdatedTime() == null) { + stmt.setLong(11, System.currentTimeMillis()); + } else { + stmt.setLong(11, deviceLocation.getUpdatedTime().getTime()); + } stmt.setInt(12, enrollmentId); stmt.setDouble(13, deviceLocation.getAltitude()); stmt.setFloat(14, deviceLocation.getSpeed()); @@ -417,7 +421,11 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { stmt.setDouble(6, deviceLocation.getLongitude()); stmt.setFloat(7, deviceLocation.getSpeed()); stmt.setFloat(8, deviceLocation.getBearing()); - stmt.setLong(9, System.currentTimeMillis()); + if (deviceLocation.getUpdatedTime() == null) { + stmt.setLong(9, System.currentTimeMillis()); + } else { + stmt.setLong(9, deviceLocation.getUpdatedTime().getTime()); + } stmt.setString(10, GeoHashGenerator.encodeGeohash(deviceLocation)); stmt.setString(11, device.getEnrolmentInfo().getOwner()); stmt.setDouble(12, deviceLocation.getAltitude());