diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2019-03-09 20:00:11 -0800 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2019-03-09 20:00:11 -0800 |
commit | c7e9f996ed7d183442a7dd2fbbc5c9329981f261 (patch) | |
tree | 7b4ffe903970396e04a2bcdbe0acd66cba156395 /src/org/traccar/handler/events/MaintenanceEventHandler.java | |
parent | 312f5d2a3af3ec53cc6ff73cd3424d68a2774dcd (diff) | |
download | trackermap-server-c7e9f996ed7d183442a7dd2fbbc5c9329981f261.tar.gz trackermap-server-c7e9f996ed7d183442a7dd2fbbc5c9329981f261.tar.bz2 trackermap-server-c7e9f996ed7d183442a7dd2fbbc5c9329981f261.zip |
Refactor maintenance handler
Diffstat (limited to 'src/org/traccar/handler/events/MaintenanceEventHandler.java')
-rw-r--r-- | src/org/traccar/handler/events/MaintenanceEventHandler.java | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/org/traccar/handler/events/MaintenanceEventHandler.java b/src/org/traccar/handler/events/MaintenanceEventHandler.java index 80d9c0d91..93ae74142 100644 --- a/src/org/traccar/handler/events/MaintenanceEventHandler.java +++ b/src/org/traccar/handler/events/MaintenanceEventHandler.java @@ -20,7 +20,8 @@ import java.util.HashMap; import java.util.Map; import io.netty.channel.ChannelHandler; -import org.traccar.Context; +import org.traccar.database.IdentityManager; +import org.traccar.database.MaintenancesManager; import org.traccar.model.Event; import org.traccar.model.Maintenance; import org.traccar.model.Position; @@ -28,21 +29,29 @@ import org.traccar.model.Position; @ChannelHandler.Sharable public class MaintenanceEventHandler extends BaseEventHandler { + private final IdentityManager identityManager; + private final MaintenancesManager maintenancesManager; + + public MaintenanceEventHandler(IdentityManager identityManager, MaintenancesManager maintenancesManager) { + this.identityManager = identityManager; + this.maintenancesManager = maintenancesManager; + } + @Override protected Map<Event, Position> analyzePosition(Position position) { - if (Context.getIdentityManager().getById(position.getDeviceId()) == null - || !Context.getIdentityManager().isLatestPosition(position)) { + if (identityManager.getById(position.getDeviceId()) == null + || !identityManager.isLatestPosition(position)) { return null; } - Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId()); + Position lastPosition = identityManager.getLastPosition(position.getDeviceId()); if (lastPosition == null) { return null; } Map<Event, Position> events = new HashMap<>(); - for (long maintenanceId : Context.getMaintenancesManager().getAllDeviceItems(position.getDeviceId())) { - Maintenance maintenance = Context.getMaintenancesManager().getById(maintenanceId); + for (long maintenanceId : maintenancesManager.getAllDeviceItems(position.getDeviceId())) { + Maintenance maintenance = maintenancesManager.getById(maintenanceId); if (maintenance.getPeriod() != 0) { double oldValue = lastPosition.getDouble(maintenance.getType()); double newValue = position.getDouble(maintenance.getType()); |