aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/api
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-18 11:08:32 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-18 11:08:32 -0700
commitddbe4d7de6ae7590e2b927066312597efa129393 (patch)
tree777882e24ce5488b4cfc8a4d6f11119abcbeb7a3 /src/main/java/org/traccar/api
parent182656b6dc1fb5d167bb752c16ecf633add001a8 (diff)
downloadtrackermap-server-ddbe4d7de6ae7590e2b927066312597efa129393.tar.gz
trackermap-server-ddbe4d7de6ae7590e2b927066312597efa129393.tar.bz2
trackermap-server-ddbe4d7de6ae7590e2b927066312597efa129393.zip
Remove positions from manager
Diffstat (limited to 'src/main/java/org/traccar/api')
-rw-r--r--src/main/java/org/traccar/api/AsyncSocket.java14
-rw-r--r--src/main/java/org/traccar/api/AsyncSocketServlet.java7
-rw-r--r--src/main/java/org/traccar/api/resource/PositionResource.java14
3 files changed, 17 insertions, 18 deletions
diff --git a/src/main/java/org/traccar/api/AsyncSocket.java b/src/main/java/org/traccar/api/AsyncSocket.java
index 3239d36c4..40aa68e88 100644
--- a/src/main/java/org/traccar/api/AsyncSocket.java
+++ b/src/main/java/org/traccar/api/AsyncSocket.java
@@ -21,11 +21,13 @@ import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.traccar.Context;
+import org.traccar.helper.model.PositionUtil;
import org.traccar.session.ConnectionManager;
import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Position;
+import org.traccar.storage.Storage;
+import org.traccar.storage.StorageException;
import java.util.Collection;
import java.util.Collections;
@@ -42,11 +44,13 @@ public class AsyncSocket extends WebSocketAdapter implements ConnectionManager.U
private final ObjectMapper objectMapper;
private final ConnectionManager connectionManager;
+ private final Storage storage;
private final long userId;
- public AsyncSocket(ObjectMapper objectMapper, ConnectionManager connectionManager, long userId) {
+ public AsyncSocket(ObjectMapper objectMapper, ConnectionManager connectionManager, Storage storage, long userId) {
this.objectMapper = objectMapper;
this.connectionManager = connectionManager;
+ this.storage = storage;
this.userId = userId;
}
@@ -55,7 +59,11 @@ public class AsyncSocket extends WebSocketAdapter implements ConnectionManager.U
super.onWebSocketConnect(session);
Map<String, Collection<?>> data = new HashMap<>();
- data.put(KEY_POSITIONS, Context.getDeviceManager().getInitialState(userId));
+ try {
+ data.put(KEY_POSITIONS, PositionUtil.getLatestPositions(storage, userId));
+ } catch (StorageException e) {
+ throw new RuntimeException(e);
+ }
sendData(data);
connectionManager.addListener(userId, this);
diff --git a/src/main/java/org/traccar/api/AsyncSocketServlet.java b/src/main/java/org/traccar/api/AsyncSocketServlet.java
index 7c532179b..7d9fdf0ed 100644
--- a/src/main/java/org/traccar/api/AsyncSocketServlet.java
+++ b/src/main/java/org/traccar/api/AsyncSocketServlet.java
@@ -22,6 +22,7 @@ import org.traccar.Context;
import org.traccar.api.resource.SessionResource;
import org.traccar.config.Keys;
import org.traccar.session.ConnectionManager;
+import org.traccar.storage.Storage;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -33,11 +34,13 @@ public class AsyncSocketServlet extends JettyWebSocketServlet {
private final ObjectMapper objectMapper;
private final ConnectionManager connectionManager;
+ private final Storage storage;
@Inject
- public AsyncSocketServlet(ObjectMapper objectMapper, ConnectionManager connectionManager) {
+ public AsyncSocketServlet(ObjectMapper objectMapper, ConnectionManager connectionManager, Storage storage) {
this.objectMapper = objectMapper;
this.connectionManager = connectionManager;
+ this.storage = storage;
}
@Override
@@ -46,7 +49,7 @@ public class AsyncSocketServlet extends JettyWebSocketServlet {
factory.setCreator((req, resp) -> {
if (req.getSession() != null) {
long userId = (Long) ((HttpSession) req.getSession()).getAttribute(SessionResource.USER_ID_KEY);
- return new AsyncSocket(objectMapper, connectionManager, userId);
+ return new AsyncSocket(objectMapper, connectionManager, storage, userId);
} else {
return null;
}
diff --git a/src/main/java/org/traccar/api/resource/PositionResource.java b/src/main/java/org/traccar/api/resource/PositionResource.java
index 099d97632..cac64feb1 100644
--- a/src/main/java/org/traccar/api/resource/PositionResource.java
+++ b/src/main/java/org/traccar/api/resource/PositionResource.java
@@ -17,10 +17,8 @@ package org.traccar.api.resource;
import org.traccar.api.BaseResource;
import org.traccar.helper.model.PositionUtil;
-import org.traccar.model.BaseModel;
import org.traccar.model.Device;
import org.traccar.model.Position;
-import org.traccar.model.User;
import org.traccar.model.UserRestrictions;
import org.traccar.storage.StorageException;
import org.traccar.storage.query.Columns;
@@ -37,7 +35,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
-import java.util.stream.Collectors;
@Path("positions")
@Produces(MediaType.APPLICATION_JSON)
@@ -68,16 +65,7 @@ public class PositionResource extends BaseResource {
new Columns.All(), new Condition.LatestPositions(deviceId)));
}
} else {
- var devices = storage.getObjects(Device.class, new Request(
- new Columns.Include("id"),
- new Condition.Permission(User.class, getUserId(), Device.class)));
- var deviceIds = devices.stream().map(BaseModel::getId).collect(Collectors.toUnmodifiableSet());
-
- var positions = storage.getObjects(Position.class, new Request(
- new Columns.All(), new Condition.LatestPositions()));
- return positions.stream()
- .filter(position -> deviceIds.contains(position.getDeviceId()))
- .collect(Collectors.toList());
+ return PositionUtil.getLatestPositions(storage, getUserId());
}
}