aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/api
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-25 13:33:35 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-25 13:33:35 -0700
commitc53d98c668af9c79767e22964f05c7bf7dc866f2 (patch)
tree42d664009487232e3a21514bb5ab52c7571262a6 /src/main/java/org/traccar/api
parent5a732a26c85785a9b801583f2fff0ce47314aa03 (diff)
downloadtrackermap-server-c53d98c668af9c79767e22964f05c7bf7dc866f2.tar.gz
trackermap-server-c53d98c668af9c79767e22964f05c7bf7dc866f2.tar.bz2
trackermap-server-c53d98c668af9c79767e22964f05c7bf7dc866f2.zip
Integrate broadcast service
Diffstat (limited to 'src/main/java/org/traccar/api')
-rw-r--r--src/main/java/org/traccar/api/BaseObjectResource.java8
-rw-r--r--src/main/java/org/traccar/api/resource/DeviceResource.java8
-rw-r--r--src/main/java/org/traccar/api/resource/PermissionsResource.java22
3 files changed, 32 insertions, 6 deletions
diff --git a/src/main/java/org/traccar/api/BaseObjectResource.java b/src/main/java/org/traccar/api/BaseObjectResource.java
index 35ff04bf3..403021c6c 100644
--- a/src/main/java/org/traccar/api/BaseObjectResource.java
+++ b/src/main/java/org/traccar/api/BaseObjectResource.java
@@ -16,6 +16,7 @@
*/
package org.traccar.api;
+import org.traccar.broadcast.BroadcastService;
import org.traccar.helper.LogAction;
import org.traccar.model.BaseModel;
import org.traccar.model.Group;
@@ -41,6 +42,9 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour
@Inject
private CacheManager cacheManager;
+ @Inject
+ private BroadcastService broadcastService;
+
protected final Class<T> baseClass;
public BaseObjectResource(Class<T> baseClass) {
@@ -67,7 +71,8 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour
entity.setId(storage.addObject(entity, new Request(new Columns.Exclude("id"))));
LogAction.create(getUserId(), entity);
storage.addPermission(new Permission(User.class, getUserId(), baseClass, entity.getId()));
- cacheManager.invalidate(User.class, getUserId(), baseClass, entity.getId());
+ cacheManager.invalidatePermission(User.class, getUserId(), baseClass, entity.getId());
+ broadcastService.invalidatePermission(User.class, getUserId(), baseClass, entity.getId());
LogAction.link(getUserId(), User.class, getUserId(), baseClass, entity.getId());
return Response.ok(entity).build();
@@ -94,6 +99,7 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour
new Columns.Exclude("id"),
new Condition.Equals("id", "id")));
cacheManager.updateOrInvalidate(entity);
+ broadcastService.invalidateObject(entity.getClass(), entity.getId());
LogAction.edit(getUserId(), entity);
return Response.ok(entity).build();
diff --git a/src/main/java/org/traccar/api/resource/DeviceResource.java b/src/main/java/org/traccar/api/resource/DeviceResource.java
index ff682d1d1..2b673a108 100644
--- a/src/main/java/org/traccar/api/resource/DeviceResource.java
+++ b/src/main/java/org/traccar/api/resource/DeviceResource.java
@@ -16,6 +16,7 @@
package org.traccar.api.resource;
import org.traccar.api.BaseObjectResource;
+import org.traccar.broadcast.BroadcastService;
import org.traccar.helper.LogAction;
import org.traccar.model.Device;
import org.traccar.model.DeviceAccumulators;
@@ -37,6 +38,7 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import java.io.IOException;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
@@ -52,6 +54,9 @@ public class DeviceResource extends BaseObjectResource<Device> {
@Inject
private ConnectionManager connectionManager;
+ @Inject
+ private BroadcastService broadcastService;
+
public DeviceResource() {
super(Device.class);
}
@@ -105,7 +110,7 @@ public class DeviceResource extends BaseObjectResource<Device> {
@Path("{id}/accumulators")
@PUT
- public Response updateAccumulators(DeviceAccumulators entity) throws StorageException {
+ public Response updateAccumulators(DeviceAccumulators entity) throws StorageException, IOException {
if (permissionsService.notAdmin(getUserId())) {
permissionsService.checkManager(getUserId());
permissionsService.checkPermission(Device.class, getUserId(), entity.getDeviceId());
@@ -133,6 +138,7 @@ public class DeviceResource extends BaseObjectResource<Device> {
cacheManager.addDevice(position.getDeviceId());
cacheManager.updatePosition(position);
connectionManager.updatePosition(position);
+ broadcastService.updatePosition(position);
} finally {
cacheManager.removeDevice(position.getDeviceId());
}
diff --git a/src/main/java/org/traccar/api/resource/PermissionsResource.java b/src/main/java/org/traccar/api/resource/PermissionsResource.java
index 7174a3eff..5ca865c31 100644
--- a/src/main/java/org/traccar/api/resource/PermissionsResource.java
+++ b/src/main/java/org/traccar/api/resource/PermissionsResource.java
@@ -17,6 +17,7 @@
package org.traccar.api.resource;
import org.traccar.api.BaseResource;
+import org.traccar.broadcast.BroadcastService;
import org.traccar.helper.LogAction;
import org.traccar.model.Permission;
import org.traccar.model.UserRestrictions;
@@ -45,6 +46,9 @@ public class PermissionsResource extends BaseResource {
@Inject
private CacheManager cacheManager;
+ @Inject
+ private BroadcastService broadcastService;
+
private void checkPermission(Permission permission) throws StorageException {
if (permissionsService.notAdmin(getUserId())) {
permissionsService.checkPermission(permission.getOwnerClass(), getUserId(), permission.getOwnerId());
@@ -71,9 +75,14 @@ public class PermissionsResource extends BaseResource {
Permission permission = new Permission(entity);
checkPermission(permission);
storage.addPermission(permission);
- cacheManager.invalidate(permission.getOwnerClass(), permission.getOwnerId(),
+ cacheManager.invalidatePermission(
+ permission.getOwnerClass(), permission.getOwnerId(),
permission.getPropertyClass(), permission.getPropertyId());
- LogAction.link(getUserId(), permission.getOwnerClass(), permission.getOwnerId(),
+ broadcastService.invalidatePermission(
+ permission.getOwnerClass(), permission.getOwnerId(),
+ permission.getPropertyClass(), permission.getPropertyId());
+ LogAction.link(getUserId(),
+ permission.getOwnerClass(), permission.getOwnerId(),
permission.getPropertyClass(), permission.getPropertyId());
}
return Response.noContent().build();
@@ -93,9 +102,14 @@ public class PermissionsResource extends BaseResource {
Permission permission = new Permission(entity);
checkPermission(permission);
storage.removePermission(permission);
- cacheManager.invalidate(permission.getOwnerClass(), permission.getOwnerId(),
+ cacheManager.invalidatePermission(
+ permission.getOwnerClass(), permission.getOwnerId(),
+ permission.getPropertyClass(), permission.getPropertyId());
+ broadcastService.invalidatePermission(
+ permission.getOwnerClass(), permission.getOwnerId(),
permission.getPropertyClass(), permission.getPropertyId());
- LogAction.unlink(getUserId(), permission.getOwnerClass(), permission.getOwnerId(),
+ LogAction.unlink(getUserId(),
+ permission.getOwnerClass(), permission.getOwnerId(),
permission.getPropertyClass(), permission.getPropertyId());
}
return Response.noContent().build();