aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-06-21 16:35:46 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2020-06-21 16:35:46 -0700
commitadd1194484bc24ff335818e1a878942cc22f7ff3 (patch)
tree0d12bd4fc708ff473ebd393d451eefad7e7e11cf /src/main/java
parentd9d4cc75b78f8094d0ed029d61b6a37733186548 (diff)
downloadtrackermap-server-add1194484bc24ff335818e1a878942cc22f7ff3.tar.gz
trackermap-server-add1194484bc24ff335818e1a878942cc22f7ff3.tar.bz2
trackermap-server-add1194484bc24ff335818e1a878942cc22f7ff3.zip
Add single object GET API
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/traccar/api/BaseObjectResource.java18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/api/BaseObjectResource.java b/src/main/java/org/traccar/api/BaseObjectResource.java
index 7de6a3877..c4206f385 100644
--- a/src/main/java/org/traccar/api/BaseObjectResource.java
+++ b/src/main/java/org/traccar/api/BaseObjectResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2020 Anton Tananaev (anton@traccar.org)
* Copyright 2017 - 2018 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,6 +20,7 @@ import java.sql.SQLException;
import java.util.Set;
import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
@@ -54,7 +55,7 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour
}
protected final Set<Long> getSimpleManagerItems(BaseObjectManager<T> manager, boolean all, long userId) {
- Set<Long> result = null;
+ Set<Long> result;
if (all) {
if (Context.getPermissionsManager().getUserAdmin(getUserId())) {
result = manager.getAllItems();
@@ -72,6 +73,19 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour
return result;
}
+ @Path("{id}")
+ @GET
+ public Response add(@PathParam("id") long id) throws SQLException {
+ Context.getPermissionsManager().checkPermission(baseClass, getUserId(), id);
+ BaseObjectManager<T> manager = Context.getManager(baseClass);
+ T entity = manager.getById(id);
+ if (entity != null) {
+ return Response.ok(entity).build();
+ } else {
+ return Response.status(Response.Status.NOT_FOUND).build();
+ }
+ }
+
@POST
public Response add(T entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());