aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/handler/events/MaintenanceEventHandler.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-03-09 20:00:11 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2019-03-09 20:00:11 -0800
commitc7e9f996ed7d183442a7dd2fbbc5c9329981f261 (patch)
tree7b4ffe903970396e04a2bcdbe0acd66cba156395 /src/org/traccar/handler/events/MaintenanceEventHandler.java
parent312f5d2a3af3ec53cc6ff73cd3424d68a2774dcd (diff)
downloadtrackermap-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.java21
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());