diff options
author | Anton Tananaev <anton@traccar.org> | 2022-06-13 18:49:01 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-06-13 18:49:01 -0700 |
commit | 8569e396f7bdafd49a974b35a2e83a57164c6c62 (patch) | |
tree | 139016fc661c0d152bbc077f7c256d35413e5477 | |
parent | e894c17cf14addb729a6c51712ef672cc2cd160b (diff) | |
download | trackermap-server-8569e396f7bdafd49a974b35a2e83a57164c6c62.tar.gz trackermap-server-8569e396f7bdafd49a974b35a2e83a57164c6c62.tar.bz2 trackermap-server-8569e396f7bdafd49a974b35a2e83a57164c6c62.zip |
Remove report template path key
5 files changed, 51 insertions, 20 deletions
diff --git a/src/main/java/org/traccar/reports/EventsReportProvider.java b/src/main/java/org/traccar/reports/EventsReportProvider.java index 6de313a13..91d061c65 100644 --- a/src/main/java/org/traccar/reports/EventsReportProvider.java +++ b/src/main/java/org/traccar/reports/EventsReportProvider.java @@ -18,6 +18,8 @@ package org.traccar.reports; import org.apache.poi.ss.util.WorkbookUtil; import org.traccar.Context; +import org.traccar.config.Config; +import org.traccar.config.Keys; import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Geofence; @@ -28,10 +30,12 @@ import org.traccar.reports.model.DeviceReportSection; import org.traccar.storage.StorageException; import javax.inject.Inject; +import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; import java.util.Date; @@ -40,10 +44,12 @@ import java.util.Iterator; public class EventsReportProvider { + private final Config config; private final ReportUtils reportUtils; @Inject - public EventsReportProvider(ReportUtils reportUtils) { + public EventsReportProvider(Config config, ReportUtils reportUtils) { + this.config = config; this.reportUtils = reportUtils; } @@ -120,9 +126,9 @@ public class EventsReportProvider { deviceEvents.setObjects(events); devicesEvents.add(deviceEvents); } - String templatePath = Context.getConfig().getString("report.templatesPath", - "templates/export/"); - try (InputStream inputStream = new FileInputStream(templatePath + "/events.xlsx")) { + + File file = Paths.get(config.getString(Keys.TEMPLATES_ROOT), "export", "events.xlsx").toFile(); + try (InputStream inputStream = new FileInputStream(file)) { var context = reportUtils.initializeContext(userId); context.putVar("devices", devicesEvents); context.putVar("sheetNames", sheetNames); diff --git a/src/main/java/org/traccar/reports/RouteReportProvider.java b/src/main/java/org/traccar/reports/RouteReportProvider.java index dbbf0906d..b1a806960 100644 --- a/src/main/java/org/traccar/reports/RouteReportProvider.java +++ b/src/main/java/org/traccar/reports/RouteReportProvider.java @@ -18,6 +18,8 @@ package org.traccar.reports; import org.apache.poi.ss.util.WorkbookUtil; import org.traccar.Context; +import org.traccar.config.Config; +import org.traccar.config.Keys; import org.traccar.helper.model.PositionUtil; import org.traccar.model.Device; import org.traccar.model.Group; @@ -28,21 +30,25 @@ import org.traccar.storage.Storage; import org.traccar.storage.StorageException; import javax.inject.Inject; +import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; import java.util.Date; public class RouteReportProvider { + private final Config config; private final ReportUtils reportUtils; private final Storage storage; @Inject - public RouteReportProvider(ReportUtils reportUtils, Storage storage) { + public RouteReportProvider(Config config, ReportUtils reportUtils, Storage storage) { + this.config = config; this.reportUtils = reportUtils; this.storage = storage; } @@ -80,9 +86,9 @@ public class RouteReportProvider { deviceRoutes.setObjects(positions); devicesRoutes.add(deviceRoutes); } - String templatePath = Context.getConfig().getString("report.templatesPath", - "templates/export/"); - try (InputStream inputStream = new FileInputStream(templatePath + "/route.xlsx")) { + + File file = Paths.get(config.getString(Keys.TEMPLATES_ROOT), "export", "route.xlsx").toFile(); + try (InputStream inputStream = new FileInputStream(file)) { var context = reportUtils.initializeContext(userId); context.putVar("devices", devicesRoutes); context.putVar("sheetNames", sheetNames); diff --git a/src/main/java/org/traccar/reports/StopsReportProvider.java b/src/main/java/org/traccar/reports/StopsReportProvider.java index 534ab7742..a6a9a94cc 100644 --- a/src/main/java/org/traccar/reports/StopsReportProvider.java +++ b/src/main/java/org/traccar/reports/StopsReportProvider.java @@ -18,6 +18,8 @@ package org.traccar.reports; import org.apache.poi.ss.util.WorkbookUtil; import org.traccar.Context; +import org.traccar.config.Config; +import org.traccar.config.Keys; import org.traccar.helper.model.PositionUtil; import org.traccar.model.Device; import org.traccar.model.Group; @@ -28,21 +30,25 @@ import org.traccar.storage.Storage; import org.traccar.storage.StorageException; import javax.inject.Inject; +import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; import java.util.Date; public class StopsReportProvider { + private final Config config; private final ReportUtils reportUtils; private final Storage storage; @Inject - public StopsReportProvider(ReportUtils reportUtils, Storage storage) { + public StopsReportProvider(Config config, ReportUtils reportUtils, Storage storage) { + this.config = config; this.reportUtils = reportUtils; this.storage = storage; } @@ -88,9 +94,9 @@ public class StopsReportProvider { deviceStops.setObjects(stops); devicesStops.add(deviceStops); } - String templatePath = Context.getConfig().getString("report.templatesPath", - "templates/export/"); - try (InputStream inputStream = new FileInputStream(templatePath + "/stops.xlsx")) { + + File file = Paths.get(config.getString(Keys.TEMPLATES_ROOT), "export", "stops.xlsx").toFile(); + try (InputStream inputStream = new FileInputStream(file)) { var context = reportUtils.initializeContext(userId); context.putVar("devices", devicesStops); context.putVar("sheetNames", sheetNames); diff --git a/src/main/java/org/traccar/reports/SummaryReportProvider.java b/src/main/java/org/traccar/reports/SummaryReportProvider.java index 25d558480..68976b987 100644 --- a/src/main/java/org/traccar/reports/SummaryReportProvider.java +++ b/src/main/java/org/traccar/reports/SummaryReportProvider.java @@ -19,6 +19,8 @@ package org.traccar.reports; import org.jxls.util.JxlsHelper; import org.traccar.Context; import org.traccar.api.security.PermissionsService; +import org.traccar.config.Config; +import org.traccar.config.Keys; import org.traccar.helper.UnitsConverter; import org.traccar.helper.model.PositionUtil; import org.traccar.helper.model.UserUtil; @@ -29,10 +31,12 @@ import org.traccar.storage.Storage; import org.traccar.storage.StorageException; import javax.inject.Inject; +import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; @@ -40,12 +44,15 @@ import java.util.Date; public class SummaryReportProvider { + private final Config config; private final ReportUtils reportUtils; private final PermissionsService permissionsService; private final Storage storage; @Inject - public SummaryReportProvider(ReportUtils reportUtils, PermissionsService permissionsService, Storage storage) { + public SummaryReportProvider( + Config config, ReportUtils reportUtils, PermissionsService permissionsService, Storage storage) { + this.config = config; this.reportUtils = reportUtils; this.permissionsService = permissionsService; this.storage = storage; @@ -157,9 +164,9 @@ public class SummaryReportProvider { Date from, Date to, boolean daily) throws StorageException, IOException { reportUtils.checkPeriodLimit(from, to); Collection<SummaryReportItem> summaries = getObjects(userId, deviceIds, groupIds, from, to, daily); - String templatePath = Context.getConfig().getString("report.templatesPath", - "templates/export/"); - try (InputStream inputStream = new FileInputStream(templatePath + "/summary.xlsx")) { + + File file = Paths.get(config.getString(Keys.TEMPLATES_ROOT), "export", "summary.xlsx").toFile(); + try (InputStream inputStream = new FileInputStream(file)) { var context = reportUtils.initializeContext(userId); context.putVar("summaries", summaries); context.putVar("from", from); diff --git a/src/main/java/org/traccar/reports/TripsReportProvider.java b/src/main/java/org/traccar/reports/TripsReportProvider.java index a8e0e3dde..bff559664 100644 --- a/src/main/java/org/traccar/reports/TripsReportProvider.java +++ b/src/main/java/org/traccar/reports/TripsReportProvider.java @@ -18,6 +18,8 @@ package org.traccar.reports; import org.apache.poi.ss.util.WorkbookUtil; import org.traccar.Context; +import org.traccar.config.Config; +import org.traccar.config.Keys; import org.traccar.helper.model.PositionUtil; import org.traccar.model.Device; import org.traccar.model.Group; @@ -28,21 +30,25 @@ import org.traccar.storage.Storage; import org.traccar.storage.StorageException; import javax.inject.Inject; +import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; import java.util.Date; public class TripsReportProvider { + private final Config config; private final ReportUtils reportUtils; private final Storage storage; @Inject - public TripsReportProvider(ReportUtils reportUtils, Storage storage) { + public TripsReportProvider(Config config, ReportUtils reportUtils, Storage storage) { + this.config = config; this.reportUtils = reportUtils; this.storage = storage; } @@ -88,9 +94,9 @@ public class TripsReportProvider { deviceTrips.setObjects(trips); devicesTrips.add(deviceTrips); } - String templatePath = Context.getConfig().getString("report.templatesPath", - "templates/export/"); - try (InputStream inputStream = new FileInputStream(templatePath + "/trips.xlsx")) { + + File file = Paths.get(config.getString(Keys.TEMPLATES_ROOT), "export", "trips.xlsx").toFile(); + try (InputStream inputStream = new FileInputStream(file)) { var context = reportUtils.initializeContext(userId); context.putVar("devices", devicesTrips); context.putVar("sheetNames", sheetNames); |