aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/api/resource
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-08-03 08:35:57 -0700
committerAnton Tananaev <anton@traccar.org>2022-08-03 08:35:57 -0700
commit38961efd25373f290bb20780f770d17b425de88c (patch)
tree7fbb0676edbe7fa3e740fa66b471c1795c9adb35 /src/main/java/org/traccar/api/resource
parentbb7bdcfc3389b6822b7680837386e3650962f30a (diff)
downloadtrackermap-server-38961efd25373f290bb20780f770d17b425de88c.tar.gz
trackermap-server-38961efd25373f290bb20780f770d17b425de88c.tar.bz2
trackermap-server-38961efd25373f290bb20780f770d17b425de88c.zip
Implement GPX export (fix #4646)
Diffstat (limited to 'src/main/java/org/traccar/api/resource')
-rw-r--r--src/main/java/org/traccar/api/resource/PositionResource.java22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/api/resource/PositionResource.java b/src/main/java/org/traccar/api/resource/PositionResource.java
index b4c8d18b9..7d7921085 100644
--- a/src/main/java/org/traccar/api/resource/PositionResource.java
+++ b/src/main/java/org/traccar/api/resource/PositionResource.java
@@ -21,6 +21,7 @@ import org.traccar.model.Device;
import org.traccar.model.Position;
import org.traccar.model.UserRestrictions;
import org.traccar.reports.CsvExportProvider;
+import org.traccar.reports.GpxExportProvider;
import org.traccar.reports.KmlExportProvider;
import org.traccar.storage.StorageException;
import org.traccar.storage.query.Columns;
@@ -54,6 +55,9 @@ public class PositionResource extends BaseResource {
@Inject
private CsvExportProvider csvExportProvider;
+ @Inject
+ private GpxExportProvider gpxExportProvider;
+
@GET
public Collection<Position> getJson(
@QueryParam("deviceId") long deviceId, @QueryParam("id") List<Long> positionIds,
@@ -118,4 +122,22 @@ public class PositionResource extends BaseResource {
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=positions.csv").build();
}
+ @Path("gpx")
+ @GET
+ @Produces("application/gpx+xml")
+ public Response getGpx(
+ @QueryParam("deviceId") long deviceId,
+ @QueryParam("from") Date from, @QueryParam("to") Date to) throws StorageException {
+ permissionsService.checkPermission(Device.class, getUserId(), deviceId);
+ StreamingOutput stream = output -> {
+ try {
+ gpxExportProvider.generate(output, deviceId, from, to);
+ } catch (StorageException e) {
+ throw new WebApplicationException(e);
+ }
+ };
+ return Response.ok(stream)
+ .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=positions.gpx").build();
+ }
+
}