use of org.apache.stanbol.entityhub.servicesapi.site.SiteException in project stanbol by apache.
the class ReferencedSiteRootResource method getEntityById.
/**
* Cool URI handler for Signs.
*
* @param id
* The id of the entity (required)
* @param headers
* the request headers used to get the requested {@link MediaType}
* @return a redirection to either a browser view, the RDF meta data or the raw binary content
*/
@GET
@Path("/entity")
public Response getEntityById(@PathParam(value = "site") String siteId, @QueryParam(value = "id") String id, @Context HttpHeaders headers) {
Site site = getSite(siteId);
log.debug("site/{}/entity Request", site.getId());
log.debug(" > id : " + id);
log.debug(" > accept : " + headers.getAcceptableMediaTypes());
log.debug(" > mediaType: " + headers.getMediaType());
Collection<String> supported = new HashSet<String>(JerseyUtils.ENTITY_SUPPORTED_MEDIA_TYPES);
supported.add(TEXT_HTML);
final MediaType acceptedMediaType = getAcceptableMediaType(headers, supported, MediaType.APPLICATION_JSON_TYPE);
if (id == null || id.isEmpty()) {
if (MediaType.TEXT_HTML_TYPE.isCompatible(acceptedMediaType)) {
ResponseBuilder rb = Response.ok(new Viewable("entity", new SiteResultData(site)));
rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
// addCORSOrigin(servletContext, rb, headers);
return rb.build();
} else {
return Response.status(Status.BAD_REQUEST).entity("No or empty ID was parsed. Missing parameter id.\n").header(HttpHeaders.ACCEPT, acceptedMediaType).build();
}
}
log.debug("handle Request for Entity {} of Site {}", id, site.getId());
Entity entity;
try {
entity = site.getEntity(id);
} catch (SiteException e) {
log.error("ReferencedSiteException while accessing Site " + site.getConfiguration().getName() + " (id=" + site.getId() + ")", e);
throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
}
if (entity != null) {
ResponseBuilder rb = Response.ok(entity);
rb.header(HttpHeaders.CONTENT_TYPE, acceptedMediaType + "; charset=utf-8");
//addCORSOrigin(servletContext, rb, headers);
return rb.build();
} else {
// TODO: How to parse an ErrorMessage?
// create an Response with the the Error?
log.debug(" ... Entity {} not found on referenced site {}", id, site.getId());
return Response.status(Status.NOT_FOUND).entity("Entity '" + id + "' not found on referenced site '" + site.getId() + "'\n").header(HttpHeaders.ACCEPT, acceptedMediaType).build();
}
}
use of org.apache.stanbol.entityhub.servicesapi.site.SiteException in project stanbol by apache.
the class ReferencedSiteRootResource method executeQuery.
/**
* Executes the query parsed by {@link #queryEntities(String, File, HttpHeaders)} or created based
* {@link #findEntity(String, String, String, int, int, HttpHeaders)}
*
* @param query
* The query to execute
* @param headers the request headers
* @return the response (results of error)
*/
private Response executeQuery(Site site, FieldQuery query, HttpHeaders headers) throws WebApplicationException {
MediaType mediaType = getAcceptableMediaType(headers, ENTITY_SUPPORTED_MEDIA_TYPES, APPLICATION_JSON_TYPE);
if (query instanceof LDPathSelect && ((LDPathSelect) query).getLDPathSelect() != null) {
//use the LDPath variant to process this query
return executeLDPathQuery(site, query, ((LDPathSelect) query).getLDPathSelect(), mediaType, headers);
} else {
//use the default query execution
QueryResultList<Representation> result;
try {
result = site.find(query);
} catch (SiteException e) {
String message = String.format("Unable to Query Site '%s' (message: %s)", site.getId(), e.getMessage());
log.error(message, e);
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(message).header(HttpHeaders.ACCEPT, mediaType).build();
}
ResponseBuilder rb = Response.ok(result);
rb.header(HttpHeaders.CONTENT_TYPE, mediaType + "; charset=utf-8");
//addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
}
Aggregations