From 89f5ca6340b71f01e57684ed4900c801e043a9c4 Mon Sep 17 00:00:00 2001 From: Christoph Krey Date: Fri, 30 Jun 2017 12:24:55 +0200 Subject: [NEW] add GET device to API for external monitoring --- src/org/traccar/api/resource/DeviceResource.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/org') diff --git a/src/org/traccar/api/resource/DeviceResource.java b/src/org/traccar/api/resource/DeviceResource.java index bfd05aad5..64d40f4af 100644 --- a/src/org/traccar/api/resource/DeviceResource.java +++ b/src/org/traccar/api/resource/DeviceResource.java @@ -31,6 +31,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import javax.ws.rs.WebApplicationException; import java.sql.SQLException; import java.util.Collection; @@ -73,6 +74,18 @@ public class DeviceResource extends BaseResource { return Response.ok(entity).build(); } + @Path("{id}") + @GET + public Response get(@PathParam("id") long id) throws SQLException { + Context.getPermissionsManager().checkDevice(getUserId(), id); + Device device = Context.getDeviceManager().getDeviceById(id); + if (device != null) { + return Response.ok(Context.getDeviceManager().getDeviceById(id)).build(); + } else { + throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build()); + } + } + @Path("{id}") @PUT public Response update(Device entity) throws SQLException { -- cgit v1.2.3