aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/api/resource/DeviceResource.java
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-07-27 13:16:59 +0500
committerAbyss777 <abyss@fox5.ru>2017-07-27 13:54:42 +0500
commite8a758072e9368f6977880e1aa607351d7cf619a (patch)
treeabf47e3c05d0fcd6c693a02def80ebaa91217b4f /src/org/traccar/api/resource/DeviceResource.java
parent495b2aa2d2b17bd1a5803ea0bd7dcc64bc81c598 (diff)
downloadtrackermap-server-e8a758072e9368f6977880e1aa607351d7cf619a.tar.gz
trackermap-server-e8a758072e9368f6977880e1aa607351d7cf619a.tar.bz2
trackermap-server-e8a758072e9368f6977880e1aa607351d7cf619a.zip
Implement BaseObjectResource generic and combine PUT/POST/DELETE functions
Diffstat (limited to 'src/org/traccar/api/resource/DeviceResource.java')
-rw-r--r--src/org/traccar/api/resource/DeviceResource.java49
1 files changed, 6 insertions, 43 deletions
diff --git a/src/org/traccar/api/resource/DeviceResource.java b/src/org/traccar/api/resource/DeviceResource.java
index a473b7bde..1c2c653a4 100644
--- a/src/org/traccar/api/resource/DeviceResource.java
+++ b/src/org/traccar/api/resource/DeviceResource.java
@@ -16,19 +16,15 @@
package org.traccar.api.resource;
import org.traccar.Context;
-import org.traccar.api.BaseResource;
+import org.traccar.api.BaseObjectResource;
import org.traccar.database.DeviceManager;
import org.traccar.model.Device;
import org.traccar.model.DeviceTotalDistance;
-import org.traccar.model.User;
import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
-import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
@@ -43,7 +39,11 @@ import java.util.Set;
@Path("devices")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
-public class DeviceResource extends BaseResource {
+public class DeviceResource extends BaseObjectResource<Device> {
+
+ public DeviceResource() {
+ super(Device.class);
+ }
@GET
public Collection<Device> get(
@@ -80,43 +80,6 @@ public class DeviceResource extends BaseResource {
return deviceManager.getItems(result);
}
- @POST
- public Response add(Device entity) throws SQLException {
- Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkDeviceReadonly(getUserId());
- Context.getPermissionsManager().checkDeviceLimit(getUserId());
- Context.getDeviceManager().addItem(entity);
- Context.getDataManager().linkObject(User.class, getUserId(), entity.getClass(), entity.getId(), true);
- Context.getPermissionsManager().refreshDeviceAndGroupPermissions();
- Context.getPermissionsManager().refreshAllExtendedPermissions();
- return Response.ok(entity).build();
- }
-
- @Path("{id}")
- @PUT
- public Response update(Device entity) throws SQLException {
- Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkDeviceReadonly(getUserId());
- Context.getPermissionsManager().checkDevice(getUserId(), entity.getId());
- Context.getDeviceManager().updateItem(entity);
- Context.getPermissionsManager().refreshDeviceAndGroupPermissions();
- Context.getPermissionsManager().refreshAllExtendedPermissions();
- return Response.ok(entity).build();
- }
-
- @Path("{id}")
- @DELETE
- public Response remove(@PathParam("id") long id) throws SQLException {
- Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkDeviceReadonly(getUserId());
- Context.getPermissionsManager().checkDevice(getUserId(), id);
- Context.getDeviceManager().removeItem(id);
- Context.getPermissionsManager().refreshDeviceAndGroupPermissions();
- Context.getPermissionsManager().refreshAllExtendedPermissions();
- Context.getAliasesManager().removeDevice(id);
- return Response.noContent().build();
- }
-
@Path("{id}/distance")
@PUT
public Response updateTotalDistance(DeviceTotalDistance entity) throws SQLException {