aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-08-01 16:14:15 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2017-08-01 16:14:15 +1200
commitbf8a7aac4921d17c086e6d35e44a1bc2e37888b8 (patch)
tree166787aa64665c8699c16b17382ae1ec68035bea /src/org
parentb65dd20c5e8c7fc9b26cb27154394d2afdbd5316 (diff)
downloadtraccar-server-bf8a7aac4921d17c086e6d35e44a1bc2e37888b8.tar.gz
traccar-server-bf8a7aac4921d17c086e6d35e44a1bc2e37888b8.tar.bz2
traccar-server-bf8a7aac4921d17c086e6d35e44a1bc2e37888b8.zip
Option to limit report period
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/reports/Events.java2
-rw-r--r--src/org/traccar/reports/ReportUtils.java8
-rw-r--r--src/org/traccar/reports/Route.java2
-rw-r--r--src/org/traccar/reports/Stops.java9
-rw-r--r--src/org/traccar/reports/Summary.java2
-rw-r--r--src/org/traccar/reports/Trips.java2
6 files changed, 22 insertions, 3 deletions
diff --git a/src/org/traccar/reports/Events.java b/src/org/traccar/reports/Events.java
index 63077de32..a13aeeeb4 100644
--- a/src/org/traccar/reports/Events.java
+++ b/src/org/traccar/reports/Events.java
@@ -42,6 +42,7 @@ public final class Events {
public static Collection<Event> getObjects(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Collection<String> types, Date from, Date to) throws SQLException {
+ ReportUtils.checkPeriodLimit(from, to);
ArrayList<Event> result = new ArrayList<>();
for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
@@ -62,6 +63,7 @@ public final class Events {
public static void getExcel(OutputStream outputStream,
long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Collection<String> types, Date from, Date to) throws SQLException, IOException {
+ ReportUtils.checkPeriodLimit(from, to);
ArrayList<DeviceReport> devicesEvents = new ArrayList<>();
ArrayList<String> sheetNames = new ArrayList<>();
HashMap<Long, String> geofenceNames = new HashMap<>();
diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java
index cf94030ab..540feb6c6 100644
--- a/src/org/traccar/reports/ReportUtils.java
+++ b/src/org/traccar/reports/ReportUtils.java
@@ -40,6 +40,7 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
@@ -49,6 +50,13 @@ public final class ReportUtils {
private ReportUtils() {
}
+ public static void checkPeriodLimit(Date from, Date to) {
+ long limit = Context.getConfig().getLong("report.periodLimit") * 1000;
+ if (limit > 0 && to.getTime() - from.getTime() > limit) {
+ throw new IllegalArgumentException("Time period exceeds the limit");
+ }
+ }
+
public static String getDistanceUnit(long userId) {
return (String) Context.getPermissionsManager().lookupPreference(userId, "distanceUnit", "km");
}
diff --git a/src/org/traccar/reports/Route.java b/src/org/traccar/reports/Route.java
index 1c53a15cc..6adb00aae 100644
--- a/src/org/traccar/reports/Route.java
+++ b/src/org/traccar/reports/Route.java
@@ -39,6 +39,7 @@ public final class Route {
public static Collection<Position> getObjects(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to) throws SQLException {
+ ReportUtils.checkPeriodLimit(from, to);
ArrayList<Position> result = new ArrayList<>();
for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
@@ -50,6 +51,7 @@ public final class Route {
public static void getExcel(OutputStream outputStream,
long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to) throws SQLException, IOException {
+ ReportUtils.checkPeriodLimit(from, to);
ArrayList<DeviceReport> devicesRoutes = new ArrayList<>();
ArrayList<String> sheetNames = new ArrayList<>();
for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
diff --git a/src/org/traccar/reports/Stops.java b/src/org/traccar/reports/Stops.java
index 886fd7915..ee6746e4e 100644
--- a/src/org/traccar/reports/Stops.java
+++ b/src/org/traccar/reports/Stops.java
@@ -55,8 +55,10 @@ public final class Stops {
return (Collection<StopReport>) result;
}
- public static Collection<StopReport> getObjects(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
+ public static Collection<StopReport> getObjects(
+ long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to) throws SQLException {
+ ReportUtils.checkPeriodLimit(from, to);
ArrayList<StopReport> result = new ArrayList<>();
for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
@@ -65,9 +67,10 @@ public final class Stops {
return result;
}
- public static void getExcel(OutputStream outputStream,
- long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
+ public static void getExcel(
+ OutputStream outputStream, long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to) throws SQLException, IOException {
+ ReportUtils.checkPeriodLimit(from, to);
ArrayList<DeviceReport> devicesStops = new ArrayList<>();
ArrayList<String> sheetNames = new ArrayList<>();
for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
diff --git a/src/org/traccar/reports/Summary.java b/src/org/traccar/reports/Summary.java
index dd9877cd7..366e40421 100644
--- a/src/org/traccar/reports/Summary.java
+++ b/src/org/traccar/reports/Summary.java
@@ -68,6 +68,7 @@ public final class Summary {
public static Collection<SummaryReport> getObjects(long userId, Collection<Long> deviceIds,
Collection<Long> groupIds, Date from, Date to) throws SQLException {
+ ReportUtils.checkPeriodLimit(from, to);
ArrayList<SummaryReport> result = new ArrayList<>();
for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
@@ -79,6 +80,7 @@ public final class Summary {
public static void getExcel(OutputStream outputStream,
long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to) throws SQLException, IOException {
+ ReportUtils.checkPeriodLimit(from, to);
Collection<SummaryReport> summaries = getObjects(userId, deviceIds, groupIds, from, to);
String templatePath = Context.getConfig().getString("report.templatesPath",
"templates/export/");
diff --git a/src/org/traccar/reports/Trips.java b/src/org/traccar/reports/Trips.java
index 68b03a819..6b97507f4 100644
--- a/src/org/traccar/reports/Trips.java
+++ b/src/org/traccar/reports/Trips.java
@@ -56,6 +56,7 @@ public final class Trips {
public static Collection<TripReport> getObjects(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to) throws SQLException {
+ ReportUtils.checkPeriodLimit(from, to);
ArrayList<TripReport> result = new ArrayList<>();
for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
@@ -67,6 +68,7 @@ public final class Trips {
public static void getExcel(OutputStream outputStream,
long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to) throws SQLException, IOException {
+ ReportUtils.checkPeriodLimit(from, to);
ArrayList<DeviceReport> devicesTrips = new ArrayList<>();
ArrayList<String> sheetNames = new ArrayList<>();
for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {