From 4d2b7fb29e83daa38b9c87cb5b586129eb976f1b Mon Sep 17 00:00:00 2001 From: Timur Shykhsefiyeu Date: Fri, 1 Mar 2024 13:38:23 +0100 Subject: [PATCH 01/17] traccar module init --- extensions/pom.xml | 1 + extensions/traccar/pom.xml | 169 ++ .../traccar/src/main/resources/swagger.json | 2278 +++++++++++++++++ pom.xml | 2 +- 4 files changed, 2449 insertions(+), 1 deletion(-) create mode 100644 extensions/traccar/pom.xml create mode 100644 extensions/traccar/src/main/resources/swagger.json diff --git a/extensions/pom.xml b/extensions/pom.xml index 19546110e..70acacd81 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -13,6 +13,7 @@ ${revision} + traccar api diff --git a/extensions/traccar/pom.xml b/extensions/traccar/pom.xml new file mode 100644 index 000000000..8ba070bce --- /dev/null +++ b/extensions/traccar/pom.xml @@ -0,0 +1,169 @@ + + 4.0.0 + + + ro.vladvesa.transitclock + extensions + ${revision} + + + + pl.goeuropa + traccar-client + ${revision} + + jar + + + 1.6.6 + 4.1.1.Final + 2.12.7 + 1.0.0 + + + + + + + io.swagger + swagger-codegen-maven-plugin + 2.4.29 + + + + generate + + + ${project.basedir}/src/main/resources/swagger.json + + java + + false + + + joda + + + resteasy + + + + + + + + + maven-compiler-plugin + 3.11.0 + + 17 + 17 + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + io.swagger + + swagger-codegen-maven-plugin + + + [2.4.29,) + + + generate + + + + + + + + + + + + + + + + + + + io.swagger + swagger-annotations + ${swagger-annotations-version} + + + + + + org.jboss.resteasy + resteasy-client + ${resteasy-version} + + + + org.jboss.resteasy + resteasy-multipart-provider + ${resteasy-version} + + + + org.jboss.resteasy + resteasy-jackson2-provider + ${resteasy-version} + + + + + com.fasterxml.jackson.jaxrs + jackson-jaxrs-base + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-annotations + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.jaxrs + jackson-jaxrs-json-provider + + + + + com.fasterxml.jackson.datatype + jackson-datatype-joda + + + joda-time + joda-time + ${jodatime-version} + + + + + com.brsanthu + migbase64 + 2.2 + + + + diff --git a/extensions/traccar/src/main/resources/swagger.json b/extensions/traccar/src/main/resources/swagger.json new file mode 100644 index 000000000..fc077d3c9 --- /dev/null +++ b/extensions/traccar/src/main/resources/swagger.json @@ -0,0 +1,2278 @@ +{ + "swagger": "2.0", + "info": { + "version": "4.8", + "title": "traccar" + }, + "host": "demo.traccar.org", + "basePath": "/api", + "schemes": [ + "http" + ], + "security": [ + { + "basicAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "paths": { + "/commands": { + "get": { + "summary": "Fetch a list of Saved Commands", + "description": "Without params, it returns a list of Drivers the user has access to", + "parameters": [ + { + "$ref": "#/parameters/all" + }, + { + "$ref": "#/parameters/userId" + }, + { + "$ref": "#/parameters/deviceId" + }, + { + "$ref": "#/parameters/groupId" + }, + { + "$ref": "#/parameters/refresh" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Command" + } + } + } + } + }, + "post": { + "summary": "Create a Saved Command", + "parameters": [ + { + "$ref": "#/parameters/Command" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Command" + } + } + } + } + }, + "/commands/{id}": { + "put": { + "summary": "Update a Saved Command", + "parameters": [ + { + "$ref": "#/parameters/entityId" + }, + { + "$ref": "#/parameters/Command" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Command" + } + } + } + }, + "delete": { + "summary": "Delete a Saved Command", + "parameters": [ + { + "$ref": "#/parameters/entityId" + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/commands/send": { + "get": { + "summary": "Fetch a list of Saved Commands supported by Device at the moment", + "description": "Return a list of saved commands linked to Device and its groups, filtered by current Device protocol support", + "parameters": [ + { + "$ref": "#/parameters/deviceId" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Command" + } + } + }, + "400": { + "description": "Could happen when the user doesn't have permission for the device" + } + } + }, + "post": { + "summary": "Dispatch commands to device", + "description": "Dispatch a new command or Saved Command if _body.id_ set", + "parameters": [ + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/Command" + } + } + ], + "responses": { + "200": { + "description": "Command sent", + "schema": { + "$ref": "#/definitions/Command" + } + }, + "202": { + "description": "Command queued", + "schema": { + "$ref": "#/definitions/Command" + } + }, + "400": { + "description": "Could happen when the user doesn't have permission or an incorrect command _type_ for the device" + } + } + } + }, + "/commands/types": { + "get": { + "summary": "Fetch a list of available Commands for the Device or all possible Commands if Device ommited", + "parameters": [ + { + "name": "deviceId", + "in": "query", + "description" : "Internal device identifier. Only works if device has already reported some locations", + "required" : false, + "type": "integer" + }, + { + "name": "protocol", + "in": "query", + "description" : "Protocol name. Can be used instead of device id", + "required" : false, + "type": "string" + }, + { + "name": "textChannel", + "in": "query", + "description" : "When `true` return SMS commands. If not specified or `false` return data commands", + "required" : false, + "type": "boolean" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/CommandType" + } + } + }, + "400": { + "description": "Could happen when trying to fetch from a device the user does not have permission" + } + } + } + }, + "/devices": { + "get": { + "summary": "Fetch a list of Devices", + "description": "Without any params, returns a list of the user's devices", + "parameters": [ + { + "$ref": "#/parameters/all" + }, + { + "$ref": "#/parameters/userId" + }, + { + "name" : "id", + "in" : "query", + "description" : "To fetch one or more devices. Multiple params can be passed like `id=31&id=42`", + "required" : false, + "type" : "integer", + "collectionFormat" : "multi" + }, + { + "name" : "uniqueId", + "in" : "query", + "description" : "To fetch one or more devices. Multiple params can be passed like `uniqueId=333331&uniqieId=44442`", + "required" : false, + "type" : "string", + "collectionFormat" : "multi" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Device" + } + } + }, + "400": { + "description": "No permission" + } + } + }, + "post": { + "summary": "Create a Device", + "parameters": [ + { + "$ref": "#/parameters/Device" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Device" + } + } + } + } + }, + "/devices/{id}": { + "put": { + "summary": "Update a Device", + "parameters": [ + { + "$ref": "#/parameters/entityId" + }, + { + "$ref": "#/parameters/Device" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Device" + } + } + } + }, + "delete": { + "summary": "Delete a Device", + "parameters": [ + { + "$ref": "#/parameters/entityId" + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/devices/{id}/accumulators": { + "put": { + "summary": "Update total distance and hours of the Device", + "parameters": [ + { + "$ref": "#/parameters/entityId" + }, + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/DeviceAccumulators" + } + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/groups": { + "get": { + "summary": "Fetch a list of Groups", + "description": "Without any params, returns a list of the Groups the user belongs to", + "parameters": [ + { + "$ref": "#/parameters/all" + }, + { + "$ref": "#/parameters/userId" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Group" + } + } + } + } + }, + "post": { + "summary": "Create a Group", + "parameters": [ + { + "$ref": "#/parameters/Group" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Group" + } + }, + "400": { + "description": "No permission" + } + } + } + }, + "/groups/{id}": { + "put": { + "summary": "Update a Group", + "parameters": [ + { + "$ref": "#/parameters/entityId" + }, + { + "$ref": "#/parameters/Group" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Group" + } + } + } + }, + "delete": { + "summary": "Delete a Group", + "parameters": [ + { + "$ref": "#/parameters/entityId" + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/permissions": { + "post": { + "summary": "Link an Object to another Object", + "parameters": [ + { + "$ref": "#/parameters/Permission" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Permission" + } + }, + "400": { + "description": "No permission" + } + } + }, + "delete": { + "summary": "Unlink an Object from another Object", + "parameters": [ + { + "$ref": "#/parameters/Permission" + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/positions": { + "get": { + "summary" : "Fetches a list of Positions", + "description" : "Without any params, it returns a list of last known positions for all the user's Devices. _from_ and _to_ fields are not required with _id_", + "consumes": [ + "application/json", + "text/csv", + "application/gpx+xml" + ], + "produces": [ + "application/json", + "text/csv", + "application/gpx+xml" + ], + "parameters": [ + { + "name": "deviceId", + "in": "query", + "description": "_deviceId_ is optional, but requires the _from_ and _to_ parameters when used", + "required": false, + "type": "integer" + }, + { + "name": "from", + "in": "query", + "description": "in IS0 8601 format. eg. `1963-11-22T18:30:00Z`", + "required": false, + "type": "string", + "format": "date-time" + }, + { + "name": "to", + "in": "query", + "description": "in IS0 8601 format. eg. `1963-11-22T18:30:00Z`", + "required": false, + "type": "string", + "format": "date-time" + }, + { + "name" : "id", + "in" : "query", + "description" : "To fetch one or more positions. Multiple params can be passed like `id=31&id=42`", + "required" : false, + "type" : "integer", + "collectionFormat" : "multi" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Position" + } + } + } + } + } + }, + "/server": { + "get": { + "summary": "Fetch Server information", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Server" + } + } + } + }, + "put": { + "summary": "Update Server information", + "parameters": [ + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/Server" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Server" + } + } + } + } + }, + "/session": { + "get": { + "summary": "Fetch Session information", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "parameters": [ + { + "name": "token", + "in": "query", + "required": false, + "type": "string" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/User" + } + }, + "404": { + "description": "Not Found" + } + } + }, + "post": { + "summary": "Create a new Session", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "parameters": [ + { + "name": "email", + "in": "formData", + "required": true, + "type": "string" + }, + { + "name": "password", + "in": "formData", + "required": true, + "type": "string", + "format": "password" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/User" + } + }, + "401": { + "description": "Unauthorized" + } + } + }, + "delete": { + "summary": "Close the Session", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "parameters": [], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/users": { + "get": { + "summary": "Fetch a list of Users", + "parameters": [ + { + "name": "userId", + "in": "query", + "description": "Can only be used by admin or manager users", + "required": false, + "type": "string" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/User" + } + } + }, + "400": { + "description": "No Permission" + } + } + }, + "post": { + "summary": "Create a User", + "parameters": [ + { + "$ref": "#/parameters/User" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/User" + } + } + } + } + }, + "/users/{id}": { + "put": { + "summary": "Update a User", + "parameters": [ + { + "$ref": "#/parameters/entityId" + }, + { + "$ref": "#/parameters/User" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/User" + } + } + } + }, + "delete": { + "summary": "Delete a User", + "parameters": [ + { + "$ref": "#/parameters/entityId" + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/notifications": { + "get": { + "summary": "Fetch a list of Notifications", + "description": "Without params, it returns a list of Notifications the user has access to", + "parameters": [ + { + "$ref": "#/parameters/all" + }, + { + "$ref": "#/parameters/userId" + }, + { + "$ref": "#/parameters/deviceId" + }, + { + "$ref": "#/parameters/groupId" + }, + { + "$ref": "#/parameters/refresh" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Notification" + } + } + } + } + }, + "post": { + "summary": "Create a Notification", + "parameters": [ + { + "$ref": "#/parameters/Notification" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Notification" + } + } + } + } + }, + "/notifications/{id}": { + "put": { + "summary": "Update a Notification", + "parameters": [ + { + "$ref": "#/parameters/entityId" + }, + { + "$ref": "#/parameters/Notification" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Notification" + } + } + } + }, + "delete": { + "summary": "Delete a Notification", + "parameters": [ + { + "$ref": "#/parameters/entityId" + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/notifications/types": { + "get": { + "summary": "Fetch a list of available Notification types", + "parameters": [], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/NotificationType" + } + } + } + } + } + }, + "/notifications/test": { + "post": { + "summary": "Send test notification to current user via Email and SMS", + "parameters": [], + "responses": { + "204": { + "description": "Successful sending" + }, + "400": { + "description": "Could happen if sending has failed" + } + } + } + }, + "/geofences": { + "get": { + "summary": "Fetch a list of Geofences", + "description": "Without params, it returns a list of Geofences the user has access to", + "parameters": [ + { + "$ref": "#/parameters/all" + }, + { + "$ref": "#/parameters/userId" + }, + { + "$ref": "#/parameters/deviceId" + }, + { + "$ref": "#/parameters/groupId" + }, + { + "$ref": "#/parameters/refresh" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Geofence" + } + } + } + } + }, + "post": { + "summary": "Create a Geofence", + "parameters": [ + { + "$ref": "#/parameters/Geofence" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Geofence" + } + } + } + } + }, + "/geofences/{id}": { + "put": { + "summary": "Update a Geofence", + "parameters": [ + { + "$ref": "#/parameters/entityId" + }, + { + "$ref": "#/parameters/Geofence" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Geofence" + } + } + } + }, + "delete": { + "summary": "Delete a Geofence", + "parameters": [ + { + "$ref": "#/parameters/entityId" + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/events/{id}": { + "get": { + "parameters": [ + { + "$ref": "#/parameters/entityId" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Event" + } + } + } + } + }, + "/reports/route": { + "get": { + "summary": "Fetch a list of Positions within the time period for the Devices or Groups", + "description": "At least one _deviceId_ or one _groupId_ must be passed", + "consumes": [ + "application/json", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" + ], + "produces": [ + "application/json", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" + ], + "parameters": [ + { + "$ref": "#/parameters/deviceIdArray" + }, + { + "$ref": "#/parameters/groupIdArray" + }, + { + "$ref": "#/parameters/fromTime" + }, + { + "$ref": "#/parameters/toTime" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Position" + } + } + } + } + } + }, + "/reports/events": { + "get": { + "summary": "Fetch a list of Events within the time period for the Devices or Groups", + "description": "At least one _deviceId_ or one _groupId_ must be passed", + "consumes": [ + "application/json", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" + ], + "produces": [ + "application/json", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" + ], + "parameters": [ + { + "$ref": "#/parameters/deviceIdArray" + }, + { + "$ref": "#/parameters/groupIdArray" + }, + { + "name": "type", + "in": "query", + "description": "% can be used to return events of all types", + "type": "array", + "items": { + "type": "string" + } + }, + { + "$ref": "#/parameters/fromTime" + }, + { + "$ref": "#/parameters/toTime" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Event" + } + } + } + } + } + }, + "/reports/summary": { + "get": { + "summary": "Fetch a list of ReportSummary within the time period for the Devices or Groups", + "description": "At least one _deviceId_ or one _groupId_ must be passed", + "consumes": [ + "application/json", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" + ], + "produces": [ + "application/json", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" + ], + "parameters": [ + { + "$ref": "#/parameters/deviceIdArray" + }, + { + "$ref": "#/parameters/groupIdArray" + }, + { + "$ref": "#/parameters/fromTime" + }, + { + "$ref": "#/parameters/toTime" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/ReportSummary" + } + } + } + } + } + }, + "/reports/trips": { + "get": { + "summary": "Fetch a list of ReportTrips within the time period for the Devices or Groups", + "description": "At least one _deviceId_ or one _groupId_ must be passed", + "consumes": [ + "application/json", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" + ], + "produces": [ + "application/json", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" + ], + "parameters": [ + { + "$ref": "#/parameters/deviceIdArray" + }, + { + "$ref": "#/parameters/groupIdArray" + }, + { + "$ref": "#/parameters/fromTime" + }, + { + "$ref": "#/parameters/toTime" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/ReportTrips" + } + } + } + } + } + }, + "/reports/stops": { + "get": { + "summary": "Fetch a list of ReportStops within the time period for the Devices or Groups", + "description": "At least one _deviceId_ or one _groupId_ must be passed", + "consumes": [ + "application/json", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" + ], + "produces": [ + "application/json", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" + ], + "parameters": [ + { + "$ref": "#/parameters/deviceIdArray" + }, + { + "$ref": "#/parameters/groupIdArray" + }, + { + "$ref": "#/parameters/fromTime" + }, + { + "$ref": "#/parameters/toTime" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/ReportStops" + } + } + } + } + } + }, + "/statistics": { + "get": { + "summary": "Fetch server Statistics", + "parameters": [ + { + "$ref": "#/parameters/fromTime" + }, + { + "$ref": "#/parameters/toTime" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Statistics" + } + } + } + } + } + }, + "/calendars": { + "get": { + "summary": "Fetch a list of Calendars", + "description": "Without params, it returns a list of Calendars the user has access to", + "parameters": [ + { + "$ref": "#/parameters/all" + }, + { + "$ref": "#/parameters/userId" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Calendar" + } + } + } + } + }, + "post": { + "summary": "Create a Calendar", + "parameters": [ + { + "$ref": "#/parameters/Calendar" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Calendar" + } + } + } + } + }, + "/calendars/{id}": { + "put": { + "summary": "Update a Calendar", + "parameters": [ + { + "$ref": "#/parameters/entityId" + }, + { + "$ref": "#/parameters/Calendar" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Calendar" + } + } + } + }, + "delete": { + "summary": "Delete a Calendar", + "parameters": [ + { + "$ref": "#/parameters/entityId" + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/attributes/computed": { + "get": { + "summary": "Fetch a list of Attributes", + "description": "Without params, it returns a list of Attributes the user has access to", + "parameters": [ + { + "$ref": "#/parameters/all" + }, + { + "$ref": "#/parameters/userId" + }, + { + "$ref": "#/parameters/deviceId" + }, + { + "$ref": "#/parameters/groupId" + }, + { + "$ref": "#/parameters/refresh" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Attribute" + } + } + } + } + }, + "post": { + "summary": "Create an Attribute", + "parameters": [ + { + "$ref": "#/parameters/Attribute" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Attribute" + } + } + } + } + }, + "/attributes/computed/{id}": { + "put": { + "summary": "Update an Attribute", + "parameters": [ + { + "$ref": "#/parameters/entityId" + }, + { + "$ref": "#/parameters/Attribute" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Attribute" + } + } + } + }, + "delete": { + "summary": "Delete an Attribute", + "parameters": [ + { + "$ref": "#/parameters/entityId" + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/drivers": { + "get": { + "summary": "Fetch a list of Drivers", + "description": "Without params, it returns a list of Drivers the user has access to", + "parameters": [ + { + "$ref": "#/parameters/all" + }, + { + "$ref": "#/parameters/userId" + }, + { + "$ref": "#/parameters/deviceId" + }, + { + "$ref": "#/parameters/groupId" + }, + { + "$ref": "#/parameters/refresh" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Driver" + } + } + } + } + }, + "post": { + "summary": "Create a Driver", + "parameters": [ + { + "$ref": "#/parameters/Driver" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Driver" + } + } + } + } + }, + "/drivers/{id}": { + "put": { + "summary": "Update a Driver", + "parameters": [ + { + "$ref": "#/parameters/entityId" + }, + { + "$ref": "#/parameters/Driver" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Driver" + } + } + } + }, + "delete": { + "summary": "Delete a Driver", + "parameters": [ + { + "$ref": "#/parameters/entityId" + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/maintenance": { + "get": { + "summary": "Fetch a list of Maintenance", + "description": "Without params, it returns a list of Maintenance the user has access to", + "parameters": [ + { + "$ref": "#/parameters/all" + }, + { + "$ref": "#/parameters/userId" + }, + { + "$ref": "#/parameters/deviceId" + }, + { + "$ref": "#/parameters/groupId" + }, + { + "$ref": "#/parameters/refresh" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Maintenance" + } + } + } + } + }, + "post": { + "summary": "Create a Maintenance", + "parameters": [ + { + "$ref": "#/parameters/Maintenance" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Maintenance" + } + } + } + } + }, + "/maintenance/{id}": { + "put": { + "summary": "Update a Maintenance", + "parameters": [ + { + "$ref": "#/parameters/entityId" + }, + { + "$ref": "#/parameters/Maintenance" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Maintenance" + } + } + } + }, + "delete": { + "summary": "Delete a Maintenance", + "parameters": [ + { + "$ref": "#/parameters/entityId" + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + } + }, + "definitions": { + "Position": { + "properties": { + "id": { + "type": "integer" + }, + "deviceId": { + "type": "integer" + }, + "protocol": { + "type": "string" + }, + "deviceTime": { + "type": "string", + "format": "date-time", + "description": "in IS0 8601 format. eg. `1963-11-22T18:30:00Z`" + }, + "fixTime": { + "type": "string", + "format": "date-time", + "description": "in IS0 8601 format. eg. `1963-11-22T18:30:00Z`" + }, + "serverTime": { + "type": "string", + "format": "date-time", + "description": "in IS0 8601 format. eg. `1963-11-22T18:30:00Z`" + }, + "outdated": { + "type": "boolean" + }, + "valid": { + "type": "boolean" + }, + "latitude": { + "type": "number" + }, + "longitude": { + "type": "number" + }, + "altitude": { + "type": "number" + }, + "speed": { + "type": "number", + "description": "in knots" + }, + "course": { + "type": "number" + }, + "address": { + "type": "string" + }, + "accuracy": { + "type": "number" + }, + "network": { + "type": "object", + "additionalProperties": true + }, + "attributes": { + "type": "object", + "additionalProperties": true + } + } + }, + "User": { + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "email": { + "type": "string" + }, + "readonly": { + "type": "boolean" + }, + "administrator": { + "type": "boolean" + }, + "map": { + "type": "string" + }, + "latitude": { + "type": "number" + }, + "longitude": { + "type": "number" + }, + "zoom": { + "type": "integer" + }, + "password": { + "type": "string" + }, + "twelveHourFormat": { + "type": "boolean" + }, + "coordinateFormat": { + "type": "string" + }, + "disabled": { + "type": "boolean" + }, + "expirationTime": { + "type": "string", + "format": "date-time", + "description": "in IS0 8601 format. eg. `1963-11-22T18:30:00Z`" + }, + "deviceLimit": { + "type": "integer" + }, + "userLimit": { + "type": "integer" + }, + "deviceReadonly": { + "type": "boolean" + }, + "limitCommands": { + "type": "boolean" + }, + "poiLayer": { + "type": "string" + }, + "token": { + "type": "string" + }, + "attributes": { + "type": "object", + "additionalProperties": true + } + } + }, + "Server": { + "properties": { + "id": { + "type": "integer" + }, + "registration": { + "type": "boolean" + }, + "readonly": { + "type": "boolean" + }, + "deviceReadonly": { + "type": "boolean" + }, + "limitCommands": { + "type": "boolean" + }, + "map": { + "type": "string" + }, + "bingKey": { + "type": "string" + }, + "mapUrl": { + "type": "string" + }, + "poiLayer": { + "type": "string" + }, + "latitude": { + "type": "number" + }, + "longitude": { + "type": "number" + }, + "zoom": { + "type": "integer" + }, + "twelveHourFormat": { + "type": "boolean" + }, + "version": { + "type": "string" + }, + "forceSettings": { + "type": "boolean" + }, + "coordinateFormat": { + "type": "string" + }, + "attributes": { + "type": "object", + "additionalProperties": true + } + } + }, + "Command": { + "properties": { + "id": { + "type": "integer" + }, + "deviceId": { + "type": "integer" + }, + "description": { + "type": "string" + }, + "type": { + "type": "string" + }, + "attributes": { + "type": "object", + "additionalProperties": true + } + } + }, + "Device": { + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "uniqueId": { + "type": "string" + }, + "status": { + "type": "string" + }, + "disabled": { + "type": "boolean" + }, + "lastUpdate": { + "type": "string", + "format": "date-time", + "description": "in IS0 8601 format. eg. `1963-11-22T18:30:00Z`" + }, + "positionId": { + "type": "integer" + }, + "groupId": { + "type": "integer" + }, + "phone": { + "type": "string" + }, + "model": { + "type": "string" + }, + "contact": { + "type": "string" + }, + "category": { + "type": "string" + }, + "geofenceIds": { + "type": "array", + "items": { + "type": "integer" + } + }, + "attributes": { + "type": "object", + "additionalProperties": true + } + } + }, + "Group": { + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "groupId": { + "type": "integer" + }, + "attributes": { + "type": "object", + "additionalProperties": true + } + } + }, + "Permission": { + "description": "This is a permission map that contain two object indexes. It is used to link/unlink objects. Order is important. Example: { deviceId:8, geofenceId: 16 }", + "properties": { + "userId": { + "description": "User Id, can be only first parameter", + "type": "integer" + }, + "deviceId": { + "description": "Device Id, can be first parameter or second only in combination with userId", + "type": "integer" + }, + "groupId": { + "description": "Group Id, can be first parameter or second only in combination with userId", + "type": "integer" + }, + "geofenceId": { + "description": "Geofence Id, can be second parameter only", + "type": "integer" + }, + "calendarId": { + "description": "Calendar Id, can be second parameter only and only in combination with userId", + "type": "integer" + }, + "attributeId": { + "description": "Computed Attribute Id, can be second parameter only", + "type": "integer" + }, + "driverId": { + "description": "Driver Id, can be second parameter only", + "type": "integer" + }, + "managedUserId": { + "description": "User Id, can be second parameter only and only in combination with userId", + "type": "integer" + } + } + }, + "CommandType": { + "properties": { + "type": { + "type": "string" + } + } + }, + "Geofence": { + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "description": { + "type": "string" + }, + "area": { + "type": "string" + }, + "calendarId": { + "type": "integer" + }, + "attributes": { + "type": "object", + "additionalProperties": true + } + } + }, + "Notification": { + "properties": { + "id": { + "type": "integer" + }, + "type": { + "type": "string" + }, + "always": { + "type": "boolean" + }, + "web": { + "type": "boolean" + }, + "mail": { + "type": "boolean" + }, + "sms": { + "type": "boolean" + }, + "calendarId": { + "type": "integer" + }, + "attributes": { + "type": "object", + "additionalProperties": true + } + } + }, + "NotificationType": { + "properties": { + "type": { + "type": "string" + } + } + }, + "Event": { + "properties": { + "id": { + "type": "integer" + }, + "type": { + "type": "string" + }, + "serverTime": { + "type": "string", + "format": "date-time", + "description": "in IS0 8601 format. eg. `1963-11-22T18:30:00Z`" + }, + "deviceId": { + "type": "integer" + }, + "positionId": { + "type": "integer" + }, + "geofenceId": { + "type": "integer" + }, + "maintenanceId": { + "type": "integer" + }, + "attributes": { + "type": "object", + "additionalProperties": true + } + } + }, + "ReportSummary": { + "properties": { + "deviceId": { + "type": "integer" + }, + "deviceName": { + "type": "string" + }, + "maxSpeed": { + "type": "number", + "description": "in knots" + }, + "averageSpeed": { + "type": "number", + "description": "in knots" + }, + "distance": { + "type": "number", + "description": "in meters" + }, + "spentFuel": { + "type": "number", + "description": "in liters" + }, + "engineHours": { + "type": "integer" + } + } + }, + "ReportTrips": { + "properties": { + "deviceId": { + "type": "integer" + }, + "deviceName": { + "type": "string" + }, + "maxSpeed": { + "type": "number", + "description": "in knots" + }, + "averageSpeed": { + "type": "number", + "description": "in knots" + }, + "distance": { + "type": "number", + "description": "in meters" + }, + "spentFuel": { + "type": "number", + "description": "in liters" + }, + "duration": { + "type": "integer" + }, + "startTime": { + "type": "string", + "format": "date-time", + "description": "in IS0 8601 format. eg. `1963-11-22T18:30:00Z`" + }, + "startAddress": { + "type": "string" + }, + "startLat": { + "type": "number" + }, + "startLon": { + "type": "number" + }, + "endTime": { + "type": "string", + "format": "date-time", + "description": "in IS0 8601 format. eg. `1963-11-22T18:30:00Z`" + }, + "endAddress": { + "type": "string" + }, + "endLat": { + "type": "number" + }, + "endLon": { + "type": "number" + }, + "driverUniqueId": { + "type": "integer" + }, + "driverName": { + "type": "string" + } + } + }, + "ReportStops": { + "properties": { + "deviceId": { + "type": "integer" + }, + "deviceName": { + "type": "string" + }, + "duration": { + "type": "integer" + }, + "startTime": { + "type": "string", + "format": "date-time", + "description": "in IS0 8601 format. eg. `1963-11-22T18:30:00Z`" + }, + "address": { + "type": "string" + }, + "lat": { + "type": "number" + }, + "lon": { + "type": "number" + }, + "endTime": { + "type": "string", + "format": "date-time", + "description": "in IS0 8601 format. eg. `1963-11-22T18:30:00Z`" + }, + "spentFuel": { + "type": "number", + "description": "in liters" + }, + "engineHours": { + "type": "integer" + } + } + }, + "Statistics": { + "properties": { + "captureTime": { + "type": "string", + "format": "date-time", + "description": "in IS0 8601 format. eg. `1963-11-22T18:30:00Z`" + }, + "activeUsers": { + "type": "integer" + }, + "activeDevices": { + "type": "integer" + }, + "requests": { + "type": "integer" + }, + "messagesReceived": { + "type": "integer" + }, + "messagesStored": { + "type": "integer" + } + } + }, + "DeviceAccumulators": { + "properties": { + "deviceId": { + "type": "integer" + }, + "totalDistance": { + "type": "number", + "description": "in meters" + }, + "hours": { + "type": "number" + } + } + }, + "Calendar": { + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "data": { + "type": "string", + "description": "base64 encoded in iCalendar format" + }, + "attributes": { + "type": "object", + "additionalProperties": true + } + } + }, + "Attribute": { + "properties": { + "id": { + "type": "integer" + }, + "description": { + "type": "string" + }, + "attribute": { + "type": "string" + }, + "expression": { + "type": "string" + }, + "type": { + "type": "string", + "description": "String|Number|Boolean" + } + } + }, + "Driver": { + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "uniqueId": { + "type": "string" + }, + "attributes": { + "type": "object", + "additionalProperties": true + } + } + }, + "Maintenance": { + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "type": { + "type": "string" + }, + "start": { + "type": "number" + }, + "period": { + "type": "number" + }, + "attributes": { + "type": "object", + "additionalProperties": true + } + } + } + }, + "parameters": { + "entityId": { + "name": "id", + "in": "path", + "required": true, + "type": "integer" + }, + "all": { + "name": "all", + "in": "query", + "description": "Can only be used by admins or managers to fetch all entities", + "type": "boolean" + }, + "refresh": { + "name": "refresh", + "in": "query", + "required": false, + "type": "boolean" + }, + "userId": { + "name": "userId", + "in": "query", + "description": "Standard users can use this only with their own _userId_", + "type": "integer" + }, + "deviceId": { + "name": "deviceId", + "in": "query", + "description": "Standard users can use this only with _deviceId_s, they have access to", + "type": "integer" + }, + "groupId": { + "name": "groupId", + "in": "query", + "description": "Standard users can use this only with _groupId_s, they have access to", + "type": "integer" + }, + "Device": { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/Device" + } + }, + "Permission": { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/Permission" + } + }, + "Group": { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/Group" + } + }, + "User": { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/User" + } + }, + "Geofence": { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/Geofence" + } + }, + "Calendar": { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/Calendar" + } + }, + "Attribute": { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/Attribute" + } + }, + "Driver": { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/Driver" + } + }, + "Command": { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/Command" + } + }, + "Notification": { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/Notification" + } + }, + "Maintenance": { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/Maintenance" + } + }, + "deviceIdArray": { + "name": "deviceId", + "in": "query", + "type": "array", + "items": { + "type": "integer" + }, + "collectionFormat": "multi" + }, + "groupIdArray": { + "name": "groupId", + "in": "query", + "type": "array", + "items": { + "type": "integer" + }, + "collectionFormat": "multi" + }, + "fromTime": { + "name": "from", + "in": "query", + "description": "in IS0 8601 format. eg. `1963-11-22T18:30:00Z`", + "required": true, + "type": "string", + "format": "date-time" + }, + "toTime": { + "name": "to", + "in": "query", + "description": "in IS0 8601 format. eg. `1963-11-22T18:30:00Z`", + "required": true, + "type": "string", + "format": "date-time" + } + }, + "securityDefinitions": { + "basicAuth": { + "type": "basic", + "description": "Basic HTTP authorization with _email_ and _password_" + } + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 3fb175fad..3daaad8f0 100644 --- a/pom.xml +++ b/pom.xml @@ -8,9 +8,9 @@ pom + extensions core app - extensions From dd4a867bb08ce69cddf42d382c7562841a0249f5 Mon Sep 17 00:00:00 2001 From: Timur Shykhsefiyeu Date: Fri, 1 Mar 2024 13:43:02 +0100 Subject: [PATCH 02/17] traccar module init: delete empty tag --- extensions/traccar/pom.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/extensions/traccar/pom.xml b/extensions/traccar/pom.xml index 8ba070bce..c2516ceb3 100644 --- a/extensions/traccar/pom.xml +++ b/extensions/traccar/pom.xml @@ -82,9 +82,6 @@ generate - - - From b53f4a9724f4bfb3f59b9823ebbb78d8125093cc Mon Sep 17 00:00:00 2001 From: Timur Shykhsefiyeu Date: Fri, 1 Mar 2024 16:05:50 +0100 Subject: [PATCH 03/17] traccar client impl --- .../config/data/TraccarConfig.java | 25 ++++ .../core/avl/TraccarAVLModule.java | 133 ++++++++++++++++++ .../domain/structs/AvlReport.java | 25 ++++ 3 files changed, 183 insertions(+) create mode 100644 core/src/main/java/org/transitclock/config/data/TraccarConfig.java create mode 100644 core/src/main/java/org/transitclock/core/avl/TraccarAVLModule.java diff --git a/core/src/main/java/org/transitclock/config/data/TraccarConfig.java b/core/src/main/java/org/transitclock/config/data/TraccarConfig.java new file mode 100644 index 000000000..1250712d9 --- /dev/null +++ b/core/src/main/java/org/transitclock/config/data/TraccarConfig.java @@ -0,0 +1,25 @@ +/* (C)2023 */ +package org.transitclock.config.data; + +import org.transitclock.config.StringConfigValue; + + +public class TraccarConfig { + /** + * Traccar properties for log in by "TraccarAVLModule" + * + * @return + */ + public static final StringConfigValue TRACCAREMAIL = new StringConfigValue("transitclock.avl.traccar.email", null, + "This is the username for the traccar server api."); + + public static final StringConfigValue TRACCARPASSWORD = new StringConfigValue("transitclock.avl.traccar.password", + null, "This is the password for the traccar server api"); + + public static final StringConfigValue TRACCARBASEURL = new StringConfigValue("transitclock.avl.traccar.baseurl", + null, "This is the url for the traccar server api."); + + public static final StringConfigValue TRACCARSOURCE = new StringConfigValue("transitclock.avl.traccar.source", + "TRACCAR", "This is the value recorded in the source for the AVL Report."); + +} diff --git a/core/src/main/java/org/transitclock/core/avl/TraccarAVLModule.java b/core/src/main/java/org/transitclock/core/avl/TraccarAVLModule.java new file mode 100644 index 000000000..bf8e437a7 --- /dev/null +++ b/core/src/main/java/org/transitclock/core/avl/TraccarAVLModule.java @@ -0,0 +1,133 @@ +/* + * This file is part of thetransitclock.org + * + * thetransitclock.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License (GPL) as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * thetransitclock.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with thetransitclock.org . If not, see . + */ +package org.transitclock.core.avl; + +import io.swagger.client.ApiClient; +import io.swagger.client.ApiException; +import io.swagger.client.api.DefaultApi; +import io.swagger.client.model.Device; +import io.swagger.client.model.Position; +import io.swagger.client.model.User; + +import lombok.NonNull; +import lombok.extern.slf4j.Slf4j; +import org.transitclock.domain.structs.AvlReport; + +import java.io.InputStream; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Collection; + +import static org.transitclock.config.data.TraccarConfig.*; + + +/** + * @author Sean Óg Crudden This module integrates TheTransitClock with the API of a traccar + * server to get vehicle locations. + *

+ * See http://www.traccar.org + *

+ * It uses classes that where generated using the swagger file provided + * with traccar. + */ +@Slf4j +public class TraccarAVLModule extends PollUrlAvlModule { + public TraccarAVLModule(String agencyId) { + super(agencyId); + + useCompression = false; + } + + + private DefaultApi initApiClient() throws RuntimeException { + DefaultApi api = new DefaultApi(); + ApiClient client = new ApiClient(); + client.setBasePath(TRACCARBASEURL.getValue()); + client.setUsername(TRACCAREMAIL.getValue()); + client.setPassword(TRACCARPASSWORD.getValue()); + api.setApiClient(client); + return api; + } + + + private User initUser(DefaultApi api) throws RuntimeException { + User user; + try { + user = api + .sessionPost(TRACCAREMAIL.getValue(), TRACCARPASSWORD.getValue()); + logger.info("Traccar login succeeded."); + return user; + } catch (ApiException e) { + logger.error(e.getMessage() + e.getCause()); + } + throw new RuntimeException("Traccar login deny"); + } + + @NonNull + private final DefaultApi API = initApiClient(); + @NonNull + private final User USER = initUser(API); + + @Override + protected void getAndProcessData() throws Exception { + + Collection avlReportsReadIn = new ArrayList<>(); + + List devices = API.devicesGet(true, USER.getId(), null, null); + + List results = API.positionsGet(null, null, null, null); + for (Position result : results) { + Device device = findDeviceById(devices, result.getDeviceId()); + + AvlReport avlReport; + + // If have device details use name. + if (device != null && device.getUniqueId() != null && !device.getUniqueId().isEmpty()) { + //Traccar return speed in kt + avlReport = new AvlReport(device.getUniqueId(), device.getName(), + result.getDeviceTime().toDate().getTime(), result.getLatitude().doubleValue(), + result.getLongitude().doubleValue(), result.getSpeed().multiply(BigDecimal.valueOf(0.5144444)).floatValue(), result.getCourse().floatValue(), TRACCARSOURCE.toString()); + } else { + avlReport = new AvlReport(result.getDeviceId().toString(), + result.getDeviceTime().toDate().getTime(), result.getLatitude().doubleValue(), + result.getLongitude().doubleValue(), result.getSpeed().multiply(BigDecimal.valueOf(0.5144444)).floatValue(), result.getCourse().floatValue(), TRACCARSOURCE.toString()); + } + if (avlReport != null) + avlReportsReadIn.add(avlReport); + } + forwardAvlReports(avlReportsReadIn); + } + + protected void forwardAvlReports(Collection avlReportsReadIn) { + processAvlReports(avlReportsReadIn); + } + + private Device findDeviceById(List devices, Integer id) { + for (Device device : devices) { + if (device.getId().equals(id)) + return device; + } + return null; + } + + @Override + protected Collection processData(InputStream in) throws Exception { + // Auto-generated method stub + return null; + } + +} diff --git a/core/src/main/java/org/transitclock/domain/structs/AvlReport.java b/core/src/main/java/org/transitclock/domain/structs/AvlReport.java index c74bc6e5e..78dbeb518 100644 --- a/core/src/main/java/org/transitclock/domain/structs/AvlReport.java +++ b/core/src/main/java/org/transitclock/domain/structs/AvlReport.java @@ -199,6 +199,31 @@ protected AvlReport() { * if speed not available * @param source Text describing the source of the report */ + + public AvlReport(String vehicleId, String vehicleName, long time, double lat, double lon, float speed, float heading, String source) { + // Store the values + this.vehicleId = vehicleId; + this.time = new Date(time); + this.location = new Location(lat, lon); + // DB requires null instead of NaN + this.speed = Float.isNaN(speed) ? null : speed; + this.heading = Float.isNaN(heading) ? null : heading; + this.source = sized(source); + this.assignmentId = null; + this.assignmentType = AssignmentType.UNSET; + this.leadVehicleId = null; + this.driverId = null; + this.licensePlate = null; + this.passengerCount = null; + this.passengerFullness = null; + this.field1Name = null; + this.field1Value = null; + this.vehicleName = vehicleName; + + // Don't yet know when processed so set timeProcessed to null + this.timeProcessed = null; + } + public AvlReport(String vehicleId, long time, double lat, double lon, float speed, float heading, String source) { // Store the values this.vehicleId = vehicleId; From ceb07370e62f0354aac953ba7ad4348bc8157d75 Mon Sep 17 00:00:00 2001 From: Timur Shykhsefiyeu Date: Fri, 1 Mar 2024 16:11:37 +0100 Subject: [PATCH 04/17] action test --- .github/workflows/maven.yml | 84 ++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 6ac210a3e..47ea628f7 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -10,7 +10,7 @@ name: Java CI with Maven on: push: - branches: [ "main", "refactor" ] + branches: [ "main", "traccar-module" ] pull_request: branches: [ "main" ] @@ -37,44 +37,44 @@ jobs: - name: Update dependency graph uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 - container-image: - if: github.repository_owner == 'opentransportro' && github.event_name == 'push' && (github.ref == 'refs/heads/main') - runs-on: ubuntu-latest - needs: - - build - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: 17 - distribution: temurin - cache: maven - - uses: actions/setup-node@v4 - with: - node-version: 18 - - name: Build container image with Jib, push to Dockerhub - env: - CONTAINER_REPO: docker.io/otrro/transitclock-server - CONTAINER_REGISTRY_USER: ${{secrets.DOCKER_USER}} - CONTAINER_REGISTRY_PASSWORD: ${{ secrets.DOCKER_AUTH }} - run: | - # we give the container two tags - # - "latest" - # - a string like "2.3_2022-12-12T21-38" - - version_with_snapshot=`mvn -q help:evaluate -Dexpression=project.version -q -DforceStdout` - version=${version_with_snapshot/-SNAPSHOT/} - - image_version=${version} - - ## if the Maven version contains SNAPSHOT, then add date to tag - if [[ $version_with_snapshot == *"SNAPSHOT"* ]]; then - image_date=`date +%Y-%m-%dT%H-%M` - image_version="${version}_${image_date}" - echo "Maven version ${version_with_snapshot} contains SNAPSHOT, adding date to container image tag" - fi - - mvn install jib:build -Djib.to.tags=latest,$image_version +# container-image: +# if: github.repository_owner == 'opentransportro' && github.event_name == 'push' && (github.ref == 'refs/heads/main') +# runs-on: ubuntu-latest +# needs: +# - build +# steps: +# - uses: actions/checkout@v4 +# with: +# fetch-depth: 0 +# - name: Set up JDK 17 +# uses: actions/setup-java@v4 +# with: +# java-version: 17 +# distribution: temurin +# cache: maven +# - uses: actions/setup-node@v4 +# with: +# node-version: 18 +# - name: Build container image with Jib, push to Dockerhub +# env: +# CONTAINER_REPO: docker.io/otrro/transitclock-server +# CONTAINER_REGISTRY_USER: ${{secrets.DOCKER_USER}} +# CONTAINER_REGISTRY_PASSWORD: ${{ secrets.DOCKER_AUTH }} +# run: | +# # we give the container two tags +# # - "latest" +# # - a string like "2.3_2022-12-12T21-38" +# +# version_with_snapshot=`mvn -q help:evaluate -Dexpression=project.version -q -DforceStdout` +# version=${version_with_snapshot/-SNAPSHOT/} +# +# image_version=${version} +# +# ## if the Maven version contains SNAPSHOT, then add date to tag +# if [[ $version_with_snapshot == *"SNAPSHOT"* ]]; then +# image_date=`date +%Y-%m-%dT%H-%M` +# image_version="${version}_${image_date}" +# echo "Maven version ${version_with_snapshot} contains SNAPSHOT, adding date to container image tag" +# fi +# +# mvn install jib:build -Djib.to.tags=latest,$image_version From 7453e9d43860013609fd8d5a4e558d0d285c765b Mon Sep 17 00:00:00 2001 From: Timur Shykhsefiyeu Date: Fri, 1 Mar 2024 20:01:41 +0100 Subject: [PATCH 05/17] fix: missing import & dependency --- core/pom.xml | 5 +++++ .../java/org/transitclock/core/avl/TraccarAVLModule.java | 1 + extensions/traccar/pom.xml | 2 -- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index fbcba4492..e2b64fc9d 100755 --- a/core/pom.xml +++ b/core/pom.xml @@ -207,6 +207,11 @@ com.fasterxml.jackson.module jackson-module-jakarta-xmlbind-annotations + + pl.goeuropa + traccar-client + ${revision} + diff --git a/core/src/main/java/org/transitclock/core/avl/TraccarAVLModule.java b/core/src/main/java/org/transitclock/core/avl/TraccarAVLModule.java index bf8e437a7..177abe546 100644 --- a/core/src/main/java/org/transitclock/core/avl/TraccarAVLModule.java +++ b/core/src/main/java/org/transitclock/core/avl/TraccarAVLModule.java @@ -31,6 +31,7 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collection; +import java.util.List; import static org.transitclock.config.data.TraccarConfig.*; diff --git a/extensions/traccar/pom.xml b/extensions/traccar/pom.xml index c2516ceb3..a4f26532d 100644 --- a/extensions/traccar/pom.xml +++ b/extensions/traccar/pom.xml @@ -13,8 +13,6 @@ traccar-client ${revision} - jar - 1.6.6 4.1.1.Final From a2d7d82013098051283cfa4817aab815b3c854a7 Mon Sep 17 00:00:00 2001 From: Timur Shykhsefiyeu Date: Fri, 1 Mar 2024 20:24:11 +0100 Subject: [PATCH 06/17] fix: actions --- .github/workflows/maven.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 47ea628f7..cb9ed78e3 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -10,7 +10,7 @@ name: Java CI with Maven on: push: - branches: [ "main", "traccar-module" ] + branches: [ "main", "refactoring" ] pull_request: branches: [ "main" ] @@ -34,8 +34,8 @@ jobs: run: mvn -B package --file pom.xml # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive - - name: Update dependency graph - uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 +# - name: Update dependency graph +# uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 # container-image: # if: github.repository_owner == 'opentransportro' && github.event_name == 'push' && (github.ref == 'refs/heads/main') From 41d4f069d460a37c715cf360b9b77b20f65bef9f Mon Sep 17 00:00:00 2001 From: Timur Shykhsefiyeu Date: Tue, 26 Mar 2024 15:28:35 +0100 Subject: [PATCH 07/17] add new methods to ConfigService & DbConfig --- .../java/org/transitclock/gtfs/DbConfig.java | 24 ++++++++++++++----- .../service/ConfigServiceImpl.java | 11 +++++++++ .../service/contract/ConfigInterface.java | 8 +++++++ 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/transitclock/gtfs/DbConfig.java b/core/src/main/java/org/transitclock/gtfs/DbConfig.java index 15f1ca20d..b5a6d5d1d 100644 --- a/core/src/main/java/org/transitclock/gtfs/DbConfig.java +++ b/core/src/main/java/org/transitclock/gtfs/DbConfig.java @@ -14,8 +14,6 @@ import lombok.extern.slf4j.Slf4j; import org.hibernate.HibernateException; import org.hibernate.Session; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.transitclock.Core; import org.transitclock.core.ServiceUtils; import org.transitclock.domain.hibernate.HibernateUtils; @@ -31,10 +29,7 @@ import org.transitclock.domain.structs.Transfer; import org.transitclock.domain.structs.Trip; import org.transitclock.domain.structs.TripPattern; -import org.transitclock.utils.IntervalTimer; -import org.transitclock.utils.MapKey; -import org.transitclock.utils.SystemTime; -import org.transitclock.utils.Time; +import org.transitclock.utils.*; /** * Reads all the configuration data from the database. The data is based on GTFS but is heavily @@ -686,6 +681,23 @@ public int getBlockCount() { return blockCount; } + /** + * Returns sorted lists of block IDs what belong to all service IDs + * + * @return Map of all service IDs with belong to block IDs + */ + public Map> getBlockIdsForAllServiceIds() { + Map> serviceIdsWithBlocks = new HashMap<>(); + + blocksByServiceMap.forEach((key, element) -> { + List ids = new ArrayList<>(); + element.forEach((innerKey, block) -> ids.add(block.getId())); + StringUtils.sortIdsNumerically(ids); + serviceIdsWithBlocks.put(key, ids); + }); + return serviceIdsWithBlocks; + } + /** * Returns blocks for the specified blockId for all service IDs. * diff --git a/core/src/main/java/org/transitclock/service/ConfigServiceImpl.java b/core/src/main/java/org/transitclock/service/ConfigServiceImpl.java index acc05666e..79abb0cd0 100644 --- a/core/src/main/java/org/transitclock/service/ConfigServiceImpl.java +++ b/core/src/main/java/org/transitclock/service/ConfigServiceImpl.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** @@ -360,4 +361,14 @@ public List getBlockIds(String serviceId) { .distinct() .collect(Collectors.toList()); } + + /* (non-Javadoc) + * @see org.transitclock.ipc.interfaces.ConfigInterface#getBlockIds() + */ + @Override + public Map> getServiceIdsWithBlockIds() { + return Core.getInstance() + .getDbConfig() + .getBlockIdsForAllServiceIds(); + } } diff --git a/core/src/main/java/org/transitclock/service/contract/ConfigInterface.java b/core/src/main/java/org/transitclock/service/contract/ConfigInterface.java index 0be18333b..2fad85674 100644 --- a/core/src/main/java/org/transitclock/service/contract/ConfigInterface.java +++ b/core/src/main/java/org/transitclock/service/contract/ConfigInterface.java @@ -13,6 +13,7 @@ import java.util.Collection; import java.util.List; +import java.util.Map; /** * Defines the RMI interface for getting configuration data. @@ -174,4 +175,11 @@ IpcRoute getRoute(String routeIdOrShortName, String directionId, String stopId, * @return vehicle IDs */ List getBlockIds(String serviceId); + + /** + * Returns sorted lists of block IDs what belong to all service IDs + * + * @return Map of service IDs with belong block IDs + */ + Map> getServiceIdsWithBlockIds (); } From abd8d8ddcb5ec0371d900fbdee03ecb1e9b0b08f Mon Sep 17 00:00:00 2001 From: Timur Shykhsefiyeu Date: Tue, 26 Mar 2024 17:14:13 +0100 Subject: [PATCH 08/17] add a new return object to /command/blockIds endpoint --- .../transitclock/api/data/ApiServiceId.java | 35 ++++++++++++++++ .../transitclock/api/data/ApiServiceIds.java | 41 +++++++++++++++++++ .../api/resources/TransitimeApi.java | 40 +++++------------- .../service/contract/ConfigInterface.java | 4 +- 4 files changed, 88 insertions(+), 32 deletions(-) create mode 100644 app/src/main/java/org/transitclock/api/data/ApiServiceId.java create mode 100644 app/src/main/java/org/transitclock/api/data/ApiServiceIds.java diff --git a/app/src/main/java/org/transitclock/api/data/ApiServiceId.java b/app/src/main/java/org/transitclock/api/data/ApiServiceId.java new file mode 100644 index 000000000..b31a3c93e --- /dev/null +++ b/app/src/main/java/org/transitclock/api/data/ApiServiceId.java @@ -0,0 +1,35 @@ +/* (C)2023 */ +package org.transitclock.api.data; + +import jakarta.xml.bind.annotation.XmlAttribute; + +import java.util.List; +import java.util.Map; + +/** + * A short description of a serviceId. For when outputting list of block IDs for service. + * + * @author SkiBu Smith + */ +public class ApiServiceId { + + @XmlAttribute + private String id; + + @XmlAttribute + private List blockIds; + + /********************** Member Functions **************************/ + + /** + * Need a no-arg constructor for Jersey. Otherwise get really obtuse "MessageBodyWriter not + * found for media type=application/json" exception. + */ + protected ApiServiceId() { + } + + public ApiServiceId(String serviceId, List blockIds) { + this.id = serviceId; + this.blockIds = blockIds; + } +} diff --git a/app/src/main/java/org/transitclock/api/data/ApiServiceIds.java b/app/src/main/java/org/transitclock/api/data/ApiServiceIds.java new file mode 100644 index 000000000..17115deb8 --- /dev/null +++ b/app/src/main/java/org/transitclock/api/data/ApiServiceIds.java @@ -0,0 +1,41 @@ +/* (C)2023 */ +package org.transitclock.api.data; + +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlRootElement; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * For outputting simple list of unsorted service IDs with lists of sorted block IDs + * + * @author SkiBu Smith + */ +@XmlRootElement(name= "allServiceIds") +public class ApiServiceIds { + + @XmlElement + private List apiServiceIds; + + /********************** Member Functions **************************/ + + /** + * Need a no-arg constructor for Jersey. Otherwise get really obtuse "MessageBodyWriter not + * found for media type=application/json" exception. + */ + protected ApiServiceIds() { + } + + /** + * Creates the API unsorted version of list of IDs. + * + * @param serviceIds + */ + public ApiServiceIds(Map> serviceIds) { + apiServiceIds = new ArrayList<>(); + serviceIds.forEach((key, list) -> apiServiceIds + .add(new ApiServiceId(key,list))); + } +} diff --git a/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java b/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java index 1811cdebe..7a99b0991 100644 --- a/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java +++ b/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java @@ -26,33 +26,7 @@ import jakarta.ws.rs.core.Response; import org.apache.commons.lang3.StringUtils; import org.hibernate.Session; -import org.transitclock.api.data.ApiActiveBlocks; -import org.transitclock.api.data.ApiActiveBlocksRoutes; -import org.transitclock.api.data.ApiAdherenceSummary; -import org.transitclock.api.data.ApiAgencies; -import org.transitclock.api.data.ApiAgency; -import org.transitclock.api.data.ApiBlock; -import org.transitclock.api.data.ApiBlocks; -import org.transitclock.api.data.ApiBlocksTerse; -import org.transitclock.api.data.ApiCalendars; -import org.transitclock.api.data.ApiCurrentServerDate; -import org.transitclock.api.data.ApiDirections; -import org.transitclock.api.data.ApiExportsData; -import org.transitclock.api.data.ApiIds; -import org.transitclock.api.data.ApiPredictions; -import org.transitclock.api.data.ApiRmiServerStatus; -import org.transitclock.api.data.ApiRoutes; -import org.transitclock.api.data.ApiRoutesDetails; -import org.transitclock.api.data.ApiSchedulesHorizStops; -import org.transitclock.api.data.ApiSchedulesVertStops; -import org.transitclock.api.data.ApiServerStatus; -import org.transitclock.api.data.ApiTrip; -import org.transitclock.api.data.ApiTripPatterns; -import org.transitclock.api.data.ApiTripWithTravelTimes; -import org.transitclock.api.data.ApiVehicleConfigs; -import org.transitclock.api.data.ApiVehicleToBlockConfigs; -import org.transitclock.api.data.ApiVehicles; -import org.transitclock.api.data.ApiVehiclesDetails; +import org.transitclock.api.data.*; import org.transitclock.api.utils.PredsByLoc; import org.transitclock.api.utils.StandardParameters; import org.transitclock.api.utils.WebUtils; @@ -1254,11 +1228,12 @@ public Response getBlocks( @Operation( summary = "Retrives a list of all blockId for the specified service ID", description = "Retrives a list of all blockId for the specified service ID." - + "Every trip is associated with a block.", + + " Every trip is associated with a block.", tags = {"base data", "trip", "block"}) public Response getBlockIds( @BeanParam StandardParameters stdParameters, - @Parameter(description = "if set, returns only the data for that serviceId.", required = false) + @Parameter(description = "If Id is set, returns only data for that serviceId or " + + "when set \"all\", returns whole data for all serviceIds", required = false) @QueryParam(value = "serviceId") String serviceId) throws WebApplicationException { @@ -1268,8 +1243,13 @@ public Response getBlockIds( try { // Get Vehicle data from server ConfigInterface inter = stdParameters.getConfigInterface(); - List ids = inter.getBlockIds(serviceId); + // Get service IDs with block Ids + if (serviceId != null && serviceId.equals("all")){ + ApiServiceIds serviceIdsWithBlockIds = new ApiServiceIds(inter.getServiceIdsWithBlockIds()); + return stdParameters.createResponse(serviceIdsWithBlockIds); + } + List ids = inter.getBlockIds(serviceId); ApiIds apiIds = new ApiIds(ids); return stdParameters.createResponse(apiIds); } catch (Exception e) { diff --git a/core/src/main/java/org/transitclock/service/contract/ConfigInterface.java b/core/src/main/java/org/transitclock/service/contract/ConfigInterface.java index 2fad85674..d8e59e759 100644 --- a/core/src/main/java/org/transitclock/service/contract/ConfigInterface.java +++ b/core/src/main/java/org/transitclock/service/contract/ConfigInterface.java @@ -52,7 +52,7 @@ IpcRoute getRoute(String routeIdOrShortName, String directionId, String stopId, /** * Obtains ordered list of route details * - * @param routeIdOrShortName + * @param routeIdsOrShortNames * @return */ List getRoutes(List routeIdsOrShortNames); @@ -181,5 +181,5 @@ IpcRoute getRoute(String routeIdOrShortName, String directionId, String stopId, * * @return Map of service IDs with belong block IDs */ - Map> getServiceIdsWithBlockIds (); + Map> getServiceIdsWithBlockIds(); } From 2e2a02ff182e1c8aa9579d564b18cd8d7693085c Mon Sep 17 00:00:00 2001 From: Timur Shykhsefiyeu Date: Wed, 27 Mar 2024 09:51:01 +0100 Subject: [PATCH 09/17] replace functionality: /command/blockIds -> /command/serviceIds --- .../transitclock/api/data/ApiServiceIds.java | 4 +-- .../api/resources/TransitimeApi.java | 28 ++++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/org/transitclock/api/data/ApiServiceIds.java b/app/src/main/java/org/transitclock/api/data/ApiServiceIds.java index 17115deb8..72912b8b3 100644 --- a/app/src/main/java/org/transitclock/api/data/ApiServiceIds.java +++ b/app/src/main/java/org/transitclock/api/data/ApiServiceIds.java @@ -13,10 +13,10 @@ * * @author SkiBu Smith */ -@XmlRootElement(name= "allServiceIds") +@XmlRootElement public class ApiServiceIds { - @XmlElement + @XmlElement(name= "serviceIds") private List apiServiceIds; /********************** Member Functions **************************/ diff --git a/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java b/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java index 7a99b0991..150018968 100644 --- a/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java +++ b/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java @@ -1232,10 +1232,9 @@ public Response getBlocks( tags = {"base data", "trip", "block"}) public Response getBlockIds( @BeanParam StandardParameters stdParameters, - @Parameter(description = "If Id is set, returns only data for that serviceId or " + - "when set \"all\", returns whole data for all serviceIds", required = false) - @QueryParam(value = "serviceId") - String serviceId) + @Parameter(description = "If set, returns only the data for that serviceId.", required = false) + @QueryParam(value = "serviceId") + String serviceId) throws WebApplicationException { // Make sure request is valid stdParameters.validate(); @@ -1243,13 +1242,8 @@ public Response getBlockIds( try { // Get Vehicle data from server ConfigInterface inter = stdParameters.getConfigInterface(); - // Get service IDs with block Ids - if (serviceId != null && serviceId.equals("all")){ - ApiServiceIds serviceIdsWithBlockIds = new ApiServiceIds(inter.getServiceIdsWithBlockIds()); - return stdParameters.createResponse(serviceIdsWithBlockIds); - } - List ids = inter.getBlockIds(serviceId); + ApiIds apiIds = new ApiIds(ids); return stdParameters.createResponse(apiIds); } catch (Exception e) { @@ -1982,16 +1976,24 @@ public Response getAllCalendars(@BeanParam StandardParameters stdParameters) thr @GET @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Operation( - summary = "Retrives all service id.", - description = "Retrives all service id.", + summary = "Retrives all service id. Optionally, retrives all service id with blockIds", + description = "Retrives all service id. Optionally, retrives all service id with blockIds", tags = {"base data", "serviceId"}) - public Response getServiceIds(@BeanParam StandardParameters stdParameters) throws WebApplicationException { + public Response getServiceIds(@BeanParam StandardParameters stdParameters, + @Parameter (description = "If set \"blocks\", returns assigned blockIds to all serviceIds", required = false) + @QueryParam(value = "withBlockIds") + String withBlockIds) throws WebApplicationException { // Make sure request is valid stdParameters.validate(); try { // Get Vehicle data from server ConfigInterface inter = stdParameters.getConfigInterface(); + // Get service IDs with block Ids + if (withBlockIds != null && withBlockIds.equals("blocks")){ + ApiServiceIds serviceIdsWithBlockIds = new ApiServiceIds(inter.getServiceIdsWithBlockIds()); + return stdParameters.createResponse(serviceIdsWithBlockIds); + } List ids = inter.getServiceIds(); ApiIds apiIds = new ApiIds(ids); From d5c11e7f6cf6c17133279b6dbe8a0ea07cd9d0e2 Mon Sep 17 00:00:00 2001 From: Timur Shykhsefiyeu Date: Wed, 27 Mar 2024 10:39:30 +0100 Subject: [PATCH 10/17] fix: parameter boolean --- .../java/org/transitclock/api/resources/TransitimeApi.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java b/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java index 150018968..be52e11ba 100644 --- a/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java +++ b/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java @@ -1980,9 +1980,9 @@ public Response getAllCalendars(@BeanParam StandardParameters stdParameters) thr description = "Retrives all service id. Optionally, retrives all service id with blockIds", tags = {"base data", "serviceId"}) public Response getServiceIds(@BeanParam StandardParameters stdParameters, - @Parameter (description = "If set \"blocks\", returns assigned blockIds to all serviceIds", required = false) + @Parameter (description = "If set 'true', returns serviceIds with assigned blockIds", required = false) @QueryParam(value = "withBlockIds") - String withBlockIds) throws WebApplicationException { + boolean withBlockIds) throws WebApplicationException { // Make sure request is valid stdParameters.validate(); @@ -1990,7 +1990,7 @@ public Response getServiceIds(@BeanParam StandardParameters stdParameters, // Get Vehicle data from server ConfigInterface inter = stdParameters.getConfigInterface(); // Get service IDs with block Ids - if (withBlockIds != null && withBlockIds.equals("blocks")){ + if (withBlockIds) { ApiServiceIds serviceIdsWithBlockIds = new ApiServiceIds(inter.getServiceIdsWithBlockIds()); return stdParameters.createResponse(serviceIdsWithBlockIds); } From 34b204ff669a4318dbce3e993222dc2930e8fece Mon Sep 17 00:00:00 2001 From: Timur Shykhsefiyeu Date: Thu, 28 Mar 2024 11:47:13 +0100 Subject: [PATCH 11/17] fix: container-image --- .github/workflows/maven.yml | 82 ++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index cb9ed78e3..b23fd1cd4 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -37,44 +37,44 @@ jobs: # - name: Update dependency graph # uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 -# container-image: -# if: github.repository_owner == 'opentransportro' && github.event_name == 'push' && (github.ref == 'refs/heads/main') -# runs-on: ubuntu-latest -# needs: -# - build -# steps: -# - uses: actions/checkout@v4 -# with: -# fetch-depth: 0 -# - name: Set up JDK 17 -# uses: actions/setup-java@v4 -# with: -# java-version: 17 -# distribution: temurin -# cache: maven -# - uses: actions/setup-node@v4 -# with: -# node-version: 18 -# - name: Build container image with Jib, push to Dockerhub -# env: -# CONTAINER_REPO: docker.io/otrro/transitclock-server -# CONTAINER_REGISTRY_USER: ${{secrets.DOCKER_USER}} -# CONTAINER_REGISTRY_PASSWORD: ${{ secrets.DOCKER_AUTH }} -# run: | -# # we give the container two tags -# # - "latest" -# # - a string like "2.3_2022-12-12T21-38" -# -# version_with_snapshot=`mvn -q help:evaluate -Dexpression=project.version -q -DforceStdout` -# version=${version_with_snapshot/-SNAPSHOT/} -# -# image_version=${version} -# -# ## if the Maven version contains SNAPSHOT, then add date to tag -# if [[ $version_with_snapshot == *"SNAPSHOT"* ]]; then -# image_date=`date +%Y-%m-%dT%H-%M` -# image_version="${version}_${image_date}" -# echo "Maven version ${version_with_snapshot} contains SNAPSHOT, adding date to container image tag" -# fi -# -# mvn install jib:build -Djib.to.tags=latest,$image_version + container-image: + if: github.repository_owner == 'goeuropa' && github.event_name == 'push' && (github.ref == 'refs/heads/main') + runs-on: ubuntu-latest + needs: + - build + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: temurin + cache: maven + - uses: actions/setup-node@v4 + with: + node-version: 18 + - name: Build container image with Jib, push to Dockerhub + env: + CONTAINER_REPO: docker.io/wkulesza/transitclock-server + CONTAINER_REGISTRY_USER: ${{secrets.DOCKER_USER}} + CONTAINER_REGISTRY_PASSWORD: ${{secrets.DOCKER_AUTH}} + run: | + # we give the container two tags + # - "latest" + # - a string like "2.3_2022-12-12T21-38" + + version_with_snapshot=`mvn -q help:evaluate -Dexpression=project.version -q -DforceStdout` + version=${version_with_snapshot/-SNAPSHOT/} + + image_version=${version} + + ## if the Maven version contains SNAPSHOT, then add date to tag + if [[ $version_with_snapshot == *"SNAPSHOT"* ]]; then + image_date=`date +%Y-%m-%dT%H-%M` + image_version="${version}_${image_date}" + echo "Maven version ${version_with_snapshot} contains SNAPSHOT, adding date to container image tag" + fi + + mvn install jib:build -Djib.to.tags=latest,$image_version From be984c9aa3a5e9a4c6d25ac652dcde4efe20b9ee Mon Sep 17 00:00:00 2001 From: Timur Shykhsefiyeu Date: Fri, 29 Mar 2024 07:45:31 +0100 Subject: [PATCH 12/17] add fetch all to command/vehiclesToBlock --- .../data/ApiVehicleToBlockConfigAbstract.java | 2 +- .../api/data/ApiVehicleToBlockConfigs.java | 24 +++------ .../api/resources/TransitimeApi.java | 18 ++++--- .../domain/structs/VehicleToBlockConfig.java | 22 +++++--- .../service/VehiclesServiceImpl.java | 50 +++++++++++-------- .../service/contract/VehiclesInterface.java | 12 ++++- 6 files changed, 75 insertions(+), 53 deletions(-) diff --git a/app/src/main/java/org/transitclock/api/data/ApiVehicleToBlockConfigAbstract.java b/app/src/main/java/org/transitclock/api/data/ApiVehicleToBlockConfigAbstract.java index 025a43664..a0186ace9 100644 --- a/app/src/main/java/org/transitclock/api/data/ApiVehicleToBlockConfigAbstract.java +++ b/app/src/main/java/org/transitclock/api/data/ApiVehicleToBlockConfigAbstract.java @@ -50,7 +50,7 @@ public abstract class ApiVehicleToBlockConfigAbstract { protected ApiVehicleToBlockConfigAbstract() {} /** - * Takes a Vehicle object for client/server communication and constructs a ApiVehicle object for + * Takes a VehicleToBlockConfig object for client/server communication and constructs a ApiVehicleToBlockConfig object for * the API. * * @param vehicle diff --git a/app/src/main/java/org/transitclock/api/data/ApiVehicleToBlockConfigs.java b/app/src/main/java/org/transitclock/api/data/ApiVehicleToBlockConfigs.java index 92821ea7b..57b1efecb 100644 --- a/app/src/main/java/org/transitclock/api/data/ApiVehicleToBlockConfigs.java +++ b/app/src/main/java/org/transitclock/api/data/ApiVehicleToBlockConfigs.java @@ -1,14 +1,13 @@ /* (C)2023 */ package org.transitclock.api.data; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import org.transitclock.service.dto.IpcVehicleToBlockConfig; +import java.util.ArrayList; +import java.util.List; + /** * For when have list of VehicleDetails. By using this class can control the element name when data * is output. @@ -18,7 +17,7 @@ @XmlRootElement public class ApiVehicleToBlockConfigs { - @XmlElement(name = "vehicleToBlock") + @XmlElement(name = "vehiclesToBlock") private List vehiclesData; /********************** Member Functions **************************/ @@ -27,23 +26,16 @@ public class ApiVehicleToBlockConfigs { * Need a no-arg constructor for Jersey. Otherwise get really obtuse "MessageBodyWriter not * found for media type=application/json" exception. */ - protected ApiVehicleToBlockConfigs() {} + protected ApiVehicleToBlockConfigs() { + } /** - * For constructing a ApiVehiclesDetails object from a Collection of Vehicle objects. + * For constructing a ApiVehicleToBlockConfigs object from a Collection of VehicleToBlockConfig objects. * * @param vehicles - * @param agencyId - * @param uiTypesForVehicles Specifies how vehicles should be drawn in UI. Can be NORMAL, - * SECONDARY, or MINOR - * @param assigned - * @throws InvocationTargetException - * @throws IllegalAccessException */ - public ApiVehicleToBlockConfigs(Collection vehicles) - throws IllegalAccessException, InvocationTargetException { + public ApiVehicleToBlockConfigs(List vehicles) { vehiclesData = new ArrayList(); - for (IpcVehicleToBlockConfig vehicleToBlock : vehicles) { vehiclesData.add(new ApiVehicleToBlockConfig(vehicleToBlock)); } diff --git a/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java b/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java index be52e11ba..5e033c0bd 100644 --- a/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java +++ b/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java @@ -50,7 +50,6 @@ import org.transitclock.service.dto.IpcTripPattern; import org.transitclock.service.dto.IpcVehicle; import org.transitclock.service.dto.IpcVehicleConfig; -import org.transitclock.service.dto.IpcVehicleToBlockConfig; import org.transitclock.service.contract.ConfigInterface; import org.transitclock.service.contract.PredictionsInterface; import org.transitclock.service.contract.PredictionsInterface.RouteStop; @@ -176,21 +175,28 @@ public Response getVehicles( @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public Response getVehiclesToBlock( @BeanParam StandardParameters stdParameters, - @Parameter(description = "Block id") @QueryParam(value = "blockId") String blockId) + @Parameter(description = "If set 'true', returns only the data with actual time windows.", required = false) + @QueryParam(value = "actual") boolean isActual, + @Parameter(description = "If set, returns only the data for that block Id.", required = false) + @QueryParam(value = "blockId") String blockId ) throws WebApplicationException { stdParameters.validate(); - Collection result = null; try { // Get Vehicle data from server VehiclesInterface inter = stdParameters.getVehiclesInterface(); - result = inter.getVehicleToBlockConfig(blockId); + if(isActual){ + var actualVTBC = inter.getActualVehicleToBlockConfigs(); + ApiVehicleToBlockConfigs apiVTBC = new ApiVehicleToBlockConfigs(actualVTBC); + // return actual ApiVehicleToBlockConfigs response + return stdParameters.createResponse(apiVTBC); + } + var result = inter.getVehicleToBlockConfigByBlockId(blockId); ApiVehicleToBlockConfigs apiVTBC = new ApiVehicleToBlockConfigs(result); - - // return ApiVehicles response + // return ApiVehicleToBlockConfigs response return stdParameters.createResponse(apiVTBC); } catch (Exception e) { // If problem getting data then return a Bad Request diff --git a/core/src/main/java/org/transitclock/domain/structs/VehicleToBlockConfig.java b/core/src/main/java/org/transitclock/domain/structs/VehicleToBlockConfig.java index bc0a81a51..3fa36508e 100644 --- a/core/src/main/java/org/transitclock/domain/structs/VehicleToBlockConfig.java +++ b/core/src/main/java/org/transitclock/domain/structs/VehicleToBlockConfig.java @@ -2,17 +2,17 @@ package org.transitclock.domain.structs; import jakarta.persistence.*; -import java.io.Serializable; -import java.util.Date; -import java.util.List; - -import lombok.*; +import lombok.Data; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.annotations.DynamicUpdate; import org.transitclock.Core; +import java.io.Serializable; +import java.util.Date; +import java.util.List; + /** * For storing static configuration for vehicle in block. * @@ -64,7 +64,7 @@ public VehicleToBlockConfig( /** * @param vehicleId vehicle ID * @param blockId block ID * @param tripId trip ID * @param - * assignmentDate time * * @param validFrom time * * @param validTo time + * assignmentDate time * * @param validFrom time * * @param validTo time */ public static VehicleToBlockConfig create( String vehicleId, String blockId, String tripId, Date assignmentDate, Date validFrom, Date validTo) { @@ -78,7 +78,9 @@ public static VehicleToBlockConfig create( return vehicleToBlockConfig; } - /** Needed because Hibernate requires no-arg constructor */ + /** + * Needed because Hibernate requires no-arg constructor + */ @SuppressWarnings("unused") protected VehicleToBlockConfig() { vehicleId = null; @@ -128,6 +130,12 @@ public static void deleteVehicleToBlockConfig(long id, Session session) throws H } } + public static List getActualVehicleToBlockConfigs(Session session) throws HibernateException { + return session + .createQuery("FROM VehicleToBlockConfig WHERE validTo > now() ORDER BY assignmentDate DESC", VehicleToBlockConfig.class) + .list(); + } + public static List getVehicleToBlockConfigsByBlockId(Session session, String blockId) throws HibernateException { return session .createQuery("FROM VehicleToBlockConfig WHERE blockId = :blockId ORDER BY assignmentDate DESC", VehicleToBlockConfig.class) diff --git a/core/src/main/java/org/transitclock/service/VehiclesServiceImpl.java b/core/src/main/java/org/transitclock/service/VehiclesServiceImpl.java index f622e9566..9091a95cd 100644 --- a/core/src/main/java/org/transitclock/service/VehiclesServiceImpl.java +++ b/core/src/main/java/org/transitclock/service/VehiclesServiceImpl.java @@ -7,19 +7,9 @@ import org.transitclock.core.BlocksInfo; import org.transitclock.core.dataCache.VehicleDataCache; import org.transitclock.domain.hibernate.HibernateUtils; -import org.transitclock.domain.structs.Block; -import org.transitclock.domain.structs.QRoute; -import org.transitclock.domain.structs.Trip; -import org.transitclock.domain.structs.VehicleConfig; -import org.transitclock.domain.structs.VehicleToBlockConfig; +import org.transitclock.domain.structs.*; import org.transitclock.service.contract.VehiclesInterface; -import org.transitclock.service.dto.IpcActiveBlock; -import org.transitclock.service.dto.IpcBlock; -import org.transitclock.service.dto.IpcVehicle; -import org.transitclock.service.dto.IpcVehicleComplete; -import org.transitclock.service.dto.IpcVehicleConfig; -import org.transitclock.service.dto.IpcVehicleGtfsRealtime; -import org.transitclock.service.dto.IpcVehicleToBlockConfig; +import org.transitclock.service.dto.*; import java.io.Serializable; import java.util.ArrayList; @@ -396,29 +386,47 @@ public Collection getVehiclesForBlocks() { } @Override - public Collection getVehicleToBlockConfig(String blockId) { + public List getActualVehicleToBlockConfigs() { List result = new ArrayList<>(); - try (Session session = HibernateUtils.getSession()){ - for (VehicleToBlockConfig vTBC : VehicleToBlockConfig.getVehicleToBlockConfigsByBlockId(session, blockId)) { + try (Session session = HibernateUtils.getSession()) { + for (VehicleToBlockConfig vTBC : VehicleToBlockConfig + .getActualVehicleToBlockConfigs(session)) { result.add(new IpcVehicleToBlockConfig(vTBC)); } } catch (Exception ex) { - logger.error("Something happened while fetching the VehicleToBlockConfig.", ex); + logger.error("Something happened while fetching the data: ", ex); } return result; } @Override - public Collection getVehicleToBlockConfigByVehicleId(String vehicleId) { + public List getVehicleToBlockConfigByBlockId(String blockId) { List result = new ArrayList<>(); - Session session = HibernateUtils.getSession(); - try { + try (Session session = HibernateUtils.getSession()) { + if (blockId != null) { + for (VehicleToBlockConfig vTBC : VehicleToBlockConfig.getVehicleToBlockConfigsByBlockId(session, blockId)) { + result.add(new IpcVehicleToBlockConfig(vTBC)); + } + } else { + for (VehicleToBlockConfig vTBC : VehicleToBlockConfig.getVehicleToBlockConfigs(session)) { + result.add(new IpcVehicleToBlockConfig(vTBC)); + } + } + } catch (Exception ex) { + logger.error("Something happened while fetching the data.", ex); + } + return result; + } + + @Override + public List getVehicleToBlockConfigByVehicleId(String vehicleId) { + List result = new ArrayList<>(); + try (Session session = HibernateUtils.getSession()) { for (var vTBC : VehicleToBlockConfig.getVehicleToBlockConfigsByVehicleId(session, vehicleId)) { result.add(new IpcVehicleToBlockConfig(vTBC)); } - session.close(); } catch (Exception ex) { - session.close(); + logger.error("Something happened while fetching the data.", ex); } return result; } diff --git a/core/src/main/java/org/transitclock/service/contract/VehiclesInterface.java b/core/src/main/java/org/transitclock/service/contract/VehiclesInterface.java index 8b308fee9..278d95c16 100644 --- a/core/src/main/java/org/transitclock/service/contract/VehiclesInterface.java +++ b/core/src/main/java/org/transitclock/service/contract/VehiclesInterface.java @@ -9,6 +9,7 @@ import org.transitclock.service.dto.IpcVehicleToBlockConfig; import java.util.Collection; +import java.util.List; /** * Defines the RMI interface used for obtaining vehicle information. @@ -174,7 +175,14 @@ Collection getActiveBlocks(Collection routeIds, int allo */ int getNumActiveBlocks(Collection routeIds, int allowableBeforeTimeSecs); - Collection getVehicleToBlockConfig(String blockId); + /** + * Gets from the server the List of VehicleToBlocksConfig that are currently active. + * + * @return Collection of VehicleToBlocksConfig that are active. + */ + List getActualVehicleToBlockConfigs(); + + List getVehicleToBlockConfigByBlockId(String blockId); - Collection getVehicleToBlockConfigByVehicleId(String vehicleId); + List getVehicleToBlockConfigByVehicleId(String vehicleId); } From 4dba5a560f4afa89faa25784b19a5e975fe84e5a Mon Sep 17 00:00:00 2001 From: Timur Shykhsefiyeu Date: Fri, 29 Mar 2024 10:30:15 +0100 Subject: [PATCH 13/17] refactoring: #1 --- .../api/data/ApiVehicleToBlockConfig.java | 6 +++--- .../data/ApiVehicleToBlockConfigAbstract.java | 19 +++++++++---------- .../api/resources/TransitimeApi.java | 12 ++++++------ .../org/transitclock/core/AvlProcessor.java | 6 +++--- .../service/VehiclesServiceImpl.java | 16 ++++++++-------- 5 files changed, 29 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/org/transitclock/api/data/ApiVehicleToBlockConfig.java b/app/src/main/java/org/transitclock/api/data/ApiVehicleToBlockConfig.java index e6f7348c9..9da737b26 100644 --- a/app/src/main/java/org/transitclock/api/data/ApiVehicleToBlockConfig.java +++ b/app/src/main/java/org/transitclock/api/data/ApiVehicleToBlockConfig.java @@ -27,9 +27,9 @@ protected ApiVehicleToBlockConfig() {} * Takes a Vehicle object for client/server communication and constructs a ApiVehicle object for * the API. Sets UiMode to UiMode.NORMAL. * - * @param vTBC + * @param vehicleToBlockConfig */ - public ApiVehicleToBlockConfig(IpcVehicleToBlockConfig vTBC) { - super(vTBC); + public ApiVehicleToBlockConfig(IpcVehicleToBlockConfig vehicleToBlockConfig) { + super(vehicleToBlockConfig); } } diff --git a/app/src/main/java/org/transitclock/api/data/ApiVehicleToBlockConfigAbstract.java b/app/src/main/java/org/transitclock/api/data/ApiVehicleToBlockConfigAbstract.java index a0186ace9..77d5b07e3 100644 --- a/app/src/main/java/org/transitclock/api/data/ApiVehicleToBlockConfigAbstract.java +++ b/app/src/main/java/org/transitclock/api/data/ApiVehicleToBlockConfigAbstract.java @@ -53,16 +53,15 @@ protected ApiVehicleToBlockConfigAbstract() {} * Takes a VehicleToBlockConfig object for client/server communication and constructs a ApiVehicleToBlockConfig object for * the API. * - * @param vehicle - * @param uiType If should be labeled as "minor" in output for UI. + * @param vehicleToBlockConfig */ - public ApiVehicleToBlockConfigAbstract(IpcVehicleToBlockConfig vTBC) { - id = vTBC.getId(); - vehicleId = vTBC.getVehicleId(); - tripId = vTBC.getTripId(); - blockId = vTBC.getBlockId(); - validFrom = vTBC.getValidFrom(); - validTo = vTBC.getValidTo(); - assignmentDate = vTBC.getAssignmentDate(); + public ApiVehicleToBlockConfigAbstract(IpcVehicleToBlockConfig vehicleToBlockConfig) { + id = vehicleToBlockConfig.getId(); + vehicleId = vehicleToBlockConfig.getVehicleId(); + tripId = vehicleToBlockConfig.getTripId(); + blockId = vehicleToBlockConfig.getBlockId(); + validFrom = vehicleToBlockConfig.getValidFrom(); + validTo = vehicleToBlockConfig.getValidTo(); + assignmentDate = vehicleToBlockConfig.getAssignmentDate(); } } diff --git a/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java b/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java index 5e033c0bd..344cb7236 100644 --- a/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java +++ b/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java @@ -188,16 +188,16 @@ public Response getVehiclesToBlock( VehiclesInterface inter = stdParameters.getVehiclesInterface(); if(isActual){ - var actualVTBC = inter.getActualVehicleToBlockConfigs(); - ApiVehicleToBlockConfigs apiVTBC = new ApiVehicleToBlockConfigs(actualVTBC); + var actualConfigs = inter.getActualVehicleToBlockConfigs(); + ApiVehicleToBlockConfigs vehiclesToBlocks = new ApiVehicleToBlockConfigs(actualConfigs); // return actual ApiVehicleToBlockConfigs response - return stdParameters.createResponse(apiVTBC); + return stdParameters.createResponse(vehiclesToBlocks); } - var result = inter.getVehicleToBlockConfigByBlockId(blockId); + var configs = inter.getVehicleToBlockConfigByBlockId(blockId); - ApiVehicleToBlockConfigs apiVTBC = new ApiVehicleToBlockConfigs(result); + ApiVehicleToBlockConfigs vehiclesToBlocks = new ApiVehicleToBlockConfigs(configs); // return ApiVehicleToBlockConfigs response - return stdParameters.createResponse(apiVTBC); + return stdParameters.createResponse(vehiclesToBlocks); } catch (Exception e) { // If problem getting data then return a Bad Request throw WebUtils.badRequestException(e); diff --git a/core/src/main/java/org/transitclock/core/AvlProcessor.java b/core/src/main/java/org/transitclock/core/AvlProcessor.java index bd8b10c74..b1e172e03 100644 --- a/core/src/main/java/org/transitclock/core/AvlProcessor.java +++ b/core/src/main/java/org/transitclock/core/AvlProcessor.java @@ -1386,12 +1386,12 @@ public void processAvlReport(AvlReport avlReport) { } try (Session session = HibernateUtils.getSession()) { String blockId = null; - for (VehicleToBlockConfig vTBC : + for (VehicleToBlockConfig vehicleToBlock : VehicleToBlockConfig.getVehicleToBlockConfigsByVehicleId(session, avlReport.getVehicleId())) { Date d = new Date(); - if (d.after(vTBC.getValidFrom()) && d.before(vTBC.getValidTo())) { - blockId = vTBC.getBlockId(); + if (d.after(vehicleToBlock.getValidFrom()) && d.before(vehicleToBlock.getValidTo())) { + blockId = vehicleToBlock.getBlockId(); break; } } diff --git a/core/src/main/java/org/transitclock/service/VehiclesServiceImpl.java b/core/src/main/java/org/transitclock/service/VehiclesServiceImpl.java index 9091a95cd..f79fc88e8 100644 --- a/core/src/main/java/org/transitclock/service/VehiclesServiceImpl.java +++ b/core/src/main/java/org/transitclock/service/VehiclesServiceImpl.java @@ -389,9 +389,9 @@ public Collection getVehiclesForBlocks() { public List getActualVehicleToBlockConfigs() { List result = new ArrayList<>(); try (Session session = HibernateUtils.getSession()) { - for (VehicleToBlockConfig vTBC : VehicleToBlockConfig + for (VehicleToBlockConfig vehicleToBlockConfig : VehicleToBlockConfig .getActualVehicleToBlockConfigs(session)) { - result.add(new IpcVehicleToBlockConfig(vTBC)); + result.add(new IpcVehicleToBlockConfig(vehicleToBlockConfig)); } } catch (Exception ex) { logger.error("Something happened while fetching the data: ", ex); @@ -404,12 +404,12 @@ public List getVehicleToBlockConfigByBlockId(String blo List result = new ArrayList<>(); try (Session session = HibernateUtils.getSession()) { if (blockId != null) { - for (VehicleToBlockConfig vTBC : VehicleToBlockConfig.getVehicleToBlockConfigsByBlockId(session, blockId)) { - result.add(new IpcVehicleToBlockConfig(vTBC)); + for (VehicleToBlockConfig vehicleToBlockConfig : VehicleToBlockConfig.getVehicleToBlockConfigsByBlockId(session, blockId)) { + result.add(new IpcVehicleToBlockConfig(vehicleToBlockConfig)); } } else { - for (VehicleToBlockConfig vTBC : VehicleToBlockConfig.getVehicleToBlockConfigs(session)) { - result.add(new IpcVehicleToBlockConfig(vTBC)); + for (VehicleToBlockConfig vehicleToBlockConfig : VehicleToBlockConfig.getVehicleToBlockConfigs(session)) { + result.add(new IpcVehicleToBlockConfig(vehicleToBlockConfig)); } } } catch (Exception ex) { @@ -422,8 +422,8 @@ public List getVehicleToBlockConfigByBlockId(String blo public List getVehicleToBlockConfigByVehicleId(String vehicleId) { List result = new ArrayList<>(); try (Session session = HibernateUtils.getSession()) { - for (var vTBC : VehicleToBlockConfig.getVehicleToBlockConfigsByVehicleId(session, vehicleId)) { - result.add(new IpcVehicleToBlockConfig(vTBC)); + for (var vehicleToBlockConfig : VehicleToBlockConfig.getVehicleToBlockConfigsByVehicleId(session, vehicleId)) { + result.add(new IpcVehicleToBlockConfig(vehicleToBlockConfig)); } } catch (Exception ex) { logger.error("Something happened while fetching the data.", ex); From 32f57f76a4a8e180c2fc324e851b2a9411593e60 Mon Sep 17 00:00:00 2001 From: Timur Shykhsefiyeu Date: Fri, 29 Mar 2024 10:39:29 +0100 Subject: [PATCH 14/17] add missing tags to /command/vehiclesToBlock --- .../java/org/transitclock/api/resources/TransitimeApi.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java b/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java index 344cb7236..5ec918ef2 100644 --- a/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java +++ b/app/src/main/java/org/transitclock/api/resources/TransitimeApi.java @@ -169,7 +169,8 @@ public Response getVehicles( @Operation( summary = "Returns data for vehicles assignment for specific block in current day", - description = "Returns data for vehicles assignment for specific block in current day") + description = "Returns data for vehicles assignment for specific block in current day", + tags = {"vehicle", "block"}) @Path("/command/vehiclesToBlock") @GET @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) From 4d2be8171f6285b7c64c13b2f99dd761af395da4 Mon Sep 17 00:00:00 2001 From: Timur Shykhsefiyeu Date: Fri, 29 Mar 2024 12:30:15 +0100 Subject: [PATCH 15/17] temp for tests --- app/pom.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/pom.xml b/app/pom.xml index 7a8b3181e..9ead19691 100755 --- a/app/pom.xml +++ b/app/pom.xml @@ -125,11 +125,11 @@ - ${env.CONTAINER_REPO} - - ${env.CONTAINER_REGISTRY_USER} - ${env.CONTAINER_REGISTRY_PASSWORD} - + timurshyk/test-tc + + + + From 8c1c8272188f0af4d619182912357e45208f3a3c Mon Sep 17 00:00:00 2001 From: Timur Shykhsefiyeu Date: Fri, 29 Mar 2024 13:19:36 +0100 Subject: [PATCH 16/17] refactoring: n.2 --- .../org/transitclock/api/data/ApiVehicleToBlockConfigs.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/transitclock/api/data/ApiVehicleToBlockConfigs.java b/app/src/main/java/org/transitclock/api/data/ApiVehicleToBlockConfigs.java index 57b1efecb..2ed3e7ab3 100644 --- a/app/src/main/java/org/transitclock/api/data/ApiVehicleToBlockConfigs.java +++ b/app/src/main/java/org/transitclock/api/data/ApiVehicleToBlockConfigs.java @@ -17,7 +17,7 @@ @XmlRootElement public class ApiVehicleToBlockConfigs { - @XmlElement(name = "vehiclesToBlock") + @XmlElement(name = "vehicleToBlock") private List vehiclesData; /********************** Member Functions **************************/ From 1e551a64dcd42674c5a8f9f73893bcbfd7894716 Mon Sep 17 00:00:00 2001 From: Timur Shykhsefiyeu <91431503+TsimurSh@users.noreply.github.com> Date: Fri, 29 Mar 2024 15:54:52 +0100 Subject: [PATCH 17/17] fix: variables app/pom.xml rollback variables --- app/pom.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/pom.xml b/app/pom.xml index 9ead19691..7a8b3181e 100755 --- a/app/pom.xml +++ b/app/pom.xml @@ -125,11 +125,11 @@ - timurshyk/test-tc - - - - + ${env.CONTAINER_REPO} + + ${env.CONTAINER_REGISTRY_USER} + ${env.CONTAINER_REGISTRY_PASSWORD} +