aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-10-16 15:28:48 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2018-10-16 15:28:48 +1300
commita10033d165293c349fc513e049583d3c0ac3e06c (patch)
tree3117a309b28b55e47396429272206a93570af7d3 /src/org/traccar/database
parent017fbd08ecbffecd1557ec022d5adc49af73300c (diff)
downloadtraccar-server-a10033d165293c349fc513e049583d3c0ac3e06c.tar.gz
traccar-server-a10033d165293c349fc513e049583d3c0ac3e06c.tar.bz2
traccar-server-a10033d165293c349fc513e049583d3c0ac3e06c.zip
Simplify base decoder dependencies
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r--src/org/traccar/database/DeviceManager.java29
-rw-r--r--src/org/traccar/database/IdentityManager.java2
2 files changed, 31 insertions, 0 deletions
diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java
index 34b02c0e2..ab2c142cc 100644
--- a/src/org/traccar/database/DeviceManager.java
+++ b/src/org/traccar/database/DeviceManager.java
@@ -68,6 +68,35 @@ public class DeviceManager extends BaseObjectManager<Device> implements Identity
refreshLastPositions();
}
+ @Override
+ public long addUnknownDevice(String uniqueId) {
+ Device device = new Device();
+ device.setName(uniqueId);
+ device.setUniqueId(uniqueId);
+ device.setCategory(Context.getConfig().getString("database.registerUnknown.defaultCategory"));
+
+ long defaultGroupId = Context.getConfig().getLong("database.registerUnknown.defaultGroupId");
+ if (defaultGroupId != 0) {
+ device.setGroupId(defaultGroupId);
+ }
+
+ try {
+ addItem(device);
+
+ LOGGER.info("Automatically registered device " + uniqueId);
+
+ if (defaultGroupId != 0) {
+ Context.getPermissionsManager().refreshDeviceAndGroupPermissions();
+ Context.getPermissionsManager().refreshAllExtendedPermissions();
+ }
+
+ return device.getId();
+ } catch (SQLException e) {
+ LOGGER.warn("Automatic device registration error", e);
+ return 0;
+ }
+ }
+
public void updateDeviceCache(boolean force) throws SQLException {
long lastUpdate = devicesLastUpdate.get();
if ((force || System.currentTimeMillis() - lastUpdate > dataRefreshDelay)
diff --git a/src/org/traccar/database/IdentityManager.java b/src/org/traccar/database/IdentityManager.java
index 82d905963..59d2f9362 100644
--- a/src/org/traccar/database/IdentityManager.java
+++ b/src/org/traccar/database/IdentityManager.java
@@ -20,6 +20,8 @@ import org.traccar.model.Position;
public interface IdentityManager {
+ long addUnknownDevice(String uniqueId);
+
Device getById(long id);
Device getByUniqueId(String uniqueId) throws Exception;