From 0bbf8f554638cdc89d5dd618c500839554602dee Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 24 Nov 2016 10:45:44 +0500 Subject: - Use one parser - Reverted passing variables way --- src/org/traccar/api/resource/ReportResource.java | 12 ++++++++---- src/org/traccar/helper/DateUtil.java | 5 ++--- src/org/traccar/reports/Events.java | 5 +---- src/org/traccar/reports/Route.java | 5 +---- src/org/traccar/reports/Summary.java | 5 +---- src/org/traccar/reports/Trips.java | 5 +---- 6 files changed, 14 insertions(+), 23 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/api/resource/ReportResource.java b/src/org/traccar/api/resource/ReportResource.java index e8e80fa2f..e37d6f01d 100644 --- a/src/org/traccar/api/resource/ReportResource.java +++ b/src/org/traccar/api/resource/ReportResource.java @@ -50,7 +50,8 @@ 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, from, to); + Route.getExcel(stream, getUserId(), deviceIds, groupIds, + DateUtil.parseDateTime(from), DateUtil.parseDateTime(to)); return Response.ok(stream.toByteArray()) .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build(); @@ -75,7 +76,8 @@ 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, from, to); + Events.getExcel(stream, getUserId(), deviceIds, groupIds, types, + DateUtil.parseDateTime(from), DateUtil.parseDateTime(to)); return Response.ok(stream.toByteArray()) .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build(); @@ -98,7 +100,8 @@ 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, from, to); + Summary.getExcel(stream, getUserId(), deviceIds, groupIds, + DateUtil.parseDateTime(from), DateUtil.parseDateTime(to)); return Response.ok(stream.toByteArray()) .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build(); @@ -121,7 +124,8 @@ 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, from, to); + Trips.getExcel(stream, getUserId(), deviceIds, groupIds, + DateUtil.parseDateTime(from), DateUtil.parseDateTime(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 840f37a7a..de36d4420 100644 --- a/src/org/traccar/helper/DateUtil.java +++ b/src/org/traccar/helper/DateUtil.java @@ -24,8 +24,7 @@ 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 static final DateTimeFormatter DATE_FORMAT = ISODateTimeFormat.dateTimeParser(); private DateUtil() { } @@ -67,7 +66,7 @@ public final class DateUtil { } public static DateTime parseDateTime(String value) { - return DATE_FORMAT_NOMILLIS.withOffsetParsed().parseDateTime(value); + return DATE_FORMAT.withOffsetParsed().parseDateTime(value); } } diff --git a/src/org/traccar/reports/Events.java b/src/org/traccar/reports/Events.java index ada1580d9..33893aad0 100644 --- a/src/org/traccar/reports/Events.java +++ b/src/org/traccar/reports/Events.java @@ -37,7 +37,6 @@ 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; @@ -70,11 +69,9 @@ public final class Events { public static void getExcel(OutputStream outputStream, long userId, Collection deviceIds, Collection groupIds, - Collection types, String fromString, String toString) throws SQLException, IOException { + Collection types, DateTime from, DateTime to) 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); diff --git a/src/org/traccar/reports/Route.java b/src/org/traccar/reports/Route.java index f438c8f4d..468771a48 100644 --- a/src/org/traccar/reports/Route.java +++ b/src/org/traccar/reports/Route.java @@ -35,7 +35,6 @@ 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; @@ -58,11 +57,9 @@ public final class Route { public static void getExcel(OutputStream outputStream, long userId, Collection deviceIds, Collection groupIds, - String fromString, String toString) throws SQLException, IOException { + DateTime from, DateTime to) 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() diff --git a/src/org/traccar/reports/Summary.java b/src/org/traccar/reports/Summary.java index d7d8ab417..02791fb5e 100644 --- a/src/org/traccar/reports/Summary.java +++ b/src/org/traccar/reports/Summary.java @@ -29,7 +29,6 @@ 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; @@ -84,9 +83,7 @@ public final class Summary { public static void getExcel(OutputStream outputStream, long userId, Collection deviceIds, Collection groupIds, - String fromString, String toString) throws SQLException, IOException { - DateTime from = DateUtil.parseDateTime(fromString); - DateTime to = DateUtil.parseDateTime(toString); + DateTime from, DateTime to) throws SQLException, IOException { Collection summaries = getObjects(userId, deviceIds, groupIds, from.toDate(), to.toDate()); 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 c31eaac83..1c2ba3fe3 100644 --- a/src/org/traccar/reports/Trips.java +++ b/src/org/traccar/reports/Trips.java @@ -35,7 +35,6 @@ 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; @@ -177,11 +176,9 @@ public final class Trips { public static void getExcel(OutputStream outputStream, long userId, Collection deviceIds, Collection groupIds, - String fromString, String toString) throws SQLException, IOException { + DateTime from, DateTime to) 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.toDate(), to.toDate()); -- cgit v1.2.3