|
|
@@ -7,6 +7,7 @@ import cz.senslog.telemetry.database.domain.UnitLocation;
|
|
|
import cz.senslog.telemetry.database.domain.UnitTelemetry;
|
|
|
import cz.senslog.telemetry.database.repository.SensLogRepository;
|
|
|
import cz.senslog.telemetry.database.domain.Filter;
|
|
|
+import cz.senslog.telemetry.utils.ListUtils;
|
|
|
import cz.senslog.telemetry.utils.TernaryCondition;
|
|
|
import io.vertx.core.http.HttpServerRequest;
|
|
|
import io.vertx.core.json.JsonArray;
|
|
|
@@ -24,9 +25,11 @@ import static cz.senslog.telemetry.database.validation.UnitTelemetryValidation.*
|
|
|
import static cz.senslog.telemetry.server.ws.ContentType.GEOJSON;
|
|
|
import static cz.senslog.telemetry.server.ws.ContentType.JSON;
|
|
|
import static cz.senslog.telemetry.utils.FluentInvoke.fluentlyOf;
|
|
|
+import static cz.senslog.telemetry.utils.ListUtils.*;
|
|
|
import static cz.senslog.telemetry.utils.TernaryCondition.ternaryIf;
|
|
|
import static io.vertx.core.http.HttpHeaders.CONTENT_TYPE;
|
|
|
import static java.lang.Boolean.parseBoolean;
|
|
|
+import static java.time.OffsetDateTime.ofInstant;
|
|
|
import static java.time.format.DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
|
|
import static java.util.Collections.emptyList;
|
|
|
import static java.util.Comparator.comparing;
|
|
|
@@ -42,7 +45,7 @@ public class OpenAPIHandler {
|
|
|
private static final ContentType DEFAULT_RESPONSE_FORMAT = JSON;
|
|
|
|
|
|
private static final BiFunction<OffsetDateTime, ZoneId, String> DATE_TIME_FORMATTER = (dateTime, zoneId) ->
|
|
|
- OffsetDateTime.ofInstant(dateTime.toInstant(), zoneId).format(ISO_OFFSET_DATE_TIME);
|
|
|
+ ofInstant(dateTime.toInstant(), zoneId).format(ISO_OFFSET_DATE_TIME);
|
|
|
|
|
|
private final SensLogRepository repo;
|
|
|
|
|
|
@@ -223,7 +226,7 @@ public class OpenAPIHandler {
|
|
|
"data", new JsonArray(
|
|
|
paging.data().stream().map(o -> JsonObject.of(
|
|
|
"unitId", o.getUnitId(),
|
|
|
- "timestamp", OffsetDateTime.ofInstant(o.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
|
|
|
+ "timestamp", ofInstant(o.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
|
|
|
"speed", o.getSpeed(),
|
|
|
"location", JsonObject.of(
|
|
|
"longitude", o.getLocation().getLongitude(),
|
|
|
@@ -253,7 +256,7 @@ public class OpenAPIHandler {
|
|
|
),
|
|
|
"properties", JsonObject.of(
|
|
|
"unitId", o.getUnitId(),
|
|
|
- "timestamp", OffsetDateTime.ofInstant(o.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
|
|
|
+ "timestamp", ofInstant(o.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
|
|
|
"speed", o.getSpeed(),
|
|
|
"observedValues", o.getObservedValues()
|
|
|
)
|
|
|
@@ -343,7 +346,7 @@ public class OpenAPIHandler {
|
|
|
"hasNext", paging.hasNext(),
|
|
|
"data", new JsonArray(
|
|
|
paging.data().stream().map(o -> JsonObject.of(
|
|
|
- "timestamp", OffsetDateTime.ofInstant(o.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
|
|
|
+ "timestamp", ofInstant(o.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
|
|
|
"speed", o.getSpeed(),
|
|
|
"location", JsonObject.of(
|
|
|
"longitude", o.getLocation().getLongitude(),
|
|
|
@@ -374,7 +377,7 @@ public class OpenAPIHandler {
|
|
|
),
|
|
|
"properties", JsonObject.of(
|
|
|
"unitId", o.getUnitId(),
|
|
|
- "timestamp", OffsetDateTime.ofInstant(o.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
|
|
|
+ "timestamp", ofInstant(o.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
|
|
|
"speed", o.getSpeed(),
|
|
|
"observedValues", o.getObservedValues()
|
|
|
)
|
|
|
@@ -447,7 +450,7 @@ public class OpenAPIHandler {
|
|
|
"size", locations.size(),
|
|
|
"data", new JsonArray(locations.stream().map(l -> JsonObject.of(
|
|
|
"unitId", l.getUnitId(),
|
|
|
- "timestamp", OffsetDateTime.ofInstant(l.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
|
|
|
+ "timestamp", ofInstant(l.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
|
|
|
"location", JsonObject.of(
|
|
|
"longitude", l.getLocation().getLongitude(),
|
|
|
"latitude", l.getLocation().getLatitude(),
|
|
|
@@ -464,7 +467,9 @@ public class OpenAPIHandler {
|
|
|
"features", unitLocation.entrySet().stream().map(entry -> JsonObject.of(
|
|
|
"type", "Feature",
|
|
|
"properties", JsonObject.of(
|
|
|
- "unitId", entry.getKey()),
|
|
|
+ "unitId", entry.getKey(),
|
|
|
+ "fromTime", firstOf(entry.getValue()).map(t -> ofInstant(t.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME)).orElse(null),
|
|
|
+ "toTime", lastOf(entry.getValue()).map(t -> ofInstant(t.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME)).orElse(null)),
|
|
|
"geometry", JsonObject.of(
|
|
|
"type", "MultiPoint",
|
|
|
"coordinates", new JsonArray(entry.getValue().stream().map(l -> JsonArray.of(
|
|
|
@@ -559,7 +564,7 @@ public class OpenAPIHandler {
|
|
|
"hasNext", paging.hasNext(),
|
|
|
"data", new JsonArray(
|
|
|
paging.data().stream().map(l -> JsonObject.of(
|
|
|
- "timestamp", OffsetDateTime.ofInstant(l.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
|
|
|
+ "timestamp", ofInstant(l.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
|
|
|
"location", JsonObject.of(
|
|
|
"longitude", l.getLocation().getLongitude(),
|
|
|
"latitude", l.getLocation().getLatitude(),
|
|
|
@@ -573,10 +578,12 @@ public class OpenAPIHandler {
|
|
|
"size", paging.size(),
|
|
|
"offset", offset,
|
|
|
"hasNext", paging.hasNext()
|
|
|
- ),
|
|
|
- "properties", JsonObject.of(
|
|
|
- "unitId", unitId
|
|
|
- ),
|
|
|
+ ),
|
|
|
+ "properties", ofNonEmpty(paging.data()).map(locs -> JsonObject.of(
|
|
|
+ "unitId", firstOf(locs).map(UnitLocation::getUnitId).orElse(null),
|
|
|
+ "fromTime", firstOf(locs).map(t -> ofInstant(t.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME)).orElse(null),
|
|
|
+ "toTime", lastOf(locs).map(t -> ofInstant(t.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME)).orElse(null)
|
|
|
+ )).orElseGet(JsonObject::new),
|
|
|
"geometry", JsonObject.of(
|
|
|
"type", "MultiPoint",
|
|
|
"coordinates", new JsonArray(paging.data().stream().map(l -> JsonArray.of(
|
|
|
@@ -956,7 +963,7 @@ public class OpenAPIHandler {
|
|
|
"data", new JsonArray(
|
|
|
paging.data().stream().map(l -> JsonObject.of(
|
|
|
"observedValue", l.getValue(),
|
|
|
- "timestamp", OffsetDateTime.ofInstant(l.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
|
|
|
+ "timestamp", ofInstant(l.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
|
|
|
"speed", l.getSpeed(),
|
|
|
"location", JsonObject.of(
|
|
|
"longitude", l.getLocation().getLongitude(),
|
|
|
@@ -985,7 +992,7 @@ public class OpenAPIHandler {
|
|
|
),
|
|
|
"properties", JsonObject.of(
|
|
|
"unitId", unitId,
|
|
|
- "timestamp", OffsetDateTime.ofInstant(o.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
|
|
|
+ "timestamp", ofInstant(o.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
|
|
|
"speed", o.getSpeed(),
|
|
|
"observedValues", JsonObject.of(
|
|
|
String.valueOf(sensorId), o.getValue()
|
|
|
@@ -1351,7 +1358,7 @@ public class OpenAPIHandler {
|
|
|
"hasNext", paging.hasNext(),
|
|
|
"data", new JsonArray(
|
|
|
paging.data().stream().map(o -> JsonObject.of(
|
|
|
- "timestamp", OffsetDateTime.ofInstant(o.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
|
|
|
+ "timestamp", ofInstant(o.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
|
|
|
"speed", o.getSpeed(),
|
|
|
"location", JsonObject.of(
|
|
|
"longitude", o.getLocation().getLongitude(),
|
|
|
@@ -1381,7 +1388,7 @@ public class OpenAPIHandler {
|
|
|
),
|
|
|
"properties", JsonObject.of(
|
|
|
"unitId", o.getUnitId(),
|
|
|
- "timestamp", OffsetDateTime.ofInstant(o.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
|
|
|
+ "timestamp", ofInstant(o.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
|
|
|
"speed", o.getSpeed(),
|
|
|
"observedValues", o.getObservedValues()
|
|
|
)
|
|
|
@@ -1469,7 +1476,7 @@ public class OpenAPIHandler {
|
|
|
"hasNext", paging.hasNext(),
|
|
|
"data", new JsonArray(
|
|
|
paging.data().stream().map(l -> JsonObject.of(
|
|
|
- "timestamp", OffsetDateTime.ofInstant(l.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
|
|
|
+ "timestamp", ofInstant(l.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME),
|
|
|
"location", JsonObject.of(
|
|
|
"longitude", l.getLocation().getLongitude(),
|
|
|
"latitude", l.getLocation().getLatitude(),
|
|
|
@@ -1484,8 +1491,11 @@ public class OpenAPIHandler {
|
|
|
"offset", offset,
|
|
|
"hasNext", paging.hasNext()
|
|
|
),
|
|
|
- "properties", ofNullable(paging.size() > 0 ? paging.data().get(0) : null)
|
|
|
- .map(l -> JsonObject.of("unitId", l.getUnitId())).orElseGet(JsonObject::new),
|
|
|
+ "properties", ofNonEmpty(paging.data()).map(locs -> JsonObject.of(
|
|
|
+ "unitId", firstOf(locs).map(UnitLocation::getUnitId).orElse(null),
|
|
|
+ "fromTime", firstOf(locs).map(t -> ofInstant(t.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME)).orElse(null),
|
|
|
+ "toTime", lastOf(locs).map(t -> ofInstant(t.getTimestamp().toInstant(), zone).format(ISO_OFFSET_DATE_TIME)).orElse(null)
|
|
|
+ )).orElseGet(JsonObject::new),
|
|
|
"geometry", JsonObject.of(
|
|
|
"type", "MultiPoint",
|
|
|
"coordinates", new JsonArray(paging.data().stream().map(l -> JsonArray.of(
|