aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r--src/org/traccar/database/AttributesManager.java2
-rw-r--r--src/org/traccar/database/DataManager.java309
-rw-r--r--src/org/traccar/database/DeviceManager.java16
-rw-r--r--src/org/traccar/database/DriversManager.java4
-rw-r--r--src/org/traccar/database/ExtendedObjectManager.java4
-rw-r--r--src/org/traccar/database/GeofenceManager.java7
-rw-r--r--src/org/traccar/database/NotificationManager.java10
-rw-r--r--src/org/traccar/database/PermissionsManager.java62
-rw-r--r--src/org/traccar/database/SimpleObjectManager.java8
9 files changed, 88 insertions, 334 deletions
diff --git a/src/org/traccar/database/AttributesManager.java b/src/org/traccar/database/AttributesManager.java
index 88bedfba4..ebfdbc9b4 100644
--- a/src/org/traccar/database/AttributesManager.java
+++ b/src/org/traccar/database/AttributesManager.java
@@ -29,7 +29,7 @@ public class AttributesManager extends ExtendedObjectManager {
public AttributesManager(DataManager dataManager) {
super(dataManager, Attribute.class, AttributePermission.class, DeviceAttribute.class, GroupAttribute.class);
refreshItems();
- refresh();
+ refreshExtendedPermissions();
}
@Override
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 4bf4b1b9a..6c9cca86c 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -23,6 +23,7 @@ import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
+import java.util.Map;
import javax.naming.InitialContext;
import javax.sql.DataSource;
@@ -39,17 +40,12 @@ import org.traccar.Config;
import org.traccar.helper.Log;
import org.traccar.model.AttributeAlias;
import org.traccar.model.Device;
-import org.traccar.model.DevicePermission;
import org.traccar.model.Event;
-import org.traccar.model.Group;
-import org.traccar.model.GroupPermission;
import org.traccar.model.Identifiable;
-import org.traccar.model.Notification;
import org.traccar.model.Position;
import org.traccar.model.Server;
import org.traccar.model.Statistics;
import org.traccar.model.User;
-import org.traccar.model.UserPermission;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
@@ -153,17 +149,6 @@ public class DataManager {
}
}
- public Collection<User> getUsers() throws SQLException {
- return QueryBuilder.create(dataSource, getQuery("database.selectUsersAll"))
- .executeQuery(User.class);
- }
-
- public void addUser(User user) throws SQLException {
- user.setId(QueryBuilder.create(dataSource, getQuery("database.insertUser"), true)
- .setObject(user)
- .executeUpdate());
- }
-
public void updateUser(User user) throws SQLException {
QueryBuilder.create(dataSource, getQuery("database.updateUser"))
.setObject(user)
@@ -175,102 +160,12 @@ public class DataManager {
}
}
- public void removeUser(long userId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.deleteUser"))
- .setLong("id", userId)
- .executeUpdate();
- }
-
- public Collection<DevicePermission> getDevicePermissions() throws SQLException {
- return QueryBuilder.create(dataSource, getQuery("database.selectDevicePermissions"))
- .executeQuery(DevicePermission.class);
- }
-
- public Collection<GroupPermission> getGroupPermissions() throws SQLException {
- return QueryBuilder.create(dataSource, getQuery("database.selectGroupPermissions"))
- .executeQuery(GroupPermission.class);
- }
-
- public Collection<Device> getAllDevices() throws SQLException {
- return QueryBuilder.create(dataSource, getQuery("database.selectDevicesAll"))
- .executeQuery(Device.class);
- }
-
- public void addDevice(Device device) throws SQLException {
- device.setId(QueryBuilder.create(dataSource, getQuery("database.insertDevice"), true)
- .setObject(device)
- .executeUpdate());
- }
-
- public void updateDevice(Device device) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.updateDevice"))
- .setObject(device)
- .executeUpdate();
- }
-
public void updateDeviceStatus(Device device) throws SQLException {
QueryBuilder.create(dataSource, getQuery("database.updateDeviceStatus"))
.setObject(device)
.executeUpdate();
}
- public void removeDevice(long deviceId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.deleteDevice"))
- .setLong("id", deviceId)
- .executeUpdate();
- }
-
- public void linkDevice(long userId, long deviceId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.linkDevice"))
- .setLong("userId", userId)
- .setLong("deviceId", deviceId)
- .executeUpdate();
- }
-
- public void unlinkDevice(long userId, long deviceId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.unlinkDevice"))
- .setLong("userId", userId)
- .setLong("deviceId", deviceId)
- .executeUpdate();
- }
-
- public Collection<Group> getAllGroups() throws SQLException {
- return QueryBuilder.create(dataSource, getQuery("database.selectGroupsAll"))
- .executeQuery(Group.class);
- }
-
- public void addGroup(Group group) throws SQLException {
- group.setId(QueryBuilder.create(dataSource, getQuery("database.insertGroup"), true)
- .setObject(group)
- .executeUpdate());
- }
-
- public void updateGroup(Group group) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.updateGroup"))
- .setObject(group)
- .executeUpdate();
- }
-
- public void removeGroup(long groupId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.deleteGroup"))
- .setLong("id", groupId)
- .executeUpdate();
- }
-
- public void linkGroup(long userId, long groupId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.linkGroup"))
- .setLong("userId", userId)
- .setLong("groupId", groupId)
- .executeUpdate();
- }
-
- public void unlinkGroup(long userId, long groupId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.unlinkGroup"))
- .setLong("userId", userId)
- .setLong("groupId", groupId)
- .executeUpdate();
- }
-
public Collection<Position> getPositions(long deviceId, Date from, Date to) throws SQLException {
return QueryBuilder.create(dataSource, getQuery("database.selectPositions"))
.setLong("deviceId", deviceId)
@@ -323,24 +218,12 @@ public class DataManager {
.executeQuerySingle(Server.class);
}
- public void updateServer(Server server) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.updateServer"))
- .setObject(server)
- .executeUpdate();
- }
-
public Event getEvent(long eventId) throws SQLException {
return QueryBuilder.create(dataSource, getQuery("database.selectEvent"))
.setLong("id", eventId)
.executeQuerySingle(Event.class);
}
- public void addEvent(Event event) throws SQLException {
- event.setId(QueryBuilder.create(dataSource, getQuery("database.insertEvent"), true)
- .setObject(event)
- .executeUpdate());
- }
-
public Collection<Event> getEvents(long deviceId, Date from, Date to) throws SQLException {
return QueryBuilder.create(dataSource, getQuery("database.selectEvents"))
.setLong("deviceId", deviceId)
@@ -349,71 +232,6 @@ public class DataManager {
.executeQuery(Event.class);
}
- public void linkGeofence(long userId, long geofenceId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.linkGeofence"))
- .setLong("userId", userId)
- .setLong("geofenceId", geofenceId)
- .executeUpdate();
- }
-
- public void unlinkGeofence(long userId, long geofenceId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.unlinkGeofence"))
- .setLong("userId", userId)
- .setLong("geofenceId", geofenceId)
- .executeUpdate();
- }
-
- public void linkGroupGeofence(long groupId, long geofenceId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.linkGroupGeofence"))
- .setLong("groupId", groupId)
- .setLong("geofenceId", geofenceId)
- .executeUpdate();
- }
-
- public void unlinkGroupGeofence(long groupId, long geofenceId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.unlinkGroupGeofence"))
- .setLong("groupId", groupId)
- .setLong("geofenceId", geofenceId)
- .executeUpdate();
- }
-
- public void linkDeviceGeofence(long deviceId, long geofenceId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.linkDeviceGeofence"))
- .setLong("deviceId", deviceId)
- .setLong("geofenceId", geofenceId)
- .executeUpdate();
- }
-
- public void unlinkDeviceGeofence(long deviceId, long geofenceId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.unlinkDeviceGeofence"))
- .setLong("deviceId", deviceId)
- .setLong("geofenceId", geofenceId)
- .executeUpdate();
- }
-
- public Collection<Notification> getNotifications() throws SQLException {
- return QueryBuilder.create(dataSource, getQuery("database.selectNotifications"))
- .executeQuery(Notification.class);
- }
-
- public void addNotification(Notification notification) throws SQLException {
- notification.setId(QueryBuilder.create(dataSource, getQuery("database.insertNotification"), true)
- .setObject(notification)
- .executeUpdate());
- }
-
- public void updateNotification(Notification notification) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.updateNotification"))
- .setObject(notification)
- .executeUpdate();
- }
-
- public void removeNotification(Notification notification) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.deleteNotification"))
- .setLong("id", notification.getId())
- .executeUpdate();
- }
-
public Collection<AttributeAlias> getAttributeAliases() throws SQLException {
return QueryBuilder.create(dataSource, getQuery("database.selectAttributeAliases"))
.executeQuery(AttributeAlias.class);
@@ -450,121 +268,16 @@ public class DataManager {
.executeUpdate());
}
- public void linkCalendar(long userId, long calendarId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.linkCalendar"))
- .setLong("userId", userId)
- .setLong("calendarId", calendarId)
- .executeUpdate();
- }
-
- public void unlinkCalendar(long userId, long calendarId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.unlinkCalendar"))
- .setLong("userId", userId)
- .setLong("calendarId", calendarId)
- .executeUpdate();
- }
-
- public Collection<UserPermission> getUserPermissions() throws SQLException {
- return QueryBuilder.create(dataSource, getQuery("database.selectUserPermissions"))
- .executeQuery(UserPermission.class);
- }
-
- public void linkUser(long userId, long managedUserId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.linkUser"))
- .setLong("userId", userId)
- .setLong("managedUserId", managedUserId)
- .executeUpdate();
- }
-
- public void unlinkUser(long userId, long managedUserId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.unlinkUser"))
- .setLong("userId", userId)
- .setLong("managedUserId", managedUserId)
- .executeUpdate();
- }
-
- public void linkAttribute(long userId, long attributeId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.linkAttribute"))
- .setLong("userId", userId)
- .setLong("attributeId", attributeId)
- .executeUpdate();
- }
-
- public void unlinkAttribute(long userId, long attributeId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.unlinkAttribute"))
- .setLong("userId", userId)
- .setLong("attributeId", attributeId)
- .executeUpdate();
- }
-
- public void linkGroupAttribute(long groupId, long attributeId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.linkGroupAttribute"))
- .setLong("groupId", groupId)
- .setLong("attributeId", attributeId)
- .executeUpdate();
- }
-
- public void unlinkGroupAttribute(long groupId, long attributeId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.unlinkGroupAttribute"))
- .setLong("groupId", groupId)
- .setLong("attributeId", attributeId)
- .executeUpdate();
- }
-
- public void linkDeviceAttribute(long deviceId, long attributeId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.linkDeviceAttribute"))
- .setLong("deviceId", deviceId)
- .setLong("attributeId", attributeId)
- .executeUpdate();
- }
-
- public void unlinkDeviceAttribute(long deviceId, long attributeId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.unlinkDeviceAttribute"))
- .setLong("deviceId", deviceId)
- .setLong("attributeId", attributeId)
- .executeUpdate();
- }
-
- public void linkDriver(long userId, long driverId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.linkDriver"))
- .setLong("userId", userId)
- .setLong("driverId", driverId)
- .executeUpdate();
- }
-
- public void unlinkDriver(long userId, long driverId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.unlinkDriver"))
- .setLong("userId", userId)
- .setLong("driverId", driverId)
- .executeUpdate();
- }
-
- public void linkGroupDriver(long groupId, long driverId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.linkGroupDriver"))
- .setLong("groupId", groupId)
- .setLong("driverId", driverId)
- .executeUpdate();
- }
-
- public void unlinkGroupDriver(long groupId, long driverId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.unlinkGroupDriver"))
- .setLong("groupId", groupId)
- .setLong("driverId", driverId)
- .executeUpdate();
- }
-
- public void linkDeviceDriver(long deviceId, long driverId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.linkDeviceDriver"))
- .setLong("deviceId", deviceId)
- .setLong("driverId", driverId)
- .executeUpdate();
- }
-
- public void unlinkDeviceDriver(long deviceId, long driverId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.unlinkDeviceDriver"))
- .setLong("deviceId", deviceId)
- .setLong("driverId", driverId)
- .executeUpdate();
+ public void linkObject(Map<String, Long> permission, boolean link) throws SQLException {
+ String query = "database." + (!link ? "un" : "") + "link";
+ for (String key : permission.keySet()) {
+ query += key.substring(0, 1).toUpperCase() + key.replace("Id", "").substring(1);
+ }
+ QueryBuilder queryBuilder = QueryBuilder.create(dataSource, getQuery(query));
+ for (String key : permission.keySet()) {
+ queryBuilder.setLong(key, permission.get(key));
+ }
+ queryBuilder.executeUpdate();
}
public <T> Collection<T> getObjects(Class<T> clazz) throws SQLException {
diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java
index f2a2dd565..ba360f165 100644
--- a/src/org/traccar/database/DeviceManager.java
+++ b/src/org/traccar/database/DeviceManager.java
@@ -85,7 +85,7 @@ public class DeviceManager implements IdentityManager {
if ((force || System.currentTimeMillis() - lastUpdate > dataRefreshDelay)
&& devicesLastUpdate.compareAndSet(lastUpdate, System.currentTimeMillis())) {
GeofenceManager geofenceManager = Context.getGeofenceManager();
- Collection<Device> databaseDevices = dataManager.getAllDevices();
+ Collection<Device> databaseDevices = dataManager.getObjects(Device.class);
if (devicesById == null) {
devicesById = new ConcurrentHashMap<>(databaseDevices.size());
}
@@ -199,7 +199,7 @@ public class DeviceManager implements IdentityManager {
}
public void addDevice(Device device) throws SQLException {
- dataManager.addDevice(device);
+ dataManager.addObject(device);
devicesById.put(device.getId(), device);
devicesByUniqueId.put(device.getUniqueId(), device);
@@ -209,7 +209,7 @@ public class DeviceManager implements IdentityManager {
}
public void updateDevice(Device device) throws SQLException {
- dataManager.updateDevice(device);
+ dataManager.updateObject(device);
devicesById.put(device.getId(), device);
devicesByUniqueId.put(device.getUniqueId(), device);
@@ -227,7 +227,7 @@ public class DeviceManager implements IdentityManager {
}
public void removeDevice(long deviceId) throws SQLException {
- dataManager.removeDevice(deviceId);
+ dataManager.removeObject(Device.class, deviceId);
if (devicesById.containsKey(deviceId)) {
String deviceUniqueId = devicesById.get(deviceId).getUniqueId();
@@ -289,7 +289,7 @@ public class DeviceManager implements IdentityManager {
long lastUpdate = groupsLastUpdate.get();
if ((force || System.currentTimeMillis() - lastUpdate > dataRefreshDelay)
&& groupsLastUpdate.compareAndSet(lastUpdate, System.currentTimeMillis())) {
- Collection<Group> databaseGroups = dataManager.getAllGroups();
+ Collection<Group> databaseGroups = dataManager.getObjects(Group.class);
if (groupsById == null) {
groupsById = new ConcurrentHashMap<>(databaseGroups.size());
}
@@ -359,18 +359,18 @@ public class DeviceManager implements IdentityManager {
public void addGroup(Group group) throws SQLException {
checkGroupCycles(group);
- dataManager.addGroup(group);
+ dataManager.addObject(group);
groupsById.put(group.getId(), group);
}
public void updateGroup(Group group) throws SQLException {
checkGroupCycles(group);
- dataManager.updateGroup(group);
+ dataManager.updateObject(group);
groupsById.put(group.getId(), group);
}
public void removeGroup(long groupId) throws SQLException {
- dataManager.removeGroup(groupId);
+ dataManager.removeObject(Group.class, groupId);
groupsById.remove(groupId);
}
diff --git a/src/org/traccar/database/DriversManager.java b/src/org/traccar/database/DriversManager.java
index 391708f64..9b01f1a70 100644
--- a/src/org/traccar/database/DriversManager.java
+++ b/src/org/traccar/database/DriversManager.java
@@ -34,7 +34,7 @@ public class DriversManager extends ExtendedObjectManager {
public DriversManager(DataManager dataManager) {
super(dataManager, Driver.class, DriverPermission.class, DeviceDriver.class, GroupDriver.class);
refreshItems();
- refresh();
+ refreshExtendedPermissions();
}
@Override
@@ -83,7 +83,7 @@ public class DriversManager extends ExtendedObjectManager {
driversByUniqueId.remove(driverUniqueId);
}
refreshUserItems();
- refresh();
+ refreshExtendedPermissions();
}
public Driver getDriverByUniqueId(String uniqueId) {
diff --git a/src/org/traccar/database/ExtendedObjectManager.java b/src/org/traccar/database/ExtendedObjectManager.java
index 5147b9f9f..a6508f066 100644
--- a/src/org/traccar/database/ExtendedObjectManager.java
+++ b/src/org/traccar/database/ExtendedObjectManager.java
@@ -82,10 +82,10 @@ public abstract class ExtendedObjectManager extends SimpleObjectManager {
@Override
public void removeItem(long itemId) throws SQLException {
super.removeItem(itemId);
- refresh();
+ refreshExtendedPermissions();
}
- public void refresh() {
+ public void refreshExtendedPermissions() {
if (getDataManager() != null) {
try {
diff --git a/src/org/traccar/database/GeofenceManager.java b/src/org/traccar/database/GeofenceManager.java
index 868804d8f..ed1f26f78 100644
--- a/src/org/traccar/database/GeofenceManager.java
+++ b/src/org/traccar/database/GeofenceManager.java
@@ -31,11 +31,12 @@ public class GeofenceManager extends ExtendedObjectManager {
public GeofenceManager(DataManager dataManager) {
super(dataManager, Geofence.class, GeofencePermission.class, DeviceGeofence.class, GroupGeofence.class);
refreshItems();
- refresh();
+ refreshExtendedPermissions();
}
- public final void refresh() {
- super.refresh();
+ @Override
+ public final void refreshExtendedPermissions() {
+ super.refreshExtendedPermissions();
recalculateDevicesGeofences();
}
diff --git a/src/org/traccar/database/NotificationManager.java b/src/org/traccar/database/NotificationManager.java
index 11d5a9aca..0987f255b 100644
--- a/src/org/traccar/database/NotificationManager.java
+++ b/src/org/traccar/database/NotificationManager.java
@@ -49,7 +49,7 @@ public class NotificationManager {
public void updateEvent(Event event, Position position) {
try {
- dataManager.addEvent(event);
+ dataManager.addObject(event);
} catch (SQLException error) {
Log.warning(error);
}
@@ -105,7 +105,7 @@ public class NotificationManager {
notificationsLock.writeLock().lock();
try {
userNotifications.clear();
- for (Notification notification : dataManager.getNotifications()) {
+ for (Notification notification : dataManager.getObjects(Notification.class)) {
getUserNotificationsUnsafe(notification.getUserId()).add(notification);
}
} finally {
@@ -139,7 +139,7 @@ public class NotificationManager {
|| cachedNotification.getSms() != notification.getSms()) {
if (!notification.getWeb() && !notification.getMail() && !notification.getSms()) {
try {
- dataManager.removeNotification(cachedNotification);
+ dataManager.removeObject(Notification.class, cachedNotification.getId());
} catch (SQLException error) {
Log.warning(error);
}
@@ -160,7 +160,7 @@ public class NotificationManager {
notificationsLock.writeLock().unlock();
}
try {
- dataManager.updateNotification(cachedNotification);
+ dataManager.updateObject(cachedNotification);
} catch (SQLException error) {
Log.warning(error);
}
@@ -170,7 +170,7 @@ public class NotificationManager {
}
} else if (notification.getWeb() || notification.getMail() || notification.getSms()) {
try {
- dataManager.addNotification(notification);
+ dataManager.addObject(notification);
} catch (SQLException error) {
Log.warning(error);
}
diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java
index f88e14bfe..caae86b84 100644
--- a/src/org/traccar/database/PermissionsManager.java
+++ b/src/org/traccar/database/PermissionsManager.java
@@ -98,7 +98,7 @@ public class PermissionsManager {
usersTokens.clear();
try {
server = dataManager.getServer();
- for (User user : dataManager.getUsers()) {
+ for (User user : dataManager.getObjects(User.class)) {
users.put(user.getId(), user);
if (user.getToken() != null) {
usersTokens.put(user.getToken(), user.getId());
@@ -112,7 +112,7 @@ public class PermissionsManager {
public final void refreshUserPermissions() {
userPermissions.clear();
try {
- for (UserPermission permission : dataManager.getUserPermissions()) {
+ for (UserPermission permission : dataManager.getObjects(UserPermission.class)) {
getUserPermissions(permission.getUserId()).add(permission.getManagedUserId());
}
} catch (SQLException error) {
@@ -126,7 +126,7 @@ public class PermissionsManager {
try {
GroupTree groupTree = new GroupTree(Context.getDeviceManager().getAllGroups(),
Context.getDeviceManager().getAllDevices());
- for (GroupPermission permission : dataManager.getGroupPermissions()) {
+ for (GroupPermission permission : dataManager.getObjects(GroupPermission.class)) {
Set<Long> userGroupPermissions = getGroupPermissions(permission.getUserId());
Set<Long> userDevicePermissions = getDevicePermissions(permission.getUserId());
userGroupPermissions.add(permission.getGroupId());
@@ -137,7 +137,7 @@ public class PermissionsManager {
userDevicePermissions.add(device.getId());
}
}
- for (DevicePermission permission : dataManager.getDevicePermissions()) {
+ for (DevicePermission permission : dataManager.getObjects(DevicePermission.class)) {
getDevicePermissions(permission.getUserId()).add(permission.getDeviceId());
}
@@ -302,6 +302,15 @@ public class PermissionsManager {
SimpleObjectManager manager = null;
switch (object) {
+ case "device":
+ checkDevice(userId, objectId);
+ break;
+ case "group":
+ checkGroup(userId, objectId);
+ break;
+ case "user":
+ checkUser(userId, objectId);
+ break;
case "geofence":
manager = Context.getGeofenceManager();
break;
@@ -332,12 +341,51 @@ public class PermissionsManager {
}
}
+ public void refreshAllExtendedPermissions() {
+ if (Context.getGeofenceManager() != null) {
+ Context.getGeofenceManager().refreshExtendedPermissions();
+ }
+ Context.getDriversManager().refreshExtendedPermissions();
+ Context.getAttributesManager().refreshExtendedPermissions();
+ }
+
+ public void refreshPermissions(Map<String, Long> entity) {
+ if (entity.containsKey("userId")) {
+ if (entity.containsKey("deviceId") || entity.containsKey("groupId")) {
+ refreshPermissions();
+ refreshAllExtendedPermissions();
+ } else if (entity.containsKey("managedUserId")) {
+ refreshUserPermissions();
+ } else if (entity.containsKey("geofenceId")) {
+ if (Context.getGeofenceManager() != null) {
+ Context.getGeofenceManager().refreshUserItems();
+ }
+ } else if (entity.containsKey("driverId")) {
+ Context.getDriversManager().refreshUserItems();
+ } else if (entity.containsKey("attributeId")) {
+ Context.getAttributesManager().refreshUserItems();
+ } else if (entity.containsKey("calendarId")) {
+ Context.getCalendarManager().refreshUserItems();
+ }
+ } else if (entity.containsKey("deviceId") || entity.containsKey("groupId")) {
+ if (entity.containsKey("geofenceId")) {
+ if (Context.getGeofenceManager() != null) {
+ Context.getGeofenceManager().refreshExtendedPermissions();
+ }
+ } else if (entity.containsKey("driverId")) {
+ Context.getDriversManager().refreshExtendedPermissions();
+ } else if (entity.containsKey("attributeId")) {
+ Context.getAttributesManager().refreshExtendedPermissions();
+ }
+ }
+ }
+
public Server getServer() {
return server;
}
public void updateServer(Server server) throws SQLException {
- dataManager.updateServer(server);
+ dataManager.updateObject(server);
this.server = server;
}
@@ -364,7 +412,7 @@ public class PermissionsManager {
}
public void addUser(User user) throws SQLException {
- dataManager.addUser(user);
+ dataManager.addObject(user);
users.put(user.getId(), user);
if (user.getToken() != null) {
usersTokens.put(user.getToken(), user.getId());
@@ -386,7 +434,7 @@ public class PermissionsManager {
}
public void removeUser(long userId) throws SQLException {
- dataManager.removeUser(userId);
+ dataManager.removeObject(User.class, userId);
usersTokens.remove(users.get(userId).getToken());
users.remove(userId);
refreshPermissions();
diff --git a/src/org/traccar/database/SimpleObjectManager.java b/src/org/traccar/database/SimpleObjectManager.java
index 84d41a84f..f5f807850 100644
--- a/src/org/traccar/database/SimpleObjectManager.java
+++ b/src/org/traccar/database/SimpleObjectManager.java
@@ -132,14 +132,6 @@ public abstract class SimpleObjectManager {
refreshUserItems();
}
-// public final Collection<? extends Identifiable> getItems(Set<Long> itemIds) {
-// Collection<Identifiable> result = new LinkedList<>();
-// for (long itemId : itemIds) {
-// result.add(getById(itemId));
-// }
-// return result;
-// }
-
public final <T> Collection<T> getItems(Class<T> clazz, Set<Long> itemIds) {
Collection<T> result = new LinkedList<>();
for (long itemId : itemIds) {