Jelajahi Sumber

DB Refactor; driver_to_action -> event, user_to_campaign -> user_to_campaign_config, driver -> entity

Lukas Cerny 1 tahun lalu
induk
melakukan
cb97915312

+ 38 - 26
init.sql

@@ -85,13 +85,21 @@ ALTER SEQUENCE maplog.obs_telemetry_id_seq OWNED BY maplog.obs_telemetry.id;
 ALTER TABLE ONLY maplog.obs_telemetry ALTER COLUMN id SET DEFAULT nextval('maplog.obs_telemetry_id_seq'::regclass);
 
 
-CREATE TABLE maplog.driver (
-    driver_id INTEGER NOT NULL PRIMARY KEY,
-    name VARCHAR(100) NOT NULL
+CREATE TABLE maplog.entity (
+    id          INTEGER NOT NULL PRIMARY KEY,
+    identity    VARCHAR(30) NOT NULL,
+    name        VARCHAR(100) NOT NULL
 );
 
-ALTER TABLE maplog.driver OWNER TO senslog;
+ALTER TABLE maplog.entity OWNER TO senslog;
+
+CREATE SEQUENCE maplog.entity_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;
+
+ALTER TABLE maplog.entity_id_seq OWNER TO senslog;
 
+ALTER SEQUENCE maplog.entity_id_seq OWNED BY maplog.entity.id;
+
+ALTER TABLE ONLY maplog.entity ALTER COLUMN id SET DEFAULT nextval('maplog.entity_id_seq'::regclass);
 
 CREATE TABLE maplog.action (
     action_id INTEGER NOT NULL PRIMARY KEY,
@@ -101,24 +109,24 @@ CREATE TABLE maplog.action (
 ALTER TABLE maplog.action OWNER TO senslog;
 
 
-CREATE TABLE maplog.driver_to_action ( -- rename to event --
+CREATE TABLE maplog.event (
     id          BIGINT NOT NULL PRIMARY KEY,
-    driver_id   INTEGER NOT NULL,
+    entity_id   INTEGER NOT NULL,
     action_id   INTEGER NOT NULL,
     unit_id     BIGINT NOT NULL,
     from_time   TIMESTAMP WITH TIME ZONE NOT NULL,
     to_time     TIMESTAMP WITH TIME ZONE,
     CONSTRAINT dta_check_time CHECK (from_time < to_time)
 );
-ALTER TABLE maplog.driver_to_action OWNER TO senslog;
+ALTER TABLE maplog.event OWNER TO senslog;
 
-CREATE SEQUENCE maplog.driver_to_action_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;
+CREATE SEQUENCE maplog.event_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;
 
-ALTER TABLE maplog.driver_to_action_id_seq OWNER TO senslog;
+ALTER TABLE maplog.event_id_seq OWNER TO senslog;
 
-ALTER SEQUENCE maplog.driver_to_action_id_seq OWNED BY maplog.driver_to_action.id;
+ALTER SEQUENCE maplog.event_id_seq OWNED BY maplog.event.id;
 
-ALTER TABLE ONLY maplog.driver_to_action ALTER COLUMN id SET DEFAULT nextval('maplog.driver_to_action_id_seq'::regclass);
+ALTER TABLE ONLY maplog.event ALTER COLUMN id SET DEFAULT nextval('maplog.event_id_seq'::regclass);
 
 CREATE TABLE maplog.phenomenon (
     id INTEGER NOT NULL PRIMARY KEY,
@@ -210,12 +218,14 @@ CREATE TABLE maplog.unit_type (
 ALTER TABLE maplog.unit_type OWNER TO senslog;
 
 
-CREATE TABLE maplog.user_to_campaign (
+CREATE TABLE maplog.user_to_campaign_config (
     user_id INTEGER NOT NULL,
     campaign_id INTEGER NOT NULL,
-    PRIMARY KEY (user_id, campaign_id)
+    entity_id INTEGER NOT NULL,
+    config JSONB NOT NULL DEFAULT '{}'::JSONB,
+    PRIMARY KEY (user_id, campaign_id, entity_id)
 );
-ALTER TABLE maplog.user_to_campaign OWNER TO senslog;
+ALTER TABLE maplog.user_to_campaign_config OWNER TO senslog;
 
 
 CREATE TYPE alert_status AS ENUM ('CREATED', 'INFORMED', 'IN_PROCESS', 'SOLVED', 'DELETED');
@@ -245,11 +255,11 @@ CREATE INDEX fki_obss_unitid_fk ON maplog.obs_telemetry USING btree (unit_id);
 
 CREATE INDEX fki_sens_phenom_fk ON maplog.sensor USING btree (phenomenon_id);
 
-CREATE INDEX fki_u2c_campid ON maplog.user_to_campaign USING btree (campaign_id);
+CREATE INDEX fki_u2c_campid_fk ON maplog.user_to_campaign_config USING btree (campaign_id);
 
-CREATE INDEX fki_u2c_campid_fk ON maplog.user_to_campaign USING btree (campaign_id);
+CREATE INDEX fki_u2c_userid_fk ON maplog.user_to_campaign_config USING btree (user_id);
 
-CREATE INDEX fki_u2c_userid_fk ON maplog.user_to_campaign USING btree (user_id);
+CREATE INDEX fki_u2c_entityid_fk ON maplog.user_to_campaign_config USING btree (entity_id);
 
 CREATE INDEX fki_un2c_campid ON maplog.unit_to_campaign USING btree (campaign_id);
 
@@ -261,13 +271,13 @@ CREATE INDEX fki_uts_sensorid_fk ON maplog.unit_to_sensor USING btree (sensor_id
 
 CREATE INDEX fki_uts_unitid_fk ON maplog.unit_to_sensor USING btree (unit_id);
 
-CREATE INDEX fki_dta_unitid_fk ON maplog.driver_to_action USING btree (unit_id);
+CREATE INDEX fki_event_unitid_fk ON maplog.event USING btree (unit_id);
 
-CREATE INDEX fki_dr2ac_driverid_fk ON maplog.driver_to_action USING btree (driver_id);
+CREATE INDEX fki_dr2ac_entityid_fk ON maplog.event USING btree (entity_id);
 
-CREATE INDEX fki_dr2ac_actionid_fk ON maplog.driver_to_action USING btree (action_id);
+CREATE INDEX fki_dr2ac_actionid_fk ON maplog.event USING btree (action_id);
 
-CREATE INDEX fki_dr2ac_unitid_fk ON maplog.driver_to_action USING btree (unit_id);
+CREATE INDEX fki_dr2ac_unitid_fk ON maplog.event USING btree (unit_id);
 
 CREATE INDEX fki_alert_unitid_fk ON maplog.alert USING btree (unit_id);
 
@@ -277,9 +287,11 @@ ALTER TABLE ONLY maplog.obs_telemetry ADD CONSTRAINT obss_unitid_fk FOREIGN KEY
 
 ALTER TABLE ONLY maplog.sensor ADD CONSTRAINT sens_phenom_fk FOREIGN KEY (phenomenon_id) REFERENCES maplog.phenomenon(id);
 
-ALTER TABLE ONLY maplog.user_to_campaign ADD CONSTRAINT u2c_campid FOREIGN KEY (campaign_id) REFERENCES maplog.campaign(id) ON UPDATE CASCADE ON DELETE CASCADE;
+ALTER TABLE ONLY maplog.user_to_campaign_config ADD CONSTRAINT u2c_campid FOREIGN KEY (campaign_id) REFERENCES maplog.campaign(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY maplog.user_to_campaign_config ADD CONSTRAINT u2c_userid_fk FOREIGN KEY (user_id) REFERENCES maplog.system_user(user_id) ON UPDATE CASCADE ON DELETE CASCADE;
 
-ALTER TABLE ONLY maplog.user_to_campaign ADD CONSTRAINT u2c_userid_fk FOREIGN KEY (user_id) REFERENCES maplog.system_user(user_id) ON UPDATE CASCADE ON DELETE CASCADE;
+ALTER TABLE ONLY maplog.user_to_campaign_config ADD CONSTRAINT u2c_entityid_fk FOREIGN KEY (entity_id) REFERENCES maplog.entity(id) ON UPDATE CASCADE ON DELETE CASCADE;
 
 ALTER TABLE ONLY maplog.unit_to_campaign ADD CONSTRAINT un2c_campid FOREIGN KEY (campaign_id) REFERENCES maplog.campaign(id) ON UPDATE CASCADE ON DELETE CASCADE;
 
@@ -291,11 +303,11 @@ ALTER TABLE ONLY maplog.unit_to_sensor ADD CONSTRAINT uts_sensorid_fk FOREIGN KE
 
 ALTER TABLE ONLY maplog.unit_to_sensor ADD CONSTRAINT uts_unitid_fk FOREIGN KEY (unit_id) REFERENCES maplog.unit(unit_id) ON UPDATE CASCADE ON DELETE CASCADE;
 
-ALTER TABLE ONLY maplog.driver_to_action ADD CONSTRAINT dta_unitid_fk FOREIGN KEY (unit_id) REFERENCES maplog.unit(unit_id) ON UPDATE CASCADE ON DELETE CASCADE;
+ALTER TABLE ONLY maplog.event ADD CONSTRAINT event_unitid_fk FOREIGN KEY (unit_id) REFERENCES maplog.unit(unit_id) ON UPDATE CASCADE ON DELETE CASCADE;
 
-ALTER TABLE ONLY maplog.driver_to_action ADD CONSTRAINT dta_driverid_fk FOREIGN KEY (driver_id) REFERENCES maplog.driver(driver_id) ON UPDATE CASCADE ON DELETE CASCADE;
+ALTER TABLE ONLY maplog.event ADD CONSTRAINT event_entityid_fk FOREIGN KEY (entity_id) REFERENCES maplog.entity(id) ON UPDATE CASCADE ON DELETE CASCADE;
 
-ALTER TABLE ONLY maplog.driver_to_action ADD CONSTRAINT dta_actionid_fk FOREIGN KEY (action_id) REFERENCES maplog.action(action_id) ON UPDATE CASCADE ON DELETE CASCADE;
+ALTER TABLE ONLY maplog.event ADD CONSTRAINT event_actionid_fk FOREIGN KEY (action_id) REFERENCES maplog.action(action_id) ON UPDATE CASCADE ON DELETE CASCADE;
 
 ALTER TABLE ONLY maplog.alert ADD CONSTRAINT alert_unitid_fk FOREIGN KEY (unit_id) REFERENCES maplog.unit(unit_id) ON UPDATE CASCADE ON DELETE CASCADE;
 

+ 4 - 4
src/main/java/cz/senslog/telemetry/database/domain/Driver.java → src/main/java/cz/senslog/telemetry/database/domain/Entity.java

@@ -1,15 +1,15 @@
 package cz.senslog.telemetry.database.domain;
 
-public class Driver {
+public class Entity {
 
     private final int id;
     private final String name;
 
-    public static Driver of(int id, String name) {
-        return new Driver(id, name);
+    public static Entity of(int id, String name) {
+        return new Entity(id, name);
     }
 
-    private Driver(int id, String name) {
+    private Entity(int id, String name) {
         this.id = id;
         this.name = name;
     }

+ 6 - 6
src/main/java/cz/senslog/telemetry/database/domain/DriverAction.java → src/main/java/cz/senslog/telemetry/database/domain/EntityAction.java

@@ -2,16 +2,16 @@ package cz.senslog.telemetry.database.domain;
 
 import java.time.OffsetDateTime;
 
-public class DriverAction {
+public class EntityAction {
 
     private final long unitId;
-    private final long driverId;
+    private final long entityId;
     private final long actionId;
     private final OffsetDateTime timestamp;
 
-    public DriverAction(long unitId, long driverId, long actionId, OffsetDateTime timestamp) {
+    public EntityAction(long unitId, long entityId, long actionId, OffsetDateTime timestamp) {
         this.unitId = unitId;
-        this.driverId = driverId;
+        this.entityId = entityId;
         this.actionId = actionId;
         this.timestamp = timestamp;
     }
@@ -20,8 +20,8 @@ public class DriverAction {
         return unitId;
     }
 
-    public long getDriverId() {
-        return driverId;
+    public long getEntityId() {
+        return entityId;
     }
 
     public long getActionId() {

+ 5 - 5
src/main/java/cz/senslog/telemetry/database/domain/Event.java

@@ -5,7 +5,7 @@ import java.time.OffsetDateTime;
 public class Event {
 
     private final long id;
-    private final long driverId;
+    private final long entityId;
     private final long actionId;
     private final long unitId;
     private final OffsetDateTime fromTime;
@@ -20,9 +20,9 @@ public class Event {
         return new Event(-1, driverId, actionId, unitId, fromTime, toTime);
     }
 
-    private Event(long id, long driverId, long actionId, long unitId, OffsetDateTime fromTime, OffsetDateTime toTime) {
+    private Event(long id, long entityId, long actionId, long unitId, OffsetDateTime fromTime, OffsetDateTime toTime) {
         this.id = id;
-        this.driverId = driverId;
+        this.entityId = entityId;
         this.actionId = actionId;
         this.unitId = unitId;
         this.fromTime = fromTime;
@@ -34,8 +34,8 @@ public class Event {
         return id;
     }
 
-    public long getDriverId() {
-        return driverId;
+    public long getEntityId() {
+        return entityId;
     }
 
     public long getActionId() {

+ 106 - 109
src/main/java/cz/senslog/telemetry/database/repository/MapLogRepository.java

@@ -6,10 +6,7 @@ import cz.senslog.telemetry.database.SortType;
 import cz.senslog.telemetry.database.domain.*;
 import cz.senslog.telemetry.database.domain.Filter;
 import io.vertx.core.Future;
-import io.vertx.pgclient.PgPool;
 import io.vertx.sqlclient.*;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
 
 import java.time.OffsetDateTime;
 import java.time.ZoneId;
@@ -35,20 +32,20 @@ public class MapLogRepository implements SensLogRepository {
     }
 
     @Override
-    public Future<Integer> updateEvent(DriverAction data) {
-        Tuple params = Tuple.of(data.getTimestamp(), data.getDriverId(), data.getActionId(), data.getUnitId());
-        return client.withTransaction(conn -> conn.preparedQuery("UPDATE maplog.driver_to_action SET to_time = $1 " +
-                        "WHERE driver_id = $2 AND action_id = $3 AND unit_id = $4 AND to_time IS NULL AND from_time < $1 RETURNING id")
+    public Future<Integer> updateEvent(EntityAction data) {
+        Tuple params = Tuple.of(data.getTimestamp(), data.getEntityId(), data.getActionId(), data.getUnitId());
+        return client.withTransaction(conn -> conn.preparedQuery("UPDATE maplog.event SET to_time = $1 " +
+                        "WHERE entity_id = $2 AND action_id = $3 AND unit_id = $4 AND to_time IS NULL AND from_time < $1 RETURNING id")
                 .execute(params)
                 .flatMap(r1 -> {
                     if (r1.rowCount() <= 0) {
-                        return conn.preparedQuery("INSERT INTO maplog.driver_to_action(from_time, driver_id, action_id, unit_id) " +
+                        return conn.preparedQuery("INSERT INTO maplog.event(from_time, entity_id, action_id, unit_id) " +
                                         "SELECT $1, $2, $3, $4  WHERE EXISTS(SELECT action_id FROM maplog.action WHERE action_id = $3) RETURNING id")
                                 .execute(params)
                                 .flatMap(r2 -> {
                                     if (r2.rowCount() <= 0) {
                                         return conn.preparedQuery("WITH rows AS (INSERT INTO maplog.action(action_id, name) VALUES ($3, 'GENERATED-ACTION') RETURNING action_id) " +
-                                                            "INSERT INTO maplog.driver_to_action(from_time, driver_id, action_id, unit_id) " +
+                                                            "INSERT INTO maplog.event(from_time, entity_id, action_id, unit_id) " +
                                                                 "SELECT $1, $2, rows.action_id, $4 FROM rows RETURNING id;")
                                                 .execute(params)
                                                 .map(RowSet::rowCount);
@@ -63,7 +60,7 @@ public class MapLogRepository implements SensLogRepository {
 
     @Override
     public Future<Long> updateEvent(long eventId, OffsetDateTime toTime) {
-        return client.withTransaction(conn -> conn.preparedQuery("UPDATE maplog.driver_to_action SET to_time = $2 WHERE id = $1 AND to_time IS NULL RETURNING id")
+        return client.withTransaction(conn -> conn.preparedQuery("UPDATE maplog.event SET to_time = $2 WHERE id = $1 AND to_time IS NULL RETURNING id")
                 .execute(Tuple.of(eventId, toTime))
                 .map(RowSet::iterator)
                 .map(it -> it.hasNext() ? it.next().getLong(0) : null)
@@ -75,9 +72,9 @@ public class MapLogRepository implements SensLogRepository {
     @Override
     public Future<Long> saveEvent(Event event) {
         return client.withTransaction(conn ->
-                conn.preparedQuery("INSERT INTO maplog.driver_to_action(driver_id, action_id, unit_id, from_time, to_time) " +
+                conn.preparedQuery("INSERT INTO maplog.event(entity_id, action_id, unit_id, from_time, to_time) " +
                         "SELECT $1, $2, $3, $4, $5  WHERE EXISTS(SELECT action_id FROM maplog.action WHERE action_id = $2) RETURNING id")
-                        .execute(Tuple.of(event.getDriverId(), event.getActionId(), event.getUnitId(), event.getFromTime(), event.getToTime()))
+                        .execute(Tuple.of(event.getEntityId(), event.getActionId(), event.getUnitId(), event.getFromTime(), event.getToTime()))
                         .map(RowSet::iterator)
                         .map(it -> it.hasNext() ? it.next().getLong(0) : null)
                         .map(Optional::ofNullable)
@@ -92,14 +89,14 @@ public class MapLogRepository implements SensLogRepository {
         }
 
         List<Tuple> tuples = events.stream().map(e -> Tuple.of(
-                e.getDriverId(),
+                e.getEntityId(),
                 e.getActionId(),
                 e.getUnitId(),
                 e.getFromTime(),
                 e.getToTime())
         ).toList();
 
-        return client.withTransaction(conn -> conn.preparedQuery("INSERT INTO maplog.driver_to_action(driver_id, action_id, unit_id, from_time, to_time) " +
+        return client.withTransaction(conn -> conn.preparedQuery("INSERT INTO maplog.event(entity_id, action_id, unit_id, from_time, to_time) " +
                 "SELECT $1, $2, $3, $4, $5  WHERE EXISTS(SELECT action_id FROM maplog.action WHERE action_id = $2) RETURNING id")
                 .executeBatch(tuples)
                 .map(rs -> StreamSupport.stream(rs.spliterator(), false).map(r -> r.getLong(0)).collect(toList())));
@@ -353,52 +350,52 @@ public class MapLogRepository implements SensLogRepository {
     }
 
     @Override
-    public Future<List<Driver>> allDrivers() {
-        return client.query("SELECT driver_id, name FROM maplog.driver ORDER BY driver_id")
+    public Future<List<Entity>> allEntities() {
+        return client.query("SELECT id, name FROM maplog.entity ORDER BY id")
                 .execute()
                 .map(rs -> StreamSupport.stream(rs.spliterator(), false)
-                        .map(row -> Driver.of(
-                                row.getInteger("driver_id"),
+                        .map(row -> Entity.of(
+                                row.getInteger("id"),
                                 row.getString("name")
                         )).collect(toList())
                 );
     }
 
-    private static final Function<Row, Driver> ROW_TO_DRIVER = (row) -> Driver.of(
-            row.getInteger("driver_id"),
+    private static final Function<Row, Entity> ROW_TO_ENTITY = (row) -> Entity.of(
+            row.getInteger("id"),
             row.getString("name")
     );
 
     @Override
-    public Future<Driver> findDriverById(int driverId) {
-        return client.preparedQuery("SELECT driver_id, name FROM maplog.driver WHERE driver_id = $1")
-                .execute(Tuple.of(driverId))
+    public Future<Entity> findEntityById(int entityId) {
+        return client.preparedQuery("SELECT id, name FROM maplog.entity WHERE id = $1")
+                .execute(Tuple.of(entityId))
                 .map(RowSet::iterator)
-                .map(iterator -> iterator.hasNext() ? ROW_TO_DRIVER.apply(iterator.next()) : null)
+                .map(iterator -> iterator.hasNext() ? ROW_TO_ENTITY.apply(iterator.next()) : null)
                 .map(Optional::ofNullable)
-                .map(p -> p.orElseThrow(() -> new DataNotFoundException(format("Driver ID '%d' not found.", driverId))));
+                .map(p -> p.orElseThrow(() -> new DataNotFoundException(format("Entity ID '%d' not found.", entityId))));
     }
 
     @Override
-    public Future<List<Driver>> findDriversByUnitId(long unitId) {
-        return client.preparedQuery("SELECT d.driver_id, d.name FROM maplog.driver AS d " +
-                        "JOIN maplog.driver_to_action AS dta ON dta.driver_id = d.driver_id " +
-                        "WHERE dta.unit_id = $1")
+    public Future<List<Entity>> findEntitiesByUnitId(long unitId) {
+        return client.preparedQuery("SELECT en.id, en.name FROM maplog.entity AS en " +
+                        "JOIN maplog.event AS e ON e.entity_id = en.id " +
+                        "WHERE e.unit_id = $1")
                 .execute(Tuple.of(unitId))
                 .map(rs -> StreamSupport.stream(rs.spliterator(), false)
-                        .map(row -> Driver.of(
-                                row.getInteger("driver_id"),
+                        .map(row -> Entity.of(
+                                row.getInteger("id"),
                                 row.getString("name")
                         )).collect(toList())
                 );
     }
 
     @Override
-    public Future<List<Action>> findActionsByDriverIdAndUnitId(int driverId, long unitId) {
+    public Future<List<Action>> findActionsByEntityIdAndUnitId(int entityId, long unitId) {
         return client.preparedQuery("SELECT a.action_id, a.name FROM maplog.action AS a " +
-                "JOIN maplog.driver_to_action AS dta ON a.action_id = dta.action_id " +
-                "WHERE dta.driver_id = $1 AND dta.unit_id = $2 ORDER BY a.action_id")
-                .execute(Tuple.of(driverId, unitId))
+                "JOIN maplog.event AS e ON a.action_id = e.action_id " +
+                "WHERE e.entity_id = $1 AND e.unit_id = $2 ORDER BY a.action_id")
+                .execute(Tuple.of(entityId, unitId))
                 .map(rs -> StreamSupport.stream(rs.spliterator(), false)
                         .map(row -> Action.of(
                                 row.getInteger("action_id"),
@@ -408,25 +405,25 @@ public class MapLogRepository implements SensLogRepository {
     }
 
     @Override
-    public Future<List<Action>> findActionsByDriverId(int driverId, OffsetDateTime from, OffsetDateTime to) {
+    public Future<List<Action>> findActionsByEntityId(int entityId, OffsetDateTime from, OffsetDateTime to) {
         String whereTimestampClause;
         Tuple tupleParams;
         if (from != null && to != null) {
-            whereTimestampClause = "WHERE dta.driver_id = $1 AND dta.from_time >= $2 AND dta.to_time < $3";
-            tupleParams = Tuple.of(driverId, from, to);
+            whereTimestampClause = "WHERE e.entity_id = $1 AND e.from_time >= $2 AND e.to_time < $3";
+            tupleParams = Tuple.of(entityId, from, to);
         } else if (from != null) {
-            whereTimestampClause = "WHERE dta.driver_id = $1 AND dta.from_time >= $2";
-            tupleParams = Tuple.of(driverId, from);
+            whereTimestampClause = "WHERE e.entity_id = $1 AND e.from_time >= $2";
+            tupleParams = Tuple.of(entityId, from);
         } else if (to != null) {
-            whereTimestampClause = "WHERE dta.driver_id = $1 AND dta.to_time < $2";
-            tupleParams = Tuple.of(driverId, to);
+            whereTimestampClause = "WHERE e.entity_id = $1 AND e.to_time < $2";
+            tupleParams = Tuple.of(entityId, to);
         } else {
-            whereTimestampClause = "WHERE dta.driver_id = $1";
-            tupleParams = Tuple.of(driverId);
+            whereTimestampClause = "WHERE e.entity_id = $1";
+            tupleParams = Tuple.of(entityId);
         }
 
         return client.preparedQuery("SELECT a.action_id, a.name FROM maplog.action AS a " +
-                        "JOIN maplog.driver_to_action AS dta ON a.action_id = dta.action_id " +
+                        "JOIN maplog.event AS e ON a.action_id = e.action_id " +
                         whereTimestampClause + " ORDER BY a.action_id")
                 .execute(tupleParams)
                 .map(rs -> StreamSupport.stream(rs.spliterator(), false)
@@ -443,38 +440,38 @@ public class MapLogRepository implements SensLogRepository {
     );
 
     @Override
-    public Future<Action> findActionByIdAndDriverId(int actionId, int driverId) {
+    public Future<Action> findActionByIdAndEntityId(int actionId, int entityId) {
         return client.preparedQuery("SELECT a.action_id, a.name FROM maplog.action AS a " +
-                "JOIN maplog.driver_to_action AS dta ON a.action_id = dta.action_id " +
-                "WHERE a.action_id = $1 AND dta.driver_id = $2")
-                .execute(Tuple.of(actionId, driverId))
+                "JOIN maplog.event AS e ON a.action_id = e.action_id " +
+                "WHERE a.action_id = $1 AND e.entity_id = $2")
+                .execute(Tuple.of(actionId, entityId))
                 .map(RowSet::iterator)
                 .map(iterator -> iterator.hasNext() ? ROW_TO_ACTION.apply(iterator.next()) : null)
                 .map(Optional::ofNullable)
-                .map(p -> p.orElseThrow(() -> new DataNotFoundException(format("Action ID '%d' not found for Driver(%d).", actionId, driverId))));
+                .map(p -> p.orElseThrow(() -> new DataNotFoundException(format("Action ID '%d' not found for Entity(%d).", actionId, entityId))));
     }
 
     @Override
-    public Future<Action> findActionByIdAndDriverIdAndUnitId(int actionId, int driverId, long unitId) {
+    public Future<Action> findActionByIdAndEntityIdAndUnitId(int actionId, int entityId, long unitId) {
         return client.preparedQuery("SELECT a.action_id, a.name FROM maplog.action AS a " +
-                        "JOIN maplog.driver_to_action AS dta ON a.action_id = dta.action_id " +
-                        "WHERE a.action_id = $1 AND dta.driver_id = $2 AND dta.unit_id = $3")
-                .execute(Tuple.of(actionId, driverId, unitId))
+                        "JOIN maplog.event AS e ON a.action_id = e.action_id " +
+                        "WHERE a.action_id = $1 AND e.entity_id = $2 AND e.unit_id = $3")
+                .execute(Tuple.of(actionId, entityId, unitId))
                 .map(RowSet::iterator)
                 .map(iterator -> iterator.hasNext() ? ROW_TO_ACTION.apply(iterator.next()) : null)
                 .map(Optional::ofNullable)
-                .map(p -> p.orElseThrow(() -> new DataNotFoundException(format("Action ID '%d' not found for Driver(%d) and Unit(%d).", actionId, driverId, unitId))));
+                .map(p -> p.orElseThrow(() -> new DataNotFoundException(format("Action ID '%d' not found for Entity(%d) and Unit(%d).", actionId, entityId, unitId))));
     }
 
     @Override
-    public Future<List<Event>> findEventsByDriverIdAndUnitIdAndActionId(int driverId, long unitId, int actionId) {
-        return client.preparedQuery("SELECT id, driver_id, action_id, unit_id, from_time, to_time FROM maplog.driver_to_action " +
-                        "WHERE driver_id = $1 AND unit_id = $2 AND action_id = $3 ORDER BY id")
-                .execute(Tuple.of(driverId, unitId, actionId))
+    public Future<List<Event>> findEventsByEntityIdAndUnitIdAndActionId(int entityId, long unitId, int actionId) {
+        return client.preparedQuery("SELECT id, entity_id, action_id, unit_id, from_time, to_time FROM maplog.event " +
+                        "WHERE entity_id = $1 AND unit_id = $2 AND action_id = $3 ORDER BY id")
+                .execute(Tuple.of(entityId, unitId, actionId))
                 .map(rs -> StreamSupport.stream(rs.spliterator(), false)
                         .map(row -> Event.of(
                                 row.getLong("id"),
-                                row.getInteger("driver_id"),
+                                row.getInteger("entity_id"),
                                 row.getInteger("action_id"),
                                 row.getLong("unit_id"),
                                 row.getOffsetDateTime("from_time"),
@@ -485,7 +482,7 @@ public class MapLogRepository implements SensLogRepository {
 
     private static final Function<Row, Event> ROW_TO_EVENT = (row) -> Event.of(
             row.getLong("id"),
-            row.getInteger("driver_id"),
+            row.getInteger("entity_id"),
             row.getInteger("action_id"),
             row.getLong("unit_id"),
             row.getOffsetDateTime("from_time"),
@@ -494,7 +491,7 @@ public class MapLogRepository implements SensLogRepository {
 
     @Override
     public Future<Event> findEventById(long eventId) {
-        return client.preparedQuery("SELECT id, driver_id, action_id, unit_id, from_time, to_time FROM maplog.driver_to_action WHERE id = $1")
+        return client.preparedQuery("SELECT id, entity_id, action_id, unit_id, from_time, to_time FROM maplog.event WHERE id = $1")
                 .execute(Tuple.of(eventId))
                 .map(RowSet::iterator)
                 .map(iterator -> iterator.hasNext() ? ROW_TO_EVENT.apply(iterator.next()) : null)
@@ -503,24 +500,24 @@ public class MapLogRepository implements SensLogRepository {
     }
 
     @Override
-    public Future<List<Unit>> findUnitsByDriverId(int driverId, OffsetDateTime from, OffsetDateTime to) {
+    public Future<List<Unit>> findUnitsByEntityId(int entityId, OffsetDateTime from, OffsetDateTime to) {
         String whereTimestampClause;
         Tuple tupleParams;
         if (from != null && to != null) {
-            whereTimestampClause = "WHERE dta.driver_id = $1 AND dta.from_time >= $2 AND dta.to_time < $3";
-            tupleParams = Tuple.of(driverId, from, to);
+            whereTimestampClause = "WHERE e.entity_id = $1 AND e.from_time >= $2 AND e.to_time < $3";
+            tupleParams = Tuple.of(entityId, from, to);
         } else if (from != null) {
-            whereTimestampClause = "WHERE dta.driver_id = $1 AND dta.from_time >= $2";
-            tupleParams = Tuple.of(driverId, from);
+            whereTimestampClause = "WHERE e.entity_id = $1 AND e.from_time >= $2";
+            tupleParams = Tuple.of(entityId, from);
         } else if (to != null) {
-            whereTimestampClause = "WHERE dta.driver_id = $1 AND dta.to_time < $2";
-            tupleParams = Tuple.of(driverId, to);
+            whereTimestampClause = "WHERE e.entity_id = $1 AND e.to_time < $2";
+            tupleParams = Tuple.of(entityId, to);
         } else {
-            whereTimestampClause = "WHERE dta.driver_id = $1";
-            tupleParams = Tuple.of(driverId);
+            whereTimestampClause = "WHERE e.entity_id = $1";
+            tupleParams = Tuple.of(entityId);
         }
-        return client.preparedQuery("SELECT u.unit_id, u.name, u.imei, u.description FROM maplog.driver_to_action AS dta " +
-                "JOIN maplog.unit AS u ON u.unit_id = dta.unit_id " + whereTimestampClause + " ORDER BY u.unit_id")
+        return client.preparedQuery("SELECT u.unit_id, u.name, u.imei, u.description FROM maplog.event AS e " +
+                "JOIN maplog.unit AS u ON u.unit_id = e.unit_id " + whereTimestampClause + " ORDER BY u.unit_id")
                 .execute(tupleParams)
                 .map(rs -> StreamSupport.stream(rs.spliterator(), false)
                         .map(row -> Unit.of(
@@ -588,37 +585,37 @@ public class MapLogRepository implements SensLogRepository {
     }
 
     @Override
-    public Future<Unit> findUnitByIdAndDriverId(long unitId, int driverId) {
+    public Future<Unit> findUnitByIdAndEntityId(long unitId, int entityId) {
         return client.preparedQuery("SELECT u.unit_id, u.name, u.imei, u.description " +
                         "FROM maplog.unit AS u " +
-                        "JOIN maplog.driver_to_action AS dta ON u.unit_id = dta.unit_id " +
-                        "WHERE dta.driver_id = $1 AND dta.unit_id = $2")
-                .execute(Tuple.of(driverId, unitId))
+                        "JOIN maplog.event AS e ON u.unit_id = e.unit_id " +
+                        "WHERE e.entity_id = $1 AND e.unit_id = $2")
+                .execute(Tuple.of(entityId, unitId))
                 .map(RowSet::iterator)
                 .map(iterator -> iterator.hasNext() ? ROW_TO_UNIT.apply(iterator.next()) : null)
                 .map(Optional::ofNullable)
-                .map(p -> p.orElseThrow(() -> new DataNotFoundException(format("Unit ID '%d' not found for Driver(%d).", unitId, driverId))));
+                .map(p -> p.orElseThrow(() -> new DataNotFoundException(format("Unit ID '%d' not found for Entity(%d).", unitId, entityId))));
     }
 
     @Override
-    public Future<Unit> findUnitByIdAndDriverIdAndActionId(long unitId, int driverId, int actionId) {
+    public Future<Unit> findUnitByIdAndEntityIdAndActionId(long unitId, int entityId, int actionId) {
         return client.preparedQuery("SELECT u.unit_id, u.name, u.imei, u.description " +
                         "FROM maplog.unit AS u " +
-                        "JOIN maplog.driver_to_action AS dta ON u.unit_id = dta.unit_id " +
-                        "WHERE u.unit_id = $1 AND dta.driver_id = $2 AND dta.action_id = $3")
-                .execute(Tuple.of(unitId, driverId, actionId))
+                        "JOIN maplog.event AS e ON u.unit_id = e.unit_id " +
+                        "WHERE u.unit_id = $1 AND e.entity_id = $2 AND e.action_id = $3")
+                .execute(Tuple.of(unitId, entityId, actionId))
                 .map(RowSet::iterator)
                 .map(iterator -> iterator.hasNext() ? ROW_TO_UNIT.apply(iterator.next()) : null)
                 .map(Optional::ofNullable)
-                .map(p -> p.orElseThrow(() -> new DataNotFoundException(format("Unit ID '%d' not found for Driver(%d) and Action(%d).", unitId, driverId, actionId))));
+                .map(p -> p.orElseThrow(() -> new DataNotFoundException(format("Unit ID '%d' not found for Entity(%d) and Action(%d).", unitId, entityId, actionId))));
     }
 
     @Override
-    public Future<List<Unit>> findUnitsByDriverIdAndActionId(int driverId, int actionId) {
+    public Future<List<Unit>> findUnitsByEntityIdAndActionId(int entityId, int actionId) {
         return client.preparedQuery("SELECT u.unit_id, u.name, u.imei, u.description FROM maplog.unit AS u " +
-                "JOIN maplog.driver_to_action dta on u.unit_id = dta.unit_id " +
-                "WHERE dta.driver_id = $1 AND dta.action_id = $2 ORDER BY u.unit_id")
-                .execute(Tuple.of(driverId, actionId))
+                "JOIN maplog.event AS e on u.unit_id = e.unit_id " +
+                "WHERE e.entity_id = $1 AND e.action_id = $2 ORDER BY u.unit_id")
+                .execute(Tuple.of(entityId, actionId))
                 .map(rs -> StreamSupport.stream(rs.spliterator(), false)
                         .map(row -> Unit.of(
                                 row.getLong("unit_id"),
@@ -904,16 +901,16 @@ public class MapLogRepository implements SensLogRepository {
         String whereTimestampClause;
         Tuple tupleParams;
         if (from != null && to != null) {
-            whereTimestampClause = "tel.time_stamp >= (CASE WHEN $5 < dta.from_time THEN $5 ELSE dta.from_time END) AND tel.time_stamp <= (CASE WHEN dta.to_time IS NULL OR $6 < dta.to_time THEN $6 ELSE dta.to_time END)";
+            whereTimestampClause = "tel.time_stamp >= (CASE WHEN $5 < e.from_time THEN $5 ELSE e.from_time END) AND tel.time_stamp <= (CASE WHEN e.to_time IS NULL OR $6 < e.to_time THEN $6 ELSE e.to_time END)";
             tupleParams = Tuple.of(eventId, offset, limit, zone.getId(), from, to);
         } else if (from != null) {
-            whereTimestampClause = "tel.time_stamp >= (CASE WHEN $5 < dta.from_time THEN $5 ELSE dta.from_time END) AND tel.time_stamp <= (CASE WHEN dta.to_time IS NULL THEN now() ELSE dta.to_time END)";
+            whereTimestampClause = "tel.time_stamp >= (CASE WHEN $5 < e.from_time THEN $5 ELSE e.from_time END) AND tel.time_stamp <= (CASE WHEN e.to_time IS NULL THEN now() ELSE e.to_time END)";
             tupleParams = Tuple.of(eventId, offset, limit, zone.getId(), from);
         } else if (to != null) {
-            whereTimestampClause = "tel.time_stamp >= dta.from_time AND tel.time_stamp <= (CASE WHEN dta.to_time IS NULL OR $5 < dta.to_time THEN $5 ELSE dta.to_time END)";
+            whereTimestampClause = "tel.time_stamp >= e.from_time AND tel.time_stamp <= (CASE WHEN e.to_time IS NULL OR $5 < e.to_time THEN $5 ELSE e.to_time END)";
             tupleParams = Tuple.of(eventId, offset, limit, zone.getId(), to);
         } else {
-            whereTimestampClause = "tel.time_stamp >= dta.from_time AND tel.time_stamp <= (CASE WHEN dta.to_time IS NULL THEN now() ELSE dta.to_time END)";
+            whereTimestampClause = "tel.time_stamp >= e.from_time AND tel.time_stamp <= (CASE WHEN e.to_time IS NULL THEN now() ELSE e.to_time END)";
             tupleParams = Tuple.of(eventId, offset, limit, zone.getId());
         }
 
@@ -947,8 +944,8 @@ public class MapLogRepository implements SensLogRepository {
                         "ST_Z (ST_Transform (tel.the_geom, 4326)) AS alt, " +
                         "ST_M (tel.the_geom) AS angle " +
                         "FROM maplog.obs_telemetry AS tel " +
-                    "JOIN maplog.driver_to_action dta on tel.unit_id = dta.unit_id " +
-                "WHERE dta.id = $1 AND " + whereTimestampClause + whereFiltersClause + " " +
+                    "JOIN maplog.event AS e on tel.unit_id = e.unit_id " +
+                "WHERE e.id = $1 AND " + whereTimestampClause + whereFiltersClause + " " +
                 "ORDER BY tel.time_stamp OFFSET $2 LIMIT $3";
 
         return client.preparedQuery(sql)
@@ -1159,16 +1156,16 @@ public class MapLogRepository implements SensLogRepository {
         String whereTimestampClause;
         Tuple tupleParams;
         if (from != null && to != null) {
-            whereTimestampClause = "tel.time_stamp >= (CASE WHEN $5 < dta.from_time THEN $5 ELSE dta.from_time END) AND tel.time_stamp <= (CASE WHEN dta.to_time IS NULL OR $6 < dta.to_time THEN $6 ELSE dta.to_time END)";
+            whereTimestampClause = "tel.time_stamp >= (CASE WHEN $5 < e.from_time THEN $5 ELSE e.from_time END) AND tel.time_stamp <= (CASE WHEN e.to_time IS NULL OR $6 < e.to_time THEN $6 ELSE e.to_time END)";
             tupleParams = Tuple.of(eventId, offset, limit, zone.getId(), from, to);
         } else if (from != null) {
-            whereTimestampClause = "tel.time_stamp >= (CASE WHEN $5 < dta.from_time THEN $5 ELSE dta.from_time END) AND tel.time_stamp <= (CASE WHEN dta.to_time IS NULL THEN now() ELSE dta.to_time END)";
+            whereTimestampClause = "tel.time_stamp >= (CASE WHEN $5 < e.from_time THEN $5 ELSE e.from_time END) AND tel.time_stamp <= (CASE WHEN e.to_time IS NULL THEN now() ELSE e.to_time END)";
             tupleParams = Tuple.of(eventId, offset, limit, zone.getId(), from);
         } else if (to != null) {
-            whereTimestampClause = "tel.time_stamp >= dta.from_time AND tel.time_stamp <= (CASE WHEN dta.to_time IS NULL OR $5 < dta.to_time THEN $5 ELSE dta.to_time END)";
+            whereTimestampClause = "tel.time_stamp >= e.from_time AND tel.time_stamp <= (CASE WHEN e.to_time IS NULL OR $5 < e.to_time THEN $5 ELSE e.to_time END)";
             tupleParams = Tuple.of(eventId, offset, limit, zone.getId(), to);
         } else {
-            whereTimestampClause = "tel.time_stamp >= dta.from_time AND tel.time_stamp <= (CASE WHEN dta.to_time IS NULL THEN now() ELSE dta.to_time END)";
+            whereTimestampClause = "tel.time_stamp >= e.from_time AND tel.time_stamp <= (CASE WHEN e.to_time IS NULL THEN now() ELSE e.to_time END)";
             tupleParams = Tuple.of(eventId, offset, limit, zone.getId());
         }
 
@@ -1200,8 +1197,8 @@ public class MapLogRepository implements SensLogRepository {
                         "ST_Y (ST_Transform (tel.the_geom, 4326)) AS lat, " +
                         "ST_Z (ST_Transform (tel.the_geom, 4326)) AS alt " +
                     "FROM maplog.obs_telemetry AS tel " +
-                    "JOIN maplog.driver_to_action dta on tel.unit_id = dta.unit_id " +
-                    "WHERE dta.id = $1 AND " + whereTimestampClause + whereFiltersClause + " " +
+                    "JOIN maplog.event AS e on tel.unit_id = e.unit_id " +
+                    "WHERE e.id = $1 AND " + whereTimestampClause + whereFiltersClause + " " +
                     "ORDER BY tel.time_stamp OFFSET $2 LIMIT $3";
 
         return client.preparedQuery(sql)
@@ -1374,9 +1371,9 @@ public class MapLogRepository implements SensLogRepository {
         String statuses = String.join(",", statusFilter.stream().map(s -> "'"+s.name()+"'").collect(toSet()));
 
         return client.preparedQuery("SELECT a.id, a.message, a.status, a.time_stamp FROM maplog.alert AS a " +
-                        "JOIN maplog.driver_to_action AS dta ON dta.unit_id = a.unit_id " +
-                        "WHERE dta.from_time <= a.time_stamp AND (CASE WHEN dta.to_time IS NULL THEN now() ELSE dta.to_time END) >= a.time_stamp " +
-                            "AND dta.id = $1 AND a.status IN ("+statuses+") " + // TODO better solution IN (array)
+                        "JOIN maplog.event AS e ON e.unit_id = a.unit_id " +
+                        "WHERE e.from_time <= a.time_stamp AND (CASE WHEN e.to_time IS NULL THEN now() ELSE e.to_time END) >= a.time_stamp " +
+                            "AND e.id = $1 AND a.status IN ("+statuses+") " + // TODO better solution IN (array)
                         "ORDER BY a.time_stamp "+sortType.name())
                 .execute(Tuple.of(eventId))
                 .map(rs -> StreamSupport.stream(rs.spliterator(), false)
@@ -1401,8 +1398,8 @@ public class MapLogRepository implements SensLogRepository {
 
     @Override
     public Future<EventAlert> findAlertByIdAndEventId(long alertId, long eventId) {
-        return client.preparedQuery("SELECT a.id, dta.id AS event_id, a.unit_id, a.message, a.status, a.time_stamp FROM maplog.alert AS a " +
-                        "JOIN maplog.driver_to_action AS dta ON dta.unit_id = a.unit_id WHERE a.id = $1 AND dta.id = $2")
+        return client.preparedQuery("SELECT a.id, e.id AS event_id, a.unit_id, a.message, a.status, a.time_stamp FROM maplog.alert AS a " +
+                        "JOIN maplog.event AS e ON e.unit_id = a.unit_id WHERE a.id = $1 AND e.id = $2")
                 .execute(Tuple.of(alertId, eventId))
                 .map(RowSet::iterator)
                 .map(it -> it.hasNext() ? ROW_TO_EVENT_ALERT.apply(it.next()) : null)
@@ -1492,7 +1489,7 @@ public class MapLogRepository implements SensLogRepository {
     }
 
     @Override
-    public Future<List<Alert>> findAlertsByDriverIdAndActionIdAndUnitId(long driverId, long actionId, long unitId, Set<AlertStatus> statusFilter, SortType sort) {
+    public Future<List<Alert>> findAlertsByEntityIdAndActionIdAndUnitId(long entityId, long actionId, long unitId, Set<AlertStatus> statusFilter, SortType sort) {
 
         if (statusFilter.isEmpty()) {
             statusFilter = Set.of(AlertStatus.CREATED, AlertStatus.INFORMED, AlertStatus.IN_PROCESS, AlertStatus.SOLVED);
@@ -1501,12 +1498,12 @@ public class MapLogRepository implements SensLogRepository {
         String statuses = String.join(",", statusFilter.stream().map(s -> "'"+s.name()+"'").collect(toSet()));
 
         return client.preparedQuery("SELECT a.id, a.message, a.time_stamp, a.status FROM maplog.alert AS a " +
-                        "JOIN maplog.driver_to_action dta on a.unit_id = dta.unit_id " +
-                        "WHERE dta.driver_id = $1 AND dta.action_id = $2 AND dta.unit_id = $3 " +
-                            "AND dta.from_time <= a.time_stamp AND (CASE WHEN dta.to_time IS NULL THEN now() ELSE dta.to_time END) >= a.time_stamp " +
+                        "JOIN maplog.event AS e on a.unit_id = e.unit_id " +
+                        "WHERE e.entity_id = $1 AND e.action_id = $2 AND e.unit_id = $3 " +
+                            "AND e.from_time <= a.time_stamp AND (CASE WHEN e.to_time IS NULL THEN now() ELSE e.to_time END) >= a.time_stamp " +
                             "AND a.status IN ("+statuses+")" +
                         "ORDER BY a.time_stamp "+sort.name())
-                .execute(Tuple.of(driverId, actionId, unitId))
+                .execute(Tuple.of(entityId, actionId, unitId))
                 .map(rs -> StreamSupport.stream(rs.spliterator(), false)
                         .map(r -> Alert.of(
                                 r.getLong("id"),

+ 14 - 14
src/main/java/cz/senslog/telemetry/database/repository/SensLogRepository.java

@@ -14,7 +14,7 @@ import java.util.Set;
 
 public interface SensLogRepository {
 
-    Future<Integer> updateEvent(DriverAction data);
+    Future<Integer> updateEvent(EntityAction data);
     Future<Long> updateEvent(long eventId, OffsetDateTime toTime);
     Future<Long> saveEvent(Event event);
     Future<List<Long>> saveEvents(List<Event> events);
@@ -33,9 +33,9 @@ public interface SensLogRepository {
     Future<List<CampaignUnit>> findUnitsByCampaignId(long campaignId);
     Future<Set<Long>> findUnitsIDByCampaignId(long campaignId);
     Future<CampaignUnit> findUnitByIdAndCampaignId(long unitId, long campaignId);
-    Future<Unit> findUnitByIdAndDriverId(long unitId, int driverId);
-    Future<Unit> findUnitByIdAndDriverIdAndActionId(long unitId, int driverId, int actionId);
-    Future<List<Unit>> findUnitsByDriverIdAndActionId(int driverId, int actionId);
+    Future<Unit> findUnitByIdAndEntityId(long unitId, int entityId);
+    Future<Unit> findUnitByIdAndEntityIdAndActionId(long unitId, int entityId, int actionId);
+    Future<List<Unit>> findUnitsByEntityIdAndActionId(int entityId, int actionId);
     Future<List<Long>> findUnitIdsByCampaignId(long campaignId);
 
     Future<List<Sensor>> allSensors();
@@ -56,20 +56,20 @@ public interface SensLogRepository {
     Future<List<Campaign>> findCampaignsByUnitId(long unitId, ZoneId zone);
 
 
-    Future<List<Driver>> allDrivers();
-    Future<Driver> findDriverById(int driverId);
-    Future<List<Driver>> findDriversByUnitId(long unitId);
+    Future<List<Entity>> allEntities();
+    Future<Entity> findEntityById(int entityId);
+    Future<List<Entity>> findEntitiesByUnitId(long unitId);
 
-    Future<List<Action>> findActionsByDriverIdAndUnitId(int driverId, long unitId);
-    Future<List<Action>> findActionsByDriverId(int driverId, OffsetDateTime from, OffsetDateTime to);
-    Future<Action> findActionByIdAndDriverId(int actionId, int driverId);
-    Future<Action> findActionByIdAndDriverIdAndUnitId(int actionId, int driverId, long unitId);
+    Future<List<Action>> findActionsByEntityIdAndUnitId(int entityId, long unitId);
+    Future<List<Action>> findActionsByEntityId(int entityId, OffsetDateTime from, OffsetDateTime to);
+    Future<Action> findActionByIdAndEntityId(int actionId, int entityId);
+    Future<Action> findActionByIdAndEntityIdAndUnitId(int actionId, int entityId, long unitId);
 
 
-    Future<List<Event>> findEventsByDriverIdAndUnitIdAndActionId(int driverId, long unitId, int actionId);
+    Future<List<Event>> findEventsByEntityIdAndUnitIdAndActionId(int entityId, long unitId, int actionId);
     Future<Event> findEventById(long eventId);
 
-    Future<List<Unit>> findUnitsByDriverId(int driverId, OffsetDateTime from, OffsetDateTime to);
+    Future<List<Unit>> findUnitsByEntityId(int entityId, OffsetDateTime from, OffsetDateTime to);
     Future<List<UnitTelemetry>> findObservationsByCampaignId(long campaignId, OffsetDateTime from, OffsetDateTime to, ZoneId zone, int offset, int limit, List<Filter> filters);
     Future<PagingRetrieve<List<UnitTelemetry>>> findObservationsByCampaignIdWithPaging(long campaignId, OffsetDateTime from, OffsetDateTime to, ZoneId zone, int offset, int limit, List<Filter> filters);
 
@@ -98,5 +98,5 @@ public interface SensLogRepository {
     Future<EventAlert> findAlertByIdAndEventId(long alertId, long eventId);
     Future<List<CampaignUnitAlert>> findAlertsByCampaignId(long campaignId, OffsetDateTime from, OffsetDateTime to, Set<AlertStatus> statusFilter, SortType sort);
     Future<List<UnitAlert>> findAlertsByCampaignIdAndUnitId(long campaignId, long unitId, OffsetDateTime from, OffsetDateTime to, Set<AlertStatus> statusFilter, SortType sort);
-    Future<List<Alert>> findAlertsByDriverIdAndActionIdAndUnitId(long driverId, long actionId, long unitId, Set<AlertStatus> statusFilter, SortType sort);
+    Future<List<Alert>> findAlertsByEntityIdAndActionIdAndUnitId(long entityId, long actionId, long unitId, Set<AlertStatus> statusFilter, SortType sort);
 }

+ 1 - 1
src/main/java/cz/senslog/telemetry/server/Fm4exSocketHandler.java

@@ -145,7 +145,7 @@ public class Fm4exSocketHandler {
             }
 
             OffsetDateTime timestamp = avlPacket.getTimestamp().atZone(UTC).toOffsetDateTime();
-            return repo.updateEvent(new DriverAction(contextUnit.getUnitId(), driverId, actionId, timestamp))
+            return repo.updateEvent(new EntityAction(contextUnit.getUnitId(), driverId, actionId, timestamp))
                     .map(res -> res > 0 ? SUCCESS : ERROR)
                     .onSuccess(res -> logger.info("[{}] AVL Driver Activity Packet was saved successfully.", socketId));
         }

+ 15 - 15
src/main/java/cz/senslog/telemetry/server/HttpVertxServer.java

@@ -93,7 +93,7 @@ public final class HttpVertxServer extends AbstractVerticle {
                     openAPIRouterBuilder.operation("unitIdGET").handler(apiHandler::unitIdGET);
                     openAPIRouterBuilder.operation("unitIdSensorsGET").handler(apiHandler::unitIdSensorsGET);
                     openAPIRouterBuilder.operation("unitIdCampaignsGET").handler(apiHandler::unitIdCampaignsGET);
-                    openAPIRouterBuilder.operation("unitIdDriversGET").handler(apiHandler::unitIdDriversGET);
+                    openAPIRouterBuilder.operation("unitIdEntitiesGET").handler(apiHandler::unitIdEntitiesGET);
 
                     openAPIRouterBuilder.operation("sensorsGET").handler(apiHandler::sensorsGET);
                     openAPIRouterBuilder.operation("sensorIdGET").handler(apiHandler::sensorIdGET);
@@ -103,18 +103,18 @@ public final class HttpVertxServer extends AbstractVerticle {
                     openAPIRouterBuilder.operation("phenomenonIdGET").handler(apiHandler::phenomenonIdGET);
                     openAPIRouterBuilder.operation("phenomenonIdSensorsGET").handler(apiHandler::phenomenonIdSensorsGET);
 
-                    openAPIRouterBuilder.operation("driversGET").handler(apiHandler::driversGET);
-                    openAPIRouterBuilder.operation("driverIdGET").handler(apiHandler::driverIdGET);
-                    openAPIRouterBuilder.operation("driverIdUnitsGET").handler(apiHandler::driverIdUnitsGET);
-                    openAPIRouterBuilder.operation("driverIdUnitIdGET").handler(apiHandler::driverIdUnitIdGET);
-                    openAPIRouterBuilder.operation("driverIdUnitIdActionsGET").handler(apiHandler::driverIdUnitIdActionsGET);
-                    openAPIRouterBuilder.operation("driverIdActionsGET").handler(apiHandler::driverIdActionsGET);
-                    openAPIRouterBuilder.operation("driverIdActionIdGET").handler(apiHandler::driverIdActionIdGET);
-                    openAPIRouterBuilder.operation("driverIdActionIdUnitsGET").handler(apiHandler::driverIdActionIdUnitsGET);
-                    openAPIRouterBuilder.operation("driverIdActionIdUnitIdGET").handler(apiHandler::driverIdActionIdUnitIdGET);
-                    openAPIRouterBuilder.operation("driverIdUnitIdActionIdGET").handler(apiHandler::driverIdUnitIdActionIdGET);
-                    openAPIRouterBuilder.operation("driverIdUnitIdActionIdEventsGET").handler(apiHandler::driverIdUnitIdActionIdEventsGET);
-                    openAPIRouterBuilder.operation("driverIdUnitIdActionIdEventsPOST").handler(apiHandler::driverIdUnitIdActionIdEventsPOST);
+                    openAPIRouterBuilder.operation("entitiesGET").handler(apiHandler::entitiesGET);
+                    openAPIRouterBuilder.operation("entityIdGET").handler(apiHandler::entityIdGET);
+                    openAPIRouterBuilder.operation("entityIdUnitsGET").handler(apiHandler::entityIdUnitsGET);
+                    openAPIRouterBuilder.operation("entityIdUnitIdGET").handler(apiHandler::entityIdUnitIdGET);
+                    openAPIRouterBuilder.operation("entityIdUnitIdActionsGET").handler(apiHandler::entityIdUnitIdActionsGET);
+                    openAPIRouterBuilder.operation("entityIdActionsGET").handler(apiHandler::entityIdActionsGET);
+                    openAPIRouterBuilder.operation("entityIdActionIdGET").handler(apiHandler::entityIdActionIdGET);
+                    openAPIRouterBuilder.operation("entityIdActionIdUnitsGET").handler(apiHandler::entityIdActionIdUnitsGET);
+                    openAPIRouterBuilder.operation("entityIdActionIdUnitIdGET").handler(apiHandler::entityIdActionIdUnitIdGET);
+                    openAPIRouterBuilder.operation("entityIdUnitIdActionIdGET").handler(apiHandler::entityIdUnitIdActionIdGET);
+                    openAPIRouterBuilder.operation("entityIdUnitIdActionIdEventsGET").handler(apiHandler::entityIdUnitIdActionIdEventsGET);
+                    openAPIRouterBuilder.operation("entityIdUnitIdActionIdEventsPOST").handler(apiHandler::entityIdUnitIdActionIdEventsPOST);
 
                     openAPIRouterBuilder.operation("eventIdGET").handler(apiHandler::eventIdGET);
                     openAPIRouterBuilder.operation("eventIdPUT").handler(apiHandler::eventIdPUT);
@@ -125,11 +125,11 @@ public final class HttpVertxServer extends AbstractVerticle {
                     openAPIRouterBuilder.operation("alertIdPUT").handler(apiHandler::alertIdPUT);
                     openAPIRouterBuilder.operation("alertIdDELETE").handler(apiHandler::alertIdDELETE);
                     openAPIRouterBuilder.operation("eventIdAlertsGET").handler(apiHandler::eventIdAlertsGET);
-                    openAPIRouterBuilder.operation("driverIdActionIdUnitIdAlertIdGET").handler(apiHandler::driverIdActionIdUnitIdAlertIdGET);
+                    openAPIRouterBuilder.operation("entityIdActionIdUnitIdAlertIdGET").handler(apiHandler::entityIdActionIdUnitIdAlertIdGET);
                     openAPIRouterBuilder.operation("campaignIdUnitsAlertsGET").handler(apiHandler::campaignIdUnitsAlertsGET);
                     openAPIRouterBuilder.operation("campaignIdUnitsAlertsPOST").handler(apiHandler::campaignIdUnitsAlertsPOST);
                     openAPIRouterBuilder.operation("campaignIdUnitIdAlertsGET").handler(apiHandler::campaignIdUnitIdAlertsGET);
-                    openAPIRouterBuilder.operation("driverIdActionIdUnitIdAlertsGET").handler(apiHandler::driverIdActionIdUnitIdAlertsGET);
+                    openAPIRouterBuilder.operation("entityIdActionIdUnitIdAlertsGET").handler(apiHandler::entityIdActionIdUnitIdAlertsGET);
 
                     Router mainRouter = openAPIRouterBuilder.createRouter();
 

+ 66 - 66
src/main/java/cz/senslog/telemetry/server/ws/OpenAPIHandler.java

@@ -611,7 +611,7 @@ public class OpenAPIHandler {
                                 "self@NavigationLink", String.format("%s/units/%d", host, u.getUnitId()),
                                 "Sensors@NavigationLink", String.format("%s/units/%d/sensors", host, u.getUnitId()),
                                 "Campaigns@NavigationLink", String.format("%s/units/%d/campaigns", host, u.getUnitId()),
-                                "Drivers@NavigationLink", String.format("%s/units/%d/drivers", host, u.getUnitId())
+                                "Entities@NavigationLink", String.format("%s/units/%d/entities", host, u.getUnitId())
                         ) : JsonObject.of()).mergeIn(JsonObject.of(
                                 "unitId", u.getUnitId(),
                                 "name", u.getName(),
@@ -1006,16 +1006,16 @@ public class OpenAPIHandler {
         }
     }
 
-    public void driversGET(RoutingContext rc) {
+    public void entitiesGET(RoutingContext rc) {
         String host =  hostURLFull(rc.request());
 
         List<String> paramNavigationLinks = rc.queryParam("navigationLinks");
         boolean navigationLinks = paramNavigationLinks.isEmpty() ? DEFAULT_NAVIGATION_LINKS : parseBoolean(paramNavigationLinks.get(0));
 
-        repo.allDrivers()
+        repo.allEntities()
                 .onSuccess(data -> rc.response().end(new JsonArray(
                         data.stream().map(d -> (navigationLinks ? JsonObject.of(
-                                "Driver@NavigationLink", String.format("%s/drivers/%d", host, d.getId())
+                                "Entity@NavigationLink", String.format("%s/entities/%d", host, d.getId())
                         ) : JsonObject.of()).mergeIn(JsonObject.of(
                                 "id", d.getId(),
                                 "name", d.getName()
@@ -1023,19 +1023,19 @@ public class OpenAPIHandler {
                 .onFailure(rc::fail);
     }
 
-    public void driverIdGET(RoutingContext rc) {
+    public void entityIdGET(RoutingContext rc) {
         String host =  hostURLFull(rc.request());
 
-        int driverId = Integer.parseInt(rc.pathParam("driverId"));
+        int entityId = Integer.parseInt(rc.pathParam("entityId"));
 
         List<String> paramNavigationLinks = rc.queryParam("navigationLinks");
         boolean navigationLinks = paramNavigationLinks.isEmpty() ? DEFAULT_NAVIGATION_LINKS : parseBoolean(paramNavigationLinks.get(0));
 
-        repo.findDriverById(driverId)
+        repo.findEntityById(entityId)
                 .onSuccess(d -> rc.response().end((navigationLinks ? JsonObject.of(
-                                "self@NavigationLink", String.format("%s/drivers/%d", host, d.getId()),
-                                "Units@NavigationLink", String.format("%s/drivers/%d/units", host, d.getId()),
-                                "Actions@NavigationLink", String.format("%s/drivers/%d/actions", host, d.getId())
+                                "self@NavigationLink", String.format("%s/entities/%d", host, d.getId()),
+                                "Units@NavigationLink", String.format("%s/entities/%d/units", host, d.getId()),
+                                "Actions@NavigationLink", String.format("%s/entities/%d/actions", host, d.getId())
                         ) : JsonObject.of()).mergeIn(JsonObject.of(
                                 "id", d.getId(),
                                 "name", d.getName()
@@ -1043,10 +1043,10 @@ public class OpenAPIHandler {
                 .onFailure(rc::fail);
     }
 
-    public void driverIdUnitsGET(RoutingContext rc) {
+    public void entityIdUnitsGET(RoutingContext rc) {
         String host =  hostURLFull(rc.request());
 
-        int driverId = Integer.parseInt(rc.pathParam("driverId"));
+        int entityId = Integer.parseInt(rc.pathParam("entityId"));
 
         List<String> paramFrom = rc.queryParam("from");
         OffsetDateTime from = TernaryCondition.<OffsetDateTime>ternaryIf(paramFrom::isEmpty, () -> null, () -> OffsetDateTime.parse(paramFrom.get(0)));
@@ -1057,10 +1057,10 @@ public class OpenAPIHandler {
         List<String> paramNavigationLinks = rc.queryParam("navigationLinks");
         boolean navigationLinks = paramNavigationLinks.isEmpty() ? DEFAULT_NAVIGATION_LINKS : parseBoolean(paramNavigationLinks.get(0));
 
-        repo.findUnitsByDriverId(driverId, from, to)
+        repo.findUnitsByEntityId(entityId, from, to)
                 .onSuccess(units -> rc.response().end(new JsonArray(
                         units.stream().map(u -> (navigationLinks ? JsonObject.of(
-                                "DriverUnit@NavigationLink", String.format("%s/drivers/%d/units/%d",host, driverId, u.getUnitId())
+                                "EntityUnit@NavigationLink", String.format("%s/entities/%d/units/%d",host, entityId, u.getUnitId())
                         ) : JsonObject.of()).mergeIn(JsonObject.of(
                                 "unitId", u.getUnitId(),
                                 "name", u.getName(),
@@ -1069,20 +1069,20 @@ public class OpenAPIHandler {
                 .onFailure(rc::fail);
     }
 
-    public void driverIdUnitIdGET(RoutingContext rc) {
+    public void entityIdUnitIdGET(RoutingContext rc) {
         String host =  hostURLFull(rc.request());
 
-        int driverId = Integer.parseInt(rc.pathParam("driverId"));
+        int entityId = Integer.parseInt(rc.pathParam("entityId"));
         long unitId = Long.parseLong(rc.pathParam("unitId"));
 
         List<String> paramNavigationLinks = rc.queryParam("navigationLinks");
         boolean navigationLinks = paramNavigationLinks.isEmpty() ? DEFAULT_NAVIGATION_LINKS : parseBoolean(paramNavigationLinks.get(0));
 
-        repo.findUnitByIdAndDriverId(unitId, driverId)
+        repo.findUnitByIdAndEntityId(unitId, entityId)
                 .onSuccess(u -> rc.response().end((navigationLinks ? JsonObject.of(
-                                "self@NavigationLink", String.format("%s/drivers/%d/units/%d", host, driverId, u.getUnitId()),
+                                "self@NavigationLink", String.format("%s/entities/%d/units/%d", host, entityId, u.getUnitId()),
                                 "Unit@NavigationLink", String.format("%s/units/%d", host, u.getUnitId()),
-                                "Actions@NavigationLink", String.format("%s/drivers/%d/units/%d/actions", host, driverId, u.getUnitId())
+                                "Actions@NavigationLink", String.format("%s/entities/%d/units/%d/actions", host, entityId, u.getUnitId())
                         ) : JsonObject.of()).mergeIn(JsonObject.of(
                                 "unitId", u.getUnitId(),
                                 "name", u.getName(),
@@ -1092,19 +1092,19 @@ public class OpenAPIHandler {
                 .onFailure(rc::fail);
     }
 
-    public void driverIdUnitIdActionsGET(RoutingContext rc) {
+    public void entityIdUnitIdActionsGET(RoutingContext rc) {
         String host =  hostURLFull(rc.request());
 
-        int driverId = Integer.parseInt(rc.pathParam("driverId"));
+        int entityId = Integer.parseInt(rc.pathParam("entityId"));
         long unitId = Long.parseLong(rc.pathParam("unitId"));
 
         List<String> paramNavigationLinks = rc.queryParam("navigationLinks");
         boolean navigationLinks = paramNavigationLinks.isEmpty() ? DEFAULT_NAVIGATION_LINKS : parseBoolean(paramNavigationLinks.get(0));
 
-        repo.findActionsByDriverIdAndUnitId(driverId, unitId)
+        repo.findActionsByEntityIdAndUnitId(entityId, unitId)
                 .onSuccess(actions -> rc.response().end(new JsonArray(
                         actions.stream().map(a -> (navigationLinks ? JsonObject.of(
-                                "DriverUntAction@NavigationLink", String.format("%s/drivers/%d/units/%d/actions/%d",host, driverId, unitId, a.getId())
+                                "EntityUntAction@NavigationLink", String.format("%s/entities/%d/units/%d/actions/%d",host, entityId, unitId, a.getId())
                         ) : JsonObject.of()).mergeIn(JsonObject.of(
                                 "id", a.getId(),
                                 "name", a.getName()
@@ -1112,10 +1112,10 @@ public class OpenAPIHandler {
                 .onFailure(rc::fail);
     }
 
-    public void driverIdActionsGET(RoutingContext rc) {
+    public void entityIdActionsGET(RoutingContext rc) {
         String host =  hostURLFull(rc.request());
 
-        int driverId = Integer.parseInt(rc.pathParam("driverId"));
+        int entityId = Integer.parseInt(rc.pathParam("entityId"));
 
         List<String> paramFrom = rc.queryParam("from");
         OffsetDateTime from = TernaryCondition.<OffsetDateTime>ternaryIf(paramFrom::isEmpty, () -> null, () -> OffsetDateTime.parse(paramFrom.get(0)));
@@ -1126,10 +1126,10 @@ public class OpenAPIHandler {
         List<String> paramNavigationLinks = rc.queryParam("navigationLinks");
         boolean navigationLinks = paramNavigationLinks.isEmpty() ? DEFAULT_NAVIGATION_LINKS : parseBoolean(paramNavigationLinks.get(0));
 
-        repo.findActionsByDriverId(driverId, from, to)
+        repo.findActionsByEntityId(entityId, from, to)
                 .onSuccess(actions -> rc.response().end(new JsonArray(
                         actions.stream().map(a -> (navigationLinks ? JsonObject.of(
-                                "DriverAction@NavigationLink", String.format("%s/drivers/%d/actions/%d",host, driverId, a.getId())
+                                "EntityAction@NavigationLink", String.format("%s/entities/%d/actions/%d",host, entityId, a.getId())
                         ) : JsonObject.of()).mergeIn(JsonObject.of(
                                 "id", a.getId(),
                                 "name", a.getName()
@@ -1137,20 +1137,20 @@ public class OpenAPIHandler {
                 .onFailure(rc::fail);
     }
 
-    public void driverIdActionIdGET(RoutingContext rc) {
+    public void entityIdActionIdGET(RoutingContext rc) {
         String host =  hostURLFull(rc.request());
 
-        int driverId = Integer.parseInt(rc.pathParam("driverId"));
+        int entityId = Integer.parseInt(rc.pathParam("entityId"));
         int actionId = Integer.parseInt(rc.pathParam("actionId"));
 
         List<String> paramNavigationLinks = rc.queryParam("navigationLinks");
         boolean navigationLinks = paramNavigationLinks.isEmpty() ? DEFAULT_NAVIGATION_LINKS : parseBoolean(paramNavigationLinks.get(0));
 
-        repo.findActionByIdAndDriverId(actionId, driverId)
+        repo.findActionByIdAndEntityId(actionId, entityId)
                 .onSuccess(a -> rc.response().end((navigationLinks ? JsonObject.of(
-                                "self@NavigationLink", String.format("%s/drivers/%d/actions/%d", host, driverId, a.getId()),
-                                "Driver@NavigationLink", String.format("%s/drivers/%d", host, driverId),
-                                "Units@NavigationLink", String.format("%s/drivers/%d/actions/%d/units", host, driverId, a.getId())
+                                "self@NavigationLink", String.format("%s/entities/%d/actions/%d", host, entityId, a.getId()),
+                                "Entity@NavigationLink", String.format("%s/entities/%d", host, entityId),
+                                "Units@NavigationLink", String.format("%s/entities/%d/actions/%d/units", host, entityId, a.getId())
                         ) : JsonObject.of()).mergeIn(JsonObject.of(
                                 "id", a.getId(),
                                 "name", a.getName()
@@ -1158,19 +1158,19 @@ public class OpenAPIHandler {
                 .onFailure(rc::fail);
     }
 
-    public void driverIdActionIdUnitsGET(RoutingContext rc) {
+    public void entityIdActionIdUnitsGET(RoutingContext rc) {
         String host =  hostURLFull(rc.request());
 
-        int driverId = Integer.parseInt(rc.pathParam("driverId"));
+        int entityId = Integer.parseInt(rc.pathParam("entityId"));
         int actionId = Integer.parseInt(rc.pathParam("actionId"));
 
         List<String> paramNavigationLinks = rc.queryParam("navigationLinks");
         boolean navigationLinks = paramNavigationLinks.isEmpty() ? DEFAULT_NAVIGATION_LINKS : parseBoolean(paramNavigationLinks.get(0));
 
-        repo.findUnitsByDriverIdAndActionId(driverId, actionId)
+        repo.findUnitsByEntityIdAndActionId(entityId, actionId)
                 .onSuccess(units -> rc.response().end(new JsonArray(
                         units.stream().map(u -> (navigationLinks ? JsonObject.of(
-                                "DriverActionUnit@NavigationLink", String.format("%s/drivers/%d/actions/%d/units/%d",host, driverId, actionId, u.getUnitId())
+                                "EntityActionUnit@NavigationLink", String.format("%s/entities/%d/actions/%d/units/%d",host, entityId, actionId, u.getUnitId())
                         ) : JsonObject.of()).mergeIn(JsonObject.of(
                                 "unitId", u.getUnitId(),
                                 "name", u.getName(),
@@ -1179,22 +1179,22 @@ public class OpenAPIHandler {
                 .onFailure(rc::fail);
     }
 
-    public void driverIdActionIdUnitIdGET(RoutingContext rc) {
+    public void entityIdActionIdUnitIdGET(RoutingContext rc) {
         String host =  hostURLFull(rc.request());
 
-        int driverId = Integer.parseInt(rc.pathParam("driverId"));
+        int entityId = Integer.parseInt(rc.pathParam("entityId"));
         int actionId = Integer.parseInt(rc.pathParam("actionId"));
         long unitId = Integer.parseInt(rc.pathParam("unitId"));
 
         List<String> paramNavigationLinks = rc.queryParam("navigationLinks");
         boolean navigationLinks = paramNavigationLinks.isEmpty() ? DEFAULT_NAVIGATION_LINKS : parseBoolean(paramNavigationLinks.get(0));
 
-        repo.findUnitByIdAndDriverIdAndActionId(unitId, driverId, actionId)
+        repo.findUnitByIdAndEntityIdAndActionId(unitId, entityId, actionId)
                 .onSuccess(u -> rc.response().end((navigationLinks ? JsonObject.of(
-                                "self@NavigationLink", String.format("%s/drivers/%d/actions/%d/units/%d", host, driverId, actionId, u.getUnitId()),
+                                "self@NavigationLink", String.format("%s/entities/%d/actions/%d/units/%d", host, entityId, actionId, u.getUnitId()),
                                 "Unit@NavigationLink", String.format("%s/units/%d", host, u.getUnitId()),
-                                "DriverAction@NavigationLink", String.format("%s/drivers/%d/actions/%d", host, driverId, actionId),
-                                "Events@NavigationLink", String.format("%s/drivers/%d/units/%d/actions/%d/events", host, driverId, u.getUnitId(), actionId)
+                                "EntityAction@NavigationLink", String.format("%s/entities/%d/actions/%d", host, entityId, actionId),
+                                "Events@NavigationLink", String.format("%s/entities/%d/units/%d/actions/%d/events", host, entityId, u.getUnitId(), actionId)
                         ) : JsonObject.of()).mergeIn(JsonObject.of(
                                 "unitId", u.getUnitId(),
                                 "name", u.getName(),
@@ -1204,22 +1204,22 @@ public class OpenAPIHandler {
                 .onFailure(rc::fail);
     }
 
-    public void driverIdUnitIdActionIdGET(RoutingContext rc) {
+    public void entityIdUnitIdActionIdGET(RoutingContext rc) {
         String host =  hostURLFull(rc.request());
 
-        int driverId = Integer.parseInt(rc.pathParam("driverId"));
+        int entityId = Integer.parseInt(rc.pathParam("entityId"));
         int actionId = Integer.parseInt(rc.pathParam("actionId"));
         long unitId = Integer.parseInt(rc.pathParam("unitId"));
 
         List<String> paramNavigationLinks = rc.queryParam("navigationLinks");
         boolean navigationLinks = paramNavigationLinks.isEmpty() ? DEFAULT_NAVIGATION_LINKS : parseBoolean(paramNavigationLinks.get(0));
 
-        repo.findActionByIdAndDriverIdAndUnitId(actionId, driverId, unitId)
+        repo.findActionByIdAndEntityIdAndUnitId(actionId, entityId, unitId)
                 .onSuccess(a -> rc.response().end((navigationLinks ? JsonObject.of(
-                                "self@NavigationLink", String.format("%s/drivers/%d/units/%d/actions/%d", host, driverId, unitId, a.getId()),
-                                "Driver@NavigationLink", String.format("%s/drivers/%d", host, driverId),
-                                "DriverUnit@NavigationLink", String.format("%s/drivers/%d/units/%d", host, driverId, unitId),
-                                "Events@NavigationLink", String.format("%s/drivers/%d/units/%d/actions/%d/events", host, driverId, unitId, a.getId())
+                                "self@NavigationLink", String.format("%s/entities/%d/units/%d/actions/%d", host, entityId, unitId, a.getId()),
+                                "Entity@NavigationLink", String.format("%s/entities/%d", host, entityId),
+                                "EntityUnit@NavigationLink", String.format("%s/entities/%d/units/%d", host, entityId, unitId),
+                                "Events@NavigationLink", String.format("%s/entities/%d/units/%d/actions/%d/events", host, entityId, unitId, a.getId())
                         ) : JsonObject.of()).mergeIn(JsonObject.of(
                                 "id", a.getId(),
                                 "name", a.getName()
@@ -1227,10 +1227,10 @@ public class OpenAPIHandler {
                 .onFailure(rc::fail);
     }
 
-    public void driverIdUnitIdActionIdEventsGET(RoutingContext rc) {
+    public void entityIdUnitIdActionIdEventsGET(RoutingContext rc) {
         String host =  hostURLFull(rc.request());
 
-        int driverId = Integer.parseInt(rc.pathParam("driverId"));
+        int entityId = Integer.parseInt(rc.pathParam("entityId"));
         int actionId = Integer.parseInt(rc.pathParam("actionId"));
         long unitId = Integer.parseInt(rc.pathParam("unitId"));
 
@@ -1240,7 +1240,7 @@ public class OpenAPIHandler {
         List<String> paramNavigationLinks = rc.queryParam("navigationLinks");
         boolean navigationLinks = paramNavigationLinks.isEmpty() ? DEFAULT_NAVIGATION_LINKS : parseBoolean(paramNavigationLinks.get(0));
 
-        repo.findEventsByDriverIdAndUnitIdAndActionId(driverId, unitId, actionId)
+        repo.findEventsByEntityIdAndUnitIdAndActionId(entityId, unitId, actionId)
                 .onSuccess(events -> rc.response().end(new JsonArray(
                         events.stream().map(e -> (navigationLinks ? JsonObject.of(
                                 "Event@NavigationLink", String.format("%s/events/%d",host, e.getId())
@@ -1267,14 +1267,14 @@ public class OpenAPIHandler {
         repo.findEventById(eventId)
                 .onSuccess(e -> rc.response().end((navigationLinks ? JsonObject.of(
                                 "self@NavigationLink", String.format("%s/events/%d", host, e.getId()),
-                                "Driver@NavigationLink", String.format("%s/drivers/%d", host, e.getDriverId()),
-                                "DriverUnit@NavigationLink", String.format("%s/drivers/%d/units/%d", host, e.getDriverId(), e.getUnitId()),
+                                "Entity@NavigationLink", String.format("%s/entities/%d", host, e.getEntityId()),
+                                "EntityUnit@NavigationLink", String.format("%s/entities/%d/units/%d", host, e.getEntityId(), e.getUnitId()),
                                 "Action@NavigationLink", String.format("%s/actions/%d", host, e.getActionId()),
                                 "Observations@NavigationLink", String.format("%s/events/%d/observations", host, e.getId()),
                                 "Locations@NavigationLink", String.format("%s/events/%d/observations/locations", host, e.getId())
                         ) : JsonObject.of()).mergeIn(JsonObject.of(
                                 "id", e.getId(),
-                                "driverId", e.getDriverId(),
+                                "entityId", e.getEntityId(),
                                 "actionId", e.getActionId(),
                                 "unitId", e.getUnitId(),
                                 "status", e.getStatus(),
@@ -1513,7 +1513,7 @@ public class OpenAPIHandler {
         }
     }
 
-    public void unitIdDriversGET(RoutingContext rc) {
+    public void unitIdEntitiesGET(RoutingContext rc) {
         String host =  hostURLFull(rc.request());
 
         long unitId = Long.parseLong(rc.pathParam("unitId"));
@@ -1521,10 +1521,10 @@ public class OpenAPIHandler {
         List<String> paramNavigationLinks = rc.queryParam("navigationLinks");
         boolean navigationLinks = paramNavigationLinks.isEmpty() ? DEFAULT_NAVIGATION_LINKS : parseBoolean(paramNavigationLinks.get(0));
 
-        repo.findDriversByUnitId(unitId)
+        repo.findEntitiesByUnitId(unitId)
                 .onSuccess(data -> rc.response().end(new JsonArray(
                         data.stream().map(d -> (navigationLinks ? JsonObject.of(
-                                "Driver@NavigationLink", String.format("%s/drivers/%d", host, d.getId())
+                                "Entity@NavigationLink", String.format("%s/entities/%d", host, d.getId())
                         ) : JsonObject.of()).mergeIn(JsonObject.of(
                                 "id", d.getId(),
                                 "name", d.getName()
@@ -1686,7 +1686,7 @@ public class OpenAPIHandler {
                 .onFailure(rc::fail);
     }
 
-    public void driverIdActionIdUnitIdAlertIdGET(RoutingContext rc) {
+    public void entityIdActionIdUnitIdAlertIdGET(RoutingContext rc) {
         String host =  hostURLFull(rc.request());
 
         long eventId = Long.parseLong(rc.pathParam("eventId"));
@@ -1818,10 +1818,10 @@ public class OpenAPIHandler {
                 .onFailure(rc::fail);
     }
 
-    public void driverIdActionIdUnitIdAlertsGET(RoutingContext rc) {
+    public void entityIdActionIdUnitIdAlertsGET(RoutingContext rc) {
         String host =  hostURLFull(rc.request());
 
-        long driverId = Long.parseLong(rc.pathParam("driverId"));
+        long entityId = Long.parseLong(rc.pathParam("entityId"));
         long actionId = Long.parseLong(rc.pathParam("actionId"));
         long unitId = Long.parseLong(rc.pathParam("unitId"));
 
@@ -1836,7 +1836,7 @@ public class OpenAPIHandler {
         List<String> paramNavigationLinks = rc.queryParam("navigationLinks");
         boolean navigationLinks = paramNavigationLinks.isEmpty() ? DEFAULT_NAVIGATION_LINKS : parseBoolean(paramNavigationLinks.get(0));
 
-        repo.findAlertsByDriverIdAndActionIdAndUnitId(driverId, actionId, unitId, statuses, sort)
+        repo.findAlertsByEntityIdAndActionIdAndUnitId(entityId, actionId, unitId, statuses, sort)
                 .onSuccess(data -> rc.response().end(new JsonArray(
                         data.stream().map(a -> (navigationLinks ? JsonObject.of(
                                 "Alert@NavigationLink", String.format("%s/alerts/%d", host, a.getId())
@@ -1849,14 +1849,14 @@ public class OpenAPIHandler {
                 .onFailure(rc::fail);
     }
 
-    public void driverIdUnitIdActionIdEventsPOST(RoutingContext rc) {
+    public void entityIdUnitIdActionIdEventsPOST(RoutingContext rc) {
 
-        long driverId = Long.parseLong(rc.pathParam("driverId"));
+        long entityId = Long.parseLong(rc.pathParam("entityId"));
         long actionId = Long.parseLong(rc.pathParam("actionId"));
         long unitId = Long.parseLong(rc.pathParam("unitId"));
 
         final Function<JsonObject, Event> jsonToEvent = json -> Event.of(
-                driverId, actionId, unitId,
+                entityId, actionId, unitId,
                 OffsetDateTime.parse(json.getString("fromTime")),
                 json.containsKey("toTime") ? OffsetDateTime.parse(json.getString("toTime")) : null
         );

File diff ditekan karena terlalu besar
+ 191 - 191
src/main/resources/openAPISpec.yaml


+ 20 - 20
src/test/java/cz/senslog/telemetry/MockSensLogRepository.java

@@ -17,7 +17,7 @@ public class MockSensLogRepository implements SensLogRepository {
     private static final Instant BASE_INSTANT_TIMESTAMP = LocalDateTime.of(2023, 1, 1, 0, 0).toInstant(ZoneOffset.UTC);
 
     @Override
-    public Future<Integer> updateEvent(DriverAction data) {
+    public Future<Integer> updateEvent(EntityAction data) {
         return Future.succeededFuture(1);
     }
 
@@ -100,17 +100,17 @@ public class MockSensLogRepository implements SensLogRepository {
     }
 
     @Override
-    public Future<Unit> findUnitByIdAndDriverId(long unitId, int driverId) {
+    public Future<Unit> findUnitByIdAndEntityId(long unitId, int entityId) {
         return Future.succeededFuture(Unit.of(1000, "mock(name)", "mock(imei)", "mock(description)"));
     }
 
     @Override
-    public Future<Unit> findUnitByIdAndDriverIdAndActionId(long unitId, int driverId, int actionId) {
+    public Future<Unit> findUnitByIdAndEntityIdAndActionId(long unitId, int entityId, int actionId) {
         return Future.succeededFuture(Unit.of(1000, "mock(name)", "mock(imei)", "mock(description)"));
     }
 
     @Override
-    public Future<List<Unit>> findUnitsByDriverIdAndActionId(int driverId, int actionId) {
+    public Future<List<Unit>> findUnitsByEntityIdAndActionId(int entityId, int actionId) {
         return Future.succeededFuture(List.of(
                 Unit.of(1000, "mock(name)", "mock(imei)", "mock(description)"),
                 Unit.of(2000, "mock(name)", "mock(imei)", "mock(description)"),
@@ -240,29 +240,29 @@ public class MockSensLogRepository implements SensLogRepository {
     }
 
     @Override
-    public Future<List<Driver>> allDrivers() {
+    public Future<List<Entity>> allEntities() {
         return Future.succeededFuture(List.of(
-                Driver.of(1, "mock(name)"),
-                Driver.of(2, "mock(name)"),
-                Driver.of(3, "mock(name)")
+                Entity.of(1, "mock(name)"),
+                Entity.of(2, "mock(name)"),
+                Entity.of(3, "mock(name)")
         ));
     }
 
     @Override
-    public Future<Driver> findDriverById(int driverId) {
-        return Future.succeededFuture(Driver.of(1, "mock(name)"));
+    public Future<Entity> findEntityById(int entityId) {
+        return Future.succeededFuture(Entity.of(1, "mock(name)"));
     }
 
     @Override
-    public Future<List<Driver>> findDriversByUnitId(long unitId) {
+    public Future<List<Entity>> findEntitiesByUnitId(long unitId) {
         return Future.succeededFuture(List.of(
-                Driver.of(1, "mock(name)"),
-                Driver.of(2, "mock(name)"))
+                Entity.of(1, "mock(name)"),
+                Entity.of(2, "mock(name)"))
         );
     }
 
     @Override
-    public Future<List<Action>> findActionsByDriverIdAndUnitId(int driverId, long unitId) {
+    public Future<List<Action>> findActionsByEntityIdAndUnitId(int entityId, long unitId) {
         return Future.succeededFuture(List.of(
                 Action.of(1, "mock(name)"),
                 Action.of(2, "mock(name)"),
@@ -271,7 +271,7 @@ public class MockSensLogRepository implements SensLogRepository {
     }
 
     @Override
-    public Future<List<Action>> findActionsByDriverId(int driverId, OffsetDateTime from, OffsetDateTime to) {
+    public Future<List<Action>> findActionsByEntityId(int entityId, OffsetDateTime from, OffsetDateTime to) {
         return Future.succeededFuture(List.of(
                 Action.of(1, "mock(name)"),
                 Action.of(2, "mock(name)"),
@@ -280,17 +280,17 @@ public class MockSensLogRepository implements SensLogRepository {
     }
 
     @Override
-    public Future<Action> findActionByIdAndDriverId(int actionId, int driverId) {
+    public Future<Action> findActionByIdAndEntityId(int actionId, int entityId) {
         return Future.succeededFuture(Action.of(1, "mock(name)"));
     }
 
     @Override
-    public Future<Action> findActionByIdAndDriverIdAndUnitId(int actionId, int driverId, long unitId) {
+    public Future<Action> findActionByIdAndEntityIdAndUnitId(int actionId, int entityId, long unitId) {
         return Future.succeededFuture(Action.of(1, "mock(name)"));
     }
 
     @Override
-    public Future<List<Event>> findEventsByDriverIdAndUnitIdAndActionId(int driverId, long unitId, int actionId) {
+    public Future<List<Event>> findEventsByEntityIdAndUnitIdAndActionId(int entityId, long unitId, int actionId) {
         OffsetDateTime baseTimestamp = OffsetDateTime.ofInstant(BASE_INSTANT_TIMESTAMP, ZoneOffset.UTC);
         return Future.succeededFuture(List.of(
                 Event.of(1, 1, 1,1000, baseTimestamp, baseTimestamp.plusHours(8)),
@@ -306,7 +306,7 @@ public class MockSensLogRepository implements SensLogRepository {
     }
 
     @Override
-    public Future<List<Unit>> findUnitsByDriverId(int driverId, OffsetDateTime from, OffsetDateTime to) {
+    public Future<List<Unit>> findUnitsByEntityId(int entityId, OffsetDateTime from, OffsetDateTime to) {
         return Future.succeededFuture(List.of(
                 Unit.of(1000, "mock(name)", "mock(imei)", "mock(description)"),
                 Unit.of(2000, "mock(name)", "mock(imei)", "mock(description)"),
@@ -462,7 +462,7 @@ public class MockSensLogRepository implements SensLogRepository {
     }
 
     @Override
-    public Future<List<Alert>> findAlertsByDriverIdAndActionIdAndUnitId(long driverId, long actionId, long unitId, Set<AlertStatus> statusFilter, SortType sort) {
+    public Future<List<Alert>> findAlertsByEntityIdAndActionIdAndUnitId(long driverId, long actionId, long unitId, Set<AlertStatus> statusFilter, SortType sort) {
         OffsetDateTime baseTimestamp = OffsetDateTime.ofInstant(BASE_INSTANT_TIMESTAMP, ZoneOffset.UTC);
         return Future.succeededFuture(List.of(Alert.of(1, "mock(message)", baseTimestamp, AlertStatus.CREATED)));
     }

+ 2 - 2
src/test/java/cz/senslog/telemetry/database/repository/MapLogRepositoryTest.java

@@ -4,7 +4,7 @@ import cz.senslog.telemetry.BinaryDataSet;
 import cz.senslog.telemetry.DataSet;
 import cz.senslog.telemetry.TestPropertiesUtils;
 import cz.senslog.telemetry.app.PropertyConfig;
-import cz.senslog.telemetry.database.domain.DriverAction;
+import cz.senslog.telemetry.database.domain.EntityAction;
 import cz.senslog.telemetry.database.domain.Unit;
 import io.vertx.core.Vertx;
 import io.vertx.core.json.JsonObject;
@@ -83,7 +83,7 @@ class MapLogRepositoryTest {
         final int actionId = 8;
         final OffsetDateTime timestamp = OffsetDateTime.of(LocalDateTime.of(2023, 1, 10, 5, 33), ZoneOffset.UTC);
 
-        DriverAction dr = new DriverAction(1000, driverId, actionId, timestamp);
+        EntityAction dr = new EntityAction(1000, driverId, actionId, timestamp);
 
         repo.updateEvent(dr).onComplete(testContext.succeeding(res -> testContext.verify(() -> {
             assertThat(res).isGreaterThan(0);

+ 178 - 178
src/test/java/cz/senslog/telemetry/server/ws/OpenAPIHandlerTest.java

@@ -705,7 +705,7 @@ class OpenAPIHandlerTest {
                     assertThat(resJson.has("self@NavigationLink")).isEqualTo(navigationLinks);
                     assertThat(resJson.has("Sensors@NavigationLink")).isEqualTo(navigationLinks);
                     assertThat(resJson.has("Campaigns@NavigationLink")).isEqualTo(navigationLinks);
-                    assertThat(resJson.has("Drivers@NavigationLink")).isEqualTo(navigationLinks);
+                    assertThat(resJson.has("Entities@NavigationLink")).isEqualTo(navigationLinks);
                     testContext.completeNow();
                 })));
     }
@@ -874,11 +874,11 @@ class OpenAPIHandlerTest {
                 })));
     }
 
-    private static Stream<Arguments> unitIdDriversGET_dataSource() {
+    private static Stream<Arguments> unitIdEntitiesGET_dataSource() {
         return Stream.of(
                 Arguments.of(Future.succeededFuture(List.of(
-                                Driver.of(1, "mock(name)"),
-                                Driver.of(2, "mock(name)"))
+                                Entity.of(1, "mock(name)"),
+                                Entity.of(2, "mock(name)"))
                         ),
                         SUCCESS, JSON
                 ),
@@ -892,15 +892,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("unitIdDriversGET_dataSource")
-    @DisplayName("API Spec Test: unitIdDriversGET")
-    void unitIdDriversGET_bySpec(Future<List<Driver>> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("unitIdEntitiesGET_dataSource")
+    @DisplayName("API Spec Test: unitIdEntitiesGET")
+    void unitIdEntitiesGET_bySpec(Future<List<Entity>> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.findDriversByUnitId(anyLong())).thenReturn(dbFuture);
+        Mockito.when(repo.findEntitiesByUnitId(anyLong())).thenReturn(dbFuture);
 
-        Operation operation = OPEN_API.getOperationById("unitIdDriversGET");
+        Operation operation = OPEN_API.getOperationById("unitIdEntitiesGET");
         RequestOptions reqOpt = new RequestOptions()
-                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/units/1000/drivers")
+                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/units/1000/entities")
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -912,8 +912,8 @@ class OpenAPIHandlerTest {
                 })));
     }
 
-    private static Stream<Arguments> unitIdDriversGET_Params_dataSource() {
-        Future<List<Driver>> future = Future.succeededFuture(List.of(Driver.of(1, "mock(name)")));
+    private static Stream<Arguments> unitIdEntitiesGET_Params_dataSource() {
+        Future<List<Entity>> future = Future.succeededFuture(List.of(Entity.of(1, "mock(name)")));
         return Stream.of(
                 Arguments.of(future, false),
                 Arguments.of(future, true)
@@ -921,15 +921,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("unitIdDriversGET_Params_dataSource")
-    @DisplayName("API Params Test: unitIdDriversGET")
-    void unitIdDriversGET_byParams(Future<List<Driver>> dbFuture, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("unitIdEntitiesGET_Params_dataSource")
+    @DisplayName("API Params Test: unitIdEntitiesGET")
+    void unitIdEntitiesGET_byParams(Future<List<Entity>> dbFuture, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.findDriversByUnitId(anyLong())).thenReturn(dbFuture);
+        Mockito.when(repo.findEntitiesByUnitId(anyLong())).thenReturn(dbFuture);
 
         RequestOptions reqOpt = new RequestOptions()
                 .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI(
-                        String.format("/units/1000/drivers?navigationLinks=%s", navigationLinks))
+                        String.format("/units/1000/entities?navigationLinks=%s", navigationLinks))
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -940,7 +940,7 @@ class OpenAPIHandlerTest {
                     assertThat(res.size()).isEqualTo(1);
                     JsonNode resJson = res.get(0);
 
-                    assertThat(resJson.has("Driver@NavigationLink")).isEqualTo(navigationLinks);
+                    assertThat(resJson.has("Entity@NavigationLink")).isEqualTo(navigationLinks);
                     testContext.completeNow();
                 })));
     }
@@ -1366,13 +1366,13 @@ class OpenAPIHandlerTest {
                 })));
     }
 
-    private static Stream<Arguments> driversGET_dataSource() {
+    private static Stream<Arguments> entitiesGET_dataSource() {
         return Stream.of(
                 Arguments.of(
                         Future.succeededFuture(List.of(
-                                Driver.of(1, "mock(name)"),
-                                Driver.of(2, "mock(name)"),
-                                Driver.of(3, "mock(name)")
+                                Entity.of(1, "mock(name)"),
+                                Entity.of(2, "mock(name)"),
+                                Entity.of(3, "mock(name)")
                         )),
                         SUCCESS, JSON
                 ),
@@ -1386,15 +1386,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("driversGET_dataSource")
-    @DisplayName("API Spec Test: driversGET")
-    void driversGET_bySpec(Future<List<Driver>> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("entitiesGET_dataSource")
+    @DisplayName("API Spec Test: entitiesGET")
+    void entitiesGET_bySpec(Future<List<Entity>> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.allDrivers()).thenReturn(dbFuture);
+        Mockito.when(repo.allEntities()).thenReturn(dbFuture);
 
-        Operation operation = OPEN_API.getOperationById("driversGET");
+        Operation operation = OPEN_API.getOperationById("entitiesGET");
         RequestOptions reqOpt = new RequestOptions()
-                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/drivers")
+                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/entities")
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -1406,8 +1406,8 @@ class OpenAPIHandlerTest {
                 })));
     }
 
-    private static Stream<Arguments> driversGET_Params_dataSource() {
-        Future<List<Driver>> future = Future.succeededFuture(List.of(Driver.of(1, "mock(name)")));
+    private static Stream<Arguments> entitiesGET_Params_dataSource() {
+        Future<List<Entity>> future = Future.succeededFuture(List.of(Entity.of(1, "mock(name)")));
         return Stream.of(
                 Arguments.of(future, false),
                 Arguments.of(future, true)
@@ -1415,15 +1415,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("driversGET_Params_dataSource")
-    @DisplayName("API Params Test: driversGET")
-    void driversGET_byParams(Future<List<Driver>> dbFuture, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("entitiesGET_Params_dataSource")
+    @DisplayName("API Params Test: entitiesGET")
+    void entitiesGET_byParams(Future<List<Entity>> dbFuture, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.allDrivers()).thenReturn(dbFuture);
+        Mockito.when(repo.allEntities()).thenReturn(dbFuture);
 
         RequestOptions reqOpt = new RequestOptions()
                 .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI(
-                        String.format("/drivers?navigationLinks=%s", navigationLinks))
+                        String.format("/entities?navigationLinks=%s", navigationLinks))
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -1434,15 +1434,15 @@ class OpenAPIHandlerTest {
                     assertThat(res.size()).isEqualTo(1);
                     JsonNode resJson = res.get(0);
 
-                    assertThat(resJson.has("Driver@NavigationLink")).isEqualTo(navigationLinks);
+                    assertThat(resJson.has("Entity@NavigationLink")).isEqualTo(navigationLinks);
                     testContext.completeNow();
                 })));
     }
 
-    private static Stream<Arguments> driverIdGET_dataSource() {
+    private static Stream<Arguments> entityIdGET_dataSource() {
         return Stream.of(
                 Arguments.of(
-                        Future.succeededFuture(Driver.of(1, "mock(name)")),
+                        Future.succeededFuture(Entity.of(1, "mock(name)")),
                         SUCCESS, JSON
                 ),
                 Arguments.of(
@@ -1452,15 +1452,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("driverIdGET_dataSource")
-    @DisplayName("API Spec Test: driverIdGET")
-    void driverIdGET_bySpec(Future<Driver> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("entityIdGET_dataSource")
+    @DisplayName("API Spec Test: entityIdGET")
+    void entityIdGET_bySpec(Future<Entity> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.findDriverById(anyInt())).thenReturn(dbFuture);
+        Mockito.when(repo.findEntityById(anyInt())).thenReturn(dbFuture);
 
-        Operation operation = OPEN_API.getOperationById("driverIdGET");
+        Operation operation = OPEN_API.getOperationById("entityIdGET");
         RequestOptions reqOpt = new RequestOptions()
-                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/drivers/1")
+                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/entities/1")
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -1472,8 +1472,8 @@ class OpenAPIHandlerTest {
                 })));
     }
 
-    private static Stream<Arguments> driverIdGET_Params_dataSource() {
-        Future<Driver> future = Future.succeededFuture(Driver.of(1, "mock(name)"));
+    private static Stream<Arguments> entityIdGET_Params_dataSource() {
+        Future<Entity> future = Future.succeededFuture(Entity.of(1, "mock(name)"));
         return Stream.of(
                 Arguments.of(future, false),
                 Arguments.of(future, true)
@@ -1481,15 +1481,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("driverIdGET_Params_dataSource")
-    @DisplayName("API Params Test: driverIdGET")
-    void driverIdGET_byParams(Future<Driver> dbFuture, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("entityIdGET_Params_dataSource")
+    @DisplayName("API Params Test: entityIdGET")
+    void entityIdGET_byParams(Future<Entity> dbFuture, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.findDriverById(anyInt())).thenReturn(dbFuture);
+        Mockito.when(repo.findEntityById(anyInt())).thenReturn(dbFuture);
 
         RequestOptions reqOpt = new RequestOptions()
                 .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI(
-                        String.format("/drivers/1?navigationLinks=%s", navigationLinks))
+                        String.format("/entities/1?navigationLinks=%s", navigationLinks))
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -1505,7 +1505,7 @@ class OpenAPIHandlerTest {
                 })));
     }
 
-    private static Stream<Arguments> driverIdUnitsGET_dataSource() {
+    private static Stream<Arguments> entityIdUnitsGET_dataSource() {
         return Stream.of(
                 Arguments.of(
                         Future.succeededFuture(List.of(
@@ -1525,15 +1525,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("driverIdUnitsGET_dataSource")
-    @DisplayName("API Spec Test: driverIdUnitsGET")
-    void driverIdUnitsGET_bySpec(Future<List<Unit>> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("entityIdUnitsGET_dataSource")
+    @DisplayName("API Spec Test: entityIdUnitsGET")
+    void entityIdUnitsGET_bySpec(Future<List<Unit>> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.findUnitsByDriverId(anyInt(), any(), any())).thenReturn(dbFuture);
+        Mockito.when(repo.findUnitsByEntityId(anyInt(), any(), any())).thenReturn(dbFuture);
 
-        Operation operation = OPEN_API.getOperationById("driverIdUnitsGET");
+        Operation operation = OPEN_API.getOperationById("entityIdUnitsGET");
         RequestOptions reqOpt = new RequestOptions()
-                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/drivers/1/units")
+                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/entities/1/units")
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -1545,7 +1545,7 @@ class OpenAPIHandlerTest {
                 })));
     }
 
-    private static Stream<Arguments> driverIdUnitsGET_Params_dataSource() {
+    private static Stream<Arguments> entityIdUnitsGET_Params_dataSource() {
         Future<List<Unit>> future = Future.succeededFuture(List.of(Unit.of(1000, "mock(name)", "mock(imei)", "mock(description)")));
         return Stream.of(
                 Arguments.of(future,
@@ -1562,15 +1562,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("driverIdUnitsGET_Params_dataSource")
-    @DisplayName("API Params Test: driverIdUnitsGET")
-    void driverIdUnitsGET_byParams(Future<List<Unit>> dbFuture, String from, String to, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("entityIdUnitsGET_Params_dataSource")
+    @DisplayName("API Params Test: entityIdUnitsGET")
+    void entityIdUnitsGET_byParams(Future<List<Unit>> dbFuture, String from, String to, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.findUnitsByDriverId(anyInt(), any(), any())).thenReturn(dbFuture);
+        Mockito.when(repo.findUnitsByEntityId(anyInt(), any(), any())).thenReturn(dbFuture);
 
         RequestOptions reqOpt = new RequestOptions()
                 .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI(
-                        String.format("/drivers/1/units?from=%s&to=%s&navigationLinks=%s", from, to, navigationLinks))
+                        String.format("/entities/1/units?from=%s&to=%s&navigationLinks=%s", from, to, navigationLinks))
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -1581,12 +1581,12 @@ class OpenAPIHandlerTest {
                     assertThat(res.size()).isEqualTo(1);
                     JsonNode resJson = res.get(0);
 
-                    assertThat(resJson.has("DriverUnit@NavigationLink")).isEqualTo(navigationLinks);
+                    assertThat(resJson.has("EntityUnit@NavigationLink")).isEqualTo(navigationLinks);
                     testContext.completeNow();
                 })));
     }
 
-    private static Stream<Arguments> driverIdUnitIdGET_dataSource() {
+    private static Stream<Arguments> entityIdUnitIdGET_dataSource() {
         return Stream.of(
                 Arguments.of(
                         Future.succeededFuture(Unit.of(1000, "mock(name)", "mock(imei)", "mock(description)")),
@@ -1599,15 +1599,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("driverIdUnitIdGET_dataSource")
-    @DisplayName("API Spec Test: driverIdUnitIdGET")
-    void driverIdUnitIdGET_bySpec(Future<Unit> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("entityIdUnitIdGET_dataSource")
+    @DisplayName("API Spec Test: entityIdUnitIdGET")
+    void entityIdUnitIdGET_bySpec(Future<Unit> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.findUnitByIdAndDriverId(anyLong(), anyInt())).thenReturn(dbFuture);
+        Mockito.when(repo.findUnitByIdAndEntityId(anyLong(), anyInt())).thenReturn(dbFuture);
 
-        Operation operation = OPEN_API.getOperationById("driverIdUnitIdGET");
+        Operation operation = OPEN_API.getOperationById("entityIdUnitIdGET");
         RequestOptions reqOpt = new RequestOptions()
-                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/drivers/1/units/1000")
+                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/entities/1/units/1000")
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -1619,7 +1619,7 @@ class OpenAPIHandlerTest {
                 })));
     }
 
-    private static Stream<Arguments> driverIdUnitIdGET_Params_dataSource() {
+    private static Stream<Arguments> entityIdUnitIdGET_Params_dataSource() {
         Future<Unit> future = Future.succeededFuture(Unit.of(1000, "mock(name)", "mock(imei)", "mock(description)"));
         return Stream.of(
                 Arguments.of(future, false),
@@ -1628,15 +1628,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("driverIdUnitIdGET_Params_dataSource")
-    @DisplayName("API Params Test: driverIdUnitIdGET")
-    void driverIdUnitIdGET_byParams(Future<Unit> dbFuture, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("entityIdUnitIdGET_Params_dataSource")
+    @DisplayName("API Params Test: entityIdUnitIdGET")
+    void entityIdUnitIdGET_byParams(Future<Unit> dbFuture, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.findUnitByIdAndDriverId(anyLong(), anyInt())).thenReturn(dbFuture);
+        Mockito.when(repo.findUnitByIdAndEntityId(anyLong(), anyInt())).thenReturn(dbFuture);
 
         RequestOptions reqOpt = new RequestOptions()
                 .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI(
-                        String.format("/drivers/1/units/1000?navigationLinks=%s", navigationLinks))
+                        String.format("/entities/1/units/1000?navigationLinks=%s", navigationLinks))
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -1652,7 +1652,7 @@ class OpenAPIHandlerTest {
                 })));
     }
 
-    private static Stream<Arguments> driverIdUnitIdActionsGET_dataSource() {
+    private static Stream<Arguments> entityIdUnitIdActionsGET_dataSource() {
         return Stream.of(
                 Arguments.of(
                         Future.succeededFuture(List.of(
@@ -1672,15 +1672,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("driverIdUnitIdActionsGET_dataSource")
-    @DisplayName("API Spec Test: driverIdUnitIdActionsGET")
-    void driverIdUnitIdActionsGET_bySpec(Future<List<Action>> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("entityIdUnitIdActionsGET_dataSource")
+    @DisplayName("API Spec Test: entityIdUnitIdActionsGET")
+    void entityIdUnitIdActionsGET_bySpec(Future<List<Action>> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.findActionsByDriverIdAndUnitId(anyInt(), anyLong())).thenReturn(dbFuture);
+        Mockito.when(repo.findActionsByEntityIdAndUnitId(anyInt(), anyLong())).thenReturn(dbFuture);
 
-        Operation operation = OPEN_API.getOperationById("driverIdUnitIdActionsGET");
+        Operation operation = OPEN_API.getOperationById("entityIdUnitIdActionsGET");
         RequestOptions reqOpt = new RequestOptions()
-                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/drivers/1/units/1000/actions")
+                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/entities/1/units/1000/actions")
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -1692,7 +1692,7 @@ class OpenAPIHandlerTest {
                 })));
     }
 
-    private static Stream<Arguments> driverIdUnitIdActionsGET_Params_dataSource() {
+    private static Stream<Arguments> entityIdUnitIdActionsGET_Params_dataSource() {
         Future<List<Action>> future = Future.succeededFuture(List.of(Action.of(1, "mock(name)")));
         return Stream.of(
                 Arguments.of(future, false),
@@ -1701,15 +1701,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("driverIdUnitIdActionsGET_Params_dataSource")
-    @DisplayName("API Params Test: driverIdUnitIdActionsGET")
-    void driverIdUnitIdActionsGET_byParams(Future<List<Action>> dbFuture, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("entityIdUnitIdActionsGET_Params_dataSource")
+    @DisplayName("API Params Test: entityIdUnitIdActionsGET")
+    void entityIdUnitIdActionsGET_byParams(Future<List<Action>> dbFuture, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.findActionsByDriverIdAndUnitId(anyInt(), anyLong())).thenReturn(dbFuture);
+        Mockito.when(repo.findActionsByEntityIdAndUnitId(anyInt(), anyLong())).thenReturn(dbFuture);
 
         RequestOptions reqOpt = new RequestOptions()
                 .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI(
-                        String.format("/drivers/1/units/1000/actions?navigationLinks=%s", navigationLinks))
+                        String.format("/entities/1/units/1000/actions?navigationLinks=%s", navigationLinks))
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -1720,12 +1720,12 @@ class OpenAPIHandlerTest {
                     assertThat(res.size()).isEqualTo(1);
                     JsonNode resJson = res.get(0);
 
-                    assertThat(resJson.has("DriverUntAction@NavigationLink")).isEqualTo(navigationLinks);
+                    assertThat(resJson.has("EntityUntAction@NavigationLink")).isEqualTo(navigationLinks);
                     testContext.completeNow();
                 })));
     }
 
-    private static Stream<Arguments> driverIdActionsGET_dataSource() {
+    private static Stream<Arguments> entityIdActionsGET_dataSource() {
         return Stream.of(
                 Arguments.of(
                         Future.succeededFuture(List.of(
@@ -1745,15 +1745,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("driverIdActionsGET_dataSource")
-    @DisplayName("API Spec Test: driverIdActionsGET")
-    void driverIdActionsGET_bySpec(Future<List<Action>> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("entityIdActionsGET_dataSource")
+    @DisplayName("API Spec Test: entityIdActionsGET")
+    void entityIdActionsGET_bySpec(Future<List<Action>> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.findActionsByDriverId(anyInt(), any(), any())).thenReturn(dbFuture);
+        Mockito.when(repo.findActionsByEntityId(anyInt(), any(), any())).thenReturn(dbFuture);
 
-        Operation operation = OPEN_API.getOperationById("driverIdActionsGET");
+        Operation operation = OPEN_API.getOperationById("entityIdActionsGET");
         RequestOptions reqOpt = new RequestOptions()
-                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/drivers/1/actions")
+                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/entities/1/actions")
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -1765,7 +1765,7 @@ class OpenAPIHandlerTest {
                 })));
     }
 
-    private static Stream<Arguments> driverIdActionsGET_Params_dataSource() {
+    private static Stream<Arguments> entityIdActionsGET_Params_dataSource() {
         Future<List<Action>> future = Future.succeededFuture(List.of(Action.of(1, "mock(name)")));
         return Stream.of(
                 Arguments.of(future,
@@ -1782,15 +1782,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("driverIdActionsGET_Params_dataSource")
-    @DisplayName("API Params Test: driverIdActionsGET")
-    void driverIdActionsGET_byParams(Future<List<Action>> dbFuture, String from, String to, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("entityIdActionsGET_Params_dataSource")
+    @DisplayName("API Params Test: entityIdActionsGET")
+    void entityIdActionsGET_byParams(Future<List<Action>> dbFuture, String from, String to, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.findActionsByDriverId(anyInt(), any(), any())).thenReturn(dbFuture);
+        Mockito.when(repo.findActionsByEntityId(anyInt(), any(), any())).thenReturn(dbFuture);
 
         RequestOptions reqOpt = new RequestOptions()
                 .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI(
-                        String.format("/drivers/1/actions?from=%s&to=%s&navigationLinks=%s", from, to, navigationLinks))
+                        String.format("/entities/1/actions?from=%s&to=%s&navigationLinks=%s", from, to, navigationLinks))
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -1801,12 +1801,12 @@ class OpenAPIHandlerTest {
                     assertThat(res.size()).isEqualTo(1);
                     JsonNode resJson = res.get(0);
 
-                    assertThat(resJson.has("DriverAction@NavigationLink")).isEqualTo(navigationLinks);
+                    assertThat(resJson.has("EntityAction@NavigationLink")).isEqualTo(navigationLinks);
                     testContext.completeNow();
                 })));
     }
 
-    private static Stream<Arguments> driverIdActionIdGET_dataSource() {
+    private static Stream<Arguments> entityIdActionIdGET_dataSource() {
         return Stream.of(
                 Arguments.of(
                         Future.succeededFuture(Action.of(1, "mock(name)")),
@@ -1819,15 +1819,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("driverIdActionIdGET_dataSource")
-    @DisplayName("API Spec Test: driverIdActionIdGET")
-    void driverIdActionIdGET_bySpec(Future<Action> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("entityIdActionIdGET_dataSource")
+    @DisplayName("API Spec Test: entityIdActionIdGET")
+    void entityIdActionIdGET_bySpec(Future<Action> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.findActionByIdAndDriverId(anyInt(), anyInt())).thenReturn(dbFuture);
+        Mockito.when(repo.findActionByIdAndEntityId(anyInt(), anyInt())).thenReturn(dbFuture);
 
-        Operation operation = OPEN_API.getOperationById("driverIdActionIdGET");
+        Operation operation = OPEN_API.getOperationById("entityIdActionIdGET");
         RequestOptions reqOpt = new RequestOptions()
-                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/drivers/1/actions/1")
+                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/entities/1/actions/1")
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -1839,7 +1839,7 @@ class OpenAPIHandlerTest {
                 })));
     }
 
-    private static Stream<Arguments> driverIdActionIdGET_Params_dataSource() {
+    private static Stream<Arguments> entityIdActionIdGET_Params_dataSource() {
         Future<Action> future = Future.succeededFuture(Action.of(1, "mock(name)"));
         return Stream.of(
                 Arguments.of(future, false),
@@ -1848,15 +1848,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("driverIdActionIdGET_Params_dataSource")
-    @DisplayName("API Params Test: driverIdActionIdGET")
-    void driverIdActionIdGET_byParams(Future<Action> dbFuture, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("entityIdActionIdGET_Params_dataSource")
+    @DisplayName("API Params Test: entityIdActionIdGET")
+    void entityIdActionIdGET_byParams(Future<Action> dbFuture, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.findActionByIdAndDriverId(anyInt(), anyInt())).thenReturn(dbFuture);
+        Mockito.when(repo.findActionByIdAndEntityId(anyInt(), anyInt())).thenReturn(dbFuture);
 
         RequestOptions reqOpt = new RequestOptions()
                 .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI(
-                        String.format("/drivers/1/actions/1?navigationLinks=%s", navigationLinks))
+                        String.format("/entities/1/actions/1?navigationLinks=%s", navigationLinks))
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -1866,13 +1866,13 @@ class OpenAPIHandlerTest {
                     JsonNode resJson = toJsonNode(b.toString());
 
                     assertThat(resJson.has("self@NavigationLink")).isEqualTo(navigationLinks);
-                    assertThat(resJson.has("Driver@NavigationLink")).isEqualTo(navigationLinks);
+                    assertThat(resJson.has("Entity@NavigationLink")).isEqualTo(navigationLinks);
                     assertThat(resJson.has("Units@NavigationLink")).isEqualTo(navigationLinks);
                     testContext.completeNow();
                 })));
     }
 
-    private static Stream<Arguments> driverIdActionIdUnitsGET_dataSource() {
+    private static Stream<Arguments> entityIdActionIdUnitsGET_dataSource() {
         return Stream.of(
                 Arguments.of(
                         Future.succeededFuture(List.of(
@@ -1892,15 +1892,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("driverIdActionIdUnitsGET_dataSource")
-    @DisplayName("API Spec Test: driverIdActionIdUnitsGET")
-    void driverIdActionIdUnitsGET_bySpec(Future<List<Unit>> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("entityIdActionIdUnitsGET_dataSource")
+    @DisplayName("API Spec Test: entityIdActionIdUnitsGET")
+    void entityIdActionIdUnitsGET_bySpec(Future<List<Unit>> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.findUnitsByDriverIdAndActionId(anyInt(), anyInt())).thenReturn(dbFuture);
+        Mockito.when(repo.findUnitsByEntityIdAndActionId(anyInt(), anyInt())).thenReturn(dbFuture);
 
-        Operation operation = OPEN_API.getOperationById("driverIdActionIdUnitsGET");
+        Operation operation = OPEN_API.getOperationById("entityIdActionIdUnitsGET");
         RequestOptions reqOpt = new RequestOptions()
-                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/drivers/1/actions/1/units")
+                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/entities/1/actions/1/units")
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -1912,7 +1912,7 @@ class OpenAPIHandlerTest {
                 })));
     }
 
-    private static Stream<Arguments> driverIdActionIdUnitsGET_Params_dataSource() {
+    private static Stream<Arguments> entityIdActionIdUnitsGET_Params_dataSource() {
         Future<List<Unit>> future = Future.succeededFuture(List.of(Unit.of(1000, "mock(name)", "mock(imei)", "mock(description)")));
         return Stream.of(
                 Arguments.of(future, false),
@@ -1921,15 +1921,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("driverIdActionIdUnitsGET_Params_dataSource")
-    @DisplayName("API Params Test: driverIdActionIdUnitsGET")
-    void driverIdActionIdUnitsGET_byParams(Future<List<Unit>> dbFuture, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("entityIdActionIdUnitsGET_Params_dataSource")
+    @DisplayName("API Params Test: entityIdActionIdUnitsGET")
+    void entityIdActionIdUnitsGET_byParams(Future<List<Unit>> dbFuture, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.findUnitsByDriverIdAndActionId(anyInt(), anyInt())).thenReturn(dbFuture);
+        Mockito.when(repo.findUnitsByEntityIdAndActionId(anyInt(), anyInt())).thenReturn(dbFuture);
 
         RequestOptions reqOpt = new RequestOptions()
                 .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI(
-                        String.format("/drivers/1/actions/1/units?navigationLinks=%s", navigationLinks))
+                        String.format("/entities/1/actions/1/units?navigationLinks=%s", navigationLinks))
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -1940,12 +1940,12 @@ class OpenAPIHandlerTest {
                     assertThat(res.size()).isEqualTo(1);
                     JsonNode resJson = res.get(0);
 
-                    assertThat(resJson.has("DriverActionUnit@NavigationLink")).isEqualTo(navigationLinks);
+                    assertThat(resJson.has("EntityActionUnit@NavigationLink")).isEqualTo(navigationLinks);
                     testContext.completeNow();
                 })));
     }
 
-    private static Stream<Arguments> driverIdActionIdUnitIdGET_dataSource() {
+    private static Stream<Arguments> entityIdActionIdUnitIdGET_dataSource() {
         return Stream.of(
                 Arguments.of(
                         Future.succeededFuture(Unit.of(1000, "mock(name)", "mock(imei)", "mock(description)")),
@@ -1958,15 +1958,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("driverIdActionIdUnitIdGET_dataSource")
-    @DisplayName("API Spec Test: driverIdActionIdUnitIdGET")
-    void driverIdActionIdUnitIdGET_bySpec(Future<Unit> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("entityIdActionIdUnitIdGET_dataSource")
+    @DisplayName("API Spec Test: entityIdActionIdUnitIdGET")
+    void entityIdActionIdUnitIdGET_bySpec(Future<Unit> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.findUnitByIdAndDriverIdAndActionId(anyLong(), anyInt(), anyInt())).thenReturn(dbFuture);
+        Mockito.when(repo.findUnitByIdAndEntityIdAndActionId(anyLong(), anyInt(), anyInt())).thenReturn(dbFuture);
 
-        Operation operation = OPEN_API.getOperationById("driverIdActionIdUnitIdGET");
+        Operation operation = OPEN_API.getOperationById("entityIdActionIdUnitIdGET");
         RequestOptions reqOpt = new RequestOptions()
-                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/drivers/1/actions/1/units/1000")
+                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/entities/1/actions/1/units/1000")
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -1978,7 +1978,7 @@ class OpenAPIHandlerTest {
                 })));
     }
 
-    private static Stream<Arguments> driverIdActionIdUnitIdGET_Params_dataSource() {
+    private static Stream<Arguments> entityIdActionIdUnitIdGET_Params_dataSource() {
         Future<Unit> future = Future.succeededFuture(Unit.of(1000, "mock(name)", "mock(imei)", "mock(description)"));
         return Stream.of(
                 Arguments.of(future, false),
@@ -1987,15 +1987,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("driverIdActionIdUnitIdGET_Params_dataSource")
-    @DisplayName("API Params Test: driverIdActionIdUnitIdGET")
-    void driverIdActionIdUnitIdGET_byParams(Future<Unit> dbFuture, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("entityIdActionIdUnitIdGET_Params_dataSource")
+    @DisplayName("API Params Test: entityIdActionIdUnitIdGET")
+    void entityIdActionIdUnitIdGET_byParams(Future<Unit> dbFuture, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.findUnitByIdAndDriverIdAndActionId(anyLong(), anyInt(), anyInt())).thenReturn(dbFuture);
+        Mockito.when(repo.findUnitByIdAndEntityIdAndActionId(anyLong(), anyInt(), anyInt())).thenReturn(dbFuture);
 
         RequestOptions reqOpt = new RequestOptions()
                 .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI(
-                        String.format("/drivers/1/actions/1/units/1000?navigationLinks=%s", navigationLinks))
+                        String.format("/entities/1/actions/1/units/1000?navigationLinks=%s", navigationLinks))
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -2005,14 +2005,14 @@ class OpenAPIHandlerTest {
                     JsonNode resJson = toJsonNode(b.toString());
 
                     assertThat(resJson.has("self@NavigationLink")).isEqualTo(navigationLinks);
-                    assertThat(resJson.has("DriverAction@NavigationLink")).isEqualTo(navigationLinks);
+                    assertThat(resJson.has("EntityAction@NavigationLink")).isEqualTo(navigationLinks);
                     assertThat(resJson.has("Events@NavigationLink")).isEqualTo(navigationLinks);
                     assertThat(resJson.has("Unit@NavigationLink")).isEqualTo(navigationLinks);
                     testContext.completeNow();
                 })));
     }
 
-    private static Stream<Arguments> driverIdUnitIdActionIdGET_dataSource() {
+    private static Stream<Arguments> entityIdUnitIdActionIdGET_dataSource() {
         return Stream.of(
                 Arguments.of(
                         Future.succeededFuture(Action.of(1, "mock(name)")),
@@ -2025,15 +2025,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("driverIdUnitIdActionIdGET_dataSource")
-    @DisplayName("API Spec Test: driverIdUnitIdActionIdGET")
-    void driverIdUnitIdActionIdGET_bySpec(Future<Action> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("entityIdUnitIdActionIdGET_dataSource")
+    @DisplayName("API Spec Test: entityIdUnitIdActionIdGET")
+    void entityIdUnitIdActionIdGET_bySpec(Future<Action> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.findActionByIdAndDriverIdAndUnitId(anyInt(), anyInt(), anyLong())).thenReturn(dbFuture);
+        Mockito.when(repo.findActionByIdAndEntityIdAndUnitId(anyInt(), anyInt(), anyLong())).thenReturn(dbFuture);
 
-        Operation operation = OPEN_API.getOperationById("driverIdUnitIdActionIdGET");
+        Operation operation = OPEN_API.getOperationById("entityIdUnitIdActionIdGET");
         RequestOptions reqOpt = new RequestOptions()
-                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/drivers/1/units/1000/actions/1")
+                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/entities/1/units/1000/actions/1")
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -2045,7 +2045,7 @@ class OpenAPIHandlerTest {
                 })));
     }
 
-    private static Stream<Arguments> driverIdUnitIdActionIdGET_Params_dataSource() {
+    private static Stream<Arguments> entityIdUnitIdActionIdGET_Params_dataSource() {
         Future<Action> future = Future.succeededFuture(Action.of(1, "mock(name)"));
         return Stream.of(
                 Arguments.of(future, false),
@@ -2054,15 +2054,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("driverIdUnitIdActionIdGET_Params_dataSource")
-    @DisplayName("API Params Test: driverIdUnitIdActionIdGET")
-    void driverIdUnitIdActionIdGET_byParams(Future<Action> dbFuture, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("entityIdUnitIdActionIdGET_Params_dataSource")
+    @DisplayName("API Params Test: entityIdUnitIdActionIdGET")
+    void entityIdUnitIdActionIdGET_byParams(Future<Action> dbFuture, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.findActionByIdAndDriverIdAndUnitId(anyInt(), anyInt(), anyLong())).thenReturn(dbFuture);
+        Mockito.when(repo.findActionByIdAndEntityIdAndUnitId(anyInt(), anyInt(), anyLong())).thenReturn(dbFuture);
 
         RequestOptions reqOpt = new RequestOptions()
                 .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI(
-                        String.format("/drivers/1/units/1000/actions/1?navigationLinks=%s", navigationLinks))
+                        String.format("/entities/1/units/1000/actions/1?navigationLinks=%s", navigationLinks))
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -2072,14 +2072,14 @@ class OpenAPIHandlerTest {
                     JsonNode resJson = toJsonNode(b.toString());
 
                     assertThat(resJson.has("self@NavigationLink")).isEqualTo(navigationLinks);
-                    assertThat(resJson.has("Driver@NavigationLink")).isEqualTo(navigationLinks);
-                    assertThat(resJson.has("DriverUnit@NavigationLink")).isEqualTo(navigationLinks);
+                    assertThat(resJson.has("Entity@NavigationLink")).isEqualTo(navigationLinks);
+                    assertThat(resJson.has("EntityUnit@NavigationLink")).isEqualTo(navigationLinks);
                     assertThat(resJson.has("Events@NavigationLink")).isEqualTo(navigationLinks);
                     testContext.completeNow();
                 })));
     }
 
-    private static Stream<Arguments> driverIdUnitIdActionIdEventsGET_dataSource() {
+    private static Stream<Arguments> entityIdUnitIdActionIdEventsGET_dataSource() {
         OffsetDateTime baseTimestamp = OffsetDateTime.ofInstant(BASE_INSTANT_TIMESTAMP, ZoneOffset.UTC);
         return Stream.of(
                 Arguments.of(
@@ -2101,15 +2101,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("driverIdUnitIdActionIdEventsGET_dataSource")
-    @DisplayName("API Spec Test: driverIdUnitIdActionIdEventsGET")
-    void driverIdUnitIdActionIdEventsGET_bySpec(Future<List<Event>> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("entityIdUnitIdActionIdEventsGET_dataSource")
+    @DisplayName("API Spec Test: entityIdUnitIdActionIdEventsGET")
+    void entityIdUnitIdActionIdEventsGET_bySpec(Future<List<Event>> dbFuture, OpenAPIResponseTyp responseTyp, ContentType contentType, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.findEventsByDriverIdAndUnitIdAndActionId(anyInt(), anyLong(), anyInt())).thenReturn(dbFuture);
+        Mockito.when(repo.findEventsByEntityIdAndUnitIdAndActionId(anyInt(), anyLong(), anyInt())).thenReturn(dbFuture);
 
-        Operation operation = OPEN_API.getOperationById("driverIdUnitIdActionIdEventsGET");
+        Operation operation = OPEN_API.getOperationById("entityIdUnitIdActionIdEventsGET");
         RequestOptions reqOpt = new RequestOptions()
-                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/drivers/1/units/1000/actions/1/events")
+                .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI("/entities/1/units/1000/actions/1/events")
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -2121,7 +2121,7 @@ class OpenAPIHandlerTest {
                 })));
     }
 
-    private static Stream<Arguments> driverIdUnitIdActionIdEventsGET_Params_dataSource() {
+    private static Stream<Arguments> entityIdUnitIdActionIdEventsGET_Params_dataSource() {
         OffsetDateTime baseFrom = OffsetDateTime.ofInstant(BASE_INSTANT_TIMESTAMP, ZoneOffset.UTC);
         OffsetDateTime baseTo = OffsetDateTime.ofInstant(BASE_INSTANT_TIMESTAMP, ZoneOffset.UTC).plusHours(8);
 
@@ -2149,15 +2149,15 @@ class OpenAPIHandlerTest {
     }
 
     @ParameterizedTest
-    @MethodSource("driverIdUnitIdActionIdEventsGET_Params_dataSource")
-    @DisplayName("API Params Test: driverIdUnitIdActionIdEventsGET")
-    void driverIdUnitIdActionIdEventsGET_byParams(Future<List<Event>> dbFuture, String zoneParam, Tuple<String, String> expectedTimezones, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
+    @MethodSource("entityIdUnitIdActionIdEventsGET_Params_dataSource")
+    @DisplayName("API Params Test: entityIdUnitIdActionIdEventsGET")
+    void entityIdUnitIdActionIdEventsGET_byParams(Future<List<Event>> dbFuture, String zoneParam, Tuple<String, String> expectedTimezones, boolean navigationLinks, Vertx vertx, VertxTestContext testContext) {
 
-        Mockito.when(repo.findEventsByDriverIdAndUnitIdAndActionId(anyInt(), anyLong(), anyInt())).thenReturn(dbFuture);
+        Mockito.when(repo.findEventsByEntityIdAndUnitIdAndActionId(anyInt(), anyLong(), anyInt())).thenReturn(dbFuture);
 
         RequestOptions reqOpt = new RequestOptions()
                 .setMethod(HttpMethod.GET).setPort(PORT).setHost(HOST).setURI(
-                        String.format("/drivers/1/units/1000/actions/1/events?zone=%s&navigationLinks=%s", zoneParam, navigationLinks))
+                        String.format("/entities/1/units/1000/actions/1/events?zone=%s&navigationLinks=%s", zoneParam, navigationLinks))
                 .setHeaders(MultiMap.caseInsensitiveMultiMap()
                         .add(HttpHeaders.ACCEPT, JSON.contentType()));
 
@@ -2261,8 +2261,8 @@ class OpenAPIHandlerTest {
                     assertThat(resJson.get("toTime").asText()).isEqualTo(expectedTimezones.item2());
 
                     assertThat(resJson.has("self@NavigationLink")).isEqualTo(navigationLinks);
-                    assertThat(resJson.has("Driver@NavigationLink")).isEqualTo(navigationLinks);
-                    assertThat(resJson.has("DriverUnit@NavigationLink")).isEqualTo(navigationLinks);
+                    assertThat(resJson.has("Entity@NavigationLink")).isEqualTo(navigationLinks);
+                    assertThat(resJson.has("EntityUnit@NavigationLink")).isEqualTo(navigationLinks);
                     assertThat(resJson.has("Action@NavigationLink")).isEqualTo(navigationLinks);
                     assertThat(resJson.has("Observations@NavigationLink")).isEqualTo(navigationLinks);
                     assertThat(resJson.has("Locations@NavigationLink")).isEqualTo(navigationLinks);

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini