aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/web/DeviceServlet.java
diff options
context:
space:
mode:
authorRafael Guterres <guterresrafael@gmail.com>2015-11-27 03:32:59 -0200
committerRafael Guterres <guterresrafael@gmail.com>2015-11-27 03:32:59 -0200
commitc57bd2d472467b1b3a45aee1b97c9a0aeef5958a (patch)
tree26fae20adf1970b5834f06393a3c703c972f39b1 /src/org/traccar/web/DeviceServlet.java
parent77cd23da84ebebcf99a97a8aef88aa9a4884ca40 (diff)
downloadtrackermap-server-c57bd2d472467b1b3a45aee1b97c9a0aeef5958a.tar.gz
trackermap-server-c57bd2d472467b1b3a45aee1b97c9a0aeef5958a.tar.bz2
trackermap-server-c57bd2d472467b1b3a45aee1b97c9a0aeef5958a.zip
Initial implementation of new api with jax-rs.
Revert servlets to old api and remove plurals. Fix findbugs for header origin.
Diffstat (limited to 'src/org/traccar/web/DeviceServlet.java')
-rw-r--r--src/org/traccar/web/DeviceServlet.java67
1 files changed, 23 insertions, 44 deletions
diff --git a/src/org/traccar/web/DeviceServlet.java b/src/org/traccar/web/DeviceServlet.java
index 7900538bb..8f983ad78 100644
--- a/src/org/traccar/web/DeviceServlet.java
+++ b/src/org/traccar/web/DeviceServlet.java
@@ -18,11 +18,9 @@ package org.traccar.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.traccar.Context;
-import org.traccar.helper.CommandCall;
import org.traccar.model.Device;
-import org.traccar.model.User;
-public class DeviceServlet extends BaseServletResource<Device> {
+public class DeviceServlet extends BaseServlet {
@Override
protected boolean handle(String command, HttpServletRequest req, HttpServletResponse resp) throws Exception {
@@ -52,8 +50,7 @@ public class DeviceServlet extends BaseServletResource<Device> {
return true;
}
- @Override
- protected void get(HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ private void get(HttpServletRequest req, HttpServletResponse resp) throws Exception {
if (Boolean.parseBoolean(req.getParameter("all"))) {
Context.getPermissionsManager().checkAdmin(getUserId(req));
sendResponse(resp.getWriter(), JsonConverter.arrayToJson(
@@ -66,57 +63,39 @@ public class DeviceServlet extends BaseServletResource<Device> {
} else {
userId = getUserId(req);
}
- Context.getPermissionsManager().check(User.class, getUserId(req), userId);
+ Context.getPermissionsManager().checkUser(getUserId(req), userId);
sendResponse(resp.getWriter(), JsonConverter.arrayToJson(
Context.getDataManager().getDevices(userId)));
}
}
- @Override
- protected void add(HttpServletRequest req, HttpServletResponse resp) throws Exception {
- super.add(req, resp, new CommandCall<Device>() {
-
- @Override
- public void after() throws Exception {
- Context.getDataManager().link(Device.class, getUserId(), getEntity().getId());
- Context.getPermissionsManager().refresh();
- }
-
- });
+ private void add(HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ Device device = JsonConverter.objectFromJson(req.getReader(), new Device());
+ long userId = getUserId(req);
+ Context.getDataManager().addDevice(device);
+ Context.getDataManager().linkDevice(userId, device.getId());
+ Context.getPermissionsManager().refresh();
+ sendResponse(resp.getWriter(), JsonConverter.objectToJson(device));
}
- @Override
- protected void update(HttpServletRequest req, HttpServletResponse resp) throws Exception {
- super.update(req, resp, new CommandCall<Device>() {
-
- @Override
- public void check() throws Exception {
- Context.getPermissionsManager().check(Device.class, getUserId(), getEntity().getId());
- }
-
- });
+ private void update(HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ Device device = JsonConverter.objectFromJson(req.getReader(), new Device());
+ Context.getPermissionsManager().checkDevice(getUserId(req), device.getId());
+ Context.getDataManager().updateDevice(device);
+ sendResponse(resp.getWriter(), true);
}
- @Override
- protected void remove(HttpServletRequest req, HttpServletResponse resp) throws Exception {
- super.remove(req, resp, new CommandCall<Device>() {
-
- @Override
- public void check() throws Exception {
- Context.getPermissionsManager().check(Device.class, getUserId(), getEntity().getId());
- }
-
- @Override
- public void after() throws Exception {
- Context.getPermissionsManager().refresh();
- }
-
- });
+ private void remove(HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ Device device = JsonConverter.objectFromJson(req.getReader(), new Device());
+ Context.getPermissionsManager().checkDevice(getUserId(req), device.getId());
+ Context.getDataManager().removeDevice(device);
+ Context.getPermissionsManager().refresh();
+ sendResponse(resp.getWriter(), true);
}
private void link(HttpServletRequest req, HttpServletResponse resp) throws Exception {
Context.getPermissionsManager().checkAdmin(getUserId(req));
- Context.getDataManager().link(Device.class,
+ Context.getDataManager().linkDevice(
Long.parseLong(req.getParameter("userId")),
Long.parseLong(req.getParameter("deviceId")));
Context.getPermissionsManager().refresh();
@@ -125,7 +104,7 @@ public class DeviceServlet extends BaseServletResource<Device> {
private void unlink(HttpServletRequest req, HttpServletResponse resp) throws Exception {
Context.getPermissionsManager().checkAdmin(getUserId(req));
- Context.getDataManager().unlink(Device.class,
+ Context.getDataManager().unlinkDevice(
Long.parseLong(req.getParameter("userId")),
Long.parseLong(req.getParameter("deviceId")));
Context.getPermissionsManager().refresh();