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 bb97b606ba..af920e2ef8 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 @@ -209,7 +209,7 @@ public interface GeoLocationBasedService { consumes = "application/json", produces = "application/json", httpMethod = "GET", - value = "Retrieve Analytics for the device group", + value = "Retrieve locations of devices", notes = "", response = Response.class, tags = "Geo Service Management", 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 cb529488d1..b44f5cc695 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 @@ -38,12 +38,9 @@ import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; import org.wso2.carbon.device.mgt.common.geo.service.*; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants; import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; -import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException; import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; import org.wso2.carbon.device.mgt.core.geo.GeoCluster; -import org.wso2.carbon.device.mgt.core.geo.GeoGrid; -import org.wso2.carbon.device.mgt.core.geo.GeoRectangle; import org.wso2.carbon.device.mgt.core.geo.geoHash.GeoCoordinate; import org.wso2.carbon.device.mgt.core.geo.geoHash.geoHashStrategy.GeoHashLengthStrategy; import org.wso2.carbon.device.mgt.core.geo.geoHash.geoHashStrategy.ZoomGeoHashLengthStrategy; @@ -199,7 +196,7 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { try { geoClusters = deviceManagementService.findGeoClusters(southWest, northEast, geohashLength); } catch (DeviceManagementException e) { - String msg = "Error occurred when finding geo clusters "; + String msg = "Error occurred while retrieving geo clusters "; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/GeoGrid.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/GeoGrid.java deleted file mode 100644 index 603347c0e6..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/GeoGrid.java +++ /dev/null @@ -1,115 +0,0 @@ -package org.wso2.carbon.device.mgt.core.geo; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; -import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException; -import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; -import org.wso2.carbon.device.mgt.core.device.details.mgt.impl.DeviceInformationManagerImpl; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -public class GeoGrid { - private static Log log = LogFactory.getLog(GeoRectangle.class); - DeviceInformationManager deviceInformationManagerService = new DeviceInformationManagerImpl(); - private int horizontalDivisions; - private int verticalDivisions; - private double minLat; - private double maxLat; - private double minLong; - private double maxLong; - private double latDistance; - private double longitudeDistance; - private double latIncrement; - private double longIncrement; - private ArrayList geoRectangles = new ArrayList<>(); - - public GeoGrid(int horizontalDivisions, int verticalDivisions, double minLat, double maxLat, double minLong, - double maxLong) { - this.horizontalDivisions = horizontalDivisions; - this.verticalDivisions = verticalDivisions; - this.minLat = minLat; - this.maxLat = maxLat; - this.minLong = minLong; - this.maxLong = maxLong; - this.latDistance = maxLat - minLat; - this.longitudeDistance = maxLong - minLong; - this.latIncrement = this.latDistance / this.horizontalDivisions; - this.longIncrement = this.longitudeDistance / this.verticalDivisions; - this.createGeoRectangles(); - } - - private void createGeoRectangles() { - double minRectangleLat; - double maxRectangleLat; - double minRectangleLong; - double maxRectangleLong; - Integer id = 0; - - for (int i = 0; i < verticalDivisions; i++) { - minRectangleLong = this.minLong + i * longIncrement; - if (i + 1 == verticalDivisions) { - maxRectangleLong = this.maxLong; - } else { - maxRectangleLong = this.minLong + (i + 1) * longIncrement; - } - - for (int m = 0; m < horizontalDivisions; m++) { - minRectangleLat = this.minLat + m * latIncrement; - if(m+1==horizontalDivisions){ - maxRectangleLat=this.maxLat; - }else { - maxRectangleLat = this.minLat + (m + 1) * latIncrement; - } - geoRectangles.add(new GeoRectangle(minRectangleLat, maxRectangleLat, minRectangleLong, maxRectangleLong)); - } - } - - } - - public ArrayList getGeoRectangles() { - return geoRectangles; - } - - public ArrayList getDevicesInGeoGrid(List devices) { - ArrayList devicesInGeoGrid = new ArrayList<>(); - for (Device device : devices) { - DeviceLocation location = null; - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()); - try { - location = deviceInformationManagerService.getDeviceLocation(deviceIdentifier); - } catch (DeviceDetailsMgtException e) { - String msg = "Exception occurred while retrieving device location." + deviceIdentifier; - log.error(msg, e); - return devicesInGeoGrid; - } - double locationLat = location.getLatitude(); - double locationLong = location.getLongitude(); - if (locationLat >= minLat && locationLat < maxLat && locationLong >= minLong && locationLong < maxLong) { - devicesInGeoGrid.add(device); - - } - } - return devicesInGeoGrid; - } - - public ArrayList placeDevicesInGeoRectangles(ArrayList devicesInGeoGrid) { - ArrayList remainingDevicesInGeoGrid = devicesInGeoGrid; - for (GeoRectangle geoRectangle : geoRectangles) { - Iterator remainingDevicesIterator = remainingDevicesInGeoGrid.iterator(); - while (remainingDevicesIterator.hasNext()) { - Device currentDevice = remainingDevicesIterator.next(); - if (geoRectangle.isDeviceInGeoRectangle(currentDevice)) { - geoRectangle.addDevice(currentDevice); - } - } - - } - return geoRectangles; - } - -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/GeoRectangle.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/GeoRectangle.java deleted file mode 100644 index ae91090dd3..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/GeoRectangle.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * 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. - */ - -package org.wso2.carbon.device.mgt.core.geo; - - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; -import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException; -import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; -import org.wso2.carbon.device.mgt.core.device.details.mgt.impl.DeviceInformationManagerImpl; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class GeoRectangle { - - private static int count = 0; - private static Log log = LogFactory.getLog(GeoRectangle.class); - DeviceInformationManager deviceInformationManagerService = new DeviceInformationManagerImpl(); - private double minLat; - private double maxLat; - private double minLong; - private double maxLong; - private double centerLat; - private double centerLong; - private double rectangleLat; - private double rectangleLong; - private double deviantLatValue = 1000; - private double deviantLongValue = 1000; - private int id; - private ArrayList devices = new ArrayList<>(); - - public GeoRectangle(double minLat, double maxLat, double minLong, double maxLong) { - this.minLat = minLat; - this.maxLat = maxLat; - this.minLong = minLong; - this.maxLong = maxLong; - this.centerLat = (this.minLat + this.maxLat) / 2; - this.centerLong = (this.minLong + this.maxLong) / 2; - this.rectangleLat = this.centerLat; - this.rectangleLong = this.centerLong; - count++; - this.id = count; - } - - public Map getCoordinates() { - Map rectangleCoordinates = new HashMap(); - - rectangleCoordinates.put("Lat", rectangleLat); - rectangleCoordinates.put("Long", rectangleLong); - return rectangleCoordinates; - } - - public boolean isDeviceInGeoRectangle(Device device) { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()); - try { - DeviceLocation location = deviceInformationManagerService.getDeviceLocation(deviceIdentifier); - double locationLat = location.getLatitude(); - double locationLong = location.getLongitude(); - if (locationLat >= minLat && locationLat < maxLat && locationLong >= minLong && locationLong < maxLong) { - checkLocationDeviants(locationLat, locationLong); - return true; - } else { - return false; - } - } catch (DeviceDetailsMgtException e) { - String msg = "Exception occurred while retrieving device location." + deviceIdentifier; - log.error(msg, e); - return false; - } - - - } - - private void checkLocationDeviants(double locationLat, double locationLong) { - double latDeviant = Math.abs(centerLat - locationLat); - double longDeviant = Math.abs(centerLong - locationLong); - if (latDeviant <= deviantLatValue) { - deviantLatValue = latDeviant; - rectangleLat = locationLat; - } - if (longDeviant <= deviantLongValue) { - deviantLongValue = longDeviant; - rectangleLong = locationLong; - } - } - - public void addDevice(Device device) { - devices.add(device); - } - - - public List getDevices() { - return devices; - } - - public int getDeviceCount() { - return devices.size(); - } - - public Double getMinLat() { - return minLat; - } - - public void setMinLat(double minLat) { - this.minLat = minLat; - } - - public Double getMaxLat() { - return maxLat; - } - - public void setMaxLat(double maxLat) { - this.maxLat = maxLat; - } - - public Double getMinLong() { - return minLong; - } - - public void setMinLong(double minLong) { - this.minLong = minLong; - } - - public Double getMaxLong() { - return maxLong; - } - - public void setMaxLong(double maxLong) { - this.maxLong = maxLong; - } - - public Integer getId() { - return id; - } - -} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/geoHash/GeoCoordinate.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/geoHash/GeoCoordinate.java index 14decb0c71..45ca28f0d4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/geoHash/GeoCoordinate.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/geoHash/GeoCoordinate.java @@ -1,5 +1,7 @@ package org.wso2.carbon.device.mgt.core.geo.geoHash; + + public class GeoCoordinate { private double latitude; private double longitude; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/geoHash/geoHashStrategy/GeoHashLengthStrategy.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/geoHash/geoHashStrategy/GeoHashLengthStrategy.java index 7f03ba5cc3..f6845b305e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/geoHash/geoHashStrategy/GeoHashLengthStrategy.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/geoHash/geoHashStrategy/GeoHashLengthStrategy.java @@ -2,6 +2,10 @@ package org.wso2.carbon.device.mgt.core.geo.geoHash.geoHashStrategy; import org.wso2.carbon.device.mgt.core.geo.geoHash.GeoCoordinate; +/** + * This interface is to decide a length for the geohash prefix + * which will be used to group the clusters based on geohash + */ public interface GeoHashLengthStrategy { int getGeohashLength(GeoCoordinate southWest, GeoCoordinate northEast, int zoom); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/geoHash/geoHashStrategy/ZoomGeoHashLengthStrategy.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/geoHash/geoHashStrategy/ZoomGeoHashLengthStrategy.java index d6fa1bf74c..0dd0e762f9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/geoHash/geoHashStrategy/ZoomGeoHashLengthStrategy.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/geoHash/geoHashStrategy/ZoomGeoHashLengthStrategy.java @@ -2,6 +2,9 @@ package org.wso2.carbon.device.mgt.core.geo.geoHash.geoHashStrategy; import org.wso2.carbon.device.mgt.core.geo.geoHash.GeoCoordinate; +/**A class that will decide the geoHashLength based on the zoom level and +* the boundaries of the map**/ + public class ZoomGeoHashLengthStrategy implements GeoHashLengthStrategy{ private int minGeohashLength = 1;