浏览代码

Refactor code

Lukas Cerny 5 年之前
父节点
当前提交
f0914d9b8d

+ 1 - 0
config/ogc2afc.yaml → config/config.yaml

@@ -19,6 +19,7 @@ services:
     feederServiceHost:
       domain: ""
       path: ""
+
   AFC:
       retrievalApi:
         domain: "http://torcos.etsist.upm.es:9219/"

+ 2 - 1
connector-module-senslog1/src/main/java/io/connector/module/senslog1/SensLog1ModuleProvider.java

@@ -4,6 +4,7 @@ import io.connector.core.http.HttpClient;
 import io.connector.core.ModuleDescriptor;
 import io.connector.core.AbstractModule;
 import io.connector.core.ModuleProvider;
+import io.connector.module.senslog1.jdbi.JDBI;
 
 public final class SensLog1ModuleProvider implements ModuleProvider {
 
@@ -13,7 +14,7 @@ public final class SensLog1ModuleProvider implements ModuleProvider {
         SensLog1Config config = new SensLog1Config(descriptor.getServiceConfig());
 
         SensLog1HttpClient httpClient = new SensLog1HttpClient(config, HttpClient.newHttpClient());
-        SensLog1SQLClient sqlClient = new SensLog1SQLClient();
+        SensLog1SQLClient sqlClient = new SensLog1SQLClient(JDBI.get());
 
         SensLog1Module module = new SensLog1Module("SensLogV1", descriptor, httpClient, sqlClient);
 

+ 121 - 70
connector-module-senslog1/src/main/java/io/connector/module/senslog1/SensLog1SQLClient.java

@@ -1,20 +1,25 @@
 package io.connector.module.senslog1;
 
 import io.connector.module.senslog1.entity.*;
-import io.connector.module.senslog1.jdbi.JDBI;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
+import org.jdbi.v3.core.Jdbi;
 import org.jdbi.v3.core.mapper.RowMapper;
 import org.jdbi.v3.core.statement.StatementContext;
 
 import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.util.List;
 
 public class SensLog1SQLClient {
 
-    static class UnitMapper implements RowMapper<Unit> {
+    private final Jdbi jdbi;
+
+    public SensLog1SQLClient(Jdbi jdbi) {
+        this.jdbi = jdbi;
+    }
+
+    private static class UnitMapper implements RowMapper<Unit> {
 
         @Override
         public Unit map(ResultSet rs, StatementContext ctx) throws SQLException {
@@ -29,7 +34,7 @@ public class SensLog1SQLClient {
         }
     }
 
-    static class SensorMapper implements RowMapper<Sensor> {
+    private static class SensorMapper implements RowMapper<Sensor> {
 
         @Override
         public Sensor map(ResultSet rs, StatementContext ctx) throws SQLException {
@@ -43,7 +48,7 @@ public class SensLog1SQLClient {
         }
     }
 
-    static class ObservationMapper implements RowMapper<Observation> {
+    private static class ObservationMapper implements RowMapper<Observation> {
 
         @Override
         public Observation map(ResultSet rs, StatementContext ctx) throws SQLException {
@@ -60,7 +65,7 @@ public class SensLog1SQLClient {
         }
     }
 
-    static class PhenomenonMapper implements RowMapper<Phenomenon> {
+    private static class PhenomenonMapper implements RowMapper<Phenomenon> {
 
         @Override
         public Phenomenon map(ResultSet rs, StatementContext ctx) throws SQLException {
@@ -73,7 +78,7 @@ public class SensLog1SQLClient {
         }
     }
 
-    static class UnitPositionMapper implements RowMapper<UnitPosition> {
+    private static class UnitPositionMapper implements RowMapper<UnitPosition> {
 
         @Override
         public UnitPosition map(ResultSet rs, StatementContext ctx) throws SQLException {
@@ -99,7 +104,7 @@ public class SensLog1SQLClient {
         }
     }
 
-    static class DatastreamMapper implements RowMapper<Datastream> {
+    private static class DatastreamMapper implements RowMapper<Datastream> {
 
         @Override
         public Datastream map(ResultSet rs, StatementContext ctx) throws SQLException {
@@ -149,38 +154,57 @@ public class SensLog1SQLClient {
     }
 
     public List<Unit> getAllUnits() {
-        return JDBI.get().withHandle(handle -> handle.createQuery("SELECT * FROM units").map(new UnitMapper()).list());
+        return jdbi.withHandle(h -> h.createQuery(
+                "SELECT * FROM units"
+            )
+                .map(new UnitMapper()).list()
+        );
     }
 
     public Unit getUnit(long id) {
-        return JDBI.get().withHandle(handle -> handle.createQuery("SELECT * FROM units WHERE unit_id = :id").
-                bind("id", id).
-                map(new UnitMapper()).findOne()).orElse(null);
+        return jdbi.withHandle(h -> h.createQuery(
+                "SELECT * FROM units WHERE unit_id = :id"
+            )
+                .bind("id", id)
+                .map(new UnitMapper()).findOne()
+        ).orElse(null);
     }
 
     public Sensor getSensor(long id) {
-        return JDBI.get().withHandle(handle -> handle.createQuery("SELECT * FROM sensors WHERE sensor_id = :id").
-                bind("id", id).
-                map(new SensorMapper()).findOne()).orElse(null);
+        return jdbi.withHandle(h -> h.createQuery(
+                "SELECT * FROM sensors WHERE sensor_id = :id"
+            )
+                .bind("id", id)
+                .map(new SensorMapper()).findOne()
+        ).orElse(null);
     }
 
     public Observation getObservation(int id) {
-        return JDBI.get().withHandle(handle -> handle.createQuery("SELECT * FROM observations WHERE observation_id = :id").
-                bind("id", id).
-                map(new ObservationMapper()).findOne()).orElse(null);
+        return jdbi.withHandle(h -> h.createQuery(
+                "SELECT * FROM observations WHERE observation_id = :id"
+        )
+                .bind("id", id)
+                .map(new ObservationMapper()).findOne()
+        ).orElse(null);
     }
 
     public UnitPosition getUnitPosition(int id) {
-        return JDBI.get().withHandle(handle -> handle.createQuery("SELECT up.*, ST_AsText(the_geom) AS coords FROM units_positions AS up WHERE up.gid = :gid").
-                bind("gid", id).
-                map(new UnitPositionMapper()).findOne()).orElse(null);
+        return jdbi.withHandle(h -> h.createQuery(
+                "SELECT up.*, ST_AsText(the_geom) AS coords FROM units_positions AS up WHERE up.gid = :gid"
+        )
+                .bind("gid", id)
+                .map(new UnitPositionMapper()).findOne()
+        ).orElse(null);
     }
 
     public List<UnitPosition> getLastPositionsForUnit(long unitId) {
-        return JDBI.get().withHandle(handle ->
-                handle.createQuery("SELECT up.*, ST_AsText(the_geom) AS coords FROM units_positions AS up WHERE up.unit_id = :unitId ORDER BY up.time_received ASC LIMIT 1").
-                        bind("unitId", unitId).
-                        map(new UnitPositionMapper()).list());
+        return jdbi.withHandle(h -> h.createQuery(
+                "SELECT up.*, ST_AsText(the_geom) AS coords FROM units_positions AS up " +
+                        "WHERE up.unit_id = :unitId ORDER BY up.time_received ASC LIMIT 1"
+        )
+                .bind("unitId", unitId)
+                .map(new UnitPositionMapper()).list()
+        );
     }
 
     public UnitPosition getSecondLatestPosition(int positionId) {
@@ -189,67 +213,85 @@ public class SensLog1SQLClient {
         // ON up.unit_id = up_2.unit_id
         // WHERE up.gid = :positionId ORDER BY up.time_received ASC LIMIT 2 OFFSET 1
 
-        return JDBI.get().withHandle(handle ->
-                handle.createQuery(
-                        "SELECT up.*, ST_AsText(up.the_geom) AS coords FROM units_positions AS up INNER JOIN units_positions AS up_2 " +
-                                "ON up.unit_id = up_2.unit_id " +
-                                "WHERE up.gid = :positionId ORDER BY up.time_received ASC LIMIT 2 OFFSET 1").
-                        bind("positionId", positionId).
-                        map(new UnitPositionMapper()).findOne()).orElse(null);
+        return jdbi.withHandle(h -> h.createQuery(
+                        "SELECT up.*, ST_AsText(up.the_geom) AS coords FROM units_positions AS up " +
+                                "INNER JOIN units_positions AS up_2 ON up.unit_id = up_2.unit_id " +
+                                "WHERE up.gid = :positionId " +
+                                "ORDER BY up.time_received ASC LIMIT 2 OFFSET 1"
+        )
+                .bind("positionId", positionId)
+                .map(new UnitPositionMapper()).findOne()
+        ).orElse(null);
     }
 
     public Unit getUnitByLocation(int locationId) {
         // SELECT DISTINCT * FROM units AS u INNER JOIN units_positions AS up ON u.unit_id = up.unit_id WHERE up.gid = :locationId
-        return JDBI.get().withHandle(handle -> handle.createQuery(
-                "SELECT DISTINCT * FROM units AS u INNER JOIN units_positions AS up ON u.unit_id = up.unit_id WHERE up.gid = :locationId").
-                bind("locationId", locationId).
-                map(new UnitMapper()).findOne()).orElse(null);
+        return jdbi.withHandle(h -> h.createQuery(
+                "SELECT DISTINCT * FROM units AS u " +
+                        "INNER JOIN units_positions AS up ON u.unit_id = up.unit_id " +
+                        "WHERE up.gid = :locationId"
+        )
+                .bind("locationId", locationId)
+                .map(new UnitMapper()).findOne()
+        ).orElse(null);
     }
 
     public Phenomenon getPhenomenon(String id) {
-        return JDBI.get().withHandle(handle -> handle.createQuery("SELECT * FROM phenomenons AS p WHERE p.phenomenon_id = :id").
-                bind("id", id).
-                map(new PhenomenonMapper()).findOne()).orElse(null);
+        return jdbi.withHandle(h -> h.createQuery(
+                "SELECT * FROM phenomenons AS p WHERE p.phenomenon_id = :id"
+        )
+                .bind("id", id)
+                .map(new PhenomenonMapper()).findOne()
+        ).orElse(null);
     }
 
     private static final Logger logger = LogManager.getLogger(SensLog1SQLClient.class);
 
     public Datastream getDataStream(long unitId, long sensorId) {
         // SELECT u.*, s.*, p.* FROM units AS u, sensors AS s, phenomenons AS p WHERE p.id = s.phenomenon_id;
-        return JDBI.get().withHandle(handle -> handle.createQuery(
+        return jdbi.withHandle(h -> h.createQuery(
                 "SELECT u.*, s.*, p.*, up.*, ST_AsText(up.the_geom) AS coords FROM units AS u, sensors AS s, phenomenons AS p, units_positions AS up " +
                         "WHERE u.unit_id = :unitId " +
                         "AND s.sensor_id = :sensorId " +
                         "AND p.phenomenon_id = s.phenomenon_id " +
                         "AND up.unit_id = :unitId " +
-                        "ORDER BY up.time_received ASC LIMIT 1").
-                bind("unitId", unitId).
-                bind("sensorId", sensorId).
-                map(new DatastreamMapper()).findOne()).orElse(null);
+                        "ORDER BY up.time_received ASC LIMIT 1"
+        )
+                .bind("unitId", unitId)
+                .bind("sensorId", sensorId)
+                .map(new DatastreamMapper()).findOne()
+        ).orElse(null);
     }
 
     public List<Datastream> getDataStreamsForUnit(long unitId) {
         // SELECT * FROM sensors INNER JOIN units_to_sensors uts ON uts.unit_id = :unitId;
-        return JDBI.get().withHandle(handle -> handle.createQuery(
+        return jdbi.withHandle(h -> h.createQuery(
                 "SELECT u.*, s.*, p.*, up.*, ST_AsText(up.the_geom) AS coords FROM units AS u, sensors AS s, phenomenons AS p, units_positions AS up " +
                         "INNER JOIN units_to_sensors AS uts ON uts.unit_id = :unitId " +
                         "WHERE s.sensor_id = uts.sensor_id " +
                         "AND p.phenomenon_id = s.phenomenon_id " +
-                        "AND up.gid = (SELECT uup.gid FROM units_positions AS uup WHERE uup.unit_id = :unitId ORDER BY uup.time_received ASC LIMIT 1)").
-                bind("unitId", unitId).
-                map(new DatastreamMapper()).list());
+                        "AND up.gid = (SELECT uup.gid FROM units_positions AS uup " +
+                        "WHERE uup.unit_id = :unitId " +
+                        "ORDER BY uup.time_received ASC LIMIT 1)"
+        )
+                .bind("unitId", unitId)
+                .map(new DatastreamMapper()).list()
+        );
     }
 
     public List<Datastream> getDataStreamsForSensor(long sensorId) {
         // SELECT * FROM sensors INNER JOIN units_to_sensors uts ON uts.sensor_id = :sensorId;
-        return JDBI.get().withHandle(handle -> handle.createQuery(
+        return jdbi.withHandle(h -> h.createQuery(
                 "SELECT u.*, s.*, p.*, up.*, ST_AsText(up.the_geom) AS coords FROM units AS u, sensors AS s, phenomenons AS p, units_positions AS up " +
                         "INNER JOIN units_to_sensors AS uts ON uts.sensor_id = :sensorId " +
                         "WHERE u.unit_id = uts.unit_id " +
                         "AND p.phenomenon_id = s.phenomenon_id " +
-                        "AND up.gid = (SELECT uup.gid FROM units_positions AS uup WHERE uup.unit_id = uts.unit_id ORDER BY uup.time_received ASC LIMIT 1)").
-                bind("sensorId", sensorId).
-                map(new DatastreamMapper()).list());
+                        "AND up.gid = (SELECT uup.gid FROM units_positions AS uup " +
+                            "WHERE uup.unit_id = uts.unit_id ORDER BY uup.time_received ASC LIMIT 1)"
+        )
+                .bind("sensorId", sensorId)
+                .map(new DatastreamMapper()).list()
+        );
     }
 
     public Datastream getDataStreamForPhenomenon(String phenomenonId) {
@@ -258,14 +300,18 @@ public class SensLog1SQLClient {
         // INNER JOIN sensors AS s ON s.sensor_id = uts.sensor_id
         // INNER JOIN phenomenons AS p ON p.phenomenon_id = '1';
 
-        return JDBI.get().withHandle(handle -> handle.createQuery(
+        return jdbi.withHandle(h -> h.createQuery(
                 "SELECT u.*, s.*, p.*, up.*, ST_AsText(up.the_geom) AS coords FROM units AS u " +
                         "INNER JOIN units_to_sensors AS uts ON uts.sensor_id = u.unit_id " +
                         "INNER JOIN sensors AS s ON s.sensor_id = uts.sensor_id " +
                         "INNER JOIN phenomenons AS p ON p.phenomenon_id = :phenomenonId " +
-                        "INNER JOIN units_positions AS up ON up.gid = (SELECT uup.gid FROM units_positions AS uup WHERE uup.unit_id = uts.unit_id ORDER BY uup.time_received ASC LIMIT 1)").
-                bind("phenomenonId", phenomenonId).
-                map(new DatastreamMapper()).findOne()).orElse(null);
+                        "INNER JOIN units_positions AS up ON up.gid = " +
+                            "(SELECT uup.gid FROM units_positions AS uup " +
+                                "WHERE uup.unit_id = uts.unit_id ORDER BY uup.time_received ASC LIMIT 1)"
+        )
+                .bind("phenomenonId", phenomenonId)
+                .map(new DatastreamMapper()).findOne()
+        ).orElse(null);
 
 //        return JDBI.get().withHandle(handle -> handle.createQuery(
 //                "SELECT u.*, s.*, p.* FROM units AS u, sensors AS s, phenomenons AS p " +
@@ -280,32 +326,37 @@ public class SensLog1SQLClient {
         // SELECT u.*, s.*, p.* FROM units AS u, sensors AS s, phenomenons AS p
         // CROSS JOIN observations AS o
         // WHERE o.observation_id = :observationId AND o.unit_id = u.unit_id AND o.sensor_id = o.sensor_id
-        return JDBI.get().withHandle(handle -> handle.createQuery(
+        return jdbi.withHandle(h -> h.createQuery(
                 "SELECT u.*, s.*, p.*, up.*, ST_AsText(up.the_geom) AS coords FROM units AS u, sensors AS s, phenomenons AS p, units_positions AS up " +
                         "CROSS JOIN observations AS o " +
                         "WHERE o.observation_id = :observationId " +
                         "AND o.unit_id = u.unit_id " +
                         "AND o.sensor_id = o.sensor_id " +
-                        "AND up.gid = (SELECT uup.gid FROM units_positions AS uup WHERE uup.unit_id = o.unit_id ORDER BY uup.time_received ASC LIMIT 1)").
-                bind("observationId", observationId).
-                map(new DatastreamMapper()).findOne()).orElse(null);
+                        "AND up.gid = " +
+                                "(SELECT uup.gid FROM units_positions AS uup " +
+                                    "WHERE uup.unit_id = o.unit_id ORDER BY uup.time_received ASC LIMIT 1)"
+        )
+                .bind("observationId", observationId)
+                .map(new DatastreamMapper()).findOne()
+        ).orElse(null);
     }
 
     public Phenomenon getPhenomenonBySensor(long sensorId) {
         // SELECT * FROM phenomenons AS p INNER JOIN sensors AS s ON p.phenomenon_id = s.phenomenon_id WHERE s.sensor_id = :sensorId
-        return JDBI.get().withHandle(handle -> handle.createQuery(
+        return jdbi.withHandle(h -> h.createQuery(
                 "SELECT * FROM phenomenons AS p INNER JOIN sensors AS s " +
-                        "ON p.phenomenon_id = s.phenomenon_id WHERE s.sensor_id = :sensorId").
-                bind("sensorId", sensorId).
-                map(new PhenomenonMapper()).findOne()).orElse(null);
+                        "ON p.phenomenon_id = s.phenomenon_id WHERE s.sensor_id = :sensorId")
+                .bind("sensorId", sensorId)
+                .map(new PhenomenonMapper()).findOne()
+        ).orElse(null);
     }
 
     public List<Observation> getObservationByUnitAndSensor(long unitId, long sensorId) {
-        return JDBI.get().withHandle(handle -> handle.createQuery(
-                "SELECT * FROM observations AS o WHERE o.unit_id = :unitId AND o.sensor_id = :sensorId").
-                bind("unitId", unitId).
-                bind("sensorId", sensorId).
-                map(new ObservationMapper()).list());
+        return jdbi.withHandle(h -> h.createQuery(
+                "SELECT * FROM observations AS o WHERE o.unit_id = :unitId AND o.sensor_id = :sensorId")
+                .bind("unitId", unitId)
+                .bind("sensorId", sensorId)
+                .map(new ObservationMapper()).list()
+        );
     }
-
 }

+ 23 - 21
connector-module-senslog1/src/main/java/io/connector/module/senslog1/gateway/OGCSensorThingsGateway.java

@@ -17,6 +17,8 @@ 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.Integer.parseInt;
+import static java.lang.Long.parseLong;
 import static java.lang.String.format;
 import static java.util.Arrays.asList;
 import static java.util.Optional.ofNullable;
@@ -44,7 +46,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
         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));
+            Unit unit = client.getUnit(parseLong(id));
             Thing thing = Converter.toThing(unit, uriComponent);
             ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(encode(thing));
         });
@@ -62,7 +64,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
             // 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));
+            Unit unit = client.getUnitByLocation(parseInt(id));
             Thing ogcThing = Converter.toThing(unit, uriComponent);
             ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(ogcThing.encode());
         });
@@ -72,7 +74,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
             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]));
+            io.connector.module.senslog1.entity.Datastream senslogDataStream = client.getDataStream(parseLong(idCmp[0]), parseLong(idCmp[1]));
             Datastream ogcDataStream = Converter.toDataStream(senslogDataStream, uriComponent);
             ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(ogcDataStream.encode());
         });
@@ -81,7 +83,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
             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<io.connector.module.senslog1.entity.Datastream> senslogDataStreams = client.getDataStreamsForUnit(parseLong(id));
             List<Datastream> ogcDataStreams = Converter.toDataStreams(senslogDataStreams, uriComponent);
             ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(encode(ogcDataStreams));
         });
@@ -90,7 +92,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
             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<io.connector.module.senslog1.entity.Datastream> senslogDataStreams = client.getDataStreamsForSensor(parseLong(id));
             List<Datastream> ogcDataStreams = Converter.toDataStreams(senslogDataStreams, uriComponent);
             ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(encode(ogcDataStreams));
         });
@@ -112,7 +114,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
             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));
+            io.connector.module.senslog1.entity.Datastream senslogDataStream = client.getDataStreamForObservation(parseInt(id));
             Datastream ogcDataStream = Converter.toDataStream(senslogDataStream, uriComponent);
             ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(encode(ogcDataStream));
         });
