From 9b74f4a691354db61a3096794f3daeec575b8517 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 23 Jan 2018 12:16:46 +0500 Subject: Implement scheduled notifications --- src/org/traccar/database/NotificationManager.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/org/traccar/database') diff --git a/src/org/traccar/database/NotificationManager.java b/src/org/traccar/database/NotificationManager.java index 4e6114001..c666f27ce 100644 --- a/src/org/traccar/database/NotificationManager.java +++ b/src/org/traccar/database/NotificationManager.java @@ -1,6 +1,6 @@ /* - * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org) - * Copyright 2016 - 2017 Andrey Kunitsyn (andrey@traccar.org) + * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2018 Andrey Kunitsyn (andrey@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package org.traccar.database; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.sql.SQLException; +import java.util.Date; import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; @@ -26,6 +27,7 @@ import java.util.Set; import org.traccar.Context; import org.traccar.helper.Log; +import org.traccar.model.Calendar; import org.traccar.model.Event; import org.traccar.model.Notification; import org.traccar.model.Position; @@ -42,12 +44,16 @@ public class NotificationManager extends ExtendedObjectManager { geocodeOnRequest = Context.getConfig().getBoolean("geocoder.onRequest"); } - private Set getEffectiveNotifications(long userId, long deviceId) { + private Set getEffectiveNotifications(long userId, long deviceId, Date date) { Set result = new HashSet<>(); Set deviceNotifications = getAllDeviceItems(deviceId); for (long itemId : getUserItems(userId)) { if (getById(itemId).getAlways() || deviceNotifications.contains(itemId)) { - result.add(itemId); + long calendarId = getById(itemId).getCalendarId(); + Calendar calendar = calendarId != 0 ? Context.getCalendarManager().getById(calendarId) : null; + if (calendar == null || calendar.checkMoment(date)) { + result.add(itemId); + } } } return result; @@ -73,7 +79,7 @@ public class NotificationManager extends ExtendedObjectManager { boolean sentWeb = false; boolean sentMail = false; boolean sentSms = Context.getSmppManager() == null; - for (long notificationId : getEffectiveNotifications(userId, deviceId)) { + for (long notificationId : getEffectiveNotifications(userId, deviceId, event.getServerTime())) { Notification notification = getById(notificationId); if (getById(notificationId).getType().equals(event.getType())) { if (!sentWeb && notification.getWeb()) { -- cgit v1.2.3 From 2fc0683c9611c55997e85c5775a8b82f71b575ae Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 23 Jan 2018 14:13:32 +0500 Subject: Rename variable --- schema/changelog-3.16.xml | 2 +- src/org/traccar/database/NotificationManager.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/org/traccar/database') diff --git a/schema/changelog-3.16.xml b/schema/changelog-3.16.xml index 615222676..74fe35c3d 100644 --- a/schema/changelog-3.16.xml +++ b/schema/changelog-3.16.xml @@ -24,7 +24,7 @@ - + diff --git a/src/org/traccar/database/NotificationManager.java b/src/org/traccar/database/NotificationManager.java index c666f27ce..34c39e8ab 100644 --- a/src/org/traccar/database/NotificationManager.java +++ b/src/org/traccar/database/NotificationManager.java @@ -44,14 +44,14 @@ public class NotificationManager extends ExtendedObjectManager { geocodeOnRequest = Context.getConfig().getBoolean("geocoder.onRequest"); } - private Set getEffectiveNotifications(long userId, long deviceId, Date date) { + private Set getEffectiveNotifications(long userId, long deviceId, Date time) { Set result = new HashSet<>(); Set deviceNotifications = getAllDeviceItems(deviceId); for (long itemId : getUserItems(userId)) { if (getById(itemId).getAlways() || deviceNotifications.contains(itemId)) { long calendarId = getById(itemId).getCalendarId(); Calendar calendar = calendarId != 0 ? Context.getCalendarManager().getById(calendarId) : null; - if (calendar == null || calendar.checkMoment(date)) { + if (calendar == null || calendar.checkMoment(time)) { result.add(itemId); } } -- cgit v1.2.3