Merge pull request #8 from Gallardo7761/feature/logicApi
Feature/logic api
This commit is contained in:
1
backend/.gitignore
vendored
1
backend/.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
/dependency-reduced-pom.xml
|
/dependency-reduced-pom.xml
|
||||||
|
/target/
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public class Constants {
|
|||||||
public static final String PUT_ACTUATOR_BY_ID = API_PREFIX + "/actuators/:actuatorId";
|
public static final String PUT_ACTUATOR_BY_ID = API_PREFIX + "/actuators/:actuatorId";
|
||||||
|
|
||||||
public static final String GET_CO_BY_DEVICE_VIEW = API_PREFIX + "/v_co_by_device";
|
public static final String GET_CO_BY_DEVICE_VIEW = API_PREFIX + "/v_co_by_device";
|
||||||
|
|
||||||
public static final String GET_GPS_BY_DEVICE_VIEW = API_PREFIX + "/v_gps_by_device";
|
public static final String GET_GPS_BY_DEVICE_VIEW = API_PREFIX + "/v_gps_by_device";
|
||||||
public static final String GET_LATEST_VALUES_VIEW = API_PREFIX + "/v_latest_values";
|
public static final String GET_LATEST_VALUES_VIEW = API_PREFIX + "/v_latest_values";
|
||||||
public static final String GET_POLLUTION_MAP_VIEW = API_PREFIX + "/v_pollution_map";
|
public static final String GET_POLLUTION_MAP_VIEW = API_PREFIX + "/v_pollution_map";
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package net.miarma.contaminus.database.entities;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import io.vertx.sqlclient.Row;
|
||||||
|
import net.miarma.contaminus.common.Table;
|
||||||
|
|
||||||
|
@Table("v_co_by_device")
|
||||||
|
public class DeviceCO {
|
||||||
|
int deviceId;
|
||||||
|
float carbonMonoxide;
|
||||||
|
long timestamp;
|
||||||
|
|
||||||
|
public DeviceCO() {}
|
||||||
|
|
||||||
|
public DeviceCO(Row row) {
|
||||||
|
this.deviceId = row.getInteger("deviceId");
|
||||||
|
this.carbonMonoxide = row.getFloat("carbonMonoxide");
|
||||||
|
this.timestamp = row.getLong("timestamp");
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceCO(int deviceId, float carbonMonoxide, long timestamp) {
|
||||||
|
super();
|
||||||
|
this.deviceId = deviceId;
|
||||||
|
this.carbonMonoxide = carbonMonoxide;
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDeviceId() {
|
||||||
|
return deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getCarbonMonoxide() {
|
||||||
|
return carbonMonoxide;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTimestamp() {
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(carbonMonoxide, deviceId, timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
DeviceCO other = (DeviceCO) obj;
|
||||||
|
return Float.floatToIntBits(carbonMonoxide) == Float.floatToIntBits(other.carbonMonoxide)
|
||||||
|
&& deviceId == other.deviceId && timestamp == other.timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "DeviceCO [deviceId=" + deviceId + ", carbonMonoxide=" + carbonMonoxide + ", timestamp=" + timestamp
|
||||||
|
+ "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package net.miarma.contaminus.database.entities;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import io.vertx.sqlclient.Row;
|
||||||
|
import net.miarma.contaminus.common.Table;
|
||||||
|
|
||||||
|
@Table("v_gps_by_device")
|
||||||
|
public class DeviceGPS {
|
||||||
|
int deviceId;
|
||||||
|
float lat;
|
||||||
|
float lon;
|
||||||
|
long timestamp;
|
||||||
|
|
||||||
|
public DeviceGPS() {}
|
||||||
|
|
||||||
|
public DeviceGPS(Row row) {
|
||||||
|
this.deviceId = row.getInteger("deviceId");
|
||||||
|
this.lat = row.getFloat("lat");
|
||||||
|
this.lon = row.getFloat("lon");
|
||||||
|
this.timestamp = row.getLong("timestamp");
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceGPS(int deviceId, long lat, long lon) {
|
||||||
|
super();
|
||||||
|
this.deviceId = deviceId;
|
||||||
|
this.lat = lat;
|
||||||
|
this.lon = lon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDeviceId() {
|
||||||
|
return deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getLat() {
|
||||||
|
return lat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getLon() {
|
||||||
|
return lon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTimestamp() {
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(deviceId, lat, lon, timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "DeviceGPS [deviceId=" + deviceId + ", lat=" + lat + ", lon=" + lon + ", timestamp=" + timestamp + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
package net.miarma.contaminus.database.entities;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import io.vertx.sqlclient.Row;
|
||||||
|
import net.miarma.contaminus.common.Table;
|
||||||
|
|
||||||
|
@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;
|
||||||
|
|
||||||
|
public DeviceLatestValuesView() {}
|
||||||
|
|
||||||
|
public DeviceLatestValuesView(Row row) {
|
||||||
|
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 = row.getLong("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 = row.getLong("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) {
|
||||||
|
super();
|
||||||
|
this.deviceId = deviceId;
|
||||||
|
this.sensorId = sensorId;
|
||||||
|
this.sensorType = sensorType;
|
||||||
|
this.unit = unit;
|
||||||
|
this.sensorStatus = sensorStatus;
|
||||||
|
this.sensorTimestamp = sensorTimestamp;
|
||||||
|
this.temperature = temperature;
|
||||||
|
this.humidity = humidity;
|
||||||
|
this.carbonMonoxide = carbonMonoxide;
|
||||||
|
this.lat = lat;
|
||||||
|
this.lon = lon;
|
||||||
|
this.airValuesTimestamp = airValuesTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDeviceId() {
|
||||||
|
return deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSensorId() {
|
||||||
|
return sensorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSensorType() {
|
||||||
|
return sensorType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUnit() {
|
||||||
|
return unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSensorStatus() {
|
||||||
|
return sensorStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getSensorTimestamp() {
|
||||||
|
return sensorTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getTemperature() {
|
||||||
|
return temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getHumidity() {
|
||||||
|
return humidity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getCarbonMonoxide() {
|
||||||
|
return carbonMonoxide;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getLat() {
|
||||||
|
return lat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getLon() {
|
||||||
|
return lon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getAirValuesTimestamp() {
|
||||||
|
return airValuesTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(airValuesTimestamp, carbonMonoxide, deviceId, humidity, lat, lon, sensorId, sensorStatus,
|
||||||
|
sensorTimestamp, sensorType, temperature, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
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)
|
||||||
|
&& Objects.equals(unit, other.unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "DeviceLatestValuesView [deviceId=" + deviceId + ", sensorId=" + sensorId + ", sensorType=" + sensorType
|
||||||
|
+ ", unit=" + unit + ", sensorStatus=" + sensorStatus + ", sensorTimestamp=" + sensorTimestamp
|
||||||
|
+ ", temperature=" + temperature + ", humidity=" + humidity + ", carbonMonoxide=" + carbonMonoxide
|
||||||
|
+ ", lat=" + lat + ", lon=" + lon + ", airValuesTimestamp=" + airValuesTimestamp + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package net.miarma.contaminus.database.entities;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import io.vertx.sqlclient.Row;
|
||||||
|
import net.miarma.contaminus.common.Table;
|
||||||
|
|
||||||
|
@Table("v_pollution_map")
|
||||||
|
public class DevicePollutionMap {
|
||||||
|
int deviceId;
|
||||||
|
String deviceName;
|
||||||
|
float lat;
|
||||||
|
float lon;
|
||||||
|
float carbonMonoxide;
|
||||||
|
long timestamp;
|
||||||
|
|
||||||
|
public DevicePollutionMap() {}
|
||||||
|
|
||||||
|
public DevicePollutionMap(Row row) {
|
||||||
|
this.deviceId = row.getInteger("deviceId");
|
||||||
|
this.deviceName = row.getString("deviceName");
|
||||||
|
this.lat = row.getFloat("lat");
|
||||||
|
this.lon = row.getFloat("lon");
|
||||||
|
this.carbonMonoxide = row.getFloat("carbonMonoxide");
|
||||||
|
this.timestamp = row.getLong("timestamp");
|
||||||
|
}
|
||||||
|
|
||||||
|
public DevicePollutionMap(int deviceId, String deviceName, float lat, float lon, float carbonMonoxide,
|
||||||
|
long timestamp) {
|
||||||
|
super();
|
||||||
|
this.deviceId = deviceId;
|
||||||
|
this.deviceName = deviceName;
|
||||||
|
this.lat = lat;
|
||||||
|
this.lon = lon;
|
||||||
|
this.carbonMonoxide = carbonMonoxide;
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDeviceId() {
|
||||||
|
return deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeviceName() {
|
||||||
|
return deviceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getLat() {
|
||||||
|
return lat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getLon() {
|
||||||
|
return lon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getCarbonMonoxide() {
|
||||||
|
return carbonMonoxide;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTimestamp() {
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(carbonMonoxide, deviceId, deviceName, lat, lon, timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "DevicePollutionMap [deviceId=" + deviceId + ", deviceName=" + deviceName + ", lat=" + lat + ", lon="
|
||||||
|
+ lon + ", carbonMonoxide=" + carbonMonoxide + ", timestamp=" + timestamp + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package net.miarma.contaminus.database.entities;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import io.vertx.sqlclient.Row;
|
||||||
|
import net.miarma.contaminus.common.Table;
|
||||||
|
|
||||||
|
@Table("v_sensor_history_by_device")
|
||||||
|
public class DeviceSensorHistory {
|
||||||
|
int deviceId;
|
||||||
|
String deviceName;
|
||||||
|
float value;
|
||||||
|
String valueType;
|
||||||
|
long timestamp;
|
||||||
|
|
||||||
|
public DeviceSensorHistory() {}
|
||||||
|
|
||||||
|
public DeviceSensorHistory(Row row) {
|
||||||
|
this.deviceId = row.getInteger("deviceId");
|
||||||
|
this.deviceName = row.getString("deviceName");
|
||||||
|
this.value = row.getFloat("value");
|
||||||
|
this.valueType = row.getString("valueType");
|
||||||
|
this.timestamp = row.getLong("timestamp");
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceSensorHistory(int deviceId, String deviceName, float value, String valueType, long timestamp) {
|
||||||
|
super();
|
||||||
|
this.deviceId = deviceId;
|
||||||
|
this.deviceName = deviceName;
|
||||||
|
this.value = value;
|
||||||
|
this.valueType = valueType;
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDeviceId() {
|
||||||
|
return deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeviceName() {
|
||||||
|
return deviceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValueType() {
|
||||||
|
return valueType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTimestamp() {
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(deviceId, deviceName, timestamp, value, valueType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
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)
|
||||||
|
&& Objects.equals(valueType, other.valueType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "DeviceSensorHistory [deviceId=" + deviceId + ", deviceName=" + deviceName + ", value=" + value
|
||||||
|
+ ", valueType=" + valueType + ", timestamp=" + timestamp + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
package net.miarma.contaminus.database.entities;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import io.vertx.sqlclient.Row;
|
||||||
|
import net.miarma.contaminus.common.Table;
|
||||||
|
|
||||||
|
@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;
|
||||||
|
|
||||||
|
public DeviceSensorValue() {}
|
||||||
|
|
||||||
|
public DeviceSensorValue(Row row) {
|
||||||
|
this.sensorId = row.getInteger("sensorId");
|
||||||
|
this.deviceId = row.getInteger("deviceId");
|
||||||
|
this.sensorType = row.getString("sensorType");
|
||||||
|
this.unit = row.getString("unit");
|
||||||
|
this.sensorStatus = row.getInteger("sensorStatus");
|
||||||
|
this.temperature = row.getFloat("temperature");
|
||||||
|
this.humidity = row.getFloat("humidty");
|
||||||
|
this.carbonMonoxide = row.getFloat("carbonMonoxide");
|
||||||
|
this.lat = row.getFloat("lat");
|
||||||
|
this.lon = row.getFloat("lon");
|
||||||
|
this.timestamp = row.getLong("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) {
|
||||||
|
super();
|
||||||
|
this.sensorId = sensorId;
|
||||||
|
this.deviceId = deviceId;
|
||||||
|
this.sensorType = sensorType;
|
||||||
|
this.unit = unit;
|
||||||
|
this.sensorStatus = sensorStatus;
|
||||||
|
this.temperature = temperature;
|
||||||
|
this.humidity = humidity;
|
||||||
|
this.carbonMonoxide = carbonMonoxide;
|
||||||
|
this.lat = lat;
|
||||||
|
this.lon = lon;
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSensorId() {
|
||||||
|
return sensorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDeviceId() {
|
||||||
|
return deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSensorType() {
|
||||||
|
return sensorType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUnit() {
|
||||||
|
return unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSensorStatus() {
|
||||||
|
return sensorStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getTemperature() {
|
||||||
|
return temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getHumidity() {
|
||||||
|
return humidity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getCarbonMonoxide() {
|
||||||
|
return carbonMonoxide;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getLat() {
|
||||||
|
return lat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getLon() {
|
||||||
|
return lon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTimestamp() {
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(carbonMonoxide, deviceId, humidity, lat, lon, sensorId, sensorStatus, sensorType,
|
||||||
|
temperature, timestamp, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "DeviceSensorValue [sensorId=" + sensorId + ", deviceId=" + deviceId + ", sensorType=" + sensorType
|
||||||
|
+ ", unit=" + unit + ", sensorStatus=" + sensorStatus + ", temperature=" + temperature + ", humidity="
|
||||||
|
+ humidity + ", carbonMonoxide=" + carbonMonoxide + ", lat=" + lat + ", lon=" + lon + ", timestamp="
|
||||||
|
+ timestamp + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package net.miarma.contaminus.database.entities;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import io.vertx.sqlclient.Row;
|
||||||
|
import net.miarma.contaminus.common.Table;
|
||||||
|
|
||||||
|
@Table("v_weather_by_device")
|
||||||
|
public class DeviceWeather {
|
||||||
|
int deviceId;
|
||||||
|
float temperature;
|
||||||
|
float humidity;
|
||||||
|
long timestamp;
|
||||||
|
|
||||||
|
public DeviceWeather() {}
|
||||||
|
|
||||||
|
public DeviceWeather(Row row) {
|
||||||
|
this.deviceId = row.getInteger("deviceId");
|
||||||
|
this.temperature = row.getFloat("temperature");
|
||||||
|
this.humidity = row.getFloat("humidity");
|
||||||
|
this.timestamp = row.getLong("timestamp");
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceWeather(int deviceId, float temperature, float humidity, long timestamp) {
|
||||||
|
super();
|
||||||
|
this.deviceId = deviceId;
|
||||||
|
this.temperature = temperature;
|
||||||
|
this.humidity = humidity;
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDeviceId() {
|
||||||
|
return deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getTemperature() {
|
||||||
|
return temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getHumidity() {
|
||||||
|
return humidity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTimestamp() {
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(deviceId, humidity, temperature, timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "DeviceWeather [deviceId=" + deviceId + ", temperature=" + temperature + ", humidity=" + humidity
|
||||||
|
+ ", timestamp=" + timestamp + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,11 @@ import io.vertx.ext.web.handler.BodyHandler;
|
|||||||
import io.vertx.ext.web.handler.CorsHandler;
|
import io.vertx.ext.web.handler.CorsHandler;
|
||||||
import net.miarma.contaminus.common.ConfigManager;
|
import net.miarma.contaminus.common.ConfigManager;
|
||||||
import net.miarma.contaminus.common.Constants;
|
import net.miarma.contaminus.common.Constants;
|
||||||
|
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.Actuator;
|
||||||
import net.miarma.contaminus.database.entities.Device;
|
import net.miarma.contaminus.database.entities.Device;
|
||||||
import net.miarma.contaminus.database.entities.Sensor;
|
import net.miarma.contaminus.database.entities.Sensor;
|
||||||
@@ -26,15 +31,14 @@ import net.miarma.contaminus.util.RestClientUtil;
|
|||||||
|
|
||||||
public class LogicLayerAPIVerticle extends AbstractVerticle {
|
public class LogicLayerAPIVerticle extends AbstractVerticle {
|
||||||
private ConfigManager configManager;
|
private ConfigManager configManager;
|
||||||
private RestClientUtil restClient;
|
|
||||||
private final Gson gson = new Gson();
|
private final Gson gson = new Gson();
|
||||||
|
private RestClientUtil restClient;
|
||||||
|
|
||||||
public LogicLayerAPIVerticle() {
|
public LogicLayerAPIVerticle() {
|
||||||
this.configManager = ConfigManager.getInstance();
|
this.configManager = ConfigManager.getInstance();
|
||||||
WebClientOptions options = new WebClientOptions()
|
WebClientOptions options = new WebClientOptions()
|
||||||
.setUserAgent("ContaminUS")
|
.setUserAgent("ContaminUS");
|
||||||
.setKeepAlive(false);
|
this.restClient = new RestClientUtil(WebClient.create(vertx, options));
|
||||||
this.restClient = new RestClientUtil(WebClient.create(Vertx.vertx(), options));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -72,25 +76,26 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
|
|||||||
startPromise.complete();
|
startPromise.complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void getGroupDevices(RoutingContext context) {
|
private void getGroupDevices(RoutingContext context) {
|
||||||
Integer groupId = Integer.parseInt(context.request().getParam("groupId"));
|
Integer groupId = Integer.parseInt(context.request().getParam("groupId"));
|
||||||
Promise<Device[]> resultList = Promise.promise();
|
|
||||||
resultList.future().onComplete(result -> {
|
Promise<Device[]> resultList = Promise.promise();
|
||||||
if (result.succeeded()) {
|
resultList.future().onComplete(complete -> {
|
||||||
Device[] devices = result.result();
|
if(complete.succeeded()) {
|
||||||
List<Device> aux = Arrays.stream(devices)
|
List<Device> aux = Arrays.asList(complete.result()).stream()
|
||||||
.filter(d -> d.getGroupId() == groupId)
|
.filter(d -> d.getGroupId() == groupId)
|
||||||
.toList();
|
.toList();
|
||||||
context.response().putHeader("Content-Type", "application/json").end(gson.toJson(aux));
|
context.response()
|
||||||
} else {
|
.putHeader("content-type", "application/json; charset=utf-8")
|
||||||
context.response().setStatusCode(500).end(result.cause().getMessage());
|
.end(gson.toJson(aux));
|
||||||
}
|
} else {
|
||||||
});
|
context.fail(500, complete.cause());
|
||||||
|
}
|
||||||
restClient.getRequest(configManager.getDataApiPort(), "http://" + configManager.getHost(),
|
});
|
||||||
Constants.GET_DEVICES, Device[].class, resultList);
|
|
||||||
}
|
this.restClient.getRequest(configManager.getDataApiPort(), configManager.getHost(),
|
||||||
|
Constants.GET_GROUP_DEVICES, Device[].class, resultList);
|
||||||
|
}
|
||||||
|
|
||||||
private void getDeviceSensors(RoutingContext context) {
|
private void getDeviceSensors(RoutingContext context) {
|
||||||
Integer deviceId = Integer.parseInt(context.request().getParam("deviceId"));
|
Integer deviceId = Integer.parseInt(context.request().getParam("deviceId"));
|
||||||
@@ -131,19 +136,94 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void getDeviceLatestValues(RoutingContext context) {
|
private void getDeviceLatestValues(RoutingContext context) {
|
||||||
context.response().end("TODO");
|
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()
|
||||||
|
.filter(d -> d.getDeviceId() == deviceId)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
context.response()
|
||||||
|
.putHeader("content-type", "application/json; charset=utf-8")
|
||||||
|
.end(gson.toJson(aux));
|
||||||
|
} else {
|
||||||
|
context.fail(500, complete.cause());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.restClient.getRequest(configManager.getDataApiPort(), configManager.getHost(),
|
||||||
|
Constants.GET_DEVICE_LATEST_VALUES, DeviceLatestValuesView[].class, resultList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getDevicePollutionMap(RoutingContext context) {
|
private void getDevicePollutionMap(RoutingContext context) {
|
||||||
context.response().end("TODO");
|
Integer deviceId = Integer.parseInt(context.request().getParam("deviceId"));
|
||||||
|
|
||||||
|
Promise<DevicePollutionMap[]> resultList = Promise.promise();
|
||||||
|
|
||||||
|
resultList.future().onComplete(complete -> {
|
||||||
|
if (complete.succeeded()) {
|
||||||
|
List<DevicePollutionMap> aux = Arrays.asList(complete.result()).stream()
|
||||||
|
.filter(d -> d.getDeviceId() == deviceId)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
context.response()
|
||||||
|
.putHeader("content-type", "application/json; charset=utf-8")
|
||||||
|
.end(gson.toJson(aux));
|
||||||
|
} else {
|
||||||
|
context.fail(500, complete.cause());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.restClient.getRequest(configManager.getDataApiPort(), configManager.getHost(),
|
||||||
|
Constants.GET_DEVICE_POLLUTION_MAP, DevicePollutionMap[].class, resultList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getDeviceHistory(RoutingContext context) {
|
private void getDeviceHistory(RoutingContext context) {
|
||||||
context.response().end("TODO");
|
Integer deviceId = Integer.parseInt(context.request().getParam("deviceId"));
|
||||||
|
|
||||||
|
Promise<DeviceSensorHistory[]> resultList = Promise.promise();
|
||||||
|
|
||||||
|
resultList.future().onComplete(complete -> {
|
||||||
|
if (complete.succeeded()) {
|
||||||
|
List<DeviceSensorHistory> aux = Arrays.asList(complete.result()).stream()
|
||||||
|
.filter(d -> d.getDeviceId() == deviceId)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
context.response()
|
||||||
|
.putHeader("content-type", "application/json; charset=utf-8")
|
||||||
|
.end(gson.toJson(aux));
|
||||||
|
} else {
|
||||||
|
context.fail(500, complete.cause());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.restClient.getRequest(configManager.getDataApiPort(), configManager.getHost(),
|
||||||
|
Constants.GET_DEVICE_HISTORY, DeviceSensorHistory[].class, resultList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getSensorValues(RoutingContext context) {
|
private void getSensorValues(RoutingContext context) {
|
||||||
context.response().end("TODO");
|
Integer deviceId = Integer.parseInt(context.request().getParam("deviceId"));
|
||||||
|
|
||||||
|
Promise<DeviceSensorValue[]> resultList = Promise.promise();
|
||||||
|
|
||||||
|
resultList.future().onComplete(complete -> {
|
||||||
|
if (complete.succeeded()) {
|
||||||
|
List<DeviceSensorValue> aux = Arrays.asList(complete.result()).stream()
|
||||||
|
.filter(d -> d.getDeviceId() == deviceId)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
context.response()
|
||||||
|
.putHeader("content-type", "application/json; charset=utf-8")
|
||||||
|
.end(gson.toJson(aux));
|
||||||
|
} else {
|
||||||
|
context.fail(500, complete.cause());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.restClient.getRequest(configManager.getDataApiPort(), configManager.getHost(),
|
||||||
|
Constants.GET_SENSOR_VALUES, DeviceSensorValue[].class, resultList);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user