From 1324c00d0ece6e20545fb75f7775a2c6cee2a391 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 17 Aug 2017 10:10:05 +0500 Subject: Pass Map to notifications --- src/org/traccar/database/ConnectionManager.java | 21 +++++++++++---------- src/org/traccar/database/NotificationManager.java | 18 +++++++----------- 2 files changed, 18 insertions(+), 21 deletions(-) (limited to 'src/org/traccar/database') diff --git a/src/org/traccar/database/ConnectionManager.java b/src/org/traccar/database/ConnectionManager.java index 7a0a6d30d..de11db21b 100644 --- a/src/org/traccar/database/ConnectionManager.java +++ b/src/org/traccar/database/ConnectionManager.java @@ -31,6 +31,7 @@ import org.traccar.model.Position; import java.net.SocketAddress; import java.sql.SQLException; import java.util.Date; +import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -84,7 +85,7 @@ public class ConnectionManager { if (enableStatusEvents && !status.equals(oldStatus)) { String eventType; - Set events = new HashSet<>(); + Map events = new HashMap<>(); switch (status) { case Device.STATUS_ONLINE: eventType = Event.TYPE_DEVICE_ONLINE; @@ -92,18 +93,18 @@ public class ConnectionManager { case Device.STATUS_UNKNOWN: eventType = Event.TYPE_DEVICE_UNKNOWN; if (updateDeviceState) { - events.addAll(updateDeviceState(deviceId)); + events.putAll(updateDeviceState(deviceId)); } break; default: eventType = Event.TYPE_DEVICE_OFFLINE; if (updateDeviceState) { - events.addAll(updateDeviceState(deviceId)); + events.putAll(updateDeviceState(deviceId)); } break; } - events.add(new Event(eventType, deviceId)); - Context.getNotificationManager().updateEvents(events, null); + events.put(new Event(eventType, deviceId), null); + Context.getNotificationManager().updateEvents(events); } Timeout timeout = timeouts.remove(deviceId); @@ -135,19 +136,19 @@ public class ConnectionManager { updateDevice(device); } - public Set updateDeviceState(long deviceId) { + public Map updateDeviceState(long deviceId) { DeviceState deviceState = Context.getDeviceManager().getDeviceState(deviceId); - Set result = new HashSet<>(); + Map result = new HashMap<>(); - Event event = Context.getMotionEventHandler().updateMotionState(deviceState); + Map event = Context.getMotionEventHandler().updateMotionState(deviceState); if (event != null) { - result.add(event); + result.putAll(event); } event = Context.getOverspeedEventHandler().updateOverspeedState(deviceState, Context.getDeviceManager(). lookupAttributeDouble(deviceId, OverspeedEventHandler.ATTRIBUTE_SPEED_LIMIT, 0, false)); if (event != null) { - result.add(event); + result.putAll(event); } return result; diff --git a/src/org/traccar/database/NotificationManager.java b/src/org/traccar/database/NotificationManager.java index 8eea287de..98cae3499 100644 --- a/src/org/traccar/database/NotificationManager.java +++ b/src/org/traccar/database/NotificationManager.java @@ -22,6 +22,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; @@ -48,13 +49,8 @@ public class NotificationManager { } public void updateEvent(Event event, Position position) { - Position relatedPosition = position; try { dataManager.addObject(event); - if (event.getPositionId() != 0 && (relatedPosition == null - || event.getPositionId() != relatedPosition.getId())) { - relatedPosition = dataManager.getObject(Position.class, event.getPositionId()); - } } catch (SQLException error) { Log.warning(error); } @@ -69,22 +65,22 @@ public class NotificationManager { Context.getConnectionManager().updateEvent(userId, event); } if (notification.getMail()) { - NotificationMail.sendMailAsync(userId, event, relatedPosition); + NotificationMail.sendMailAsync(userId, event, position); } if (notification.getSms()) { - NotificationSms.sendSmsAsync(userId, event, relatedPosition); + NotificationSms.sendSmsAsync(userId, event, position); } } } } if (Context.getEventForwarder() != null) { - Context.getEventForwarder().forwardEvent(event, relatedPosition); + Context.getEventForwarder().forwardEvent(event, position); } } - public void updateEvents(Collection events, Position position) { - for (Event event : events) { - updateEvent(event, position); + public void updateEvents(Map events) { + for (Entry event : events.entrySet()) { + updateEvent(event.getKey(), event.getValue()); } } -- cgit v1.2.3