@@ -120,7 +122,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
         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.module.senslog1.entity.Sensor senslogSensor = client.getSensor(parseLong(id));
             io.connector.model.sensorthings.Sensor ogcSensor = Converter.toSensor(senslogSensor, uriComponent);
             ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(encode(ogcSensor));
         });
@@ -151,7 +153,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
             String id = ctx.pathParam("id");
             String[] idCmp = Converter.disassemblyId(id);
             String sensorId = idCmp[1];
-            Phenomenon phenomenon = client.getPhenomenonBySensor(Long.parseLong(sensorId));
+            Phenomenon phenomenon = client.getPhenomenonBySensor(parseLong(sensorId));
             ObservedProperty observedProperty = Converter.toObservedProperty(phenomenon, uriComponent);
             ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(observedProperty.encode());
         });
@@ -163,7 +165,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
             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)));
+            Optional<io.connector.module.senslog1.entity.Observation> observationOpt = ofNullable(client.getObservation(parseInt(id)));
             io.connector.module.senslog1.entity.Observation senslogObservation = observationOpt.orElseThrow(exception);
 
             io.connector.model.sensorthings.Observation ogcObservation = Converter.toObservation(senslogObservation, uriComponent);
@@ -178,7 +180,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
             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.module.senslog1.entity.Observation> senslogObservations = client.getObservationByUnitAndSensor(parseLong(unitId), parseLong(sensorId));
             List<io.connector.model.sensorthings.Observation> ogcObservations = Converter.toObservation(senslogObservations, uriComponent);
             ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(encode(ogcObservations));
         });
