use of org.apache.stanbol.entityhub.servicesapi.model.Entity in project stanbol by apache.
the class EntityhubRootResource method lookupSymbol.
@GET
@Path("lookup")
@Produces({ APPLICATION_JSON, RDF_XML, N3, TURTLE, X_TURTLE, RDF_JSON, N_TRIPLE, TEXT_HTML })
public Response lookupSymbol(@QueryParam("id") String reference, @QueryParam("create") boolean create, @Context HttpHeaders headers) throws WebApplicationException {
log.info("GET /lookup Request");
log.info(" > id: " + reference);
log.info(" > create : " + create);
log.info(" > accept: " + headers.getAcceptableMediaTypes());
MediaType acceptedMediaType = getAcceptableMediaType(headers, ENTITY_SUPPORTED_MEDIA_TYPE_INCL_HTML, APPLICATION_JSON_TYPE);
if (acceptedMediaType.isCompatible(TEXT_HTML_TYPE) && reference == null) {
//return docu
ResponseBuilder rb = Response.ok(new Viewable("lookup", this));
rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
//addCORSOrigin(servletContext, rb, headers);
return rb.build();
} else {
if (reference == null || reference.isEmpty()) {
// TODO: how to parse an error message
throw new WebApplicationException(BAD_REQUEST);
}
Entity entity;
try {
entity = entityhub.lookupLocalEntity(reference, create);
} catch (EntityhubException e) {
throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
}
if (entity == null) {
return Response.status(Status.NOT_FOUND).entity("No symbol found for '" + reference + "'.").header(HttpHeaders.ACCEPT, acceptedMediaType).build();
} else {
ResponseBuilder rb = Response.ok(entity);
rb.header(HttpHeaders.CONTENT_TYPE, acceptedMediaType + "; charset=utf-8");
//addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
}
}
Aggregations