From f5d1ab7403395aa5fb036c40ad2745de7b69da58 Mon Sep 17 00:00:00 2001 From: Gathika94 Date: Mon, 20 Nov 2017 14:45:14 +0530 Subject: [PATCH] backend api working properly --- .../service/api/GeoLocationBasedService.java | 22 ++++++++++--- .../impl/GeoLocationBasedServiceImpl.java | 2 +- .../core/dao/impl/AbstractDeviceDAOImpl.java | 22 +++++++------ .../device/mgt/core/geo/GeoCluster.java | 31 +++++++++++++++---- 4 files changed, 57 insertions(+), 20 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GeoLocationBasedService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GeoLocationBasedService.java index 64a5566f69..c6db0370a8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GeoLocationBasedService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GeoLocationBasedService.java @@ -247,15 +247,29 @@ public interface GeoLocationBasedService { }) Response getGeoDeviceLocations( @ApiParam( - name = "deviceId", - value = "The registered device Id.", + name = "minLat", + value = "minimum latitude", required = true) - //@QueryParam("horizontalDivisions") int horizontalDivisions, - //@QueryParam("verticalDivisions") int verticalDivisions, @QueryParam("minLat") double minLat, + @ApiParam( + name = "maxLat", + value = "maxmimum latitude", + required = true) @QueryParam("maxLat") double maxLat, + @ApiParam( + name = "minLong", + value = "minimum longitude", + required = true) @QueryParam("minLong") double minLong, + @ApiParam( + name = "maxLong", + value = "maximum longitudeude", + required = true) @QueryParam("maxLong") double maxLong, + @ApiParam( + name = "zoom", + value = "zoom level", + required = true) @QueryParam("zoom") int zoom); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java index fa50719e74..ac3e7972ee 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java @@ -237,7 +237,7 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { GeoCoordinate northEast = new GeoCoordinate(maxLat, maxLong); int geohashLength = geoHashLengthStrategy.getGeohashLength(southWest, northEast, zoom); DeviceManagementProviderService deviceManagementService=DeviceMgtAPIUtils.getDeviceManagementService(); - List geoClusters = null; + List geoClusters; try { geoClusters = deviceManagementService.findGeoClusters(southWest, northEast, geohashLength); } catch (DeviceManagementException e) { 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 df8fc22d5d..643d599381 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 @@ -1067,15 +1067,16 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { Connection conn; PreparedStatement stmt = null; ResultSet rs = null; - List results = new ArrayList<>(); + List geoClusters = new ArrayList<>(); try { conn = this.getConnection(); - String sql ="SELECT AVG(DEVICE_LOCATION.LATITUDE) AS LATITUDE,AVG(DEVICE_LOCATION.LONGITUDE) AS LONGITUDE" + - ", MIN(DEVICE_LOCATION.LATITUDE) AS MIN_LATITUDE, MAX(DEVICE_LOCATION.LATITUDE) AS MAX_LATITUDE, " + - "MIN(DEVICE_LOCATION.LONGITUDE) AS MIN_LONGITUDE, MAX(DEVICE_LOCATION.LONGITUDE) AS MAX_LONGITUDE" + - ", SUBSTRING (DEVICE_LOCATION.GEO_HASH,1,?) AS GEOHASH_PREFIX, COUNT(*) AS COUNT FROM " + - "DM_DEVICE_LOCATION AS DEVICE_LOCATION,DM_DEVICE AS DEVICE WHERE DEVICE_LOCATION.LATITUDE BETWEEN" + - " ? AND ? AND DEVICE_LOCATION.LONGITUDE BETWEEN ? AND ? AND DEVICE.TENANT_ID=? AND " + + String sql ="SELECT AVG(DEVICE_LOCATION.LATITUDE) AS LATITUDE,AVG(DEVICE_LOCATION.LONGITUDE) AS " + + "LONGITUDE, MIN(DEVICE_LOCATION.LATITUDE) AS MIN_LATITUDE, MAX(DEVICE_LOCATION.LATITUDE) " + + "AS MAX_LATITUDE, MIN(DEVICE_LOCATION.LONGITUDE) AS MIN_LONGITUDE, 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 FROM DM_DEVICE_LOCATION AS" + + " DEVICE_LOCATION,DM_DEVICE AS DEVICE WHERE DEVICE_LOCATION.LATITUDE BETWEEN ? AND ? AND " + + "DEVICE_LOCATION.LONGITUDE BETWEEN ? AND ? AND DEVICE.TENANT_ID=? AND " + "DEVICE.ID=DEVICE_LOCATION.DEVICE_ID GROUP BY GEOHASH_PREFIX"; stmt = conn.prepareStatement(sql); stmt.setInt(1, geohashLength); @@ -1092,9 +1093,12 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { double max_latitude = rs.getDouble("MAX_LATITUDE"); double min_longitude = rs.getDouble("MIN_LONGITUDE"); double max_longitude = rs.getDouble("MAX_LONGITUDE"); + String device_identification = rs.getString("DEVICE_IDENTIFICATION"); long count = rs.getLong("COUNT"); String geohashPrefix = rs.getString("GEOHASH_PREFIX"); - results.add(new GeoCluster(new GeoCoordinate(latitude, longitude), count, geohashPrefix)); + geoClusters.add(new GeoCluster(new GeoCoordinate(latitude, longitude), + new GeoCoordinate(min_latitude,min_longitude), new GeoCoordinate(max_latitude,max_longitude), + count, geohashPrefix,device_identification)); } } catch (SQLException e) { throw new DeviceManagementDAOException("Error occurred while retrieving information of " + @@ -1102,6 +1106,6 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } - return results; + return geoClusters; } } 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 ace906a6be..46720671c1 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 @@ -4,25 +4,44 @@ import org.wso2.carbon.device.mgt.core.geo.geoHash.GeoCoordinate; public class GeoCluster { private GeoCoordinate coordinates; + private GeoCoordinate southWestBound; + private GeoCoordinate northEastBound; private long count; private String geohashPrefix; - private String deviceId; + private String deviceIdentification; - public GeoCluster(GeoCoordinate coordinates,long count,String geohashPrefix){ + + public GeoCluster(GeoCoordinate coordinates,GeoCoordinate southWestBound,GeoCoordinate northEastBound,long count, + String geohashPrefix,String deviceIdentification){ this.coordinates=coordinates; + this.southWestBound=southWestBound; + this.northEastBound=northEastBound; this.count=count; this.geohashPrefix=geohashPrefix; + this.deviceIdentification=deviceIdentification; + } + + public String getGeohashPrefix() { + return geohashPrefix; } public long getCount() { return count; } - public void setDeviceId(String deviceId) { - this.deviceId = deviceId; + public GeoCoordinate getCoordinates() { + return coordinates; + } + + public GeoCoordinate getSouthWestBound() { + return southWestBound; + } + + public GeoCoordinate getNorthEastBound() { + return northEastBound; } - public String getDeviceId() { - return deviceId; + public String getDeviceIdentification() { + return deviceIdentification; } }