Add Geo Json and fence shape attributes

corrective-policy
Pahansith 4 years ago
parent d9294c83f3
commit 47dc8ec708

@ -41,22 +41,29 @@ public class GeofenceWrapper {
@ApiModelProperty(
name = "latitude",
value = "Latitude of center of the geo fence",
required = true)
value = "Latitude of center of the geo fence")
private double latitude;
@ApiModelProperty(
name = "longitude",
value = "Longitude of center of the geo fence",
required = true)
value = "Longitude of center of the geo fence")
private double longitude;
@ApiModelProperty(
name = "radius",
value = "Radius from the center",
required = true)
value = "Radius from the center")
private float radius;
@ApiModelProperty(
name = "geoJson",
value = "JSON data set of the polygon fence")
private String geoJson;
@ApiModelProperty(
name = "fenceShape",
value = "Shape of the fence")
private String fenceShape;
public int getId() {
return id;
}
@ -104,4 +111,20 @@ public class GeofenceWrapper {
public void setRadius(float radius) {
this.radius = radius;
}
public String getGeoJson() {
return geoJson;
}
public void setGeoJson(String geoJson) {
this.geoJson = geoJson;
}
public String getFenceShape() {
return fenceShape;
}
public void setFenceShape(String fenceShape) {
this.fenceShape = fenceShape;
}
}

@ -597,6 +597,8 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
geofenceData.setLatitude(geofenceWrapper.getLatitude());
geofenceData.setLongitude(geofenceWrapper.getLongitude());
geofenceData.setRadius(geofenceWrapper.getRadius());
geofenceData.setGeoJson(geofenceWrapper.getGeoJson());
geofenceData.setFenceShape(geofenceWrapper.getFenceShape());
GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService();
if (!geoService.createGeofence(geofenceData)) {
@ -644,6 +646,8 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
geofenceWrapper.setLatitude(geofenceData.getLatitude());
geofenceWrapper.setLongitude(geofenceData.getLongitude());
geofenceWrapper.setRadius(geofenceData.getRadius());
geofenceWrapper.setGeoJson(geofenceData.getGeoJson());
geofenceWrapper.setFenceShape(geofenceData.getFenceShape());
return geofenceWrapper;
}

