Search in sources :

Example 1 with MissingOntologyException

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);
    }
}
Also used : MissingOntologyException(org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) SessionLimitException(org.apache.stanbol.ontologymanager.servicesapi.session.SessionLimitException) StoredOntologySource(org.apache.stanbol.ontologymanager.servicesapi.io.StoredOntologySource) NonReferenceableSessionException(org.apache.stanbol.ontologymanager.servicesapi.session.NonReferenceableSessionException) MissingOntologyException(org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException) SessionLimitException(org.apache.stanbol.ontologymanager.servicesapi.session.SessionLimitException) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException) IOException(java.io.IOException) DuplicateSessionIDException(org.apache.stanbol.ontologymanager.servicesapi.session.DuplicateSessionIDException) OntologyNetworkConfiguration(org.apache.stanbol.ontologymanager.ontonet.api.OntologyNetworkConfiguration) Session(org.apache.stanbol.ontologymanager.servicesapi.session.Session) DuplicateSessionIDException(org.apache.stanbol.ontologymanager.servicesapi.session.DuplicateSessionIDException)

Example 2 with MissingOntologyException

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);
}
Also used : MissingOntologyException(org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException) UnmodifiableOntologyCollectorException(org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID)

Example 3 with MissingOntologyException

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);
    }
}
Also used : MissingOntologyException(org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException) StoredOntologySource(org.apache.stanbol.ontologymanager.servicesapi.io.StoredOntologySource) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) NoSuchScopeException(org.apache.stanbol.ontologymanager.servicesapi.scope.NoSuchScopeException) MissingOntologyException(org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException) UnmodifiableOntologyCollectorException(org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException) DuplicateIDException(org.apache.stanbol.ontologymanager.servicesapi.collector.DuplicateIDException) IOException(java.io.IOException) OntologyNetworkConfiguration(org.apache.stanbol.ontologymanager.ontonet.api.OntologyNetworkConfiguration) Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) DuplicateIDException(org.apache.stanbol.ontologymanager.servicesapi.collector.DuplicateIDException) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) OntologySpace(org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace) OntologyInputSource(org.apache.stanbol.ontologymanager.servicesapi.io.OntologyInputSource)

Example 4 with MissingOntologyException

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);
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) MissingOntologyException(org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException) OntologySpace(org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace) Test(org.junit.Test)

Example 5 with MissingOntologyException

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;
}
Also used : Origin(org.apache.stanbol.ontologymanager.servicesapi.io.Origin) IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) MissingOntologyException(org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) UnmodifiableOntologyCollectorException(org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) RootOntologySource(org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource) GraphSource(org.apache.stanbol.ontologymanager.sources.clerezza.GraphSource)

Aggregations

MissingOntologyException (org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException)5 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)4 UnmodifiableOntologyCollectorException (org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException)3 IOException (java.io.IOException)2 OntologyNetworkConfiguration (org.apache.stanbol.ontologymanager.ontonet.api.OntologyNetworkConfiguration)2 StoredOntologySource (org.apache.stanbol.ontologymanager.servicesapi.io.StoredOntologySource)2 OntologySpace (org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace)2 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)2 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)1 IRI (org.apache.clerezza.commons.rdf.IRI)1 DuplicateIDException (org.apache.stanbol.ontologymanager.servicesapi.collector.DuplicateIDException)1 OntologyInputSource (org.apache.stanbol.ontologymanager.servicesapi.io.OntologyInputSource)1 Origin (org.apache.stanbol.ontologymanager.servicesapi.io.Origin)1 NoSuchScopeException (org.apache.stanbol.ontologymanager.servicesapi.scope.NoSuchScopeException)1 Scope (org.apache.stanbol.ontologymanager.servicesapi.scope.Scope)1 DuplicateSessionIDException (org.apache.stanbol.ontologymanager.servicesapi.session.DuplicateSessionIDException)1 NonReferenceableSessionException (org.apache.stanbol.ontologymanager.servicesapi.session.NonReferenceableSessionException)1 Session (org.apache.stanbol.ontologymanager.servicesapi.session.Session)1 SessionLimitException (org.apache.stanbol.ontologymanager.servicesapi.session.SessionLimitException)1 GraphSource (org.apache.stanbol.ontologymanager.sources.clerezza.GraphSource)1