From f7a4d1977e71797b231ebb9a55308fee7c2b64d7 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 11 Apr 2018 14:55:11 +0500 Subject: Add support of multiple Maintenances --- src/org/traccar/database/NotificationManager.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/org/traccar/database/NotificationManager.java') diff --git a/src/org/traccar/database/NotificationManager.java b/src/org/traccar/database/NotificationManager.java index 1c59a8666..9f2606f7f 100644 --- a/src/org/traccar/database/NotificationManager.java +++ b/src/org/traccar/database/NotificationManager.java @@ -78,8 +78,10 @@ public class NotificationManager extends ExtendedObjectManager { 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() != null + && Context.getGeofenceManager().checkItemPermission(userId, event.getGeofenceId())) + && (event.getMaintenanceId() == 0 + || Context.getMaintenancesManager().checkItemPermission(userId, event.getMaintenanceId()))) { if (usersToForward != null) { usersToForward.add(userId); } -- cgit v1.2.3 From 30ae3d104e9b0446364ebc316dc10d0f811e1480 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 13 Apr 2018 12:21:05 +0500 Subject: - Rename field to Period - Remove unnecessary check for null - Move MaintenanceManager initialization with other event related managers --- schema/changelog-3.17.xml | 2 +- src/org/traccar/Context.java | 3 +-- src/org/traccar/database/NotificationManager.java | 4 ++-- src/org/traccar/events/MaintenanceEventHandler.java | 6 +++--- src/org/traccar/model/Maintenance.java | 10 +++++----- 5 files changed, 12 insertions(+), 13 deletions(-) (limited to 'src/org/traccar/database/NotificationManager.java') diff --git a/schema/changelog-3.17.xml b/schema/changelog-3.17.xml index 5e67fe75d..ef296fe25 100644 --- a/schema/changelog-3.17.xml +++ b/schema/changelog-3.17.xml @@ -25,7 +25,7 @@ - + diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java index a1a5f5a8e..67fd02f75 100644 --- a/src/org/traccar/Context.java +++ b/src/org/traccar/Context.java @@ -393,8 +393,6 @@ public final class Context { commandsManager = new CommandsManager(dataManager); - maintenancesManager = new MaintenancesManager(dataManager); - statisticsManager = new StatisticsManager(); if (config.getBoolean("sms.smpp.enable")) { @@ -429,6 +427,7 @@ public final class Context { geofenceManager = new GeofenceManager(dataManager); calendarManager = new CalendarManager(dataManager); + maintenancesManager = new MaintenancesManager(dataManager); notificationManager = new NotificationManager(dataManager); Properties velocityProperties = new Properties(); velocityProperties.setProperty("file.resource.loader.path", diff --git a/src/org/traccar/database/NotificationManager.java b/src/org/traccar/database/NotificationManager.java index 9f2606f7f..3bc048356 100644 --- a/src/org/traccar/database/NotificationManager.java +++ b/src/org/traccar/database/NotificationManager.java @@ -78,8 +78,8 @@ public class NotificationManager extends ExtendedObjectManager { 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) { diff --git a/src/org/traccar/events/MaintenanceEventHandler.java b/src/org/traccar/events/MaintenanceEventHandler.java index b556e1003..4a6122826 100644 --- a/src/org/traccar/events/MaintenanceEventHandler.java +++ b/src/org/traccar/events/MaintenanceEventHandler.java @@ -42,12 +42,12 @@ public class MaintenanceEventHandler extends BaseEventHandler { Map events = new HashMap<>(); for (long maintenanceId : Context.getMaintenancesManager().getAllDeviceItems(position.getDeviceId())) { Maintenance maintenance = Context.getMaintenancesManager().getById(maintenanceId); - if (maintenance.getLapse() != 0) { + if (maintenance.getPeriod() != 0) { double oldValue = lastPosition.getDouble(maintenance.getType()); double newValue = position.getDouble(maintenance.getType()); if (oldValue != 0.0 && newValue != 0.0 - && (long) ((oldValue - maintenance.getStart()) / maintenance.getLapse()) - < (long) ((newValue - maintenance.getStart()) / maintenance.getLapse())) { + && (long) ((oldValue - maintenance.getStart()) / maintenance.getPeriod()) + < (long) ((newValue - maintenance.getStart()) / maintenance.getPeriod())) { Event event = new Event(Event.TYPE_MAINTENANCE, position.getDeviceId(), position.getId()); event.setMaintenanceId(maintenanceId); event.set(maintenance.getType(), newValue); diff --git a/src/org/traccar/model/Maintenance.java b/src/org/traccar/model/Maintenance.java index 82052e160..73f67ea96 100644 --- a/src/org/traccar/model/Maintenance.java +++ b/src/org/traccar/model/Maintenance.java @@ -48,14 +48,14 @@ public class Maintenance extends ExtendedModel { this.start = start; } - private double lapse; + private double period; - public double getLapse() { - return lapse; + public double getPeriod() { + return period; } - public void setLapse(double lapse) { - this.lapse = lapse; + public void setPeriod(double period) { + this.period = period; } } -- cgit v1.2.3