diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/api/resource/CommandResource.java | 3 | ||||
-rw-r--r-- | src/org/traccar/database/CommandsManager.java | 13 | ||||
-rw-r--r-- | src/org/traccar/model/Command.java | 7 |
3 files changed, 12 insertions, 11 deletions
diff --git a/src/org/traccar/api/resource/CommandResource.java b/src/org/traccar/api/resource/CommandResource.java index a25421e31..703638701 100644 --- a/src/org/traccar/api/resource/CommandResource.java +++ b/src/org/traccar/api/resource/CommandResource.java @@ -69,8 +69,7 @@ public class CommandResource extends ExtendedObjectResource<Command> { } else { Context.getPermissionsManager().checkLimitCommands(getUserId()); } - boolean sent = Context.getCommandsManager().sendCommand(entity); - if (!sent) { + if (!Context.getCommandsManager().sendCommand(entity)) { return Response.accepted(entity).build(); } return Response.ok(entity).build(); diff --git a/src/org/traccar/database/CommandsManager.java b/src/org/traccar/database/CommandsManager.java index 07695cbf7..9ceb995ef 100644 --- a/src/org/traccar/database/CommandsManager.java +++ b/src/org/traccar/database/CommandsManager.java @@ -48,13 +48,9 @@ public class CommandsManager extends ExtendedObjectManager<Command> { 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()); + command = getById(command.getId()).clone(); + command.setDeviceId(deviceId); } - boolean sent = true; if (command.getTextChannel()) { Position lastPosition = Context.getIdentityManager().getLastPosition(deviceId); String phone = Context.getIdentityManager().getById(deviceId).getPhone(); @@ -75,10 +71,11 @@ public class CommandsManager extends ExtendedObjectManager<Command> { if (activeDevice != null) { activeDevice.sendCommand(command); } else { - sent = !getDeviceQueue(deviceId).add(command); + getDeviceQueue(deviceId).add(command); + return false; } } - return sent; + return true; } public Collection<Long> getSupportedCommands(long deviceId) { diff --git a/src/org/traccar/model/Command.java b/src/org/traccar/model/Command.java index 67134dc7d..09f0f251b 100644 --- a/src/org/traccar/model/Command.java +++ b/src/org/traccar/model/Command.java @@ -20,7 +20,7 @@ import org.traccar.database.QueryIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonIgnoreProperties(ignoreUnknown = true) -public class Command extends Message { +public class Command extends Message implements Cloneable { public static final String TYPE_CUSTOM = "custom"; public static final String TYPE_IDENTIFICATION = "deviceIdentification"; @@ -77,6 +77,11 @@ public class Command extends Message { public static final String KEY_SERVER = "server"; public static final String KEY_PORT = "port"; + @Override + public Command clone() throws CloneNotSupportedException { + return (Command) super.clone(); + } + private boolean textChannel; public boolean getTextChannel() { |