aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/api/BaseObjectResource.java
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-07-28 10:43:21 +0500
committerAbyss777 <abyss@fox5.ru>2017-07-28 10:50:14 +0500
commit0da1f5da4e5e0e39259ab3333c1273ba5cb382a7 (patch)
tree1e3f55166e922ab43c0be495abed71e536fdc216 /src/org/traccar/api/BaseObjectResource.java
parentd3021c9ae11b177fe05b79e98f1e560e8c3cbaf5 (diff)
downloadtrackermap-server-0da1f5da4e5e0e39259ab3333c1273ba5cb382a7.tar.gz
trackermap-server-0da1f5da4e5e0e39259ab3333c1273ba5cb382a7.tar.bz2
trackermap-server-0da1f5da4e5e0e39259ab3333c1273ba5cb382a7.zip
Combine some GET functions
Diffstat (limited to 'src/org/traccar/api/BaseObjectResource.java')
-rw-r--r--src/org/traccar/api/BaseObjectResource.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/org/traccar/api/BaseObjectResource.java b/src/org/traccar/api/BaseObjectResource.java
index 4475e3b4d..a1b90bc28 100644
--- a/src/org/traccar/api/BaseObjectResource.java
+++ b/src/org/traccar/api/BaseObjectResource.java
@@ -17,6 +17,7 @@
package org.traccar.api;
import java.sql.SQLException;
+import java.util.Set;
import javax.ws.rs.DELETE;
import javax.ws.rs.POST;
@@ -28,6 +29,7 @@ import javax.ws.rs.core.Response;
import org.traccar.Context;
import org.traccar.database.BaseObjectManager;
import org.traccar.database.ExtendedObjectManager;
+import org.traccar.database.ManagableObjects;
import org.traccar.database.SimpleObjectManager;
import org.traccar.model.BaseModel;
import org.traccar.model.Device;
@@ -42,6 +44,29 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour
this.baseClass = baseClass;
}
+ protected final Class<T> getBaseClass() {
+ return baseClass;
+ }
+
+ protected final Set<Long> getSimpleManagerItems(BaseObjectManager<T> manager, boolean all, long userId) {
+ Set<Long> result = null;
+ if (all) {
+ if (Context.getPermissionsManager().isAdmin(getUserId())) {
+ result = manager.getAllItems();
+ } else {
+ Context.getPermissionsManager().checkManager(getUserId());
+ result = ((ManagableObjects) manager).getManagedItems(getUserId());
+ }
+ } else {
+ if (userId == 0) {
+ userId = getUserId();
+ }
+ Context.getPermissionsManager().checkUser(getUserId(), userId);
+ result = ((ManagableObjects) manager).getUserItems(userId);
+ }
+ return result;
+ }
+
@POST
public Response add(T entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());