Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestOntologySpaces.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestOntologySpaces.java?rev=1153575&r1=1153574&r2=1153575&view=diff ============================================================================== --- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestOntologySpaces.java (original) +++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestOntologySpaces.java Wed Aug 3 16:47:20 2011 @@ -25,16 +25,18 @@ import java.util.Hashtable; import org.apache.stanbol.ontologymanager.ontonet.Constants; import org.apache.stanbol.ontologymanager.ontonet.api.ONManager; +import org.apache.stanbol.ontologymanager.ontonet.api.OfflineConfiguration; import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource; import org.apache.stanbol.ontologymanager.ontonet.api.io.ParentPathInputSource; import org.apache.stanbol.ontologymanager.ontonet.api.io.RootOntologySource; import org.apache.stanbol.ontologymanager.ontonet.api.ontology.CoreOntologySpace; import org.apache.stanbol.ontologymanager.ontonet.api.ontology.CustomOntologySpace; import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologySpaceFactory; -import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologySpaceModificationException; import org.apache.stanbol.ontologymanager.ontonet.api.ontology.SessionOntologySpace; import org.apache.stanbol.ontologymanager.ontonet.api.ontology.UnmodifiableOntologySpaceException; import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerImpl; +import org.apache.stanbol.ontologymanager.ontonet.impl.OfflineConfigurationImpl; +import org.apache.stanbol.owl.OWLOntologyManagerFactory; import org.junit.BeforeClass; import org.junit.Test; import org.semanticweb.owlapi.model.AddAxiom; @@ -59,31 +61,37 @@ public class TestOntologySpaces { private static OWLOntology ont = null, ont2 = null; - private static OntologyInputSource ontSrc, minorSrc, dropSrc, nonexSrc; + private static OntologyInputSource inMemorySrc, minorSrc, dropSrc, nonexSrc; private static OntologySpaceFactory spaceFactory; + private static OfflineConfiguration offline; + private static OntologyInputSource getLocalSource(String resourcePath, OWLOntologyManager mgr) throws OWLOntologyCreationException, URISyntaxException { URL url = TestOntologySpaces.class.getResource(resourcePath); File f = new File(url.toURI()); - return new ParentPathInputSource(f, mgr != null ? mgr : onm.getOntologyManagerFactory() - .createOntologyManager(true)); + return new ParentPathInputSource(f, mgr != null ? mgr + : OWLOntologyManagerFactory.createOWLOntologyManager(offline.getOntologySourceLocations() + .toArray(new IRI[0]))); } @BeforeClass public static void setup() throws Exception { + offline = new OfflineConfigurationImpl(new Hashtable<String,Object>()); + // An ONManagerImpl with no store and default settings - onm = new ONManagerImpl(null, null, new Hashtable<String,Object>()); + onm = new ONManagerImpl(null, null, offline, new Hashtable<String,Object>()); spaceFactory = onm.getOntologySpaceFactory(); if (spaceFactory == null) fail("Could not instantiate ontology space factory"); - OWLOntologyManager mgr = onm.getOntologyManagerFactory().createOntologyManager(true); + OWLOntologyManager mgr = OWLOntologyManagerFactory.createOWLOntologyManager(offline + .getOntologySourceLocations().toArray(new IRI[0])); OWLDataFactory df = mgr.getOWLDataFactory(); ont = mgr.createOntology(baseIri); - ontSrc = new RootOntologySource(ont, null); + inMemorySrc = new RootOntologySource(ont, null); // Let's state that Linus is a human being OWLClass cHuman = df.getOWLClass(IRI.create(baseIri + "/" + Constants.humanBeing)); OWLIndividual iLinus = df.getOWLNamedIndividual(IRI.create(baseIri + "/" + Constants.linus)); @@ -115,7 +123,7 @@ public class TestOntologySpaces { @Test public void testCoreLock() throws Exception { - CoreOntologySpace space = spaceFactory.createCoreOntologySpace(scopeIri, ontSrc); + CoreOntologySpace space = spaceFactory.createCoreOntologySpace(scopeIri, inMemorySrc); space.setUp(); try { space.addOntology(minorSrc); @@ -134,7 +142,7 @@ public class TestOntologySpaces { @Test public void testCustomLock() throws Exception { - CustomOntologySpace space = spaceFactory.createCustomOntologySpace(scopeIri, ontSrc); + CustomOntologySpace space = spaceFactory.createCustomOntologySpace(scopeIri, inMemorySrc); space.setUp(); try { space.addOntology(minorSrc); @@ -148,24 +156,20 @@ public class TestOntologySpaces { public void testRemoveCustomOntology() throws Exception { CustomOntologySpace space = null; space = spaceFactory.createCustomOntologySpace(scopeIri, dropSrc); - IRI pizzaId = dropSrc.getRootOntology().getOntologyID().getOntologyIRI(); - IRI wineId = nonexSrc.getRootOntology().getOntologyID().getOntologyIRI(); - try { - space.addOntology(ontSrc); - space.addOntology(nonexSrc); - // The other remote ontologies may change base IRI... - assertTrue(space.containsOntology(ont.getOntologyID().getOntologyIRI()) - && space.containsOntology(pizzaId) && space.containsOntology(wineId)); - space.removeOntology(dropSrc); - assertFalse(space.containsOntology(pizzaId)); - space.removeOntology(nonexSrc); - assertFalse(space.containsOntology(wineId)); - // OntologyUtils.printOntology(space.getTopOntology(), System.err); - } catch (UnmodifiableOntologySpaceException e) { - fail("Modification was disallowed on non-locked ontology space."); - } catch (OntologySpaceModificationException e) { - fail("Modification failed on ontology space " + e.getSpace().getID()); - } + 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.containsOntology(ont.getOntologyID().getOntologyIRI()) + && space.containsOntology(dropId) && space.containsOntology(nonexId)); + space.removeOntology(dropSrc); + assertFalse(space.containsOntology(dropId)); + space.removeOntology(nonexSrc); + assertFalse(space.containsOntology(nonexId)); + // OntologyUtils.printOntology(space.getTopOntology(), System.err); + } @Test @@ -174,16 +178,17 @@ public class TestOntologySpaces { space.setUp(); try { // First add an in-memory ontology with a few axioms. - space.addOntology(ontSrc); + space.addOntology(inMemorySrc); // Now add a real online ontology space.addOntology(dropSrc); // The in-memory ontology must be in the space. - assertTrue(space.getOntologies().contains(ont)); + assertTrue(space.getOntologies(true).contains(ont)); // The in-memory ontology must still have its axioms. assertTrue(space.getOntology(ont.getOntologyID().getOntologyIRI()).containsAxiom(linusIsHuman)); - // The top ontology must still have axioms from in-memory - // ontologies. - assertTrue(space.getTopOntology().containsAxiom(linusIsHuman)); + + // // The top ontology must still have axioms from in-memory + // // ontologies. NO LONGER + // assertTrue(space.getTopOntology().containsAxiom(linusIsHuman)); } catch (UnmodifiableOntologySpaceException e) { fail("Modification was denied on unlocked ontology space."); }
Modified: incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyRegistry.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyRegistry.java?rev=1153575&r1=1153574&r2=1153575&view=diff ============================================================================== --- incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyRegistry.java (original) +++ incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyRegistry.java Wed Aug 3 16:47:20 2011 @@ -163,8 +163,9 @@ public class TestOntologyRegistry { // space.addOntology(new // OntologyRegistryIRISource(testRegistryIri,onm.getOwlCacheManager(),onm.getRegistryLoader())); space.addOntology(ontologySource); + // FIXME : no longer use the top ontology? assertTrue(space.getTopOntology() != null); - assertTrue(space.getOntologies().contains(space.getTopOntology())); + assertTrue(space.getOntologies(true).contains(space.getTopOntology())); } /** Modified: incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ONMScopeOntologyResource.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ONMScopeOntologyResource.java?rev=1153575&r1=1153574&r2=1153575&view=diff ============================================================================== --- incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ONMScopeOntologyResource.java (original) +++ incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ONMScopeOntologyResource.java Wed Aug 3 16:47:20 2011 @@ -1,19 +1,19 @@ /* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You under the Apache License, Version 2.0 -* (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.stanbol.ontologymanager.web.resources; import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; @@ -106,6 +106,8 @@ public class ONMScopeOntologyResource ex if (!ontologyid.equals("all")) { + // First of all, it could be a simple request for the space root! + String absur = uriInfo.getAbsolutePath().toString(); URI uri = URI.create(absur.substring(0, absur.lastIndexOf(ontologyid) - 1)); @@ -119,6 +121,15 @@ public class ONMScopeOntologyResource ex OntologyScope scope = reg.getScope(sciri); if (scope == null) return Response.status(NOT_FOUND).build(); + // First of all, it could be a simple request for the space root! + if (ontiri.equals(scope.getCoreSpace().getID())) { + return Response.ok(scope.getCoreSpace().getTopOntology()).build(); + } else if (ontiri.equals(scope.getCustomSpace().getID())) { + return Response.ok(scope.getCustomSpace().getTopOntology()).build(); + } else if (scope.getSessionSpace(ontiri) != null) { + return Response.ok(scope.getSessionSpace(ontiri).getTopOntology()).build(); + } + /* * BEGIN debug code, uncomment only for local testing OWLOntology test = null, top = null; test = * scope.getCustomSpace().getOntology(ontiri); System.out.println("Ontology " + ontiri); for @@ -132,8 +143,11 @@ public class ONMScopeOntologyResource ex // By default, always try retrieving the ontology from the custom space // first. OntologySpace space = scope.getCustomSpace(); - if (space == null) space = scope.getCoreSpace(); if (space != null) ont = space.getOntology(ontiri); + if (space == null || ont == null) { + space = scope.getCoreSpace(); + if (space != null) ont = space.getOntology(ontiri); + } if (ont == null) { OWLOntologyManager tmpmgr; @@ -143,8 +157,8 @@ public class ONMScopeOntologyResource ex "OfflineConfiguration missing in ServletContext"); else tmpmgr = OWLOntologyManagerFactory.createOWLOntologyManager(offline .getOntologySourceLocations().toArray(new IRI[0])); - - final Set<OWLOntology> ontologies = scope.getSessionSpace(ontiri).getOntologies(); + + final Set<OWLOntology> ontologies = scope.getSessionSpace(ontiri).getOntologies(true); OWLOntologySetProvider provider = new OWLOntologySetProvider() { @Override @@ -179,9 +193,9 @@ public class ONMScopeOntologyResource ex if (scope == null) return Response.status(404).build(); - final Set<OWLOntology> customOntologies = scope.getCustomSpace().getOntologies(); + final Set<OWLOntology> customOntologies = scope.getCustomSpace().getOntologies(true); - final Set<OWLOntology> coreOntologies = scope.getCoreSpace().getOntologies(); + final Set<OWLOntology> coreOntologies = scope.getCoreSpace().getOntologies(true); final Set<OntologySpace> sessionSpaces = scope.getSessionSpaces(); @@ -240,7 +254,7 @@ public class ONMScopeOntologyResource ex // Inserisco le session ontologies; for (OntologySpace ontologySpace : sessionSpaces) { - Set<OWLOntology> sessionOntologies = ontologySpace.getOntologies(); + Set<OWLOntology> sessionOntologies = ontologySpace.getOntologies(true); for (OWLOntology ontology : sessionOntologies) { OWLOntology ont; Modified: incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ONMScopeResource.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ONMScopeResource.java?rev=1153575&r1=1153574&r2=1153575&view=diff ============================================================================== --- incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ONMScopeResource.java (original) +++ incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ONMScopeResource.java Wed Aug 3 16:47:20 2011 @@ -56,7 +56,6 @@ import org.apache.stanbol.ontologymanage import org.apache.stanbol.ontologymanager.registry.impl.RegistryLoaderImpl; import org.apache.stanbol.ontologymanager.registry.io.RegistryIRISource; import org.semanticweb.owlapi.model.IRI; -import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyCreationException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -81,8 +80,6 @@ public class ONMScopeResource extends Ba protected ClerezzaOntologyStorage storage; - protected ServletContext servletContext; - public ONMScopeResource(@Context ServletContext servletContext) { this.servletContext = servletContext; this.onm = (ONManager) ContextHelper.getServiceFromContext(ONManager.class, servletContext); @@ -112,19 +109,10 @@ public class ONMScopeResource extends Ba public Response getTopOntology(@Context UriInfo uriInfo, @Context HttpHeaders headers, @Context ServletContext servletContext) { - ScopeRegistry reg = onm.getScopeRegistry(); - OntologyScope scope = reg.getScope(IRI.create(uriInfo.getAbsolutePath())); - if (scope == null) return Response.status(404).build(); - - OntologySpace cs = scope.getCustomSpace(); - OWLOntology ont = null; - if (cs != null) ont = scope.getCustomSpace().getTopOntology(); - if (ont == null) ont = scope.getCoreSpace().getTopOntology(); - - return Response.ok(ont).build(); - + if (scope == null) return Response.status(NOT_FOUND).build(); + else return Response.ok(scope.asOWLOntology()).build(); } @POST @@ -207,7 +195,6 @@ public class ONMScopeResource extends Ba // First thing, check the core source. try { - coreSrc = new RegistryIRISource(IRI.create(coreRegistry), onm.getOwlCacheManager(), loader); } catch (Exception e1) { // Bad or not supplied core registry, try the ontology. Modified: incubator/stanbol/trunk/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Classify.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Classify.java?rev=1153575&r1=1153574&r2=1153575&view=diff ============================================================================== --- incubator/stanbol/trunk/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Classify.java (original) +++ incubator/stanbol/trunk/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Classify.java Wed Aug 3 16:47:20 2011 @@ -270,7 +270,7 @@ public class Classify extends BaseStanbo IRI iri = IRI.create(scope); ScopeRegistry reg = onm.getScopeRegistry(); OntologyScope ontoscope = reg.getScope(iri); - Iterator<OWLOntology> importscope = ontoscope.getCustomSpace().getOntologies().iterator(); + Iterator<OWLOntology> importscope = ontoscope.getCustomSpace().getOntologies(true).iterator(); Iterator<OntologySpace> importsession = ontoscope.getSessionSpaces().iterator(); // Add ontology as import form scope, if it is anonymus we @@ -287,7 +287,7 @@ public class Classify extends BaseStanbo // Add ontology form sessions while (importsession.hasNext()) { - Iterator<OWLOntology> sessionontos = importsession.next().getOntologies().iterator(); + Iterator<OWLOntology> sessionontos = importsession.next().getOntologies(true).iterator(); while (sessionontos.hasNext()) { OWLOntology auxonto = sessionontos.next(); if (!auxonto.getOntologyID().isAnonymous()) { @@ -310,7 +310,7 @@ public class Classify extends BaseStanbo ScopeRegistry reg = onm.getScopeRegistry(); OntologyScope ontoscope = reg.getScope(iri); SessionOntologySpace sos = ontoscope.getSessionSpace(IRI.create(session)); - for (OWLOntology a : ontoscope.getCustomSpace().getOntologies()) + for (OWLOntology a : ontoscope.getCustomSpace().getOntologies(true)) mgr.addAxioms(inputowl, a.getAxioms()); for (OWLOntology a : sos.getOntologyManager().getOntologies()) mgr.addAxioms(inputowl, a.getAxioms()); Modified: incubator/stanbol/trunk/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ConsistencyCheck.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ConsistencyCheck.java?rev=1153575&r1=1153574&r2=1153575&view=diff ============================================================================== --- incubator/stanbol/trunk/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ConsistencyCheck.java (original) +++ incubator/stanbol/trunk/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ConsistencyCheck.java Wed Aug 3 16:47:20 2011 @@ -320,7 +320,7 @@ public class ConsistencyCheck extends Ba IRI iri = IRI.create(scope); ScopeRegistry reg = onm.getScopeRegistry(); OntologyScope ontoscope = reg.getScope(iri); - Iterator<OWLOntology> importscope = ontoscope.getCustomSpace().getOntologies().iterator(); + Iterator<OWLOntology> importscope = ontoscope.getCustomSpace().getOntologies(true).iterator(); Iterator<OntologySpace> importsession = ontoscope.getSessionSpaces().iterator(); // Add ontology as import form scope, if it is anonymus we @@ -337,7 +337,7 @@ public class ConsistencyCheck extends Ba // Add ontology form sessions while (importsession.hasNext()) { - Iterator<OWLOntology> sessionontos = importsession.next().getOntologies().iterator(); + Iterator<OWLOntology> sessionontos = importsession.next().getOntologies(true).iterator(); while (sessionontos.hasNext()) { OWLOntology auxonto = sessionontos.next(); if (!auxonto.getOntologyID().isAnonymous()) { Modified: incubator/stanbol/trunk/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Enrichment.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Enrichment.java?rev=1153575&r1=1153574&r2=1153575&view=diff ============================================================================== --- incubator/stanbol/trunk/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Enrichment.java (original) +++ incubator/stanbol/trunk/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Enrichment.java Wed Aug 3 16:47:20 2011 @@ -247,7 +247,7 @@ public class Enrichment extends BaseStan IRI iri = IRI.create(scope); ScopeRegistry reg = onm.getScopeRegistry(); OntologyScope ontoscope = reg.getScope(iri); - Iterator<OWLOntology> importscope = ontoscope.getCustomSpace().getOntologies().iterator(); + Iterator<OWLOntology> importscope = ontoscope.getCustomSpace().getOntologies(true).iterator(); Iterator<OntologySpace> importsession = ontoscope.getSessionSpaces().iterator(); // Add ontology as import form scope, if it is anonymus we @@ -264,7 +264,7 @@ public class Enrichment extends BaseStan // Add ontology form sessions while (importsession.hasNext()) { - Iterator<OWLOntology> sessionontos = importsession.next().getOntologies().iterator(); + Iterator<OWLOntology> sessionontos = importsession.next().getOntologies(true).iterator(); while (sessionontos.hasNext()) { OWLOntology auxonto = sessionontos.next(); if (!auxonto.getOntologyID().isAnonymous()) {
