aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database/NotificationManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/database/NotificationManager.java')
-rw-r--r--src/org/traccar/database/NotificationManager.java31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/org/traccar/database/NotificationManager.java b/src/org/traccar/database/NotificationManager.java
index 4e6114001..3bc048356 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<Notification> {
geocodeOnRequest = Context.getConfig().getBoolean("geocoder.onRequest");
}
- private Set<Long> getEffectiveNotifications(long userId, long deviceId) {
+ private Set<Long> getEffectiveNotifications(long userId, long deviceId, Date time) {
Set<Long> result = new HashSet<>();
Set<Long> 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(time)) {
+ result.add(itemId);
+ }
}
}
return result;
@@ -67,13 +73,22 @@ public class NotificationManager extends ExtendedObjectManager<Notification> {
long deviceId = event.getDeviceId();
Set<Long> users = Context.getPermissionsManager().getDeviceUsers(deviceId);
+ Set<Long> usersToForward = null;
+ if (Context.getEventForwarder() != null) {
+ usersToForward = new HashSet<>();
+ }
for (long userId : users) {
- if (event.getGeofenceId() == 0 || Context.getGeofenceManager() != null
- && Context.getGeofenceManager().checkItemPermission(userId, event.getGeofenceId())) {
+ if ((event.getGeofenceId() == 0
+ || Context.getGeofenceManager().checkItemPermission(userId, event.getGeofenceId()))
+ && (event.getMaintenanceId() == 0
+ || Context.getMaintenancesManager().checkItemPermission(userId, event.getMaintenanceId()))) {
+ if (usersToForward != null) {
+ usersToForward.add(userId);
+ }
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()) {
@@ -96,7 +111,7 @@ public class NotificationManager extends ExtendedObjectManager<Notification> {
}
}
if (Context.getEventForwarder() != null) {
- Context.getEventForwarder().forwardEvent(event, position);
+ Context.getEventForwarder().forwardEvent(event, position, usersToForward);
}
}