From 975d2850e245c880e9105b68746cb535ea09fa90 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 15 Mar 2017 16:56:55 +0500 Subject: Use timezone from preferences for excel reports --- src/org/traccar/api/resource/ReportResource.java | 8 ++++---- src/org/traccar/helper/DateUtil.java | 6 ------ src/org/traccar/reports/Events.java | 12 ++++++++---- src/org/traccar/reports/Route.java | 12 ++++++++---- src/org/traccar/reports/Summary.java | 12 ++++++++---- src/org/traccar/reports/Trips.java | 12 ++++++++---- 6 files changed, 36 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/org/traccar/api/resource/ReportResource.java b/src/org/traccar/api/resource/ReportResource.java index a1b35d64e..a0f686e80 100644 --- a/src/org/traccar/api/resource/ReportResource.java +++ b/src/org/traccar/api/resource/ReportResource.java @@ -51,7 +51,7 @@ public class ReportResource extends BaseResource { @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException, IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); Route.getExcel(stream, getUserId(), deviceIds, groupIds, - DateUtil.parseDateTime(from), DateUtil.parseDateTime(to)); + DateUtil.parseDate(from), DateUtil.parseDate(to)); return Response.ok(stream.toByteArray()) .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build(); @@ -76,7 +76,7 @@ public class ReportResource extends BaseResource { @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException, IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); Events.getExcel(stream, getUserId(), deviceIds, groupIds, types, - DateUtil.parseDateTime(from), DateUtil.parseDateTime(to)); + DateUtil.parseDate(from), DateUtil.parseDate(to)); return Response.ok(stream.toByteArray()) .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build(); @@ -99,7 +99,7 @@ public class ReportResource extends BaseResource { @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException, IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); Summary.getExcel(stream, getUserId(), deviceIds, groupIds, - DateUtil.parseDateTime(from), DateUtil.parseDateTime(to)); + DateUtil.parseDate(from), DateUtil.parseDate(to)); return Response.ok(stream.toByteArray()) .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build(); @@ -123,7 +123,7 @@ public class ReportResource extends BaseResource { @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException, IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); Trips.getExcel(stream, getUserId(), deviceIds, groupIds, - DateUtil.parseDateTime(from), DateUtil.parseDateTime(to)); + DateUtil.parseDate(from), DateUtil.parseDate(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 de36d4420..30bb1b2fa 100644 --- a/src/org/traccar/helper/DateUtil.java +++ b/src/org/traccar/helper/DateUtil.java @@ -18,7 +18,6 @@ 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; @@ -64,9 +63,4 @@ public final class DateUtil { public static Date parseDate(String value) { return DATE_FORMAT.parseDateTime(value).toDate(); } - - public static DateTime parseDateTime(String value) { - return DATE_FORMAT.withOffsetParsed().parseDateTime(value); - } - } diff --git a/src/org/traccar/reports/Events.java b/src/org/traccar/reports/Events.java index d2255684f..e5acd28f9 100644 --- a/src/org/traccar/reports/Events.java +++ b/src/org/traccar/reports/Events.java @@ -27,9 +27,10 @@ import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Locale; import org.apache.poi.ss.util.WorkbookUtil; -import org.joda.time.DateTime; +import org.apache.velocity.tools.generic.DateTool; import org.jxls.area.Area; import org.jxls.builder.xls.XlsCommentAreaBuilder; import org.jxls.common.CellRef; @@ -70,13 +71,13 @@ public final class Events { public static void getExcel(OutputStream outputStream, long userId, Collection deviceIds, Collection groupIds, - Collection types, DateTime from, DateTime to) throws SQLException, IOException { + Collection types, Date from, Date to) throws SQLException, IOException { ArrayList devicesEvents = new ArrayList<>(); ArrayList sheetNames = new ArrayList<>(); HashMap geofenceNames = new HashMap<>(); for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) { Context.getPermissionsManager().checkDevice(userId, deviceId); - Collection events = Context.getDataManager().getEvents(deviceId, from.toDate(), to.toDate()); + Collection events = Context.getDataManager().getEvents(deviceId, from, to); boolean all = types.isEmpty() || types.contains(Event.ALL_EVENTS); for (Iterator iterator = events.iterator(); iterator.hasNext();) { Event event = iterator.next(); @@ -120,7 +121,10 @@ 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("webUrl", Context.getVelocityEngine().getProperty("web.url")); + jxlsContext.putVar("dateTool", new DateTool()); + jxlsContext.putVar("timezone", ReportUtils.getTimezone(userId)); + jxlsContext.putVar("locale", Locale.getDefault()); 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 c1acaf322..932501a89 100644 --- a/src/org/traccar/reports/Route.java +++ b/src/org/traccar/reports/Route.java @@ -25,9 +25,10 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.List; +import java.util.Locale; import org.apache.poi.ss.util.WorkbookUtil; -import org.joda.time.DateTime; +import org.apache.velocity.tools.generic.DateTool; import org.jxls.area.Area; import org.jxls.builder.xls.XlsCommentAreaBuilder; import org.jxls.common.CellRef; @@ -58,13 +59,13 @@ public final class Route { public static void getExcel(OutputStream outputStream, long userId, Collection deviceIds, Collection groupIds, - DateTime from, DateTime to) throws SQLException, IOException { + Date from, Date to) throws SQLException, IOException { ArrayList devicesRoutes = new ArrayList<>(); ArrayList sheetNames = new ArrayList<>(); for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) { Context.getPermissionsManager().checkDevice(userId, deviceId); Collection positions = Context.getDataManager() - .getPositions(deviceId, from.toDate(), to.toDate()); + .getPositions(deviceId, from, to); DeviceReport deviceRoutes = new DeviceReport(); Device device = Context.getIdentityManager().getDeviceById(deviceId); deviceRoutes.setDeviceName(device.getName()); @@ -88,7 +89,10 @@ 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("webUrl", Context.getVelocityEngine().getProperty("web.url")); + jxlsContext.putVar("dateTool", new DateTool()); + jxlsContext.putVar("timezone", ReportUtils.getTimezone(userId)); + jxlsContext.putVar("locale", Locale.getDefault()); 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 cacb4d1d6..543392e05 100644 --- a/src/org/traccar/reports/Summary.java +++ b/src/org/traccar/reports/Summary.java @@ -24,8 +24,9 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import java.util.Date; +import java.util.Locale; -import org.joda.time.DateTime; +import org.apache.velocity.tools.generic.DateTool; import org.jxls.transform.poi.PoiTransformer; import org.jxls.util.JxlsHelper; import org.traccar.Context; @@ -79,8 +80,8 @@ public final class Summary { public static void getExcel(OutputStream outputStream, long userId, Collection deviceIds, Collection groupIds, - DateTime from, DateTime to) throws SQLException, IOException { - Collection summaries = getObjects(userId, deviceIds, groupIds, from.toDate(), to.toDate()); + Date from, Date to) throws SQLException, IOException { + Collection summaries = getObjects(userId, deviceIds, groupIds, from, to); String templatePath = Context.getConfig().getString("report.templatesPath", "templates/export/"); try (InputStream inputStream = new FileInputStream(templatePath + "/summary.xlsx")) { @@ -90,7 +91,10 @@ 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()); + jxlsContext.putVar("webUrl", Context.getVelocityEngine().getProperty("web.url")); + jxlsContext.putVar("dateTool", new DateTool()); + jxlsContext.putVar("timezone", ReportUtils.getTimezone(userId)); + jxlsContext.putVar("locale", Locale.getDefault()); 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 45b52b63c..4b688688d 100644 --- a/src/org/traccar/reports/Trips.java +++ b/src/org/traccar/reports/Trips.java @@ -25,9 +25,10 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.List; +import java.util.Locale; import org.apache.poi.ss.util.WorkbookUtil; -import org.joda.time.DateTime; +import org.apache.velocity.tools.generic.DateTool; import org.jxls.area.Area; import org.jxls.builder.xls.XlsCommentAreaBuilder; import org.jxls.common.CellRef; @@ -193,12 +194,12 @@ public final class Trips { public static void getExcel(OutputStream outputStream, long userId, Collection deviceIds, Collection groupIds, - DateTime from, DateTime to) throws SQLException, IOException { + Date from, Date to) throws SQLException, IOException { ArrayList devicesTrips = new ArrayList<>(); ArrayList sheetNames = new ArrayList<>(); for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) { Context.getPermissionsManager().checkDevice(userId, deviceId); - Collection trips = detectTrips(deviceId, from.toDate(), to.toDate()); + Collection trips = detectTrips(deviceId, from, to); DeviceReport deviceTrips = new DeviceReport(); Device device = Context.getIdentityManager().getDeviceById(deviceId); deviceTrips.setDeviceName(device.getName()); @@ -222,7 +223,10 @@ 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()); + jxlsContext.putVar("webUrl", Context.getVelocityEngine().getProperty("web.url")); + jxlsContext.putVar("dateTool", new DateTool()); + jxlsContext.putVar("timezone", ReportUtils.getTimezone(userId)); + jxlsContext.putVar("locale", Locale.getDefault()); Transformer transformer = TransformerFactory.createTransformer(inputStream, outputStream); List xlsAreas = new XlsCommentAreaBuilder(transformer).build(); for (Area xlsArea : xlsAreas) { -- cgit v1.2.3