aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database
diff options
context:
space:
mode:
authorRafael Guterres <guterresrafael@gmail.com>2015-11-27 03:32:59 -0200
committerRafael Guterres <guterresrafael@gmail.com>2015-11-27 03:32:59 -0200
commitc57bd2d472467b1b3a45aee1b97c9a0aeef5958a (patch)
tree26fae20adf1970b5834f06393a3c703c972f39b1 /src/org/traccar/database
parent77cd23da84ebebcf99a97a8aef88aa9a4884ca40 (diff)
downloadtraccar-server-c57bd2d472467b1b3a45aee1b97c9a0aeef5958a.tar.gz
traccar-server-c57bd2d472467b1b3a45aee1b97c9a0aeef5958a.tar.bz2
traccar-server-c57bd2d472467b1b3a45aee1b97c9a0aeef5958a.zip
Initial implementation of new api with jax-rs.
Revert servlets to old api and remove plurals. Fix findbugs for header origin.
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r--src/org/traccar/database/DataManager.java19
-rw-r--r--src/org/traccar/database/PermissionsManager.java4
2 files changed, 21 insertions, 2 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 530ec1779..c98a5ede7 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -31,6 +31,7 @@ import java.util.Map;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import org.traccar.Config;
+import org.traccar.helper.Clazz;
import org.traccar.helper.DriverDelegate;
import org.traccar.helper.Log;
import org.traccar.model.Device;
@@ -385,6 +386,24 @@ public class DataManager implements IdentityManager {
.executeUpdate();
}
+ public <T> Collection<T> get(Class<T> clazz) throws SQLException {
+ if (clazz.equals(User.class)) {
+ return (Collection<T>) getUsers();
+ } else if (clazz.equals(Device.class)) {
+ return (Collection<T>) getAllDevices();
+ }
+ return null;
+ }
+
+ public <T> T get(T entity) throws Exception {
+ if (entity instanceof User) {
+ return (T) getUser(Clazz.getId(entity));
+ } else if (entity instanceof Device) {
+ return (T) getDeviceById(Clazz.getId(entity));
+ }
+ return null;
+ }
+
public void add(Object entity) throws SQLException {
if (entity instanceof User) {
addUser((User) entity);
diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java
index 138641973..0a43f4ff4 100644
--- a/src/org/traccar/database/PermissionsManager.java
+++ b/src/org/traccar/database/PermissionsManager.java
@@ -67,7 +67,7 @@ public class PermissionsManager {
}
}
- private void checkUser(long userId, long otherUserId) throws SecurityException {
+ public void checkUser(long userId, long otherUserId) throws SecurityException {
if (userId != otherUserId) {
checkAdmin(userId);
}
@@ -77,7 +77,7 @@ public class PermissionsManager {
return getNotNull(userId);
}
- private void checkDevice(long userId, long deviceId) throws SecurityException {
+ public void checkDevice(long userId, long deviceId) throws SecurityException {
if (!getNotNull(userId).contains(deviceId)) {
throw new SecurityException("Device access denied");
}