Fixed errors in Business Logic API and finished it.
This commit is contained in:
16
backend/src/main/java/net/miarma/contaminus/Main.java
Normal file
16
backend/src/main/java/net/miarma/contaminus/Main.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package net.miarma.contaminus;
|
||||
|
||||
import net.miarma.contaminus.database.QueryBuilder;
|
||||
import net.miarma.contaminus.database.entities.DeviceSensorValue;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
String query = QueryBuilder
|
||||
.select(DeviceSensorValue.class)
|
||||
.build();
|
||||
System.out.println(query);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public class DeviceSensorValue {
|
||||
this.unit = row.getString("unit");
|
||||
this.sensorStatus = row.getInteger("sensorStatus");
|
||||
this.temperature = row.getFloat("temperature");
|
||||
this.humidity = row.getFloat("humidty");
|
||||
this.humidity = row.getFloat("humidity");
|
||||
this.carbonMonoxide = row.getFloat("carbonMonoxide");
|
||||
this.lat = row.getFloat("lat");
|
||||
this.lon = row.getFloat("lon");
|
||||
|
||||
@@ -21,6 +21,9 @@ import net.miarma.contaminus.database.DatabaseManager;
|
||||
import net.miarma.contaminus.database.QueryBuilder;
|
||||
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.Sensor;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@@ -77,6 +80,9 @@ public class DataLayerAPIVerticle extends AbstractVerticle {
|
||||
|
||||
// Views Routes
|
||||
router.route(HttpMethod.GET, Constants.GET_LATEST_VALUES_VIEW).handler(this::getLatestValuesView);
|
||||
router.route(HttpMethod.GET, Constants.GET_POLLUTION_MAP_VIEW).handler(this::getDevicePollutionMapView);
|
||||
router.route(HttpMethod.GET, Constants.GET_SENSOR_VALUES_VIEW).handler(this::getSensorValuesView);
|
||||
router.route(HttpMethod.GET, Constants.GET_SENSOR_HISTORY_BY_DEVICE_VIEW).handler(this::getSensorHistoryByDeviceView);
|
||||
|
||||
vertx.createHttpServer()
|
||||
.requestHandler(router)
|
||||
@@ -170,5 +176,53 @@ public class DataLayerAPIVerticle extends AbstractVerticle {
|
||||
context.fail(500, onFailure);
|
||||
});
|
||||
}
|
||||
|
||||
private void getDevicePollutionMapView(RoutingContext context) {
|
||||
String query = QueryBuilder
|
||||
.select(DevicePollutionMap.class)
|
||||
.build();
|
||||
|
||||
dbManager.execute(query, DevicePollutionMap.class,
|
||||
onSuccess -> {
|
||||
context.response()
|
||||
.putHeader("content-type", "application/json; charset=utf-8")
|
||||
.end(gson.toJson(onSuccess));
|
||||
},
|
||||
onFailure -> {
|
||||
context.fail(500, onFailure);
|
||||
});
|
||||
}
|
||||
|
||||
private void getSensorValuesView(RoutingContext context) {
|
||||
String query = QueryBuilder
|
||||
.select(DeviceSensorValue.class)
|
||||
.build();
|
||||
|
||||
dbManager.execute(query, DeviceSensorValue.class,
|
||||
onSuccess -> {
|
||||
context.response()
|
||||
.putHeader("content-type", "application/json; charset=utf-8")
|
||||
.end(gson.toJson(onSuccess));
|
||||
},
|
||||
onFailure -> {
|
||||
context.fail(500, onFailure);
|
||||
});
|
||||
}
|
||||
|
||||
private void getSensorHistoryByDeviceView(RoutingContext context) {
|
||||
String query = QueryBuilder
|
||||
.select(DeviceSensorHistory.class)
|
||||
.build();
|
||||
|
||||
dbManager.execute(query, DeviceSensorHistory.class,
|
||||
onSuccess -> {
|
||||
context.response()
|
||||
.putHeader("content-type", "application/json; charset=utf-8")
|
||||
.end(gson.toJson(onSuccess));
|
||||
},
|
||||
onFailure -> {
|
||||
context.fail(500, onFailure);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
|
||||
resultList.future().onComplete(complete -> {
|
||||
if (complete.succeeded()) {
|
||||
List<DeviceLatestValuesView> aux = Stream.of(complete.result())
|
||||
.filter(d -> d.getDeviceId() == deviceId)
|
||||
.filter(elem -> elem.getDeviceId() == deviceId)
|
||||
.toList();
|
||||
|
||||
context.response()
|
||||
@@ -166,7 +166,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
|
||||
resultList.future().onComplete(complete -> {
|
||||
if (complete.succeeded()) {
|
||||
List<DevicePollutionMap> aux = Arrays.asList(complete.result()).stream()
|
||||
.filter(d -> d.getDeviceId() == deviceId)
|
||||
.filter(elem -> elem.getDeviceId() == deviceId)
|
||||
.toList();
|
||||
|
||||
context.response()
|
||||
@@ -189,7 +189,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
|
||||
resultList.future().onComplete(complete -> {
|
||||
if (complete.succeeded()) {
|
||||
List<DeviceSensorHistory> aux = Arrays.asList(complete.result()).stream()
|
||||
.filter(d -> d.getDeviceId() == deviceId)
|
||||
.filter(elem -> elem.getDeviceId() == deviceId)
|
||||
.toList();
|
||||
|
||||
context.response()
|
||||
@@ -205,14 +205,14 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
|
||||
}
|
||||
|
||||
private void getSensorValues(RoutingContext context) {
|
||||
Integer deviceId = Integer.parseInt(context.request().getParam("deviceId"));
|
||||
Integer sensorId = Integer.parseInt(context.request().getParam("sensorId"));
|
||||
|
||||
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)
|
||||
.filter(val -> val.getSensorId() == sensorId)
|
||||
.toList();
|
||||
|
||||
context.response()
|
||||
|
||||
Reference in New Issue
Block a user