use of org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException in project stanbol by apache.
the class SessionManagerImpl method rebuildSessions.
private void rebuildSessions() {
if (ontologyProvider == null) {
log.warn("No ontology provider supplied. Cannot rebuild sessions");
return;
}
OntologyNetworkConfiguration struct = ontologyProvider.getOntologyNetworkConfiguration();
for (String sessionId : struct.getSessionIDs()) {
long before = System.currentTimeMillis();
log.debug("Rebuilding session with ID \"{}\"", sessionId);
Session session;
try {
session = createSession(sessionId);
} catch (DuplicateSessionIDException e) {
log.warn("Session \"{}\" already exists and will be reused.", sessionId);
session = getSession(sessionId);
} catch (SessionLimitException e) {
log.error("Cannot create session {}. Session limit of {} reached.", sessionId, getActiveSessionLimit());
break;
}
// Register even if some ontologies were to fail to be restored afterwards.
sessionsByID.put(sessionId, session);
// Restored sessions are inactive at first.
session.setActive(false);
for (OWLOntologyID key : struct.getOntologyKeysForSession(sessionId)) try {
session.addOntology(new StoredOntologySource(key));
} catch (MissingOntologyException ex) {
log.error("Could not find an ontology with public key {} to be managed by session \"{}\". Proceeding to next ontology.", key, sessionId);
continue;
} catch (Exception ex) {
log.error("Exception caught while trying to add ontology with public key " + key + " to rebuilt session \"" + sessionId + "\". Proceeding to next ontology.", ex);
continue;
}
for (String scopeId : struct.getAttachedScopes(sessionId)) {
/*
* The scope is attached by reference, so we won't have to bother checking if the scope has
* been rebuilt by then (which could not happen if the SessionManager is being activated
* first).
*/
session.attachScope(scopeId);
}
log.info("Session \"{}\" rebuilt in {} ms.", sessionId, System.currentTimeMillis() - before);
}
}
use of org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException in project stanbol by apache.
the class AbstractOntologyCollectorImpl method removeOntology.
@Override
public void removeOntology(OWLOntologyID publicKey) throws OntologyCollectorModificationException {
if (publicKey == null)
throw new IllegalArgumentException("Cannot remove an ontology by providing a null public key.");
if (publicKey.getOntologyIRI() == null)
throw new IllegalArgumentException("Cannot remove an ontology whose public key has a null ontology IRI.");
if (locked)
throw new UnmodifiableOntologyCollectorException(this);
Set<OWLOntologyID> aliases = ontologyProvider.listAliases(publicKey);
aliases.add(publicKey);
boolean removed = false;
for (OWLOntologyID alias : aliases) removed |= managedOntologies.remove(alias);
// Don't fire if the ontology wasn't there in the first place.
if (removed)
fireOntologyRemoved(publicKey);
else
throw new MissingOntologyException(this, publicKey);
}
use of org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException in project stanbol by apache.
the class ScopeManagerImpl method rebuildScopes.
private void rebuildScopes() {
OntologyNetworkConfiguration struct = ontologyProvider.getOntologyNetworkConfiguration();
for (String scopeId : struct.getScopeIDs()) {
long before = System.currentTimeMillis();
log.debug("Rebuilding scope with ID \"{}\".", scopeId);
Collection<OWLOntologyID> coreOnts = struct.getCoreOntologyKeysForScope(scopeId);
OntologyInputSource<?>[] srcs = new OntologyInputSource<?>[coreOnts.size()];
int i = 0;
for (OWLOntologyID coreOnt : coreOnts) {
log.debug("Core ontology key : {}", coreOnts);
srcs[i++] = new StoredOntologySource(coreOnt);
}
Scope scope;
try {
scope = createOntologyScope(scopeId, srcs);
} catch (DuplicateIDException e) {
String dupe = e.getDuplicateID();
log.warn("Scope \"{}\" already exists and will be reused.", dupe);
scope = getScope(dupe);
}
OntologySpace custom = scope.getCustomSpace();
// Register even if some ontologies were to fail to be restored afterwards.
scopeMap.put(scopeId, scope);
for (OWLOntologyID key : struct.getCustomOntologyKeysForScope(scopeId)) try {
log.debug("Custom ontology key : {}", key);
custom.addOntology(new StoredOntologySource(key));
} catch (MissingOntologyException ex) {
log.error("Could not find an ontology with public key {} to be managed by scope \"{}\". Proceeding to next ontology.", key, scopeId);
continue;
} catch (Exception ex) {
log.error("Exception caught while trying to add ontology with public key " + key + " to rebuilt scope \"" + scopeId + "\". proceeding to next ontology", ex);
continue;
}
log.info("Scope \"{}\" rebuilt in {} ms.", scopeId, System.currentTimeMillis() - before);
}
}
use of org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException in project stanbol by apache.
the class TestOntologySpaces method testRemoveCustomOntology.
@Test
public void testRemoveCustomOntology() throws Exception {
OntologySpace space = null;
space = factory.createCustomOntologySpace("testRemoveCustomOntology", dropSrc);
IRI dropId = dropSrc.getRootOntology().getOntologyID().getOntologyIRI();
IRI nonexId = nonexSrc.getRootOntology().getOntologyID().getOntologyIRI();
space.addOntology(inMemorySrc);
space.addOntology(nonexSrc);
// The other remote ontologies may change base IRI...
assertTrue(space.hasOntology(ont.getOntologyID().getOntologyIRI()));
assertTrue(space.hasOntology(dropId));
assertTrue(space.hasOntology(nonexId));
IRI bogus = IRI.create("http://www.example.org/ontology/bogus");
try {
space.removeOntology(bogus);
fail("Removing nonexisting ontology succeeded without an exception. This should not happen.");
} catch (MissingOntologyException mex) {
log.info("Expected exception caught when removing missing ontology {}", bogus);
}
space.removeOntology(dropId);
assertFalse(space.hasOntology(dropId));
space.removeOntology(nonexId);
assertFalse(space.hasOntology(nonexId));
// OntologyUtils.printOntology(space.getTopOntology(), System.err);
}
use of org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException in project stanbol by apache.
the class AbstractOntologyCollectorImpl method addOntology.
@Override
public synchronized OWLOntologyID addOntology(OntologyInputSource<?> ontologySource) throws UnmodifiableOntologyCollectorException {
// Check for error conditions.
if (locked)
throw new UnmodifiableOntologyCollectorException(this);
if (ontologySource == null)
throw new IllegalArgumentException("Ontology source cannot be null.");
log.debug("Adding ontology to collector {}", getID());
OWLOntologyID key = null;
if (ontologySource.hasRootOntology()) {
long before = System.currentTimeMillis();
Object o = ontologySource.getRootOntology();
// Check the origin anyhow, as it may be useful for setting aliases with physical locations etc.
if (ontologySource.hasOrigin())
key = ontologyProvider.loadInStore(o, false, ontologySource.getOrigin());
else
key = ontologyProvider.loadInStore(o, false);
if (key != null) {
managedOntologies.add(key);
// Note that imported ontologies are not considered as managed! TODO should we change this?
log.info("Add ontology completed in {} ms.", (System.currentTimeMillis() - before));
// Fire the event
fireOntologyAdded(key);
}
} else if (ontologySource.hasOrigin()) {
// Just the origin : see if it is satisfiable
log.debug("Checking origin satisfiability...");
Origin<?> origin = ontologySource.getOrigin();
Object ref = origin.getReference();
log.debug("Origin wraps a {}", ref.getClass().getCanonicalName());
if (ref instanceof org.semanticweb.owlapi.model.IRI)
try {
log.debug("Deferring addition to physical IRI {} (if available).", ref);
key = addOntology(new RootOntologySource((org.semanticweb.owlapi.model.IRI) ref));
} catch (OWLOntologyCreationException e) {
throw new RuntimeException(e);
}
else if (ref instanceof IRI) {
log.debug("Deferring addition to stored Clerezza graph {} (if available).", ref);
key = addOntology(new GraphSource((IRI) ref));
} else if (ref instanceof OWLOntologyID) {
OWLOntologyID idref = (OWLOntologyID) ref;
log.debug("Deferring addition to stored ontology with public key {} (if available).", ref);
if (!ontologyProvider.hasOntology(idref))
throw new MissingOntologyException(this, idref);
key = idref;
if (managedOntologies.add(idref))
fireOntologyAdded(idref);
} else
throw new IllegalArgumentException("Invalid origin " + origin);
} else
throw new IllegalArgumentException("Ontology source must provide either an ontology object, or a way to reference one (i.e. an origin).");
log.info("Public key : {}", key);
return key;
}
Aggregations