From f5a266953e53a7f1785bcb584759582621ec9de3 Mon Sep 17 00:00:00 2001 From: Rafael Guterres Date: Sat, 21 Nov 2015 01:57:46 -0200 Subject: Add support to generic resources and refactor in classes to support types and commandpattern. --- src/org/traccar/web/CommandServlet.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/org/traccar/web/CommandServlet.java') diff --git a/src/org/traccar/web/CommandServlet.java b/src/org/traccar/web/CommandServlet.java index 958f1a888..be2d50ccc 100644 --- a/src/org/traccar/web/CommandServlet.java +++ b/src/org/traccar/web/CommandServlet.java @@ -7,6 +7,7 @@ import javax.servlet.http.HttpServletResponse; import org.traccar.Context; import org.traccar.database.ActiveDevice; import org.traccar.model.Command; +import org.traccar.model.Device; public class CommandServlet extends BaseServlet { @@ -34,19 +35,17 @@ public class CommandServlet extends BaseServlet { } private void send(HttpServletRequest req, HttpServletResponse resp) throws Exception { - - Command command = JsonConverter.objectFromJson(req.getReader(), new Command()); - Context.getPermissionsManager().checkDevice(getUserId(req), command.getDeviceId()); + Command command = JsonConverter.objectFromJson(req.getReader(), Command.class); + Context.getPermissionsManager().check(Device.class, getUserId(req), command.getDeviceId()); getActiveDevice(command.getDeviceId()).sendCommand(command); sendResponse(resp.getWriter(), true); } private void raw(HttpServletRequest req, HttpServletResponse resp) throws Exception { - JsonObject json = Json.createReader(req.getReader()).readObject(); long deviceId = json.getJsonNumber("deviceId").longValue(); String command = json.getString("command"); - Context.getPermissionsManager().checkDevice(getUserId(req), deviceId); + Context.getPermissionsManager().check(Device.class, getUserId(req), deviceId); getActiveDevice(deviceId).write(command); sendResponse(resp.getWriter(), true); } -- cgit v1.2.3