1
0

changed deviceId from Integer to String/CHAR(6)

This commit is contained in:
Jose
2025-05-08 18:23:12 +02:00
parent 5665cb3e5e
commit b6f13cfff8
29 changed files with 445 additions and 248 deletions

View File

@@ -11,6 +11,8 @@ public class Constants {
/* API Endpoints */
public static final String POST_PAYLOAD = RAW_API_PREFIX + "/device-payload";
public static final String GET_GROUPS = RAW_API_PREFIX + "/groups";
public static final String POST_GROUPS = RAW_API_PREFIX + "/groups";
public static final String PUT_GROUP_BY_ID = RAW_API_PREFIX + "/groups/:groupId";

View File

@@ -10,7 +10,7 @@ import net.miarma.contaminus.util.DateParser;
public class Actuator {
private Integer actuatorId;
private Integer deviceId;
private String deviceId;
private Integer status;
private Long timestamp;
@@ -18,12 +18,12 @@ public class Actuator {
public Actuator(Row row) {
this.actuatorId = row.getInteger("actuatorId");
this.deviceId = row.getInteger("deviceId");
this.deviceId = row.getString("deviceId");
this.status = row.getInteger("status");
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
}
public Actuator(Integer actuatorId, Integer deviceId, Integer status, Long timestamp) {
public Actuator(Integer actuatorId, String deviceId, Integer status, Long timestamp) {
super();
this.actuatorId = actuatorId;
this.deviceId = deviceId;
@@ -39,11 +39,11 @@ public class Actuator {
this.actuatorId = actuatorId;
}
public Integer getDeviceId() {
public String getDeviceId() {
return deviceId;
}
public void setDeviceId(Integer deviceId) {
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}

View File

@@ -10,6 +10,7 @@ import net.miarma.contaminus.util.DateParser;
public class COValue {
private Integer valueId;
private String deviceId;
private Integer sensorId;
private Float value;
private Long timestamp;
@@ -18,14 +19,16 @@ public class COValue {
public COValue(Row row) {
this.valueId = row.getInteger("valueId");
this.deviceId = row.getString("deviceId");
this.sensorId = row.getInteger("sensorId");
this.value = row.getFloat("value");
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
}
public COValue(Integer valueId, Integer sensorId, Float value, Long timestamp) {
public COValue(Integer valueId, String deviceId, Integer sensorId, Float value, Long timestamp) {
super();
this.valueId = valueId;
this.deviceId = deviceId;
this.sensorId = sensorId;
this.value = value;
this.timestamp = timestamp;
@@ -38,6 +41,14 @@ public class COValue {
public void setValueId(Integer valueId) {
this.valueId = valueId;
}
public String getDeviceId() {
return deviceId;
}
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}
public Integer getSensorId() {
return sensorId;
@@ -65,7 +76,7 @@ public class COValue {
@Override
public int hashCode() {
return Objects.hash(sensorId, timestamp, value, valueId);
return Objects.hash(deviceId, sensorId, timestamp, value, valueId);
}
@Override
@@ -77,17 +88,20 @@ public class COValue {
if (getClass() != obj.getClass())
return false;
COValue other = (COValue) obj;
return Objects.equals(sensorId, other.sensorId) && Objects.equals(timestamp, other.timestamp)
&& Objects.equals(value, other.value) && Objects.equals(valueId, other.valueId);
return Objects.equals(deviceId, other.deviceId) && Objects.equals(sensorId, other.sensorId)
&& Objects.equals(timestamp, other.timestamp) && Objects.equals(value, other.value)
&& Objects.equals(valueId, other.valueId);
}
@Override
public String toString() {
return "COValue [valueId=" + valueId + ", sensorId=" + sensorId + ", value=" + value + ", timestamp="
+ timestamp + "]";
return "COValue [valueId=" + valueId + ", deviceId=" + deviceId + ", sensorId=" + sensorId + ", value=" + value
+ ", timestamp=" + timestamp + "]";
}
public static COValue fromPayload(DevicePayload payload) {
return new COValue(null, payload.getDeviceId(), payload.getSensorId(), payload.getCarbonMonoxide(), payload.getTimestamp());
}
}

View File

@@ -6,30 +6,30 @@ import net.miarma.contaminus.common.Table;
@Table("devices")
public class Device {
private Integer deviceId;
private String deviceId;
private Integer groupId;
private String deviceName;
public Device() {}
public Device(Row row) {
this.deviceId = row.getInteger("deviceId");
this.deviceId = row.getString("deviceId");
this.groupId = row.getInteger("groupId");
this.deviceName = row.getString("deviceName");
}
public Device(Integer deviceId, Integer groupId, String deviceName) {
public Device(String deviceId, Integer groupId, String deviceName) {
super();
this.deviceId = deviceId;
this.groupId = groupId;
this.deviceName = deviceName;
}
public Integer getDeviceId() {
public String getDeviceId() {
return deviceId;
}
public void setDeviceId(Integer deviceId) {
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}

View File

@@ -8,26 +8,26 @@ import net.miarma.contaminus.util.DateParser;
@Table("v_co_by_device")
public class DeviceCO {
private Integer deviceId;
private String deviceId;
private Float carbonMonoxide;
private Long timestamp;
public DeviceCO() {}
public DeviceCO(Row row) {
this.deviceId = row.getInteger("deviceId");
this.deviceId = row.getString("deviceId");
this.carbonMonoxide = row.getFloat("carbonMonoxide");
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
}
public DeviceCO(Integer deviceId, Float carbonMonoxide, Long timestamp) {
public DeviceCO(String deviceId, Float carbonMonoxide, Long timestamp) {
super();
this.deviceId = deviceId;
this.carbonMonoxide = carbonMonoxide;
this.timestamp = timestamp;
}
public Integer getDeviceId() {
public String getDeviceId() {
return deviceId;
}

View File

@@ -8,7 +8,7 @@ import net.miarma.contaminus.util.DateParser;
@Table("v_gps_by_device")
public class DeviceGPS {
private Integer deviceId;
private String deviceId;
private Float lat;
private Float lon;
private Long timestamp;
@@ -16,20 +16,20 @@ public class DeviceGPS {
public DeviceGPS() {}
public DeviceGPS(Row row) {
this.deviceId = row.getInteger("deviceId");
this.deviceId = row.getString("deviceId");
this.lat = row.getFloat("lat");
this.lon = row.getFloat("lon");
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
}
public DeviceGPS(Integer deviceId, Float lat, Float lon) {
public DeviceGPS(String deviceId, Float lat, Float lon) {
super();
this.deviceId = deviceId;
this.lat = lat;
this.lon = lon;
}
public Integer getDeviceId() {
public String getDeviceId() {
return deviceId;
}

View File

@@ -7,7 +7,7 @@ import net.miarma.contaminus.util.DateParser;
@Table("v_latest_values")
public class DeviceLatestValuesView {
private Integer deviceId;
private String deviceId;
private Integer sensorId;
private String sensorType;
private String unit;
@@ -23,7 +23,7 @@ public class DeviceLatestValuesView {
public DeviceLatestValuesView() {}
public DeviceLatestValuesView(Row row) {
this.deviceId = row.getInteger("deviceId");
this.deviceId = row.getString("deviceId");
this.sensorId = row.getInteger("sensorId");
this.sensorType = row.getString("sensorType");
this.unit = row.getString("unit");
@@ -37,7 +37,7 @@ public class DeviceLatestValuesView {
this.airValuesTimestamp = DateParser.parseDate(row.getLocalDateTime("airValuesTimestamp"));
}
public DeviceLatestValuesView(Integer deviceId, Integer sensorId, String sensorType, String unit, Integer sensorStatus,
public DeviceLatestValuesView(String deviceId, Integer sensorId, String sensorType, String unit, Integer sensorStatus,
Long sensorTimestamp, Float temperature, Float humidity, Float carbonMonoxide, Float lat, Float lon,
Long airValuesTimestamp) {
super();
@@ -55,7 +55,7 @@ public class DeviceLatestValuesView {
this.airValuesTimestamp = airValuesTimestamp;
}
public Integer getDeviceId() {
public String getDeviceId() {
return deviceId;
}

View File

@@ -0,0 +1,130 @@
package net.miarma.contaminus.database.entities;
import java.util.Objects;
public class DevicePayload {
private String deviceId;
private Integer sensorId;
private Float temperature;
private Float humidity;
private Float pressure;
private Float carbonMonoxide;
private Float lat;
private Float lon;
private Long timestamp;
public DevicePayload() {}
public DevicePayload(String deviceId, Integer sensorId, String sensorType, String unit, Integer sensorStatus,
Float temperature, Float humidity, Float pressure, Float carbonMonoxide, Float lat, Float lon, Long timestamp) {
super();
this.deviceId = deviceId;
this.sensorId = sensorId;
this.temperature = temperature;
this.humidity = humidity;
this.pressure = pressure;
this.carbonMonoxide = carbonMonoxide;
this.lat = lat;
this.lon = lon;
this.timestamp = timestamp;
}
public String getDeviceId() {
return deviceId;
}
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}
public Integer getSensorId() {
return sensorId;
}
public void setSensorId(Integer sensorId) {
this.sensorId = sensorId;
}
public Float getTemperature() {
return temperature;
}
public void setTemperature(Float temperature) {
this.temperature = temperature;
}
public Float getHumidity() {
return humidity;
}
public void setHumidity(Float humidity) {
this.humidity = humidity;
}
public Float getPressure() {
return pressure;
}
public Float getCarbonMonoxide() {
return carbonMonoxide;
}
public void setCarbonMonoxide(Float carbonMonoxide) {
this.carbonMonoxide = carbonMonoxide;
}
public Float getLat() {
return lat;
}
public void setLat(Float lat) {
this.lat = lat;
}
public Float getLon() {
return lon;
}
public void setLon(Float lon) {
this.lon = lon;
}
public Long getTimestamp() {
return timestamp;
}
public void setTimestamp(Long timestamp) {
this.timestamp = timestamp;
}
@Override
public int hashCode() {
return Objects.hash(carbonMonoxide, deviceId, humidity, lat, lon, pressure, sensorId, temperature, timestamp);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
DevicePayload other = (DevicePayload) obj;
return Objects.equals(carbonMonoxide, other.carbonMonoxide) && Objects.equals(deviceId, other.deviceId)
&& Objects.equals(humidity, other.humidity) && Objects.equals(lat, other.lat)
&& Objects.equals(lon, other.lon) && Objects.equals(pressure, other.pressure)
&& Objects.equals(sensorId, other.sensorId) && Objects.equals(temperature, other.temperature)
&& Objects.equals(timestamp, other.timestamp);
}
@Override
public String toString() {
return "DevicePayload [deviceId=" + deviceId + ", sensorId=" + sensorId + ", temperature=" + temperature
+ ", humidity=" + humidity + ", pressure=" + pressure + ", carbonMonoxide=" + carbonMonoxide + ", lat="
+ lat + ", lon=" + lon + ", timestamp=" + timestamp + "]";
}
}

View File

@@ -8,7 +8,7 @@ import net.miarma.contaminus.util.DateParser;
@Table("v_pollution_map")
public class DevicePollutionMap {
private Integer deviceId;
private String deviceId;
private String deviceName;
private Float lat;
private Float lon;
@@ -18,7 +18,7 @@ public class DevicePollutionMap {
public DevicePollutionMap() {}
public DevicePollutionMap(Row row) {
this.deviceId = row.getInteger("deviceId");
this.deviceId = row.getString("deviceId");
this.deviceName = row.getString("deviceName");
this.lat = row.getFloat("lat");
this.lon = row.getFloat("lon");
@@ -26,7 +26,7 @@ public class DevicePollutionMap {
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
}
public DevicePollutionMap(Integer deviceId, String deviceName, Float lat, Float lon, Float carbonMonoxide,
public DevicePollutionMap(String deviceId, String deviceName, Float lat, Float lon, Float carbonMonoxide,
Long timestamp) {
super();
this.deviceId = deviceId;
@@ -37,7 +37,7 @@ public class DevicePollutionMap {
this.timestamp = timestamp;
}
public Integer getDeviceId() {
public String getDeviceId() {
return deviceId;
}

View File

@@ -8,7 +8,7 @@ import net.miarma.contaminus.util.DateParser;
@Table("v_sensor_history_by_device")
public class DeviceSensorHistory {
private Integer deviceId;
private String deviceId;
private String deviceName;
private Float value;
private String valueType;
@@ -17,14 +17,14 @@ public class DeviceSensorHistory {
public DeviceSensorHistory() {}
public DeviceSensorHistory(Row row) {
this.deviceId = row.getInteger("deviceId");
this.deviceId = row.getString("deviceId");
this.deviceName = row.getString("deviceName");
this.value = row.getFloat("value");
this.valueType = row.getString("valueType");
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
}
public DeviceSensorHistory(Integer deviceId, String deviceName, Float value, String valueType, Long timestamp) {
public DeviceSensorHistory(String deviceId, String deviceName, Float value, String valueType, Long timestamp) {
super();
this.deviceId = deviceId;
this.deviceName = deviceName;
@@ -33,7 +33,7 @@ public class DeviceSensorHistory {
this.timestamp = timestamp;
}
public Integer getDeviceId() {
public String getDeviceId() {
return deviceId;
}

View File

@@ -9,7 +9,7 @@ import net.miarma.contaminus.util.DateParser;
@Table("v_sensor_values")
public class DeviceSensorValue {
private Integer sensorId;
private Integer deviceId;
private String deviceId;
private String sensorType;
private String unit;
private Integer sensorStatus;
@@ -24,7 +24,7 @@ public class DeviceSensorValue {
public DeviceSensorValue(Row row) {
this.sensorId = row.getInteger("sensorId");
this.deviceId = row.getInteger("deviceId");
this.deviceId = row.getString("deviceId");
this.sensorType = row.getString("sensorType");
this.unit = row.getString("unit");
this.sensorStatus = row.getInteger("sensorStatus");
@@ -36,7 +36,7 @@ public class DeviceSensorValue {
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
}
public DeviceSensorValue(Integer sensorId, Integer deviceId, String sensorType, String unit, Integer sensorStatus,
public DeviceSensorValue(Integer sensorId, String deviceId, String sensorType, String unit, Integer sensorStatus,
Float temperature, Float humidity, Float carbonMonoxide, Float lat, Float lon, Long timestamp) {
super();
this.sensorId = sensorId;
@@ -56,7 +56,7 @@ public class DeviceSensorValue {
return sensorId;
}
public Integer getDeviceId() {
public String getDeviceId() {
return deviceId;
}

View File

@@ -8,7 +8,7 @@ import net.miarma.contaminus.util.DateParser;
@Table("v_weather_by_device")
public class DeviceWeather {
private Integer deviceId;
private String deviceId;
private Float temperature;
private Float humidity;
private Long timestamp;
@@ -16,13 +16,13 @@ public class DeviceWeather {
public DeviceWeather() {}
public DeviceWeather(Row row) {
this.deviceId = row.getInteger("deviceId");
this.deviceId = row.getString("deviceId");
this.temperature = row.getFloat("temperature");
this.humidity = row.getFloat("humidity");
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
}
public DeviceWeather(Integer deviceId, Float temperature, Float humidity, Long timestamp) {
public DeviceWeather(String deviceId, Float temperature, Float humidity, Long timestamp) {
super();
this.deviceId = deviceId;
this.temperature = temperature;
@@ -30,7 +30,7 @@ public class DeviceWeather {
this.timestamp = timestamp;
}
public Integer getDeviceId() {
public String getDeviceId() {
return deviceId;
}

View File

@@ -10,6 +10,7 @@ import net.miarma.contaminus.util.DateParser;
public class GpsValue {
private Integer valueId;
private String deviceId;
private Integer sensorId;
private Float lat;
private Float lon;
@@ -19,15 +20,17 @@ public class GpsValue {
public GpsValue(Row row) {
this.valueId = row.getInteger("valueId");
this.deviceId = row.getString("deviceId");
this.sensorId = row.getInteger("sensorId");
this.lat = row.getFloat("lat");
this.lon = row.getFloat("lon");
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
}
public GpsValue(Integer valueId, Integer sensorId, Float lat, Float lon, Long timestamp) {
public GpsValue(Integer valueId, String deviceId, Integer sensorId, Float lat, Float lon, Long timestamp) {
super();
this.valueId = valueId;
this.deviceId = deviceId;
this.sensorId = sensorId;
this.lat = lat;
this.lon = lon;
@@ -41,6 +44,14 @@ public class GpsValue {
public void setValueId(Integer valueId) {
this.valueId = valueId;
}
public String getDeviceId() {
return deviceId;
}
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}
public Integer getSensorId() {
return sensorId;
@@ -76,7 +87,7 @@ public class GpsValue {
@Override
public int hashCode() {
return Objects.hash(lat, lon, sensorId, timestamp, valueId);
return Objects.hash(deviceId, lat, lon, sensorId, timestamp, valueId);
}
@Override
@@ -88,17 +99,20 @@ public class GpsValue {
if (getClass() != obj.getClass())
return false;
GpsValue other = (GpsValue) obj;
return Objects.equals(lat, other.lat) && Objects.equals(lon, other.lon)
&& Objects.equals(sensorId, other.sensorId) && Objects.equals(timestamp, other.timestamp)
&& Objects.equals(valueId, other.valueId);
return Objects.equals(deviceId, other.deviceId) && Objects.equals(lat, other.lat)
&& Objects.equals(lon, other.lon) && Objects.equals(sensorId, other.sensorId)
&& Objects.equals(timestamp, other.timestamp) && Objects.equals(valueId, other.valueId);
}
@Override
public String toString() {
return "GpsValue [valueId=" + valueId + ", sensorId=" + sensorId + ", lat=" + lat + ", lon=" + lon
+ ", timestamp=" + timestamp + "]";
return "GpsValue [valueId=" + valueId + ", deviceId=" + deviceId + ", sensorId=" + sensorId + ", lat=" + lat
+ ", lon=" + lon + ", timestamp=" + timestamp + "]";
}
public static GpsValue fromPayload(DevicePayload payload) {
return new GpsValue(null, payload.getDeviceId(), payload.getSensorId(), payload.getLat(), payload.getLon(),
payload.getTimestamp());
}
}

View File

@@ -10,7 +10,7 @@ import net.miarma.contaminus.util.DateParser;
public class Sensor {
private Integer sensorId;
private Integer deviceId;
private String deviceId;
private String sensorType;
private String unit;
private Integer status;
@@ -20,14 +20,14 @@ public class Sensor {
public Sensor(Row row) {
this.sensorId = row.getInteger("sensorId");
this.deviceId = row.getInteger("deviceId");
this.deviceId = row.getString("deviceId");
this.sensorType = row.getString("sensorType");
this.unit = row.getString("unit");
this.status = row.getInteger("status");
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
}
public Sensor(Integer sensorId, Integer deviceId, String sensorType, String unit, Integer status, Long timestamp) {
public Sensor(Integer sensorId, String deviceId, String sensorType, String unit, Integer status, Long timestamp) {
super();
this.sensorId = sensorId;
this.deviceId = deviceId;
@@ -45,11 +45,11 @@ public class Sensor {
this.sensorId = sensorId;
}
public Integer getDeviceId() {
public String getDeviceId() {
return deviceId;
}
public void setDeviceId(Integer deviceId) {
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}

View File

@@ -10,27 +10,33 @@ import net.miarma.contaminus.util.DateParser;
public class WeatherValue {
private Integer valueId;
private String deviceId;
private Integer sensorId;
private Float temperature;
private Float humidity;
private Float pressure;
private Long timestamp;
public WeatherValue() {}
public WeatherValue(Row row) {
this.valueId = row.getInteger("valueId");
this.deviceId = row.getString("deviceId");
this.sensorId = row.getInteger("sensorId");
this.temperature = row.getFloat("temperature");
this.humidity = row.getFloat("humidity");
this.pressure = row.getFloat("pressure");
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
}
public WeatherValue(Integer valueId, Integer sensorId, Float temperature, Float humidity, Long timestamp) {
public WeatherValue(Integer valueId, String deviceId, Integer sensorId, Float temperature, Float humidity, Float pressure, Long timestamp) {
super();
this.valueId = valueId;
this.deviceId = deviceId;
this.sensorId = sensorId;
this.temperature = temperature;
this.humidity = humidity;
this.pressure = pressure;
this.timestamp = timestamp;
}
@@ -41,6 +47,14 @@ public class WeatherValue {
public void setValueId(Integer valueId) {
this.valueId = valueId;
}
public String getDeviceId() {
return deviceId;
}
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}
public Integer getSensorId() {
return sensorId;
@@ -65,6 +79,14 @@ public class WeatherValue {
public void setHumidity(Float humidity) {
this.humidity = humidity;
}
public Float getPressure() {
return pressure;
}
public void setPressure(Float pressure) {
this.pressure = pressure;
}
public Long getTimestamp() {
return timestamp;
@@ -76,7 +98,7 @@ public class WeatherValue {
@Override
public int hashCode() {
return Objects.hash(humidity, sensorId, temperature, timestamp, valueId);
return Objects.hash(deviceId, humidity, pressure, sensorId, temperature, timestamp, valueId);
}
@Override
@@ -88,17 +110,22 @@ public class WeatherValue {
if (getClass() != obj.getClass())
return false;
WeatherValue other = (WeatherValue) obj;
return Objects.equals(humidity, other.humidity) && Objects.equals(sensorId, other.sensorId)
return Objects.equals(deviceId, other.deviceId) && Objects.equals(humidity, other.humidity)
&& Objects.equals(pressure, other.pressure) && Objects.equals(sensorId, other.sensorId)
&& Objects.equals(temperature, other.temperature) && Objects.equals(timestamp, other.timestamp)
&& Objects.equals(valueId, other.valueId);
}
@Override
public String toString() {
return "WeatherValue [valueId=" + valueId + ", sensorId=" + sensorId + ", temperature=" + temperature
+ ", humidity=" + humidity + ", timestamp=" + timestamp + "]";
return "WeatherValue [valueId=" + valueId + ", deviceId=" + deviceId + ", sensorId=" + sensorId
+ ", temperature=" + temperature + ", humidity=" + humidity + ", pressure=" + pressure + ", timestamp="
+ timestamp + "]";
}
public static WeatherValue fromPayload(DevicePayload payload) {
return new WeatherValue(null, payload.getDeviceId(), payload.getSensorId(), payload.getTemperature(),
payload.getHumidity(), payload.getPressure(), payload.getTimestamp());
}
}

View File

@@ -23,13 +23,17 @@ import net.miarma.contaminus.common.SingleJsonResponse;
import net.miarma.contaminus.database.DatabaseManager;
import net.miarma.contaminus.database.QueryBuilder;
import net.miarma.contaminus.database.entities.Actuator;
import net.miarma.contaminus.database.entities.COValue;
import net.miarma.contaminus.database.entities.Device;
import net.miarma.contaminus.database.entities.DeviceLatestValuesView;
import net.miarma.contaminus.database.entities.DevicePayload;
import net.miarma.contaminus.database.entities.DevicePollutionMap;
import net.miarma.contaminus.database.entities.DeviceSensorHistory;
import net.miarma.contaminus.database.entities.DeviceSensorValue;
import net.miarma.contaminus.database.entities.GpsValue;
import net.miarma.contaminus.database.entities.Group;
import net.miarma.contaminus.database.entities.Sensor;
import net.miarma.contaminus.database.entities.WeatherValue;
/*
* This class is a Verticle that will handle the Data Layer API.
@@ -76,6 +80,9 @@ public class DataLayerAPIVerticle extends AbstractVerticle {
.allowedMethods(allowedMethods));
router.route().handler(BodyHandler.create());
// Payload
router.route(HttpMethod.POST, Constants.POST_PAYLOAD).handler(this::addDevicePayload);
// Group Routes
router.route(HttpMethod.GET, Constants.GET_GROUPS).handler(this::getAllGroups);
router.route(HttpMethod.GET, Constants.GET_GROUP_BY_ID).handler(this::getGroupById);
@@ -120,6 +127,48 @@ public class DataLayerAPIVerticle extends AbstractVerticle {
}
});
}
private void addDevicePayload(RoutingContext context) {
JsonObject body = context.body().asJsonObject();
DevicePayload devicePayload = gson.fromJson(body.toString(), DevicePayload.class);
COValue coValue = COValue.fromPayload(devicePayload);
GpsValue gpsValue = GpsValue.fromPayload(devicePayload);
WeatherValue weatherValue = WeatherValue.fromPayload(devicePayload);
String coQuery = QueryBuilder
.insert(coValue)
.build();
String gpsQuery = QueryBuilder
.insert(gpsValue)
.build();
String weatherQuery = QueryBuilder
.insert(weatherValue)
.build();
dbManager.execute(coQuery, COValue.class,
onSuccess -> {
dbManager.execute(gpsQuery, GpsValue.class,
onSuccess2 -> {
dbManager.execute(weatherQuery, WeatherValue.class,
onSuccess3 -> {
context.response()
.putHeader("content-type", "application/json; charset=utf-8")
.end(gson.toJson(SingleJsonResponse.of("Payload added successfully")));
},
onFailure3 -> {
context.fail(500, onFailure3);
});
},
onFailure2 -> {
context.fail(500, onFailure2);
});
},
onFailure -> {
context.fail(500, onFailure);
});
}
private void getAllGroups(RoutingContext context) {
String query = QueryBuilder
@@ -211,7 +260,7 @@ public class DataLayerAPIVerticle extends AbstractVerticle {
}
private void getDeviceById(RoutingContext context) {
Integer deviceId = Integer.parseInt(context.request().getParam("deviceId"));
String deviceId = context.request().getParam("deviceId");
Device device = new Device(deviceId, null, null);
String query = QueryBuilder

View File

@@ -95,7 +95,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
}
private void getDeviceSensors(RoutingContext context) {
Integer deviceId = Integer.parseInt(context.request().getParam("deviceId"));
String deviceId = context.request().getParam("deviceId");
Promise<Sensor[]> resultList = Promise.promise();
resultList.future().onComplete(result -> {
if (result.succeeded()) {
@@ -114,7 +114,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
}
private void getDeviceActuators(RoutingContext context) {
Integer deviceId = Integer.parseInt(context.request().getParam("deviceId"));
String deviceId = context.request().getParam("deviceId");
Promise<Actuator[]> resultList = Promise.promise();
resultList.future().onComplete(result -> {
if (result.succeeded()) {
@@ -133,7 +133,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
}
private void getDeviceLatestValues(RoutingContext context) {
Integer deviceId = Integer.parseInt(context.request().getParam("deviceId"));
String deviceId = context.request().getParam("deviceId");
Promise<DeviceLatestValuesView[]> resultList = Promise.promise();
resultList.future().onComplete(complete -> {
@@ -155,7 +155,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
}
private void getDevicePollutionMap(RoutingContext context) {
Integer deviceId = Integer.parseInt(context.request().getParam("deviceId"));
String deviceId = context.request().getParam("deviceId");
Promise<DevicePollutionMap[]> resultList = Promise.promise();
@@ -178,7 +178,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
}
private void getDeviceHistory(RoutingContext context) {
Integer deviceId = Integer.parseInt(context.request().getParam("deviceId"));
String deviceId = context.request().getParam("deviceId");
Promise<DeviceSensorHistory[]> resultList = Promise.promise();