From 6f163bdf3856323a5aa075f9a2e1aeb01b7bc598 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 9 Jun 2022 08:53:26 -0700 Subject: Remove more from context --- .../org/traccar/reports/StopsReportProvider.java | 7 +++++-- .../org/traccar/reports/TripsReportProvider.java | 7 +++++-- .../java/org/traccar/reports/common/TripsConfig.java | 20 +++++++++++++++++++- 3 files changed, 29 insertions(+), 5 deletions(-) (limited to 'src/main/java/org/traccar/reports') diff --git a/src/main/java/org/traccar/reports/StopsReportProvider.java b/src/main/java/org/traccar/reports/StopsReportProvider.java index 8899dc42f..b7896c423 100644 --- a/src/main/java/org/traccar/reports/StopsReportProvider.java +++ b/src/main/java/org/traccar/reports/StopsReportProvider.java @@ -34,6 +34,7 @@ import org.traccar.database.IdentityManager; import org.traccar.model.Device; import org.traccar.model.Group; import org.traccar.reports.common.ReportUtils; +import org.traccar.reports.common.TripsConfig; import org.traccar.reports.model.DeviceReportSection; import org.traccar.reports.model.StopReportItem; import org.traccar.storage.Storage; @@ -45,11 +46,13 @@ public class StopsReportProvider { private final PermissionsService permissionsService; private final Storage storage; + private final TripsConfig tripsConfig; @Inject - public StopsReportProvider(PermissionsService permissionsService, Storage storage) { + public StopsReportProvider(PermissionsService permissionsService, Storage storage, TripsConfig tripsConfig) { this.permissionsService = permissionsService; this.storage = storage; + this.tripsConfig = tripsConfig; } private Collection detectStops(long deviceId, Date from, Date to) throws StorageException { @@ -61,7 +64,7 @@ public class StopsReportProvider { return ReportUtils.detectTripsAndStops( storage, identityManager, deviceManager, Context.getDataManager().getPositions(deviceId, from, to), - Context.getTripsConfig(), ignoreOdometer, StopReportItem.class); + tripsConfig, ignoreOdometer, StopReportItem.class); } public Collection getObjects( diff --git a/src/main/java/org/traccar/reports/TripsReportProvider.java b/src/main/java/org/traccar/reports/TripsReportProvider.java index bcd79ab25..0505baaa1 100644 --- a/src/main/java/org/traccar/reports/TripsReportProvider.java +++ b/src/main/java/org/traccar/reports/TripsReportProvider.java @@ -33,6 +33,7 @@ import org.traccar.database.IdentityManager; import org.traccar.model.Device; import org.traccar.model.Group; import org.traccar.reports.common.ReportUtils; +import org.traccar.reports.common.TripsConfig; import org.traccar.reports.model.DeviceReportSection; import org.traccar.reports.model.TripReportItem; import org.traccar.storage.Storage; @@ -44,11 +45,13 @@ public class TripsReportProvider { private final PermissionsService permissionsService; private final Storage storage; + private final TripsConfig tripsConfig; @Inject - public TripsReportProvider(PermissionsService permissionsService, Storage storage) { + public TripsReportProvider(PermissionsService permissionsService, Storage storage, TripsConfig tripsConfig) { this.permissionsService = permissionsService; this.storage = storage; + this.tripsConfig = tripsConfig; } private Collection detectTrips(long deviceId, Date from, Date to) throws StorageException { @@ -60,7 +63,7 @@ public class TripsReportProvider { return ReportUtils.detectTripsAndStops( storage, identityManager, deviceManager, Context.getDataManager().getPositions(deviceId, from, to), - Context.getTripsConfig(), ignoreOdometer, TripReportItem.class); + tripsConfig, ignoreOdometer, TripReportItem.class); } public Collection getObjects(long userId, Collection deviceIds, Collection groupIds, diff --git a/src/main/java/org/traccar/reports/common/TripsConfig.java b/src/main/java/org/traccar/reports/common/TripsConfig.java index 9a7cebafb..c28cbeed4 100644 --- a/src/main/java/org/traccar/reports/common/TripsConfig.java +++ b/src/main/java/org/traccar/reports/common/TripsConfig.java @@ -16,9 +16,27 @@ */ package org.traccar.reports.common; +import org.traccar.config.Config; +import org.traccar.config.Keys; + +import javax.inject.Inject; + public class TripsConfig { - public TripsConfig(double minimalTripDistance, long minimalTripDuration, long minimalParkingDuration, + @Inject + public TripsConfig(Config config) { + this( + config.getLong(Keys.REPORT_TRIP_MINIMAL_TRIP_DISTANCE), + config.getLong(Keys.REPORT_TRIP_MINIMAL_TRIP_DURATION) * 1000, + config.getLong(Keys.REPORT_TRIP_MINIMAL_PARKING_DURATION) * 1000, + config.getLong(Keys.REPORT_TRIP_MINIMAL_NO_DATA_DURATION) * 1000, + config.getBoolean(Keys.REPORT_TRIP_USE_IGNITION), + config.getBoolean(Keys.EVENT_MOTION_PROCESS_INVALID_POSITIONS), + config.getDouble(Keys.EVENT_MOTION_SPEED_THRESHOLD)); + } + + public TripsConfig( + double minimalTripDistance, long minimalTripDuration, long minimalParkingDuration, long minimalNoDataDuration, boolean useIgnition, boolean processInvalidPositions, double speedThreshold) { this.minimalTripDistance = minimalTripDistance; this.minimalTripDuration = minimalTripDuration; -- cgit v1.2.3