aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/api/resource/DeviceResource.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/api/resource/DeviceResource.java')
-rw-r--r--src/org/traccar/api/resource/DeviceResource.java64
1 files changed, 35 insertions, 29 deletions
diff --git a/src/org/traccar/api/resource/DeviceResource.java b/src/org/traccar/api/resource/DeviceResource.java
index 50589171d..00b77e16c 100644
--- a/src/org/traccar/api/resource/DeviceResource.java
+++ b/src/org/traccar/api/resource/DeviceResource.java
@@ -15,9 +15,11 @@
*/
package org.traccar.api.resource;
+import org.traccar.Context;
import org.traccar.api.BaseResource;
+
+import java.sql.SQLException;
import java.util.Collection;
-import javax.annotation.security.RolesAllowed;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
@@ -26,52 +28,56 @@ import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.traccar.model.Device;
-import org.traccar.model.User;
@Path("devices")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
-public class DeviceResource extends BaseResource<Device> {
+public class DeviceResource extends BaseResource {
@GET
- @RolesAllowed(User.ROLE_ADMIN)
- @Override
- public Collection<Device> getEntities() {
- return super.getEntities();
- }
-
- @GET
- @Path("{id}")
- @RolesAllowed(User.ROLE_USER)
- @Override
- public Device getEntity(@PathParam("id") long id) {
- return super.getEntity(id);
+ public Collection<Device> get() {
+ try {
+ return Context.getDataManager().getAllDevices();
+ } catch (SQLException e) {
+ throw new WebApplicationException(e);
+ }
}
@POST
- @RolesAllowed(User.ROLE_USER)
- @Override
- public Response postEntity(Device entity) {
- return super.postEntity(entity);
+ public Response add(Device entity) {
+ try {
+ Context.getDataManager().addDevice(entity);
+ return Response.ok(entity).build();
+ } catch (SQLException e) {
+ throw new WebApplicationException(e);
+ }
}
- @PUT
@Path("{id}")
- @RolesAllowed(User.ROLE_USER)
- @Override
- public Response putEntity(@PathParam("id") long id, Device entity) {
- return super.putEntity(id, entity);
+ @PUT
+ public Response update(@PathParam("id") long id, Device entity) {
+ try {
+ entity.setId(id);
+ Context.getDataManager().updateDevice(entity);
+ return Response.ok(entity).build();
+ } catch (SQLException e) {
+ throw new WebApplicationException(e);
+ }
}
- @DELETE
@Path("{id}")
- @RolesAllowed(User.ROLE_USER)
- @Override
- public Response deleteEntity(@PathParam("id") long id) {
- return super.deleteEntity(id);
+ @DELETE
+ public Response remove(@PathParam("id") long id) {
+ try {
+ Context.getDataManager().removeDevice(id);
+ return Response.noContent().build();
+ } catch (SQLException e) {
+ throw new WebApplicationException(e);
+ }
}
}