From e8a758072e9368f6977880e1aa607351d7cf619a Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 27 Jul 2017 13:16:59 +0500 Subject: Implement BaseObjectResource generic and combine PUT/POST/DELETE functions --- src/org/traccar/api/resource/GeofenceResource.java | 43 +++------------------- 1 file changed, 6 insertions(+), 37 deletions(-) (limited to 'src/org/traccar/api/resource/GeofenceResource.java') diff --git a/src/org/traccar/api/resource/GeofenceResource.java b/src/org/traccar/api/resource/GeofenceResource.java index 9a110fbcf..d07810732 100644 --- a/src/org/traccar/api/resource/GeofenceResource.java +++ b/src/org/traccar/api/resource/GeofenceResource.java @@ -16,22 +16,16 @@ package org.traccar.api.resource; import org.traccar.Context; -import org.traccar.api.BaseResource; +import org.traccar.api.BaseObjectResource; import org.traccar.database.GeofenceManager; import org.traccar.model.Geofence; -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; -import javax.ws.rs.core.Response; import java.sql.SQLException; import java.util.Collection; @@ -41,7 +35,11 @@ import java.util.Set; @Path("geofences") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) -public class GeofenceResource extends BaseResource { +public class GeofenceResource extends BaseObjectResource { + + public GeofenceResource() { + super(Geofence.class); + } @GET public Collection get( @@ -79,34 +77,5 @@ public class GeofenceResource extends BaseResource { result.retainAll(geofenceManager.getDeviceItems(deviceId)); } return geofenceManager.getItems(result); - - } - - @POST - public Response add(Geofence entity) throws SQLException { - Context.getPermissionsManager().checkReadonly(getUserId()); - Context.getGeofenceManager().addItem(entity); - Context.getDataManager().linkObject(User.class, getUserId(), entity.getClass(), entity.getId(), true); - Context.getGeofenceManager().refreshUserItems(); - return Response.ok(entity).build(); } - - @Path("{id}") - @PUT - public Response update(Geofence entity) throws SQLException { - Context.getPermissionsManager().checkReadonly(getUserId()); - Context.getPermissionsManager().checkPermission(Geofence.class, getUserId(), entity.getId()); - Context.getGeofenceManager().updateItem(entity); - return Response.ok(entity).build(); - } - - @Path("{id}") - @DELETE - public Response remove(@PathParam("id") long id) throws SQLException { - Context.getPermissionsManager().checkReadonly(getUserId()); - Context.getPermissionsManager().checkPermission(Geofence.class, getUserId(), id); - Context.getGeofenceManager().removeItem(id); - return Response.noContent().build(); - } - } -- cgit v1.2.3