@@ -190,7 +192,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
         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));
+            UnitPosition unitPosition = client.getUnitPosition(parseInt(id));
             Location location = Converter.toLocation(unitPosition, uriComponent);
             ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(location.encode());
         });
@@ -198,7 +200,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
         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<UnitPosition> unitPositions = client.getLastPositionsForUnit(parseLong(id));
             List<Location> locations = Converter.toLocation(unitPositions, uriComponent);
             ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(encode(locations));
         });
@@ -212,7 +214,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
         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));
+            UnitPosition unitPosition = client.getUnitPosition(parseInt(id));
             HistoricalLocation historicalLocation = Converter.toHistoricalLocation(unitPosition, uriComponent);
             ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(historicalLocation.encode());
         });
@@ -220,7 +222,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
         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<UnitPosition> unitPositions = client.getLastPositionsForUnit(parseLong(id));
             List<HistoricalLocation> historicalLocations = Converter.toHistoricalLocation(unitPositions, uriComponent);
             ctx.response().putHeader(CONTENT_TYPE, APPLICATION_JSON).end(encode(historicalLocations));
         });
@@ -230,7 +232,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
             // 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));
+            UnitPosition unitPosition = client.getSecondLatestPosition(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());
         });
@@ -306,13 +308,14 @@ public class OGCSensorThingsGateway extends AbstractGateway {
             Objects.requireNonNull(unit);
             Objects.requireNonNull(uriComponent);
 
+            String absoluteUrl = uriComponent.getGatewayUri();
             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.setSelfLink(format("%s/Things(%s)", absoluteUrl, thingId));
+            thing.setLocationsNavigationLink(format("%s/Things(%s)/Locations", absoluteUrl, thingId));
+            thing.setDataStreamNavigationLink(format("%s/Things(%s)/Datastreams", absoluteUrl, thingId));
+            thing.setHistoricalLocationsNavigationLink(format("%s/Things(%s)/HistoricalLocations", absoluteUrl, thingId));
 //            thing.setName(); // TODO - co sem hodit unitTypeId?
             thing.setDescription(unit.getDescription());
             thing.setProperties(null);
@@ -421,7 +424,6 @@ public class OGCSensorThingsGateway extends AbstractGateway {
         }
 
         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());
