aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-04 11:01:01 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-04 11:01:01 -0700
commit31c4ad41f4d91dec3c98af06614e9518d3689a14 (patch)
tree6606a8e8e4f35d86bf0f6cc4da6d3ebd54f9ae23 /src/main/java/org/traccar
parent94a2a94330d82fa1c1960b8783e5061c188196e3 (diff)
downloadtrackermap-server-31c4ad41f4d91dec3c98af06614e9518d3689a14.tar.gz
trackermap-server-31c4ad41f4d91dec3c98af06614e9518d3689a14.tar.bz2
trackermap-server-31c4ad41f4d91dec3c98af06614e9518d3689a14.zip
Inject report providers
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r--src/main/java/org/traccar/api/resource/ReportResource.java46
-rw-r--r--src/main/java/org/traccar/reports/EventsReportProvider.java (renamed from src/main/java/org/traccar/reports/Events.java)9
-rw-r--r--src/main/java/org/traccar/reports/RouteReportProvider.java (renamed from src/main/java/org/traccar/reports/Route.java)11
-rw-r--r--src/main/java/org/traccar/reports/StopsReportProvider.java (renamed from src/main/java/org/traccar/reports/Stops.java)13
-rw-r--r--src/main/java/org/traccar/reports/SummaryReportProvider.java (renamed from src/main/java/org/traccar/reports/Summary.java)18
-rw-r--r--src/main/java/org/traccar/reports/TripsReportProvider.java (renamed from src/main/java/org/traccar/reports/Trips.java)13
6 files changed, 56 insertions, 54 deletions
diff --git a/src/main/java/org/traccar/api/resource/ReportResource.java b/src/main/java/org/traccar/api/resource/ReportResource.java
index 5346df31b..38eb52685 100644
--- a/src/main/java/org/traccar/api/resource/ReportResource.java
+++ b/src/main/java/org/traccar/api/resource/ReportResource.java
@@ -23,6 +23,7 @@ import java.util.Date;
import java.util.List;
import javax.activation.DataHandler;
+import javax.inject.Inject;
import javax.mail.MessagingException;
import javax.mail.internet.MimeBodyPart;
import javax.mail.util.ByteArrayDataSource;
@@ -43,14 +44,14 @@ import org.traccar.helper.LogAction;
import org.traccar.model.Event;
import org.traccar.model.Position;
import org.traccar.model.UserRestrictions;
-import org.traccar.reports.Events;
-import org.traccar.reports.Summary;
-import org.traccar.reports.Trips;
+import org.traccar.reports.EventsReportProvider;
+import org.traccar.reports.SummaryReportProvider;
+import org.traccar.reports.TripsReportProvider;
import org.traccar.reports.model.StopReportItem;
import org.traccar.reports.model.SummaryReportItem;
import org.traccar.reports.model.TripReportItem;
-import org.traccar.reports.Route;
-import org.traccar.reports.Stops;
+import org.traccar.reports.RouteReportProvider;
+import org.traccar.reports.StopsReportProvider;
import org.traccar.storage.StorageException;
@Path("reports")
@@ -63,6 +64,21 @@ public class ReportResource extends BaseResource {
private static final String XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
private static final String CONTENT_DISPOSITION_VALUE_XLSX = "attachment; filename=report.xlsx";
+ @Inject
+ private EventsReportProvider eventsReportProvider;
+
+ @Inject
+ private RouteReportProvider routeReportProvider;
+
+ @Inject
+ private StopsReportProvider stopsReportProvider;
+
+ @Inject
+ private SummaryReportProvider summaryReportProvider;
+
+ @Inject
+ private TripsReportProvider tripsReportProvider;
+
private interface ReportExecutor {
void execute(ByteArrayOutputStream stream) throws StorageException, IOException;
}
@@ -102,7 +118,7 @@ public class ReportResource extends BaseResource {
@QueryParam("from") Date from, @QueryParam("to") Date to) throws StorageException {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
LogAction.logReport(getUserId(), "route", from, to, deviceIds, groupIds);
- return Route.getObjects(getUserId(), deviceIds, groupIds, from, to);
+ return routeReportProvider.getObjects(getUserId(), deviceIds, groupIds, from, to);
}
@Path("route")
@@ -115,7 +131,7 @@ public class ReportResource extends BaseResource {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
return executeReport(getUserId(), mail, stream -> {
LogAction.logReport(getUserId(), "route", from, to, deviceIds, groupIds);
- Route.getExcel(stream, getUserId(), deviceIds, groupIds, from, to);
+ routeReportProvider.getExcel(stream, getUserId(), deviceIds, groupIds, from, to);
});
}
@@ -127,7 +143,7 @@ public class ReportResource extends BaseResource {
@QueryParam("from") Date from, @QueryParam("to") Date to) throws StorageException {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
LogAction.logReport(getUserId(), "events", from, to, deviceIds, groupIds);
- return Events.getObjects(storage, getUserId(), deviceIds, groupIds, types, from, to);
+ return eventsReportProvider.getObjects(storage, getUserId(), deviceIds, groupIds, types, from, to);
}
@Path("events")
@@ -141,7 +157,7 @@ public class ReportResource extends BaseResource {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
return executeReport(getUserId(), mail, stream -> {
LogAction.logReport(getUserId(), "events", from, to, deviceIds, groupIds);
- Events.getExcel(stream, storage, getUserId(), deviceIds, groupIds, types, from, to);
+ eventsReportProvider.getExcel(stream, storage, getUserId(), deviceIds, groupIds, types, from, to);
});
}
@@ -153,7 +169,7 @@ public class ReportResource extends BaseResource {
throws StorageException {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
LogAction.logReport(getUserId(), "summary", from, to, deviceIds, groupIds);
- return Summary.getObjects(getUserId(), deviceIds, groupIds, from, to, daily);
+ return summaryReportProvider.getObjects(getUserId(), deviceIds, groupIds, from, to, daily);
}
@Path("summary")
@@ -167,7 +183,7 @@ public class ReportResource extends BaseResource {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
return executeReport(getUserId(), mail, stream -> {
LogAction.logReport(getUserId(), "summary", from, to, deviceIds, groupIds);
- Summary.getExcel(stream, getUserId(), deviceIds, groupIds, from, to, daily);
+ summaryReportProvider.getExcel(stream, getUserId(), deviceIds, groupIds, from, to, daily);
});
}
@@ -179,7 +195,7 @@ public class ReportResource extends BaseResource {
@QueryParam("from") Date from, @QueryParam("to") Date to) throws StorageException {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
LogAction.logReport(getUserId(), "trips", from, to, deviceIds, groupIds);
- return Trips.getObjects(getUserId(), deviceIds, groupIds, from, to);
+ return tripsReportProvider.getObjects(getUserId(), deviceIds, groupIds, from, to);
}
@Path("trips")
@@ -192,7 +208,7 @@ public class ReportResource extends BaseResource {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
return executeReport(getUserId(), mail, stream -> {
LogAction.logReport(getUserId(), "trips", from, to, deviceIds, groupIds);
- Trips.getExcel(stream, getUserId(), deviceIds, groupIds, from, to);
+ tripsReportProvider.getExcel(stream, getUserId(), deviceIds, groupIds, from, to);
});
}
@@ -204,7 +220,7 @@ public class ReportResource extends BaseResource {
@QueryParam("from") Date from, @QueryParam("to") Date to) throws StorageException {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
LogAction.logReport(getUserId(), "stops", from, to, deviceIds, groupIds);
- return Stops.getObjects(getUserId(), deviceIds, groupIds, from, to);
+ return stopsReportProvider.getObjects(getUserId(), deviceIds, groupIds, from, to);
}
@Path("stops")
@@ -217,7 +233,7 @@ public class ReportResource extends BaseResource {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
return executeReport(getUserId(), mail, stream -> {
LogAction.logReport(getUserId(), "stops", from, to, deviceIds, groupIds);
- Stops.getExcel(stream, getUserId(), deviceIds, groupIds, from, to);
+ stopsReportProvider.getExcel(stream, getUserId(), deviceIds, groupIds, from, to);
});
}
diff --git a/src/main/java/org/traccar/reports/Events.java b/src/main/java/org/traccar/reports/EventsReportProvider.java
index 130fba724..c4b0aad86 100644
--- a/src/main/java/org/traccar/reports/Events.java
+++ b/src/main/java/org/traccar/reports/EventsReportProvider.java
@@ -38,12 +38,9 @@ import org.traccar.reports.model.DeviceReportSection;
import org.traccar.storage.Storage;
import org.traccar.storage.StorageException;
-public final class Events {
+public class EventsReportProvider {
- private Events() {
- }
-
- public static Collection<Event> getObjects(
+ public Collection<Event> getObjects(
Storage storage, long userId,
Collection<Long> deviceIds, Collection<Long> groupIds,
Collection<String> types, Date from, Date to) throws StorageException {
@@ -68,7 +65,7 @@ public final class Events {
return result;
}
- public static void getExcel(
+ public void getExcel(
OutputStream outputStream, Storage storage, long userId,
Collection<Long> deviceIds, Collection<Long> groupIds,
Collection<String> types, Date from, Date to) throws StorageException, IOException {
diff --git a/src/main/java/org/traccar/reports/Route.java b/src/main/java/org/traccar/reports/RouteReportProvider.java
index 5b8629aad..4c4a41405 100644
--- a/src/main/java/org/traccar/reports/Route.java
+++ b/src/main/java/org/traccar/reports/RouteReportProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2022 Anton Tananaev (anton@traccar.org)
* Copyright 2016 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -33,12 +33,9 @@ import org.traccar.reports.common.ReportUtils;
import org.traccar.reports.model.DeviceReportSection;
import org.traccar.storage.StorageException;
-public final class Route {
+public class RouteReportProvider {
- private Route() {
- }
-
- public static Collection<Position> getObjects(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
+ public Collection<Position> getObjects(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to) throws StorageException {
ReportUtils.checkPeriodLimit(from, to);
ArrayList<Position> result = new ArrayList<>();
@@ -49,7 +46,7 @@ public final class Route {
return result;
}
- public static void getExcel(OutputStream outputStream,
+ public void getExcel(OutputStream outputStream,
long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to) throws StorageException, IOException {
ReportUtils.checkPeriodLimit(from, to);
diff --git a/src/main/java/org/traccar/reports/Stops.java b/src/main/java/org/traccar/reports/StopsReportProvider.java
index e688d53da..8dedb9a24 100644
--- a/src/main/java/org/traccar/reports/Stops.java
+++ b/src/main/java/org/traccar/reports/StopsReportProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2022 Anton Tananaev (anton@traccar.org)
* Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -37,12 +37,9 @@ import org.traccar.reports.model.DeviceReportSection;
import org.traccar.reports.model.StopReportItem;
import org.traccar.storage.StorageException;
-public final class Stops {
+public class StopsReportProvider {
- private Stops() {
- }
-
- private static Collection<StopReportItem> detectStops(long deviceId, Date from, Date to) throws StorageException {
+ private Collection<StopReportItem> detectStops(long deviceId, Date from, Date to) throws StorageException {
boolean ignoreOdometer = Context.getDeviceManager()
.lookupAttributeBoolean(deviceId, "report.ignoreOdometer", false, false, true);
@@ -54,7 +51,7 @@ public final class Stops {
Context.getTripsConfig(), ignoreOdometer, StopReportItem.class);
}
- public static Collection<StopReportItem> getObjects(
+ public Collection<StopReportItem> getObjects(
long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to) throws StorageException {
ReportUtils.checkPeriodLimit(from, to);
@@ -66,7 +63,7 @@ public final class Stops {
return result;
}
- public static void getExcel(
+ public void getExcel(
OutputStream outputStream, long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to) throws StorageException, IOException {
ReportUtils.checkPeriodLimit(from, to);
diff --git a/src/main/java/org/traccar/reports/Summary.java b/src/main/java/org/traccar/reports/SummaryReportProvider.java
index 30c4cb057..a2306f3d1 100644
--- a/src/main/java/org/traccar/reports/Summary.java
+++ b/src/main/java/org/traccar/reports/SummaryReportProvider.java
@@ -33,12 +33,9 @@ import org.traccar.reports.common.ReportUtils;
import org.traccar.reports.model.SummaryReportItem;
import org.traccar.storage.StorageException;
-public final class Summary {
+public class SummaryReportProvider {
- private Summary() {
- }
-
- private static SummaryReportItem calculateSummaryResult(long deviceId, Collection<Position> positions) {
+ private SummaryReportItem calculateSummaryResult(long deviceId, Collection<Position> positions) {
SummaryReportItem result = new SummaryReportItem();
result.setDeviceId(deviceId);
result.setDeviceName(Context.getIdentityManager().getById(deviceId).getName());
@@ -91,13 +88,13 @@ public final class Summary {
return result;
}
- private static int getDay(long userId, Date date) {
+ private int getDay(long userId, Date date) {
Calendar calendar = Calendar.getInstance(ReportUtils.getTimezone(userId));
calendar.setTime(date);
return calendar.get(Calendar.DAY_OF_MONTH);
}
- private static Collection<SummaryReportItem> calculateSummaryResults(
+ 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));
@@ -122,8 +119,9 @@ public final class Summary {
return results;
}
- public static Collection<SummaryReportItem> getObjects(long userId, Collection<Long> deviceIds,
- Collection<Long> groupIds, Date from, Date to, boolean daily) throws StorageException {
+ public Collection<SummaryReportItem> getObjects(
+ long userId, Collection<Long> deviceIds,
+ Collection<Long> groupIds, Date from, Date to, boolean daily) throws StorageException {
ReportUtils.checkPeriodLimit(from, to);
ArrayList<SummaryReportItem> result = new ArrayList<>();
for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
@@ -138,7 +136,7 @@ public final class Summary {
return result;
}
- public static void getExcel(OutputStream outputStream,
+ public void getExcel(OutputStream outputStream,
long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to, boolean daily) throws StorageException, IOException {
ReportUtils.checkPeriodLimit(from, to);
diff --git a/src/main/java/org/traccar/reports/Trips.java b/src/main/java/org/traccar/reports/TripsReportProvider.java
index 74e24cf2f..6aff08a1d 100644
--- a/src/main/java/org/traccar/reports/Trips.java
+++ b/src/main/java/org/traccar/reports/TripsReportProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2022 Anton Tananaev (anton@traccar.org)
* Copyright 2016 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -36,12 +36,9 @@ import org.traccar.reports.model.DeviceReportSection;
import org.traccar.reports.model.TripReportItem;
import org.traccar.storage.StorageException;
-public final class Trips {
+public class TripsReportProvider {
- private Trips() {
- }
-
- private static Collection<TripReportItem> detectTrips(long deviceId, Date from, Date to) throws StorageException {
+ private Collection<TripReportItem> detectTrips(long deviceId, Date from, Date to) throws StorageException {
boolean ignoreOdometer = Context.getDeviceManager()
.lookupAttributeBoolean(deviceId, "report.ignoreOdometer", false, false, true);
@@ -53,7 +50,7 @@ public final class Trips {
Context.getTripsConfig(), ignoreOdometer, TripReportItem.class);
}
- public static Collection<TripReportItem> getObjects(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
+ public Collection<TripReportItem> getObjects(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to) throws StorageException {
ReportUtils.checkPeriodLimit(from, to);
ArrayList<TripReportItem> result = new ArrayList<>();
@@ -64,7 +61,7 @@ public final class Trips {
return result;
}
- public static void getExcel(OutputStream outputStream,
+ public void getExcel(OutputStream outputStream,
long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to) throws StorageException, IOException {
ReportUtils.checkPeriodLimit(from, to);