Search in sources :

Example 1 with SetInputSource

use of org.apache.stanbol.ontologymanager.servicesapi.io.SetInputSource in project stanbol by apache.

the class ScopeResource method registerScope.

/**
 * At least one between corereg and coreont must be present. Registry iris supersede ontology iris.
 *
 * @param scopeid
 * @param coreRegistry
 *            a. If it is a well-formed IRI it supersedes <code>coreOntology</code>.
 * @param coreOntologies
 * @param customRegistry
 *            a. If it is a well-formed IRI it supersedes <code>customOntology</code>.
 * @param customOntologies
 * @param activate
 *            if true, the new scope will be activated upon creation.
 * @param uriInfo
 * @param headers
 * @return
 */
@PUT
@Consumes(MediaType.WILDCARD)
public Response registerScope(@PathParam("scopeid") String scopeid, @QueryParam("corereg") final List<String> coreRegistries, @QueryParam("coreont") final List<String> coreOntologies, @DefaultValue("false") @QueryParam("activate") boolean activate, @Context HttpHeaders headers) {
    log.debug("Request URI {}", uriInfo.getRequestUri());
    scope = onm.getScope(scopeid);
    List<OntologyInputSource<?>> srcs = new ArrayList<OntologyInputSource<?>>(coreOntologies.size() + coreRegistries.size());
    // First thing, check registry sources.
    if (coreRegistries != null)
        for (String reg : coreRegistries) if (reg != null && !reg.isEmpty())
            try {
                // Library IDs are sanitized differently
                srcs.add(new LibrarySource(URIUtils.desanitize(IRI.create(reg)), regMgr));
            } catch (Exception e1) {
                throw new WebApplicationException(e1, BAD_REQUEST);
            // Bad or not supplied core registry, try the ontology.
            }
    // Then ontology sources
    if (coreOntologies != null)
        for (String ont : coreOntologies) if (ont != null && !ont.isEmpty())
            try {
                srcs.add(new RootOntologySource(IRI.create(ont)));
            } catch (OWLOntologyCreationException e2) {
                // If this fails too, throw a bad request.
                throw new WebApplicationException(e2, BAD_REQUEST);
            }
    // Now the creation.
    try {
        // Expand core sources
        List<OntologyInputSource<?>> expanded = new ArrayList<OntologyInputSource<?>>();
        for (OntologyInputSource<?> coreSrc : srcs) if (coreSrc != null) {
            if (coreSrc instanceof SetInputSource) {
                for (Object o : ((SetInputSource<?>) coreSrc).getOntologies()) {
                    OntologyInputSource<?> src = null;
                    if (o instanceof OWLOntology)
                        src = new RootOntologySource((OWLOntology) o);
                    else if (o instanceof Graph)
                        src = new GraphSource((Graph) o);
                    if (src != null)
                        expanded.add(src);
                }
            } else
                // Must be denoting a single ontology
                expanded.add(coreSrc);
        }
        scope = onm.createOntologyScope(scopeid, expanded.toArray(new OntologyInputSource[0]));
        // Setup and register the scope. If no custom space was set, it will
        // still be open for modification.
        scope.setUp();
        onm.setScopeActive(scopeid, activate);
    } catch (DuplicateIDException e) {
        throw new WebApplicationException(e, CONFLICT);
    } catch (Exception ex) {
        throw new WebApplicationException(ex, INTERNAL_SERVER_ERROR);
    }
    ResponseBuilder rb = Response.created(uriInfo.getAbsolutePath());
    // addCORSOrigin(servletContext, rb, headers);
    return rb.build();
}
Also used : SetInputSource(org.apache.stanbol.ontologymanager.servicesapi.io.SetInputSource) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) LibrarySource(org.apache.stanbol.ontologymanager.registry.io.LibrarySource) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) UnsupportedFormatException(org.apache.clerezza.rdf.core.serializedform.UnsupportedFormatException) IrremovableOntologyException(org.apache.stanbol.ontologymanager.servicesapi.collector.IrremovableOntologyException) WebApplicationException(javax.ws.rs.WebApplicationException) UnmodifiableOntologyCollectorException(org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException) DuplicateIDException(org.apache.stanbol.ontologymanager.servicesapi.collector.DuplicateIDException) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException) IOException(java.io.IOException) OntologyLoadingException(org.apache.stanbol.ontologymanager.servicesapi.ontology.OntologyLoadingException) OntologyCollectorModificationException(org.apache.stanbol.ontologymanager.servicesapi.collector.OntologyCollectorModificationException) ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph) Graph(org.apache.clerezza.commons.rdf.Graph) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) DuplicateIDException(org.apache.stanbol.ontologymanager.servicesapi.collector.DuplicateIDException) RootOntologySource(org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) GraphSource(org.apache.stanbol.ontologymanager.sources.clerezza.GraphSource) OntologyInputSource(org.apache.stanbol.ontologymanager.servicesapi.io.OntologyInputSource) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 Graph (org.apache.clerezza.commons.rdf.Graph)1 ImmutableGraph (org.apache.clerezza.commons.rdf.ImmutableGraph)1 UnsupportedFormatException (org.apache.clerezza.rdf.core.serializedform.UnsupportedFormatException)1 LibrarySource (org.apache.stanbol.ontologymanager.registry.io.LibrarySource)1 DuplicateIDException (org.apache.stanbol.ontologymanager.servicesapi.collector.DuplicateIDException)1 IrremovableOntologyException (org.apache.stanbol.ontologymanager.servicesapi.collector.IrremovableOntologyException)1 OntologyCollectorModificationException (org.apache.stanbol.ontologymanager.servicesapi.collector.OntologyCollectorModificationException)1 UnmodifiableOntologyCollectorException (org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException)1 OntologyInputSource (org.apache.stanbol.ontologymanager.servicesapi.io.OntologyInputSource)1 SetInputSource (org.apache.stanbol.ontologymanager.servicesapi.io.SetInputSource)1 OntologyLoadingException (org.apache.stanbol.ontologymanager.servicesapi.ontology.OntologyLoadingException)1 GraphSource (org.apache.stanbol.ontologymanager.sources.clerezza.GraphSource)1 RootOntologySource (org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource)1 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)1