diff --git a/arlas-persistence-core/src/main/java/io/arlas/persistence/server/app/Documentation.java b/arlas-persistence-core/src/main/java/io/arlas/persistence/server/app/Documentation.java index 352f970..66335d1 100644 --- a/arlas-persistence-core/src/main/java/io/arlas/persistence/server/app/Documentation.java +++ b/arlas-persistence-core/src/main/java/io/arlas/persistence/server/app/Documentation.java @@ -27,6 +27,7 @@ public class Documentation { public static final String ZONE = "Zone of the document."; public static final String LIST_OPERATION = "Fetch a list of data related to a zone."; public static final String GET_GROUPS_OPERATION = "Returns the users' groups allowed to interact with the given zone."; + public static final String GET_FROM_ID_OPERATION = "Fetch an entry given its id."; public static final String GET_FROM_KEY_ZONE_OPERATION = "Fetch an entry given its zone and key."; public static final String DELETE_OPERATION = "Delete an entry given its key and id."; public static final String CREATE_OPERATION = "Store a new piece of data for the provided zone and key (auto generate id)."; diff --git a/arlas-persistence-core/src/main/java/io/arlas/persistence/server/impl/GoogleFirestorePersistenceServiceImpl.java b/arlas-persistence-core/src/main/java/io/arlas/persistence/server/impl/GoogleFirestorePersistenceServiceImpl.java index 4eab8d3..845a8bb 100644 --- a/arlas-persistence-core/src/main/java/io/arlas/persistence/server/impl/GoogleFirestorePersistenceServiceImpl.java +++ b/arlas-persistence-core/src/main/java/io/arlas/persistence/server/impl/GoogleFirestorePersistenceServiceImpl.java @@ -199,7 +199,7 @@ public Data getById(String id, IdentityParam identityParam) throws ArlasExceptio PersistenceService.isWriterOnData(identityParam, data)) { return data; } else { - throw new ForbidenException("You are not authorized to delete this resource"); + throw new ForbidenException("You are not authorized to get this resource"); } } diff --git a/arlas-persistence-rest/src/main/java/io/arlas/persistence/rest/PersistenceRestService.java b/arlas-persistence-rest/src/main/java/io/arlas/persistence/rest/PersistenceRestService.java index e2a5265..59c6dbe 100644 --- a/arlas-persistence-rest/src/main/java/io/arlas/persistence/rest/PersistenceRestService.java +++ b/arlas-persistence-rest/src/main/java/io/arlas/persistence/rest/PersistenceRestService.java @@ -173,6 +173,44 @@ public Response get( return ResponseFormatter.getResultResponse(halService.dataWithLinks(dataWithLinks, uriInfo, identityparam)); } + @Timed + @Path("resources/{id}") + @GET + @Produces(UTF8JSON) + @Consumes(UTF8JSON) + @ApiOperation( + value = Documentation.GET_FROM_ID_OPERATION, + produces = UTF8JSON, + notes = Documentation.GET_FROM_ID_OPERATION, + consumes = UTF8JSON + ) + @ApiResponses(value = {@ApiResponse(code = 200, message = "Successful operation", response = DataWithLinks.class), + @ApiResponse(code = 404, message = "Id not found.", response = Error.class), + @ApiResponse(code = 500, message = "Arlas Persistence Error.", response = Error.class)}) + + @UnitOfWork + public Response get( + @Context UriInfo uriInfo, + @Context HttpHeaders headers, + + @ApiParam(name = "id", + value = Documentation.ID, + required = true) + @PathParam(value = "id") String id, + + + // -------------------------------------------------------- + // ----------------------- FORM ----------------------- + // -------------------------------------------------------- + @ApiParam(name = "pretty", value = io.arlas.server.app.Documentation.FORM_PRETTY, + defaultValue = "false") + @QueryParam(value = "pretty") Boolean pretty + ) throws ArlasException { + IdentityParam identityparam = getIdentityParam(headers); + DataWithLinks dataWithLinks = new DataWithLinks(persistenceService.getById(id, identityparam), identityparam); + return ResponseFormatter.getResultResponse(halService.dataWithLinks(dataWithLinks, uriInfo, identityparam)); + } + @Timed @Path("groups/{zone}") @GET