|
|
@@ -1,10 +1,30 @@
|
|
|
package io.connector.module.senslog1.gateway;
|
|
|
|
|
|
import io.connector.core.AbstractGateway;
|
|
|
+import io.connector.core.http.RequestUriComponent;
|
|
|
+import io.connector.model.sensorthings.*;
|
|
|
import io.connector.module.senslog1.SensLog1SQLClient;
|
|
|
+import io.connector.module.senslog1.entity.Phenomenon;
|
|
|
+import io.connector.module.senslog1.entity.Unit;
|
|
|
+import io.connector.module.senslog1.entity.UnitPosition;
|
|
|
+import org.apache.logging.log4j.LogManager;
|
|
|
+import org.apache.logging.log4j.Logger;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Supplier;
|
|
|
+
|
|
|
+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.String.format;
|
|
|
+import static java.util.Arrays.asList;
|
|
|
+import static java.util.Optional.ofNullable;
|
|
|
|
|
|
public class OGCSensorThingsGateway extends AbstractGateway {
|
|
|
|
|
|
+ private final static Logger logger = LogManager.getLogger(OGCSensorThingsGateway.class);
|
|
|
+
|
|
|
private final SensLog1SQLClient client;
|
|
|
|
|
|
public OGCSensorThingsGateway(String id, SensLog1SQLClient client) {
|
|
|
@@ -14,6 +34,408 @@ public class OGCSensorThingsGateway extends AbstractGateway {
|
|
|
|
|
|
@Override
|
|
|
protected void run() {
|
|
|
+ router().get(create("Things")).handler(ctx -> { // Unit - OVERENO
|
|
|
+ RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
|
|
|
+ List<Unit> units = client.getAllUnits();
|
|
|
+ List<Thing> things = Converter.toThing(units, uriComponent);
|
|
|
+ ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(encode(things));
|
|
|
+ });
|
|
|
+
|
|
|
+ router().get(create("Things(:id)")).handler(ctx -> { // OVERENO
|
|
|
+ RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
|
|
|
+ String id = ctx.pathParam("id");
|
|
|
+ Unit unit = client.getUnit(Long.parseLong(id));
|
|
|
+ Thing thing = Converter.toThing(unit, uriComponent);
|
|
|
+ ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(encode(thing));
|
|
|
+ });
|
|
|
+
|
|
|
+ router().get(create("Datastreams(:id)/Thing")).handler(ctx -> { // OVERENO
|
|
|
+ logger.info("Handling a request: {}.", ctx.request().absoluteURI());
|
|
|
+ RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
|
|
|
+ String id = ctx.pathParam("id"); // resourceUrn + observedProperty
|
|
|
+ String[] idCmp = Converter.disassemblyId(id);
|
|
|
+ String unitId = idCmp[0];
|
|
|
+ ctx.reroute(format("%s/Things(%s)", uriComponent.getGatewayPath(), unitId));
|
|
|
+ });
|
|
|
+
|
|
|
+ router().get(create("HistoricalLocations(:id)/Thing")).handler(ctx -> { // OVERENO
|
|
|
+ // z tabulky unit positions vytahnout radek s id = :id, a z unit_id zjistit jak vec se ma vratit
|
|
|
+ RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
|
|
|
+ String id = ctx.pathParam("id");
|
|
|
+ Unit unit = client.getUnitByLocation(Integer.parseInt(id));
|
|
|
+ Thing ogcThing = Converter.toThing(unit, uriComponent);
|
|
|
+ ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(ogcThing.encode());
|
|
|
+ });
|
|
|
+
|
|
|
+ router().get(create("Datastreams(:id)")).handler(ctx -> { // OVERENO
|
|
|
+ logger.info("Handling a request: {}.", ctx.request().absoluteURI());
|
|
|
+ RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
|
|
|
+ String id = ctx.pathParam("id"); // resource + measurement + time
|
|
|
+ String[] idCmp = Converter.disassemblyId(id);
|
|
|
+ io.connector.module.senslog1.entity.Datastream senslogDataStream = client.getDataStream(Long.parseLong(idCmp[0]), Long.parseLong(idCmp[1]));
|
|
|
+ Datastream ogcDataStream = Converter.toDataStream(senslogDataStream, uriComponent);
|
|
|
+ ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(ogcDataStream.encode());
|
|
|
+ });
|
|
|
+
|
|
|
+ router().get(create("Things(:id)/Datastreams")).handler(ctx -> { // OVERENO
|
|
|
+ logger.info("Handling a request: {}.", ctx.request().absoluteURI());
|
|
|
+ RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
|
|
|
+ String id = ctx.pathParam("id");
|
|
|
+ List<io.connector.module.senslog1.entity.Datastream> senslogDataStreams = client.getDataStreamsForUnit(Long.parseLong(id));
|
|
|
+ List<Datastream> ogcDataStreams = Converter.toDataStreams(senslogDataStreams, uriComponent);
|
|
|
+ ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(encode(ogcDataStreams));
|
|
|
+ });
|
|
|
+
|
|
|
+ router().get(create("Sensors(:id)/Datastreams")).handler(ctx -> { // sensor OEVERENO
|
|
|
+ logger.info("Handling a request: {}.", ctx.request().absoluteURI());
|
|
|
+ RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
|
|
|
+ String id = ctx.pathParam("id");
|
|
|
+ List<io.connector.module.senslog1.entity.Datastream> senslogDataStreams = client.getDataStreamsForSensor(Long.parseLong(id));
|
|
|
+ List<Datastream> ogcDataStreams = Converter.toDataStreams(senslogDataStreams, uriComponent);
|
|
|
+ ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(encode(ogcDataStreams));
|
|
|
+ });
|
|
|
+
|
|
|
+ router().get(create("ObservedProperties(:id)/Datastream")).handler(ctx -> { // observedProperties = phenomenons OVERENO
|
|
|
+ // sensor ma v sobe phenomenon id, podle toho se nsjde sensor a pak se z units_to_sensor najde unit
|
|
|
+ // to je jediny spojeni o kterym vim
|
|
|
+ logger.info("Handling a request: {}.", ctx.request().absoluteURI());
|
|
|
+ RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
|
|
|
+ String id = ctx.pathParam("id");
|
|
|
+ io.connector.module.senslog1.entity.Datastream senslogDataStream = client.getDataStreamForPhenomenon(id);
|
|
|
+ Datastream ogcDataStream = Converter.toDataStream(senslogDataStream, uriComponent);
|
|
|
+ ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(encode(ogcDataStream));
|
|
|
+ });
|
|
|
+
|
|
|
+ router().get(create("Observations(:id)/Datastream")).handler(ctx -> { // Observations OVERENO
|
|
|
+ // observation ma v sobe unitId a sensorId - to tvori datastream
|
|
|
+ // tabulka observations ma v sobe jak unit tak sensor id
|
|
|
+ logger.info("Handling a request: {}.", ctx.request().absoluteURI());
|
|
|
+ RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
|
|
|
+ String id = ctx.pathParam("id");
|
|
|
+ io.connector.module.senslog1.entity.Datastream senslogDataStream = client.getDataStreamForObservation(Integer.parseInt(id));
|
|
|
+ Datastream ogcDataStream = Converter.toDataStream(senslogDataStream, uriComponent);
|
|
|
+ ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(encode(ogcDataStream));
|
|
|
+ });
|
|
|
+
|
|
|
+ router().get(create("Sensors(:id)")).handler(ctx -> { // OVERENO
|
|
|
+ RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
|
|
|
+ String id = ctx.pathParam("id");
|
|
|
+ io.connector.module.senslog1.entity.Sensor senslogSensor = client.getSensor(Long.parseLong(id));
|
|
|
+ io.connector.model.sensorthings.Sensor ogcSensor = Converter.toSensor(senslogSensor, uriComponent);
|
|
|
+ ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(encode(ogcSensor));
|
|
|
+ });
|
|
|
+
|
|
|
+ // unitId(thing):sensorId(sensor)
|
|
|
+ router().get(create("Datastreams(:id)/Sensor")).handler(ctx -> { // OVERENO
|
|
|
+ logger.info("Handling a request: {}.", ctx.request().absoluteURI());
|
|
|
+ RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
|
|
|
+ String id = ctx.pathParam("id"); // resourceUrn + observedProperty
|
|
|
+ String[] idCmp = Converter.disassemblyId(id);
|
|
|
+ String resourceUrn = idCmp[1];
|
|
|
+ ctx.reroute(format("%s/Sensors(%s)", uriComponent.getGatewayPath(), resourceUrn));
|
|
|
+ });
|
|
|
+
|
|
|
+ router().get(create("ObservedProperties(:id)")).handler(ctx -> { // phenomenons OVERENO
|
|
|
+ RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
|
|
|
+ String id = ctx.pathParam("id");
|
|
|
+ Phenomenon phenomenon = client.getPhenomenon(id);
|
|
|
+ ObservedProperty observedProperty = Converter.toObservedProperty(phenomenon, uriComponent);
|
|
|
+ ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(observedProperty.encode());
|
|
|
+ });
|
|
|
+
|
|
|
+ // observedProperty = phenomenons
|
|
|
+ router().get(create("Datastreams(:id)/ObservedProperty")).handler(ctx -> { // OVERENO
|
|
|
+ // id datstreamu obsahuje sensorID kterej ma v sobe phenomenonId
|
|
|
+ logger.info("Handling a request: {}.", ctx.request().absoluteURI());
|
|
|
+ RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
|
|
|
+ String id = ctx.pathParam("id");
|
|
|
+ String[] idCmp = Converter.disassemblyId(id);
|
|
|
+ String sensorId = idCmp[1];
|
|
|
+ Phenomenon phenomenon = client.getPhenomenonBySensor(Long.parseLong(sensorId));
|
|
|
+ ObservedProperty observedProperty = Converter.toObservedProperty(phenomenon, uriComponent);
|
|
|
+ ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(observedProperty.encode());
|
|
|
+ });
|
|
|
+
|
|
|
+ router().get(create("Observations(:id)")).handler(ctx -> { // tabulka observations OVERENO
|
|
|
+ RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
|
|
|
+ String id = ctx.pathParam("id");
|
|
|
+
|
|
|
+ final Supplier<IllegalArgumentException> exception = () -> new IllegalArgumentException(format(
|
|
|
+ "Can not find Observation with @iot.id '%s'.", id));
|
|
|
+
|
|
|
+ Optional<io.connector.module.senslog1.entity.Observation> observationOpt = ofNullable(client.getObservation(Integer.parseInt(id)));
|
|
|
+ io.connector.module.senslog1.entity.Observation senslogObservation = observationOpt.orElseThrow(exception);
|
|
|
+
|
|
|
+ io.connector.model.sensorthings.Observation ogcObservation = Converter.toObservation(senslogObservation, uriComponent);
|
|
|
+ ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(ogcObservation.encode());
|
|
|
+ });
|
|
|
+
|
|
|
+ router().get(create("Datastreams(:id)/Observations")).handler(ctx -> { // OVERENO
|
|
|
+ // observations ma sensor a unit ID, takze najdu observaci podle IDcek co se dostanou v requestu
|
|
|
+ logger.info("Handling a request: {}.", ctx.request().absoluteURI());
|
|
|
+ RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
|
|
|
+ String id = ctx.pathParam("id");
|
|
|
+ String[] idCmp = Converter.disassemblyId(id);
|
|
|
+ String unitId = idCmp[0];
|
|
|
+ String sensorId = idCmp[1];
|
|
|
+ List<io.connector.module.senslog1.entity.Observation> senslogObservations = client.getObservationByUnitAndSensor(Long.parseLong(unitId), Long.parseLong(sensorId));
|
|
|
+ List<io.connector.model.sensorthings.Observation> ogcObservations = Converter.toObservation(senslogObservations, uriComponent);
|
|
|
+ ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(encode(ogcObservations));
|
|
|
+ });
|
|
|
+
|
|
|
+ router().get(create("FeaturesOfInterest(:id)")).handler(ctx -> {
|
|
|
+ // TODO - SKIP
|
|
|
+ });
|
|
|
+
|
|
|
+ router().get(create("Locations(:id)")).handler(ctx -> { // lokace pro dany id OVERENO
|
|
|
+ RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
|
|
|
+ String id = ctx.pathParam("id");
|
|
|
+ UnitPosition unitPosition = client.getUnitPosition(Integer.parseInt(id));
|
|
|
+ Location location = Converter.toLocation(unitPosition, uriComponent);
|
|
|
+ ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(location.encode());
|
|
|
+ });
|
|
|
+
|
|
|
+ router().get(create("Things(:id)/Locations")).handler(ctx -> { // posledni lokaci pro things s :id OVERENO
|
|
|
+ RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
|
|
|
+ String id = ctx.pathParam("id");
|
|
|
+ List<UnitPosition> unitPositions = client.getLastPositionsForUnit(Long.parseLong(id));
|
|
|
+ List<Location> locations = Converter.toLocation(unitPositions, uriComponent);
|
|
|
+ ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(encode(locations));
|
|
|
+ });
|
|
|
+
|
|
|
+ router().get(create("HistoricalLocations(:id)/Locations")).handler(ctx -> { // reroutovani na Locations(:id) OVERENO
|
|
|
+ RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
|
|
|
+ String id = ctx.pathParam("id");
|
|
|
+ ctx.reroute(format("%s/Locations(%s)", uriComponent.getGatewayPath(), id));
|
|
|
+ });
|
|
|
+
|
|
|
+ router().get(create("HistoricalLocations(:id)")).handler(ctx -> { // reroutovani na Locations(:id) OVERENO
|
|
|
+ RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
|
|
|
+ String id = ctx.pathParam("id");
|
|
|
+ UnitPosition unitPosition = client.getUnitPosition(Integer.parseInt(id));
|
|
|
+ HistoricalLocation historicalLocation = Converter.toHistoricalLocation(unitPosition, uriComponent);
|
|
|
+ ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(historicalLocation.encode());
|
|
|
+ });
|
|
|
+
|
|
|
+ router().get(create("Things(:id)/HistoricalLocations")).handler(ctx -> { // vratit posledni location pro unit s :id OVERENO
|
|
|
+ RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
|
|
|
+ String id = ctx.pathParam("id");
|
|
|
+ List<UnitPosition> unitPositions = client.getLastPositionsForUnit(Long.parseLong(id));
|
|
|
+ List<HistoricalLocation> historicalLocations = Converter.toHistoricalLocation(unitPositions, uriComponent);
|
|
|
+ ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(encode(historicalLocations));
|
|
|
+ });
|
|
|
+
|
|
|
+ router().get(create("Locations(:id)/HistoricalLocations")).handler(ctx -> { // vratit lokaci ktera je pred lokaci s id = :id OVERENO
|
|
|
+ // vratit lokaci s id - 1
|
|
|
+ // najit lokaci s id = :id, zjistit jaky patri veci, a najit lokaci pro tuhle veci ktera je pred lokaci s id = :id
|
|
|
+ RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
|
|
|
+ String id = ctx.pathParam("id");
|
|
|
+ UnitPosition unitPosition = client.getSecondLatestPosition(Integer.parseInt(id));
|
|
|
+ HistoricalLocation historicalLocation = Converter.toHistoricalLocation(unitPosition, uriComponent); // TODO tady se v afc vraci list
|
|
|
+ ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(historicalLocation.encode());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private static class Converter {
|
|
|
+
|
|
|
+ private static final String DELIMITER = ":";
|
|
|
+
|
|
|
+ static String assemblyId(String... parts) {
|
|
|
+ return String.join(DELIMITER, parts);
|
|
|
+ }
|
|
|
+
|
|
|
+ static String[] disassemblyId(String id) {
|
|
|
+ return id.split(DELIMITER);
|
|
|
+ }
|
|
|
+
|
|
|
+ static List<Datastream> toDataStreams(List<io.connector.module.senslog1.entity.Datastream> senslogDatastreams,
|
|
|
+ RequestUriComponent uriComponent) {
|
|
|
+ logger.info("Mapuju datastreamy");
|
|
|
+ List<Datastream> ogcDataStreams = new ArrayList<>(senslogDatastreams.size());
|
|
|
+ for (io.connector.module.senslog1.entity.Datastream dataStream : senslogDatastreams) {
|
|
|
+ ogcDataStreams.add(toDataStream(dataStream, uriComponent));
|
|
|
+ }
|
|
|
+ return ogcDataStreams;
|
|
|
+ }
|
|
|
+
|
|
|
+ static Datastream toDataStream(io.connector.module.senslog1.entity.Datastream senslogDatastream,
|
|
|
+ RequestUriComponent uriComponent) {
|
|
|
+ logger.info("Mapuju datastream");
|
|
|
+ Unit unit = senslogDatastream.getUnit();
|
|
|
+ io.connector.module.senslog1.entity.Sensor sensor = senslogDatastream.getSensor();
|
|
|
+ Phenomenon phenomenon = senslogDatastream.getPhenomenon();
|
|
|
+
|
|
|
+ String dataStreamId = assemblyId(String.valueOf(unit.getId()), String.valueOf(sensor.getId()));
|
|
|
+ String absoluteUrl = uriComponent.getGatewayUri();
|
|
|
+
|
|
|
+ Datastream datastream = new Datastream();
|
|
|
+ datastream.setId(dataStreamId);
|
|
|
+ datastream.setSelfLink(format("%s/Datastreams(%s)", absoluteUrl, dataStreamId));
|
|
|
+ datastream.setThingNavigationLink(format("%s/Datastreams(%s)/Thing", absoluteUrl, dataStreamId));
|
|
|
+ datastream.setSensorNavigationLink(format("%s/Datastreams(%s)/Sensor", absoluteUrl, dataStreamId));
|
|
|
+ datastream.setObservedPropertyNavigationLink(format("%s/Datastreams(%s)/ObservedProperty", absoluteUrl, dataStreamId));
|
|
|
+ datastream.setObservationsNavigationLink(format("%s/Datastreams(%s)/Observations", absoluteUrl, dataStreamId));
|
|
|
+ datastream.setName(sensor.getName());
|
|
|
+ datastream.setDescription(unit.getDescription());
|
|
|
+
|
|
|
+ Datastream.UnitOfMeasurement uom = new Datastream.UnitOfMeasurement();
|
|
|
+ uom.setName(phenomenon.getName());
|
|
|
+ uom.setSymbol("");
|
|
|
+ uom.setDefinition(phenomenon.getUnit());
|
|
|
+ datastream.setUnitOfMeasurement(uom);
|
|
|
+
|
|
|
+ datastream.setObservationType("http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement");
|
|
|
+
|
|
|
+ UnitPosition unitPosition = senslogDatastream.getUnitPosition();
|
|
|
+ Geometry geometry = new Geometry();
|
|
|
+ geometry.setType("Point");
|
|
|
+ geometry.setCoordinates(asList(unitPosition.getLongitude(), unitPosition.getLatitude(), unitPosition.getAltitude()));
|
|
|
+ datastream.setObservedArea(geometry);
|
|
|
+
|
|
|
+// String startDate = "<none>"; TODO
|
|
|
+// String endDate = telemetry == null || telemetry.getObservations().isEmpty() ? "<none>" : telemetry.getObservations().get(0).getTime();
|
|
|
+// String time = startDate + "/" + endDate;
|
|
|
+// datastream.setPhenomenonTime(time);
|
|
|
+// datastream.setResultTime(time);
|
|
|
+
|
|
|
+ logger.info("konec mapovani datastreamu");
|
|
|
+ return datastream;
|
|
|
+ }
|
|
|
+
|
|
|
+ static Thing toThing(Unit unit, RequestUriComponent uriComponent) {
|
|
|
+ Objects.requireNonNull(unit);
|
|
|
+ Objects.requireNonNull(uriComponent);
|
|
|
+
|
|
|
+ Thing thing = new Thing();
|
|
|
+ String thingId = String.valueOf(unit.getId());
|
|
|
+ thing.setId(thingId);
|
|
|
+ thing.setSelfLink(format("%s/Things(%s)", uriComponent.getGatewayUri(), thingId));
|
|
|
+ thing.setLocationsNavigationLink(format("Things(%s)/Locations", thingId));
|
|
|
+ thing.setDataStreamNavigationLink(format("Things(%s)/Datastreams", thingId));
|
|
|
+ thing.setHistoricalLocationsNavigationLink(format("Things(%s)/HistoricalLocations", thingId));
|
|
|
+// thing.setName(); // TODO - co sem hodit unitTypeId?
|
|
|
+ thing.setDescription(unit.getDescription());
|
|
|
+ thing.setProperties(null);
|
|
|
+
|
|
|
+ return thing;
|
|
|
+ }
|
|
|
+
|
|
|
+ static List<Thing> toThing(List<Unit> units, RequestUriComponent uriComponent) {
|
|
|
+ List<Thing> things = new ArrayList<>(units.size());
|
|
|
+ for (Unit unit : units) {
|
|
|
+ things.add(toThing(unit, uriComponent));
|
|
|
+ }
|
|
|
+ return things;
|
|
|
+ }
|
|
|
+
|
|
|
+ static List<Location> toLocation(List<UnitPosition> unitPositions, RequestUriComponent uriComponent) {
|
|
|
+ List<Location> locations = new ArrayList<>(unitPositions.size());
|
|
|
+ for (UnitPosition unitPosition : unitPositions) {
|
|
|
+ locations.add(toLocation(unitPosition, uriComponent));
|
|
|
+ }
|
|
|
+ return locations;
|
|
|
+ }
|
|
|
+
|
|
|
+ static Location toLocation(UnitPosition unitPosition, RequestUriComponent uriComponent) {
|
|
|
+ Location location = new Location();
|
|
|
+ String locationId = String.valueOf(unitPosition.getGid());
|
|
|
+ String absoluteUrl = uriComponent.getGatewayUri();
|
|
|
+ location.setId(locationId);
|
|
|
+ location.setSelfLink(format("%s/Locations(%s)", absoluteUrl, locationId));
|
|
|
+ location.setHistoricalLocationsNavigationLink(format("%s/Locations(%s)/HistoricalLocations", absoluteUrl, locationId));
|
|
|
+// location.setName(); // TODO
|
|
|
+// location.setDescription(); // TODO
|
|
|
+ location.setEncodingType("application/vnd.geo+json");
|
|
|
+
|
|
|
+ Location.Info info = new Location.Info();
|
|
|
+ info.setType("Feature");
|
|
|
+ location.setLocation(info);
|
|
|
+
|
|
|
+ Geometry geometry = new Geometry();
|
|
|
+ geometry.setType("Point");
|
|
|
+ geometry.setCoordinates(Arrays.asList(unitPosition.getLongitude(), unitPosition.getLatitude(), unitPosition.getAltitude()));
|
|
|
+ info.setGeometry(geometry);
|
|
|
+
|
|
|
+ return location;
|
|
|
+ }
|
|
|
+
|
|
|
+ static List<HistoricalLocation> toHistoricalLocation(List<UnitPosition> unitPositions, RequestUriComponent uriComponent) {
|
|
|
+ List<HistoricalLocation> historicalLocations = new ArrayList<>(unitPositions.size());
|
|
|
+ for (UnitPosition unitPosition : unitPositions) {
|
|
|
+ historicalLocations.add(toHistoricalLocation(unitPosition, uriComponent));
|
|
|
+ }
|
|
|
+ return historicalLocations;
|
|
|
+ }
|
|
|
+
|
|
|
+ static HistoricalLocation toHistoricalLocation(UnitPosition unitPosition, RequestUriComponent uriComponent) {
|
|
|
+ HistoricalLocation historicalLocation = new HistoricalLocation();
|
|
|
+
|
|
|
+ String locationId = String.valueOf(unitPosition.getUnitId());
|
|
|
+ String absoluteUrl = uriComponent.getGatewayUri();
|
|
|
+ historicalLocation.setId(locationId);
|
|
|
+ historicalLocation.setSelfLink(format("%s/HistoricalLocations(%s)", absoluteUrl, locationId));
|
|
|
+ historicalLocation.setLocationsNavigationLink(format("%s/HistoricalLocations(%s)/Locations", absoluteUrl, locationId));
|
|
|
+ historicalLocation.setThingNavigationLink(format("%s/HistoricalLocations(%s)/Thing", absoluteUrl, locationId));
|
|
|
+ historicalLocation.setTime(unitPosition.getFirstTimeStamp().toString());
|
|
|
+
|
|
|
+ return historicalLocation;
|
|
|
+ }
|
|
|
+
|
|
|
+ static ObservedProperty toObservedProperty(Phenomenon phenomenon, RequestUriComponent uriComponent) {
|
|
|
+ ObservedProperty observedProperty = new ObservedProperty();
|
|
|
+ String observedPropertyId = phenomenon.getId();
|
|
|
+ String absoluteUrl = uriComponent.getGatewayUri();
|
|
|
+ observedProperty.setId(observedPropertyId);
|
|
|
+ observedProperty.setSelfLink(format("%s/ObservedProperties(%s)", absoluteUrl, observedPropertyId));
|
|
|
+ observedProperty.setDataStreamNavigationLink(format("%s/ObservedProperties(%s)/Datastream", absoluteUrl, observedPropertyId));
|
|
|
+ observedProperty.setName(phenomenon.getName());
|
|
|
+// observedProperty.setDescription(); // TODO
|
|
|
+// observedProperty.setDefinition(); // TODO
|
|
|
+
|
|
|
+ return observedProperty;
|
|
|
+ }
|
|
|
+
|
|
|
+ static List<io.connector.model.sensorthings.Observation> toObservation(List<io.connector.module.senslog1.entity.Observation> senslogObservations,
|
|
|
+ RequestUriComponent uriComponent) {
|
|
|
+ List<io.connector.model.sensorthings.Observation> observations = new ArrayList<>(senslogObservations.size());
|
|
|
+ for (io.connector.module.senslog1.entity.Observation senslogObservation : senslogObservations) {
|
|
|
+ observations.add(toObservation(senslogObservation, uriComponent));
|
|
|
+ }
|
|
|
+ return observations;
|
|
|
+ }
|
|
|
+
|
|
|
+ static io.connector.model.sensorthings.Observation toObservation(io.connector.module.senslog1.entity.Observation senslogObservation, RequestUriComponent uriComponent) {
|
|
|
+ Observation observation = new Observation();
|
|
|
+ String observationId = String.valueOf(senslogObservation.getId());
|
|
|
+ String absoluteUrl = uriComponent.getGatewayUri();
|
|
|
+ observation.setId(observationId);
|
|
|
+ observation.setSelfLink(format("%s/Observations(%s)", absoluteUrl, observationId));
|
|
|
+ // TODO - co s feature of interest?
|
|
|
+ // observation.setFeatureOfInterestNavigationLink(format("Observations(%s)/FeatureOfInterest", observationId));
|
|
|
+// observation.setFeatureOfInterestNavigationLink("https://storage07-afarcloud.qa.pdmfc.com/storage/rest/registry/getAllObservationTypes");
|
|
|
+ observation.setDataStreamNavigationLink(format("%s/Observations(%s)/Datastream", absoluteUrl, observationId));
|
|
|
+ observation.setPhenomenonTime(senslogObservation.getTimestamp().toString());
|
|
|
+ observation.setResultTime(senslogObservation.getTimeReceived().toString());
|
|
|
+ observation.setResult(senslogObservation.getObservedValue());
|
|
|
+ return observation;
|
|
|
+ }
|
|
|
+
|
|
|
+ static Sensor toSensor(io.connector.module.senslog1.entity.Sensor senslogSensor, RequestUriComponent uriComponent) {
|
|
|
+ String afcDomain = "https://storage07-afarcloud.qa.pdmfc.com/storage/rest"; // TODO - naco zmenit tohle
|
|
|
+
|
|
|
+ Sensor sensor = new Sensor();
|
|
|
+ String sensorId = String.valueOf(senslogSensor.getId());
|
|
|
+ String absoluteUrl = uriComponent.getGatewayUri();
|
|
|
+ sensor.setId(sensorId);
|
|
|
+ sensor.setSelfLink(format("%s/Sensors(%s)", absoluteUrl, sensorId));
|
|
|
+ sensor.setDataStreamNavigationLink(format("%s/Sensors(%s)/Datastreams", absoluteUrl, sensorId));
|
|
|
+ sensor.setName(senslogSensor.getName());
|
|
|
+ sensor.setDescription(senslogSensor.getType());
|
|
|
+ sensor.setEncodingType("application/json");
|
|
|
+ sensor.setMetadata(format("%s/registry/getSensor/%s", afcDomain, sensorId));
|
|
|
+
|
|
|
+ return sensor;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
}
|