From 6104d26ebe6c56a7d42937e03793f978d5ededfb Mon Sep 17 00:00:00 2001 From: Kaveesha Date: Mon, 14 Sep 2020 12:39:57 +0530 Subject: [PATCH] Add device name to Geo Cluster Locations data list --- .../service/impl/GeoLocationBasedServiceImplTest.java | 4 ++-- .../device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java | 4 +++- .../mgt/core/dao/impl/device/GenericDeviceDAOImpl.java | 2 ++ .../mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java | 4 +++- .../org/wso2/carbon/device/mgt/core/geo/GeoCluster.java | 8 +++++++- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImplTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImplTest.java index 5553e02d22..d19e835848 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImplTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImplTest.java @@ -47,10 +47,10 @@ public class GeoLocationBasedServiceImplTest { List geoClusters = new ArrayList<>(); geoClusters.add(new GeoCluster(new GeoCoordinate(1.5, 80.7), new GeoCoordinate(1.1, 79.5), new GeoCoordinate(1.9, 82.1), 3, - "tb32", "aegtew234", "android", "1234")); + "tb32", "aegtew234", "test1", "android", "1234")); geoClusters.add(new GeoCluster(new GeoCoordinate(10.2, 86.1), new GeoCoordinate(9.8, 84.7), new GeoCoordinate(11.1, 88.1), 4, - "t1gd", "swerty12s", "android", "1234")); + "t1gd", "swerty12s", "t2test", "android", "1234")); Mockito.doReturn(geoClusters).when(deviceManagementProviderService) .findGeoClusters(null, Mockito.any(GeoCoordinate.class), Mockito.any(GeoCoordinate.class), Mockito.anyInt()); Response response = geoLocationBasedService.getGeoDeviceLocations(null, 0.4, 15, 75.6, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java index 3d279928f6..825b684e0c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java @@ -1733,6 +1733,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { " MAX(DEVICE_LOCATION.LONGITUDE) AS MAX_LONGITUDE," + " SUBSTRING(DEVICE_LOCATION.GEO_HASH,1,?) AS GEOHASH_PREFIX, COUNT(*) AS COUNT," + " MIN(DEVICE.DEVICE_IDENTIFICATION) AS DEVICE_IDENTIFICATION," + + " MIN(DEVICE.NAME) AS NAME," + " MIN(DEVICE_TYPE.NAME) AS TYPE, " + " MIN(DEVICE.LAST_UPDATED_TIMESTAMP) AS LAST_UPDATED_TIMESTAMP " + "FROM DM_DEVICE_LOCATION AS DEVICE_LOCATION,DM_DEVICE AS DEVICE, DM_DEVICE_TYPE AS DEVICE_TYPE " + @@ -1763,13 +1764,14 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { double min_longitude = rs.getDouble("MIN_LONGITUDE"); double max_longitude = rs.getDouble("MAX_LONGITUDE"); String device_identification = rs.getString("DEVICE_IDENTIFICATION"); + String device_name = rs.getString("NAME"); String device_type = rs.getString("TYPE"); String last_seen = rs.getString("LAST_UPDATED_TIMESTAMP"); long count = rs.getLong("COUNT"); String geohashPrefix = rs.getString("GEOHASH_PREFIX"); geoClusters.add(new GeoCluster(new GeoCoordinate(latitude, longitude), new GeoCoordinate(min_latitude, min_longitude), new GeoCoordinate(max_latitude, max_longitude), - count, geohashPrefix, device_identification, device_type, last_seen)); + count, geohashPrefix, device_identification, device_name, device_type, last_seen)); } } catch (SQLException e) { throw new DeviceManagementDAOException("Error occurred while retrieving information of " + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java index 63df06538d..f4bda81221 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java @@ -30,6 +30,8 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.impl.AbstractDeviceDAOImpl; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; +import org.wso2.carbon.device.mgt.core.geo.GeoCluster; +import org.wso2.carbon.device.mgt.core.geo.geoHash.GeoCoordinate; import org.wso2.carbon.device.mgt.core.report.mgt.Constants; import java.sql.Connection; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java index 7aa74a1f1c..1d0d9c246c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java @@ -968,6 +968,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { + ") AS GEOHASH_PREFIX, " + "COUNT(*) AS COUNT, " + "MIN(DEVICE.DEVICE_IDENTIFICATION) AS DEVICE_IDENTIFICATION, " + + "MIN(DEVICE.NAME) AS NAME, " + "MIN(DEVICE_TYPE.NAME) AS TYPE, " + "MIN(DEVICE.LAST_UPDATED_TIMESTAMP) AS LAST_UPDATED_TIMESTAMP, " + "COUNT(DEVICE_LOCATION.GEO_HASH) " @@ -1004,6 +1005,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { double min_longitude = rs.getDouble("MIN_LONGITUDE"); double max_longitude = rs.getDouble("MAX_LONGITUDE"); String device_identification = rs.getString("DEVICE_IDENTIFICATION"); + String device_name = rs.getString("NAME"); String device_type = rs.getString("TYPE"); String last_seen = rs.getString("LAST_UPDATED_TIMESTAMP"); long count = rs.getLong("COUNT"); @@ -1011,7 +1013,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { geoClusters.add(new GeoCluster(new GeoCoordinate(latitude, longitude), new GeoCoordinate(min_latitude, min_longitude), new GeoCoordinate(max_latitude, max_longitude), count, geohashPrefix, - device_identification, device_type, last_seen)); + device_identification, device_name, device_type, last_seen)); } } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/GeoCluster.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/GeoCluster.java index 6fa306f20b..e4838aaf6e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/GeoCluster.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/GeoCluster.java @@ -9,18 +9,20 @@ public class GeoCluster { private long count; private String geohashPrefix; private String deviceIdentification; + private String deviceName; private String deviceType; private String lastSeen; public GeoCluster(GeoCoordinate coordinates, GeoCoordinate southWestBound, GeoCoordinate northEastBound, long count, - String geohashPrefix, String deviceIdentification, String deviceType, String lastSeen){ + String geohashPrefix, String deviceIdentification, String deviceName, String deviceType, String lastSeen){ this.coordinates=coordinates; this.southWestBound=southWestBound; this.northEastBound=northEastBound; this.count=count; this.geohashPrefix=geohashPrefix; this.deviceIdentification=deviceIdentification; + this.deviceName=deviceName; this.deviceType=deviceType; this.lastSeen = lastSeen; @@ -50,6 +52,10 @@ public class GeoCluster { return deviceIdentification; } + public String getDeviceName() { + return deviceName; + } + public String getDeviceType() { return deviceType; }