aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/BasePipelineFactory.java4
-rw-r--r--src/org/traccar/api/resource/EventResource.java2
-rw-r--r--src/org/traccar/database/ConnectionManager.java4
-rw-r--r--src/org/traccar/database/DataManager.java12
-rw-r--r--src/org/traccar/events/CommandResultEventHandler.java6
-rw-r--r--src/org/traccar/events/MotionEventHandler.java8
-rw-r--r--src/org/traccar/events/OverspeedEventHandler.java46
-rw-r--r--src/org/traccar/model/Event.java16
8 files changed, 32 insertions, 66 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index 55820deb7..634c6d6a4 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -132,11 +132,11 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
commandResultEventHandler = new CommandResultEventHandler();
- if (Context.getConfig().getBoolean("event.overspeedhandler")) {
+ if (Context.getConfig().getBoolean("event.overspeedHandler")) {
overspeedEventHandler = new OverspeedEventHandler();
}
- if (Context.getConfig().getBoolean("event.motionhandler")) {
+ if (Context.getConfig().getBoolean("event.motionHandler")) {
motionEventHandler = new MotionEventHandler();
}
diff --git a/src/org/traccar/api/resource/EventResource.java b/src/org/traccar/api/resource/EventResource.java
index e0ad34728..4ea3e3b49 100644
--- a/src/org/traccar/api/resource/EventResource.java
+++ b/src/org/traccar/api/resource/EventResource.java
@@ -32,7 +32,7 @@ public class EventResource extends BaseResource {
@GET
public Collection<Event> get(
@QueryParam("deviceId") long deviceId, @QueryParam("type") String type,
- @QueryParam("interval") long interval) throws SQLException {
+ @QueryParam("interval") int interval) throws SQLException {
Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
return Context.getDataManager().getLastEvents(deviceId, type, interval);
}
diff --git a/src/org/traccar/database/ConnectionManager.java b/src/org/traccar/database/ConnectionManager.java
index d6728357c..9e0da8485 100644
--- a/src/org/traccar/database/ConnectionManager.java
+++ b/src/org/traccar/database/ConnectionManager.java
@@ -90,9 +90,9 @@ public class ConnectionManager {
device.setMotion(status);
} else {
if (!status.equals(device.getStatus())) {
- Event event = new Event(Event.DEVICE_OFFLINE, deviceId);
+ Event event = new Event(Event.TYPE_DEVICE_OFFLINE, deviceId);
if (status.equals(Device.STATUS_ONLINE)) {
- event.setType(Event.DEVICE_ONLINE);
+ event.setType(Event.TYPE_DEVICE_ONLINE);
}
updateEvent(event);
}
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index fcb8899bc..dffb8937c 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -43,6 +43,7 @@ import java.net.URL;
import java.net.URLClassLoader;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
@@ -510,12 +511,11 @@ public class DataManager implements IdentityManager {
.executeQuery(Event.class);
}
- public Collection<Event> getLastEvents(long deviceId, String type, long interval) throws SQLException {
- return QueryBuilder.create(dataSource, getQuery("database.selectLastEvents"))
- .setLong("deviceId", deviceId)
- .setString("type", type)
- .setLong("interval", interval)
- .executeQuery(Event.class);
+ public Collection<Event> getLastEvents(long deviceId, String type, int interval) throws SQLException {
+ Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.SECOND, -interval);
+ Date to = calendar.getTime();
+ return getEvents(deviceId, type, new Date(), to);
}
}
diff --git a/src/org/traccar/events/CommandResultEventHandler.java b/src/org/traccar/events/CommandResultEventHandler.java
index 8ef015841..23c62566a 100644
--- a/src/org/traccar/events/CommandResultEventHandler.java
+++ b/src/org/traccar/events/CommandResultEventHandler.java
@@ -8,9 +8,9 @@ public class CommandResultEventHandler extends BaseEventHandler {
@Override
protected Event analizePosition(Position position) {
- Object cmdResult = position.getAttributes().get(Position.KEY_RESULT);
- if (cmdResult != null) {
- return new Event(Event.COMMAND_RESULT, position.getDeviceId(), position.getId());
+ Object commandResult = position.getAttributes().get(Position.KEY_RESULT);
+ if (commandResult != null) {
+ return new Event(Event.TYPE_COMMAND_RESULT, position.getDeviceId(), position.getId());
}
return null;
}
diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java
index d4dd12a39..a3b81ddc4 100644
--- a/src/org/traccar/events/MotionEventHandler.java
+++ b/src/org/traccar/events/MotionEventHandler.java
@@ -12,10 +12,10 @@ import org.traccar.model.Position;
public class MotionEventHandler extends BaseEventHandler {
private static final double SPEED_THRESHOLD = 0.01;
- private long suppressRepeated;
+ private int suppressRepeated;
public MotionEventHandler() {
- suppressRepeated = Context.getConfig().getLong("event.suppressrepeated", 60);
+ suppressRepeated = Context.getConfig().getInteger("event.suppressRepeated", 60);
}
@Override
@@ -35,10 +35,10 @@ public class MotionEventHandler extends BaseEventHandler {
String motion = device.getMotion();
if (valid && speed > SPEED_THRESHOLD && !motion.equals(Device.STATUS_MOVING)) {
Context.getConnectionManager().updateDevice(position.getDeviceId(), Device.STATUS_MOVING, null);
- event = new Event(Event.DEVICE_MOVING, position.getDeviceId(), position.getId());
+ event = new Event(Event.TYPE_DEVICE_MOVING, position.getDeviceId(), position.getId());
} else if (valid && speed < SPEED_THRESHOLD && motion.equals(Device.STATUS_MOVING)) {
Context.getConnectionManager().updateDevice(position.getDeviceId(), Device.STATUS_STOPPED, null);
- event = new Event(Event.DEVICE_STOPPED, position.getDeviceId(), position.getId());
+ event = new Event(Event.TYPE_DEVICE_STOPPED, position.getDeviceId(), position.getId());
}
try {
if (event != null && !Context.getDataManager().getLastEvents(
diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java
index 706e9b905..30410ff32 100644
--- a/src/org/traccar/events/OverspeedEventHandler.java
+++ b/src/org/traccar/events/OverspeedEventHandler.java
@@ -6,35 +6,17 @@ import org.traccar.BaseEventHandler;
import org.traccar.Context;
import org.traccar.model.Event;
import org.traccar.model.Position;
-import org.traccar.model.Server;
import org.traccar.helper.Log;
-//import org.traccar.model.Device;
-//import org.traccar.model.Group;
import org.traccar.helper.UnitsConverter;
public class OverspeedEventHandler extends BaseEventHandler {
private double globalSpeedLimit;
- private long suppressRepeated;
+ private int suppressRepeated;
public OverspeedEventHandler() {
- globalSpeedLimit = Context.getConfig().getInteger("event.globalspeedlimit", 0);
- suppressRepeated = Context.getConfig().getLong("event.suppressrepeated", 60);
- try {
- Server server = Context.getDataManager().getServer();
- String speedUnit = server.getSpeedUnit();
- if (speedUnit != null) {
- switch (speedUnit) {
- case "kmh" : globalSpeedLimit = UnitsConverter.knotsFromKph(globalSpeedLimit);
- break;
- case "mph" : globalSpeedLimit = UnitsConverter.knotsFromMph(globalSpeedLimit);
- default : break;
- }
- }
- } catch (SQLException error) {
- Log.warning(error);
- }
-
+ globalSpeedLimit = UnitsConverter.knotsFromKph(Context.getConfig().getInteger("event.globalSpeedLimit", 0));
+ suppressRepeated = Context.getConfig().getInteger("event.suppressRepeated", 60);
}
@Override
@@ -45,28 +27,12 @@ public class OverspeedEventHandler extends BaseEventHandler {
}
double speed = position.getSpeed();
boolean valid = position.getValid();
- double deviceSpeedLimit = 0;
- double groupSpeedLimit = 0;
-// Device device = Context.getIdentityManager().getDeviceById(position.getDeviceId());
-// if (device != null) {
-// deviceSpeedLimit = device.getSpeedLimit();
-// try {
-// Group group = Context.getDataManager().getGroupById(device.getGroupId());
-// if (group != null) {
-// groupSpeedLimit = group.getSpeedLimit();
-// }
-// } catch (SQLException error) {
-// Log.warning(error);
-// }
-// }
- if (valid && globalSpeedLimit != 0 && speed > globalSpeedLimit
- || valid && groupSpeedLimit != 0 && speed > groupSpeedLimit
- || valid && deviceSpeedLimit != 0 && speed > deviceSpeedLimit) {
+ if (valid && globalSpeedLimit != 0 && speed > globalSpeedLimit) {
try {
if (Context.getDataManager().getLastEvents(
- position.getDeviceId(), Event.DEVICE_OVERSPEED, suppressRepeated).isEmpty()) {
- event = new Event(Event.DEVICE_OVERSPEED, position.getDeviceId(), position.getId());
+ position.getDeviceId(), Event.TYPE_DEVICE_OVERSPEED, suppressRepeated).isEmpty()) {
+ event = new Event(Event.TYPE_DEVICE_OVERSPEED, position.getDeviceId(), position.getId());
}
} catch (SQLException error) {
Log.warning(error);
diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java
index 27c750c49..75049c433 100644
--- a/src/org/traccar/model/Event.java
+++ b/src/org/traccar/model/Event.java
@@ -30,18 +30,18 @@ public class Event extends Message {
this.id = id;
}
- public static final String COMMAND_RESULT = "command-result";
+ public static final String TYPE_COMMAND_RESULT = "commandResult";
- public static final String DEVICE_ONLINE = "device-online";
- public static final String DEVICE_OFFLINE = "device-offline";
+ public static final String TYPE_DEVICE_ONLINE = "deviceOnline";
+ public static final String TYPE_DEVICE_OFFLINE = "deviceOffline";
- public static final String DEVICE_MOVING = "device-moving";
- public static final String DEVICE_STOPPED = "device-stopped";
+ public static final String TYPE_DEVICE_MOVING = "deviceMoving";
+ public static final String TYPE_DEVICE_STOPPED = "deviceStopped";
- public static final String DEVICE_OVERSPEED = "device-overspeed";
+ public static final String TYPE_DEVICE_OVERSPEED = "deviceOverspeed";
- public static final String GEOFENCE_ENTER = "geofence-enter";
- public static final String GEOFENCE_EXIT = "geofence-exit";
+ public static final String TYPE_GEOFENCE_ENTER = "geofenceEnter";
+ public static final String TYPE_GEOFENCE_EXIT = "geofenceExit";
private Date eventTime;