use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.
the class EntityhubRootResource method getSymbolMappings.
@GET
@Path("mapping/symbol")
@Produces({ APPLICATION_JSON, RDF_XML, N3, TURTLE, X_TURTLE, RDF_JSON, N_TRIPLE, TEXT_HTML })
public Response getSymbolMappings(@QueryParam("id") String symbol, @Context HttpHeaders headers) throws WebApplicationException {
log.debug("getSymbolMappings() POST Request > symbol: {} > accept: {}", symbol, headers.getAcceptableMediaTypes());
Set<String> supported = new HashSet<String>(JerseyUtils.REPRESENTATION_SUPPORTED_MEDIA_TYPES);
supported.add(TEXT_HTML);
MediaType acceptedMediaType = getAcceptableMediaType(headers, supported, APPLICATION_JSON_TYPE);
if (symbol == null || symbol.isEmpty()) {
//if HTML -> print the docu of the restfull service
if (TEXT_HTML_TYPE.isCompatible(acceptedMediaType)) {
ResponseBuilder rb = Response.ok(new Viewable("mapping_symbol", this));
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 symbol given. Missing parameter id.\n").header(HttpHeaders.ACCEPT, acceptedMediaType).build();
}
}
//Entityhub entityhub = ContextHelper.getServiceFromContext(Entityhub.class, servletContext);
Collection<Entity> mappings;
try {
mappings = entityhub.getMappingsByTarget(symbol);
} catch (EntityhubException e) {
throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
}
if (mappings == null || mappings.isEmpty()) {
return Response.status(Status.NOT_FOUND).entity("No mapping found for symbol '" + symbol + "'.\n").header(HttpHeaders.ACCEPT, acceptedMediaType).build();
} else {
// TODO: Implement Support for list of Signs, Representations and Strings
// For now use a pseudo QueryResultList
QueryResultList<Entity> mappingResultList = new QueryResultListImpl<Entity>(null, mappings, Entity.class);
ResponseBuilder rb = Response.ok(mappingResultList);
rb.header(HttpHeaders.CONTENT_TYPE, acceptedMediaType + "; charset=utf-8");
//addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
}
use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.
the class EntityhubRootResource method findEntity.
@POST
@Path("/find")
@Produces({ APPLICATION_JSON, RDF_XML, N3, TURTLE, X_TURTLE, RDF_JSON, N_TRIPLE, TEXT_HTML })
public Response findEntity(@FormParam(value = "name") String name, @FormParam(value = "field") String parsedField, @FormParam(value = "lang") String language, @FormParam(value = "limit") Integer limit, @FormParam(value = "offset") Integer offset, // solution!
@FormParam(value = "select") String select, @FormParam(value = "ldpath") String ldpath, @Context HttpHeaders headers) {
log.debug("/find Request");
final MediaType acceptedMediaType = getAcceptableMediaType(headers, ENTITY_SUPPORTED_MEDIA_TYPE_INCL_HTML, MediaType.APPLICATION_JSON_TYPE);
if (name == null || name.isEmpty()) {
if (acceptedMediaType.isCompatible(TEXT_HTML_TYPE)) {
//return HTML docu
ResponseBuilder rb = Response.ok(new Viewable("find", this));
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("The name must not be null nor empty for find requests. Missing parameter name.\n").header(HttpHeaders.ACCEPT, acceptedMediaType).build();
}
} else {
final String property;
if (parsedField == null) {
property = DEFAULT_FIND_FIELD;
} else {
parsedField = parsedField.trim();
if (parsedField.isEmpty()) {
property = DEFAULT_FIND_FIELD;
} else {
property = nsPrefixService.getFullName(parsedField);
if (property == null) {
String messsage = String.format("The prefix '%s' of the parsed field '%' is not " + "mapped to any namespace. Please parse the full URI instead!\n", NamespaceMappingUtils.getPrefix(parsedField), parsedField);
return Response.status(Status.BAD_REQUEST).entity(messsage).header(HttpHeaders.ACCEPT, acceptedMediaType).build();
}
}
}
FieldQuery query = JerseyUtils.createFieldQueryForFindRequest(name, property, language, limit == null || limit < 1 ? DEFAULT_FIND_RESULT_LIMIT : limit, offset, ldpath);
// For the Entityhub we support to select additional fields for results
// of find requests. For the Sites and {site} endpoint this is currently
// deactivated because of very bad performance with OPTIONAL graph patterns
// in SPARQL queries.
Collection<String> additionalSelectedFields = new ArrayList<String>();
if (select != null && !select.isEmpty()) {
for (String selected : select.trim().split(" ")) {
if (selected != null && !selected.isEmpty()) {
additionalSelectedFields.add(selected);
}
}
}
query.addSelectedFields(additionalSelectedFields);
return executeQuery(query, headers, acceptedMediaType);
}
}
use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.
the class SiteManagerRootResource method getQueryDocumentation.
@GET
@Path("/query")
public Response getQueryDocumentation(@Context HttpHeaders headers) {
ResponseBuilder rb = Response.ok(new Viewable("query", this));
rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
//addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.
the class RootResource method performShowOntology.
/**
* Helper method to make sure a ResponseBuilder is created on every conditions, so that it is then
* possible to enable CORS on it afterwards.
*
* @param ontologyId
* @return
*/
protected ResponseBuilder performShowOntology(String ontologyId) {
if (ontologyId == null || ontologyId.isEmpty()) {
return Response.status(BAD_REQUEST);
}
OWLOntologyID key = OntologyUtils.decode(ontologyId);
if (ontologyProvider.listOrphans().contains(key)) {
return Response.status(NO_CONTENT);
}
OWLOntology o = getOWLOntology(ontologyId, false, uriInfo.getRequestUri());
if (o == null) {
return Response.status(NOT_FOUND);
}
// Assemble dependency list
Map<OWLOntologyID, OntologyProvider.Status> deps = new HashMap<OWLOntologyID, OntologyProvider.Status>();
for (OWLOntologyID dep : getDescriptor().getDependencies(key)) {
deps.put(dep, ontologyProvider.getStatus(dep));
}
Set<OntologyCollector> handles = new HashSet<OntologyCollector>();
if (onManager != null) {
for (Scope scope : onManager.getRegisteredScopes()) {
if (scope.getCoreSpace().hasOntology(key)) {
handles.add(scope.getCoreSpace());
}
if (scope.getCustomSpace().hasOntology(key)) {
handles.add(scope.getCustomSpace());
}
}
}
if (sessionManager != null) {
for (String sesId : sessionManager.getRegisteredSessionIDs()) {
if (sessionManager.getSession(sesId).hasOntology(key)) {
handles.add(sessionManager.getSession(sesId));
}
}
}
return Response.ok(new Viewable("ontology", new OntologyStats(uriInfo, key, o, ontologyProvider.listAliases(key), deps, handles)));
}
use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.
the class ScopeResource method managedOntologyShow.
@GET
@Path("/{ontologyId:.+}")
@Produces(TEXT_HTML)
public Response managedOntologyShow(@PathParam("scopeid") String scopeid, @PathParam("ontologyId") String ontologyId, @Context HttpHeaders headers) {
ResponseBuilder rb;
scope = onm.getScope(scopeid);
if (scope == null)
rb = Response.status(NOT_FOUND);
else if (ontologyId == null || ontologyId.isEmpty())
rb = Response.status(BAD_REQUEST);
else if (!ontologyProvider.hasOntology(OntologyUtils.decode(ontologyId)))
rb = Response.status(NOT_FOUND);
else {
IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/ontology/");
OWLOntology o = scope.getCustomSpace().getOntology(OntologyUtils.decode(ontologyId), OWLOntology.class, false, prefix);
if (o == null)
o = scope.getCoreSpace().getOntology(OntologyUtils.decode(ontologyId), OWLOntology.class, false, prefix);
if (o == null)
rb = Response.status(NOT_FOUND);
else
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
o.getOWLOntologyManager().saveOntology(o, new ManchesterOWLSyntaxOntologyFormat(), out);
rb = Response.ok(new Viewable("ontology", new OntologyPrettyPrintResource(uriInfo, out, scope)));
} catch (OWLOntologyStorageException e) {
throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
}
}
rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
// addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
Aggregations