Changes
This commit is contained in:
@@ -23,18 +23,23 @@ public class DeviceLatestValuesView {
|
||||
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 = DateParser.parseDate(row.getLocalDateTime("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 = DateParser.parseDate(row.getLocalDateTime("airValuesTimestamp"));
|
||||
this.deviceId = row.getInteger("deviceId") != null ? row.getInteger("deviceId") : -1;
|
||||
this.sensorId = row.getInteger("sensorId") != null ? row.getInteger("sensorId") : -1;
|
||||
this.sensorType = row.getString("sensorType") != null ? row.getString("sensorType") : "unknown";
|
||||
this.unit = row.getString("unit") != null ? row.getString("unit") : "unknown";
|
||||
this.sensorStatus = row.getInteger("sensorStatus") != null ? row.getInteger("sensorStatus") : 0;
|
||||
|
||||
this.sensorTimestamp = row.getLocalDateTime("sensorTimestamp") != null ?
|
||||
DateParser.parseDate(row.getLocalDateTime("sensorTimestamp")) : 0;
|
||||
|
||||
this.temperature = row.getFloat("temperature") != null ? row.getFloat("temperature") : 0.0f;
|
||||
this.humidity = row.getFloat("humidity") != null ? row.getFloat("humidity") : 0.0f;
|
||||
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,
|
||||
|
||||
@@ -19,6 +19,7 @@ import net.miarma.contaminus.common.Constants;
|
||||
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.Sensor;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@@ -73,6 +74,9 @@ public class DataLayerAPIVerticle extends AbstractVerticle {
|
||||
router.route(HttpMethod.POST, Constants.POST_ACTUATORS).handler(this::addActuator);
|
||||
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()
|
||||
.requestHandler(router)
|
||||
.listen(configManager.getDataApiPort(), configManager.getHost());
|
||||
@@ -144,4 +148,26 @@ public class DataLayerAPIVerticle extends AbstractVerticle {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -146,14 +146,14 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
|
||||
.toList();
|
||||
|
||||
context.response()
|
||||
.putHeader("content-type", "application/json; charset=utf-8")
|
||||
.end(gson.toJson(aux));
|
||||
.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(),
|
||||
this.restClient.getRequest(configManager.getDataApiPort(), "http://" + configManager.getHost(),
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user