com.github.trepo.dcap.server.rest.Get Maven / Gradle / Ivy
The newest version!
package com.github.trepo.dcap.server.rest;
import com.github.trepo.dcap.store.Store;
import com.github.trepo.vgraph.Commit;
import com.google.gson.Gson;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
/**
* Get a commit.
* @author John Clark.
*/
@Path("/{commit}")
public class Get {
/**
* Gson instance for serialization.
*/
private Gson gson = new Gson();
/**
* The commit store to use.
*/
private Store store;
/**
* Get a commit.
* @param commitId The id of the commit to get.
* @return The commit, or 404.
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response get(@PathParam("commit") String commitId) {
Commit commit = store.get(commitId);
if (commit == null) {
throw new WebApplicationException("Commit not Found", Response.Status.NOT_FOUND);
}
return Response
.status(Response.Status.OK)
.entity(gson.toJson(commit))
.build();
}
/**
* Sets the Commit Store to use via Injection.
* @param commitStore The commit store.
*/
@Inject
public void setStore(Store commitStore) {
store = commitStore;
}
}