aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-03-07 22:53:42 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2021-03-07 22:53:42 -0800
commit440b2a96c3febdd498628c9b6cfaec01649786f2 (patch)
treec1e692e0f3e5b2ccf3199d67ac97ce77326bc069 /src/main/java/org
parente28ae518fddc930dcb26d70a4456ee1b28fb0ecc (diff)
downloadtrackermap-server-440b2a96c3febdd498628c9b6cfaec01649786f2.tar.gz
trackermap-server-440b2a96c3febdd498628c9b6cfaec01649786f2.tar.bz2
trackermap-server-440b2a96c3febdd498628c9b6cfaec01649786f2.zip
Use device time for events
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/traccar/handler/events/AlertEventHandler.java2
-rw-r--r--src/main/java/org/traccar/handler/events/CommandResultEventHandler.java2
-rw-r--r--src/main/java/org/traccar/handler/events/DriverEventHandler.java2
-rw-r--r--src/main/java/org/traccar/handler/events/FuelDropEventHandler.java2
-rw-r--r--src/main/java/org/traccar/handler/events/GeofenceEventHandler.java4
-rw-r--r--src/main/java/org/traccar/handler/events/IgnitionEventHandler.java4
-rw-r--r--src/main/java/org/traccar/handler/events/MaintenanceEventHandler.java2
-rw-r--r--src/main/java/org/traccar/handler/events/MotionEventHandler.java2
-rw-r--r--src/main/java/org/traccar/handler/events/OverspeedEventHandler.java2
-rw-r--r--src/main/java/org/traccar/model/Event.java10
10 files changed, 17 insertions, 15 deletions
diff --git a/src/main/java/org/traccar/handler/events/AlertEventHandler.java b/src/main/java/org/traccar/handler/events/AlertEventHandler.java
index 0b7c8d23e..05dbc516e 100644
--- a/src/main/java/org/traccar/handler/events/AlertEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/AlertEventHandler.java
@@ -48,7 +48,7 @@ public class AlertEventHandler extends BaseEventHandler {
}
}
if (!ignoreAlert) {
- Event event = new Event(Event.TYPE_ALARM, position.getDeviceId(), position.getId());
+ Event event = new Event(Event.TYPE_ALARM, position);
event.set(Position.KEY_ALARM, (String) alarm);
return Collections.singletonMap(event, position);
}
diff --git a/src/main/java/org/traccar/handler/events/CommandResultEventHandler.java b/src/main/java/org/traccar/handler/events/CommandResultEventHandler.java
index cfe676653..9b7ff554e 100644
--- a/src/main/java/org/traccar/handler/events/CommandResultEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/CommandResultEventHandler.java
@@ -29,7 +29,7 @@ public class CommandResultEventHandler extends BaseEventHandler {
protected Map<Event, Position> analyzePosition(Position position) {
Object commandResult = position.getAttributes().get(Position.KEY_RESULT);
if (commandResult != null) {
- Event event = new Event(Event.TYPE_COMMAND_RESULT, position.getDeviceId(), position.getId());
+ Event event = new Event(Event.TYPE_COMMAND_RESULT, position);
event.set(Position.KEY_RESULT, (String) commandResult);
return Collections.singletonMap(event, position);
}
diff --git a/src/main/java/org/traccar/handler/events/DriverEventHandler.java b/src/main/java/org/traccar/handler/events/DriverEventHandler.java
index 994df93fa..6fdf4246b 100644
--- a/src/main/java/org/traccar/handler/events/DriverEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/DriverEventHandler.java
@@ -46,7 +46,7 @@ public class DriverEventHandler extends BaseEventHandler {
oldDriverUniqueId = lastPosition.getString(Position.KEY_DRIVER_UNIQUE_ID);
}
if (!driverUniqueId.equals(oldDriverUniqueId)) {
- Event event = new Event(Event.TYPE_DRIVER_CHANGED, position.getDeviceId(), position.getId());
+ Event event = new Event(Event.TYPE_DRIVER_CHANGED, position);
event.set(Position.KEY_DRIVER_UNIQUE_ID, driverUniqueId);
return Collections.singletonMap(event, position);
}
diff --git a/src/main/java/org/traccar/handler/events/FuelDropEventHandler.java b/src/main/java/org/traccar/handler/events/FuelDropEventHandler.java
index bc1426b86..343a17311 100644
--- a/src/main/java/org/traccar/handler/events/FuelDropEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/FuelDropEventHandler.java
@@ -57,7 +57,7 @@ public class FuelDropEventHandler extends BaseEventHandler {
double drop = lastPosition.getDouble(Position.KEY_FUEL_LEVEL)
- position.getDouble(Position.KEY_FUEL_LEVEL);
if (drop >= fuelDropThreshold) {
- Event event = new Event(Event.TYPE_DEVICE_FUEL_DROP, position.getDeviceId(), position.getId());
+ Event event = new Event(Event.TYPE_DEVICE_FUEL_DROP, position);
event.set(ATTRIBUTE_FUEL_DROP_THRESHOLD, fuelDropThreshold);
return Collections.singletonMap(event, position);
}
diff --git a/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java b/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java
index 067c97957..f4807e56b 100644
--- a/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java
@@ -69,7 +69,7 @@ public class GeofenceEventHandler extends BaseEventHandler {
long calendarId = geofenceManager.getById(geofenceId).getCalendarId();
Calendar calendar = calendarId != 0 ? calendarManager.getById(calendarId) : null;
if (calendar == null || calendar.checkMoment(position.getFixTime())) {
- Event event = new Event(Event.TYPE_GEOFENCE_EXIT, position.getDeviceId(), position.getId());
+ Event event = new Event(Event.TYPE_GEOFENCE_EXIT, position);
event.setGeofenceId(geofenceId);
events.put(event, position);
}
@@ -78,7 +78,7 @@ public class GeofenceEventHandler extends BaseEventHandler {
long calendarId = geofenceManager.getById(geofenceId).getCalendarId();
Calendar calendar = calendarId != 0 ? calendarManager.getById(calendarId) : null;
if (calendar == null || calendar.checkMoment(position.getFixTime())) {
- Event event = new Event(Event.TYPE_GEOFENCE_ENTER, position.getDeviceId(), position.getId());
+ Event event = new Event(Event.TYPE_GEOFENCE_ENTER, position);
event.setGeofenceId(geofenceId);
events.put(event, position);
}
diff --git a/src/main/java/org/traccar/handler/events/IgnitionEventHandler.java b/src/main/java/org/traccar/handler/events/IgnitionEventHandler.java
index ec133bafc..69df9a46b 100644
--- a/src/main/java/org/traccar/handler/events/IgnitionEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/IgnitionEventHandler.java
@@ -52,10 +52,10 @@ public class IgnitionEventHandler extends BaseEventHandler {
if (ignition && !oldIgnition) {
result = Collections.singletonMap(
- new Event(Event.TYPE_IGNITION_ON, position.getDeviceId(), position.getId()), position);
+ new Event(Event.TYPE_IGNITION_ON, position), position);
} else if (!ignition && oldIgnition) {
result = Collections.singletonMap(
- new Event(Event.TYPE_IGNITION_OFF, position.getDeviceId(), position.getId()), position);
+ new Event(Event.TYPE_IGNITION_OFF, position), position);
}
}
}
diff --git a/src/main/java/org/traccar/handler/events/MaintenanceEventHandler.java b/src/main/java/org/traccar/handler/events/MaintenanceEventHandler.java
index 93ae74142..0f960ad1f 100644
--- a/src/main/java/org/traccar/handler/events/MaintenanceEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/MaintenanceEventHandler.java
@@ -58,7 +58,7 @@ public class MaintenanceEventHandler extends BaseEventHandler {
if (oldValue != 0.0 && newValue != 0.0
&& (long) ((oldValue - maintenance.getStart()) / maintenance.getPeriod())
< (long) ((newValue - maintenance.getStart()) / maintenance.getPeriod())) {
- Event event = new Event(Event.TYPE_MAINTENANCE, position.getDeviceId(), position.getId());
+ Event event = new Event(Event.TYPE_MAINTENANCE, position);
event.setMaintenanceId(maintenanceId);
event.set(maintenance.getType(), newValue);
events.put(event, position);
diff --git a/src/main/java/org/traccar/handler/events/MotionEventHandler.java b/src/main/java/org/traccar/handler/events/MotionEventHandler.java
index 9ec02ccfb..db276f32b 100644
--- a/src/main/java/org/traccar/handler/events/MotionEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/MotionEventHandler.java
@@ -45,7 +45,7 @@ public class MotionEventHandler extends BaseEventHandler {
private Map<Event, Position> newEvent(DeviceState deviceState, boolean newMotion) {
String eventType = newMotion ? Event.TYPE_DEVICE_MOVING : Event.TYPE_DEVICE_STOPPED;
Position position = deviceState.getMotionPosition();
- Event event = new Event(eventType, position.getDeviceId(), position.getId());
+ Event event = new Event(eventType, position);
deviceState.setMotionState(newMotion);
deviceState.setMotionPosition(null);
return Collections.singletonMap(event, position);
diff --git a/src/main/java/org/traccar/handler/events/OverspeedEventHandler.java b/src/main/java/org/traccar/handler/events/OverspeedEventHandler.java
index c396b28e9..347ad9005 100644
--- a/src/main/java/org/traccar/handler/events/OverspeedEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/OverspeedEventHandler.java
@@ -53,7 +53,7 @@ public class OverspeedEventHandler extends BaseEventHandler {
private Map<Event, Position> newEvent(DeviceState deviceState, double speedLimit) {
Position position = deviceState.getOverspeedPosition();
- Event event = new Event(Event.TYPE_DEVICE_OVERSPEED, position.getDeviceId(), position.getId());
+ Event event = new Event(Event.TYPE_DEVICE_OVERSPEED, position);
event.set(ATTRIBUTE_SPEED, deviceState.getOverspeedPosition().getSpeed());
event.set(ATTRIBUTE_SPEED_LIMIT, speedLimit);
event.setGeofenceId(deviceState.getOverspeedGeofenceId());
diff --git a/src/main/java/org/traccar/model/Event.java b/src/main/java/org/traccar/model/Event.java
index 47b74811a..a7a134ecf 100644
--- a/src/main/java/org/traccar/model/Event.java
+++ b/src/main/java/org/traccar/model/Event.java
@@ -19,15 +19,17 @@ import java.util.Date;
public class Event extends Message {
- public Event(String type, long deviceId, long positionId) {
- this(type, deviceId);
- setPositionId(positionId);
+ public Event(String type, Position position) {
+ setType(type);
+ setPositionId(position.getId());
+ setDeviceId(position.getDeviceId());
+ eventTime = position.getDeviceTime();
}
public Event(String type, long deviceId) {
setType(type);
setDeviceId(deviceId);
- this.eventTime = new Date();
+ eventTime = new Date();
}
public Event() {