Search in sources :

Example 76 with OWLOntologyID

use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.

the class ScopeResource method managedOntologyGetOWL.

/**
     * Gets the ontology with the given identifier in its version managed by the session.
     * 
     * @param sessionId
     *            the session identifier.
     * @param ontologyId
     *            the ontology identifier.
     * @param uriInfo
     * @param headers
     * @return the requested managed ontology, or {@link Status#NOT_FOUND} if either the sessionn does not
     *         exist, or the if the ontology either does not exist or is not managed.
     */
@GET
@Path("/{ontologyId:.+}")
@Produces(value = { RDF_XML, TURTLE, X_TURTLE, MANCHESTER_OWL, FUNCTIONAL_OWL, OWL_XML, TEXT_PLAIN })
public Response managedOntologyGetOWL(@PathParam("scopeid") String scopeid, @PathParam("ontologyId") String ontologyId, @DefaultValue("false") @QueryParam("merge") boolean merge, @Context UriInfo uriInfo, @Context HttpHeaders headers) {
    log.debug("Absolute URL Path {}", uriInfo.getRequestUri());
    log.debug("Ontology ID {}", ontologyId);
    ResponseBuilder rb;
    scope = onm.getScope(scopeid);
    if (scope == null)
        rb = Response.status(NOT_FOUND);
    else {
        IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/ontology/");
        OWLOntology o = null;
        OWLOntologyID id = OntologyUtils.decode(ontologyId);
        OntologySpace spc = scope.getCustomSpace();
        if (spc != null && spc.hasOntology(id)) {
            o = spc.getOntology(id, OWLOntology.class, merge, prefix);
        } else {
            spc = scope.getCoreSpace();
            if (spc != null && spc.hasOntology(id))
                o = spc.getOntology(id, OWLOntology.class, merge, prefix);
        }
        if (o == null)
            rb = Response.status(NOT_FOUND);
        else
            rb = Response.ok(o);
    }
    // addCORSOrigin(servletContext, rb, headers);
    return rb.build();
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) OntologySpace(org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 77 with OWLOntologyID

use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.

the class ScopeResource method managedOntologyUnload.

/**
     * Unloads an ontology from an ontology scope.
     * 
     * @param scopeId
     * @param ontologyid
     * @param uriInfo
     * @param headers
     */
@DELETE
@Path("/{ontologyId:.+}")
public Response managedOntologyUnload(@PathParam("scopeid") String scopeid, @PathParam("ontologyId") String ontologyId, @PathParam("scopeid") String scopeId, @Context UriInfo uriInfo, @Context HttpHeaders headers) {
    ResponseBuilder rb;
    scope = onm.getScope(scopeid);
    if (ontologyId != null && !ontologyId.trim().isEmpty()) {
        OWLOntologyID id = OntologyUtils.decode(ontologyId);
        OntologySpace cs = scope.getCustomSpace();
        if (// ontology not managed
        !cs.hasOntology(id))
            // ontology not managed
            rb = Response.notModified();
        else
            try {
                onm.setScopeActive(scopeId, false);
                cs.removeOntology(id);
                rb = Response.ok();
            } catch (IrremovableOntologyException e) {
                throw new WebApplicationException(e, FORBIDDEN);
            } catch (UnmodifiableOntologyCollectorException e) {
                throw new WebApplicationException(e, FORBIDDEN);
            } catch (OntologyCollectorModificationException e) {
                throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
            } finally {
                onm.setScopeActive(scopeId, true);
            }
    } else
        // null/blank ontology ID
        rb = Response.status(BAD_REQUEST);
    // addCORSOrigin(servletContext, rb, headers);
    return rb.build();
}
Also used : IrremovableOntologyException(org.apache.stanbol.ontologymanager.servicesapi.collector.IrremovableOntologyException) WebApplicationException(javax.ws.rs.WebApplicationException) OntologyCollectorModificationException(org.apache.stanbol.ontologymanager.servicesapi.collector.OntologyCollectorModificationException) UnmodifiableOntologyCollectorException(org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) OntologySpace(org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 78 with OWLOntologyID

use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.

the class ScopeResource method manageOntology.

/**
     * Tells the session that it should manage the ontology obtained by dereferencing the supplied IRI.<br>
     * <br>
     * Note that the PUT method cannot be used, as it is not possible to predict what ID the ontology will
     * have until it is parsed.
     * 
     * @param content
     *            the ontology physical IRI
     * @return {@link Status#OK} if the addition was successful, {@link Status#NOT_FOUND} if there is no such
     *         session at all, {@link Status#FORBIDDEN} if the session is locked or cannot modified for some
     *         other reason, {@link Status#INTERNAL_SERVER_ERROR} if some other error occurs.
     */
@POST
@Consumes(value = MediaType.TEXT_PLAIN)
public Response manageOntology(String iri, @PathParam("scopeid") String scopeid, @Context HttpHeaders headers) {
    ResponseBuilder rb;
    scope = onm.getScope(scopeid);
    if (scope == null)
        rb = Response.status(NOT_FOUND);
    else
        try {
            OWLOntologyID key = scope.getCustomSpace().addOntology(new RootOntologySource(IRI.create(iri)));
            URI created = getCreatedResource(OntologyUtils.encode(key));
            rb = Response.created(created);
        } catch (UnmodifiableOntologyCollectorException e) {
            throw new WebApplicationException(e, FORBIDDEN);
        } catch (OWLOntologyCreationException e) {
            throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
        }
    // addCORSOrigin(servletContext, rb, headers);
    return rb.build();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) UnmodifiableOntologyCollectorException(org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException) RootOntologySource(org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) URI(java.net.URI) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 79 with OWLOntologyID

use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.

the class SessionResource method managedOntologyGetMixed.

/**
     * Gets the ontology with the given identifier in its version managed by the session.
     * 
     * @param sessionId
     *            the session identifier.
     * @param ontologyId
     *            the ontology identifier.
     * @param uriInfo
     * @param headers
     * @return the requested managed ontology, or {@link Status#NOT_FOUND} if either the sessionn does not
     *         exist, or the if the ontology either does not exist or is not managed.
     */
@GET
@Path(value = "/{ontologyId:.+}")
@Produces(value = { RDF_XML, TURTLE, X_TURTLE })
public Response managedOntologyGetMixed(@PathParam("id") String sessionId, @PathParam("ontologyId") String ontologyId, @DefaultValue("false") @QueryParam("merge") boolean merge, //                                            @Context UriInfo uriInfo,
@Context HttpHeaders headers) {
    ResponseBuilder rb;
    session = sesMgr.getSession(sessionId);
    if (session == null)
        rb = Response.status(NOT_FOUND);
    else {
        IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/");
        OWLOntologyID id = OntologyUtils.decode(ontologyId);
        if (merge) {
            ImmutableGraph g = session.getOntology(id, ImmutableGraph.class, merge, prefix);
            rb = (g != null) ? Response.ok(g) : Response.status(NOT_FOUND);
        } else {
            OWLOntology o = session.getOntology(id, OWLOntology.class, merge, prefix);
            rb = (o != null) ? Response.ok(o) : Response.status(NOT_FOUND);
        }
    }
    //        addCORSOrigin(servletContext, rb, headers);
    return rb.build();
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 80 with OWLOntologyID

use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.

the class SessionResource method managedOntologyUnload.

/**
     * Tells the session to no longer manage the ontology with the supplied <i>logical</i> identifier. The
     * ontology will be lost if not stored or not managed by another collector.
     * 
     * @param sessionId
     *            the session identifier.
     * @param ontologyId
     *            the ontology identifier.
     * @param uriInfo
     * @param headers
     * @return {@link Status#OK} if the removal was successful, {@link Status#NOT_FOUND} if there is no such
     *         session at all, {@link Status#FORBIDDEN} if the session or the ontology is locked or cannot
     *         modified for some other reason, {@link Status#INTERNAL_SERVER_ERROR} if some other error
     *         occurs.
     */
@DELETE
@Path(value = "/{ontologyId:.+}")
public Response managedOntologyUnload(@PathParam("id") String sessionId, @PathParam("ontologyId") String ontologyId, //                                          @Context UriInfo uriInfo,
@Context HttpHeaders headers) {
    ResponseBuilder rb;
    session = sesMgr.getSession(sessionId);
    if (session == null)
        rb = Response.status(NOT_FOUND);
    else {
        OWLOntologyID id = OntologyUtils.decode(ontologyId);
        if (!session.hasOntology(id))
            rb = Response.notModified();
        else
            try {
                session.removeOntology(id);
                rb = Response.ok();
            } catch (IrremovableOntologyException e) {
                throw new WebApplicationException(e, FORBIDDEN);
            } catch (UnmodifiableOntologyCollectorException e) {
                throw new WebApplicationException(e, FORBIDDEN);
            } catch (OntologyCollectorModificationException e) {
                throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
            }
    }
    //        addCORSOrigin(servletContext, rb, headers);
    return rb.build();
}
Also used : IrremovableOntologyException(org.apache.stanbol.ontologymanager.servicesapi.collector.IrremovableOntologyException) WebApplicationException(javax.ws.rs.WebApplicationException) OntologyCollectorModificationException(org.apache.stanbol.ontologymanager.servicesapi.collector.OntologyCollectorModificationException) UnmodifiableOntologyCollectorException(org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Aggregations

OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)86 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)31 Test (org.junit.Test)27 HashSet (java.util.HashSet)22 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)22 InputStream (java.io.InputStream)20 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)19 Triple (org.apache.clerezza.commons.rdf.Triple)19 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)19 IRI (org.apache.clerezza.commons.rdf.IRI)17 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)16 IRI (org.semanticweb.owlapi.model.IRI)14 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)13 IOException (java.io.IOException)12 UnmodifiableOntologyCollectorException (org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException)12 WebApplicationException (javax.ws.rs.WebApplicationException)11 Graph (org.apache.clerezza.commons.rdf.Graph)10 AddImport (org.semanticweb.owlapi.model.AddImport)10 Path (javax.ws.rs.Path)9 OntologySpace (org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace)8