Changes
This commit is contained in:
@@ -23,18 +23,23 @@ public class DeviceLatestValuesView {
|
|||||||
public DeviceLatestValuesView() {}
|
public DeviceLatestValuesView() {}
|
||||||
|
|
||||||
public DeviceLatestValuesView(Row row) {
|
public DeviceLatestValuesView(Row row) {
|
||||||
this.deviceId = row.getInteger("deviceId");
|
this.deviceId = row.getInteger("deviceId") != null ? row.getInteger("deviceId") : -1;
|
||||||
this.sensorId = row.getInteger("sensorId");
|
this.sensorId = row.getInteger("sensorId") != null ? row.getInteger("sensorId") : -1;
|
||||||
this.sensorType = row.getString("sensorType");
|
this.sensorType = row.getString("sensorType") != null ? row.getString("sensorType") : "unknown";
|
||||||
this.unit = row.getString("unit");
|
this.unit = row.getString("unit") != null ? row.getString("unit") : "unknown";
|
||||||
this.sensorStatus = row.getInteger("sensorStatus");
|
this.sensorStatus = row.getInteger("sensorStatus") != null ? row.getInteger("sensorStatus") : 0;
|
||||||
this.sensorTimestamp = DateParser.parseDate(row.getLocalDateTime("sensorTimestamp"));
|
|
||||||
this.temperature = row.getFloat("temperature");
|
this.sensorTimestamp = row.getLocalDateTime("sensorTimestamp") != null ?
|
||||||
this.humidity = row.getFloat("humidity");
|
DateParser.parseDate(row.getLocalDateTime("sensorTimestamp")) : 0;
|
||||||
this.carbonMonoxide = row.getFloat("carbonMonoxide");
|
|
||||||
this.lat = row.getFloat("lat");
|
this.temperature = row.getFloat("temperature") != null ? row.getFloat("temperature") : 0.0f;
|
||||||
this.lon = row.getFloat("lon");
|
this.humidity = row.getFloat("humidity") != null ? row.getFloat("humidity") : 0.0f;
|
||||||
this.airValuesTimestamp = DateParser.parseDate(row.getLocalDateTime("airValuesTimestamp"));
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeviceLatestValuesView(int deviceId, int sensorId, String sensorType, String unit, int sensorStatus,
|
public DeviceLatestValuesView(int deviceId, int sensorId, String sensorType, String unit, int sensorStatus,
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import net.miarma.contaminus.common.Constants;
|
|||||||
import net.miarma.contaminus.database.DatabaseManager;
|
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.Sensor;
|
import net.miarma.contaminus.database.entities.Sensor;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@@ -73,6 +74,9 @@ public class DataLayerAPIVerticle extends AbstractVerticle {
|
|||||||
router.route(HttpMethod.POST, Constants.POST_ACTUATORS).handler(this::addActuator);
|
router.route(HttpMethod.POST, Constants.POST_ACTUATORS).handler(this::addActuator);
|
||||||
router.route(HttpMethod.PUT, Constants.PUT_ACTUATOR_BY_ID).handler(this::updateActuator);
|
router.route(HttpMethod.PUT, Constants.PUT_ACTUATOR_BY_ID).handler(this::updateActuator);
|
||||||
|
|
||||||
|
// Views Routes
|
||||||
|
router.route(HttpMethod.GET, Constants.GET_LATEST_VALUES_VIEW).handler(this::getLatestValuesView);
|
||||||
|
|
||||||
vertx.createHttpServer()
|
vertx.createHttpServer()
|
||||||
.requestHandler(router)
|
.requestHandler(router)
|
||||||
.listen(configManager.getDataApiPort(), configManager.getHost());
|
.listen(configManager.getDataApiPort(), configManager.getHost());
|
||||||
@@ -144,4 +148,26 @@ public class DataLayerAPIVerticle extends AbstractVerticle {
|
|||||||
context.response().end("TODO");
|
context.response().end("TODO");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A PARTIR DE AQUI LO HACEMOS ÁLVARO Y YO
|
||||||
|
* NO RAYARSE
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
private void getLatestValuesView(RoutingContext context) {
|
||||||
|
String query = QueryBuilder
|
||||||
|
.select(DeviceLatestValuesView.class)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
dbManager.execute(query, DeviceLatestValuesView.class,
|
||||||
|
onSuccess -> {
|
||||||
|
context.response()
|
||||||
|
.putHeader("content-type", "application/json; charset=utf-8")
|
||||||
|
.end(gson.toJson(onSuccess));
|
||||||
|
},
|
||||||
|
onFailure -> {
|
||||||
|
context.fail(500, onFailure);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.restClient.getRequest(configManager.getDataApiPort(), configManager.getHost(),
|
this.restClient.getRequest(configManager.getDataApiPort(), "http://" + configManager.getHost(),
|
||||||
Constants.GET_GROUP_DEVICES, Device[].class, resultList);
|
Constants.GET_GROUP_DEVICES, Device[].class, resultList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,14 +146,14 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
|
|||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
context.response()
|
context.response()
|
||||||
.putHeader("content-type", "application/json; charset=utf-8")
|
.putHeader("content-type", "application/json; charset=utf-8")
|
||||||
.end(gson.toJson(aux));
|
.end(gson.toJson(aux));
|
||||||
} else {
|
} else {
|
||||||
context.fail(500, complete.cause());
|
context.fail(500, complete.cause());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.restClient.getRequest(configManager.getDataApiPort(), configManager.getHost(),
|
this.restClient.getRequest(configManager.getDataApiPort(), "http://" + configManager.getHost(),
|
||||||
Constants.GET_DEVICE_LATEST_VALUES, DeviceLatestValuesView[].class, resultList);
|
Constants.GET_DEVICE_LATEST_VALUES, DeviceLatestValuesView[].class, resultList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +176,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.restClient.getRequest(configManager.getDataApiPort(), configManager.getHost(),
|
this.restClient.getRequest(configManager.getDataApiPort(), "http://" + configManager.getHost(),
|
||||||
Constants.GET_DEVICE_POLLUTION_MAP, DevicePollutionMap[].class, resultList);
|
Constants.GET_DEVICE_POLLUTION_MAP, DevicePollutionMap[].class, resultList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,7 +199,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.restClient.getRequest(configManager.getDataApiPort(), configManager.getHost(),
|
this.restClient.getRequest(configManager.getDataApiPort(), "http://" + configManager.getHost(),
|
||||||
Constants.GET_DEVICE_HISTORY, DeviceSensorHistory[].class, resultList);
|
Constants.GET_DEVICE_HISTORY, DeviceSensorHistory[].class, resultList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +222,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.restClient.getRequest(configManager.getDataApiPort(), configManager.getHost(),
|
this.restClient.getRequest(configManager.getDataApiPort(), "http://" + configManager.getHost(),
|
||||||
Constants.GET_SENSOR_VALUES, DeviceSensorValue[].class, resultList);
|
Constants.GET_SENSOR_VALUES, DeviceSensorValue[].class, resultList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user