@ -526,29 +526,39 @@ public class RequestValidationUtil {
}
public static void validateGeofenceData(GeofenceWrapper geofenceWrapper) {
boolean isGeoJsonExists = false;
if (geofenceWrapper.getFenceName() == null || geofenceWrapper.getFenceName().trim().isEmpty()) {
String msg = "Geofence name should not be null or empty";
log.error(msg);
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
}
if (geofenceWrapper.getLatitude() < -90 || geofenceWrapper.getLatitude() > 90) {
if (!geofenceWrapper.getGeoJson().trim().isEmpty()) {
isGeoJsonExists = true;
}
if ((geofenceWrapper.getLatitude() < -90 || geofenceWrapper.getLatitude() > 90) && !isGeoJsonExists) {
String msg = "Latitude should be a value between -90 and 90";
log.error(msg);
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
}
if (geofenceWrapper.getLongitude() < -180 || geofenceWrapper.getLongitude() > 180) {
if ((geofenceWrapper.getLongitude() < -180 || geofenceWrapper.getLongitude() > 180) && !isGeoJsonExists) {
String msg = "Longitude should be a value between -180 and 180";
log.error(msg);
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
}
if (geofenceWrapper.getRadius() < 1) {
if (geofenceWrapper.getRadius() < 1 && !isGeoJsonExists) {
String msg = "Minimum radius of the fence should be 1m";
log.error(msg);
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
}
if (geofenceWrapper.getFenceShape().trim().isEmpty()) {
String msg = "Fence shape should not be empty";
log.error(msg);
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
}
}
}

@ -18,8 +18,6 @@
package org.wso2.carbon.device.mgt.common.geo.service;
import org.apache.commons.lang.StringUtils;
public class GeofenceData {
private int id;
private String fenceName;
@ -29,6 +27,8 @@ public class GeofenceData {
private float radius;
private int tenantId;
private String owner;
private String geoJson;
private String fenceShape;
public int getId() {
return id;
@ -93,4 +93,20 @@ public class GeofenceData {
public void setOwner(String owner) {
this.owner = owner;
}
public String getGeoJson() {
return geoJson;
}
public void setGeoJson(String geoJson) {
this.geoJson = geoJson;
}
public String getFenceShape() {
return fenceShape;
}
public void setFenceShape(String fenceShape) {
this.fenceShape = fenceShape;
}
}

@ -48,6 +48,8 @@ public class GeofenceDAOImpl implements GeofenceDAO {
"LATITUDE, " +
"LONGITUDE, " +
"RADIUS, " +
"GEO_JSON, " +
"FENCE_SHAPE, " +
"CREATED_TIMESTAMP, " +
"OWNER, " +
"TENANT_ID) " +
@ -58,9 +60,11 @@ public class GeofenceDAOImpl implements GeofenceDAO {
stmt.setDouble(3, geofenceData.getLatitude());
stmt.setDouble(4, geofenceData.getLongitude());
stmt.setFloat(5, geofenceData.getRadius());
stmt.setTimestamp(6, new Timestamp(new Date().getTime()));
stmt.setString(7, geofenceData.getOwner());
stmt.setInt(8, geofenceData.getTenantId());
stmt.setString(6, geofenceData.getGeoJson());
stmt.setString(7, geofenceData.getFenceShape());
stmt.setTimestamp(8, new Timestamp(new Date().getTime()));
stmt.setString(9, geofenceData.getOwner());
stmt.setInt(10, geofenceData.getTenantId());
return stmt.executeUpdate();
}
} catch (SQLException e) {
@ -82,6 +86,8 @@ public class GeofenceDAOImpl implements GeofenceDAO {
"LATITUDE, " +
"LONGITUDE, " +
"RADIUS, " +
"GEO_JSON, " +
"FENCE_SHAPE, " +
"OWNER, " +
"TENANT_ID " +
"FROM DM_GEOFENCE " +
@ -116,6 +122,8 @@ public class GeofenceDAOImpl implements GeofenceDAO {
"LATITUDE, " +
"LONGITUDE, " +
"RADIUS, " +
"GEO_JSON, " +
"FENCE_SHAPE, " +
"OWNER, " +
"TENANT_ID " +
"FROM DM_GEOFENCE " +
@ -163,6 +171,8 @@ public class GeofenceDAOImpl implements GeofenceDAO {
"LATITUDE = ?, " +
"LONGITUDE = ?, " +
"RADIUS = ? " +
"GEO_JSON = ? " +
"FENCE_SHAPE = ? " +
"WHERE ID = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, geofenceData.getFenceName());
@ -170,7 +180,9 @@ public class GeofenceDAOImpl implements GeofenceDAO {
stmt.setDouble(3, geofenceData.getLatitude());
stmt.setDouble(4, geofenceData.getLongitude());
stmt.setFloat(5, geofenceData.getRadius());
stmt.setInt(6, fenceId);
stmt.setString(6, geofenceData.getGeoJson());
stmt.setString(7, geofenceData.getFenceShape());
stmt.setInt(8, fenceId);
return stmt.executeUpdate();
}
} catch (SQLException e) {
@ -194,6 +206,8 @@ public class GeofenceDAOImpl implements GeofenceDAO {
geofenceData.setLatitude(rst.getDouble("LATITUDE"));
geofenceData.setLongitude(rst.getDouble("LONGITUDE"));
geofenceData.setRadius(rst.getFloat("RADIUS"));
geofenceData.setGeoJson(rst.getString("GEO_JSON"));
geofenceData.setFenceShape(rst.getString("FENCE_SHAPE"));
geofenceData.setOwner(rst.getString("OWNER"));
geofenceData.setTenantId(rst.getInt("TENANT_ID"));
geofenceDataList.add(geofenceData);

@ -658,6 +658,8 @@ CREATE TABLE IF NOT EXISTS DM_GEOFENCE (
LATITUDE DOUBLE NULL,
LONGITUDE DOUBLE NULL,
RADIUS DOUBLE NULL,
GEO_JSON TEXT DEFAULT NULL,
FENCE_SHAPE VARCHAR(100) DEFAULT NULL,
CREATED_TIMESTAMP TIMESTAMP NOT NULL,
OWNER VARCHAR(255) NOT NULL,
TENANT_ID INTEGER DEFAULT 0,

@ -703,9 +703,11 @@ CREATE TABLE DM_GEOFENCE (
ID INT IDENTITY NOT NULL,
FENCE_NAME VARCHAR(255) NOT NULL,
DESCRIPTION VARCHAR(MAX) DEFAULT NULL,
LATITUDE DECIMAL(3,5) NOT NULL,
LONGITUDE DECIMAL(3,5) NOT NULL,
RADIUS DECIMAL(30,4) NOT NULL,
LATITUDE DECIMAL(3,5) DEFAULT NULL,
LONGITUDE DECIMAL(3,5) DEFAULT NULL,
RADIUS DECIMAL(30,4) DEFAULT NULL,
GEO_JSON VARCHAR(MAX) DEFAULT NULL,
FENCE_SHAPE VARCHAR(100) DEFAULT NULL,
CREATED_TIMESTAMP DATETIME2 NOT NULL,
OWNER VARCHAR(255) NOT NULL,
TENANT_ID INTEGER DEFAULT 0,

@ -719,9 +719,11 @@ CREATE TABLE IF NOT EXISTS DM_GEOFENCE (
ID INT NOT NULL AUTO_INCREMENT,
FENCE_NAME VARCHAR(255) NOT NULL,
DESCRIPTION TEXT DEFAULT NULL,
LATITUDE DOUBLE NOT NULL,
LONGITUDE DOUBLE NOT NULL,
RADIUS DOUBLE NOT NULL,
LATITUDE DOUBLE DEFAULT NULL,
LONGITUDE DOUBLE DEFAULT NULL,
RADIUS DOUBLE DEFAULT NULL,
GEO_JSON TEXT DEFAULT NULL,
FENCE_SHAPE VARCHAR(100) DEFAULT NULL,
CREATED_TIMESTAMP TIMESTAMP NOT NULL,
OWNER VARCHAR(255) NOT NULL,
TENANT_ID INTEGER DEFAULT 0,

@ -1072,9 +1072,11 @@ CREATE TABLE DM_GEOFENCE (
ID NUMBER(10) NOT NULL,
FENCE_NAME VARCHAR2(255) NOT NULL,
DESCRIPTION CLOB DEFAULT NULL,
LATITUDE BINARY_DOUBLE NOT NULL,
LONGITUDE BINARY_DOUBLE NOT NULL,
RADIUS BINARY_DOUBLE NOT NULL,
LATITUDE BINARY_DOUBLE DEFAULT NULL,
LONGITUDE BINARY_DOUBLE DEFAULT NULL,
RADIUS BINARY_DOUBLE DEFAULT NULL,
GEO_JSON CLOB DEFAULT NULL,
FENCE_SHAPE VARCHAR2(100) DEFAULT NULL,
CREATED_TIMESTAMP TIMESTAMP(0) NOT NULL,
OWNER VARCHAR2(255) NOT NULL,
TENANT_ID NUMBER(10) DEFAULT 0,

@ -721,9 +721,11 @@ CREATE TABLE IF NOT EXISTS DM_GEOFENCE (
ID INTEGER DEFAULT NEXTVAL ('DM_GEOFENCE_seq') NOT NULL,
FENCE_NAME VARCHAR(255) NOT NULL,
DESCRIPTION TEXT DEFAULT NULL,
LATITUDE DECIMAL(3,5) NOT NULL,
LONGITUDE DECIMAL(3,5) NOT NULL,
RADIUS DECIMAL(35,3) NOT NULL,
LATITUDE DECIMAL(3,5) DEFAULT NULL,
LONGITUDE DECIMAL(3,5) DEFAULT NULL,
RADIUS DECIMAL(35,3) DEFAULT NULL,
GEO_JSON TEXT DEFAULT NULL,
FENCE_SHAPE VARCHAR(100) DEFAULT NULL,
CREATED_TIMESTAMP TIMESTAMP(0) NOT NULL,
OWNER VARCHAR(255) NOT NULL,
TENANT_ID INTEGER DEFAULT 0,

Loading…
Cancel
Save