aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/handler
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-03-09 12:19:46 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2019-03-09 12:19:46 -0800
commit2af6e4cc6255f59acaa17e6763063b775d7ba1ea (patch)
treed95d2aeb584eb2c8c5709ea727e881aa1c4fc8cd /src/org/traccar/handler
parent8018a9269789d532431ed455b82c3a67acdd0e50 (diff)
downloadtraccar-server-2af6e4cc6255f59acaa17e6763063b775d7ba1ea.tar.gz
traccar-server-2af6e4cc6255f59acaa17e6763063b775d7ba1ea.tar.bz2
traccar-server-2af6e4cc6255f59acaa17e6763063b775d7ba1ea.zip
Refactor fuel drop manager
Diffstat (limited to 'src/org/traccar/handler')
-rw-r--r--src/org/traccar/handler/events/FuelDropEventHandler.java18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/org/traccar/handler/events/FuelDropEventHandler.java b/src/org/traccar/handler/events/FuelDropEventHandler.java
index f13b8c7bb..59de61bba 100644
--- a/src/org/traccar/handler/events/FuelDropEventHandler.java
+++ b/src/org/traccar/handler/events/FuelDropEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2019 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
package org.traccar.handler.events;
import io.netty.channel.ChannelHandler;
-import org.traccar.Context;
+import org.traccar.database.IdentityManager;
import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -29,22 +29,28 @@ public class FuelDropEventHandler extends BaseEventHandler {
public static final String ATTRIBUTE_FUEL_DROP_THRESHOLD = "fuelDropThreshold";
+ private final IdentityManager identityManager;
+
+ public FuelDropEventHandler(IdentityManager identityManager) {
+ this.identityManager = identityManager;
+ }
+
@Override
protected Map<Event, Position> analyzePosition(Position position) {
- Device device = Context.getIdentityManager().getById(position.getDeviceId());
+ Device device = identityManager.getById(position.getDeviceId());
if (device == null) {
return null;
}
- if (!Context.getIdentityManager().isLatestPosition(position)) {
+ if (!identityManager.isLatestPosition(position)) {
return null;
}
- double fuelDropThreshold = Context.getDeviceManager()
+ double fuelDropThreshold = identityManager
.lookupAttributeDouble(device.getId(), ATTRIBUTE_FUEL_DROP_THRESHOLD, 0, false);
if (fuelDropThreshold > 0) {
- Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
+ Position lastPosition = identityManager.getLastPosition(position.getDeviceId());
if (position.getAttributes().containsKey(Position.KEY_FUEL_LEVEL)
&& lastPosition != null && lastPosition.getAttributes().containsKey(Position.KEY_FUEL_LEVEL)) {