diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-07-30 10:08:04 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-07-30 10:08:04 +1200 |
commit | d97c74a7cf0efe5f4209e31a998b97fc1be8023b (patch) | |
tree | 9b9ba9473a8f1e7f2a8928bce6329d47cc9b6e04 /src/org/traccar/web/PositionServlet.java | |
parent | 173699d5683605e72267b24a248085c2abccc38f (diff) | |
parent | 66dbefa18290d2f31d545fd1f511207cdcd7c3a2 (diff) | |
download | trackermap-server-d97c74a7cf0efe5f4209e31a998b97fc1be8023b.tar.gz trackermap-server-d97c74a7cf0efe5f4209e31a998b97fc1be8023b.tar.bz2 trackermap-server-d97c74a7cf0efe5f4209e31a998b97fc1be8023b.zip |
Merge pull request #1322 from demianalonso/devices-position
Service call to retrieve a group of devices
Diffstat (limited to 'src/org/traccar/web/PositionServlet.java')
-rw-r--r-- | src/org/traccar/web/PositionServlet.java | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/org/traccar/web/PositionServlet.java b/src/org/traccar/web/PositionServlet.java index a29b5b274..78bcb22e7 100644 --- a/src/org/traccar/web/PositionServlet.java +++ b/src/org/traccar/web/PositionServlet.java @@ -18,6 +18,11 @@ package org.traccar.web; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.traccar.Context; +import org.traccar.model.MiscFormatter; +import org.traccar.model.Position; + +import java.util.HashMap; +import java.util.Map; public class PositionServlet extends BaseServlet { @@ -28,6 +33,9 @@ public class PositionServlet extends BaseServlet { case "/get": get(req, resp); break; + case "/devices": + devices(req, resp); + break; default: return false; } @@ -44,4 +52,19 @@ public class PositionServlet extends BaseServlet { JsonConverter.parseDate(req.getParameter("to"))))); } + private void devices(HttpServletRequest req, HttpServletResponse resp) throws Exception { + long userId = getUserId(req); + Map<String, Object> positions = new HashMap<>(); + + for(String deviceIdString : req.getParameterValues("devicesId")) { + Long deviceId = Long.parseLong(deviceIdString); + + Context.getPermissionsManager().checkDevice(userId, deviceId); + + Position position = Context.getConnectionManager().getLastPosition(deviceId); + positions.put(deviceId.toString(), position); + } + + sendResponse(resp.getWriter(), MiscFormatter.toJson(positions)); + } } |