backend api working properly

revert-70aa11f8
Gathika94 7 years ago
parent c74a56cb45
commit f5d1ab7403

@ -247,15 +247,29 @@ public interface GeoLocationBasedService {
}) })
Response getGeoDeviceLocations( Response getGeoDeviceLocations(
@ApiParam( @ApiParam(
name = "deviceId", name = "minLat",
value = "The registered device Id.", value = "minimum latitude",
required = true) required = true)
//@QueryParam("horizontalDivisions") int horizontalDivisions,
//@QueryParam("verticalDivisions") int verticalDivisions,
@QueryParam("minLat") double minLat, @QueryParam("minLat") double minLat,
@ApiParam(
name = "maxLat",
value = "maxmimum latitude",
required = true)
@QueryParam("maxLat") double maxLat, @QueryParam("maxLat") double maxLat,
@ApiParam(
name = "minLong",
value = "minimum longitude",
required = true)
@QueryParam("minLong") double minLong, @QueryParam("minLong") double minLong,
@ApiParam(
name = "maxLong",
value = "maximum longitudeude",
required = true)
@QueryParam("maxLong") double maxLong, @QueryParam("maxLong") double maxLong,
@ApiParam(
name = "zoom",
value = "zoom level",
required = true)
@QueryParam("zoom") int zoom); @QueryParam("zoom") int zoom);

@ -237,7 +237,7 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
GeoCoordinate northEast = new GeoCoordinate(maxLat, maxLong); GeoCoordinate northEast = new GeoCoordinate(maxLat, maxLong);
int geohashLength = geoHashLengthStrategy.getGeohashLength(southWest, northEast, zoom); int geohashLength = geoHashLengthStrategy.getGeohashLength(southWest, northEast, zoom);
DeviceManagementProviderService deviceManagementService=DeviceMgtAPIUtils.getDeviceManagementService(); DeviceManagementProviderService deviceManagementService=DeviceMgtAPIUtils.getDeviceManagementService();
List<GeoCluster> geoClusters = null; List<GeoCluster> geoClusters;
try { try {
geoClusters = deviceManagementService.findGeoClusters(southWest, northEast, geohashLength); geoClusters = deviceManagementService.findGeoClusters(southWest, northEast, geohashLength);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {

@ -1067,15 +1067,16 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
List<GeoCluster> results = new ArrayList<>(); List<GeoCluster> geoClusters = new ArrayList<>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql ="SELECT AVG(DEVICE_LOCATION.LATITUDE) AS LATITUDE,AVG(DEVICE_LOCATION.LONGITUDE) AS LONGITUDE" + String sql ="SELECT AVG(DEVICE_LOCATION.LATITUDE) AS LATITUDE,AVG(DEVICE_LOCATION.LONGITUDE) AS " +
", MIN(DEVICE_LOCATION.LATITUDE) AS MIN_LATITUDE, MAX(DEVICE_LOCATION.LATITUDE) AS MAX_LATITUDE, " + "LONGITUDE, MIN(DEVICE_LOCATION.LATITUDE) AS MIN_LATITUDE, MAX(DEVICE_LOCATION.LATITUDE) " +
"MIN(DEVICE_LOCATION.LONGITUDE) AS MIN_LONGITUDE, MAX(DEVICE_LOCATION.LONGITUDE) AS MAX_LONGITUDE" + "AS MAX_LATITUDE, MIN(DEVICE_LOCATION.LONGITUDE) AS MIN_LONGITUDE, MAX(DEVICE_LOCATION.LONGITUDE)" +
", SUBSTRING (DEVICE_LOCATION.GEO_HASH,1,?) AS GEOHASH_PREFIX, COUNT(*) AS COUNT FROM " + " AS MAX_LONGITUDE, SUBSTRING (DEVICE_LOCATION.GEO_HASH,1,?) AS GEOHASH_PREFIX, COUNT(*) " +
"DM_DEVICE_LOCATION AS DEVICE_LOCATION,DM_DEVICE AS DEVICE WHERE DEVICE_LOCATION.LATITUDE BETWEEN" + "AS COUNT, MIN(DEVICE.DEVICE_IDENTIFICATION) AS DEVICE_IDENTIFICATION FROM DM_DEVICE_LOCATION AS" +
" ? AND ? AND DEVICE_LOCATION.LONGITUDE BETWEEN ? AND ? AND DEVICE.TENANT_ID=? AND " + " 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"; "DEVICE.ID=DEVICE_LOCATION.DEVICE_ID GROUP BY GEOHASH_PREFIX";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, geohashLength); stmt.setInt(1, geohashLength);
@ -1092,9 +1093,12 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
double max_latitude = rs.getDouble("MAX_LATITUDE"); double max_latitude = rs.getDouble("MAX_LATITUDE");
double min_longitude = rs.getDouble("MIN_LONGITUDE"); double min_longitude = rs.getDouble("MIN_LONGITUDE");
double max_longitude = rs.getDouble("MAX_LONGITUDE"); double max_longitude = rs.getDouble("MAX_LONGITUDE");
String device_identification = rs.getString("DEVICE_IDENTIFICATION");
long count = rs.getLong("COUNT"); long count = rs.getLong("COUNT");
String geohashPrefix = rs.getString("GEOHASH_PREFIX"); 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) { } catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving information of " + throw new DeviceManagementDAOException("Error occurred while retrieving information of " +
@ -1102,6 +1106,6 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
return results; return geoClusters;
} }
} }

@ -4,25 +4,44 @@ import org.wso2.carbon.device.mgt.core.geo.geoHash.GeoCoordinate;
public class GeoCluster { public class GeoCluster {
private GeoCoordinate coordinates; private GeoCoordinate coordinates;
private GeoCoordinate southWestBound;
private GeoCoordinate northEastBound;
private long count; private long count;
private String geohashPrefix; 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.coordinates=coordinates;
this.southWestBound=southWestBound;
this.northEastBound=northEastBound;
this.count=count; this.count=count;
this.geohashPrefix=geohashPrefix; this.geohashPrefix=geohashPrefix;
this.deviceIdentification=deviceIdentification;
}
public String getGeohashPrefix() {
return geohashPrefix;
} }
public long getCount() { public long getCount() {
return count; return count;
} }
public void setDeviceId(String deviceId) { public GeoCoordinate getCoordinates() {
this.deviceId = deviceId; return coordinates;
}
public GeoCoordinate getSouthWestBound() {
return southWestBound;
}
public GeoCoordinate getNorthEastBound() {
return northEastBound;
} }
public String getDeviceId() { public String getDeviceIdentification() {
return deviceId; return deviceIdentification;
} }
} }

Loading…
Cancel
Save