aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-12-05 23:33:18 +1300
committerGitHub <noreply@github.com>2016-12-05 23:33:18 +1300
commit40607036c5aa6385a7ae3f3a283bf107238a5944 (patch)
tree72ff1743d96f79e4a9d85b0d48715e5f9aa67cf9 /src/org/traccar/database
parenta9260f9e470add52f1fe3df35ea93e0d547c3fe7 (diff)
parenteffcde41e6f77df3829a9809f48fcc3aed9caade (diff)
downloadtrackermap-server-40607036c5aa6385a7ae3f3a283bf107238a5944.tar.gz
trackermap-server-40607036c5aa6385a7ae3f3a283bf107238a5944.tar.bz2
trackermap-server-40607036c5aa6385a7ae3f3a283bf107238a5944.zip
Merge pull request #2638 from Abyss777/improve_notifications
Use model instead of attributes to store Notification options
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r--src/org/traccar/database/NotificationManager.java25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/org/traccar/database/NotificationManager.java b/src/org/traccar/database/NotificationManager.java
index 7e79e289f..ee804f5cd 100644
--- a/src/org/traccar/database/NotificationManager.java
+++ b/src/org/traccar/database/NotificationManager.java
@@ -59,10 +59,10 @@ public class NotificationManager {
&& Context.getGeofenceManager().checkGeofence(userId, event.getGeofenceId())) {
Notification notification = getUserNotificationByType(userId, event.getType());
if (notification != null) {
- if (notification.getAttributes().containsKey("web")) {
+ if (notification.getWeb()) {
Context.getConnectionManager().updateEvent(userId, event, position);
}
- if (notification.getAttributes().containsKey("mail")) {
+ if (notification.getMail()) {
NotificationMail.sendMailAsync(userId, event, position);
}
}
@@ -130,8 +130,9 @@ public class NotificationManager {
public void updateNotification(Notification notification) {
Notification cachedNotification = getUserNotificationByType(notification.getUserId(), notification.getType());
if (cachedNotification != null) {
- if (!cachedNotification.getAttributes().equals(notification.getAttributes())) {
- if (notification.getAttributes().isEmpty()) {
+ if (cachedNotification.getWeb() != notification.getWeb()
+ || cachedNotification.getMail() != notification.getMail()) {
+ if (!notification.getWeb() && !notification.getMail()) {
try {
dataManager.removeNotification(cachedNotification);
} catch (SQLException error) {
@@ -146,6 +147,8 @@ public class NotificationManager {
} else {
notificationsLock.writeLock().lock();
try {
+ cachedNotification.setWeb(notification.getWeb());
+ cachedNotification.setMail(notification.getMail());
cachedNotification.setAttributes(notification.getAttributes());
} finally {
notificationsLock.writeLock().unlock();
@@ -159,7 +162,7 @@ public class NotificationManager {
} else {
notification.setId(cachedNotification.getId());
}
- } else if (!notification.getAttributes().isEmpty()) {
+ } else if (notification.getWeb() || notification.getMail()) {
try {
dataManager.addNotification(notification);
} catch (SQLException error) {
@@ -193,4 +196,16 @@ public class NotificationManager {
return notifications;
}
+ public Collection<Notification> getAllUserNotifications(long userId) {
+ Map<String, Notification> notifications = new HashMap<>();
+ for (Notification notification : getAllNotifications()) {
+ notification.setUserId(userId);
+ notifications.put(notification.getType(), notification);
+ }
+ for (Notification notification : getUserNotifications(userId)) {
+ notifications.put(notification.getType(), notification);
+ }
+ return notifications.values();
+ }
+
}