diff options
author | Rafael Guterres <guterresrafael@gmail.com> | 2015-11-21 01:57:46 -0200 |
---|---|---|
committer | Rafael Guterres <guterresrafael@gmail.com> | 2015-11-21 01:57:46 -0200 |
commit | f5a266953e53a7f1785bcb584759582621ec9de3 (patch) | |
tree | 06aed01befc06db1384d731d5d17ee897335c302 /src/org/traccar/database | |
parent | cfe237cf26c6309b8431b3b81d589628ae363804 (diff) | |
download | traccar-server-f5a266953e53a7f1785bcb584759582621ec9de3.tar.gz traccar-server-f5a266953e53a7f1785bcb584759582621ec9de3.tar.bz2 traccar-server-f5a266953e53a7f1785bcb584759582621ec9de3.zip |
Add support to generic resources and refactor in classes to support types and commandpattern.
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r-- | src/org/traccar/database/DataManager.java | 39 | ||||
-rw-r--r-- | src/org/traccar/database/PermissionsManager.java | 12 |
2 files changed, 49 insertions, 2 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 24a07a05c..767582604 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -379,4 +379,43 @@ public class DataManager implements IdentityManager { .executeUpdate(); } + public void add(Object entity) throws SQLException { + if (entity instanceof User) { + addUser((User) entity); + } else if (entity instanceof Device) { + addDevice((Device) entity); + } else if (entity instanceof Position) { + addPosition((Position) entity); + } + } + + public void update(Object entity) throws SQLException { + if (entity instanceof User) { + updateUser((User) entity); + } else if (entity instanceof Device) { + updateDevice((Device) entity); + } else if (entity instanceof Server) { + updateServer((Server) entity); + } + } + + public void remove(Object entity) throws SQLException { + if (entity instanceof User) { + removeUser((User) entity); + } else if (entity instanceof Device) { + removeDevice((Device) entity); + } + } + + public void link(Class clazz, long userId, long entityId) throws SQLException { + if (clazz.equals(Device.class)) { + linkDevice(userId, entityId); + } + } + + public void unlink(Class clazz, long userId, long entityId) throws SQLException { + if (clazz.equals(Device.class)) { + unlinkDevice(userId, entityId); + } + } } diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java index a38a29c32..138641973 100644 --- a/src/org/traccar/database/PermissionsManager.java +++ b/src/org/traccar/database/PermissionsManager.java @@ -22,6 +22,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; import org.traccar.helper.Log; +import org.traccar.model.Device; import org.traccar.model.Permission; import org.traccar.model.User; @@ -66,7 +67,7 @@ public class PermissionsManager { } } - public void checkUser(long userId, long otherUserId) throws SecurityException { + private void checkUser(long userId, long otherUserId) throws SecurityException { if (userId != otherUserId) { checkAdmin(userId); } @@ -76,10 +77,17 @@ public class PermissionsManager { return getNotNull(userId); } - public void checkDevice(long userId, long deviceId) throws SecurityException { + private void checkDevice(long userId, long deviceId) throws SecurityException { if (!getNotNull(userId).contains(deviceId)) { throw new SecurityException("Device access denied"); } } + public <T> void check(Class<T> clazz, long userId, long entityId) throws SecurityException { + if (clazz.equals(User.class)) { + checkUser(userId, entityId); + } else if (clazz.equals(Device.class)) { + checkDevice(userId, entityId); + } + } } |