|
|
@@ -5,11 +5,13 @@ import io.connector.core.AbstractGateway;
|
|
|
import io.connector.core.DataCollection;
|
|
|
import io.connector.core.Message;
|
|
|
import io.connector.core.MessageHeader;
|
|
|
+import io.connector.core.config.AllowedStation;
|
|
|
import io.connector.model.senslog1.*;
|
|
|
import io.connector.module.senslog1.SensLog1Client;
|
|
|
import io.connector.module.senslog1.SensLog1SchedulerConfig;
|
|
|
import io.vertx.core.MultiMap;
|
|
|
import io.vertx.core.buffer.Buffer;
|
|
|
+import io.vertx.core.json.JsonArray;
|
|
|
import io.vertx.core.json.JsonObject;
|
|
|
|
|
|
import java.time.OffsetDateTime;
|
|
|
@@ -17,6 +19,7 @@ import java.util.*;
|
|
|
|
|
|
import static java.time.OffsetDateTime.MAX;
|
|
|
import static java.time.OffsetDateTime.MIN;
|
|
|
+import static java.time.format.DateTimeFormatter.ISO_DATE_TIME;
|
|
|
import static java.time.format.DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
|
|
|
|
|
public class SensLog1Gateway extends AbstractGateway {
|
|
|
@@ -39,27 +42,43 @@ public class SensLog1Gateway extends AbstractGateway {
|
|
|
|
|
|
event().consume("schedule-observations", message -> {
|
|
|
List<UnitData> unitData = client.lastObservations();
|
|
|
- OffsetDateTime from = MAX, to = MIN;
|
|
|
+
|
|
|
+ AllowedStation allowedStation = schedulerConfig.getAllowedStations();
|
|
|
+ JsonArray stations = new JsonArray();
|
|
|
for (UnitData unit : unitData) {
|
|
|
- for (SensorData sensor : unit.getSensors()) {
|
|
|
- for (Observation observation : sensor.getObservations()) {
|
|
|
- if (observation.getTimestamp().isBefore(from)) {
|
|
|
- from = observation.getTimestamp();
|
|
|
- }
|
|
|
- if (observation.getTimestamp().isAfter(to)) {
|
|
|
- to = observation.getTimestamp();
|
|
|
+ if (allowedStation.isAllowed(Long.toString(unit.getId()))) {
|
|
|
+ OffsetDateTime from = MAX, to = MIN;
|
|
|
+ JsonArray allowedSensors = new JsonArray();
|
|
|
+ for (SensorData sensor : unit.getSensors()) {
|
|
|
+ for (Observation observation : sensor.getObservations()) {
|
|
|
+ OffsetDateTime time = observation.getTimestamp();
|
|
|
+ if (time.isBefore(from)) {
|
|
|
+ from = observation.getTimestamp();
|
|
|
+ }
|
|
|
+ if (time.isAfter(to)) {
|
|
|
+ to = observation.getTimestamp();
|
|
|
+ }
|
|
|
+ allowedSensors.add(new JsonObject()
|
|
|
+ .put("id", sensor.getId())
|
|
|
+ .put("timestamp", time.format(ISO_OFFSET_DATE_TIME))
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
+ stations.add(new JsonObject()
|
|
|
+ .put("id", unit.getId())
|
|
|
+ .put("fromDate", from.format(ISO_OFFSET_DATE_TIME))
|
|
|
+ .put("allowedSensors", allowedSensors));
|
|
|
}
|
|
|
}
|
|
|
+ JsonObject configBody = new JsonObject()
|
|
|
+ .put("startDate", schedulerConfig.getStartDate().format(ISO_DATE_TIME))
|
|
|
+ .put("allowedStations", stations);
|
|
|
|
|
|
- // TODO add scheduler config to the body
|
|
|
- String allowedUnits = String.join(",", schedulerConfig.getAllowedStations());
|
|
|
|
|
|
- message.reply(message.body()).options()
|
|
|
+ message.reply(configBody).options()
|
|
|
.addHeader("fromDate", "2020-02-10T06:30:00+01:00") // from.format(ISO_OFFSET_DATE_TIME))
|
|
|
.addHeader("toDate", "2020-02-10T07:30:00+01:00") // to.format(ISO_OFFSET_DATE_TIME))
|
|
|
- .addHeader("unitId", allowedUnits);
|
|
|
+ .addHeader("unitId", "");
|
|
|
});
|
|
|
|
|
|
event().consume("units", message -> {
|