backend api working properly

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

@ -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);

@ -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<GeoCluster> geoClusters = null;
List<GeoCluster> geoClusters;
try {
geoClusters = deviceManagementService.findGeoClusters(southWest, northEast, geohashLength);
} catch (DeviceManagementException e) {

@ -1067,15 +1067,16 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<GeoCluster> results = new ArrayList<>();
List<GeoCluster> 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;
}
}

@ -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;
}
}

Loading…
Cancel
Save