aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/web/ServerServlet.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/ServerServlet.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/ServerServlet.java')
-rw-r--r--src/org/traccar/web/ServerServlet.java27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/org/traccar/web/ServerServlet.java b/src/org/traccar/web/ServerServlet.java
index 7ed096bc6..312876f36 100644
--- a/src/org/traccar/web/ServerServlet.java
+++ b/src/org/traccar/web/ServerServlet.java
@@ -18,16 +18,17 @@ 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.Server;
-public class ServerServlet extends BaseServlet {
+public class ServerServlet extends BaseServletResource<Server> {
@Override
protected boolean handle(String command, HttpServletRequest req, HttpServletResponse resp) throws Exception {
switch (command) {
case "/get":
- get(resp);
+ get(req, resp);
break;
case "/update":
update(req, resp);
@@ -38,16 +39,22 @@ public class ServerServlet extends BaseServlet {
return true;
}
- private void get(HttpServletResponse resp) throws Exception {
- sendResponse(resp.getWriter(), JsonConverter.objectToJson(
- Context.getDataManager().getServer()));
+ @Override
+ protected void update(HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ super.update(req, resp, new CommandCall() {
+
+ @Override
+ public void check() {
+ Context.getPermissionsManager().checkAdmin(getUserId());
+ }
+
+ });
}
- private void update(HttpServletRequest req, HttpServletResponse resp) throws Exception {
- Server server = JsonConverter.objectFromJson(req.getReader(), new Server());
- Context.getPermissionsManager().checkAdmin(getUserId(req));
- Context.getDataManager().updateServer(server);
- sendResponse(resp.getWriter(), true);
+ @Override
+ protected void get(HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ sendResponse(resp.getWriter(), JsonConverter.objectToJson(
+ Context.getDataManager().getServer()));
}
}