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.unit = row.getString("unit");
|
||||||
this.sensorStatus = row.getInteger("sensorStatus");
|
this.sensorStatus = row.getInteger("sensorStatus");
|
||||||
this.temperature = row.getFloat("temperature");
|
this.temperature = row.getFloat("temperature");
|
||||||
this.humidity = row.getFloat("humidty");
|
this.humidity = row.getFloat("humidity");
|
||||||
this.carbonMonoxide = row.getFloat("carbonMonoxide");
|
this.carbonMonoxide = row.getFloat("carbonMonoxide");
|
||||||
this.lat = row.getFloat("lat");
|
this.lat = row.getFloat("lat");
|
||||||
this.lon = row.getFloat("lon");
|
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.QueryBuilder;
|
||||||
import net.miarma.contaminus.database.entities.Device;
|
import net.miarma.contaminus.database.entities.Device;
|
||||||
import net.miarma.contaminus.database.entities.DeviceLatestValuesView;
|
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;
|
import net.miarma.contaminus.database.entities.Sensor;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@@ -77,6 +80,9 @@ public class DataLayerAPIVerticle extends AbstractVerticle {
|
|||||||
|
|
||||||
// Views Routes
|
// Views Routes
|
||||||
router.route(HttpMethod.GET, Constants.GET_LATEST_VALUES_VIEW).handler(this::getLatestValuesView);
|
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()
|
vertx.createHttpServer()
|
||||||
.requestHandler(router)
|
.requestHandler(router)
|
||||||
@@ -171,4 +177,52 @@ public class DataLayerAPIVerticle extends AbstractVerticle {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 -> {
|
resultList.future().onComplete(complete -> {
|
||||||
if (complete.succeeded()) {
|
if (complete.succeeded()) {
|
||||||
List<DeviceLatestValuesView> aux = Stream.of(complete.result())
|
List<DeviceLatestValuesView> aux = Stream.of(complete.result())
|
||||||
.filter(d -> d.getDeviceId() == deviceId)
|
.filter(elem -> elem.getDeviceId() == deviceId)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
context.response()
|
context.response()
|
||||||
@@ -166,7 +166,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
|
|||||||
resultList.future().onComplete(complete -> {
|
resultList.future().onComplete(complete -> {
|
||||||
if (complete.succeeded()) {
|
if (complete.succeeded()) {
|
||||||
List<DevicePollutionMap> aux = Arrays.asList(complete.result()).stream()
|
List<DevicePollutionMap> aux = Arrays.asList(complete.result()).stream()
|
||||||
.filter(d -> d.getDeviceId() == deviceId)
|
.filter(elem -> elem.getDeviceId() == deviceId)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
context.response()
|
context.response()
|
||||||
@@ -189,7 +189,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
|
|||||||
resultList.future().onComplete(complete -> {
|
resultList.future().onComplete(complete -> {
|
||||||
if (complete.succeeded()) {
|
if (complete.succeeded()) {
|
||||||
List<DeviceSensorHistory> aux = Arrays.asList(complete.result()).stream()
|
List<DeviceSensorHistory> aux = Arrays.asList(complete.result()).stream()
|
||||||
.filter(d -> d.getDeviceId() == deviceId)
|
.filter(elem -> elem.getDeviceId() == deviceId)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
context.response()
|
context.response()
|
||||||
@@ -205,14 +205,14 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void getSensorValues(RoutingContext context) {
|
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();
|
Promise<DeviceSensorValue[]> resultList = Promise.promise();
|
||||||
|
|
||||||
resultList.future().onComplete(complete -> {
|
resultList.future().onComplete(complete -> {
|
||||||
if (complete.succeeded()) {
|
if (complete.succeeded()) {
|
||||||
List<DeviceSensorValue> aux = Arrays.asList(complete.result()).stream()
|
List<DeviceSensorValue> aux = Arrays.asList(complete.result()).stream()
|
||||||
.filter(d -> d.getDeviceId() == deviceId)
|
.filter(val -> val.getSensorId() == sensorId)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
context.response()
|
context.response()
|
||||||
|
|||||||
Reference in New Issue
Block a user