diff options
author | Philipp Prangenberg <philipp.prangenberg@derkurier.de> | 2016-12-05 12:30:15 +0100 |
---|---|---|
committer | Philipp Prangenberg <philipp.prangenberg@derkurier.de> | 2016-12-05 12:30:15 +0100 |
commit | c710550576a3882b7ecccc47f69b5c1528fa969d (patch) | |
tree | 6e9f5489e5a059b5346d7fca671f51073863a4e2 /src/org/traccar/database | |
parent | a21f436a58133f7da0cae06366d729665f3b8f9c (diff) | |
download | trackermap-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/database')
-rw-r--r-- | src/org/traccar/database/DeviceManager.java | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java index c70e67231..700d22679 100644 --- a/src/org/traccar/database/DeviceManager.java +++ b/src/org/traccar/database/DeviceManager.java @@ -49,6 +49,7 @@ public class DeviceManager implements IdentityManager { private AtomicLong devicesLastUpdate = new AtomicLong(); private Map<Long, Group> groupsById; + private Map<String, Group> groupsByName; private AtomicLong groupsLastUpdate = new AtomicLong(); private final Map<Long, Position> positions = new ConcurrentHashMap<>(); @@ -245,15 +246,21 @@ public class DeviceManager implements IdentityManager { if (groupsById == null) { groupsById = new ConcurrentHashMap<>(databaseGroups.size()); } + if(groupsByName == null){ + groupsByName = new ConcurrentHashMap<>(databaseGroups.size()); + } Set<Long> databaseGroupsIds = new HashSet<>(); + Set<String> databaseGroupsNames = new HashSet<>(); for (Group group : databaseGroups) { databaseGroupsIds.add(group.getId()); + databaseGroupsNames.add(group.getName()); if (groupsById.containsKey(group.getId())) { Group cachedGroup = groupsById.get(group.getId()); cachedGroup.setName(group.getName()); cachedGroup.setGroupId(group.getGroupId()); } else { groupsById.put(group.getId(), group); + groupsByName.put(group.getName(), group); } } for (Long cachedGroupId : groupsById.keySet()) { @@ -269,6 +276,8 @@ public class DeviceManager implements IdentityManager { return groupsById.get(id); } + public Group getGroupByName(String name) { return groupsByName.get(name); } + public Collection<Group> getAllGroups() { boolean forceUpdate = groupsById.isEmpty(); |