device details can be get through the api

4.x.x
Gathika94 7 years ago
parent f5d1ab7403
commit ad061d09a6

@ -235,7 +235,7 @@ public interface GeoLocationBasedService {
}),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid Device Identifiers found.",
message = "Bad Request. \n Invalid parameters found.",
response = Response.class),
@ApiResponse(
code = 401,

@ -183,55 +183,13 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
@GET
@Consumes("application/json")
@Produces("application/json")
public Response getGeoDeviceLocations(//@QueryParam("horizontalDivisions") int horizontalDivisions,
//@QueryParam("verticalDivisions") int verticalDivisions,
public Response getGeoDeviceLocations(
@QueryParam("minLat") double minLat,
@QueryParam("maxLat") double maxLat,
@QueryParam("minLong") double minLong,
@QueryParam("maxLong") double maxLong,
@QueryParam("zoom") int zoom) {
/*DeviceManagementProviderService deviceManagementService = DeviceMgtAPIUtils.getDeviceManagementService();
GeoGrid geoGrid = new GeoGrid(horizontalDivisions, verticalDivisions, minLat, maxLat, minLong, maxLong);
try {
List<Device> devices = deviceManagementService.getAllDevices();
ArrayList<Device> devicesInGeoGrid = geoGrid.getDevicesInGeoGrid(devices);
List<GeoRectangle> geoRectangles = geoGrid.placeDevicesInGeoRectangles(devicesInGeoGrid);
Map<String, Map<String, String>> details = new HashMap<>();
for (GeoRectangle geoRectangle : geoRectangles) {
Map<String, String> rectangleDetails = new HashMap<>();
Map<String, Double> rectangleCoordinates = geoRectangle.getCoordinates();
String rectangleLat = rectangleCoordinates.get("Lat").toString();
String rectangleLong = rectangleCoordinates.get("Long").toString();
String minRectangleLat = geoRectangle.getMinLat().toString();
String maxRectangleLat = geoRectangle.getMaxLat().toString();
String minRectangleLong = geoRectangle.getMinLong().toString();
String maxRectangleLong = geoRectangle.getMaxLong().toString();
rectangleDetails.put("rectangleLat", rectangleLat);
rectangleDetails.put("rectangleLong", rectangleLong);
rectangleDetails.put("minLat",minRectangleLat);
rectangleDetails.put("maxLat",maxRectangleLat);
rectangleDetails.put("minLong",minRectangleLong);
rectangleDetails.put("maxLong",maxRectangleLong);
if (geoRectangle.getDeviceCount() == 0) {
rectangleDetails.put("count", "0");
rectangleDetails.put("deviceId", null);
} else if (geoRectangle.getDeviceCount() == 1) {
Device device = geoRectangle.getDevices().get(0);
rectangleDetails.put("count", "1");
rectangleDetails.put("deviceID", device.getDeviceIdentifier());
} else {
int deviceCount = geoRectangle.getDeviceCount();
rectangleDetails.put("count", Integer.toString(deviceCount));
rectangleDetails.put("deviceID", null);
}
details.put(geoRectangle.getId().toString(), rectangleDetails);
}
return Response.ok().entity(details).build();*/
GeoHashLengthStrategy geoHashLengthStrategy= new ZoomGeoHashLengthStrategy();
GeoCoordinate southWest = new GeoCoordinate(minLat, minLong);
GeoCoordinate northEast = new GeoCoordinate(maxLat, maxLong);
@ -241,7 +199,7 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
try {
geoClusters = deviceManagementService.findGeoClusters(southWest, northEast, geohashLength);
} catch (DeviceManagementException e) {
String msg = "Error occurred ";
String msg = "Error occurred when finding geo clusters ";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
}

@ -1070,14 +1070,19 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
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, 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";
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, " +
"MIN(DEVICE_TYPE.NAME) AS TYPE " +
"FROM DM_DEVICE_LOCATION AS DEVICE_LOCATION,DM_DEVICE AS DEVICE, DM_DEVICE_TYPE AS DEVICE_TYPE " +
"WHERE DEVICE_LOCATION.LATITUDE BETWEEN ? AND ? AND " +
"DEVICE_LOCATION.LONGITUDE BETWEEN ? AND ? AND " +
"DEVICE.TENANT_ID=? AND " +
"DEVICE.ID=DEVICE_LOCATION.DEVICE_ID AND DEVICE.DEVICE_TYPE_ID=DEVICE_TYPE.ID" +
" GROUP BY GEOHASH_PREFIX";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, geohashLength);
stmt.setDouble(2, southWest.getLatitude());
@ -1094,11 +1099,12 @@ 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_type=rs.getString("TYPE");
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));
count, geohashPrefix,device_identification,device_type));
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving information of " +

@ -9,16 +9,20 @@ public class GeoCluster {
private long count;
private String geohashPrefix;
private String deviceIdentification;
private String deviceType;
public GeoCluster(GeoCoordinate coordinates,GeoCoordinate southWestBound,GeoCoordinate northEastBound,long count,
String geohashPrefix,String deviceIdentification){
public GeoCluster(GeoCoordinate coordinates, GeoCoordinate southWestBound, GeoCoordinate northEastBound, long count,
String geohashPrefix, String deviceIdentification, String deviceType){
this.coordinates=coordinates;
this.southWestBound=southWestBound;
this.northEastBound=northEastBound;
this.count=count;
this.geohashPrefix=geohashPrefix;
this.deviceIdentification=deviceIdentification;
this.deviceType=deviceType;
}
public String getGeohashPrefix() {
@ -44,4 +48,7 @@ public class GeoCluster {
public String getDeviceIdentification() {
return deviceIdentification;
}
public String getDeviceType() { return deviceType;
}
}

Loading…
Cancel
Save