diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-06-20 22:56:18 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-20 22:56:18 +1200 |
commit | 63aa4472c7d851a0b414dd3c295ccce2bc8c827f (patch) | |
tree | fca526a145f48ba07128649dd77348dbab257721 /src/org/traccar/api | |
parent | cc26f01471506935d6f438a102fbf9478dcebb1b (diff) | |
parent | f82970ac21ec2f050a09493fa7bc46c7178b57c3 (diff) | |
download | trackermap-server-63aa4472c7d851a0b414dd3c295ccce2bc8c827f.tar.gz trackermap-server-63aa4472c7d851a0b414dd3c295ccce2bc8c827f.tar.bz2 trackermap-server-63aa4472c7d851a0b414dd3c295ccce2bc8c827f.zip |
Merge pull request #2030 from Abyss777/master
Link and unlink geofences in web client
Diffstat (limited to 'src/org/traccar/api')
-rw-r--r-- | src/org/traccar/api/resource/GeofenceResource.java | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/org/traccar/api/resource/GeofenceResource.java b/src/org/traccar/api/resource/GeofenceResource.java index 9c80e61a1..44f6fc2f5 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 geofenceManager.getGeofences(result); + } @POST |