From a10033d165293c349fc513e049583d3c0ac3e06c Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 16 Oct 2018 15:28:48 +1300 Subject: Simplify base decoder dependencies --- src/org/traccar/database/DeviceManager.java | 29 +++++++++++++++++++++++++++ src/org/traccar/database/IdentityManager.java | 2 ++ 2 files changed, 31 insertions(+) (limited to 'src/org/traccar/database') 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 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; -- cgit v1.2.3