From 0da1f5da4e5e0e39259ab3333c1273ba5cb382a7 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 28 Jul 2017 10:43:21 +0500 Subject: Combine some GET functions --- src/org/traccar/api/BaseObjectResource.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/org/traccar/api/BaseObjectResource.java') 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 extends BaseResour this.baseClass = baseClass; } + protected final Class getBaseClass() { + return baseClass; + } + + protected final Set getSimpleManagerItems(BaseObjectManager manager, boolean all, long userId) { + Set 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()); -- cgit v1.2.3