use of org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException in project stanbol by apache.
the class TestClerezzaSpaces method testCustomLock.
@Test
public void testCustomLock() throws Exception {
OntologySpace space = factory.createCustomOntologySpace(scopeId, inMemorySrc);
space.setUp();
try {
space.addOntology(minorSrc);
fail("Modification was permitted on locked ontology space.");
} catch (UnmodifiableOntologyCollectorException e) {
assertSame(space, e.getOntologyCollector());
}
}
use of org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException in project stanbol by apache.
the class TestClerezzaSpaces method testCoreLock.
@Test
public void testCoreLock() throws Exception {
OntologySpace space = factory.createCoreOntologySpace(scopeId, inMemorySrc);
space.setUp();
try {
space.addOntology(minorSrc);
fail("Modification was permitted on locked ontology space.");
} catch (UnmodifiableOntologyCollectorException e) {
assertSame(space, e.getOntologyCollector());
}
}
use of org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException in project stanbol by apache.
the class TestOntologySpaces method testCoreLock.
@Test
public void testCoreLock() throws Exception {
OntologySpace space = factory.createCoreOntologySpace("testCoreLock", inMemorySrc);
space.setUp();
try {
space.addOntology(minorSrc);
fail("Modification was permitted on locked ontology space.");
} catch (UnmodifiableOntologyCollectorException e) {
assertSame(space, e.getOntologyCollector());
}
}
use of org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException in project stanbol by apache.
the class SessionResource 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("id") String sessionId, @Context HttpHeaders headers) {
session = sesMgr.getSession(sessionId);
if (session == null)
return Response.status(NOT_FOUND).build();
try {
session.addOntology(new RootOntologySource(IRI.create(iri)));
} catch (UnmodifiableOntologyCollectorException e) {
throw new WebApplicationException(e, FORBIDDEN);
} catch (OWLOntologyCreationException e) {
throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
}
ResponseBuilder rb = Response.ok();
// addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
use of org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException in project stanbol by apache.
the class SessionResource method manageOntology.
/**
* Tells the session that it should manage the ontology obtained by parsing the supplied content.<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 content
* @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 = { RDF_XML, OWL_XML, N_TRIPLE, N3, TURTLE, X_TURTLE, FUNCTIONAL_OWL, MANCHESTER_OWL, RDF_JSON })
public Response manageOntology(InputStream content, @PathParam("id") String sessionId, @Context HttpHeaders headers) {
long before = System.currentTimeMillis();
ResponseBuilder rb;
session = sesMgr.getSession(sessionId);
String mt = headers.getMediaType().toString();
if (// Always check session first
session == null)
// Always check session first
rb = Response.status(NOT_FOUND);
else
try {
log.debug("POST content claimed to be of type {}.", mt);
OntologyInputSource<?> src;
if (OWL_XML.equals(mt) || FUNCTIONAL_OWL.equals(mt) || MANCHESTER_OWL.equals(mt))
src = new OntologyContentInputSource(content);
else
// content = new BufferedInputStream(content);
src = new GraphContentInputSource(content, mt, ontologyProvider.getStore());
log.debug("SUCCESS parse with media type {}.", mt);
OWLOntologyID key = session.addOntology(src);
if (key == null || key.isAnonymous()) {
log.error("FAILED parse with media type {}.", mt);
throw new WebApplicationException(INTERNAL_SERVER_ERROR);
}
// FIXME ugly but will have to do for the time being
log.debug("SUCCESS add ontology to session {}.", session.getID());
log.debug("Storage key : {}", key);
// key.split("::")[1];
String uri = OntologyUtils.encode(key);
// uri = uri.substring((ontologyProvider.getGraphPrefix() + "::").length());
URI created = null;
if (uri != null && !uri.isEmpty()) {
created = getCreatedResource(uri);
rb = Response.created(created);
} else
rb = Response.ok();
log.info("POST request for ontology addition completed in {} ms.", (System.currentTimeMillis() - before));
log.info("New resource URL is {}", created);
} catch (UnmodifiableOntologyCollectorException e) {
throw new WebApplicationException(e, FORBIDDEN);
} catch (OWLOntologyCreationException e) {
log.error("FAILED parse with media type {}.", mt);
throw new WebApplicationException(e, BAD_REQUEST);
}
// addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
Aggregations