Search in sources :

Example 1 with OntologyCollectorModificationException

use of org.apache.stanbol.ontologymanager.servicesapi.collector.OntologyCollectorModificationException 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 2 with OntologyCollectorModificationException

use of org.apache.stanbol.ontologymanager.servicesapi.collector.OntologyCollectorModificationException 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

DELETE (javax.ws.rs.DELETE)2 Path (javax.ws.rs.Path)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)2 IrremovableOntologyException (org.apache.stanbol.ontologymanager.servicesapi.collector.IrremovableOntologyException)2 OntologyCollectorModificationException (org.apache.stanbol.ontologymanager.servicesapi.collector.OntologyCollectorModificationException)2 UnmodifiableOntologyCollectorException (org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException)2 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)2 OntologySpace (org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace)1