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();
}
Aggregations