diff options
-rw-r--r-- | src/org/traccar/BaseProtocol.java | 5 | ||||
-rw-r--r-- | src/org/traccar/ServerManager.java | 30 | ||||
-rw-r--r-- | src/org/traccar/api/resource/DeviceResource.java | 4 | ||||
-rw-r--r-- | src/org/traccar/api/resource/SupportedCommandResource.java | 48 | ||||
-rw-r--r-- | src/org/traccar/database/DataManager.java | 1 | ||||
-rw-r--r-- | src/org/traccar/web/WebServer.java | 11 | ||||
-rw-r--r-- | web/app/Application.js | 2 | ||||
-rw-r--r-- | web/app/store/SupportedCommands.js (renamed from web/app/store/CommandTypes.js) | 33 | ||||
-rw-r--r-- | web/app/view/CommandDialog.js | 4 | ||||
-rw-r--r-- | web/app/view/DevicesController.js | 7 |
10 files changed, 111 insertions, 34 deletions
diff --git a/src/org/traccar/BaseProtocol.java b/src/org/traccar/BaseProtocol.java index 7714f18db..46a3fad5f 100644 --- a/src/org/traccar/BaseProtocol.java +++ b/src/org/traccar/BaseProtocol.java @@ -19,6 +19,7 @@ import org.traccar.database.ActiveDevice; import org.traccar.model.Command; import java.util.Arrays; +import java.util.Collection; import java.util.HashSet; import java.util.Set; @@ -40,6 +41,10 @@ public abstract class BaseProtocol implements Protocol { supportedCommands.addAll(Arrays.asList(commands)); } + public Collection<String> getSupportedCommands() { + return supportedCommands; + } + @Override public void sendCommand(ActiveDevice activeDevice, Command command) { if (!supportedCommands.contains(command.getType())) { diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java index cd6a071db..59bb88829 100644 --- a/src/org/traccar/ServerManager.java +++ b/src/org/traccar/ServerManager.java @@ -20,14 +20,19 @@ 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 { @@ -62,20 +67,22 @@ public class ServerManager { for (String name : names) { Class protocolClass = Class.forName(packageName + '.' + name); if (BaseProtocol.class.isAssignableFrom(protocolClass)) { - initProtocolServer((BaseProtocol) protocolClass.newInstance()); + BaseProtocol baseProtocol = (BaseProtocol) protocolClass.newInstance(); + protocols.put(baseProtocol.getName(), baseProtocol); + initProtocolServer(baseProtocol); } } } public void start() { - for (Object server: serverList) { - ((TrackerServer) server).start(); + for (TrackerServer server: serverList) { + server.start(); } } public void stop() { - for (Object server: serverList) { - ((TrackerServer) server).stop(); + for (TrackerServer server: serverList) { + server.stop(); } // Release resources @@ -89,4 +96,17 @@ public class ServerManager { } } + public Collection<String> getProtocolSuppportedCommands(String protocol) { + List<String> result = new ArrayList<>(); + + if (protocol != null) { + BaseProtocol baseProtocol = protocols.get(protocol); + for (String commandKey : baseProtocol.getSupportedCommands()) { + result.add(commandKey); + } + } + + return result; + } + } diff --git a/src/org/traccar/api/resource/DeviceResource.java b/src/org/traccar/api/resource/DeviceResource.java index 0017f13ee..18c4cb0ce 100644 --- a/src/org/traccar/api/resource/DeviceResource.java +++ b/src/org/traccar/api/resource/DeviceResource.java @@ -30,8 +30,8 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import java.sql.SQLException; -import java.util.Collection; + +import org.traccar.model.Device; @Path("devices") @Produces(MediaType.APPLICATION_JSON) diff --git a/src/org/traccar/api/resource/SupportedCommandResource.java b/src/org/traccar/api/resource/SupportedCommandResource.java new file mode 100644 index 000000000..393588d9b --- /dev/null +++ b/src/org/traccar/api/resource/SupportedCommandResource.java @@ -0,0 +1,48 @@ +/* + * Copyright 2016 Gabor Somogyi (gabor.g.somogyi@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.api.resource; + +import org.traccar.Context; +import org.traccar.api.BaseResource; +import org.traccar.model.Position; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import java.sql.SQLException; +import java.util.Collection; +import java.util.Collections; + +@Path("supportedcommands") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class SupportedCommandResource extends BaseResource { + + @GET + public Collection<String> get(@QueryParam("deviceId") long deviceId) throws SQLException { + Context.getPermissionsManager().checkDevice(getUserId(), deviceId); + 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 5a233411b..ac3be45ac 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -482,5 +482,4 @@ public class DataManager implements IdentityManager { .setObject(server) .executeUpdate(); } - } diff --git a/src/org/traccar/web/WebServer.java b/src/org/traccar/web/WebServer.java index fc78dce65..bcb0442f6 100644 --- a/src/org/traccar/web/WebServer.java +++ b/src/org/traccar/web/WebServer.java @@ -35,14 +35,15 @@ import org.traccar.api.ObjectMapperProvider; import org.traccar.api.ResourceErrorHandler; import org.traccar.api.SecurityRequestFilter; import org.traccar.api.resource.CommandResource; -import org.traccar.api.resource.DevicePermissionResource; -import org.traccar.api.resource.DeviceResource; import org.traccar.api.resource.GroupPermissionResource; -import org.traccar.api.resource.GroupResource; -import org.traccar.api.resource.PositionResource; import org.traccar.api.resource.ServerResource; import org.traccar.api.resource.SessionResource; +import org.traccar.api.resource.DevicePermissionResource; import org.traccar.api.resource.UserResource; +import org.traccar.api.resource.GroupResource; +import org.traccar.api.resource.DeviceResource; +import org.traccar.api.resource.PositionResource; +import org.traccar.api.resource.SupportedCommandResource; import org.traccar.helper.Log; import javax.naming.InitialContext; @@ -147,7 +148,7 @@ public class WebServer { resourceConfig.register(CorsResponseFilter.class); resourceConfig.registerClasses(ServerResource.class, SessionResource.class, CommandResource.class, GroupPermissionResource.class, DevicePermissionResource.class, UserResource.class, - GroupResource.class, DeviceResource.class, PositionResource.class); + GroupResource.class, DeviceResource.class, PositionResource.class, SupportedCommandResource.class); servletHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/*"); handlers.addHandler(servletHandler); diff --git a/web/app/Application.js b/web/app/Application.js index 69ce8f891..f68ef981e 100644 --- a/web/app/Application.js +++ b/web/app/Application.js @@ -45,7 +45,7 @@ Ext.define('Traccar.Application', { 'MapTypes', 'DistanceUnits', 'SpeedUnits', - 'CommandTypes', + 'SupportedCommands', 'TimeUnits', 'Languages' ], diff --git a/web/app/store/CommandTypes.js b/web/app/store/SupportedCommands.js index 3f5094266..612909180 100644 --- a/web/app/store/CommandTypes.js +++ b/web/app/store/SupportedCommands.js @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2016 Gabor Somogyi (gabor.g.somogyi@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,21 +14,22 @@ * limitations under the License. */ -Ext.define('Traccar.store.CommandTypes', { +Ext.define('Traccar.store.SupportedCommands', { extend: 'Ext.data.Store', - fields: ['key', 'name'], + fields: [ + { type: 'string', name: 'key'} + ], - data: [{ - key: 'positionPeriodic', - name: Strings.commandPositionPeriodic - }, { - key: 'positionStop', - name: Strings.commandPositionStop - }, { - key: 'engineStop', - name: Strings.commandEngineStop - }, { - key: 'engineResume', - name: Strings.commandEngineResume - }] + listeners: { + 'beforeload' : function(store, eOpts) { + var proxy; + proxy = store.getProxy(); + proxy.setUrl('/api/supportedcommands?deviceId' + proxy.extraParams.deviceId); + } + }, + + proxy: { + type: 'rest', + url: '' + } }); diff --git a/web/app/view/CommandDialog.js b/web/app/view/CommandDialog.js index 66cd190ea..05412f39c 100644 --- a/web/app/view/CommandDialog.js +++ b/web/app/view/CommandDialog.js @@ -30,8 +30,8 @@ Ext.define('Traccar.view.CommandDialog', { xtype: 'combobox', name: 'type', fieldLabel: Strings.commandType, - store: 'CommandTypes', - displayField: 'name', + store: 'SupportedCommands', + displayField: 'key', valueField: 'key', listeners: { select: 'onSelect' diff --git a/web/app/view/DevicesController.js b/web/app/view/DevicesController.js index 10918c13a..9dee0ff7c 100644 --- a/web/app/view/DevicesController.js +++ b/web/app/view/DevicesController.js @@ -80,11 +80,14 @@ Ext.define('Traccar.view.DevicesController', { }, onCommandClick: function () { - var device, command, dialog; + var device, deviceId, command, dialog, comboStore; device = this.getView().getSelectionModel().getSelection()[0]; + deviceId = device.get('id'); command = Ext.create('Traccar.model.Command'); - command.set('deviceId', device.get('id')); + command.set('deviceId', deviceId); dialog = Ext.create('Traccar.view.CommandDialog'); + comboStore = dialog.down('form').down('combobox').getStore(); + comboStore.getProxy().setExtraParam('deviceId', deviceId); dialog.down('form').loadRecord(command); dialog.show(); }, |