aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/api/BaseObjectResource.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-07-28 20:01:19 +1200
committerGitHub <noreply@github.com>2017-07-28 20:01:19 +1200
commitb6694bf035aa3dd8595c9d24fa88a93abf7676d6 (patch)
tree1e3f55166e922ab43c0be495abed71e536fdc216 /src/org/traccar/api/BaseObjectResource.java
parentd3021c9ae11b177fe05b79e98f1e560e8c3cbaf5 (diff)
parent0da1f5da4e5e0e39259ab3333c1273ba5cb382a7 (diff)
downloadtrackermap-server-b6694bf035aa3dd8595c9d24fa88a93abf7676d6.tar.gz
trackermap-server-b6694bf035aa3dd8595c9d24fa88a93abf7676d6.tar.bz2
trackermap-server-b6694bf035aa3dd8595c9d24fa88a93abf7676d6.zip
Merge pull request #3399 from Abyss777/optimize_get
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());