Search in sources :

Example 26 with Viewable

use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.

the class ScopeResource method getHtmlInfo.

@GET
@Produces(TEXT_HTML)
public Response getHtmlInfo(@PathParam("scopeid") String scopeid, @Context HttpHeaders headers) {
    ResponseBuilder rb;
    scope = onm.getScope(scopeid);
    if (scope == null)
        rb = Response.status(NOT_FOUND);
    else
        // TODO move to a dedicated class
        rb = Response.ok(new Viewable("index", this));
    rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
    // addCORSOrigin(servletContext, rb, headers);
    return rb.build();
}
Also used : Viewable(org.apache.stanbol.commons.web.viewable.Viewable) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 27 with Viewable

use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.

the class SessionResource method managedOntologyShow.

@GET
@Path("/{ontologyId:.+}")
@Produces(TEXT_HTML)
public Response managedOntologyShow(@PathParam("ontologyId") String ontologyId, @Context HttpHeaders headers) {
    ResponseBuilder rb;
    if (session == 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/session/");
        OWLOntology o = session.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, session)));
            } 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();
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) ManchesterOWLSyntaxOntologyFormat(org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxOntologyFormat) WebApplicationException(javax.ws.rs.WebApplicationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) Viewable(org.apache.stanbol.commons.web.viewable.Viewable) OntologyPrettyPrintResource(org.apache.stanbol.ontologymanager.web.util.OntologyPrettyPrintResource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 28 with Viewable

use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.

the class TopicClassifierRootResource method get.

@GET
@Produces(TEXT_HTML)
public Response get(@Context HttpHeaders headers) {
    ResponseBuilder rb = Response.ok(new Viewable("index", this));
    rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
    return rb.build();
}
Also used : Viewable(org.apache.stanbol.commons.web.viewable.Viewable) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 29 with Viewable

use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.

the class ReferencedSiteRootResource method getQueryDocumentation.

@GET
@Path("/query")
@Produces(TEXT_HTML)
public Response getQueryDocumentation(@Context HttpHeaders headers, @PathParam(value = "site") String siteId) {
    ResponseBuilder rb = Response.ok(new Viewable("query", new SiteResultData(getSite(siteId))));
    rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
    //addCORSOrigin(servletContext, rb, headers);
    return rb.build();
}
Also used : Viewable(org.apache.stanbol.commons.web.viewable.Viewable) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Path(javax.ws.rs.Path) EntityhubLDPath(org.apache.stanbol.entityhub.ldpath.EntityhubLDPath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 30 with Viewable

use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.

the class ReferencedSiteRootResource method findEntity.

@POST
@Path("/find")
public Response findEntity(@PathParam(value = "site") String siteId, @FormParam(value = "name") String name, @FormParam(value = "field") String parsedField, @FormParam(value = "lang") String language, // @FormParam(value="select") String select,
@FormParam(value = "limit") Integer limit, @FormParam(value = "offset") Integer offset, @FormParam(value = "ldpath") String ldpath, @Context HttpHeaders headers) {
    Site site = getSite(siteId);
    log.debug("site/{}/find Request", site.getId());
    Collection<String> supported = new HashSet<String>(JerseyUtils.QUERY_RESULT_SUPPORTED_MEDIA_TYPES);
    supported.add(TEXT_HTML);
    final MediaType acceptedMediaType = getAcceptableMediaType(headers, supported, MediaType.APPLICATION_JSON_TYPE);
    if (name == null || name.isEmpty()) {
        if (MediaType.TEXT_HTML_TYPE.isCompatible(acceptedMediaType)) {
            ResponseBuilder rb = Response.ok(new Viewable("find", 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("The name must not be null nor empty for find requests. Missing parameter name.\n").header(HttpHeaders.ACCEPT, acceptedMediaType).build();
        }
    }
    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();
            }
        }
    }
    return executeQuery(site, createFieldQueryForFindRequest(name, property, language, limit == null || limit < 1 ? DEFAULT_FIND_RESULT_LIMIT : limit, offset, ldpath), headers);
}
Also used : ManagedSite(org.apache.stanbol.entityhub.servicesapi.site.ManagedSite) Site(org.apache.stanbol.entityhub.servicesapi.site.Site) Viewable(org.apache.stanbol.commons.web.viewable.Viewable) MediaType(javax.ws.rs.core.MediaType) MediaTypeUtil.getAcceptableMediaType(org.apache.stanbol.commons.web.base.utils.MediaTypeUtil.getAcceptableMediaType) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) EntityhubLDPath(org.apache.stanbol.entityhub.ldpath.EntityhubLDPath) POST(javax.ws.rs.POST)

Aggregations

Viewable (org.apache.stanbol.commons.web.viewable.Viewable)43 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)40 GET (javax.ws.rs.GET)30 Produces (javax.ws.rs.Produces)26 Path (javax.ws.rs.Path)20 WebApplicationException (javax.ws.rs.WebApplicationException)15 EntityhubLDPath (org.apache.stanbol.entityhub.ldpath.EntityhubLDPath)14 MediaType (javax.ws.rs.core.MediaType)12 MediaTypeUtil.getAcceptableMediaType (org.apache.stanbol.commons.web.base.utils.MediaTypeUtil.getAcceptableMediaType)12 HashSet (java.util.HashSet)11 Entity (org.apache.stanbol.entityhub.servicesapi.model.Entity)7 POST (javax.ws.rs.POST)6 EntityhubException (org.apache.stanbol.entityhub.servicesapi.EntityhubException)6 IRI (org.semanticweb.owlapi.model.IRI)5 Consumes (javax.ws.rs.Consumes)4 OWLOntologyStorageException (org.semanticweb.owlapi.model.OWLOntologyStorageException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3