aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/web/CommandServlet.java
diff options
context:
space:
mode:
authorRafael Guterres <guterresrafael@gmail.com>2015-11-21 01:57:46 -0200
committerRafael Guterres <guterresrafael@gmail.com>2015-11-21 01:57:46 -0200
commitf5a266953e53a7f1785bcb584759582621ec9de3 (patch)
tree06aed01befc06db1384d731d5d17ee897335c302 /src/org/traccar/web/CommandServlet.java
parentcfe237cf26c6309b8431b3b81d589628ae363804 (diff)
downloadtrackermap-server-f5a266953e53a7f1785bcb584759582621ec9de3.tar.gz
trackermap-server-f5a266953e53a7f1785bcb584759582621ec9de3.tar.bz2
trackermap-server-f5a266953e53a7f1785bcb584759582621ec9de3.zip
Add support to generic resources and refactor in classes to support types and commandpattern.
Diffstat (limited to 'src/org/traccar/web/CommandServlet.java')
-rw-r--r--src/org/traccar/web/CommandServlet.java9
1 files changed, 4 insertions, 5 deletions
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);
}