From ee7452124062845401afb0920d1569217595b8c5 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 9 Jul 2016 22:50:35 +1200 Subject: Fix issue with missing groups --- src/org/traccar/database/GeofenceManager.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/database/GeofenceManager.java b/src/org/traccar/database/GeofenceManager.java index cc9f82879..d3cf2ad1f 100644 --- a/src/org/traccar/database/GeofenceManager.java +++ b/src/org/traccar/database/GeofenceManager.java @@ -30,11 +30,12 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import org.traccar.Context; import org.traccar.helper.Log; import org.traccar.model.Device; +import org.traccar.model.DeviceGeofence; import org.traccar.model.Geofence; +import org.traccar.model.GeofencePermission; +import org.traccar.model.Group; import org.traccar.model.GroupGeofence; import org.traccar.model.Position; -import org.traccar.model.DeviceGeofence; -import org.traccar.model.GeofencePermission; public class GeofenceManager { @@ -137,15 +138,15 @@ public class GeofenceManager { } for (Device device : dataManager.getAllDevicesCached()) { - long groupId = device.getGroupId(); - while (groupId != 0) { + Group group = dataManager.getGroupById(device.getGroupId()); + while (group != null) { getDeviceGeofences(deviceGeofencesWithGroups, - device.getId()).addAll(getGroupGeofences(groupId)); - groupId = dataManager.getGroupById(groupId).getGroupId(); + device.getId()).addAll(getGroupGeofences(group.getGroupId())); + group = dataManager.getGroupById(group.getGroupId()); } List deviceGeofenceIds = device.getGeofenceIds(); if (deviceGeofenceIds == null) { - deviceGeofenceIds = new ArrayList(); + deviceGeofenceIds = new ArrayList<>(); } else { deviceGeofenceIds.clear(); } @@ -232,7 +233,7 @@ public class GeofenceManager { } public List getCurrentDeviceGeofences(Position position) { - List result = new ArrayList(); + List result = new ArrayList<>(); for (Long geofenceId : getAllDeviceGeofences(position.getDeviceId())) { if (getGeofence(geofenceId).getGeometry().containsPoint(position.getLatitude(), position.getLongitude())) { result.add(geofenceId); -- cgit v1.2.3