aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/reports
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-13 17:19:15 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-13 17:19:15 -0700
commite894c17cf14addb729a6c51712ef672cc2cd160b (patch)
tree2f9b239d3445bf60e26baab0dbf7658b6ec841f5 /src/main/java/org/traccar/reports
parent75044332bebdd8bf3d77431a7008d617dc5f5986 (diff)
downloadtrackermap-server-e894c17cf14addb729a6c51712ef672cc2cd160b.tar.gz
trackermap-server-e894c17cf14addb729a6c51712ef672cc2cd160b.tar.bz2
trackermap-server-e894c17cf14addb729a6c51712ef672cc2cd160b.zip
Refactor getPositions method
Diffstat (limited to 'src/main/java/org/traccar/reports')
-rw-r--r--src/main/java/org/traccar/reports/RouteReportProvider.java11
-rw-r--r--src/main/java/org/traccar/reports/StopsReportProvider.java8
-rw-r--r--src/main/java/org/traccar/reports/SummaryReportProvider.java10
-rw-r--r--src/main/java/org/traccar/reports/TripsReportProvider.java14
4 files changed, 25 insertions, 18 deletions
diff --git a/src/main/java/org/traccar/reports/RouteReportProvider.java b/src/main/java/org/traccar/reports/RouteReportProvider.java
index 136a154aa..dbbf0906d 100644
--- a/src/main/java/org/traccar/reports/RouteReportProvider.java
+++ b/src/main/java/org/traccar/reports/RouteReportProvider.java
@@ -18,11 +18,13 @@ package org.traccar.reports;
import org.apache.poi.ss.util.WorkbookUtil;
import org.traccar.Context;
+import org.traccar.helper.model.PositionUtil;
import org.traccar.model.Device;
import org.traccar.model.Group;
import org.traccar.model.Position;
import org.traccar.reports.common.ReportUtils;
import org.traccar.reports.model.DeviceReportSection;
+import org.traccar.storage.Storage;
import org.traccar.storage.StorageException;
import javax.inject.Inject;
@@ -37,10 +39,12 @@ import java.util.Date;
public class RouteReportProvider {
private final ReportUtils reportUtils;
+ private final Storage storage;
@Inject
- public RouteReportProvider(ReportUtils reportUtils) {
+ public RouteReportProvider(ReportUtils reportUtils, Storage storage) {
this.reportUtils = reportUtils;
+ this.storage = storage;
}
public Collection<Position> getObjects(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
@@ -49,7 +53,7 @@ public class RouteReportProvider {
ArrayList<Position> result = new ArrayList<>();
for (long deviceId: reportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
- result.addAll(Context.getDataManager().getPositions(deviceId, from, to));
+ result.addAll(PositionUtil.getPositions(storage, deviceId, from, to));
}
return result;
}
@@ -62,8 +66,7 @@ public class RouteReportProvider {
ArrayList<String> sheetNames = new ArrayList<>();
for (long deviceId: reportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
- Collection<Position> positions = Context.getDataManager()
- .getPositions(deviceId, from, to);
+ var positions = PositionUtil.getPositions(storage, deviceId, from, to);
DeviceReportSection deviceRoutes = new DeviceReportSection();
Device device = Context.getIdentityManager().getById(deviceId);
deviceRoutes.setDeviceName(device.getName());
diff --git a/src/main/java/org/traccar/reports/StopsReportProvider.java b/src/main/java/org/traccar/reports/StopsReportProvider.java
index 807a6133b..534ab7742 100644
--- a/src/main/java/org/traccar/reports/StopsReportProvider.java
+++ b/src/main/java/org/traccar/reports/StopsReportProvider.java
@@ -18,11 +18,13 @@ package org.traccar.reports;
import org.apache.poi.ss.util.WorkbookUtil;
import org.traccar.Context;
+import org.traccar.helper.model.PositionUtil;
import org.traccar.model.Device;
import org.traccar.model.Group;
import org.traccar.reports.common.ReportUtils;
import org.traccar.reports.model.DeviceReportSection;
import org.traccar.reports.model.StopReportItem;
+import org.traccar.storage.Storage;
import org.traccar.storage.StorageException;
import javax.inject.Inject;
@@ -37,17 +39,19 @@ import java.util.Date;
public class StopsReportProvider {
private final ReportUtils reportUtils;
+ private final Storage storage;
@Inject
- public StopsReportProvider(ReportUtils reportUtils) {
+ public StopsReportProvider(ReportUtils reportUtils, Storage storage) {
this.reportUtils = reportUtils;
+ this.storage = storage;
}
private Collection<StopReportItem> detectStops(long deviceId, Date from, Date to) throws StorageException {
boolean ignoreOdometer = Context.getDeviceManager()
.lookupAttributeBoolean(deviceId, "report.ignoreOdometer", false, false, true);
return reportUtils.detectTripsAndStops(
- Context.getDataManager().getPositions(deviceId, from, to), ignoreOdometer, StopReportItem.class);
+ PositionUtil.getPositions(storage, deviceId, from, to), ignoreOdometer, StopReportItem.class);
}
public Collection<StopReportItem> getObjects(
diff --git a/src/main/java/org/traccar/reports/SummaryReportProvider.java b/src/main/java/org/traccar/reports/SummaryReportProvider.java
index 28abe790b..25d558480 100644
--- a/src/main/java/org/traccar/reports/SummaryReportProvider.java
+++ b/src/main/java/org/traccar/reports/SummaryReportProvider.java
@@ -25,6 +25,7 @@ import org.traccar.helper.model.UserUtil;
import org.traccar.model.Position;
import org.traccar.reports.common.ReportUtils;
import org.traccar.reports.model.SummaryReportItem;
+import org.traccar.storage.Storage;
import org.traccar.storage.StorageException;
import javax.inject.Inject;
@@ -41,11 +42,13 @@ public class SummaryReportProvider {
private final ReportUtils reportUtils;
private final PermissionsService permissionsService;
+ private final Storage storage;
@Inject
- public SummaryReportProvider(ReportUtils reportUtils, PermissionsService permissionsService) {
+ public SummaryReportProvider(ReportUtils reportUtils, PermissionsService permissionsService, Storage storage) {
this.reportUtils = reportUtils;
this.permissionsService = permissionsService;
+ this.storage = storage;
}
private SummaryReportItem calculateSummaryResult(long deviceId, Collection<Position> positions) {
@@ -111,9 +114,8 @@ public class SummaryReportProvider {
private Collection<SummaryReportItem> calculateSummaryResults(
long userId, long deviceId, Date from, Date to, boolean daily) throws StorageException {
- ArrayList<Position> positions = new ArrayList<>(Context.getDataManager().getPositions(deviceId, from, to));
-
- ArrayList<SummaryReportItem> results = new ArrayList<>();
+ var positions = PositionUtil.getPositions(storage, deviceId, from, to);
+ var results = new ArrayList<SummaryReportItem>();
if (daily && !positions.isEmpty()) {
int startIndex = 0;
int startDay = getDay(userId, positions.iterator().next().getFixTime());
diff --git a/src/main/java/org/traccar/reports/TripsReportProvider.java b/src/main/java/org/traccar/reports/TripsReportProvider.java
index 5e598cb50..a8e0e3dde 100644
--- a/src/main/java/org/traccar/reports/TripsReportProvider.java
+++ b/src/main/java/org/traccar/reports/TripsReportProvider.java
@@ -18,14 +18,13 @@ package org.traccar.reports;
import org.apache.poi.ss.util.WorkbookUtil;
import org.traccar.Context;
-import org.traccar.Main;
-import org.traccar.database.DeviceManager;
-import org.traccar.database.IdentityManager;
+import org.traccar.helper.model.PositionUtil;
import org.traccar.model.Device;
import org.traccar.model.Group;
import org.traccar.reports.common.ReportUtils;
import org.traccar.reports.model.DeviceReportSection;
import org.traccar.reports.model.TripReportItem;
+import org.traccar.storage.Storage;
import org.traccar.storage.StorageException;
import javax.inject.Inject;
@@ -40,21 +39,20 @@ import java.util.Date;
public class TripsReportProvider {
private final ReportUtils reportUtils;
+ private final Storage storage;
@Inject
- public TripsReportProvider(ReportUtils reportUtils) {
+ public TripsReportProvider(ReportUtils reportUtils, Storage storage) {
this.reportUtils = reportUtils;
+ this.storage = storage;
}
private Collection<TripReportItem> detectTrips(long deviceId, Date from, Date to) throws StorageException {
boolean ignoreOdometer = Context.getDeviceManager()
.lookupAttributeBoolean(deviceId, "report.ignoreOdometer", false, false, true);
- IdentityManager identityManager = Main.getInjector().getInstance(IdentityManager.class);
- DeviceManager deviceManager = Main.getInjector().getInstance(DeviceManager.class);
-
return reportUtils.detectTripsAndStops(
- Context.getDataManager().getPositions(deviceId, from, to), ignoreOdometer, TripReportItem.class);
+ PositionUtil.getPositions(storage, deviceId, from, to), ignoreOdometer, TripReportItem.class);
}
public Collection<TripReportItem> getObjects(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,