mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
device details can be get through the api
This commit is contained in:
parent
f5d1ab7403
commit
ad061d09a6
@ -235,7 +235,7 @@ public interface GeoLocationBasedService {
|
|||||||
}),
|
}),
|
||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
code = 400,
|
code = 400,
|
||||||
message = "Bad Request. \n Invalid Device Identifiers found.",
|
message = "Bad Request. \n Invalid parameters found.",
|
||||||
response = Response.class),
|
response = Response.class),
|
||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
code = 401,
|
code = 401,
|
||||||
|
|||||||
@ -183,55 +183,13 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
|
|||||||
@GET
|
@GET
|
||||||
@Consumes("application/json")
|
@Consumes("application/json")
|
||||||
@Produces("application/json")
|
@Produces("application/json")
|
||||||
public Response getGeoDeviceLocations(//@QueryParam("horizontalDivisions") int horizontalDivisions,
|
public Response getGeoDeviceLocations(
|
||||||
//@QueryParam("verticalDivisions") int verticalDivisions,
|
|
||||||
@QueryParam("minLat") double minLat,
|
@QueryParam("minLat") double minLat,
|
||||||
@QueryParam("maxLat") double maxLat,
|
@QueryParam("maxLat") double maxLat,
|
||||||
@QueryParam("minLong") double minLong,
|
@QueryParam("minLong") double minLong,
|
||||||
@QueryParam("maxLong") double maxLong,
|
@QueryParam("maxLong") double maxLong,
|
||||||
@QueryParam("zoom") int zoom) {
|
@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();
|
GeoHashLengthStrategy geoHashLengthStrategy= new ZoomGeoHashLengthStrategy();
|
||||||
GeoCoordinate southWest = new GeoCoordinate(minLat, minLong);
|
GeoCoordinate southWest = new GeoCoordinate(minLat, minLong);
|
||||||
GeoCoordinate northEast = new GeoCoordinate(maxLat, maxLong);
|
GeoCoordinate northEast = new GeoCoordinate(maxLat, maxLong);
|
||||||
@ -241,7 +199,7 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
|
|||||||
try {
|
try {
|
||||||
geoClusters = deviceManagementService.findGeoClusters(southWest, northEast, geohashLength);
|
geoClusters = deviceManagementService.findGeoClusters(southWest, northEast, geohashLength);
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred ";
|
String msg = "Error occurred when finding geo clusters ";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
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<>();
|
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 " +
|
String sql ="SELECT AVG(DEVICE_LOCATION.LATITUDE) AS LATITUDE,AVG(DEVICE_LOCATION.LONGITUDE) AS LONGITUDE," +
|
||||||
"LONGITUDE, MIN(DEVICE_LOCATION.LATITUDE) AS MIN_LATITUDE, MAX(DEVICE_LOCATION.LATITUDE) " +
|
" MIN(DEVICE_LOCATION.LATITUDE) AS MIN_LATITUDE, MAX(DEVICE_LOCATION.LATITUDE) AS MAX_LATITUDE," +
|
||||||
"AS MAX_LATITUDE, MIN(DEVICE_LOCATION.LONGITUDE) AS MIN_LONGITUDE, MAX(DEVICE_LOCATION.LONGITUDE)" +
|
" MIN(DEVICE_LOCATION.LONGITUDE) AS MIN_LONGITUDE," +
|
||||||
" AS MAX_LONGITUDE, SUBSTRING (DEVICE_LOCATION.GEO_HASH,1,?) AS GEOHASH_PREFIX, COUNT(*) " +
|
" MAX(DEVICE_LOCATION.LONGITUDE) AS MAX_LONGITUDE, " +
|
||||||
"AS COUNT, MIN(DEVICE.DEVICE_IDENTIFICATION) AS DEVICE_IDENTIFICATION FROM DM_DEVICE_LOCATION AS" +
|
"SUBSTRING (DEVICE_LOCATION.GEO_HASH,1,?) AS GEOHASH_PREFIX, COUNT(*) AS COUNT, " +
|
||||||
" DEVICE_LOCATION,DM_DEVICE AS DEVICE WHERE DEVICE_LOCATION.LATITUDE BETWEEN ? AND ? AND " +
|
"MIN(DEVICE.DEVICE_IDENTIFICATION) AS DEVICE_IDENTIFICATION, " +
|
||||||
"DEVICE_LOCATION.LONGITUDE BETWEEN ? AND ? AND DEVICE.TENANT_ID=? AND " +
|
"MIN(DEVICE_TYPE.NAME) AS TYPE " +
|
||||||
"DEVICE.ID=DEVICE_LOCATION.DEVICE_ID GROUP BY GEOHASH_PREFIX";
|
"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 = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, geohashLength);
|
stmt.setInt(1, geohashLength);
|
||||||
stmt.setDouble(2, southWest.getLatitude());
|
stmt.setDouble(2, southWest.getLatitude());
|
||||||
@ -1094,11 +1099,12 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
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");
|
String device_identification = rs.getString("DEVICE_IDENTIFICATION");
|
||||||
|
String device_type=rs.getString("TYPE");
|
||||||
long count = rs.getLong("COUNT");
|
long count = rs.getLong("COUNT");
|
||||||
String geohashPrefix = rs.getString("GEOHASH_PREFIX");
|
String geohashPrefix = rs.getString("GEOHASH_PREFIX");
|
||||||
geoClusters.add(new GeoCluster(new GeoCoordinate(latitude, longitude),
|
geoClusters.add(new GeoCluster(new GeoCoordinate(latitude, longitude),
|
||||||
new GeoCoordinate(min_latitude,min_longitude), new GeoCoordinate(max_latitude,max_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) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceManagementDAOException("Error occurred while retrieving information of " +
|
throw new DeviceManagementDAOException("Error occurred while retrieving information of " +
|
||||||
|
|||||||
@ -9,16 +9,20 @@ public class GeoCluster {
|
|||||||
private long count;
|
private long count;
|
||||||
private String geohashPrefix;
|
private String geohashPrefix;
|
||||||
private String deviceIdentification;
|
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.coordinates=coordinates;
|
||||||
this.southWestBound=southWestBound;
|
this.southWestBound=southWestBound;
|
||||||
this.northEastBound=northEastBound;
|
this.northEastBound=northEastBound;
|
||||||
this.count=count;
|
this.count=count;
|
||||||
this.geohashPrefix=geohashPrefix;
|
this.geohashPrefix=geohashPrefix;
|
||||||
this.deviceIdentification=deviceIdentification;
|
this.deviceIdentification=deviceIdentification;
|
||||||
|
this.deviceType=deviceType;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getGeohashPrefix() {
|
public String getGeohashPrefix() {
|
||||||
@ -44,4 +48,7 @@ public class GeoCluster {
|
|||||||
public String getDeviceIdentification() {
|
public String getDeviceIdentification() {
|
||||||
return deviceIdentification;
|
return deviceIdentification;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDeviceType() { return deviceType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user