diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/traccar/api/resource/CommandResource.java | 18 | ||||
-rw-r--r-- | src/main/java/org/traccar/database/CommandsManager.java | 9 |
2 files changed, 19 insertions, 8 deletions
diff --git a/src/main/java/org/traccar/api/resource/CommandResource.java b/src/main/java/org/traccar/api/resource/CommandResource.java index d50c7ee0c..c23d91e77 100644 --- a/src/main/java/org/traccar/api/resource/CommandResource.java +++ b/src/main/java/org/traccar/api/resource/CommandResource.java @@ -117,20 +117,30 @@ public class CommandResource extends ExtendedObjectResource<Command> { } else { permissionsService.checkRestriction(getUserId(), UserRestrictions::getLimitCommands); } - boolean result = true; + if (groupId > 0) { permissionsService.checkPermission(Group.class, getUserId(), groupId); var devices = DeviceUtil.getAccessibleDevices(storage, getUserId(), List.of(), List.of(groupId)); + List<QueuedCommand> queuedCommands = new ArrayList<>(); for (Device device : devices) { Command command = QueuedCommand.fromCommand(entity).toCommand(); command.setDeviceId(device.getId()); - result = commandsManager.sendCommand(command) && result; + QueuedCommand queuedCommand = commandsManager.sendCommand(command); + if (queuedCommand != null) { + queuedCommands.add(queuedCommand); + } + } + if (!queuedCommands.isEmpty()) { + return Response.accepted(queuedCommands).build(); } } else { permissionsService.checkPermission(Device.class, getUserId(), entity.getDeviceId()); - result = commandsManager.sendCommand(entity); + QueuedCommand queuedCommand = commandsManager.sendCommand(entity); + if (queuedCommand != null) { + return Response.accepted(queuedCommand).build(); + } } - return result ? Response.ok(entity).build() : Response.accepted(entity).build(); + return Response.ok(entity).build(); } @GET diff --git a/src/main/java/org/traccar/database/CommandsManager.java b/src/main/java/org/traccar/database/CommandsManager.java index fb8f2f9d6..bef696e58 100644 --- a/src/main/java/org/traccar/database/CommandsManager.java +++ b/src/main/java/org/traccar/database/CommandsManager.java @@ -61,7 +61,7 @@ public class CommandsManager implements BroadcastInterface { broadcastService.registerListener(this); } - public boolean sendCommand(Command command) throws Exception { + public QueuedCommand sendCommand(Command command) throws Exception { long deviceId = command.getDeviceId(); if (command.getTextChannel()) { if (smsManager == null) { @@ -84,12 +84,13 @@ public class CommandsManager implements BroadcastInterface { if (deviceSession != null && deviceSession.supportsLiveCommands()) { deviceSession.sendCommand(command); } else { - storage.addObject(QueuedCommand.fromCommand(command), new Request(new Columns.Exclude("id"))); + QueuedCommand queuedCommand = QueuedCommand.fromCommand(command); + queuedCommand.setId(storage.addObject(queuedCommand, new Request(new Columns.Exclude("id")))); broadcastService.updateCommand(true, deviceId); - return false; + return queuedCommand; } } - return true; + return null; } public Collection<Command> readQueuedCommands(long deviceId) { |