Merge branch 'main' into feature/logicApi
This commit is contained in:
@@ -27,12 +27,13 @@ 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_LATEST_VALUES_VIEW = API_PREFIX + "/v_latest_values";
|
public static final String GET_GPS_BY_DEVICE_VIEW = API_PREFIX + "/v_gps_by_device";
|
||||||
public static final String GET_POLLUTION_MAP_VIEW = API_PREFIX + "/v_pollution_map";
|
public static final String GET_LATEST_VALUES_VIEW = API_PREFIX + "/v_latest_values";
|
||||||
public static final String GET_SENSOR_HISTORY_BY_DEVICE_VIEW = API_PREFIX + "/v_sensor_history_by_device";
|
public static final String GET_POLLUTION_MAP_VIEW = API_PREFIX + "/v_pollution_map";
|
||||||
public static final String GET_SENSOR_VALUES_VIEW = API_PREFIX + "/v_sensor_values";
|
public static final String GET_SENSOR_HISTORY_BY_DEVICE_VIEW = API_PREFIX + "/v_sensor_history_by_device";
|
||||||
public static final String GET_WEATHER_BY_DEVICE_VIEW = API_PREFIX + "/v_weather_by_device";
|
public static final String GET_SENSOR_VALUES_VIEW = API_PREFIX + "/v_sensor_values";
|
||||||
|
public static final String GET_WEATHER_BY_DEVICE_VIEW = API_PREFIX + "/v_weather_by_device";
|
||||||
|
|
||||||
/* Bussiness Logic API */
|
/* Bussiness Logic API */
|
||||||
public static final String GET_GROUP_BY_ID = API_PREFIX + "/groups/:groupId";
|
public static final String GET_GROUP_BY_ID = API_PREFIX + "/groups/:groupId";
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.google.gson.Gson;
|
|||||||
|
|
||||||
import io.vertx.core.AbstractVerticle;
|
import io.vertx.core.AbstractVerticle;
|
||||||
import io.vertx.core.Promise;
|
import io.vertx.core.Promise;
|
||||||
|
import io.vertx.core.Vertx;
|
||||||
import io.vertx.core.http.HttpMethod;
|
import io.vertx.core.http.HttpMethod;
|
||||||
import io.vertx.ext.web.Router;
|
import io.vertx.ext.web.Router;
|
||||||
import io.vertx.ext.web.RoutingContext;
|
import io.vertx.ext.web.RoutingContext;
|
||||||
@@ -23,6 +24,9 @@ import net.miarma.contaminus.database.entities.DeviceLatestValuesView;
|
|||||||
import net.miarma.contaminus.database.entities.DevicePollutionMap;
|
import net.miarma.contaminus.database.entities.DevicePollutionMap;
|
||||||
import net.miarma.contaminus.database.entities.DeviceSensorHistory;
|
import net.miarma.contaminus.database.entities.DeviceSensorHistory;
|
||||||
import net.miarma.contaminus.database.entities.DeviceSensorValue;
|
import net.miarma.contaminus.database.entities.DeviceSensorValue;
|
||||||
|
import net.miarma.contaminus.database.entities.Actuator;
|
||||||
|
import net.miarma.contaminus.database.entities.Device;
|
||||||
|
import net.miarma.contaminus.database.entities.Sensor;
|
||||||
import net.miarma.contaminus.util.RestClientUtil;
|
import net.miarma.contaminus.util.RestClientUtil;
|
||||||
|
|
||||||
public class LogicLayerAPIVerticle extends AbstractVerticle {
|
public class LogicLayerAPIVerticle extends AbstractVerticle {
|
||||||
@@ -72,7 +76,6 @@ 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"));
|
||||||
|
|
||||||
@@ -95,11 +98,41 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void getDeviceSensors(RoutingContext context) {
|
private void getDeviceSensors(RoutingContext context) {
|
||||||
context.response().end("TODO");
|
Integer deviceId = Integer.parseInt(context.request().getParam("deviceId"));
|
||||||
|
Promise<Sensor[]> resultList = Promise.promise();
|
||||||
|
resultList.future().onComplete(result -> {
|
||||||
|
if (result.succeeded()) {
|
||||||
|
Sensor[] sensors = result.result();
|
||||||
|
List<Sensor> aux = Arrays.stream(sensors)
|
||||||
|
.filter(s -> s.getDeviceId() == deviceId)
|
||||||
|
.toList();
|
||||||
|
context.response().putHeader("Content-Type", "application/json").end(gson.toJson(aux));
|
||||||
|
} else {
|
||||||
|
context.response().setStatusCode(500).end(result.cause().getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
restClient.getRequest(configManager.getDataApiPort(), "http://" + configManager.getHost(),
|
||||||
|
Constants.GET_SENSORS, Sensor[].class, resultList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getDeviceActuators(RoutingContext context) {
|
private void getDeviceActuators(RoutingContext context) {
|
||||||
context.response().end("TODO");
|
Integer deviceId = Integer.parseInt(context.request().getParam("deviceId"));
|
||||||
|
Promise<Actuator[]> resultList = Promise.promise();
|
||||||
|
resultList.future().onComplete(result -> {
|
||||||
|
if (result.succeeded()) {
|
||||||
|
Actuator[] devices = result.result();
|
||||||
|
List<Actuator> aux = Arrays.stream(devices)
|
||||||
|
.filter(a -> a.getDeviceId() == deviceId)
|
||||||
|
.toList();
|
||||||
|
context.response().putHeader("Content-Type", "application/json").end(gson.toJson(aux));
|
||||||
|
} else {
|
||||||
|
context.response().setStatusCode(500).end(result.cause().getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
restClient.getRequest(configManager.getDataApiPort(), "http://" + configManager.getHost(),
|
||||||
|
Constants.GET_DEVICES, Actuator[].class, resultList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getDeviceLatestValues(RoutingContext context) {
|
private void getDeviceLatestValues(RoutingContext context) {
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class RestClientUtil {
|
|||||||
* @param promise Promise to be executed on call finish
|
* @param promise Promise to be executed on call finish
|
||||||
*/
|
*/
|
||||||
public <T> void getRequest(Integer port, String host, String resource, Class<T> classType, Promise<T> promise) {
|
public <T> void getRequest(Integer port, String host, String resource, Class<T> classType, Promise<T> promise) {
|
||||||
client.getAbs(host + ":" + port + "/" + resource).send(elem -> {
|
client.getAbs(host + ":" + port + resource).send(elem -> {
|
||||||
if (elem.succeeded()) {
|
if (elem.succeeded()) {
|
||||||
promise.complete(gson.fromJson(elem.result().bodyAsString(), classType));
|
promise.complete(gson.fromJson(elem.result().bodyAsString(), classType));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user