aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debug.xml7
-rw-r--r--schema/changelog-3.7.xml2
-rw-r--r--setup/unix/traccar.xml2
-rw-r--r--setup/windows/traccar.xml2
-rw-r--r--src/org/traccar/api/resource/ServerResource.java5
-rw-r--r--src/org/traccar/database/DeviceManager.java32
-rw-r--r--src/org/traccar/database/PermissionsManager.java11
-rw-r--r--src/org/traccar/events/GeofenceEventHandler.java37
-rw-r--r--src/org/traccar/events/MotionEventHandler.java32
-rw-r--r--src/org/traccar/events/OverspeedEventHandler.java37
10 files changed, 87 insertions, 80 deletions
diff --git a/debug.xml b/debug.xml
index fab27920e..abd230748 100644
--- a/debug.xml
+++ b/debug.xml
@@ -41,10 +41,11 @@
<entry key='logger.level'>all</entry>
<entry key='logger.file'>target/tracker-server.log</entry>
+ <entry key='deviceManager.lookupGroupsAttribute'>true</entry>
+
<entry key='event.enable'>true</entry>
- <entry key='event.suppressRepeated'>60</entry>
<entry key='event.overspeedHandler'>true</entry>
- <entry key='event.globalSpeedLimit'>90</entry>
+ <entry key='event.overspeed.notRepeat'>true</entry>
<entry key='event.motionHandler'>true</entry>
<entry key='event.geofenceHandler'>true</entry>
<entry key='event.alertHandler'>true</entry>
@@ -171,7 +172,7 @@
</entry>
<entry key='database.updateDeviceStatus'>
- UPDATE devices SET status = :status, lastUpdate = :lastUpdate WHERE id = :id;
+ UPDATE devices SET lastUpdate = :lastUpdate WHERE id = :id;
</entry>
<entry key='database.deleteDevice'>
diff --git a/schema/changelog-3.7.xml b/schema/changelog-3.7.xml
index ae85f69f3..d82dbe91b 100644
--- a/schema/changelog-3.7.xml
+++ b/schema/changelog-3.7.xml
@@ -26,6 +26,8 @@
<dropColumn tableName="devices" columnName="motion" />
+ <dropColumn tableName="devices" columnName="status" />
+
<addColumn tableName="groups">
<column name="attributes" type="VARCHAR(4096)" />
</addColumn>
diff --git a/setup/unix/traccar.xml b/setup/unix/traccar.xml
index 186e981cb..da09d74d6 100644
--- a/setup/unix/traccar.xml
+++ b/setup/unix/traccar.xml
@@ -120,7 +120,7 @@
</entry>
<entry key='database.updateDeviceStatus'>
- UPDATE devices SET status = :status, lastUpdate = :lastUpdate WHERE id = :id;
+ UPDATE devices SET lastUpdate = :lastUpdate WHERE id = :id;
</entry>
<entry key='database.deleteDevice'>
diff --git a/setup/windows/traccar.xml b/setup/windows/traccar.xml
index aa3809763..a3971e4f8 100644
--- a/setup/windows/traccar.xml
+++ b/setup/windows/traccar.xml
@@ -120,7 +120,7 @@
</entry>
<entry key='database.updateDeviceStatus'>
- UPDATE devices SET status = :status, lastUpdate = :lastUpdate WHERE id = :id;
+ UPDATE devices SET lastUpdate = :lastUpdate WHERE id = :id;
</entry>
<entry key='database.deleteDevice'>
diff --git a/src/org/traccar/api/resource/ServerResource.java b/src/org/traccar/api/resource/ServerResource.java
index 9e42687ab..0ca0d62aa 100644
--- a/src/org/traccar/api/resource/ServerResource.java
+++ b/src/org/traccar/api/resource/ServerResource.java
@@ -37,14 +37,13 @@ public class ServerResource extends BaseResource {
@PermitAll
@GET
public Server get() throws SQLException {
- return Context.getDataManager().getServer();
+ return Context.getPermissionsManager().getServer();
}
@PUT
public Response update(Server entity) throws SQLException {
Context.getPermissionsManager().checkAdmin(getUserId());
- Context.getDataManager().updateServer(entity);
- Context.getPermissionsManager().refresh();
+ Context.getPermissionsManager().updateServer(entity);
return Response.ok(entity).build();
}
diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java
index 5a0c87985..3476139f2 100644
--- a/src/org/traccar/database/DeviceManager.java
+++ b/src/org/traccar/database/DeviceManager.java
@@ -32,6 +32,7 @@ import org.traccar.helper.Log;
import org.traccar.model.Device;
import org.traccar.model.Group;
import org.traccar.model.Position;
+import org.traccar.model.Server;
public class DeviceManager implements IdentityManager {
@@ -40,6 +41,7 @@ public class DeviceManager implements IdentityManager {
private final Config config;
private final DataManager dataManager;
private final long dataRefreshDelay;
+ private boolean lookupGroupsAttribute;
private Map<Long, Device> devicesById;
private Map<String, Device> devicesByUniqueId;
@@ -54,6 +56,7 @@ public class DeviceManager implements IdentityManager {
this.dataManager = dataManager;
this.config = Context.getConfig();
dataRefreshDelay = config.getLong("database.refreshDelay", DEFAULT_REFRESH_DELAY) * 1000;
+ lookupGroupsAttribute = config.getBoolean("deviceManager.lookupGroupsAttribute");
if (dataManager != null) {
try {
updateGroupCache(true);
@@ -312,4 +315,33 @@ public class DeviceManager implements IdentityManager {
dataManager.removeGroup(groupId);
groupsById.remove(groupId);
}
+
+ public String lookupAttribute(long deviceId, String attributeName) {
+ String result = null;
+ Device device = getDeviceById(deviceId);
+ if (device != null) {
+ if (device.getAttributes().containsKey(attributeName)) {
+ result = (String) device.getAttributes().get(attributeName);
+ }
+ if (result == null && lookupGroupsAttribute) {
+ long groupId = device.getGroupId();
+ while (groupId != 0) {
+ if (getGroupById(groupId) != null) {
+ result = (String) getGroupById(groupId).getAttributes().get(attributeName);
+ if (result != null) {
+ break;
+ }
+ groupId = getGroupById(groupId).getGroupId();
+ } else {
+ groupId = 0;
+ }
+ }
+ }
+ if (result == null) {
+ Server server = Context.getPermissionsManager().getServer();
+ result = (String) server.getAttributes().get(attributeName);
+ }
+ }
+ return result;
+ }
}
diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java
index d786dcc4e..92fcc3ebd 100644
--- a/src/org/traccar/database/PermissionsManager.java
+++ b/src/org/traccar/database/PermissionsManager.java
@@ -34,7 +34,7 @@ public class PermissionsManager {
private final DataManager dataManager;
- private Server server;
+ private volatile Server server;
private final Map<Long, User> users = new HashMap<>();
@@ -153,4 +153,13 @@ public class PermissionsManager {
}
}
+ public Server getServer() {
+ return server;
+ }
+
+ public void updateServer(Server server) throws SQLException {
+ dataManager.updateServer(server);
+ this.server = server;
+ }
+
}
diff --git a/src/org/traccar/events/GeofenceEventHandler.java b/src/org/traccar/events/GeofenceEventHandler.java
index a9bed6f82..a0291dcfa 100644
--- a/src/org/traccar/events/GeofenceEventHandler.java
+++ b/src/org/traccar/events/GeofenceEventHandler.java
@@ -15,30 +15,23 @@
*/
package org.traccar.events;
-import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.traccar.BaseEventHandler;
import org.traccar.Context;
-import org.traccar.database.DataManager;
import org.traccar.database.GeofenceManager;
-import org.traccar.helper.Log;
import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Position;
public class GeofenceEventHandler extends BaseEventHandler {
- private int suppressRepeated;
private GeofenceManager geofenceManager;
- private DataManager dataManager;
public GeofenceEventHandler() {
- suppressRepeated = Context.getConfig().getInteger("event.suppressRepeated", 60);
geofenceManager = Context.getGeofenceManager();
- dataManager = Context.getDataManager();
}
@Override
@@ -63,29 +56,15 @@ public class GeofenceEventHandler extends BaseEventHandler {
device.setGeofenceIds(currentGeofences);
Collection<Event> events = new ArrayList<>();
- try {
- if (dataManager.getLastEvents(position.getDeviceId(),
- Event.TYPE_GEOFENCE_ENTER, suppressRepeated).isEmpty()) {
- for (long geofenceId : newGeofences) {
- Event event = new Event(Event.TYPE_GEOFENCE_ENTER, position.getDeviceId(), position.getId());
- event.setGeofenceId(geofenceId);
- events.add(event);
- }
- }
- } catch (SQLException error) {
- Log.warning(error);
+ for (long geofenceId : newGeofences) {
+ Event event = new Event(Event.TYPE_GEOFENCE_ENTER, position.getDeviceId(), position.getId());
+ event.setGeofenceId(geofenceId);
+ events.add(event);
}
- try {
- if (dataManager.getLastEvents(position.getDeviceId(),
- Event.TYPE_GEOFENCE_EXIT, suppressRepeated).isEmpty()) {
- for (long geofenceId : oldGeofences) {
- Event event = new Event(Event.TYPE_GEOFENCE_EXIT, position.getDeviceId(), position.getId());
- event.setGeofenceId(geofenceId);
- events.add(event);
- }
- }
- } catch (SQLException error) {
- Log.warning(error);
+ for (long geofenceId : oldGeofences) {
+ Event event = new Event(Event.TYPE_GEOFENCE_EXIT, position.getDeviceId(), position.getId());
+ event.setGeofenceId(geofenceId);
+ events.add(event);
}
return events;
}
diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java
index 4b652a727..ddb99185f 100644
--- a/src/org/traccar/events/MotionEventHandler.java
+++ b/src/org/traccar/events/MotionEventHandler.java
@@ -15,13 +15,11 @@
*/
package org.traccar.events;
-import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import org.traccar.BaseEventHandler;
import org.traccar.Context;
-import org.traccar.helper.Log;
import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -29,11 +27,6 @@ import org.traccar.model.Position;
public class MotionEventHandler extends BaseEventHandler {
private static final double SPEED_THRESHOLD = 0.01;
- private int suppressRepeated;
-
- public MotionEventHandler() {
- suppressRepeated = Context.getConfig().getInteger("event.suppressRepeated", 60);
- }
@Override
protected Collection<Event> analyzePosition(Position position) {
@@ -53,25 +46,12 @@ public class MotionEventHandler extends BaseEventHandler {
if (lastPosition != null) {
oldSpeed = lastPosition.getSpeed();
}
- try {
- if (speed > SPEED_THRESHOLD && oldSpeed <= SPEED_THRESHOLD) {
- result = new ArrayList<>();
- result.add(new Event(Event.TYPE_DEVICE_MOVING, position.getDeviceId(), position.getId()));
- } else if (speed <= SPEED_THRESHOLD && oldSpeed > SPEED_THRESHOLD) {
- result = new ArrayList<>();
- result.add(new Event(Event.TYPE_DEVICE_STOPPED, position.getDeviceId(), position.getId()));
- }
-
- if (result != null && !result.isEmpty()) {
- for (Event event : result) {
- if (!Context.getDataManager().getLastEvents(position.getDeviceId(),
- event.getType(), suppressRepeated).isEmpty()) {
- event = null;
- }
- }
- }
- } catch (SQLException error) {
- Log.warning(error);
+ if (speed > SPEED_THRESHOLD && oldSpeed <= SPEED_THRESHOLD) {
+ result = new ArrayList<>();
+ result.add(new Event(Event.TYPE_DEVICE_MOVING, position.getDeviceId(), position.getId()));
+ } else if (speed <= SPEED_THRESHOLD && oldSpeed > SPEED_THRESHOLD) {
+ result = new ArrayList<>();
+ result.add(new Event(Event.TYPE_DEVICE_STOPPED, position.getDeviceId(), position.getId()));
}
return result;
}
diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java
index 6c9b523f4..dbdb01ffb 100644
--- a/src/org/traccar/events/OverspeedEventHandler.java
+++ b/src/org/traccar/events/OverspeedEventHandler.java
@@ -15,7 +15,6 @@
*/
package org.traccar.events;
-import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
@@ -24,17 +23,16 @@ import org.traccar.Context;
import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Position;
-import org.traccar.helper.Log;
import org.traccar.helper.UnitsConverter;
public class OverspeedEventHandler extends BaseEventHandler {
- private double globalSpeedLimit;
- private int suppressRepeated;
+ public static final String ATTRIBUTE_SPEED_LIMIT = "speedLimit";
+
+ private boolean notRepeat;
public OverspeedEventHandler() {
- globalSpeedLimit = UnitsConverter.knotsFromKph(Context.getConfig().getInteger("event.globalSpeedLimit", 0));
- suppressRepeated = Context.getConfig().getInteger("event.suppressRepeated", 60);
+ notRepeat = Context.getConfig().getBoolean("event.overspeed.notRepeat");
}
@Override
@@ -50,17 +48,24 @@ public class OverspeedEventHandler extends BaseEventHandler {
Collection<Event> events = new ArrayList<>();
double speed = position.getSpeed();
-
- if (globalSpeedLimit != 0 && speed > globalSpeedLimit) {
- try {
- if (Context.getDataManager().getLastEvents(
- position.getDeviceId(), Event.TYPE_DEVICE_OVERSPEED, suppressRepeated).isEmpty()) {
- events.add(new Event(Event.TYPE_DEVICE_OVERSPEED, position.getDeviceId(), position.getId()));
- }
- } catch (SQLException error) {
- Log.warning(error);
+ double speedLimit = 0;
+ String speedLimitAttribute = Context.getDeviceManager().lookupAttribute(device.getId(), ATTRIBUTE_SPEED_LIMIT);
+ if (speedLimitAttribute != null) {
+ speedLimit = Double.parseDouble(speedLimitAttribute);
+ }
+ if (speedLimit == 0) {
+ return null;
+ }
+ double oldSpeed = 0;
+ if (notRepeat) {
+ Position lastPosition = Context.getDeviceManager().getLastPosition(position.getDeviceId());
+ if (lastPosition != null) {
+ oldSpeed = lastPosition.getSpeed();
}
-
+ }
+ speedLimit = UnitsConverter.knotsFromKph(speedLimit);
+ if (speed > speedLimit && oldSpeed <= speedLimit) {
+ events.add(new Event(Event.TYPE_DEVICE_OVERSPEED, position.getDeviceId(), position.getId()));
}
return events;
}