diff options
author | Anton Tananaev <anton@traccar.org> | 2023-10-04 07:59:51 +0800 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2023-10-04 07:59:51 +0800 |
commit | a10728fc9174591c4535b5ced290f7b51ec98851 (patch) | |
tree | 825747529ec908b2b832db55fcc503b757ac27ff /src/main/java/org/traccar/api/resource | |
parent | 45a0d3b8673a5bab98570b84a864e6b313fe2899 (diff) | |
download | trackermap-server-a10728fc9174591c4535b5ced290f7b51ec98851.tar.gz trackermap-server-a10728fc9174591c4535b5ced290f7b51ec98851.tar.bz2 trackermap-server-a10728fc9174591c4535b5ced290f7b51ec98851.zip |
Return queued command with id
Diffstat (limited to 'src/main/java/org/traccar/api/resource')
-rw-r--r-- | src/main/java/org/traccar/api/resource/CommandResource.java | 18 |
1 files changed, 14 insertions, 4 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 |