aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2023-10-04 08:16:10 +0800
committerAnton Tananaev <anton@traccar.org>2023-10-04 08:16:10 +0800
commit6c78fc675501ab348f877e423b984d1a2a132ef1 (patch)
treea1cc3d14aeaa239ffa71b402bd786dbdb62dba10
parenta10728fc9174591c4535b5ced290f7b51ec98851 (diff)
downloadtrackermap-server-6c78fc675501ab348f877e423b984d1a2a132ef1.tar.gz
trackermap-server-6c78fc675501ab348f877e423b984d1a2a132ef1.tar.bz2
trackermap-server-6c78fc675501ab348f877e423b984d1a2a132ef1.zip
Event for sent queued commands
-rw-r--r--src/main/java/org/traccar/database/CommandsManager.java14
-rw-r--r--src/main/java/org/traccar/model/Event.java1
-rw-r--r--templates/full/queuedCommandSent.vm11
-rw-r--r--templates/short/queuedCommandSent.vm2
4 files changed, 27 insertions, 1 deletions
diff --git a/src/main/java/org/traccar/database/CommandsManager.java b/src/main/java/org/traccar/database/CommandsManager.java
index bef696e58..90180b989 100644
--- a/src/main/java/org/traccar/database/CommandsManager.java
+++ b/src/main/java/org/traccar/database/CommandsManager.java
@@ -22,6 +22,7 @@ import org.traccar.broadcast.BroadcastInterface;
import org.traccar.broadcast.BroadcastService;
import org.traccar.model.Command;
import org.traccar.model.Device;
+import org.traccar.model.Event;
import org.traccar.model.Position;
import org.traccar.model.QueuedCommand;
import org.traccar.session.ConnectionManager;
@@ -38,6 +39,8 @@ import jakarta.annotation.Nullable;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
import java.util.stream.Collectors;
@Singleton
@@ -48,16 +51,19 @@ public class CommandsManager implements BroadcastInterface {
private final SmsManager smsManager;
private final ConnectionManager connectionManager;
private final BroadcastService broadcastService;
+ private final NotificationManager notificationManager;
@Inject
public CommandsManager(
Storage storage, ServerManager serverManager, @Nullable SmsManager smsManager,
- ConnectionManager connectionManager, BroadcastService broadcastService) {
+ ConnectionManager connectionManager, BroadcastService broadcastService,
+ NotificationManager notificationManager) {
this.storage = storage;
this.serverManager = serverManager;
this.smsManager = smsManager;
this.connectionManager = connectionManager;
this.broadcastService = broadcastService;
+ this.notificationManager = notificationManager;
broadcastService.registerListener(this);
}
@@ -103,10 +109,16 @@ public class CommandsManager implements BroadcastInterface {
new Columns.All(),
new Condition.Equals("deviceId", deviceId),
new Order("id", false, count)));
+ Map<Event, Position> events = new HashMap<>();
for (var command : commands) {
storage.removeObject(QueuedCommand.class, new Request(
new Condition.Equals("id", command.getId())));
+
+ Event event = new Event(Event.TYPE_QUEUED_COMMAND_SENT, command.getDeviceId());
+ event.set("id", command.getId());
+ events.put(event, null);
}
+ notificationManager.updateEvents(events);
return commands.stream().map(QueuedCommand::toCommand).collect(Collectors.toList());
} catch (StorageException e) {
throw new RuntimeException(e);
diff --git a/src/main/java/org/traccar/model/Event.java b/src/main/java/org/traccar/model/Event.java
index 0e851d748..6f90de9da 100644
--- a/src/main/java/org/traccar/model/Event.java
+++ b/src/main/java/org/traccar/model/Event.java
@@ -46,6 +46,7 @@ public class Event extends Message {
public static final String TYPE_DEVICE_UNKNOWN = "deviceUnknown";
public static final String TYPE_DEVICE_OFFLINE = "deviceOffline";
public static final String TYPE_DEVICE_INACTIVE = "deviceInactive";
+ public static final String TYPE_QUEUED_COMMAND_SENT = "queuedCommandSent";
public static final String TYPE_DEVICE_MOVING = "deviceMoving";
public static final String TYPE_DEVICE_STOPPED = "deviceStopped";
diff --git a/templates/full/queuedCommandSent.vm b/templates/full/queuedCommandSent.vm
new file mode 100644
index 000000000..148dd2094
--- /dev/null
+++ b/templates/full/queuedCommandSent.vm
@@ -0,0 +1,11 @@
+#set($subject = "$device.name: queued command sent")
+<!DOCTYPE html>
+<html>
+<body>
+Device: $device.name<br>
+Queued command sent<br>
+Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)<br>
+<br>
+<a href="$webUrl/settings/notifications?token=$token">Unsubscribe</a>
+</body>
+</html>
diff --git a/templates/short/queuedCommandSent.vm b/templates/short/queuedCommandSent.vm
new file mode 100644
index 000000000..67f031280
--- /dev/null
+++ b/templates/short/queuedCommandSent.vm
@@ -0,0 +1,2 @@
+#set($subject = "$device.name: queued command sent")
+Queued command sent to $device.name at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)