|
|
@@ -1,288 +0,0 @@
|
|
|
-package io.connector.module.ogc.sensorthings.gateway;
|
|
|
-
|
|
|
-import io.connector.core.AbstractGateway;
|
|
|
-import io.connector.model.afarcloud.*;
|
|
|
-import io.connector.module.ogc.sensorthings.SensorThingsClient;
|
|
|
-import io.vertx.core.MultiMap;
|
|
|
-import io.vertx.core.http.HttpServerRequest;
|
|
|
-import io.vertx.core.json.JsonObject;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-import static io.connector.core.http.ContentType.APPLICATION_JSON;
|
|
|
-import static io.connector.core.http.Header.CONTENT_TYPE;
|
|
|
-import static io.connector.core.AddressPath.Creator.create;
|
|
|
-import static io.vertx.core.json.Json.encode;
|
|
|
-import static java.lang.Double.parseDouble;
|
|
|
-import static java.lang.Integer.parseInt;
|
|
|
-import static java.lang.String.format;
|
|
|
-import static java.util.Arrays.asList;
|
|
|
-import static java.util.Collections.emptyList;
|
|
|
-import static java.util.Collections.singletonList;
|
|
|
-import static java.util.Comparator.comparing;
|
|
|
-
|
|
|
-public class AFarCloudGateway extends AbstractGateway {
|
|
|
-
|
|
|
- private final SensorThingsClient client;
|
|
|
-
|
|
|
- public AFarCloudGateway(String id, SensorThingsClient client) {
|
|
|
- super(id);
|
|
|
- this.client = client;
|
|
|
- }
|
|
|
-
|
|
|
- private static String getRequiredParam(MultiMap params, String paramName) {
|
|
|
- String param = getParam(params, paramName);
|
|
|
- if (param == null) {
|
|
|
- throw new IllegalArgumentException(format("Parameter '%s' is required.", paramName));
|
|
|
- }
|
|
|
- return param;
|
|
|
- }
|
|
|
-
|
|
|
- private static String getParam(MultiMap params, String paramName) {
|
|
|
- return params.contains(paramName) ? params.get(paramName) : null;
|
|
|
- }
|
|
|
-
|
|
|
- private static String getParam(MultiMap params, String paramName, String defValue) {
|
|
|
- return params.contains(paramName) ? params.get(paramName) : defValue;
|
|
|
- }
|
|
|
-
|
|
|
- private static List<String> getSplittedParam(MultiMap params, String paramName) {
|
|
|
- String param = getParam(params, paramName);
|
|
|
- return param != null ? asList(param.split(",")) : emptyList();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void run() {
|
|
|
-
|
|
|
- // Query sensor telemetry
|
|
|
- router().get(create("getSensorTelemetry/latest")).handler(ctx -> {
|
|
|
-
|
|
|
- HttpServerRequest req = ctx.request();
|
|
|
- MultiMap params = req.params();
|
|
|
-
|
|
|
- final int limit = parseInt(getRequiredParam(params, "limit"));
|
|
|
- final List<String> entityNames = getSplittedParam(params, "entityNames");
|
|
|
- final List<String> devices = getSplittedParam(params, "devices");
|
|
|
- final List<String> services = getSplittedParam(params, "services");
|
|
|
- final List<String> types = getSplittedParam(params, "types");
|
|
|
- final List<String> providers = getSplittedParam(params, "providers");
|
|
|
- final List<String> measurements = getSplittedParam(params, "measurements");
|
|
|
- final Integer minAltitude = params.contains("altitude") ? parseInt(params.get("altitude")) : null; // TODO
|
|
|
- final String order = getParam(params, "order", "DESC").toUpperCase();
|
|
|
-
|
|
|
- ResponseModel<SensorTelemetry> responseModel = new ResponseModel<>();
|
|
|
-
|
|
|
- for (Map.Entry<String, String> entry : params.entries()) {
|
|
|
- responseModel.addParam(entry.getKey(), entry.getValue());
|
|
|
- }
|
|
|
- responseModel.setQuery(req.path()+"&"+req.query());
|
|
|
-
|
|
|
- // GET all telemetries
|
|
|
- List<SensorTelemetry> telemetries = new ArrayList<>(limit);
|
|
|
- for (int i = 0; i < limit; i++) {
|
|
|
- SensorTelemetry telemetry = new SensorTelemetry();
|
|
|
- telemetry.setMeasurement("wind_speed");
|
|
|
-
|
|
|
- Observation observation = new Observation();
|
|
|
- observation.setTime("2020-04-19T14:17:00Z");
|
|
|
- observation.setAltitude(282.);
|
|
|
- observation.setLatitude(50.0393219);
|
|
|
- observation.setLongitude(14.6106731);
|
|
|
- observation.setGeohash("u2fksmrhjmeq");
|
|
|
- observation.setValue(0.55);
|
|
|
- observation.setEntityName("1305167562287832");
|
|
|
- observation.setSequenceNumber("123");
|
|
|
- observation.setService("environmentalObservations");
|
|
|
- observation.setProvider("LESP");
|
|
|
- observation.setType("air_sensor");
|
|
|
- observation.setUom("http://qudt.org/vocab/multiSensor/M-PER-SEC");
|
|
|
- telemetry.addObservation(observation);
|
|
|
-
|
|
|
- telemetries.add(telemetry);
|
|
|
- }
|
|
|
- responseModel.setNumResults(telemetries.size());
|
|
|
-
|
|
|
- Comparator<SensorTelemetry> comparator = comparing(SensorTelemetry::getMeasurement);
|
|
|
- if (order.equals("DESC")) {
|
|
|
- comparator = comparator.reversed();
|
|
|
- }
|
|
|
- telemetries.sort(comparator);
|
|
|
-
|
|
|
- responseModel.setResults(telemetries);
|
|
|
- ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(encode(responseModel));
|
|
|
- });
|
|
|
-
|
|
|
- router().get(create("getObservationsBySensor/latest")).handler(ctx -> {
|
|
|
-
|
|
|
- HttpServerRequest req = ctx.request();
|
|
|
- MultiMap params = req.params();
|
|
|
-
|
|
|
- final int limit = parseInt(getRequiredParam(params, "limit"));
|
|
|
- final List<String> entityNames = getSplittedParam(params, "entityNames");
|
|
|
- final List<String> devices = getSplittedParam(params, "devices");
|
|
|
- final List<String> services = getSplittedParam(params, "services");
|
|
|
- final List<String> types = getSplittedParam(params, "types");
|
|
|
- final List<String> providers = getSplittedParam(params, "providers");
|
|
|
- final List<String> measurements = getSplittedParam(params, "measurements");
|
|
|
- final String order = getParam(params, "order", "DESC").toUpperCase();
|
|
|
- final Integer minAltitude = params.contains("altitude") ? parseInt(params.get("altitude")) : null; // TODO
|
|
|
- final Double centrLong = params.contains("centr_long") ? parseDouble(params.get("centr_long")) : null; // TODO
|
|
|
- final Double centrLat = params.contains("centr_lat") ? parseDouble(params.get("centr_lat")) : null; // TODO
|
|
|
- final Integer radius = params.contains("radius") ? parseInt(params.get("radius")) : null; // TODO
|
|
|
-
|
|
|
- ResponseModel<ResourceMeasurement> responseModel = new ResponseModel<>();
|
|
|
-
|
|
|
- for (Map.Entry<String, String> entry : params.entries()) {
|
|
|
- responseModel.addParam(entry.getKey(), entry.getValue());
|
|
|
- }
|
|
|
- responseModel.setQuery(req.path()+"&"+req.query());
|
|
|
-
|
|
|
- ResourceMeasurement measurement = new ResourceMeasurement();
|
|
|
- measurement.setResource("10002376");
|
|
|
- responseModel.setResults(singletonList(measurement));
|
|
|
-
|
|
|
- SensorTelemetry telemetry = new SensorTelemetry();
|
|
|
- telemetry.setMeasurement("wind_speed");
|
|
|
- measurement.setMeasurements(singletonList(telemetry));
|
|
|
-
|
|
|
- for (int i = 0; i < limit; i++) {
|
|
|
- Observation observation = new Observation();
|
|
|
- observation.setTime("2020-04-19T14:17:00Z");
|
|
|
- observation.setAltitude(282.);
|
|
|
- observation.setLatitude(50.0393219);
|
|
|
- observation.setLongitude(14.6106731);
|
|
|
- observation.setGeohash("u2fksmrhjmeq");
|
|
|
- observation.setValue(0.55);
|
|
|
- observation.setEntityName("1305167562287832");
|
|
|
- observation.setSequenceNumber("123");
|
|
|
- observation.setService("environmentalObservations");
|
|
|
- observation.setProvider("LESP");
|
|
|
- observation.setType("air_sensor");
|
|
|
- observation.setUom("http://qudt.org/vocab/multiSensor/M-PER-SEC");
|
|
|
- telemetry.addObservation(observation);
|
|
|
- }
|
|
|
-
|
|
|
- int counter = 0;
|
|
|
- for (ResourceMeasurement result : responseModel.getResults()) {
|
|
|
-
|
|
|
- Comparator<SensorTelemetry> comparator = comparing(SensorTelemetry::getMeasurement);
|
|
|
- if (order.equals("DESC")) {
|
|
|
- comparator = comparator.reversed();
|
|
|
- }
|
|
|
- result.getMeasurements().sort(comparator);
|
|
|
-
|
|
|
- for (SensorTelemetry resultMeasurement : result.getMeasurements()) {
|
|
|
- counter += resultMeasurement.getObservations().size();
|
|
|
- }
|
|
|
- }
|
|
|
- responseModel.setNumResults(counter);
|
|
|
-
|
|
|
- ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(encode(responseModel));
|
|
|
- });
|
|
|
-
|
|
|
- // Query sensor telemetry interval
|
|
|
- router().get(create("getSensorTelemetry/historic")).handler(ctx -> {
|
|
|
-
|
|
|
- HttpServerRequest req = ctx.request();
|
|
|
- MultiMap params = req.params();
|
|
|
-
|
|
|
- final int limit = 100;
|
|
|
- final String startTime = getRequiredParam(params, "start_time");
|
|
|
- final String endTime = getParam(params, "end_time");
|
|
|
-
|
|
|
- ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(
|
|
|
- new JsonObject().put("message", "not implemented yet").encode());
|
|
|
- });
|
|
|
-
|
|
|
- router().get(create("getObservationsBySensor/historic")).handler(ctx -> {
|
|
|
-
|
|
|
- HttpServerRequest req = ctx.request();
|
|
|
- MultiMap params = req.params();
|
|
|
-
|
|
|
- final int limit = 100;
|
|
|
- final String startTime = getRequiredParam(params, "start_time");
|
|
|
- final String endTime = getParam(params, "end_time");
|
|
|
-
|
|
|
- ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(
|
|
|
- new JsonObject().put("message", "not implemented yet").encode());
|
|
|
- });
|
|
|
-
|
|
|
- // Query region telemetry
|
|
|
- router().get(create("getRegionTelemetry/latest")).handler(ctx -> {
|
|
|
- ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(
|
|
|
- new JsonObject().put("message", "not implemented yet").encode());
|
|
|
- });
|
|
|
-
|
|
|
- // Query region telemetry interval
|
|
|
- router().get(create("getRegionTelemetry/historic")).handler(ctx -> {
|
|
|
- ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(
|
|
|
- new JsonObject().put("message", "not implemented yet").encode());
|
|
|
- });
|
|
|
-
|
|
|
- // Query collar telemetry
|
|
|
- router().get(create("getCollarTelemetry/latest")).handler(ctx -> {
|
|
|
- ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(
|
|
|
- new JsonObject().put("message", "not implemented yet").encode());
|
|
|
- });
|
|
|
-
|
|
|
- router().get(create("getObservationsByCollar/latest")).handler(ctx -> {
|
|
|
- ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(
|
|
|
- new JsonObject().put("message", "not implemented yet").encode());
|
|
|
- });
|
|
|
-
|
|
|
- router().get(create("getObservationsByCollar/historic")).handler(ctx -> {
|
|
|
- ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(
|
|
|
- new JsonObject().put("message", "not implemented yet").encode());
|
|
|
- });
|
|
|
-
|
|
|
- // Query collar telemetry interval
|
|
|
- router().get(create("getCollarTelemetry/historic")).handler(ctx -> {
|
|
|
- ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(
|
|
|
- new JsonObject().put("message", "not implemented yet").encode());
|
|
|
- });
|
|
|
-
|
|
|
- // Schema-measurement
|
|
|
- router().get(create("getMeasurements")).handler(ctx -> {
|
|
|
- ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(
|
|
|
- new JsonObject().put("message", "not implemented yet").encode());
|
|
|
- });
|
|
|
-
|
|
|
- // Registry
|
|
|
- router().get(create("registry/getSensor/:id")).handler(ctx -> {
|
|
|
- // domain is different
|
|
|
-
|
|
|
- String resourceId = ctx.pathParam("id");
|
|
|
-
|
|
|
- MultiSensor multiSensor = new MultiSensor();
|
|
|
- multiSensor.setResourceId(resourceId);
|
|
|
- multiSensor.setResourceType("AFC 8CF95740000008AE");
|
|
|
- multiSensor.setResourceUrn("urn:afc:AS07:enviro:IMA:air_quality:10002222");
|
|
|
- multiSensor.setLatitude(50.0382589);
|
|
|
- multiSensor.setLongitude(14.6112164);
|
|
|
- multiSensor.setAltitude(280.0);
|
|
|
- multiSensor.setPreprocessing(false);
|
|
|
- multiSensor.setPythonScript("");
|
|
|
-
|
|
|
- MultiSensor.SensorSchema sensorSchema = new MultiSensor.SensorSchema();
|
|
|
- sensorSchema.setObservedProperty("air_temperature");
|
|
|
- sensorSchema.setUom("http://qudt.org/vocab/multiSensor/DEG_C");
|
|
|
- sensorSchema.setAccuracy(0.1);
|
|
|
- sensorSchema.setPropertyId(456);
|
|
|
- sensorSchema.setMin_value(-40.0);
|
|
|
- sensorSchema.setMax_value(60.0);
|
|
|
- multiSensor.setObservations(singletonList(sensorSchema));
|
|
|
-
|
|
|
- ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(encode(multiSensor));
|
|
|
- });
|
|
|
-
|
|
|
- router().get(create("registry/getCollar/:id")).handler(ctx -> {
|
|
|
- // domain is different
|
|
|
-
|
|
|
- ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(
|
|
|
- new JsonObject().put("message", "not implemented yet").encode());
|
|
|
- });
|
|
|
- }
|
|
|
-}
|