From ed72ff6e7f964bc56a4948c15c97f37c072bf326 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Sun, 22 Oct 2017 18:55:34 +0500 Subject: Set deviceId in Saved Command before send --- src/org/traccar/api/resource/CommandResource.java | 9 +++------ src/org/traccar/database/CommandsManager.java | 14 +++++++++----- 2 files changed, 12 insertions(+), 11 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/api/resource/CommandResource.java b/src/org/traccar/api/resource/CommandResource.java index 996c15daf..a25421e31 100644 --- a/src/org/traccar/api/resource/CommandResource.java +++ b/src/org/traccar/api/resource/CommandResource.java @@ -62,17 +62,14 @@ public class CommandResource extends ExtendedObjectResource { Context.getPermissionsManager().checkReadonly(getUserId()); long deviceId = entity.getDeviceId(); long id = entity.getId(); - boolean sent; - if (deviceId != 0 && id != 0) { + Context.getPermissionsManager().checkDevice(getUserId(), deviceId); + if (id != 0) { Context.getPermissionsManager().checkPermission(Command.class, getUserId(), id); - Context.getPermissionsManager().checkDevice(getUserId(), deviceId); Context.getPermissionsManager().checkUserDeviceCommand(getUserId(), deviceId, id); - sent = Context.getCommandsManager().sendCommand(id, deviceId); } else { Context.getPermissionsManager().checkLimitCommands(getUserId()); - Context.getPermissionsManager().checkDevice(getUserId(), deviceId); - sent = Context.getCommandsManager().sendCommand(entity, deviceId); } + boolean sent = Context.getCommandsManager().sendCommand(entity); if (!sent) { return Response.accepted(entity).build(); } diff --git a/src/org/traccar/database/CommandsManager.java b/src/org/traccar/database/CommandsManager.java index cae4ac6f7..07695cbf7 100644 --- a/src/org/traccar/database/CommandsManager.java +++ b/src/org/traccar/database/CommandsManager.java @@ -45,11 +45,15 @@ public class CommandsManager extends ExtendedObjectManager { return !getAllDeviceItems(deviceId).contains(commandId); } - public boolean sendCommand(long commandId, long deviceId) throws Exception { - return sendCommand(getById(commandId), deviceId); - } - - public boolean sendCommand(Command command, long deviceId) throws Exception { + public boolean sendCommand(Command command) throws Exception { + long deviceId = command.getDeviceId(); + if (command.getId() != 0) { + Command savedCommand = getById(command.getId()); + command.setTextChannel(savedCommand.getTextChannel()); + command.setType(savedCommand.getType()); + command.setAttributes(savedCommand.getAttributes()); + command.setDescription(savedCommand.getDescription()); + } boolean sent = true; if (command.getTextChannel()) { Position lastPosition = Context.getIdentityManager().getLastPosition(deviceId); -- cgit v1.2.3