aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/org')
-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);