aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/api/resource
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/resource
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/resource')
-rw-r--r--src/main/java/org/traccar/api/resource/DeviceResource.java8
-rw-r--r--src/main/java/org/traccar/api/resource/PermissionsResource.java22
2 files changed, 25 insertions, 5 deletions
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();