1
0

Fixed errors in Business Logic API and finished it.

This commit is contained in:
Jose
2025-03-16 02:19:50 +01:00
parent 664aea42cd
commit e54f63ba74
17 changed files with 260 additions and 274 deletions

View File

@@ -9,10 +9,10 @@ import net.miarma.contaminus.util.DateParser;
@Table("actuators")
public class Actuator {
private int actuatorId;
private int deviceId;
private int status;
private long timestamp;
private Integer actuatorId;
private Integer deviceId;
private Integer status;
private Long timestamp;
public Actuator() {}
@@ -23,7 +23,7 @@ public class Actuator {
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
}
public Actuator(int actuatorId, int deviceId, int status, long timestamp) {
public Actuator(Integer actuatorId, Integer deviceId, Integer status, Long timestamp) {
super();
this.actuatorId = actuatorId;
this.deviceId = deviceId;
@@ -31,35 +31,35 @@ public class Actuator {
this.timestamp = timestamp;
}
public int getActuatorId() {
public Integer getActuatorId() {
return actuatorId;
}
public void setActuatorId(int actuatorId) {
public void setActuatorId(Integer actuatorId) {
this.actuatorId = actuatorId;
}
public int getDeviceId() {
public Integer getDeviceId() {
return deviceId;
}
public void setDeviceId(int deviceId) {
public void setDeviceId(Integer deviceId) {
this.deviceId = deviceId;
}
public int getStatus() {
public Integer getStatus() {
return status;
}
public void setStatus(int status) {
public void setStatus(Integer status) {
this.status = status;
}
public long getTimestamp() {
public Long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
public void setTimestamp(Long timestamp) {
this.timestamp = timestamp;
}

View File

@@ -9,10 +9,10 @@ import net.miarma.contaminus.util.DateParser;
@Table("co_values")
public class COValue {
private int valueId;
private int sensorId;
private float value;
private long timestamp;
private Integer valueId;
private Integer sensorId;
private Float value;
private Long timestamp;
public COValue() {}
@@ -23,7 +23,7 @@ public class COValue {
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
}
public COValue(int valueId, int sensorId, float value, long timestamp) {
public COValue(Integer valueId, Integer sensorId, Float value, Long timestamp) {
super();
this.valueId = valueId;
this.sensorId = sensorId;
@@ -31,35 +31,35 @@ public class COValue {
this.timestamp = timestamp;
}
public int getValueId() {
public Integer getValueId() {
return valueId;
}
public void setValueId(int valueId) {
public void setValueId(Integer valueId) {
this.valueId = valueId;
}
public int getSensorId() {
public Integer getSensorId() {
return sensorId;
}
public void setSensorId(int sensorId) {
public void setSensorId(Integer sensorId) {
this.sensorId = sensorId;
}
public float getValue() {
public Float getValue() {
return value;
}
public void setValue(float value) {
public void setValue(Float value) {
this.value = value;
}
public long getTimestamp() {
public Long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
public void setTimestamp(Long timestamp) {
this.timestamp = timestamp;
}
@@ -77,9 +77,8 @@ public class COValue {
if (getClass() != obj.getClass())
return false;
COValue other = (COValue) obj;
return sensorId == other.sensorId
&& Objects.equals(timestamp, other.timestamp)
&& Float.floatToIntBits(value) == Float.floatToIntBits(other.value) && valueId == other.valueId;
return Objects.equals(sensorId, other.sensorId) && Objects.equals(timestamp, other.timestamp)
&& Objects.equals(value, other.value) && Objects.equals(valueId, other.valueId);
}
@Override
@@ -89,4 +88,6 @@ public class COValue {
}
}

View File

@@ -1,15 +1,13 @@
package net.miarma.contaminus.database.entities;
import java.util.Objects;
import io.vertx.sqlclient.Row;
import net.miarma.contaminus.common.Table;
@Table("devices")
public class Device {
private int deviceId;
private int groupId;
private Integer deviceId;
private Integer groupId;
private String deviceName;
public Device() {}
@@ -20,26 +18,26 @@ public class Device {
this.deviceName = row.getString("deviceName");
}
public Device(int deviceId, int groupId, String deviceName) {
public Device(Integer deviceId, Integer groupId, String deviceName) {
super();
this.deviceId = deviceId;
this.groupId = groupId;
this.deviceName = deviceName;
}
public int getDeviceId() {
public Integer getDeviceId() {
return deviceId;
}
public void setDeviceId(int deviceId) {
public void setDeviceId(Integer deviceId) {
this.deviceId = deviceId;
}
public int getGroupId() {
public Integer getGroupId() {
return groupId;
}
public void setGroupId(int groupId) {
public void setGroupId(Integer groupId) {
this.groupId = groupId;
}
@@ -51,29 +49,7 @@ public class Device {
this.deviceName = deviceName;
}
@Override
public int hashCode() {
return Objects.hash(deviceId, deviceName, groupId);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Device other = (Device) obj;
return deviceId == other.deviceId
&& Objects.equals(deviceName, other.deviceName)
&& groupId == other.groupId;
}
@Override
public String toString() {
return "Device [deviceId=" + deviceId + ", groupId=" + groupId + ", deviceName=" + deviceName + "]";
}

View File

@@ -8,9 +8,9 @@ import net.miarma.contaminus.util.DateParser;
@Table("v_co_by_device")
public class DeviceCO {
int deviceId;
float carbonMonoxide;
long timestamp;
private Integer deviceId;
private Float carbonMonoxide;
private Long timestamp;
public DeviceCO() {}
@@ -20,22 +20,22 @@ public class DeviceCO {
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
}
public DeviceCO(int deviceId, float carbonMonoxide, long timestamp) {
public DeviceCO(Integer deviceId, Float carbonMonoxide, Long timestamp) {
super();
this.deviceId = deviceId;
this.carbonMonoxide = carbonMonoxide;
this.timestamp = timestamp;
}
public int getDeviceId() {
public Integer getDeviceId() {
return deviceId;
}
public float getCarbonMonoxide() {
public Float getCarbonMonoxide() {
return carbonMonoxide;
}
public long getTimestamp() {
public Long getTimestamp() {
return timestamp;
}
@@ -53,8 +53,8 @@ public class DeviceCO {
if (getClass() != obj.getClass())
return false;
DeviceCO other = (DeviceCO) obj;
return Float.floatToIntBits(carbonMonoxide) == Float.floatToIntBits(other.carbonMonoxide)
&& deviceId == other.deviceId && timestamp == other.timestamp;
return Objects.equals(carbonMonoxide, other.carbonMonoxide) && Objects.equals(deviceId, other.deviceId)
&& Objects.equals(timestamp, other.timestamp);
}
@Override
@@ -62,4 +62,6 @@ public class DeviceCO {
return "DeviceCO [deviceId=" + deviceId + ", carbonMonoxide=" + carbonMonoxide + ", timestamp=" + timestamp
+ "]";
}
}

View File

@@ -8,10 +8,10 @@ import net.miarma.contaminus.util.DateParser;
@Table("v_gps_by_device")
public class DeviceGPS {
int deviceId;
float lat;
float lon;
long timestamp;
private Integer deviceId;
private Float lat;
private Float lon;
private Long timestamp;
public DeviceGPS() {}
@@ -22,26 +22,26 @@ public class DeviceGPS {
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
}
public DeviceGPS(int deviceId, long lat, long lon) {
public DeviceGPS(Integer deviceId, Float lat, Float lon) {
super();
this.deviceId = deviceId;
this.lat = lat;
this.lon = lon;
}
public int getDeviceId() {
public Integer getDeviceId() {
return deviceId;
}
public float getLat() {
public Float getLat() {
return lat;
}
public float getLon() {
public Float getLon() {
return lon;
}
public long getTimestamp() {
public Long getTimestamp() {
return timestamp;
}
@@ -59,12 +59,14 @@ public class DeviceGPS {
if (getClass() != obj.getClass())
return false;
DeviceGPS other = (DeviceGPS) obj;
return deviceId == other.deviceId && Float.floatToIntBits(lat) == Float.floatToIntBits(other.lat)
&& Float.floatToIntBits(lon) == Float.floatToIntBits(other.lon) && timestamp == other.timestamp;
return Objects.equals(deviceId, other.deviceId) && Objects.equals(lat, other.lat)
&& Objects.equals(lon, other.lon) && Objects.equals(timestamp, other.timestamp);
}
@Override
public String toString() {
return "DeviceGPS [deviceId=" + deviceId + ", lat=" + lat + ", lon=" + lon + ", timestamp=" + timestamp + "]";
}
}

View File

@@ -7,44 +7,39 @@ import net.miarma.contaminus.util.DateParser;
@Table("v_latest_values")
public class DeviceLatestValuesView {
int deviceId;
int sensorId;
String sensorType;
String unit;
int sensorStatus;
long sensorTimestamp;
float temperature;
float humidity;
float carbonMonoxide;
float lat;
float lon;
long airValuesTimestamp;
private Integer deviceId;
private Integer sensorId;
private String sensorType;
private String unit;
private Integer sensorStatus;
private Long sensorTimestamp;
private Float temperature;
private Float humidity;
private Float carbonMonoxide;
private Float lat;
private Float lon;
private Long airValuesTimestamp;
public DeviceLatestValuesView() {}
public DeviceLatestValuesView(Row row) {
this.deviceId = row.getInteger("deviceId") != null ? row.getInteger("deviceId") : -1;
this.sensorId = row.getInteger("sensorId") != null ? row.getInteger("sensorId") : -1;
this.sensorType = row.getString("sensorType") != null ? row.getString("sensorType") : "unknown";
this.unit = row.getString("unit") != null ? row.getString("unit") : "unknown";
this.sensorStatus = row.getInteger("sensorStatus") != null ? row.getInteger("sensorStatus") : 0;
this.sensorTimestamp = row.getLocalDateTime("sensorTimestamp") != null ?
DateParser.parseDate(row.getLocalDateTime("sensorTimestamp")) : 0;
this.temperature = row.getFloat("temperature") != null ? row.getFloat("temperature") : 0.0f;
this.humidity = row.getFloat("humidity") != null ? row.getFloat("humidity") : 0.0f;
this.carbonMonoxide = row.getFloat("carbonMonoxide") != null ? row.getFloat("carbonMonoxide") : 0.0f;
this.lat = row.getFloat("lat") != null ? row.getFloat("lat") : 0.0f;
this.lon = row.getFloat("lon") != null ? row.getFloat("lon") : 0.0f;
this.airValuesTimestamp = row.getLocalDateTime("airValuesTimestamp") != null ?
DateParser.parseDate(row.getLocalDateTime("airValuesTimestamp")) : 0;
this.deviceId = row.getInteger("deviceId");
this.sensorId = row.getInteger("sensorId");
this.sensorType = row.getString("sensorType");
this.unit = row.getString("unit");
this.sensorStatus = row.getInteger("sensorStatus");
this.sensorTimestamp = DateParser.parseDate(row.getLocalDateTime("sensorTimestamp"));
this.temperature = row.getFloat("temperature");
this.humidity = row.getFloat("humidity");
this.carbonMonoxide = row.getFloat("carbonMonoxide");
this.lat = row.getFloat("lat");
this.lon = row.getFloat("lon");
this.airValuesTimestamp = DateParser.parseDate(row.getLocalDateTime("airValuesTimestamp"));
}
public DeviceLatestValuesView(int deviceId, int sensorId, String sensorType, String unit, int sensorStatus,
long sensorTimestamp, float temperature, float humidity, float carbonMonoxide, float lat, float lon,
long airValuesTimestamp) {
public DeviceLatestValuesView(Integer deviceId, Integer sensorId, String sensorType, String unit, Integer sensorStatus,
Long sensorTimestamp, Float temperature, Float humidity, Float carbonMonoxide, Float lat, Float lon,
Long airValuesTimestamp) {
super();
this.deviceId = deviceId;
this.sensorId = sensorId;
@@ -60,11 +55,11 @@ public class DeviceLatestValuesView {
this.airValuesTimestamp = airValuesTimestamp;
}
public int getDeviceId() {
public Integer getDeviceId() {
return deviceId;
}
public int getSensorId() {
public Integer getSensorId() {
return sensorId;
}
@@ -76,35 +71,35 @@ public class DeviceLatestValuesView {
return unit;
}
public int getSensorStatus() {
public Integer getSensorStatus() {
return sensorStatus;
}
public long getSensorTimestamp() {
public Long getSensorTimestamp() {
return sensorTimestamp;
}
public float getTemperature() {
public Float getTemperature() {
return temperature;
}
public float getHumidity() {
public Float getHumidity() {
return humidity;
}
public float getCarbonMonoxide() {
public Float getCarbonMonoxide() {
return carbonMonoxide;
}
public float getLat() {
public Float getLat() {
return lat;
}
public float getLon() {
public Float getLon() {
return lon;
}
public long getAirValuesTimestamp() {
public Long getAirValuesTimestamp() {
return airValuesTimestamp;
}
@@ -123,14 +118,13 @@ public class DeviceLatestValuesView {
if (getClass() != obj.getClass())
return false;
DeviceLatestValuesView other = (DeviceLatestValuesView) obj;
return airValuesTimestamp == other.airValuesTimestamp
&& Float.floatToIntBits(carbonMonoxide) == Float.floatToIntBits(other.carbonMonoxide)
&& deviceId == other.deviceId && Float.floatToIntBits(humidity) == Float.floatToIntBits(other.humidity)
&& Float.floatToIntBits(lat) == Float.floatToIntBits(other.lat)
&& Float.floatToIntBits(lon) == Float.floatToIntBits(other.lon) && sensorId == other.sensorId
&& sensorStatus == other.sensorStatus && sensorTimestamp == other.sensorTimestamp
&& Objects.equals(sensorType, other.sensorType)
&& Float.floatToIntBits(temperature) == Float.floatToIntBits(other.temperature)
return Objects.equals(airValuesTimestamp, other.airValuesTimestamp)
&& 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(sensorId, other.sensorId)
&& Objects.equals(sensorStatus, other.sensorStatus)
&& Objects.equals(sensorTimestamp, other.sensorTimestamp)
&& Objects.equals(sensorType, other.sensorType) && Objects.equals(temperature, other.temperature)
&& Objects.equals(unit, other.unit);
}
@@ -143,4 +137,6 @@ public class DeviceLatestValuesView {
}
}

View File

@@ -8,12 +8,12 @@ import net.miarma.contaminus.util.DateParser;
@Table("v_pollution_map")
public class DevicePollutionMap {
int deviceId;
String deviceName;
float lat;
float lon;
float carbonMonoxide;
long timestamp;
private Integer deviceId;
private String deviceName;
private Float lat;
private Float lon;
private Float carbonMonoxide;
private Long timestamp;
public DevicePollutionMap() {}
@@ -26,8 +26,8 @@ public class DevicePollutionMap {
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
}
public DevicePollutionMap(int deviceId, String deviceName, float lat, float lon, float carbonMonoxide,
long timestamp) {
public DevicePollutionMap(Integer deviceId, String deviceName, Float lat, Float lon, Float carbonMonoxide,
Long timestamp) {
super();
this.deviceId = deviceId;
this.deviceName = deviceName;
@@ -37,7 +37,7 @@ public class DevicePollutionMap {
this.timestamp = timestamp;
}
public int getDeviceId() {
public Integer getDeviceId() {
return deviceId;
}
@@ -45,19 +45,19 @@ public class DevicePollutionMap {
return deviceName;
}
public float getLat() {
public Float getLat() {
return lat;
}
public float getLon() {
public Float getLon() {
return lon;
}
public float getCarbonMonoxide() {
public Float getCarbonMonoxide() {
return carbonMonoxide;
}
public long getTimestamp() {
public Long getTimestamp() {
return timestamp;
}
@@ -75,10 +75,9 @@ public class DevicePollutionMap {
if (getClass() != obj.getClass())
return false;
DevicePollutionMap other = (DevicePollutionMap) obj;
return Float.floatToIntBits(carbonMonoxide) == Float.floatToIntBits(other.carbonMonoxide)
&& deviceId == other.deviceId && Objects.equals(deviceName, other.deviceName)
&& Float.floatToIntBits(lat) == Float.floatToIntBits(other.lat)
&& Float.floatToIntBits(lon) == Float.floatToIntBits(other.lon) && timestamp == other.timestamp;
return Objects.equals(carbonMonoxide, other.carbonMonoxide) && Objects.equals(deviceId, other.deviceId)
&& Objects.equals(deviceName, other.deviceName) && Objects.equals(lat, other.lat)
&& Objects.equals(lon, other.lon) && Objects.equals(timestamp, other.timestamp);
}
@Override
@@ -86,4 +85,6 @@ public class DevicePollutionMap {
return "DevicePollutionMap [deviceId=" + deviceId + ", deviceName=" + deviceName + ", lat=" + lat + ", lon="
+ lon + ", carbonMonoxide=" + carbonMonoxide + ", timestamp=" + timestamp + "]";
}
}

View File

@@ -8,11 +8,11 @@ import net.miarma.contaminus.util.DateParser;
@Table("v_sensor_history_by_device")
public class DeviceSensorHistory {
int deviceId;
String deviceName;
float value;
String valueType;
long timestamp;
private Integer deviceId;
private String deviceName;
private Float value;
private String valueType;
private Long timestamp;
public DeviceSensorHistory() {}
@@ -24,7 +24,7 @@ public class DeviceSensorHistory {
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
}
public DeviceSensorHistory(int deviceId, String deviceName, float value, String valueType, long timestamp) {
public DeviceSensorHistory(Integer 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 int getDeviceId() {
public Integer getDeviceId() {
return deviceId;
}
@@ -41,7 +41,7 @@ public class DeviceSensorHistory {
return deviceName;
}
public float getValue() {
public Float getValue() {
return value;
}
@@ -49,7 +49,7 @@ public class DeviceSensorHistory {
return valueType;
}
public long getTimestamp() {
public Long getTimestamp() {
return timestamp;
}
@@ -67,8 +67,8 @@ public class DeviceSensorHistory {
if (getClass() != obj.getClass())
return false;
DeviceSensorHistory other = (DeviceSensorHistory) obj;
return deviceId == other.deviceId && Objects.equals(deviceName, other.deviceName)
&& timestamp == other.timestamp && Float.floatToIntBits(value) == Float.floatToIntBits(other.value)
return Objects.equals(deviceId, other.deviceId) && Objects.equals(deviceName, other.deviceName)
&& Objects.equals(timestamp, other.timestamp) && Objects.equals(value, other.value)
&& Objects.equals(valueType, other.valueType);
}
@@ -77,4 +77,6 @@ public class DeviceSensorHistory {
return "DeviceSensorHistory [deviceId=" + deviceId + ", deviceName=" + deviceName + ", value=" + value
+ ", valueType=" + valueType + ", timestamp=" + timestamp + "]";
}
}

View File

@@ -8,17 +8,17 @@ import net.miarma.contaminus.util.DateParser;
@Table("v_sensor_values")
public class DeviceSensorValue {
int sensorId;
int deviceId;
String sensorType;
String unit;
int sensorStatus;
float temperature;
float humidity;
float carbonMonoxide;
float lat;
float lon;
long timestamp;
private Integer sensorId;
private Integer deviceId;
private String sensorType;
private String unit;
private Integer sensorStatus;
private Float temperature;
private Float humidity;
private Float carbonMonoxide;
private Float lat;
private Float lon;
private Long timestamp;
public DeviceSensorValue() {}
@@ -36,8 +36,8 @@ public class DeviceSensorValue {
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
}
public DeviceSensorValue(int sensorId, int deviceId, String sensorType, String unit, int sensorStatus,
float temperature, float humidity, float carbonMonoxide, float lat, float lon, long timestamp) {
public DeviceSensorValue(Integer sensorId, Integer deviceId, String sensorType, String unit, Integer sensorStatus,
Float temperature, Float humidity, Float carbonMonoxide, Float lat, Float lon, Long timestamp) {
super();
this.sensorId = sensorId;
this.deviceId = deviceId;
@@ -52,11 +52,11 @@ public class DeviceSensorValue {
this.timestamp = timestamp;
}
public int getSensorId() {
public Integer getSensorId() {
return sensorId;
}
public int getDeviceId() {
public Integer getDeviceId() {
return deviceId;
}
@@ -68,31 +68,31 @@ public class DeviceSensorValue {
return unit;
}
public int getSensorStatus() {
public Integer getSensorStatus() {
return sensorStatus;
}
public float getTemperature() {
public Float getTemperature() {
return temperature;
}
public float getHumidity() {
public Float getHumidity() {
return humidity;
}
public float getCarbonMonoxide() {
public Float getCarbonMonoxide() {
return carbonMonoxide;
}
public float getLat() {
public Float getLat() {
return lat;
}
public float getLon() {
public Float getLon() {
return lon;
}
public long getTimestamp() {
public Long getTimestamp() {
return timestamp;
}
@@ -111,13 +111,12 @@ public class DeviceSensorValue {
if (getClass() != obj.getClass())
return false;
DeviceSensorValue other = (DeviceSensorValue) obj;
return Float.floatToIntBits(carbonMonoxide) == Float.floatToIntBits(other.carbonMonoxide)
&& deviceId == other.deviceId && Float.floatToIntBits(humidity) == Float.floatToIntBits(other.humidity)
&& Float.floatToIntBits(lat) == Float.floatToIntBits(other.lat)
&& Float.floatToIntBits(lon) == Float.floatToIntBits(other.lon) && sensorId == other.sensorId
&& sensorStatus == other.sensorStatus && Objects.equals(sensorType, other.sensorType)
&& Float.floatToIntBits(temperature) == Float.floatToIntBits(other.temperature)
&& timestamp == other.timestamp && Objects.equals(unit, other.unit);
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(sensorId, other.sensorId)
&& Objects.equals(sensorStatus, other.sensorStatus) && Objects.equals(sensorType, other.sensorType)
&& Objects.equals(temperature, other.temperature) && Objects.equals(timestamp, other.timestamp)
&& Objects.equals(unit, other.unit);
}
@Override
@@ -127,4 +126,6 @@ public class DeviceSensorValue {
+ humidity + ", carbonMonoxide=" + carbonMonoxide + ", lat=" + lat + ", lon=" + lon + ", timestamp="
+ timestamp + "]";
}
}

View File

@@ -8,10 +8,10 @@ import net.miarma.contaminus.util.DateParser;
@Table("v_weather_by_device")
public class DeviceWeather {
int deviceId;
float temperature;
float humidity;
long timestamp;
private Integer deviceId;
private Float temperature;
private Float humidity;
private Long timestamp;
public DeviceWeather() {}
@@ -22,7 +22,7 @@ public class DeviceWeather {
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
}
public DeviceWeather(int deviceId, float temperature, float humidity, long timestamp) {
public DeviceWeather(Integer deviceId, Float temperature, Float humidity, Long timestamp) {
super();
this.deviceId = deviceId;
this.temperature = temperature;
@@ -30,19 +30,19 @@ public class DeviceWeather {
this.timestamp = timestamp;
}
public int getDeviceId() {
public Integer getDeviceId() {
return deviceId;
}
public float getTemperature() {
public Float getTemperature() {
return temperature;
}
public float getHumidity() {
public Float getHumidity() {
return humidity;
}
public long getTimestamp() {
public Long getTimestamp() {
return timestamp;
}
@@ -60,9 +60,8 @@ public class DeviceWeather {
if (getClass() != obj.getClass())
return false;
DeviceWeather other = (DeviceWeather) obj;
return deviceId == other.deviceId && Float.floatToIntBits(humidity) == Float.floatToIntBits(other.humidity)
&& Float.floatToIntBits(temperature) == Float.floatToIntBits(other.temperature)
&& timestamp == other.timestamp;
return Objects.equals(deviceId, other.deviceId) && Objects.equals(humidity, other.humidity)
&& Objects.equals(temperature, other.temperature) && Objects.equals(timestamp, other.timestamp);
}
@Override
@@ -70,4 +69,6 @@ public class DeviceWeather {
return "DeviceWeather [deviceId=" + deviceId + ", temperature=" + temperature + ", humidity=" + humidity
+ ", timestamp=" + timestamp + "]";
}
}

View File

@@ -9,11 +9,11 @@ import net.miarma.contaminus.util.DateParser;
@Table("gps_values")
public class GpsValue {
private int valueId;
private int sensorId;
private float lat;
private float lon;
private long timestamp;
private Integer valueId;
private Integer sensorId;
private Float lat;
private Float lon;
private Long timestamp;
public GpsValue() {}
@@ -25,7 +25,7 @@ public class GpsValue {
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
}
public GpsValue(int valueId, int sensorId, float lat, float lon, long timestamp) {
public GpsValue(Integer valueId, Integer sensorId, Float lat, Float lon, Long timestamp) {
super();
this.valueId = valueId;
this.sensorId = sensorId;
@@ -34,43 +34,43 @@ public class GpsValue {
this.timestamp = timestamp;
}
public int getValueId() {
public Integer getValueId() {
return valueId;
}
public void setValueId(int valueId) {
public void setValueId(Integer valueId) {
this.valueId = valueId;
}
public int getSensorId() {
public Integer getSensorId() {
return sensorId;
}
public void setSensorId(int sensorId) {
public void setSensorId(Integer sensorId) {
this.sensorId = sensorId;
}
public float getLat() {
public Float getLat() {
return lat;
}
public void setLat(float lat) {
public void setLat(Float lat) {
this.lat = lat;
}
public float getLon() {
public Float getLon() {
return lon;
}
public void setLon(float lon) {
public void setLon(Float lon) {
this.lon = lon;
}
public long getTimestamp() {
public Long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
public void setTimestamp(Long timestamp) {
this.timestamp = timestamp;
}
@@ -88,9 +88,9 @@ public class GpsValue {
if (getClass() != obj.getClass())
return false;
GpsValue other = (GpsValue) obj;
return Float.floatToIntBits(lat) == Float.floatToIntBits(other.lat)
&& Float.floatToIntBits(lon) == Float.floatToIntBits(other.lon)
&& sensorId == other.sensorId && timestamp == other.timestamp && valueId == other.valueId;
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);
}
@Override

View File

@@ -8,7 +8,7 @@ import net.miarma.contaminus.common.Table;
@Table("groups")
public class Group {
private int groupId;
private Integer groupId;
private String groupName;
public Group() {}
@@ -18,17 +18,17 @@ public class Group {
this.groupName = row.getString("groupName");
}
public Group(int groupId, String groupName) {
public Group(Integer groupId, String groupName) {
super();
this.groupId = groupId;
this.groupName = groupName;
}
public int getGroupId() {
public Integer getGroupId() {
return groupId;
}
public void setGroupId(int groupId) {
public void setGroupId(Integer groupId) {
this.groupId = groupId;
}
@@ -54,8 +54,7 @@ public class Group {
if (getClass() != obj.getClass())
return false;
Group other = (Group) obj;
return groupId == other.groupId
&& Objects.equals(groupName, other.groupName);
return Objects.equals(groupId, other.groupId) && Objects.equals(groupName, other.groupName);
}
@Override

View File

@@ -9,12 +9,12 @@ import net.miarma.contaminus.util.DateParser;
@Table("sensors")
public class Sensor {
private int sensorId;
private int deviceId;
private Integer sensorId;
private Integer deviceId;
private String sensorType;
private String unit;
private int status;
private long timestamp;
private Integer status;
private Long timestamp;
public Sensor() {}
@@ -27,7 +27,7 @@ public class Sensor {
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
}
public Sensor(int sensorId, int deviceId, String sensorType, String unit, int status, long timestamp) {
public Sensor(Integer sensorId, Integer deviceId, String sensorType, String unit, Integer status, Long timestamp) {
super();
this.sensorId = sensorId;
this.deviceId = deviceId;
@@ -37,19 +37,19 @@ public class Sensor {
this.timestamp = timestamp;
}
public int getSensorId() {
public Integer getSensorId() {
return sensorId;
}
public void setSensorId(int sensorId) {
public void setSensorId(Integer sensorId) {
this.sensorId = sensorId;
}
public int getDeviceId() {
public Integer getDeviceId() {
return deviceId;
}
public void setDeviceId(int deviceId) {
public void setDeviceId(Integer deviceId) {
this.deviceId = deviceId;
}
@@ -69,19 +69,19 @@ public class Sensor {
this.unit = unit;
}
public int getStatus() {
public Integer getStatus() {
return status;
}
public void setStatus(int status) {
public void setStatus(Integer status) {
this.status = status;
}
public long getTimestamp() {
public Long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
public void setTimestamp(Long timestamp) {
this.timestamp = timestamp;
}
@@ -99,8 +99,9 @@ public class Sensor {
if (getClass() != obj.getClass())
return false;
Sensor other = (Sensor) obj;
return deviceId == other.deviceId && sensorId == other.sensorId && Objects.equals(sensorType, other.sensorType)
&& status == other.status && timestamp == other.timestamp && Objects.equals(unit, other.unit);
return Objects.equals(deviceId, other.deviceId) && Objects.equals(sensorId, other.sensorId)
&& Objects.equals(sensorType, other.sensorType) && Objects.equals(status, other.status)
&& Objects.equals(timestamp, other.timestamp) && Objects.equals(unit, other.unit);
}
@Override

View File

@@ -9,11 +9,11 @@ import net.miarma.contaminus.util.DateParser;
@Table("weather_values")
public class WeatherValue {
private int valueId;
private int sensorId;
private float temperature;
private float humidity;
private long timestamp;
private Integer valueId;
private Integer sensorId;
private Float temperature;
private Float humidity;
private Long timestamp;
public WeatherValue() {}
@@ -25,7 +25,7 @@ public class WeatherValue {
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
}
public WeatherValue(int valueId, int sensorId, float temperature, float humidity, long timestamp) {
public WeatherValue(Integer valueId, Integer sensorId, Float temperature, Float humidity, Long timestamp) {
super();
this.valueId = valueId;
this.sensorId = sensorId;
@@ -34,43 +34,43 @@ public class WeatherValue {
this.timestamp = timestamp;
}
public int getValueId() {
public Integer getValueId() {
return valueId;
}
public void setValueId(int valueId) {
public void setValueId(Integer valueId) {
this.valueId = valueId;
}
public int getSensorId() {
public Integer getSensorId() {
return sensorId;
}
public void setSensorId(int sensorId) {
public void setSensorId(Integer sensorId) {
this.sensorId = sensorId;
}
public float getTemperature() {
public Float getTemperature() {
return temperature;
}
public void setTemperature(float temperature) {
public void setTemperature(Float temperature) {
this.temperature = temperature;
}
public float getHumidity() {
public Float getHumidity() {
return humidity;
}
public void setHumidity(float humidity) {
public void setHumidity(Float humidity) {
this.humidity = humidity;
}
public long getTimestamp() {
public Long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
public void setTimestamp(Long timestamp) {
this.timestamp = timestamp;
}
@@ -88,9 +88,9 @@ public class WeatherValue {
if (getClass() != obj.getClass())
return false;
WeatherValue other = (WeatherValue) obj;
return Float.floatToIntBits(humidity) == Float.floatToIntBits(other.humidity) && sensorId == other.sensorId
&& Float.floatToIntBits(temperature) == Float.floatToIntBits(other.temperature)
&& timestamp == other.timestamp && valueId == other.valueId;
return Objects.equals(humidity, other.humidity) && Objects.equals(sensorId, other.sensorId)
&& Objects.equals(temperature, other.temperature) && Objects.equals(timestamp, other.timestamp)
&& Objects.equals(valueId, other.valueId);
}
@Override

View File

@@ -5,6 +5,7 @@ import java.util.HashSet;
import java.util.Set;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Promise;
@@ -27,7 +28,7 @@ public class DataLayerAPIVerticle extends AbstractVerticle {
private JDBCPool pool;
private DatabaseManager dbManager;
private ConfigManager configManager;
private Gson gson = new Gson();
private final Gson gson = new GsonBuilder().serializeNulls().create();
public DataLayerAPIVerticle(JDBCPool pool) {
this.pool = pool;

View File

@@ -4,8 +4,10 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Stream;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Promise;
@@ -19,18 +21,18 @@ import io.vertx.ext.web.handler.BodyHandler;
import io.vertx.ext.web.handler.CorsHandler;
import net.miarma.contaminus.common.ConfigManager;
import net.miarma.contaminus.common.Constants;
import net.miarma.contaminus.database.entities.Actuator;
import net.miarma.contaminus.database.entities.Device;
import net.miarma.contaminus.database.entities.DeviceLatestValuesView;
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.Actuator;
import net.miarma.contaminus.database.entities.Sensor;
import net.miarma.contaminus.util.RestClientUtil;
public class LogicLayerAPIVerticle extends AbstractVerticle {
private ConfigManager configManager;
private final Gson gson = new Gson();
private final Gson gson = new GsonBuilder().serializeNulls().create();
private RestClientUtil restClient;
public LogicLayerAPIVerticle() {
@@ -81,7 +83,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
Promise<Device[]> resultList = Promise.promise();
resultList.future().onComplete(complete -> {
if(complete.succeeded()) {
List<Device> aux = Arrays.asList(complete.result()).stream()
List<Device> aux = Stream.of(complete.result())
.filter(d -> d.getGroupId() == groupId)
.toList();
context.response()
@@ -93,7 +95,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
});
this.restClient.getRequest(configManager.getDataApiPort(), "http://" + configManager.getHost(),
Constants.GET_GROUP_DEVICES, Device[].class, resultList);
Constants.GET_DEVICES, Device[].class, resultList);
}
private void getDeviceSensors(RoutingContext context) {
@@ -131,17 +133,16 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
});
restClient.getRequest(configManager.getDataApiPort(), "http://" + configManager.getHost(),
Constants.GET_DEVICES, Actuator[].class, resultList);
Constants.GET_ACTUATORS, Actuator[].class, resultList);
}
private void getDeviceLatestValues(RoutingContext context) {
Integer deviceId = Integer.parseInt(context.request().getParam("deviceId"));
Promise<DeviceLatestValuesView[]> resultList = Promise.promise();
resultList.future().onComplete(complete -> {
if (complete.succeeded()) {
List<DeviceLatestValuesView> aux = Arrays.asList(complete.result()).stream()
List<DeviceLatestValuesView> aux = Stream.of(complete.result())
.filter(d -> d.getDeviceId() == deviceId)
.toList();
@@ -154,7 +155,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
});
this.restClient.getRequest(configManager.getDataApiPort(), "http://" + configManager.getHost(),
Constants.GET_DEVICE_LATEST_VALUES, DeviceLatestValuesView[].class, resultList);
Constants.GET_LATEST_VALUES_VIEW, DeviceLatestValuesView[].class, resultList);
}
private void getDevicePollutionMap(RoutingContext context) {
@@ -177,7 +178,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
});
this.restClient.getRequest(configManager.getDataApiPort(), "http://" + configManager.getHost(),
Constants.GET_DEVICE_POLLUTION_MAP, DevicePollutionMap[].class, resultList);
Constants.GET_POLLUTION_MAP_VIEW, DevicePollutionMap[].class, resultList);
}
private void getDeviceHistory(RoutingContext context) {
@@ -200,7 +201,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
});
this.restClient.getRequest(configManager.getDataApiPort(), "http://" + configManager.getHost(),
Constants.GET_DEVICE_HISTORY, DeviceSensorHistory[].class, resultList);
Constants.GET_SENSOR_HISTORY_BY_DEVICE_VIEW, DeviceSensorHistory[].class, resultList);
}
private void getSensorValues(RoutingContext context) {
@@ -223,6 +224,6 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
});
this.restClient.getRequest(configManager.getDataApiPort(), "http://" + configManager.getHost(),
Constants.GET_SENSOR_VALUES, DeviceSensorValue[].class, resultList);
Constants.GET_SENSOR_VALUES_VIEW, DeviceSensorValue[].class, resultList);
}
}

View File

@@ -33,6 +33,8 @@ public class RestClientUtil {
public <T> void getRequest(Integer port, String host, String resource, Class<T> classType, Promise<T> promise) {
client.getAbs(host + ":" + port + resource).send(elem -> {
if (elem.succeeded()) {
System.out.println(host + ":" + port + resource);
System.out.println(elem.result().bodyAsString());
promise.complete(gson.fromJson(elem.result().bodyAsString(), classType));
} else {
promise.fail(elem.cause());