From 03fe3c30a4b98cb93ca6e250a83a94d58d3106cb Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Mon, 10 Jan 2022 19:49:15 -0600 Subject: Added positions to events report --- src/main/java/org/traccar/reports/Events.java | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/traccar/reports/Events.java b/src/main/java/org/traccar/reports/Events.java index 66d9e708d..be4dbc6b1 100644 --- a/src/main/java/org/traccar/reports/Events.java +++ b/src/main/java/org/traccar/reports/Events.java @@ -26,6 +26,7 @@ import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.Iterator; +import java.util.Optional; import org.apache.poi.ss.util.WorkbookUtil; import org.traccar.Context; @@ -34,6 +35,7 @@ import org.traccar.model.Event; import org.traccar.model.Geofence; import org.traccar.model.Group; import org.traccar.model.Maintenance; +import org.traccar.model.Position; import org.traccar.reports.model.DeviceReport; public final class Events { @@ -72,15 +74,18 @@ public final class Events { ArrayList sheetNames = new ArrayList<>(); HashMap geofenceNames = new HashMap<>(); HashMap maintenanceNames = new HashMap<>(); + HashMap positionObjects = new HashMap<>(); for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) { Context.getPermissionsManager().checkDevice(userId, deviceId); Collection events = Context.getDataManager().getEvents(deviceId, from, to); + Collection positions = Context.getDataManager().getPositions(deviceId, from, to); boolean all = types.isEmpty() || types.contains(Event.ALL_EVENTS); for (Iterator iterator = events.iterator(); iterator.hasNext();) { Event event = iterator.next(); if (all || types.contains(event.getType())) { long geofenceId = event.getGeofenceId(); long maintenanceId = event.getMaintenanceId(); + long positionId = event.getPositionId(); if (geofenceId != 0) { if (Context.getGeofenceManager().checkItemPermission(userId, geofenceId)) { Geofence geofence = Context.getGeofenceManager().getById(geofenceId); @@ -89,8 +94,10 @@ public final class Events { } } else { iterator.remove(); + continue; } - } else if (maintenanceId != 0) { + } + if (maintenanceId != 0) { if (Context.getMaintenancesManager().checkItemPermission(userId, maintenanceId)) { Maintenance maintenance = Context.getMaintenancesManager().getById(maintenanceId); if (maintenance != null) { @@ -98,6 +105,14 @@ public final class Events { } } else { iterator.remove(); + continue; + } + } + if (positionId != 0) { + // Position checks not implemented + Optional position = positions.stream().filter(pos -> pos.getId() == positionId).findFirst(); + if (position.isPresent()) { + positionObjects.put(positionId, position.get()); } } } else { @@ -125,9 +140,10 @@ public final class Events { jxlsContext.putVar("sheetNames", sheetNames); jxlsContext.putVar("geofenceNames", geofenceNames); jxlsContext.putVar("maintenanceNames", maintenanceNames); + jxlsContext.putVar("positions", positionObjects); jxlsContext.putVar("from", from); jxlsContext.putVar("to", to); ReportUtils.processTemplateWithSheets(inputStream, outputStream, jxlsContext); } } -} +} \ No newline at end of file -- cgit v1.2.3