use of org.apache.stanbol.reasoners.web.utils.ReasoningServiceResult in project stanbol by apache.
the class JobsResource method get.
/**
* To read a /reasoners job output.
*
* @param id
* @return
*/
@GET
@Path("/{jid}")
public Response get(@PathParam("jid") String id, @Context HttpHeaders headers) {
log.info("Pinging job {}", id);
// No id
if (id == null || id.equals("")) {
ResponseBuilder rb = Response.status(Status.BAD_REQUEST);
return rb.build();
}
JobManager m = getJobManager();
// If the job exists
if (m.hasJob(id)) {
log.info("Found job with id {}", id);
Future<?> f = m.ping(id);
if (f.isDone() && (!f.isCancelled())) {
/**
* We return OK with the result
*/
Object o;
try {
o = f.get();
if (o instanceof ReasoningServiceResult) {
log.debug("Is a ReasoningServiceResult");
ReasoningServiceResult<?> result = (ReasoningServiceResult<?>) o;
return new ResponseTaskBuilder(new JobResultResource(uriInfo, headers)).build(result);
} else {
log.error("Job {} does not belong to reasoners", id);
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
} catch (InterruptedException e) {
log.error("Error: ", e);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
} catch (ExecutionException e) {
log.error("Error: ", e);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
} else {
/**
* We return 404 with additional info
*/
String jobService = new StringBuilder().append(getPublicBaseUri()).append("jobs/").append(id).toString();
this.jobLocation = jobService;
Viewable viewable = new Viewable("404.ftl", this);
ResponseBuilder rb = Response.status(Status.NOT_FOUND);
rb.header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML + "; charset=utf-8");
rb.entity(viewable);
return rb.build();
}
} else {
log.info("No job found with id {}", id);
ResponseBuilder rb = Response.status(Status.NOT_FOUND);
rb.header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML + "; charset=utf-8");
return rb.build();
}
}
Aggregations