From bf68718e05f811ffeb2b4b57acab56dca3e7de56 Mon Sep 17 00:00:00 2001 From: Gábor Somogyi Date: Wed, 27 Apr 2016 22:22:08 +0200 Subject: Command framework ugly hack version --- src/org/traccar/database/DataManager.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/org/traccar/database') diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index eb0be9274..3dba215f6 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -472,6 +472,12 @@ public class DataManager implements IdentityManager { .executeQuery(Position.class); } + public Position getLatestPosition(long deviceId) throws SQLException { + return QueryBuilder.create(dataSource, getQuery("database.selectLatestPosition")) + .setLong("deviceId", deviceId) + .executeQuerySingle(Position.class); + } + public Server getServer() throws SQLException { return QueryBuilder.create(dataSource, getQuery("database.selectServers")) .executeQuerySingle(Server.class); @@ -482,5 +488,4 @@ public class DataManager implements IdentityManager { .setObject(server) .executeUpdate(); } - } -- cgit v1.2.3 From 1a605980b1a120614ccaeb56faac37b05a81a4e9 Mon Sep 17 00:00:00 2001 From: Gábor Somogyi Date: Tue, 3 May 2016 23:15:27 +0200 Subject: Removed database.selectLatestPosition --- setup/unix/traccar.xml | 4 ---- setup/windows/traccar.xml | 4 ---- src/org/traccar/api/resource/SupportedCommandResource.java | 6 +++--- src/org/traccar/database/DataManager.java | 6 ------ 4 files changed, 3 insertions(+), 17 deletions(-) (limited to 'src/org/traccar/database') diff --git a/setup/unix/traccar.xml b/setup/unix/traccar.xml index 8dfcf6386..2ddf6551f 100644 --- a/setup/unix/traccar.xml +++ b/setup/unix/traccar.xml @@ -152,10 +152,6 @@ SELECT * FROM positions WHERE deviceId = :deviceId AND fixTime BETWEEN :from AND :to ORDER BY fixTime; - - SELECT TOP 1 * FROM positions WHERE deviceId = :deviceId AND protocol IS NOT NULL; - - INSERT INTO positions (deviceId, protocol, serverTime, deviceTime, fixTime, valid, latitude, longitude, altitude, speed, course, address, attributes) VALUES (:deviceId, :protocol, :now, :deviceTime, :fixTime, :valid, :latitude, :longitude, :altitude, :speed, :course, :address, :attributes); diff --git a/setup/windows/traccar.xml b/setup/windows/traccar.xml index 80351325b..bf1b216af 100644 --- a/setup/windows/traccar.xml +++ b/setup/windows/traccar.xml @@ -161,10 +161,6 @@ SELECT * FROM positions WHERE id IN (SELECT positionId FROM devices); - - SELECT TOP 1 * FROM positions WHERE deviceId = :deviceId AND protocol IS NOT NULL; - - UPDATE devices SET positionId = :id WHERE id = :deviceId; diff --git a/src/org/traccar/api/resource/SupportedCommandResource.java b/src/org/traccar/api/resource/SupportedCommandResource.java index 849447060..bf4fd4969 100644 --- a/src/org/traccar/api/resource/SupportedCommandResource.java +++ b/src/org/traccar/api/resource/SupportedCommandResource.java @@ -34,9 +34,9 @@ public class SupportedCommandResource extends BaseResource { @GET public Collection get(@QueryParam("deviceId") long deviceId) throws SQLException { Context.getPermissionsManager().checkDevice(getUserId(), deviceId); - Position latestPosition = Context.getDataManager().getLatestPosition(deviceId); - if (latestPosition != null) { - return Context.getServerManager().getProtocolSuppportedCommands(latestPosition.getProtocol()); + Position lastPosition = Context.getConnectionManager().getLastPosition(deviceId); + if (lastPosition != null) { + return Context.getServerManager().getProtocolSuppportedCommands(lastPosition.getProtocol()); } else { return Collections.EMPTY_LIST; } diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 3dba215f6..3732c82eb 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -472,12 +472,6 @@ public class DataManager implements IdentityManager { .executeQuery(Position.class); } - public Position getLatestPosition(long deviceId) throws SQLException { - return QueryBuilder.create(dataSource, getQuery("database.selectLatestPosition")) - .setLong("deviceId", deviceId) - .executeQuerySingle(Position.class); - } - public Server getServer() throws SQLException { return QueryBuilder.create(dataSource, getQuery("database.selectServers")) .executeQuerySingle(Server.class); -- cgit v1.2.3 From 301f2d314f446410da78615ac76ce0c07571d445 Mon Sep 17 00:00:00 2001 From: Gábor Somogyi Date: Sun, 8 May 2016 13:06:25 +0200 Subject: Review fixes --- src/org/traccar/BaseProtocol.java | 1 + src/org/traccar/Protocol.java | 3 +++ src/org/traccar/ServerManager.java | 25 ---------------------- .../traccar/api/resource/CommandTypeResource.java | 9 +------- src/org/traccar/database/ActiveDevice.java | 14 ++++++++++++ src/org/traccar/model/CommandType.java | 14 +++++++----- web/app/store/CommandTypes.js | 12 +++++------ web/app/view/CommandDialog.js | 2 +- 8 files changed, 35 insertions(+), 45 deletions(-) (limited to 'src/org/traccar/database') diff --git a/src/org/traccar/BaseProtocol.java b/src/org/traccar/BaseProtocol.java index 46a3fad5f..c77e61a81 100644 --- a/src/org/traccar/BaseProtocol.java +++ b/src/org/traccar/BaseProtocol.java @@ -41,6 +41,7 @@ public abstract class BaseProtocol implements Protocol { supportedCommands.addAll(Arrays.asList(commands)); } + @Override public Collection getSupportedCommands() { return supportedCommands; } diff --git a/src/org/traccar/Protocol.java b/src/org/traccar/Protocol.java index edf9bfb36..c99fd8ecb 100644 --- a/src/org/traccar/Protocol.java +++ b/src/org/traccar/Protocol.java @@ -3,12 +3,15 @@ package org.traccar; import org.traccar.database.ActiveDevice; import org.traccar.model.Command; +import java.util.Collection; import java.util.List; public interface Protocol { String getName(); + Collection getSupportedCommands(); + void sendCommand(ActiveDevice activeDevice, Command command); void initTrackerServers(List serverList); diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java index cf49b3e2c..010438a44 100644 --- a/src/org/traccar/ServerManager.java +++ b/src/org/traccar/ServerManager.java @@ -15,26 +15,19 @@ */ package org.traccar; -import org.traccar.model.CommandType; - import java.io.File; import java.net.URI; import java.net.URL; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collection; import java.util.Enumeration; -import java.util.HashMap; import java.util.LinkedList; import java.util.List; -import java.util.Map; import java.util.jar.JarEntry; import java.util.jar.JarFile; public class ServerManager { - private final Map protocols = new HashMap<>(); private final List serverList = new LinkedList<>(); public ServerManager() throws Exception { @@ -70,7 +63,6 @@ public class ServerManager { Class protocolClass = Class.forName(packageName + '.' + name); if (BaseProtocol.class.isAssignableFrom(protocolClass)) { BaseProtocol baseProtocol = (BaseProtocol) protocolClass.newInstance(); - protocols.put(baseProtocol.getName(), baseProtocol); initProtocolServer(baseProtocol); } } @@ -98,21 +90,4 @@ public class ServerManager { } } - public Collection getProtocolCommandTypes(String protocol) { - List result = new ArrayList<>(); - - if (protocol != null) { - BaseProtocol baseProtocol = protocols.get(protocol); - if (baseProtocol != null) { - for (String commandKey : baseProtocol.getSupportedCommands()) { - CommandType commandType = new CommandType(); - commandType.setKey(commandKey); - result.add(commandType); - } - } - } - - return result; - } - } diff --git a/src/org/traccar/api/resource/CommandTypeResource.java b/src/org/traccar/api/resource/CommandTypeResource.java index 9f9ecf249..ce27f5241 100644 --- a/src/org/traccar/api/resource/CommandTypeResource.java +++ b/src/org/traccar/api/resource/CommandTypeResource.java @@ -17,7 +17,6 @@ package org.traccar.api.resource; import org.traccar.Context; import org.traccar.api.BaseResource; -import org.traccar.model.Position; import org.traccar.model.CommandType; import javax.ws.rs.Consumes; @@ -28,7 +27,6 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import java.sql.SQLException; import java.util.Collection; -import java.util.Collections; @Path("commandtypes") @Produces(MediaType.APPLICATION_JSON) @@ -38,12 +36,7 @@ public class CommandTypeResource extends BaseResource { @GET public Collection get(@QueryParam("deviceId") long deviceId) throws SQLException { Context.getPermissionsManager().checkDevice(getUserId(), deviceId); - Position lastPosition = Context.getConnectionManager().getLastPosition(deviceId); - if (lastPosition != null) { - return Context.getServerManager().getProtocolCommandTypes(lastPosition.getProtocol()); - } else { - return Collections.EMPTY_LIST; - } + return Context.getConnectionManager().getActiveDevice(deviceId).getCommandTypes(); } } diff --git a/src/org/traccar/database/ActiveDevice.java b/src/org/traccar/database/ActiveDevice.java index 746d3b393..3f2510af1 100644 --- a/src/org/traccar/database/ActiveDevice.java +++ b/src/org/traccar/database/ActiveDevice.java @@ -18,8 +18,12 @@ package org.traccar.database; import org.jboss.netty.channel.Channel; import org.traccar.Protocol; import org.traccar.model.Command; +import org.traccar.model.CommandType; import java.net.SocketAddress; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; public class ActiveDevice { @@ -43,6 +47,16 @@ public class ActiveDevice { return deviceId; } + public Collection getCommandTypes() { + List result = new ArrayList<>(); + + for (String commandKey : protocol.getSupportedCommands()) { + result.add(new CommandType(commandKey)); + } + + return result; + } + public void sendCommand(Command command) { protocol.sendCommand(this, command); } diff --git a/src/org/traccar/model/CommandType.java b/src/org/traccar/model/CommandType.java index 057dda4c5..210316f71 100644 --- a/src/org/traccar/model/CommandType.java +++ b/src/org/traccar/model/CommandType.java @@ -17,13 +17,17 @@ package org.traccar.model; public class CommandType { - private String key; + private String type; - public String getKey() { - return key; + public CommandType(String type) { + this.type = type; } - public void setKey(String key) { - this.key = key; + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; } } diff --git a/web/app/store/CommandTypes.js b/web/app/store/CommandTypes.js index b8cb03668..2ef190edc 100644 --- a/web/app/store/CommandTypes.js +++ b/web/app/store/CommandTypes.js @@ -16,7 +16,7 @@ Ext.define('Traccar.store.CommandTypes', { extend: 'Ext.data.Store', - fields: ['key', 'name'], + fields: ['type', 'name'], listeners: { 'beforeload' : function(store) { @@ -33,10 +33,10 @@ Ext.define('Traccar.store.CommandTypes', { type: 'json', getData: function(data) { Ext.each(data, function(entry) { - entry.name = entry.key; - if (typeof entry.key !== "undefined") { - var key = 'command' + entry.key.charAt(0).toUpperCase() + entry.key.slice(1); - var name = Strings[key]; + entry.name = entry.type; + if (typeof entry.type !== "undefined") { + var nameKey = 'command' + entry.type.charAt(0).toUpperCase() + entry.type.slice(1); + var name = Strings[nameKey]; if (typeof name !== "undefined") { entry.name = name; } @@ -44,6 +44,6 @@ Ext.define('Traccar.store.CommandTypes', { }); return data; } - }, + } } }); diff --git a/web/app/view/CommandDialog.js b/web/app/view/CommandDialog.js index 66cd190ea..d23b50d4c 100644 --- a/web/app/view/CommandDialog.js +++ b/web/app/view/CommandDialog.js @@ -32,7 +32,7 @@ Ext.define('Traccar.view.CommandDialog', { fieldLabel: Strings.commandType, store: 'CommandTypes', displayField: 'name', - valueField: 'key', + valueField: 'type', listeners: { select: 'onSelect' } -- cgit v1.2.3