You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by al...@apache.org on 2012/07/30 16:12:26 UTC
svn commit: r1367100 [3/4] - in /incubator/stanbol/trunk:
commons/owl/src/main/java/org/apache/stanbol/commons/owl/util/
ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/
ontologymanager/ontonet/src/main/java/org/apa...
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/renderers/ScopeSetRenderer.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/renderers/ScopeSetRenderer.java?rev=1367100&r1=1367099&r2=1367100&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/renderers/ScopeSetRenderer.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/renderers/ScopeSetRenderer.java Mon Jul 30 14:12:24 2012
@@ -69,7 +69,7 @@ public class ScopeSetRenderer {
additions.add(new AddImport(ont, __factory.getOWLImportsDeclaration(IRI
.create("http://www.ontologydesignpatterns.org/schemas/meta.owl"))));
for (OntologyScope scope : scopes) {
- OWLNamedIndividual iScope = __factory.getOWLNamedIndividual(IRI.create(scope.getNamespace()
+ OWLNamedIndividual iScope = __factory.getOWLNamedIndividual(IRI.create(scope.getDefaultNamespace()
+ scope.getID()));
OWLAxiom ax = __factory.getOWLClassAssertionAxiom(cScope, iScope);
additions.add(new AddAxiom(ont, ax));
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionManagerImpl.java?rev=1367100&r1=1367099&r2=1367100&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionManagerImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionManagerImpl.java Mon Jul 30 14:12:24 2012
@@ -35,7 +35,7 @@ import org.apache.stanbol.ontologymanage
import org.apache.stanbol.ontologymanager.ontonet.api.OfflineConfiguration;
import org.apache.stanbol.ontologymanager.ontonet.api.OntologyNetworkConfiguration;
import org.apache.stanbol.ontologymanager.ontonet.api.collector.OntologyCollectorListener;
-import org.apache.stanbol.ontologymanager.ontonet.api.io.GraphSource;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.Origin;
import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyProvider;
import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologyScope;
import org.apache.stanbol.ontologymanager.ontonet.api.scope.ScopeEventListener;
@@ -51,6 +51,7 @@ import org.apache.stanbol.ontologymanage
import org.apache.stanbol.ontologymanager.ontonet.api.session.SessionManager;
import org.osgi.service.component.ComponentContext;
import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLOntologyID;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -257,12 +258,13 @@ public class SessionManagerImpl implemen
*/
if (sessionsByID.containsKey(sessionID)) throw new DuplicateSessionIDException(sessionID.toString());
checkSessionLimit();
- IRI ns = IRI.create(getNamespace() + getID() + "/");
+ IRI ns = IRI.create(getDefaultNamespace() + getID() + "/");
Session session = new SessionImpl(sessionID, ns, ontologyProvider);
// Have the ontology provider listen to ontology events
if (ontologyProvider instanceof OntologyCollectorListener) session
.addOntologyCollectorListener((OntologyCollectorListener) ontologyProvider);
+ else session.addOntologyCollectorListener(ontologyProvider.getOntologyNetworkDescriptor());
if (ontologyProvider instanceof SessionListener) session
.addSessionListener((SessionListener) ontologyProvider);
@@ -376,8 +378,11 @@ public class SessionManagerImpl implemen
// Register even if some ontologies were to fail to be restored afterwards.
sessionsByID.put(sessionId, session);
session.setActive(false); // Restored sessions are inactive at first.
- for (String key : struct.getOntologyKeysForSession(sessionId))
- session.addOntology(new GraphSource(key)); // TODO use the public key instead!
+ for (OWLOntologyID key : struct.getOntologyKeysForSession(sessionId)) {
+ session.addOntology(
+ // new GraphSource(key)
+ Origin.create(key)); // TODO use the public key instead!
+ }
for (String scopeId : struct.getAttachedScopes(sessionId)) {
/*
* The scope is attached by reference, so we won't have to bother checking if the scope
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/util/OntologyUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/util/OntologyUtils.java?rev=1367100&r1=1367099&r2=1367100&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/util/OntologyUtils.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/util/OntologyUtils.java Mon Jul 30 14:12:24 2012
@@ -33,6 +33,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Set;
+import org.apache.stanbol.commons.owl.util.URIUtils;
import org.apache.stanbol.ontologymanager.ontonet.api.collector.UnmodifiableOntologyCollectorException;
import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologySpaceSource;
@@ -50,6 +51,7 @@ import org.semanticweb.owlapi.model.OWLI
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyChange;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
+import org.semanticweb.owlapi.model.OWLOntologyID;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
import org.semanticweb.owlapi.model.UnknownOWLOntologyException;
@@ -69,17 +71,20 @@ public class OntologyUtils {
private static String[] preferredFormats = {RDF_XML, TURTLE, X_TURTLE, RDF_JSON, N3, N_TRIPLE,
MANCHESTER_OWL, FUNCTIONAL_OWL, OWL_XML};
+ @Deprecated
public static OWLOntology appendOntology(OntologyInputSource<OWLOntology> parentSrc,
OntologyInputSource<OWLOntology> childSrc) {
return appendOntology(parentSrc, childSrc, null, null);
}
+ @Deprecated
public static OWLOntology appendOntology(OntologyInputSource<OWLOntology> parentSrc,
OntologyInputSource<OWLOntology> childSrc,
IRI rewritePrefix) {
return appendOntology(parentSrc, childSrc, null, rewritePrefix);
}
+ @Deprecated
public static OWLOntology appendOntology(OntologyInputSource<OWLOntology> parentSrc,
OntologyInputSource<OWLOntology> childSrc,
OWLOntologyManager ontologyManager) {
@@ -93,6 +98,7 @@ public class OntologyUtils {
* parent. <br>
* Note: the ontology manager will not load additional ontologies.
*
+ * @deprecated
* @param parentSrc
* must exist!
* @param childSrc
@@ -194,6 +200,56 @@ public class OntologyUtils {
}
/**
+ * Provides a standardized string format for an OWL Ontology ID. The string returned is of type
+ * <tt>ontologyIRI[:::versionIRI]</tt>. Any substring <tt>":::"</tt> present in <tt>ontologyIRI</tt> or
+ * <tt>versionIRI</tt> will be URL-encoded (i.e. converted to <tt>"%3A%3A%3A"</tt>).<br/>
+ * <br/>
+ * Also note that both <tt>ontologyIRI</tt> and <tt>versionIRI</tt> are sanitized in the process. No other
+ * URL encoding occurs.
+ *
+ * @param id
+ * the OWL ontology ID to encode
+ * @return the string form of this ID.
+ * @see URIUtils#sanitize(IRI)
+ */
+ public static String encode(OWLOntologyID id) {
+ if (id == null) throw new IllegalArgumentException("Cannot encode a null OWLOntologyID.");
+ if (id.getOntologyIRI() == null) throw new IllegalArgumentException(
+ "Cannot encode an OWLOntologyID that is missing an ontologyIRI.");
+ String s = "";
+ s += URIUtils.sanitize(id.getOntologyIRI()).toString().replace(":::", "%3A%3A%3A");
+ if (id.getVersionIRI() != null) s += (":::")
+ + URIUtils.sanitize(id.getVersionIRI()).toString()
+ .replace(":::", "%3A%3A%3A");
+ return s;
+ }
+
+ /**
+ * Extracts an OWL Ontology ID from its standard string form. The string must be of type
+ * <tt>ontologyIRI[:::versionIRI]</tt>. Any substring <tt>"%3A%3A%3A"</tt> present in <tt>ontologyIRI</tt>
+ * or <tt>versionIRI</tt> will be URL-decoded (i.e. converted to <tt>":::"</tt>).<br/>
+ * <br/>
+ * Also note that both <tt>ontologyIRI</tt> and <tt>versionIRI</tt> are desanitized in the process.
+ *
+ * @param stringForm
+ * the string to decode
+ * @return the string form of this ID.
+ * @see URIUtils#desanitize(IRI)
+ */
+ public static OWLOntologyID decode(String stringForm) {
+ if (stringForm == null || stringForm.isEmpty()) throw new IllegalArgumentException(
+ "Supplied string form must be non-null and non-empty.");
+ IRI oiri, viri;
+ String[] split = stringForm.split(":::");
+ if (split.length >= 1) {
+ oiri = URIUtils.desanitize(IRI.create(split[0].replace("%3A%3A%3A", ":::")));
+ viri = (split.length > 1) ? URIUtils.desanitize(IRI.create(split[1].replace("%3A%3A%3A", ":::")))
+ : null;
+ return (viri != null) ? new OWLOntologyID(oiri, viri) : new OWLOntologyID(oiri);
+ } else return null; // Anonymous but versioned ontologies are not acceptable.
+ }
+
+ /**
* Non-recursively adds import statements to the root ontology so that it is directly linked to all the
* ontologies in the subtrees set.
*
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/TestOntologyNetworkPersistence.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/TestOntologyNetworkPersistence.java?rev=1367100&r1=1367099&r2=1367100&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/TestOntologyNetworkPersistence.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/TestOntologyNetworkPersistence.java Mon Jul 30 14:12:24 2012
@@ -68,106 +68,9 @@ public class TestOntologyNetworkPersiste
private Logger log = LoggerFactory.getLogger(getClass());
- private OntologyProvider<TcProvider> ontologyProvider;
-
private ONManager onm;
- @Test
- public void updatesGraphOnSpaceModification() throws Exception {
-
- // Ensure the metadata graph is there.
- TripleCollection meta = ontologyProvider.getMetaGraph(TripleCollection.class);
- assertNotNull(meta);
-
- String scopeId = "updateTest";
- OntologyScope scope = onm.createOntologyScope(scopeId, new GraphContentInputSource(getClass()
- .getResourceAsStream("/ontologies/test1.owl")));
-
- UriRef collector = new UriRef(_NS_STANBOL_INTERNAL + OntologySpace.shortName + "/"
- + scope.getCoreSpace().getID());
- UriRef test1id = new UriRef(ontologyProvider.getKey(IRI
- .create("http://stanbol.apache.org/ontologies/test1.owl"))); // Has no versionIRI
- // Be strict: the whole property pair must be there.
- UriRef predicate = MANAGES;
- assertTrue(meta.contains(new TripleImpl(collector, predicate, test1id)));
- predicate = IS_MANAGED_BY;
- assertTrue(meta.contains(new TripleImpl(test1id, predicate, collector)));
-
- scope.tearDown(); // To modify the core space.
-
- scope.getCoreSpace().addOntology(
- new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/minorcharacters.owl")));
- UriRef minorId = new UriRef(ontologyProvider.getKey(IRI
- .create("http://stanbol.apache.org/ontologies/pcomics/minorcharacters.owl")));
- predicate = MANAGES;
- assertTrue(meta.contains(new TripleImpl(collector, predicate, minorId)));
- predicate = IS_MANAGED_BY;
- assertTrue(meta.contains(new TripleImpl(minorId, predicate, collector)));
-
- scope.getCustomSpace().addOntology(
- new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/test1.owl")));
-
- scope.getCustomSpace().addOntology(
- new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/minorcharacters.owl")));
- }
-
- @Test
- public void preservesManagedOntologies() throws Exception {
- String id = "preserve";
- OntologyScope scope = onManager.createOntologyScope(id, new GraphContentInputSource(getClass()
- .getResourceAsStream("/ontologies/mockfoaf.rdf")));
- scope.getCustomSpace().addOntology(
- new GraphContentInputSource(getClass().getResourceAsStream(
- "/ontologies/nonexistentcharacters.owl")));
-
- // Simulate Stanbol going down.
- log.info("Stanbol going down...");
- resetOntologyProvider(); // but keep the TcProvider
- resetManagers();
-
- OntologyScope sc = onManager.getScope(id);
- assertNotNull(sc);
- // assertEquals(scope, sc); XXX should scopes be equal on ID + content?
- }
-
- @Test
- public void scopesAndSessionsOutliveOntoNet() throws Exception {
- /*
- * Both scopes will be created, but scope1 will be unregistered and we expect not to be able to
- * rebuild it.
- */
- String id1 = "scope1", id2 = "scope2", sid2 = "auto-" + System.currentTimeMillis();
-
- // Setup a network
- OntologyScope scope1 = onManager.createOntologyScope(id1);
- assertNotNull(scope1);
- OntologyScope scope2 = onManager.createOntologyScope(id2);
- assertNotNull(scope2);
- onManager.deregisterScope(scope1);
-
- // A session with a system ID
- Session ses1 = sessionManager.createSession();
- String sid1 = ses1.getID();
- assertNotNull(ses1);
- assertNotNull(sid1);
- assertFalse(sid1.isEmpty());
- // A session with an ID chosen manually
- Session ses2 = sessionManager.createSession(sid2);
- assertNotNull(ses2);
- assertNotNull(ses2.getID());
- assertEquals(sid2, ses2.getID());
-
- log.info("Stanbol going down...");
- resetOntologyProvider(); // but keep the TcProvider
- resetManagers();
-
- // The unregistered scope should be missing.
- assertNull(onManager.getScope(id1));
- // The other collectors should have been rebuilt.
- assertNotNull(onManager.getScope(id2));
- assertNotNull(sessionManager.getSession(sid1));
- assertNotNull(sessionManager.getSession(sid2));
- }
+ private OntologyProvider<TcProvider> ontologyProvider;
/*
* Use a dedicated TC Provider that is setup once before the tests begin and never cleared.
@@ -279,6 +182,25 @@ public class TestOntologyNetworkPersiste
new OntologySpaceFactoryImpl(ontologyProvider, empty), empty);
}
+ @Test
+ public void preservesManagedOntologies() throws Exception {
+ String id = "preserve";
+ OntologyScope scope = onManager.createOntologyScope(id, new GraphContentInputSource(getClass()
+ .getResourceAsStream("/ontologies/mockfoaf.rdf")));
+ scope.getCustomSpace().addOntology(
+ new GraphContentInputSource(getClass().getResourceAsStream(
+ "/ontologies/nonexistentcharacters.owl")));
+
+ // Simulate Stanbol going down.
+ log.info("Stanbol going down...");
+ resetOntologyProvider(); // but keep the TcProvider
+ resetManagers();
+
+ OntologyScope sc = onManager.getScope(id);
+ assertNotNull(sc);
+ // assertEquals(scope, sc); XXX should scopes be equal on ID + content?
+ }
+
/*
* With this method, the ontology provider and all its internal indices are cleared. However, the Clerezza
* persistence objects are not cleared, so we can check if we can still retrieve metadata from them.
@@ -288,4 +210,80 @@ public class TestOntologyNetworkPersiste
new Hashtable<String,Object>()), parser);
}
+ @Test
+ public void scopesAndSessionsOutliveOntoNet() throws Exception {
+ /*
+ * Both scopes will be created, but scope1 will be unregistered and we expect not to be able to
+ * rebuild it.
+ */
+ String id1 = "scope1", id2 = "scope2", sid2 = "auto-" + System.currentTimeMillis();
+
+ // Setup a network
+ OntologyScope scope1 = onManager.createOntologyScope(id1);
+ assertNotNull(scope1);
+ OntologyScope scope2 = onManager.createOntologyScope(id2);
+ assertNotNull(scope2);
+ onManager.deregisterScope(scope1);
+
+ // A session with a system ID
+ Session ses1 = sessionManager.createSession();
+ String sid1 = ses1.getID();
+ assertNotNull(ses1);
+ assertNotNull(sid1);
+ assertFalse(sid1.isEmpty());
+ // A session with an ID chosen manually
+ Session ses2 = sessionManager.createSession(sid2);
+ assertNotNull(ses2);
+ assertNotNull(ses2.getID());
+ assertEquals(sid2, ses2.getID());
+
+ log.info("Stanbol going down...");
+ resetOntologyProvider(); // but keep the TcProvider
+ resetManagers();
+
+ // The unregistered scope should be missing.
+ assertNull(onManager.getScope(id1));
+ // The other collectors should have been rebuilt.
+ assertNotNull(onManager.getScope(id2));
+ assertNotNull(sessionManager.getSession(sid1));
+ assertNotNull(sessionManager.getSession(sid2));
+ }
+
+ @Test
+ public void updatesGraphOnSpaceModification() throws Exception {
+
+ // Ensure the metadata graph is there.
+ TripleCollection meta = ontologyProvider.getMetaGraph(TripleCollection.class);
+ assertNotNull(meta);
+
+ String scopeId = "updateTest";
+ OntologyScope scope = onm.createOntologyScope(scopeId, new GraphContentInputSource(getClass()
+ .getResourceAsStream("/ontologies/test1.owl")));
+
+ UriRef collector = new UriRef(_NS_STANBOL_INTERNAL + OntologySpace.shortName + "/"
+ + scope.getCoreSpace().getID());
+ UriRef test1id = new UriRef("http://stanbol.apache.org/ontologies/test1.owl"); // Has no versionIRI
+ // Be strict: the whole property pair must be there.
+ UriRef predicate = MANAGES;
+ assertTrue(meta.contains(new TripleImpl(collector, predicate, test1id)));
+ predicate = IS_MANAGED_BY;
+ assertTrue(meta.contains(new TripleImpl(test1id, predicate, collector)));
+
+ scope.tearDown(); // To modify the core space.
+
+ scope.getCoreSpace().addOntology(
+ new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/minorcharacters.owl")));
+ UriRef minorId = new UriRef("http://stanbol.apache.org/ontologies/pcomics/minorcharacters.owl");
+ predicate = MANAGES;
+ assertTrue(meta.contains(new TripleImpl(collector, predicate, minorId)));
+ predicate = IS_MANAGED_BY;
+ assertTrue(meta.contains(new TripleImpl(minorId, predicate, collector)));
+
+ scope.getCustomSpace().addOntology(
+ new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/test1.owl")));
+
+ scope.getCustomSpace().addOntology(
+ new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/minorcharacters.owl")));
+ }
+
}
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestClerezzaSpaces.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestClerezzaSpaces.java?rev=1367100&r1=1367099&r2=1367100&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestClerezzaSpaces.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestClerezzaSpaces.java Mon Jul 30 14:12:24 2012
@@ -116,7 +116,7 @@ public class TestClerezzaSpaces {
factory = new OntologySpaceFactoryImpl(new ClerezzaOntologyProvider(tcManager, offline, parser),
new Hashtable<String,Object>());
- factory.setNamespace(IRI.create("http://stanbol.apache.org/ontology/"));
+ factory.setDefaultNamespace(IRI.create("http://stanbol.apache.org/ontology/"));
}
String scopeId = "Comics";
@@ -210,7 +210,7 @@ public class TestClerezzaSpaces {
/* Now test namespaces. */
// Null namespace (invalid).
- factory.setNamespace(null);
+ factory.setDefaultNamespace(null);
try {
shouldBeNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE);
fail("Expected IllegalArgumentException not thrown despite null OntoNet namespace.");
@@ -218,7 +218,7 @@ public class TestClerezzaSpaces {
assertNull(shouldBeNull);
// Namespace with query (invalid).
- factory.setNamespace(IRI.create("http://stanbol.apache.org/ontology/?query=true"));
+ factory.setDefaultNamespace(IRI.create("http://stanbol.apache.org/ontology/?query=true"));
try {
shouldBeNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE);
fail("Expected IllegalArgumentException not thrown despite query in OntoNet namespace.");
@@ -226,7 +226,7 @@ public class TestClerezzaSpaces {
assertNull(shouldBeNull);
// Namespace with fragment (invalid).
- factory.setNamespace(IRI.create("http://stanbol.apache.org/ontology#fragment"));
+ factory.setDefaultNamespace(IRI.create("http://stanbol.apache.org/ontology#fragment"));
try {
shouldBeNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE);
fail("Expected IllegalArgumentException not thrown despite fragment in OntoNet namespace.");
@@ -234,7 +234,7 @@ public class TestClerezzaSpaces {
assertNull(shouldBeNull);
// Namespace ending with hash (invalid).
- factory.setNamespace(IRI.create("http://stanbol.apache.org/ontology#"));
+ factory.setDefaultNamespace(IRI.create("http://stanbol.apache.org/ontology#"));
try {
shouldBeNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE);
fail("Expected IllegalArgumentException not thrown despite fragment in OntoNet namespace.");
@@ -242,15 +242,15 @@ public class TestClerezzaSpaces {
assertNull(shouldBeNull);
// Namespace ending with neither (valid, should automatically add slash).
- factory.setNamespace(IRI.create("http://stanbol.apache.org/ontology"));
+ factory.setDefaultNamespace(IRI.create("http://stanbol.apache.org/ontology"));
shouldBeNotNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE);
assertNotNull(shouldBeNotNull);
- assertTrue(shouldBeNotNull.getNamespace().toString().endsWith("/"));
+ assertTrue(shouldBeNotNull.getDefaultNamespace().toString().endsWith("/"));
shouldBeNotNull = null;
// Namespace ending with slash (valid).
- factory.setNamespace(IRI.create("http://stanbol.apache.org/ontology/"));
+ factory.setDefaultNamespace(IRI.create("http://stanbol.apache.org/ontology/"));
shouldBeNotNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE);
assertNotNull(shouldBeNotNull);
}
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestOntologyScope.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestOntologyScope.java?rev=1367100&r1=1367099&r2=1367100&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestOntologyScope.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestOntologyScope.java Mon Jul 30 14:12:24 2012
@@ -16,7 +16,7 @@
*/
package org.apache.stanbol.ontologymanager.ontonet.ontology;
-import static org.apache.stanbol.ontologymanager.ontonet.MockOsgiContext.onManager;
+import static org.apache.stanbol.ontologymanager.ontonet.MockOsgiContext.*;
import static org.apache.stanbol.ontologymanager.ontonet.MockOsgiContext.reset;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -138,10 +138,10 @@ public class TestOntologyScope {
onManager.setOntologyNetworkNamespace("http://stanbol.apache.org/ontology");
shouldBeNotNull = onManager.createOntologyScope(scopeIdBlank);
assertNotNull(shouldBeNotNull);
- assertTrue(shouldBeNotNull.getNamespace().toString().endsWith("/"));
+ assertTrue(shouldBeNotNull.getDefaultNamespace().toString().endsWith("/"));
// Now set again the correct namespace.
- onManager.setOntologyNetworkNamespace(onManager.getOntologyNetworkNamespace());
+ onManager.setOntologyNetworkNamespace(offline.getDefaultOntologyNetworkNamespace().toString());
shouldBeNotNull = null;
try {
shouldBeNotNull = onManager.createOntologyScope(scopeId1, src1, src2);
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=1367100&r1=1367099&r2=1367100&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 Mon Jul 30 14:12:24 2012
@@ -31,6 +31,7 @@ import java.net.URL;
import org.apache.stanbol.commons.owl.OWLOntologyManagerFactory;
import org.apache.stanbol.ontologymanager.ontonet.Constants;
+import org.apache.stanbol.ontologymanager.ontonet.api.collector.MissingOntologyException;
import org.apache.stanbol.ontologymanager.ontonet.api.collector.UnmodifiableOntologyCollectorException;
import org.apache.stanbol.ontologymanager.ontonet.api.io.BlankOntologySource;
import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
@@ -53,6 +54,8 @@ import org.semanticweb.owlapi.model.OWLI
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class TestOntologySpaces {
@@ -63,6 +66,8 @@ public class TestOntologySpaces {
private static OntologyInputSource<OWLOntology> inMemorySrc, minorSrc, dropSrc, nonexSrc;
private static OWLAxiom linusIsHuman = null;
+ private Logger log = LoggerFactory.getLogger(getClass());
+
private static OWLOntology ont = null, ont2 = null;
private static OntologyInputSource<OWLOntology> getLocalSource(String resourcePath, OWLOntologyManager mgr) throws OWLOntologyCreationException,
@@ -180,7 +185,7 @@ public class TestOntologySpaces {
/* Now test namespaces. */
// Null namespace (invalid).
- factory.setNamespace(null);
+ factory.setDefaultNamespace(null);
try {
shouldBeNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE, new BlankOntologySource());
fail("Expected IllegalArgumentException not thrown despite null OntoNet namespace.");
@@ -188,7 +193,7 @@ public class TestOntologySpaces {
assertNull(shouldBeNull);
// Namespace with query (invalid).
- factory.setNamespace(IRI.create("http://stanbol.apache.org/ontology/?query=true"));
+ factory.setDefaultNamespace(IRI.create("http://stanbol.apache.org/ontology/?query=true"));
try {
shouldBeNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE, new BlankOntologySource());
fail("Expected IllegalArgumentException not thrown despite query in OntoNet namespace.");
@@ -196,7 +201,7 @@ public class TestOntologySpaces {
assertNull(shouldBeNull);
// Namespace with fragment (invalid).
- factory.setNamespace(IRI.create("http://stanbol.apache.org/ontology#fragment"));
+ factory.setDefaultNamespace(IRI.create("http://stanbol.apache.org/ontology#fragment"));
try {
shouldBeNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE, new BlankOntologySource());
fail("Expected IllegalArgumentException not thrown despite fragment in OntoNet namespace.");
@@ -204,7 +209,7 @@ public class TestOntologySpaces {
assertNull(shouldBeNull);
// Namespace ending with hash (invalid).
- factory.setNamespace(IRI.create("http://stanbol.apache.org/ontology#"));
+ factory.setDefaultNamespace(IRI.create("http://stanbol.apache.org/ontology#"));
try {
shouldBeNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE);
fail("Expected IllegalArgumentException not thrown despite fragment in OntoNet namespace.");
@@ -212,15 +217,15 @@ public class TestOntologySpaces {
assertNull(shouldBeNull);
// Namespace ending with neither (valid, should automatically add slash).
- factory.setNamespace(IRI.create("http://stanbol.apache.org/ontology"));
+ factory.setDefaultNamespace(IRI.create("http://stanbol.apache.org/ontology"));
shouldBeNotNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE);
assertNotNull(shouldBeNotNull);
- assertTrue(shouldBeNotNull.getNamespace().toString().endsWith("/"));
+ assertTrue(shouldBeNotNull.getDefaultNamespace().toString().endsWith("/"));
shouldBeNotNull = null;
// Namespace ending with slash (valid).
- factory.setNamespace(IRI.create("http://stanbol.apache.org/ontology/"));
+ factory.setDefaultNamespace(IRI.create("http://stanbol.apache.org/ontology/"));
shouldBeNotNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE);
assertNotNull(shouldBeNotNull);
}
@@ -241,7 +246,12 @@ public class TestOntologySpaces {
assertTrue(space.hasOntology(nonexId));
IRI bogus = IRI.create("http://www.example.org/ontology/bogus");
- space.removeOntology(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));
Modified: incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/OntoNetRootResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/OntoNetRootResource.java?rev=1367100&r1=1367099&r2=1367100&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/OntoNetRootResource.java (original)
+++ incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/OntoNetRootResource.java Mon Jul 30 14:12:24 2012
@@ -57,6 +57,8 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
import javax.servlet.ServletContext;
import javax.ws.rs.Consumes;
@@ -76,6 +78,7 @@ import javax.ws.rs.core.Response.Respons
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;
+import org.apache.clerezza.rdf.core.Graph;
import org.apache.clerezza.rdf.core.MGraph;
import org.apache.clerezza.rdf.core.Triple;
import org.apache.clerezza.rdf.core.TripleCollection;
@@ -84,14 +87,19 @@ import org.apache.clerezza.rdf.core.impl
import org.apache.clerezza.rdf.core.serializedform.UnsupportedFormatException;
import org.apache.clerezza.rdf.ontologies.OWL;
import org.apache.stanbol.commons.indexedgraph.IndexedMGraph;
+import org.apache.stanbol.commons.owl.util.URIUtils;
import org.apache.stanbol.commons.web.base.ContextHelper;
import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
+import org.apache.stanbol.ontologymanager.ontonet.api.OntologyLoadingException;
import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyContentInputSource;
import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyNetworkMultiplexer;
import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyProvider;
import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologyScope;
import org.apache.stanbol.ontologymanager.ontonet.api.session.SessionManager;
+import org.apache.stanbol.ontologymanager.ontonet.impl.clerezza.MGraphNetworkMultiplexer;
+import org.apache.stanbol.ontologymanager.ontonet.impl.util.OntologyUtils;
import org.apache.stanbol.ontologymanager.registry.api.RegistryContentException;
import org.apache.stanbol.ontologymanager.registry.api.RegistryManager;
import org.apache.stanbol.ontologymanager.registry.api.model.Library;
@@ -104,6 +112,7 @@ import org.semanticweb.owlapi.model.OWLI
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyChange;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
+import org.semanticweb.owlapi.model.OWLOntologyID;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
import org.semanticweb.owlapi.model.RemoveImport;
import org.slf4j.Logger;
@@ -129,6 +138,8 @@ public class OntoNetRootResource extends
private Logger log = LoggerFactory.getLogger(getClass());
+ protected ONManager onManager;
+
/*
* Placeholder for the OntologyProvider to be fetched from the servlet context.
*/
@@ -139,8 +150,6 @@ public class OntoNetRootResource extends
*/
protected RegistryManager registryManager;
- protected ONManager onManager;
-
protected SessionManager sessionManager;
public OntoNetRootResource(@Context ServletContext servletContext) {
@@ -178,7 +187,8 @@ public class OntoNetRootResource extends
}
private MGraph getGraph(String ontologyId, boolean merged) {
- IRI iri = IRI.create(ontologyId);
+ long before = System.currentTimeMillis();
+ IRI iri = URIUtils.sanitize(IRI.create(ontologyId));
log.debug("Will try to retrieve ontology {} from provider.", iri);
/*
* Export directly to MGraph since the OWLOntologyWriter uses (de-)serializing converters for the
@@ -190,7 +200,7 @@ public class OntoNetRootResource extends
*/
MGraph o = null, oTemp = null;
try {
- oTemp = ontologyProvider.getStoredOntology(iri, MGraph.class, merged);
+ oTemp = ontologyProvider.getStoredOntology(new OWLOntologyID(iri), MGraph.class, merged);
} catch (Exception ex) {
log.warn("Retrieval of ontology with ID " + iri + " failed.", ex);
}
@@ -248,9 +258,21 @@ public class OntoNetRootResource extends
// remove old statement
o.remove(t);
}
+ log.debug("Exported as Clerezza Graph in {} ms. Handing over to writer.", System.currentTimeMillis()
+ - before);
return o;
}
+ public Set<String> getHandles(OWLOntologyID ontologyId) {
+ Set<String> handles = new HashSet<String>();
+ if (onManager != null) for (OntologyScope scope : onManager.getRegisteredScopes())
+ if (scope.getCoreSpace().hasOntology(ontologyId)
+ || scope.getCustomSpace().hasOntology(ontologyId)) handles.add(scope.getID());
+ if (sessionManager != null) for (String sesId : sessionManager.getRegisteredSessionIDs())
+ if (sessionManager.getSession(sesId).hasOntology(ontologyId)) handles.add(sesId);
+ return handles;
+ }
+
@GET
@Produces(TEXT_HTML)
public Response getHtmlInfo(@Context HttpHeaders headers) {
@@ -306,33 +328,31 @@ public class OntoNetRootResource extends
return rb.build();
}
- public Set<String> getOntologies() {
- Set<String> filtered = new HashSet<String>();
- for (String s : ontologyProvider.getPublicKeys()) {
- // String s1 = s.split("::")[1];
- if (s != null && !s.isEmpty()) filtered.add(s);
- }
- return filtered;
+ @GET
+ @Produces({RDF_XML, TURTLE, X_TURTLE, APPLICATION_JSON, RDF_JSON})
+ public Response getMetaGraph(@Context HttpHeaders headers) {
+ ResponseBuilder rb = Response.ok(ontologyProvider.getMetaGraph(Graph.class));
+ addCORSOrigin(servletContext, rb, headers);
+ return rb.build();
}
- public Set<String> getHandles(String ontologyId) {
- Set<String> handles = new HashSet<String>();
- IRI ontologyIri = IRI.create(ontologyId);
- if (onManager != null) for (OntologyScope scope : onManager.getRegisteredScopes())
- if (scope.getCoreSpace().hasOntology(ontologyIri)
- || scope.getCustomSpace().hasOntology(ontologyIri)) handles.add(scope.getID());
- if (sessionManager != null) for (String sesId : sessionManager.getRegisteredSessionIDs())
- if (sessionManager.getSession(sesId).hasOntology(ontologyIri)) handles.add(sesId);
- return handles;
+ public SortedSet<OWLOntologyID> getOntologies() {
+ SortedSet<OWLOntologyID> filtered = new TreeSet<OWLOntologyID>();
+ for (OWLOntologyID id : ontologyProvider.getPublicKeys())
+ if (id != null) filtered.add(id);
+
+ return filtered;
}
private OWLOntology getOntology(String ontologyId, boolean merge) {
- IRI iri = IRI.create(ontologyId);
+ long before = System.currentTimeMillis();
+ IRI iri = URIUtils.sanitize(IRI.create(ontologyId));
log.debug("Will try to retrieve ontology {} from provider.", iri);
// TODO be selective: if the ontology is small enough, use OWLOntology otherwise export to Graph.
OWLOntology o = null;
try {
- o = (OWLOntology) ontologyProvider.getStoredOntology(iri, OWLOntology.class, merge);
+ o = (OWLOntology) ontologyProvider.getStoredOntology(new OWLOntologyID(iri), OWLOntology.class,
+ merge);
} catch (Exception ex) {
log.warn("Retrieval of ontology with ID " + iri + " failed.", ex);
}
@@ -366,26 +386,31 @@ public class OntoNetRootResource extends
log.debug("Retrieved ontology {} .", iri);
- // Rewrite import statements
- String uri = uriInfo.getRequestUri().toString();
- URI base = URI.create(uri.substring(0, uri.lastIndexOf(ontologyId) - 1));
+ // Rewrite import statements - no ontology collector to do it for us here.
+ URI base = URI.create(getPublicBaseUri() + "ontonet/");
List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
OWLDataFactory df = o.getOWLOntologyManager().getOWLDataFactory();
- /*
- * TODO manage import rewrites better once the container ID is fully configurable (i.e. instead of
- * going upOne() add "session" or "ontology" if needed).
- */
+
+ // TODO manage import rewrites better once the container ID is fully configurable.
for (OWLImportsDeclaration oldImp : o.getImportsDeclarations()) {
changes.add(new RemoveImport(o, oldImp));
String s = oldImp.getIRI().toString();
if (s.contains("::")) s = s.substring(s.indexOf("::") + 2, s.length());
- IRI target = IRI.create(base + "/" + s);
+ IRI target = IRI.create(base + s);
changes.add(new AddImport(o, df.getOWLImportsDeclaration(target)));
}
o.getOWLOntologyManager().applyChanges(changes);
+ log.debug("Exported as Clerezza Graph in {} ms. Handing over to writer.", System.currentTimeMillis()
+ - before);
return o;
}
+ public int getSize(OWLOntologyID ontologyId) {
+ OntologyNetworkMultiplexer desc = new MGraphNetworkMultiplexer(
+ ontologyProvider.getMetaGraph(MGraph.class));
+ return desc.getSize(ontologyId);
+ }
+
@POST
@Consumes({MULTIPART_FORM_DATA})
@Produces({TEXT_HTML, TEXT_PLAIN, RDF_XML, TURTLE, X_TURTLE, N3})
@@ -427,10 +452,14 @@ public class OntoNetRootResource extends
formats = Arrays.asList(new String[] {RDF_XML, TURTLE, X_TURTLE, N3, N_TRIPLE, OWL_XML,
FUNCTIONAL_OWL, MANCHESTER_OWL, RDF_JSON});
int unsupported = 0, failed = 0;
- for (String f : formats)
+ Iterator<String> itf = formats.iterator();
+ if (!itf.hasNext()) throw new OntologyLoadingException("No suitable format found or defined.");
+ do {
+ String f = itf.next();
try {
// Re-instantiate the stream on every attempt
InputStream content = new FileInputStream(file);
+ // ClerezzaOWLUtils.guessOntologyID(new FileInputStream(file), Parser.getInstance(), f);
key = ontologyProvider.loadInStore(content, f, true);
} catch (UnsupportedFormatException e) {
log.warn(
@@ -438,16 +467,14 @@ public class OntoNetRootResource extends
headers.getMediaType());
// rb = Response.status(UNSUPPORTED_MEDIA_TYPE);
unsupported++;
- continue;
} catch (IOException e) {
log.debug(">>> FAILURE format {} (I/O error)", f);
failed++;
- continue;
} catch (Exception e) { // SAXParseException and others
log.debug(">>> FAILURE format {} (parse error)", f);
failed++;
- continue;
}
+ } while ((key == null || key.trim().isEmpty()) && itf.hasNext());
if (key == null || key.trim().isEmpty()) {
if (failed > 0) throw new WebApplicationException(BAD_REQUEST);
else if (unsupported > 0) throw new WebApplicationException(UNSUPPORTED_MEDIA_TYPE);
@@ -467,7 +494,9 @@ public class OntoNetRootResource extends
if (key != null && !key.isEmpty()) {
// FIXME ugly but will have to do for the time being
- String uri = key.split("::")[1];
+ String uri
+ // = key.split("::")[1];
+ = key.substring((ontologyProvider.getGraphPrefix() + "::").length());
if (uri != null && !uri.isEmpty()) rb = Response.seeOther(URI.create("/ontonet/" + uri));
else rb = Response.ok();
} else rb = Response.status(Status.INTERNAL_SERVER_ERROR);
@@ -549,4 +578,8 @@ public class OntoNetRootResource extends
(System.currentTimeMillis() - before), r.getStatus());
return r;
}
+
+ public String stringForm(OWLOntologyID ontologyID) {
+ return OntologyUtils.encode(ontologyID);
+ }
}
Modified: incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ScopeResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ScopeResource.java?rev=1367100&r1=1367099&r2=1367100&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ScopeResource.java (original)
+++ incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ScopeResource.java Mon Jul 30 14:12:24 2012
@@ -52,6 +52,7 @@ import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
@@ -81,6 +82,7 @@ import javax.ws.rs.core.UriInfo;
import org.apache.clerezza.rdf.core.Graph;
import org.apache.clerezza.rdf.core.TripleCollection;
import org.apache.clerezza.rdf.core.access.TcProvider;
+import org.apache.stanbol.commons.owl.util.URIUtils;
import org.apache.stanbol.commons.web.base.ContextHelper;
import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
@@ -92,6 +94,7 @@ import org.apache.stanbol.ontologymanage
import org.apache.stanbol.ontologymanager.ontonet.api.io.GraphContentInputSource;
import org.apache.stanbol.ontologymanager.ontonet.api.io.GraphSource;
import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.Origin;
import org.apache.stanbol.ontologymanager.ontonet.api.io.RootOntologyIRISource;
import org.apache.stanbol.ontologymanager.ontonet.api.io.RootOntologySource;
import org.apache.stanbol.ontologymanager.ontonet.api.io.SetInputSource;
@@ -107,6 +110,7 @@ import org.coode.owlapi.manchesterowlsyn
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
+import org.semanticweb.owlapi.model.OWLOntologyID;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -132,7 +136,7 @@ public class ScopeResource extends BaseS
*/
protected ONManager onm;
- protected OntologyProvider<TcProvider> provider;
+ protected OntologyProvider<TcProvider> ontologyProvider;
/*
* Placeholder for the RegistryManager to be fetched from the servlet context.
@@ -149,7 +153,7 @@ public class ScopeResource extends BaseS
this.onm = (ONManager) ContextHelper.getServiceFromContext(ONManager.class, servletContext);
this.regMgr = (RegistryManager) ContextHelper.getServiceFromContext(RegistryManager.class,
servletContext);
- this.provider = (OntologyProvider<TcProvider>) ContextHelper.getServiceFromContext(
+ this.ontologyProvider = (OntologyProvider<TcProvider>) ContextHelper.getServiceFromContext(
OntologyProvider.class, servletContext);
if (scopeId == null || scopeId.isEmpty()) {
@@ -220,8 +224,8 @@ public class ScopeResource extends BaseS
public SortedSet<String> getCoreOntologies() {
SortedSet<String> result = new TreeSet<String>();
- for (IRI iri : scope.getCoreSpace().listManagedOntologies())
- result.add(iri.toString());
+ for (OWLOntologyID id : scope.getCoreSpace().listManagedOntologies())
+ result.add(OntologyUtils.encode(id));
return result;
}
@@ -261,8 +265,8 @@ public class ScopeResource extends BaseS
public SortedSet<String> getCustomOntologies() {
SortedSet<String> result = new TreeSet<String>();
- for (IRI iri : scope.getCustomSpace().listManagedOntologies())
- result.add(iri.toString());
+ for (OWLOntologyID id : scope.getCustomSpace().listManagedOntologies())
+ result.add(OntologyUtils.encode(id));
return result;
}
@@ -311,6 +315,21 @@ public class ScopeResource extends BaseS
return regMgr.getLibraries();
}
+ public SortedSet<String> getManageableOntologies() {
+ SortedSet<String> result = new TreeSet<String>();
+ // for (String s : ontologyProvider.getPublicKeys()) {
+ // // String s1 = s.split("::")[1];
+ // if (s != null && !s.isEmpty()) result.add(s);
+ // }
+ for (OWLOntologyID id : ontologyProvider.listOntologies())
+ result.add(OntologyUtils.encode(id));
+ for (OWLOntologyID id : scope.getCoreSpace().listManagedOntologies())
+ result.remove(OntologyUtils.encode(id));
+ for (OWLOntologyID id : scope.getCustomSpace().listManagedOntologies())
+ result.remove(OntologyUtils.encode(id));
+ return result;
+ }
+
/*
* Needed for freemarker
*/
@@ -478,24 +497,23 @@ public class ScopeResource extends BaseS
@Context UriInfo uriInfo,
@Context HttpHeaders headers) {
ResponseBuilder rb;
- if (ontologyId != null && !ontologyId.equals("")) {
- IRI ontIri = IRI.create(ontologyId);
+ if (ontologyId != null && !ontologyId.trim().isEmpty()) {
+ OWLOntologyID id = OntologyUtils.decode(ontologyId);
OntologySpace cs = scope.getCustomSpace();
- if (cs.hasOntology(ontIri)) {
- try {
- onm.setScopeActive(scopeId, false);
- cs.removeOntology(ontIri);
- rb = Response.ok();
- } catch (IrremovableOntologyException e) {
- throw new WebApplicationException(e, FORBIDDEN);
- } catch (UnmodifiableOntologyCollectorException e) {
- throw new WebApplicationException(e, FORBIDDEN);
- } catch (OntologyCollectorModificationException e) {
- throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
- } finally {
- onm.setScopeActive(scopeId, true);
- }
- } else rb = Response.notModified(); // ontology not managed
+ if (!cs.hasOntology(id)) rb = Response.notModified(); // ontology not managed
+ else try {
+ onm.setScopeActive(scopeId, false);
+ cs.removeOntology(id);
+ rb = Response.ok();
+ } catch (IrremovableOntologyException e) {
+ throw new WebApplicationException(e, FORBIDDEN);
+ } catch (UnmodifiableOntologyCollectorException e) {
+ throw new WebApplicationException(e, FORBIDDEN);
+ } catch (OntologyCollectorModificationException e) {
+ throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
+ } finally {
+ onm.setScopeActive(scopeId, true);
+ }
} else rb = Response.status(BAD_REQUEST); // null/blank ontology ID
addCORSOrigin(servletContext, rb, headers);
return rb.build();
@@ -530,14 +548,15 @@ public class ScopeResource extends BaseS
*
* TODO : we might find a reason to change that in the future.
*/
- new GraphContentInputSource(content, mt.toString(), provider.getStore()));
+ new GraphContentInputSource(content, mt.toString(), ontologyProvider.getStore()));
if (key == null || key.isEmpty()) {
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 parse with media type {}.", mt);
- String uri = key.split("::")[1];
+ String uri = // key.split("::")[1];
+ key.substring((ontologyProvider.getGraphPrefix() + "::").length());
URI created = null;
if (uri != null && !uri.isEmpty()) {
created = getCreatedResource(uri);
@@ -589,29 +608,40 @@ public class ScopeResource extends BaseS
log.debug(" post(FormDataMultiPart data)");
ResponseBuilder rb;
+ // TODO remove and make sure it is set across the method
+ rb = Response.status(BAD_REQUEST);
+
IRI location = null, library = null;
File file = null; // If found, it takes precedence over location.
String format = null;
+ Set<String> keys = new HashSet<String>();
for (BodyPart bpart : data.getBodyParts()) {
log.debug("is a {}", bpart.getClass());
if (bpart instanceof FormDataBodyPart) {
FormDataBodyPart dbp = (FormDataBodyPart) bpart;
String name = dbp.getName();
if (name.equals("file")) file = bpart.getEntityAs(File.class);
- else if (name.equals("format") && !dbp.getValue().equals("auto")) format = dbp.getValue();
- else if (name.equals("url")) try {
- URI.create(dbp.getValue()); // To throw 400 if malformed.
- location = IRI.create(dbp.getValue());
- } catch (Exception ex) {
- log.error("Malformed IRI for " + dbp.getValue(), ex);
- throw new WebApplicationException(ex, BAD_REQUEST);
- }
- else if (name.equals("library") && !"null".equals(dbp.getValue())) try {
- URI.create(dbp.getValue()); // To throw 400 if malformed.
- library = IRI.create(dbp.getValue());
- } catch (Exception ex) {
- log.error("Malformed IRI for " + dbp.getValue(), ex);
- throw new WebApplicationException(ex, BAD_REQUEST);
+ else {
+ String value = dbp.getValue();
+ if (name.equals("format") && !value.equals("auto")) format = value;
+ else if (name.equals("url")) try {
+ URI.create(value); // To throw 400 if malformed.
+ location = IRI.create(value);
+ } catch (Exception ex) {
+ log.error("Malformed IRI for " + value, ex);
+ throw new WebApplicationException(ex, BAD_REQUEST);
+ }
+ else if (name.equals("library") && !"null".equals(value)) try {
+ URI.create(value); // To throw 400 if malformed.
+ library = IRI.create(value);
+ } catch (Exception ex) {
+ log.error("Malformed IRI for " + value, ex);
+ throw new WebApplicationException(ex, BAD_REQUEST);
+ }
+ else if (name.equals("stored") && !"null".equals(value)) {
+ log.info("Request to manage ontology with key {}", value);
+ keys.add(value);
+ }
}
}
@@ -629,7 +659,8 @@ public class ScopeResource extends BaseS
try {
// Use a buffered stream that can be reset for multiple attempts.
InputStream content = new BufferedInputStream(new FileInputStream(file));
- src = new GraphContentInputSource(content, format, provider.getStore());
+ src = new GraphContentInputSource(content, format, ontologyProvider.getStore());
+ break;
} catch (OntologyLoadingException e) {
// throw new WebApplicationException(e, BAD_REQUEST);
continue;
@@ -661,7 +692,8 @@ public class ScopeResource extends BaseS
String key = scope.getCustomSpace().addOntology(src);
if (key == null || key.isEmpty()) throw new WebApplicationException(INTERNAL_SERVER_ERROR);
// FIXME ugly but will have to do for the time being
- String uri = key.split("::")[1];
+ String uri = // key.split("::")[1];
+ key.substring((ontologyProvider.getGraphPrefix() + "::").length());
if (uri != null && !uri.isEmpty()) {
rb = Response.seeOther(URI.create("/ontonet/ontology/" + scope.getID() + "/" + uri)/*
* getCreatedResource
@@ -670,9 +702,15 @@ public class ScopeResource extends BaseS
*/);
} else rb = Response.ok();
} else rb = Response.status(INTERNAL_SERVER_ERROR);
- } else throw new WebApplicationException(BAD_REQUEST);
+ }
+ if (!keys.isEmpty()) {
+ for (String key : keys)
+ scope.getCustomSpace().addOntology(Origin.create(OntologyUtils.decode(key)));
+ rb = Response.seeOther(URI.create("/ontonet/ontology/" + scope.getID()));
+ }
+ // else throw new WebApplicationException(BAD_REQUEST);
// rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
- // FIXME return an appropriate response e.g. 303
+ // FIXME return an appropriate response e.g. 201
addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
@@ -709,7 +747,7 @@ public class ScopeResource extends BaseS
if (coreRegistries != null) for (String reg : coreRegistries)
if (reg != null && !reg.isEmpty()) try {
// Library IDs are sanitized differently
- srcs.add(new LibrarySource(IRI.create(reg.replace("%23", "#")), regMgr));
+ 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.
Modified: incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionManagerResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionManagerResource.java?rev=1367100&r1=1367099&r2=1367100&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionManagerResource.java (original)
+++ incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionManagerResource.java Mon Jul 30 14:12:24 2012
@@ -129,7 +129,7 @@ public class SessionManagerResource exte
o = ontMgr.createOntology(IRI.create(uriInfo.getRequestUri()));
List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
for (String id : sessionManager.getRegisteredSessionIDs()) {
- IRI sessionid = IRI.create(sessionManager.getNamespace() + sessionManager.getID() + "/" + id);
+ IRI sessionid = IRI.create(sessionManager.getDefaultNamespace() + sessionManager.getID() + "/" + id);
OWLNamedIndividual ind = df.getOWLNamedIndividual(sessionid);
changes.add(new AddAxiom(o, df.getOWLClassAssertionAxiom(cSession, ind)));
}
Modified: incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionResource.java?rev=1367100&r1=1367099&r2=1367100&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionResource.java (original)
+++ incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionResource.java Mon Jul 30 14:12:24 2012
@@ -90,6 +90,7 @@ import org.apache.stanbol.ontologymanage
import org.apache.stanbol.ontologymanager.ontonet.api.io.GraphContentInputSource;
import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyContentInputSource;
import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.Origin;
import org.apache.stanbol.ontologymanager.ontonet.api.io.RootOntologyIRISource;
import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyProvider;
import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologyScope;
@@ -98,11 +99,14 @@ import org.apache.stanbol.ontologymanage
import org.apache.stanbol.ontologymanager.ontonet.api.session.SessionLimitException;
import org.apache.stanbol.ontologymanager.ontonet.api.session.SessionManager;
import org.apache.stanbol.ontologymanager.ontonet.impl.util.OntologyUtils;
+import org.apache.stanbol.ontologymanager.registry.api.RegistryManager;
+import org.apache.stanbol.ontologymanager.registry.io.LibrarySource;
import org.apache.stanbol.ontologymanager.web.util.OntologyPrettyPrintResource;
import org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxOntologyFormat;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
+import org.semanticweb.owlapi.model.OWLOntologyID;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -125,20 +129,27 @@ public class SessionResource extends Bas
protected ONManager onMgr;
- protected OntologyProvider<TcProvider> provider;
+ protected OntologyProvider<TcProvider> ontologyProvider;
/*
* Placeholder for the session manager to be fetched from the servlet context.
*/
protected SessionManager sesMgr;
+ /*
+ * Placeholder for the RegistryManager to be fetched from the servlet context.
+ */
+ protected RegistryManager regMgr;
+
protected Session session;
public SessionResource(@PathParam(value = "id") String sessionId, @Context ServletContext servletContext) {
this.servletContext = servletContext;
this.sesMgr = (SessionManager) ContextHelper.getServiceFromContext(SessionManager.class,
servletContext);
- this.provider = (OntologyProvider<TcProvider>) ContextHelper.getServiceFromContext(
+ this.regMgr = (RegistryManager) ContextHelper.getServiceFromContext(RegistryManager.class,
+ servletContext);
+ this.ontologyProvider = (OntologyProvider<TcProvider>) ContextHelper.getServiceFromContext(
OntologyProvider.class, servletContext);
this.onMgr = (ONManager) ContextHelper.getServiceFromContext(ONManager.class, servletContext);
session = sesMgr.getSession(sessionId);
@@ -233,6 +244,22 @@ public class SessionResource extends Bas
return rb.build();
}
+ @POST
+ @Produces({WILDCARD})
+ public Response emptyPost(@Context HttpHeaders headers) {
+ log.debug(" post(no data)");
+ for (OntologyScope sc : getAllScopes()) { // First remove appended scopes not in the list
+ String scid = sc.getID();
+ if (getAppendedScopes().contains(scid)) {
+ session.detachScope(scid);
+ log.info("Removed scope \"{]\".", scid);
+ }
+ }
+ ResponseBuilder rb = Response.ok();
+ addCORSOrigin(servletContext, rb, headers);
+ return rb.build();
+ }
+
/*
* Needed for freemarker
*/
@@ -275,10 +302,19 @@ public class SessionResource extends Bas
return rb.build();
}
+ public SortedSet<String> getManageableOntologies() {
+ SortedSet<String> result = new TreeSet<String>();
+ for (OWLOntologyID id : ontologyProvider.listOntologies())
+ result.add(OntologyUtils.encode(id));
+ for (OWLOntologyID id : session.listManagedOntologies())
+ result.remove(OntologyUtils.encode(id));
+ return result;
+ }
+
public SortedSet<String> getOntologies() {
SortedSet<String> result = new TreeSet<String>();
- for (IRI iri : session.listManagedOntologies())
- result.add(iri.toString());
+ for (OWLOntologyID id : session.listManagedOntologies())
+ result.add(OntologyUtils.encode(id));
return result;
}
@@ -446,11 +482,10 @@ public class SessionResource extends Bas
ResponseBuilder rb;
if (session == null) rb = Response.status(NOT_FOUND);
else {
- IRI iri = IRI.create(ontologyId);
- OWLOntology o = session.getOntology(iri, OWLOntology.class);
- if (o == null) rb = Response.notModified();
+ OWLOntologyID id = OntologyUtils.decode(ontologyId);
+ if (!session.hasOntology(id)) rb = Response.notModified();
else try {
- session.removeOntology(iri);
+ session.removeOntology(id);
rb = Response.ok();
} catch (IrremovableOntologyException e) {
throw new WebApplicationException(e, FORBIDDEN);
@@ -490,7 +525,7 @@ public class SessionResource extends Bas
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, provider.getStore());
+ src = new GraphContentInputSource(content, mt, ontologyProvider.getStore());
log.debug("SUCCESS parse with media type {}.", mt);
String key = session.addOntology(src);
if (key == null || key.isEmpty()) {
@@ -500,7 +535,8 @@ public class SessionResource extends Bas
// 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);
- String uri = key.split("::")[1];
+ String uri = // key.split("::")[1];
+ key.substring((ontologyProvider.getGraphPrefix() + "::").length());
URI created = null;
if (uri != null && !uri.isEmpty()) {
created = getCreatedResource(uri);
@@ -548,22 +584,6 @@ public class SessionResource extends Bas
}
@POST
- @Produces({WILDCARD})
- public Response emptyPost(@Context HttpHeaders headers) {
- log.debug(" post(no data)");
- for (OntologyScope sc : getAllScopes()) { // First remove appended scopes not in the list
- String scid = sc.getID();
- if (getAppendedScopes().contains(scid)) {
- session.detachScope(scid);
- log.info("Removed scope \"{]\".", scid);
- }
- }
- ResponseBuilder rb = Response.ok();
- addCORSOrigin(servletContext, rb, headers);
- return rb.build();
- }
-
- @POST
@Consumes({MULTIPART_FORM_DATA})
@Produces({WILDCARD})
public Response postOntology(FormDataMultiPart data, @Context HttpHeaders headers) {
@@ -571,10 +591,14 @@ public class SessionResource extends Bas
long before = System.currentTimeMillis();
ResponseBuilder rb;
- IRI location = null;
+ // TODO remove and make sure it is set across the method
+ rb = Response.status(BAD_REQUEST);
+
+ IRI location = null, library = null;
File file = null; // If found, it takes precedence over location.
String format = null;
- Set<String> toAppend = new HashSet<String>();
+ Set<String> toAppend = null;
+ Set<String> keys = new HashSet<String>();
for (BodyPart bpart : data.getBodyParts()) {
log.debug("Found body part of type {}", bpart.getClass());
@@ -583,29 +607,42 @@ public class SessionResource extends Bas
String name = dbp.getName();
if (name.equals("file")) {
file = bpart.getEntityAs(File.class);
- } else if (name.equals("format") && !dbp.getValue().equals("auto")) format = dbp.getValue();
- else if (name.equals("url")) try {
- URI.create(dbp.getValue()); // To throw 400 if malformed.
- location = IRI.create(dbp.getValue());
- } catch (Exception ex) {
- log.error("Malformed IRI for " + dbp.getValue(), ex);
- throw new WebApplicationException(ex, BAD_REQUEST);
- }
- if (name.equals("scope")) {
- log.info("Request to append scope \"{}\".", dbp.getValue());
- toAppend.add(dbp.getValue());
+ } else {
+ String value = dbp.getValue();
+ if (name.equals("format") && !value.equals("auto")) format = value;
+ else if (name.equals("url")) try {
+ URI.create(value); // To throw 400 if malformed.
+ location = IRI.create(value);
+ } catch (Exception ex) {
+ log.error("Malformed IRI for " + value, ex);
+ throw new WebApplicationException(ex, BAD_REQUEST);
+ }
+ else if (name.equals("library") && !"null".equals(value)) try {
+ URI.create(value); // To throw 400 if malformed.
+ library = IRI.create(value);
+ } catch (Exception ex) {
+ log.error("Malformed IRI for " + value, ex);
+ throw new WebApplicationException(ex, BAD_REQUEST);
+ }
+ else if (name.equals("stored") && !"null".equals(value)) {
+ log.info("Request to manage ontology with key {}", value);
+ keys.add(value);
+ } else if (name.equals("scope")) {
+ log.info("Request to append scope \"{}\".", value);
+ if (toAppend == null) toAppend = new HashSet<String>();
+ toAppend.add(value);
+ }
}
}
}
boolean fileOk = file != null && file.canRead() && file.exists();
- if (fileOk || location != null) { // File and location take precedence
+ if (fileOk || location != null || library != null) { // File and location take precedence
// Then add the file
OntologyInputSource<?> src = null;
if (fileOk) { // File first
Collection<String> formats;
if (format == null || "".equals(format.trim())) formats = OntologyUtils.getPreferredFormats();
else formats = Collections.singleton(format);
-
for (String f : formats)
try {
log.debug("Trying format {}.", f);
@@ -615,9 +652,10 @@ public class SessionResource extends Bas
log.debug("Streams created in {} ms", System.currentTimeMillis() - b4buf);
log.debug("Creating ontology input source...");
b4buf = System.currentTimeMillis();
- src = new GraphContentInputSource(content, f, provider.getStore());
+ src = new GraphContentInputSource(content, f, ontologyProvider.getStore());
log.debug("Done in {} ms", System.currentTimeMillis() - b4buf);
log.info("SUCCESS parse with format {}.", f);
+ break;
} catch (OntologyLoadingException e) {
log.debug("FAILURE parse with format {}.", f);
continue;
@@ -633,6 +671,13 @@ public class SessionResource extends Bas
log.error("Failed to load ontology from " + location, e);
throw new WebApplicationException(e, BAD_REQUEST);
}
+ } else if (library != null) { // This comes last, since it will most likely have a value.
+ try {
+ src = new LibrarySource(library, regMgr);
+ } catch (Exception e) {
+ log.error("Failed to load ontology library " + library, e);
+ throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
+ }
} else {
log.error("Bad request");
log.error(" file is: {}", file);
@@ -647,14 +692,21 @@ public class SessionResource extends Bas
// FIXME ugly but will have to do for the time being
log.debug("Addition done in {} ms.", System.currentTimeMillis() - b4add);
log.debug("Storage key : {}", key);
- String uri = key.split("::")[1];
+ String uri = // key.split("::")[1];
+ key.substring((ontologyProvider.getGraphPrefix() + "::").length());
if (uri != null && !uri.isEmpty()) rb = Response.seeOther(URI.create("/ontonet/session/"
+ session.getID() + "/"
+ uri));
else rb = Response.seeOther(URI.create("/ontonet/session/" + session.getID()));
} else rb = Response.status(INTERNAL_SERVER_ERROR);
- } else // Now check scopes
- if (!toAppend.isEmpty() || (toAppend.isEmpty() && !getAppendedScopes().isEmpty())) {
+ }
+ if (!keys.isEmpty()) {
+ for (String key : keys)
+ session.addOntology(Origin.create(OntologyUtils.decode(key)));
+ rb = Response.seeOther(URI.create("/ontonet/session/" + session.getID()));
+ } // Now check scopes
+ if (toAppend != null
+ && (!toAppend.isEmpty() || (toAppend.isEmpty() && !getAppendedScopes().isEmpty()))) {
for (OntologyScope sc : getAllScopes()) { // First remove appended scopes not in the list
String scid = sc.getID();
if (!toAppend.contains(scid) && getAppendedScopes().contains(scid)) {
@@ -670,10 +722,11 @@ public class SessionResource extends Bas
}
}
rb = Response.seeOther(URI.create("/ontonet/session/" + session.getID()));
- } else {
- log.error("Nothing to do with session {}.", session.getID());
- throw new WebApplicationException(BAD_REQUEST);
}
+ // else {
+ // log.error("Nothing to do with session {}.", session.getID());
+ // throw new WebApplicationException(BAD_REQUEST);
+ // }
// rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
addCORSOrigin(servletContext, rb, headers);
log.info("POST ontology completed in {} ms.", System.currentTimeMillis() - before);
Modified: incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/util/OntologyPrettyPrintResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/util/OntologyPrettyPrintResource.java?rev=1367100&r1=1367099&r2=1367100&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/util/OntologyPrettyPrintResource.java (original)
+++ incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/util/OntologyPrettyPrintResource.java Mon Jul 30 14:12:24 2012
@@ -20,7 +20,7 @@ import javax.servlet.ServletContext;
import javax.ws.rs.core.UriInfo;
import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
-import org.apache.stanbol.ontologymanager.ontonet.api.NamedResource;
+import org.apache.stanbol.ontologymanager.ontonet.api.NamedArtifact;
/**
* This is a dummy resource to be used for human-readable HTML output.
@@ -30,7 +30,7 @@ import org.apache.stanbol.ontologymanage
*/
public class OntologyPrettyPrintResource extends BaseStanbolResource {
- private NamedResource owner = null;
+ private NamedArtifact owner = null;
private Object result;
@@ -43,12 +43,12 @@ public class OntologyPrettyPrintResource
public OntologyPrettyPrintResource(ServletContext context,
UriInfo uriInfo,
Object result,
- NamedResource owner) {
+ NamedArtifact owner) {
this(context, uriInfo, result);
this.owner = owner;
}
- public NamedResource getOwner() {
+ public NamedArtifact getOwner() {
return this.owner;
}
Added: incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/static/images/unload_icon_16.png
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/static/images/unload_icon_16.png?rev=1367100&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/static/images/unload_icon_16.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/OntoNetRootResource/webview.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/OntoNetRootResource/webview.ftl?rev=1367100&r1=1367099&r2=1367100&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/OntoNetRootResource/webview.ftl (original)
+++ incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/OntoNetRootResource/webview.ftl Mon Jul 30 14:12:24 2012
@@ -62,7 +62,7 @@
</div>
<script>
- $(".enginelisting p").click(function () {
+ $(".collapseheader").click(function () {
$(this).parents("div").toggleClass("collapsed");
});
</script>
@@ -73,12 +73,14 @@
<table id="allOntologies">
<div>
<tr>
- <th>ID</th>
- <th>Direct handles</th>
+ <th width="90%">ID</th>
+ <th width="5%">Triples</th>
+ <th width="5%">Direct handles</th>
</tr>
- <#list it.ontologies as ontology>
+ <#list ontologies as ontology>
<tr>
- <td><a href="${it.publicBaseUri}ontonet/${ontology}">${ontology}</a></td>
+ <td><a href="${it.publicBaseUri}ontonet/${it.stringForm(ontology)}">${it.stringForm(ontology)}</a></td>
+ <td>${it.getSize(ontology)}</td>
<td>${it.getHandles(ontology)?size}</td>
</tr>
</#list>
Modified: incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/ScopeResource/index.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/ScopeResource/index.ftl?rev=1367100&r1=1367099&r2=1367100&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/ScopeResource/index.ftl (original)
+++ incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/ScopeResource/index.ftl Mon Jul 30 14:12:24 2012
@@ -30,6 +30,21 @@
<p class="collapseheader"><b>Load an ontology</b></p>
<div class="collapsable">
<br/>
+
+ <form method="POST" enctype="multipart/form-data" accept-charset="utf-8">
+ <fieldset>
+ <legend>Manage stored ontology</legend>
+ <p><b>Ontology ID:</b>
+ <select name="stored">
+ <option value="null"><please select an ontology></option>
+ <#list it.manageableOntologies as manageable>
+ <option value="${manageable}">${manageable}</option>
+ </#list>
+ </select>
+ <input type="submit" value="Manage"/>
+ </p>
+ </fieldset>
+ </form>
<form method="POST" enctype="multipart/form-data" accept-charset="utf-8">
<fieldset>
@@ -91,17 +106,19 @@
});
</script>
- <h3>Stored ontologies</h3>
+ <h3>Managed ontologies</h3>
<h4>Custom</h4>
<#assign ontologies = it.customOntologies>
- <div class="storeContents">
+ <div class="storeContents" id="managed_custom">
<table id="customOnt">
<div>
<tr>
+ <th></th>
<th>Name</th>
</tr>
<#list ontologies as ontology>
<tr>
+ <td><img src="${it.staticRootUrl}/ontonet/images/unload_icon_16.png" title="Unmanage this ontology" onClick="javascript:unload('${ontology}')"/></td>
<td><a href="${it.publicBaseUri}ontonet/ontology/${it.scope.ID}/${ontology}">${ontology}</a></td>
</tr>
</#list>
@@ -110,14 +127,16 @@
</div>
<h4>Core</h4>
<#assign ontologies2 = it.coreOntologies>
- <div class="storeContents">
+ <div class="storeContents" id="managed_core">
<table id="coreOnt">
<div>
<tr>
+ <th></th>
<th>Name</th>
</tr>
<#list ontologies2 as ontology2>
<tr>
+ <td><img src="${it.staticRootUrl}/ontonet/images/unload_icon_16.png" title="Unmanage this ontology" onClick="javascript:unload('${ontology2}')"/></td>
<td><a href="/ontonet/ontology/${it.scope.ID}/${ontology2}">${ontology2}</a></td>
</tr>
</#list>
@@ -127,5 +146,26 @@
</div> <!-- web view -->
+ <script language="JavaScript">
+
+ function unload(ontologyid) {
+ var lurl = "${it.publicBaseUri}ontonet/ontology/${it.scope.ID}" + "/" + ontologyid;
+ $.ajax({
+ url: lurl,
+ type: "DELETE",
+ async: true,
+ cache: false,
+ success: function(data, textStatus, xhr) {
+ $("#managed_custom").load("${it.publicBaseUri}ontonet/ontology/${it.scope.ID} #managed_custom>table");
+ $("#managed_core").load("${it.publicBaseUri}ontonet/ontology/${it.scope.ID} #managed_core>table");
+ },
+ error: function() {
+ alert(result.status + ' ' + result.statusText);
+ }
+ });
+ }
+
+ </script>
+
</...@common.page>
</#escape>
\ No newline at end of file