aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-10-23 19:16:28 +1300
committerGitHub <noreply@github.com>2017-10-23 19:16:28 +1300
commit496f6a612eb02396946db2715225f55cc7003a0d (patch)
tree8028751cd713e90c1b1a35eab4027dda9280959d /src
parentf6f514bea19a75544378fdbfccb6808ea1a0424e (diff)
parent22efd02c8a45963e08e887d402bd4b9161636ddf (diff)
downloadtrackermap-server-496f6a612eb02396946db2715225f55cc7003a0d.tar.gz
trackermap-server-496f6a612eb02396946db2715225f55cc7003a0d.tar.bz2
trackermap-server-496f6a612eb02396946db2715225f55cc7003a0d.zip
Merge pull request #3600 from Abyss777/fix_3592
Set deviceId in Saved Command before sending
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/api/resource/CommandResource.java10
-rw-r--r--src/org/traccar/database/CommandsManager.java17
-rw-r--r--src/org/traccar/model/Command.java7
3 files changed, 18 insertions, 16 deletions
diff --git a/src/org/traccar/api/resource/CommandResource.java b/src/org/traccar/api/resource/CommandResource.java
index 996c15daf..703638701 100644
--- a/src/org/traccar/api/resource/CommandResource.java
+++ b/src/org/traccar/api/resource/CommandResource.java
@@ -62,18 +62,14 @@ public class CommandResource extends ExtendedObjectResource<Command> {
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);
}
- 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 cae4ac6f7..9ceb995ef 100644
--- a/src/org/traccar/database/CommandsManager.java
+++ b/src/org/traccar/database/CommandsManager.java
@@ -45,12 +45,12 @@ public class CommandsManager extends ExtendedObjectManager<Command> {
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 {
- boolean sent = true;
+ public boolean sendCommand(Command command) throws Exception {
+ long deviceId = command.getDeviceId();
+ if (command.getId() != 0) {
+ command = getById(command.getId()).clone();
+ command.setDeviceId(deviceId);
+ }
if (command.getTextChannel()) {
Position lastPosition = Context.getIdentityManager().getLastPosition(deviceId);
String phone = Context.getIdentityManager().getById(deviceId).getPhone();
@@ -71,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..16205ede1 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() {