aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-10-22 18:55:34 +0500
committerAbyss777 <abyss@fox5.ru>2017-10-22 19:22:49 +0500
commited72ff6e7f964bc56a4948c15c97f37c072bf326 (patch)
tree70568d6af20bc90a071c907583ccb951059bcd2a /src
parent9ace2318b9ea5a2d949800eedff8398808d3a6ce (diff)
downloadtrackermap-server-ed72ff6e7f964bc56a4948c15c97f37c072bf326.tar.gz
trackermap-server-ed72ff6e7f964bc56a4948c15c97f37c072bf326.tar.bz2
trackermap-server-ed72ff6e7f964bc56a4948c15c97f37c072bf326.zip
Set deviceId in Saved Command before send
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/api/resource/CommandResource.java9
-rw-r--r--src/org/traccar/database/CommandsManager.java14
2 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 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<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);
}
+ 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<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 {
+ 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);