Search in sources :

Example 21 with Scope

use of org.apache.stanbol.ontologymanager.servicesapi.scope.Scope 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)));
}
Also used : Status(javax.ws.rs.core.Response.Status) HashMap(java.util.HashMap) OntologyCollector(org.apache.stanbol.ontologymanager.servicesapi.collector.OntologyCollector) Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OntologyProvider(org.apache.stanbol.ontologymanager.servicesapi.ontology.OntologyProvider) Viewable(org.apache.stanbol.commons.web.viewable.Viewable) HashSet(java.util.HashSet)

Example 22 with Scope

use of org.apache.stanbol.ontologymanager.servicesapi.scope.Scope in project stanbol by apache.

the class ScopeManagerResource method getScopeModel.

/**
 * Default GET method for obtaining the set of (both active and, optionally, inactive) ontology scopes
 * currently registered with this instance of KReS.
 *
 * @param inactive
 *            if true, both active and inactive scopes will be included. Default is false.
 * @param headers
 *            the HTTP headers, supplied by the REST call.
 * @param servletContext
 *            the servlet context, supplied by the REST call.
 * @return a string representation of the requested scope set, in a format acceptable by the client.
 */
@GET
@Produces(value = { RDF_XML, OWL_XML, TURTLE, X_TURTLE, FUNCTIONAL_OWL, MANCHESTER_OWL, RDF_JSON, N3, N_TRIPLE, TEXT_PLAIN })
public Response getScopeModel(@DefaultValue("false") @QueryParam("with-inactive") boolean inactive, @Context HttpHeaders headers, @Context ServletContext servletContext) {
    Set<Scope> scopes = inactive ? onm.getRegisteredScopes() : onm.getActiveScopes();
    OWLOntology ontology = ScopeSetRenderer.getScopes(scopes);
    ResponseBuilder rb = Response.ok(ontology);
    MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
    if (mediaType != null)
        rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
    // addCORSOrigin(servletContext, rb, headers);
    return rb.build();
}
Also used : Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) MediaType(javax.ws.rs.core.MediaType) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Scope (org.apache.stanbol.ontologymanager.servicesapi.scope.Scope)22 Test (org.junit.Test)7 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)7 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)6 HashSet (java.util.HashSet)5 IRI (org.apache.clerezza.commons.rdf.IRI)5 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)5 IOException (java.io.IOException)4 Triple (org.apache.clerezza.commons.rdf.Triple)4 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)4 OntologySpace (org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace)4 GraphContentInputSource (org.apache.stanbol.ontologymanager.sources.clerezza.GraphContentInputSource)4 Produces (javax.ws.rs.Produces)3 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)3 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)3 UnmodifiableOntologyCollectorException (org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException)3 NoSuchScopeException (org.apache.stanbol.ontologymanager.servicesapi.scope.NoSuchScopeException)3 Session (org.apache.stanbol.ontologymanager.servicesapi.session.Session)3 InputStream (java.io.InputStream)2 POST (javax.ws.rs.POST)2