aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/BaseProtocolDecoder.java
diff options
context:
space:
mode:
authorPhilipp Prangenberg <philipp.prangenberg@derkurier.de>2016-12-05 12:30:15 +0100
committerPhilipp Prangenberg <philipp.prangenberg@derkurier.de>2016-12-05 12:30:15 +0100
commitc710550576a3882b7ecccc47f69b5c1528fa969d (patch)
tree6e9f5489e5a059b5346d7fca671f51073863a4e2 /src/org/traccar/BaseProtocolDecoder.java
parenta21f436a58133f7da0cae06366d729665f3b8f9c (diff)
downloadtrackermap-server-c710550576a3882b7ecccc47f69b5c1528fa969d.tar.gz
trackermap-server-c710550576a3882b7ecccc47f69b5c1528fa969d.tar.bz2
trackermap-server-c710550576a3882b7ecccc47f69b5c1528fa969d.zip
Added functionality to get group by name.
Implemented configurable default group and default category when registering unknown devices
Diffstat (limited to 'src/org/traccar/BaseProtocolDecoder.java')
-rw-r--r--src/org/traccar/BaseProtocolDecoder.java17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java
index d8130c79e..5b5cc3146 100644
--- a/src/org/traccar/BaseProtocolDecoder.java
+++ b/src/org/traccar/BaseProtocolDecoder.java
@@ -19,6 +19,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.socket.DatagramChannel;
import org.traccar.helper.Log;
import org.traccar.model.Device;
+import org.traccar.model.Group;
import org.traccar.model.Position;
import java.net.InetSocketAddress;
@@ -34,8 +35,22 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
public long addUnknownDevice(String uniqueId) {
Device device = new Device();
+ String defaultGroupName = Context.getConfig().getString("database.registerUnknown.defaultGroup", "NOTDEFINED");
device.setName(uniqueId);
device.setUniqueId(uniqueId);
+ device.setCategory(Context.getConfig().getString("database.registerUnknown.defaultCategory", "default"));
+
+ if(!defaultGroupName.equals("NOTDEFINED")){
+// for (Group g:Context.getDeviceManager().getAllGroups()) {
+// if(g.getName().equalsIgnoreCase(defaultGroupName)){
+// device.setGroupId(g.getGroupId());
+// break;
+// }
+// }
+ Group defaultGroup = Context.getDeviceManager().getGroupByName(defaultGroupName);
+ if(defaultGroup != null)
+ device.setGroupId(defaultGroup.getId());
+ }
try {
Context.getDeviceManager().addDevice(device);
@@ -183,4 +198,4 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
}
}
-}
+} \ No newline at end of file