Skip to content

Commit

Permalink
Merge pull request #19 from gisaia/feature/getById
Browse files Browse the repository at this point in the history
Add endpoint "get by id"
  • Loading branch information
alainbodiguel authored Jul 22, 2020
2 parents 1cd7db9 + 8161696 commit c87e70e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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).";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c87e70e

Please sign in to comment.