diff options
-rw-r--r-- | src/org/traccar/database/DeviceManager.java | 19 | ||||
-rw-r--r-- | src/org/traccar/events/OverspeedEventHandler.java | 3 | ||||
-rw-r--r-- | src/org/traccar/reports/ReportUtils.java | 2 | ||||
-rw-r--r-- | src/org/traccar/reports/Summary.java | 14 | ||||
-rw-r--r-- | src/org/traccar/reports/Trips.java | 14 |
5 files changed, 28 insertions, 24 deletions
diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java index 5f68df831..21e370051 100644 --- a/src/org/traccar/database/DeviceManager.java +++ b/src/org/traccar/database/DeviceManager.java @@ -316,7 +316,16 @@ public class DeviceManager implements IdentityManager { groupsById.remove(groupId); } - public String lookupAttribute(long deviceId, String attributeName) { + public String lookupServerAttribute(long deviceId, String attributeName) { + return lookupAttribute(deviceId, attributeName, true); + } + + public String lookupConfigAttribute(long deviceId, String attributeName) { + return lookupAttribute(deviceId, attributeName, false); + } + + + private String lookupAttribute(long deviceId, String attributeName, boolean lookupServer) { String result = null; Device device = getDeviceById(deviceId); if (device != null) { @@ -338,8 +347,12 @@ public class DeviceManager implements IdentityManager { } } if (result == null) { - Server server = Context.getPermissionsManager().getServer(); - result = (String) server.getAttributes().get(attributeName); + if (lookupServer) { + Server server = Context.getPermissionsManager().getServer(); + result = (String) server.getAttributes().get(attributeName); + } else { + result = Context.getConfig().getString(attributeName); + } } } return result; diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java index 302fa87cd..a32dfae7e 100644 --- a/src/org/traccar/events/OverspeedEventHandler.java +++ b/src/org/traccar/events/OverspeedEventHandler.java @@ -48,7 +48,8 @@ public class OverspeedEventHandler extends BaseEventHandler { Collection<Event> events = new ArrayList<>(); double speed = position.getSpeed(); double speedLimit = 0; - String speedLimitAttribute = Context.getDeviceManager().lookupAttribute(device.getId(), ATTRIBUTE_SPEED_LIMIT); + String speedLimitAttribute = Context.getDeviceManager() + .lookupServerAttribute(device.getId(), ATTRIBUTE_SPEED_LIMIT); if (speedLimitAttribute != null) { speedLimit = Double.parseDouble(speedLimitAttribute); } diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java index c973c3ff3..818920ad5 100644 --- a/src/org/traccar/reports/ReportUtils.java +++ b/src/org/traccar/reports/ReportUtils.java @@ -30,8 +30,6 @@ public final class ReportUtils { private ReportUtils() { } - public static final String IGNORE_ODOMETER = "report.ignoreOdometer"; - public static Collection<Long> getDeviceList(Collection<Long> deviceIds, Collection<Long> groupIds) { Collection<Long> result = new ArrayList<>(); result.addAll(deviceIds); diff --git a/src/org/traccar/reports/Summary.java b/src/org/traccar/reports/Summary.java index 79e1a7c05..763ddb600 100644 --- a/src/org/traccar/reports/Summary.java +++ b/src/org/traccar/reports/Summary.java @@ -24,7 +24,6 @@ import javax.json.Json; import javax.json.JsonArrayBuilder; import org.traccar.Context; -import org.traccar.model.Device; import org.traccar.model.Position; import org.traccar.reports.model.SummaryReport; import org.traccar.web.CsvBuilder; @@ -36,11 +35,9 @@ public final class Summary { } private static SummaryReport calculateSummaryResult(long deviceId, Date from, Date to) throws SQLException { - boolean ignoreOdometerConfig = Context.getConfig().getBoolean(ReportUtils.IGNORE_ODOMETER); SummaryReport result = new SummaryReport(); - Device device = Context.getDeviceManager().getDeviceById(deviceId); result.setDeviceId(deviceId); - result.setDeviceName(device.getName()); + result.setDeviceName(Context.getDeviceManager().getDeviceById(deviceId).getName()); Collection<Position> positions = Context.getDataManager().getPositions(deviceId, from, to); if (positions != null && !positions.isEmpty()) { Position firstPosition = null; @@ -64,11 +61,10 @@ public final class Summary { result.setMaxSpeed(position.getSpeed()); } boolean ignoreOdometer = false; - if (device.getAttributes().containsKey(ReportUtils.IGNORE_ODOMETER)) { - ignoreOdometer = Boolean.parseBoolean(device.getAttributes() - .get(ReportUtils.IGNORE_ODOMETER).toString()); - } else { - ignoreOdometer = ignoreOdometerConfig; + String ignoreOdometerAttribute = Context.getDeviceManager() + .lookupConfigAttribute(deviceId, "report.ignoreOdometer"); + if (ignoreOdometerAttribute != null) { + ignoreOdometer = Boolean.parseBoolean(ignoreOdometerAttribute); } result.setDistance(ReportUtils.calculateDistance(firstPosition, previousPosition, !ignoreOdometer)); result.setAverageSpeed(speedSum / positions.size()); diff --git a/src/org/traccar/reports/Trips.java b/src/org/traccar/reports/Trips.java index 514c5d1c4..c4a7f2c8f 100644 --- a/src/org/traccar/reports/Trips.java +++ b/src/org/traccar/reports/Trips.java @@ -25,7 +25,6 @@ import javax.json.Json; import javax.json.JsonArrayBuilder; import org.traccar.Context; -import org.traccar.model.Device; import org.traccar.model.Position; import org.traccar.reports.model.TripReport; import org.traccar.web.CsvBuilder; @@ -37,7 +36,6 @@ public final class Trips { } private static TripReport calculateTrip(ArrayList<Position> positions, int startIndex, int endIndex) { - boolean ignoreOdometerConfig = Context.getConfig().getBoolean(ReportUtils.IGNORE_ODOMETER); Position startTrip = positions.get(startIndex); Position endTrip = positions.get(endIndex); @@ -55,8 +53,7 @@ public final class Trips { long tripDuration = endTrip.getFixTime().getTime() - positions.get(startIndex).getFixTime().getTime(); long deviceId = startTrip.getDeviceId(); trip.setDeviceId(deviceId); - Device device = Context.getDeviceManager().getDeviceById(deviceId); - trip.setDeviceName(device.getName()); + trip.setDeviceName(Context.getDeviceManager().getDeviceById(deviceId).getName()); trip.setStartPositionId(startTrip.getId()); trip.setStartTime(startTrip.getFixTime()); trip.setStartAddress(startTrip.getAddress()); @@ -64,11 +61,10 @@ public final class Trips { trip.setEndTime(endTrip.getFixTime()); trip.setEndAddress(endTrip.getAddress()); boolean ignoreOdometer = false; - if (device.getAttributes().containsKey(ReportUtils.IGNORE_ODOMETER)) { - ignoreOdometer = Boolean.parseBoolean(device.getAttributes() - .get(ReportUtils.IGNORE_ODOMETER).toString()); - } else { - ignoreOdometer = ignoreOdometerConfig; + String ignoreOdometerAttribute = Context.getDeviceManager() + .lookupConfigAttribute(deviceId, "report.ignoreOdometer"); + if (ignoreOdometerAttribute != null) { + ignoreOdometer = Boolean.parseBoolean(ignoreOdometerAttribute); } trip.setDistance(ReportUtils.calculateDistance(startTrip, endTrip, !ignoreOdometer)); trip.setDuration(tripDuration); |