aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/reports
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2016-11-01 10:35:31 +0500
committerAbyss777 <abyss@fox5.ru>2016-11-01 10:35:31 +0500
commit1ea8569eb87a714d6b2e2b817d05190dd3784384 (patch)
tree81c7a40ec551810fb97689fac65eeb57ae353eab /src/org/traccar/reports
parent12ddac1b181692a1e32a1a26e9189ab3091dd4bc (diff)
downloadtraccar-server-1ea8569eb87a714d6b2e2b817d05190dd3784384.tar.gz
traccar-server-1ea8569eb87a714d6b2e2b817d05190dd3784384.tar.bz2
traccar-server-1ea8569eb87a714d6b2e2b817d05190dd3784384.zip
Remove json conversion in reports
Diffstat (limited to 'src/org/traccar/reports')
-rw-r--r--src/org/traccar/reports/Events.java12
-rw-r--r--src/org/traccar/reports/Route.java14
-rw-r--r--src/org/traccar/reports/Summary.java20
-rw-r--r--src/org/traccar/reports/Trips.java14
4 files changed, 18 insertions, 42 deletions
diff --git a/src/org/traccar/reports/Events.java b/src/org/traccar/reports/Events.java
index 77d995f56..88ff687d8 100644
--- a/src/org/traccar/reports/Events.java
+++ b/src/org/traccar/reports/Events.java
@@ -28,9 +28,6 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import javax.json.Json;
-import javax.json.JsonArrayBuilder;
-
import org.jxls.area.Area;
import org.jxls.builder.xls.XlsCommentAreaBuilder;
import org.jxls.common.CellRef;
@@ -44,16 +41,15 @@ import org.traccar.model.Event;
import org.traccar.model.Geofence;
import org.traccar.model.Group;
import org.traccar.reports.model.DeviceReport;
-import org.traccar.web.JsonConverter;
public final class Events {
private Events() {
}
- public static String getJson(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
+ public static Collection<Event> getObjects(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Collection<String> types, Date from, Date to) throws SQLException {
- JsonArrayBuilder json = Json.createArrayBuilder();
+ ArrayList<Event> result = new ArrayList<>();
for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
Collection<Event> events = Context.getDataManager().getEvents(deviceId, from, to);
@@ -62,12 +58,12 @@ public final class Events {
if (all || types.contains(event.getType())) {
long geofenceId = event.getGeofenceId();
if (geofenceId == 0 || Context.getGeofenceManager().checkGeofence(userId, geofenceId)) {
- json.add(JsonConverter.objectToJson(event));
+ result.add(event);
}
}
}
}
- return json.build().toString();
+ return result;
}
public static void getExcel(OutputStream outputStream,
diff --git a/src/org/traccar/reports/Route.java b/src/org/traccar/reports/Route.java
index 6992c89cc..4226d05ef 100644
--- a/src/org/traccar/reports/Route.java
+++ b/src/org/traccar/reports/Route.java
@@ -26,9 +26,6 @@ import java.util.Collection;
import java.util.Date;
import java.util.List;
-import javax.json.Json;
-import javax.json.JsonArrayBuilder;
-
import org.jxls.area.Area;
import org.jxls.builder.xls.XlsCommentAreaBuilder;
import org.jxls.common.CellRef;
@@ -41,23 +38,20 @@ import org.traccar.model.Device;
import org.traccar.model.Group;
import org.traccar.model.Position;
import org.traccar.reports.model.DeviceReport;
-import org.traccar.web.JsonConverter;
public final class Route {
private Route() {
}
- public static String getJson(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
+ public static Collection<Position> getObjects(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to) throws SQLException {
- JsonArrayBuilder json = Json.createArrayBuilder();
+ ArrayList<Position> result = new ArrayList<>();
for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
- for (Position position : Context.getDataManager().getPositions(deviceId, from, to)) {
- json.add(JsonConverter.objectToJson(position));
- }
+ result.addAll(Context.getDataManager().getPositions(deviceId, from, to));
}
- return json.build().toString();
+ return result;
}
public static void getExcel(OutputStream outputStream,
diff --git a/src/org/traccar/reports/Summary.java b/src/org/traccar/reports/Summary.java
index 14f8b7839..a82624bcf 100644
--- a/src/org/traccar/reports/Summary.java
+++ b/src/org/traccar/reports/Summary.java
@@ -25,15 +25,11 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
-import javax.json.Json;
-import javax.json.JsonArrayBuilder;
-
import org.jxls.transform.poi.PoiTransformer;
import org.jxls.util.JxlsHelper;
import org.traccar.Context;
import org.traccar.model.Position;
import org.traccar.reports.model.SummaryReport;
-import org.traccar.web.JsonConverter;
public final class Summary {
@@ -74,24 +70,20 @@ public final class Summary {
return result;
}
- public static String getJson(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
- Date from, Date to) throws SQLException {
- JsonArrayBuilder json = Json.createArrayBuilder();
+ public static Collection<SummaryReport> getObjects(long userId, Collection<Long> deviceIds,
+ Collection<Long> groupIds, Date from, Date to) throws SQLException {
+ ArrayList<SummaryReport> result = new ArrayList<>();
for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
- json.add(JsonConverter.objectToJson(calculateSummaryResult(deviceId, from, to)));
+ result.add(calculateSummaryResult(deviceId, from, to));
}
- return json.build().toString();
+ return result;
}
public static void getExcel(OutputStream outputStream,
long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to) throws SQLException, IOException {
- ArrayList<SummaryReport> summaries = new ArrayList<>();
- for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
- Context.getPermissionsManager().checkDevice(userId, deviceId);
- summaries.add(calculateSummaryResult(deviceId, from, to));
- }
+ Collection<SummaryReport> summaries = getObjects(userId, deviceIds, groupIds, from, to);
String templatePath = Context.getConfig().getString("report.templatesPath",
"templates/export/");
try (InputStream inputStream = new FileInputStream(templatePath + "/summary.xlsx")) {
diff --git a/src/org/traccar/reports/Trips.java b/src/org/traccar/reports/Trips.java
index 705644849..30fef40c9 100644
--- a/src/org/traccar/reports/Trips.java
+++ b/src/org/traccar/reports/Trips.java
@@ -26,9 +26,6 @@ import java.util.Collection;
import java.util.Date;
import java.util.List;
-import javax.json.Json;
-import javax.json.JsonArrayBuilder;
-
import org.jxls.area.Area;
import org.jxls.builder.xls.XlsCommentAreaBuilder;
import org.jxls.common.CellRef;
@@ -42,7 +39,6 @@ import org.traccar.model.Group;
import org.traccar.model.Position;
import org.traccar.reports.model.DeviceReport;
import org.traccar.reports.model.TripReport;
-import org.traccar.web.JsonConverter;
public final class Trips {
@@ -167,16 +163,14 @@ public final class Trips {
return result;
}
- public static String getJson(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
+ public static Collection<TripReport> getObjects(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to) throws SQLException {
- JsonArrayBuilder json = Json.createArrayBuilder();
+ ArrayList<TripReport> result = new ArrayList<>();
for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
- for (TripReport tripReport : detectTrips(deviceId, from, to)) {
- json.add(JsonConverter.objectToJson(tripReport));
- }
+ result.addAll(detectTrips(deviceId, from, to));
}
- return json.build().toString();
+ return result;
}
public static void getExcel(OutputStream outputStream,