aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2016-06-18 07:59:43 +0500
committerAbyss777 <abyss@fox5.ru>2016-06-18 07:59:43 +0500
commit4109447d0adc778b246543b77672c280d58da8bf (patch)
tree08ee98636cec128587bbf5f25654c5e3534dfcd9 /src
parentb3b0cd9d6f2d26cef2e64ef38e23203f1f3fa51a (diff)
downloadtrackermap-server-4109447d0adc778b246543b77672c280d58da8bf.tar.gz
trackermap-server-4109447d0adc778b246543b77672c280d58da8bf.tar.bz2
trackermap-server-4109447d0adc778b246543b77672c280d58da8bf.zip
- Update Geofences API and Manager a bit
- Show geofence name in event toasts - Link/Unlink geofences to users, devices and groups
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/api/resource/GeofenceResource.java25
-rw-r--r--src/org/traccar/database/GeofenceManager.java25
2 files changed, 43 insertions, 7 deletions
diff --git a/src/org/traccar/api/resource/GeofenceResource.java b/src/org/traccar/api/resource/GeofenceResource.java
index 9c80e61a1..e94e3fedb 100644
--- a/src/org/traccar/api/resource/GeofenceResource.java
+++ b/src/org/traccar/api/resource/GeofenceResource.java
@@ -17,6 +17,7 @@ package org.traccar.api.resource;
import org.traccar.Context;
import org.traccar.api.BaseResource;
+import org.traccar.database.GeofenceManager;
import org.traccar.model.Geofence;
import javax.ws.rs.Consumes;
@@ -33,6 +34,8 @@ import javax.ws.rs.core.Response;
import java.sql.SQLException;
import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
@Path("geofences")
@Produces(MediaType.APPLICATION_JSON)
@@ -41,17 +44,33 @@ public class GeofenceResource extends BaseResource {
@GET
public Collection<Geofence> get(
- @QueryParam("all") boolean all, @QueryParam("userId") long userId) throws SQLException {
+ @QueryParam("all") boolean all, @QueryParam("userId") long userId, @QueryParam("groupId") long groupId,
+ @QueryParam("deviceId") long deviceId) throws SQLException {
+
+ GeofenceManager geofenceManager = Context.getGeofenceManager();
+ Set<Long> result;
if (all) {
Context.getPermissionsManager().checkAdmin(getUserId());
- return Context.getGeofenceManager().getAllGeofences();
+ result = new HashSet<>(geofenceManager.getAllGeofencesIds());
} else {
if (userId == 0) {
userId = getUserId();
}
Context.getPermissionsManager().checkUser(getUserId(), userId);
- return Context.getGeofenceManager().getUserGeofences(userId);
+ result = new HashSet<Long>(geofenceManager.getUserGeofencesIds(userId));
+ }
+
+ if (groupId != 0) {
+ Context.getPermissionsManager().checkGroup(getUserId(), groupId);
+ result.retainAll(geofenceManager.getGroupGeofencesIds(groupId));
}
+
+ if (deviceId != 0) {
+ Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
+ result.retainAll(geofenceManager.getDeviceGeofencesIds(deviceId));
+ }
+ return Context.getGeofenceManager().getGeofences(result);
+
}
@POST
diff --git a/src/org/traccar/database/GeofenceManager.java b/src/org/traccar/database/GeofenceManager.java
index 0a07e2cf3..3f4d4c5ce 100644
--- a/src/org/traccar/database/GeofenceManager.java
+++ b/src/org/traccar/database/GeofenceManager.java
@@ -70,6 +70,15 @@ public class GeofenceManager {
return groupGeofences.get(groupId);
}
+ public Set<Long> getGroupGeofencesIds(long groupId) {
+ groupGeofencesLock.readLock().lock();
+ try {
+ return getGroupGeofences(groupId);
+ } finally {
+ groupGeofencesLock.readLock().unlock();
+ }
+ }
+
public Set<Long> getAllDeviceGeofences(long deviceId) {
deviceGeofencesLock.readLock().lock();
try {
@@ -77,10 +86,9 @@ public class GeofenceManager {
} finally {
deviceGeofencesLock.readLock().unlock();
}
-
}
- public Set<Long> getDeviceGeofences(long deviceId) {
+ public Set<Long> getDeviceGeofencesIds(long deviceId) {
deviceGeofencesLock.readLock().lock();
try {
return getDeviceGeofences(deviceGeofences, deviceId);
@@ -174,11 +182,20 @@ public class GeofenceManager {
}
}
- public final Collection<Geofence> getUserGeofences(long userId) {
+ public final Set<Long> getAllGeofencesIds() {
+ geofencesLock.readLock().lock();
+ try {
+ return geofences.keySet();
+ } finally {
+ geofencesLock.readLock().unlock();
+ }
+ }
+
+ public final Collection<Geofence> getGeofences(Set<Long> geofencesIds) {
geofencesLock.readLock().lock();
try {
Collection<Geofence> result = new LinkedList<>();
- for (Long geofenceId : getUserGeofencesIds(userId)) {
+ for (Long geofenceId : geofencesIds) {
result.add(getGeofence(geofenceId));
}
return result;