aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorGábor Somogyi <gabor.g.somogyi@gmail.com>2016-05-08 13:06:25 +0200
committerGábor Somogyi <gabor.g.somogyi@gmail.com>2016-05-08 13:29:18 +0200
commit301f2d314f446410da78615ac76ce0c07571d445 (patch)
tree71c96669b970bb8315388cc01db21e00b743796d /src/org/traccar
parent37bc675580c640d4fa7968fee575544fb3a550e3 (diff)
downloadtrackermap-server-301f2d314f446410da78615ac76ce0c07571d445.tar.gz
trackermap-server-301f2d314f446410da78615ac76ce0c07571d445.tar.bz2
trackermap-server-301f2d314f446410da78615ac76ce0c07571d445.zip
Review fixes
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/BaseProtocol.java1
-rw-r--r--src/org/traccar/Protocol.java3
-rw-r--r--src/org/traccar/ServerManager.java25
-rw-r--r--src/org/traccar/api/resource/CommandTypeResource.java9
-rw-r--r--src/org/traccar/database/ActiveDevice.java14
-rw-r--r--src/org/traccar/model/CommandType.java14
6 files changed, 28 insertions, 38 deletions
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<String> 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<String> getSupportedCommands();
+
void sendCommand(ActiveDevice activeDevice, Command command);
void initTrackerServers(List<TrackerServer> 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<String, BaseProtocol> protocols = new HashMap<>();
private final List<TrackerServer> 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<CommandType> getProtocolCommandTypes(String protocol) {
- List<CommandType> 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<CommandType> 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<CommandType> getCommandTypes() {
+ List<CommandType> 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;
}
}