From d196a75e70f80dd1a45202b82052b1227bf1ae8d Mon Sep 17 00:00:00 2001 From: Philipp Prangenberg Date: Thu, 8 Dec 2016 08:10:50 +0100 Subject: Moving from GroupName to GroupID in default settings --- src/org/traccar/BaseProtocolDecoder.java | 12 ++++-------- src/org/traccar/database/DeviceManager.java | 16 ---------------- 2 files changed, 4 insertions(+), 24 deletions(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java index 103a999b0..ff7ab685a 100644 --- a/src/org/traccar/BaseProtocolDecoder.java +++ b/src/org/traccar/BaseProtocolDecoder.java @@ -19,7 +19,6 @@ 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; @@ -35,16 +34,13 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { public long addUnknownDevice(String uniqueId) { Device device = new Device(); - String defaultGroupName = Context.getConfig().getString("database.registerUnknown.defaultGroup", "NOTDEFINED"); + long defaultGroupId = Context.getConfig().getLong("database.registerUnknown.defaultGroupId"); device.setName(uniqueId); device.setUniqueId(uniqueId); - device.setCategory(Context.getConfig().getString("database.registerUnknown.defaultCategory", "default")); + device.setCategory(Context.getConfig().getString("database.registerUnknown.defaultCategory")); - if (!defaultGroupName.equals("NOTDEFINED")) { - Group defaultGroup = Context.getDeviceManager().getGroupByName(defaultGroupName); - if (defaultGroup != null) { - device.setGroupId(defaultGroup.getId()); - } + if (defaultGroupId != 0) { + device.setGroupId(defaultGroupId); } try { diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java index a75b0616c..c70e67231 100644 --- a/src/org/traccar/database/DeviceManager.java +++ b/src/org/traccar/database/DeviceManager.java @@ -49,7 +49,6 @@ public class DeviceManager implements IdentityManager { private AtomicLong devicesLastUpdate = new AtomicLong(); private Map groupsById; - private Map groupsByName; private AtomicLong groupsLastUpdate = new AtomicLong(); private final Map positions = new ConcurrentHashMap<>(); @@ -246,9 +245,6 @@ public class DeviceManager implements IdentityManager { if (groupsById == null) { groupsById = new ConcurrentHashMap<>(databaseGroups.size()); } - if (groupsByName == null) { - groupsByName = new ConcurrentHashMap<>(databaseGroups.size()); - } Set databaseGroupsIds = new HashSet<>(); for (Group group : databaseGroups) { databaseGroupsIds.add(group.getId()); @@ -258,7 +254,6 @@ public class DeviceManager implements IdentityManager { cachedGroup.setGroupId(group.getGroupId()); } else { groupsById.put(group.getId(), group); - groupsByName.put(group.getName(), group); } } for (Long cachedGroupId : groupsById.keySet()) { @@ -274,10 +269,6 @@ public class DeviceManager implements IdentityManager { return groupsById.get(id); } - public Group getGroupByName(String name) { - return groupsByName.get(name); - } - public Collection getAllGroups() { boolean forceUpdate = groupsById.isEmpty(); @@ -313,24 +304,17 @@ public class DeviceManager implements IdentityManager { checkGroupCycles(group); dataManager.addGroup(group); groupsById.put(group.getId(), group); - groupsByName.put(group.getName(), group); } public void updateGroup(Group group) throws SQLException { - String oldGroupName = groupsById.get(group.getId()).getName(); checkGroupCycles(group); dataManager.updateGroup(group); groupsById.put(group.getId(), group); - if (!oldGroupName.equals(group.getName())) { - groupsByName.remove(oldGroupName); - } - groupsByName.put(group.getName(), group); } public void removeGroup(long groupId) throws SQLException { dataManager.removeGroup(groupId); groupsById.remove(groupId); - groupsByName.remove(getGroupById(groupId).getName()); } public boolean lookupAttributeBoolean( -- cgit v1.2.3