@@ -432,7 +434,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
             sensor.setName(senslogSensor.getName());
             sensor.setDescription(senslogSensor.getType());
             sensor.setEncodingType("application/json");
-            sensor.setMetadata(format("%s/registry/getSensor/%s", afcDomain, sensorId));
+            sensor.setMetadata(""); // TODO no metadata at this moment
 
             return sensor;
         }

+ 26 - 0
connector-module-senslog1/src/main/java/io/connector/module/senslog1/jdbi/DBConfig.java

@@ -0,0 +1,26 @@
+package io.connector.module.senslog1.jdbi;
+
+public class DBConfig {
+
+    private final String url;
+    private final String username;
+    private final String password;
+
+    public DBConfig(String url, String username, String password) {
+        this.url = url;
+        this.username = username;
+        this.password = password;
+    }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+}

+ 9 - 2
connector-module-senslog1/src/main/java/io/connector/module/senslog1/jdbi/JDBI.java

@@ -8,9 +8,16 @@ public class JDBI {
 
     public static Jdbi get() {
         if (connection == null) {
-            connection = Jdbi.create("jdbc:postgresql://localhost:5432/senslog1", "postgres", "root");
+
+            DBConfig config = new DBConfig(
+                    "jdbc:postgresql://localhost:5432/senslog1",
+                    "senslog_app",
+                    "SENSlog"
+            );
+
+            connection = Jdbi.create(config.getUrl(), config.getUsername(), config.getPassword());
         }
 
         return connection;
     }
-}
+}

+ 0 - 0
SenslogV1.postman_collection.json → postman/SenslogV1.postman_collection.json