From d08857e6c87d41eba835f16035e2da9159de9e49 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 22 Nov 2016 06:28:00 +1300 Subject: Implement unknown status event --- src/org/traccar/api/resource/NotificationResource.java | 1 + src/org/traccar/database/ConnectionManager.java | 16 ++++++++++++---- src/org/traccar/database/NotificationManager.java | 6 +++--- src/org/traccar/model/Event.java | 1 + 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/org/traccar/api/resource/NotificationResource.java b/src/org/traccar/api/resource/NotificationResource.java index 9010babf2..c43cca122 100644 --- a/src/org/traccar/api/resource/NotificationResource.java +++ b/src/org/traccar/api/resource/NotificationResource.java @@ -56,4 +56,5 @@ public class NotificationResource extends BaseResource { Context.getNotificationManager().updateNotification(entity); return Response.ok(entity).build(); } + } diff --git a/src/org/traccar/database/ConnectionManager.java b/src/org/traccar/database/ConnectionManager.java index 216c90bc2..bc44c31ae 100644 --- a/src/org/traccar/database/ConnectionManager.java +++ b/src/org/traccar/database/ConnectionManager.java @@ -76,10 +76,19 @@ public class ConnectionManager { } if (enableStatusEvents && !status.equals(device.getStatus())) { - Event event = new Event(Event.TYPE_DEVICE_OFFLINE, deviceId); - if (status.equals(Device.STATUS_ONLINE)) { - event.setType(Event.TYPE_DEVICE_ONLINE); + String eventType; + switch (status) { + case Device.STATUS_ONLINE: + eventType = Event.TYPE_DEVICE_ONLINE; + break; + case Device.STATUS_UNKNOWN: + eventType = Event.TYPE_DEVICE_UNKNOWN; + break; + default: + eventType = Event.TYPE_DEVICE_OFFLINE; + break; } + Event event = new Event(eventType, deviceId); if (Context.getNotificationManager() != null) { Context.getNotificationManager().updateEvent(event, null); } @@ -91,7 +100,6 @@ public class ConnectionManager { timeout.cancel(); } - if (time != null) { device.setLastUpdate(time); } diff --git a/src/org/traccar/database/NotificationManager.java b/src/org/traccar/database/NotificationManager.java index 110f699b7..b82fca0f3 100644 --- a/src/org/traccar/database/NotificationManager.java +++ b/src/org/traccar/database/NotificationManager.java @@ -74,7 +74,6 @@ public class NotificationManager { } public void updateEvents(Collection events, Position position) { - for (Event event : events) { updateEvent(event, position); } @@ -159,6 +158,7 @@ public class NotificationManager { } } else { notification.setId(cachedNotification.getId()); + notification.setId(cachedNotification.getId()); } } else if (!notification.getAttributes().isEmpty()) { try { @@ -176,9 +176,8 @@ public class NotificationManager { } public Set getAllNotifications() { - Set notifications = new HashSet<>(); - long id = 0; + long id = 1; Field[] fields = Event.class.getDeclaredFields(); for (Field field : fields) { if (Modifier.isStatic(field.getModifiers()) && field.getName().startsWith("TYPE_")) { @@ -194,4 +193,5 @@ public class NotificationManager { } return notifications; } + } diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java index cdb79f04d..3dc4778e1 100644 --- a/src/org/traccar/model/Event.java +++ b/src/org/traccar/model/Event.java @@ -40,6 +40,7 @@ public class Event extends Message { public static final String TYPE_COMMAND_RESULT = "commandResult"; public static final String TYPE_DEVICE_ONLINE = "deviceOnline"; + public static final String TYPE_DEVICE_UNKNOWN = "deviceUnknown"; public static final String TYPE_DEVICE_OFFLINE = "deviceOffline"; public static final String TYPE_DEVICE_MOVING = "deviceMoving"; -- cgit v1.2.3 From cd121c173f7c3ef0a815583eccec1232968894b9 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 22 Nov 2016 18:25:25 +1300 Subject: Remove duplicate line --- src/org/traccar/database/NotificationManager.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/org/traccar/database/NotificationManager.java b/src/org/traccar/database/NotificationManager.java index b82fca0f3..7e79e289f 100644 --- a/src/org/traccar/database/NotificationManager.java +++ b/src/org/traccar/database/NotificationManager.java @@ -158,7 +158,6 @@ public class NotificationManager { } } else { notification.setId(cachedNotification.getId()); - notification.setId(cachedNotification.getId()); } } else if (!notification.getAttributes().isEmpty()) { try { -- cgit v1.2.3