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 --- 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 +++++----- 4 files changed, 11 insertions(+), 12 deletions(-) (limited to 'src') 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