From b14169a2b7bfcaecaa0f5ea9baafad4e7e4f1ae2 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 23 Nov 2016 11:41:11 +0500 Subject: - Pass client timezone to excel template - Templates: adjust timezone, use "https" in links --- src/org/traccar/api/resource/ReportResource.java | 12 ++++-------- src/org/traccar/helper/DateUtil.java | 6 ++++++ src/org/traccar/reports/Events.java | 9 +++++++-- src/org/traccar/reports/Route.java | 10 ++++++++-- src/org/traccar/reports/Summary.java | 9 +++++++-- src/org/traccar/reports/Trips.java | 9 +++++++-- templates/export/events.xlsx | Bin 12307 -> 12346 bytes templates/export/route.xlsx | Bin 12806 -> 13042 bytes templates/export/summary.xlsx | Bin 12330 -> 12315 bytes templates/export/trips.xlsx | Bin 13161 -> 13197 bytes 10 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/org/traccar/api/resource/ReportResource.java b/src/org/traccar/api/resource/ReportResource.java index 2717fe01e..e8e80fa2f 100644 --- a/src/org/traccar/api/resource/ReportResource.java +++ b/src/org/traccar/api/resource/ReportResource.java @@ -50,8 +50,7 @@ public class ReportResource extends BaseResource { @QueryParam("deviceId") final List deviceIds, @QueryParam("groupId") final List groupIds, @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException, IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); - Route.getExcel(stream, getUserId(), deviceIds, groupIds, - DateUtil.parseDate(from), DateUtil.parseDate(to)); + Route.getExcel(stream, getUserId(), deviceIds, groupIds, from, to); return Response.ok(stream.toByteArray()) .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build(); @@ -76,8 +75,7 @@ public class ReportResource extends BaseResource { @QueryParam("type") final List types, @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException, IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); - Events.getExcel(stream, getUserId(), deviceIds, groupIds, types, - DateUtil.parseDate(from), DateUtil.parseDate(to)); + Events.getExcel(stream, getUserId(), deviceIds, groupIds, types, from, to); return Response.ok(stream.toByteArray()) .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build(); @@ -100,8 +98,7 @@ public class ReportResource extends BaseResource { @QueryParam("deviceId") final List deviceIds, @QueryParam("groupId") final List groupIds, @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException, IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); - Summary.getExcel(stream, getUserId(), deviceIds, groupIds, - DateUtil.parseDate(from), DateUtil.parseDate(to)); + Summary.getExcel(stream, getUserId(), deviceIds, groupIds, from, to); return Response.ok(stream.toByteArray()) .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build(); @@ -124,8 +121,7 @@ public class ReportResource extends BaseResource { @QueryParam("deviceId") final List deviceIds, @QueryParam("groupId") final List groupIds, @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException, IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); - Trips.getExcel(stream, getUserId(), deviceIds, groupIds, - DateUtil.parseDate(from), DateUtil.parseDate(to)); + Trips.getExcel(stream, getUserId(), deviceIds, groupIds, from, to); return Response.ok(stream.toByteArray()) .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build(); diff --git a/src/org/traccar/helper/DateUtil.java b/src/org/traccar/helper/DateUtil.java index ad8534eb8..840f37a7a 100644 --- a/src/org/traccar/helper/DateUtil.java +++ b/src/org/traccar/helper/DateUtil.java @@ -18,12 +18,14 @@ package org.traccar.helper; import java.util.Calendar; import java.util.Date; +import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormatter; import org.joda.time.format.ISODateTimeFormat; public final class DateUtil { private static final DateTimeFormatter DATE_FORMAT = ISODateTimeFormat.dateTime(); + private static final DateTimeFormatter DATE_FORMAT_NOMILLIS = ISODateTimeFormat.dateTimeNoMillis(); private DateUtil() { } @@ -64,4 +66,8 @@ public final class DateUtil { return DATE_FORMAT.parseDateTime(value).toDate(); } + public static DateTime parseDateTime(String value) { + return DATE_FORMAT_NOMILLIS.withOffsetParsed().parseDateTime(value); + } + } diff --git a/src/org/traccar/reports/Events.java b/src/org/traccar/reports/Events.java index 9d82b97a5..ada1580d9 100644 --- a/src/org/traccar/reports/Events.java +++ b/src/org/traccar/reports/Events.java @@ -28,6 +28,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; +import org.joda.time.DateTime; import org.jxls.area.Area; import org.jxls.builder.xls.XlsCommentAreaBuilder; import org.jxls.common.CellRef; @@ -36,6 +37,7 @@ import org.jxls.transform.Transformer; import org.jxls.transform.poi.PoiTransformer; import org.jxls.util.TransformerFactory; import org.traccar.Context; +import org.traccar.helper.DateUtil; import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Geofence; @@ -68,13 +70,15 @@ public final class Events { public static void getExcel(OutputStream outputStream, long userId, Collection deviceIds, Collection groupIds, - Collection types, Date from, Date to) throws SQLException, IOException { + Collection types, String fromString, String toString) throws SQLException, IOException { ArrayList devicesEvents = new ArrayList<>(); ArrayList sheetNames = new ArrayList<>(); + DateTime from = DateUtil.parseDateTime(fromString); + DateTime to = DateUtil.parseDateTime(toString); HashMap geofenceNames = new HashMap<>(); for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) { Context.getPermissionsManager().checkDevice(userId, deviceId); - Collection events = Context.getDataManager().getEvents(deviceId, from, to); + Collection events = Context.getDataManager().getEvents(deviceId, from.toDate(), to.toDate()); boolean all = types.isEmpty() || types.contains(Event.ALL_EVENTS); for (Iterator iterator = events.iterator(); iterator.hasNext();) { Event event = iterator.next(); @@ -118,6 +122,7 @@ public final class Events { jxlsContext.putVar("to", to); jxlsContext.putVar("distanceUnit", ReportUtils.getDistanceUnit(userId)); jxlsContext.putVar("speedUnit", ReportUtils.getSpeedUnit(userId)); + jxlsContext.putVar("timezone", from.getZone()); jxlsContext.putVar("bracketsRegex", "[\\{\\}\"]"); Transformer transformer = TransformerFactory.createTransformer(inputStream, outputStream); List xlsAreas = new XlsCommentAreaBuilder(transformer).build(); diff --git a/src/org/traccar/reports/Route.java b/src/org/traccar/reports/Route.java index b29e04b2e..f438c8f4d 100644 --- a/src/org/traccar/reports/Route.java +++ b/src/org/traccar/reports/Route.java @@ -26,6 +26,7 @@ import java.util.Collection; import java.util.Date; import java.util.List; +import org.joda.time.DateTime; import org.jxls.area.Area; import org.jxls.builder.xls.XlsCommentAreaBuilder; import org.jxls.common.CellRef; @@ -34,6 +35,7 @@ import org.jxls.transform.Transformer; import org.jxls.transform.poi.PoiTransformer; import org.jxls.util.TransformerFactory; import org.traccar.Context; +import org.traccar.helper.DateUtil; import org.traccar.model.Device; import org.traccar.model.Group; import org.traccar.model.Position; @@ -56,12 +58,15 @@ public final class Route { public static void getExcel(OutputStream outputStream, long userId, Collection deviceIds, Collection groupIds, - Date from, Date to) throws SQLException, IOException { + String fromString, String toString) throws SQLException, IOException { ArrayList devicesRoutes = new ArrayList<>(); ArrayList sheetNames = new ArrayList<>(); + DateTime from = DateUtil.parseDateTime(fromString); + DateTime to = DateUtil.parseDateTime(toString); for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) { Context.getPermissionsManager().checkDevice(userId, deviceId); - Collection positions = Context.getDataManager().getPositions(deviceId, from, to); + Collection positions = Context.getDataManager() + .getPositions(deviceId, from.toDate(), to.toDate()); DeviceReport deviceRoutes = new DeviceReport(); Device device = Context.getIdentityManager().getDeviceById(deviceId); deviceRoutes.setDeviceName(device.getName()); @@ -85,6 +90,7 @@ public final class Route { jxlsContext.putVar("to", to); jxlsContext.putVar("distanceUnit", ReportUtils.getDistanceUnit(userId)); jxlsContext.putVar("speedUnit", ReportUtils.getSpeedUnit(userId)); + jxlsContext.putVar("timezone", from.getZone()); jxlsContext.putVar("bracketsRegex", "[\\{\\}\"]"); Transformer transformer = TransformerFactory.createTransformer(inputStream, outputStream); List xlsAreas = new XlsCommentAreaBuilder(transformer).build(); diff --git a/src/org/traccar/reports/Summary.java b/src/org/traccar/reports/Summary.java index 95a3737a1..d7d8ab417 100644 --- a/src/org/traccar/reports/Summary.java +++ b/src/org/traccar/reports/Summary.java @@ -25,9 +25,11 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Date; +import org.joda.time.DateTime; import org.jxls.transform.poi.PoiTransformer; import org.jxls.util.JxlsHelper; import org.traccar.Context; +import org.traccar.helper.DateUtil; import org.traccar.model.Position; import org.traccar.reports.model.SummaryReport; @@ -82,8 +84,10 @@ public final class Summary { public static void getExcel(OutputStream outputStream, long userId, Collection deviceIds, Collection groupIds, - Date from, Date to) throws SQLException, IOException { - Collection summaries = getObjects(userId, deviceIds, groupIds, from, to); + String fromString, String toString) throws SQLException, IOException { + DateTime from = DateUtil.parseDateTime(fromString); + DateTime to = DateUtil.parseDateTime(toString); + Collection summaries = getObjects(userId, deviceIds, groupIds, from.toDate(), to.toDate()); String templatePath = Context.getConfig().getString("report.templatesPath", "templates/export/"); try (InputStream inputStream = new FileInputStream(templatePath + "/summary.xlsx")) { @@ -93,6 +97,7 @@ public final class Summary { jxlsContext.putVar("to", to); jxlsContext.putVar("distanceUnit", ReportUtils.getDistanceUnit(userId)); jxlsContext.putVar("speedUnit", ReportUtils.getSpeedUnit(userId)); + jxlsContext.putVar("timezone", from.getZone()); JxlsHelper.getInstance().setUseFastFormulaProcessor(false) .processTemplate(inputStream, outputStream, jxlsContext); } diff --git a/src/org/traccar/reports/Trips.java b/src/org/traccar/reports/Trips.java index 91a080d45..c31eaac83 100644 --- a/src/org/traccar/reports/Trips.java +++ b/src/org/traccar/reports/Trips.java @@ -26,6 +26,7 @@ import java.util.Collection; import java.util.Date; import java.util.List; +import org.joda.time.DateTime; import org.jxls.area.Area; import org.jxls.builder.xls.XlsCommentAreaBuilder; import org.jxls.common.CellRef; @@ -34,6 +35,7 @@ import org.jxls.transform.Transformer; import org.jxls.transform.poi.PoiTransformer; import org.jxls.util.TransformerFactory; import org.traccar.Context; +import org.traccar.helper.DateUtil; import org.traccar.model.Device; import org.traccar.model.Group; import org.traccar.model.Position; @@ -175,12 +177,14 @@ public final class Trips { public static void getExcel(OutputStream outputStream, long userId, Collection deviceIds, Collection groupIds, - Date from, Date to) throws SQLException, IOException { + String fromString, String toString) throws SQLException, IOException { ArrayList devicesTrips = new ArrayList<>(); ArrayList sheetNames = new ArrayList<>(); + DateTime from = DateUtil.parseDateTime(fromString); + DateTime to = DateUtil.parseDateTime(toString); for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) { Context.getPermissionsManager().checkDevice(userId, deviceId); - Collection trips = detectTrips(deviceId, from, to); + Collection trips = detectTrips(deviceId, from.toDate(), to.toDate()); DeviceReport deviceTrips = new DeviceReport(); Device device = Context.getIdentityManager().getDeviceById(deviceId); deviceTrips.setDeviceName(device.getName()); @@ -204,6 +208,7 @@ public final class Trips { jxlsContext.putVar("to", to); jxlsContext.putVar("distanceUnit", ReportUtils.getDistanceUnit(userId)); jxlsContext.putVar("speedUnit", ReportUtils.getSpeedUnit(userId)); + jxlsContext.putVar("timezone", from.getZone()); Transformer transformer = TransformerFactory.createTransformer(inputStream, outputStream); List xlsAreas = new XlsCommentAreaBuilder(transformer).build(); for (Area xlsArea : xlsAreas) { diff --git a/templates/export/events.xlsx b/templates/export/events.xlsx index f0ff05a23..80a54fa57 100644 Binary files a/templates/export/events.xlsx and b/templates/export/events.xlsx differ diff --git a/templates/export/route.xlsx b/templates/export/route.xlsx index 24027523d..79a2649b7 100644 Binary files a/templates/export/route.xlsx and b/templates/export/route.xlsx differ diff --git a/templates/export/summary.xlsx b/templates/export/summary.xlsx index 88788f82a..53539ed8b 100644 Binary files a/templates/export/summary.xlsx and b/templates/export/summary.xlsx differ diff --git a/templates/export/trips.xlsx b/templates/export/trips.xlsx index 83d22678e..20130f44a 100644 Binary files a/templates/export/trips.xlsx and b/templates/export/trips.xlsx differ -- cgit v1.2.3