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/19 19:10:07 UTC

svn commit: r1363428 [4/4] - in /incubator/stanbol/trunk: commons/owl/src/main/java/org/apache/stanbol/commons/owl/util/ commons/owl/src/test/java/org/apache/stanbol/commons/owl/util/ enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/...

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=1363428&r1=1363427&r2=1363428&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 Thu Jul 19 17:10:05 2012
@@ -76,6 +76,7 @@ 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.access.TcProvider;
 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;
@@ -84,8 +85,10 @@ import org.apache.stanbol.ontologymanage
 import org.apache.stanbol.ontologymanager.ontonet.api.collector.OntologyCollectorModificationException;
 import org.apache.stanbol.ontologymanager.ontonet.api.collector.UnmodifiableOntologyCollectorException;
 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.RootOntologyIRISource;
+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.DuplicateSessionIDException;
 import org.apache.stanbol.ontologymanager.ontonet.api.session.Session;
@@ -118,6 +121,8 @@ public class SessionResource extends Bas
 
     protected ONManager onMgr;
 
+    protected OntologyProvider<TcProvider> provider;
+
     /*
      * Placeholder for the session manager to be fetched from the servlet context.
      */
@@ -129,6 +134,8 @@ public class SessionResource extends Bas
         this.servletContext = servletContext;
         this.sesMgr = (SessionManager) ContextHelper.getServiceFromContext(SessionManager.class,
             servletContext);
+        this.provider = (OntologyProvider<TcProvider>) ContextHelper.getServiceFromContext(
+            OntologyProvider.class, servletContext);
         this.onMgr = (ONManager) ContextHelper.getServiceFromContext(ONManager.class, servletContext);
         session = sesMgr.getSession(sessionId);
     }
@@ -139,8 +146,9 @@ public class SessionResource extends Bas
                                     @DefaultValue("false") @QueryParam("merge") boolean merge,
                                     @Context HttpHeaders headers) {
         if (session == null) return Response.status(NOT_FOUND).build();
+        IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/");
         // Export to Clerezza Graph, which can be rendered as JSON-LD.
-        ResponseBuilder rb = Response.ok(session.export(Graph.class, merge));
+        ResponseBuilder rb = Response.ok(session.export(Graph.class, merge, prefix));
         addCORSOrigin(servletContext, rb, headers);
         return rb.build();
     }
@@ -152,9 +160,10 @@ public class SessionResource extends Bas
                                     @Context HttpHeaders headers) {
         if (session == null) return Response.status(NOT_FOUND).build();
         ResponseBuilder rb;
+        IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/");
         // Export smaller graphs to OWLOntology due to the more human-readable rendering.
-        if (merge) rb = Response.ok(session.export(Graph.class, merge));
-        else rb = Response.ok(session.export(OWLOntology.class, merge));
+        if (merge) rb = Response.ok(session.export(Graph.class, merge, prefix));
+        else rb = Response.ok(session.export(OWLOntology.class, merge, prefix));
         addCORSOrigin(servletContext, rb, headers);
         return rb.build();
     }
@@ -165,8 +174,9 @@ public class SessionResource extends Bas
                                   @DefaultValue("false") @QueryParam("merge") boolean merge,
                                   @Context HttpHeaders headers) {
         if (session == null) return Response.status(NOT_FOUND).build();
+        IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/");
         // Export to OWLOntology, the only to support OWL formats.
-        ResponseBuilder rb = Response.ok(session.export(OWLOntology.class, merge));
+        ResponseBuilder rb = Response.ok(session.export(OWLOntology.class, merge, prefix));
         addCORSOrigin(servletContext, rb, headers);
         return rb.build();
     }
@@ -239,6 +249,10 @@ public class SessionResource extends Bas
         return appended;
     }
 
+    private URI getCreatedResource(String ontologyIRI) {
+        return URI.create("/" + ontologyIRI);
+    }
+
     @GET
     @Produces(TEXT_HTML)
     public Response getHtmlInfo(@Context HttpHeaders headers) {
@@ -300,7 +314,8 @@ public class SessionResource extends Bas
                                             @Context UriInfo uriInfo,
                                             @Context HttpHeaders headers) {
         if (session == null) return Response.status(NOT_FOUND).build();
-        Graph o = session.getOntology(IRI.create(ontologyId), Graph.class, merge);
+        IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/");
+        Graph o = session.getOntology(IRI.create(ontologyId), Graph.class, merge, prefix);
         ResponseBuilder rb = (o != null) ? Response.ok(o) : Response.status(NOT_FOUND);
         addCORSOrigin(servletContext, rb, headers);
         return rb.build();
@@ -328,12 +343,15 @@ public class SessionResource extends Bas
                                             @Context HttpHeaders headers) {
         ResponseBuilder rb;
         if (session == null) rb = Response.status(NOT_FOUND);
-        else if (merge) {
-            Graph g = session.getOntology(IRI.create(ontologyId), Graph.class, merge);
-            rb = (g != null) ? Response.ok(g) : Response.status(NOT_FOUND);
-        } else {
-            OWLOntology o = session.getOntology(IRI.create(ontologyId), OWLOntology.class, merge);
-            rb = (o != null) ? Response.ok(o) : Response.status(NOT_FOUND);
+        else {
+            IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/");
+            if (merge) {
+                Graph g = session.getOntology(IRI.create(ontologyId), Graph.class, merge, prefix);
+                rb = (g != null) ? Response.ok(g) : Response.status(NOT_FOUND);
+            } else {
+                OWLOntology o = session.getOntology(IRI.create(ontologyId), OWLOntology.class, merge, prefix);
+                rb = (o != null) ? Response.ok(o) : Response.status(NOT_FOUND);
+            }
         }
         addCORSOrigin(servletContext, rb, headers);
         return rb.build();
@@ -360,7 +378,8 @@ public class SessionResource extends Bas
                                           @Context UriInfo uriInfo,
                                           @Context HttpHeaders headers) {
         if (session == null) return Response.status(NOT_FOUND).build();
-        OWLOntology o = session.getOntology(IRI.create(ontologyId), OWLOntology.class, merge);
+        IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/");
+        OWLOntology o = session.getOntology(IRI.create(ontologyId), OWLOntology.class, merge, prefix);
         ResponseBuilder rb = (o != null) ? Response.ok(o) : Response.status(NOT_FOUND);
         addCORSOrigin(servletContext, rb, headers);
         return rb.build();
@@ -375,7 +394,8 @@ public class SessionResource extends Bas
         if (session == null) rb = Response.status(NOT_FOUND);
         else if (ontologyId == null || ontologyId.isEmpty()) rb = Response.status(BAD_REQUEST);
         else {
-            OWLOntology o = session.getOntology(IRI.create(ontologyId), OWLOntology.class, false);
+            IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/");
+            OWLOntology o = session.getOntology(IRI.create(ontologyId), OWLOntology.class, false, prefix);
             if (o == null) rb = Response.status(NOT_FOUND);
             else try {
                 ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -450,17 +470,40 @@ public class SessionResource extends Bas
                        RDF_JSON})
     public Response manageOntology(InputStream content, @Context HttpHeaders headers) {
         long before = System.currentTimeMillis();
-        if (session == null) return Response.status(NOT_FOUND).build();
-        try {
-            session.addOntology(new GraphContentInputSource(content)
-            // new OntologyContentInputSource(content)
-            );
+        ResponseBuilder rb;
+        String mt = headers.getMediaType().toString();
+        if (session == null) rb = Response.status(NOT_FOUND); // Always check session first
+        else try {
+            log.debug("POST content claimed to be of type {}.", mt);
+            OntologyInputSource<?> src;
+            if (OWL_XML.equals(mt) || FUNCTIONAL_OWL.equals(mt) || MANCHESTER_OWL.equals(mt)) src = new OntologyContentInputSource(
+                    content);
+            else // content = new BufferedInputStream(content);
+            src = new GraphContentInputSource(content, mt, provider.getStore());
+            log.debug("SUCCESS parse with media type {}.", mt);
+            String key = session.addOntology(src);
+            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 add ontology to session {}.", session.getID());
+            log.debug("Storage key : {}", key);
+            String uri = key.split("::")[1];
+            URI created = null;
+            if (uri != null && !uri.isEmpty()) {
+                created = getCreatedResource(uri);
+                rb = Response.created(created);
+            } else rb = Response.ok();
+            log.info("POST request for ontology addition completed in {} ms.",
+                (System.currentTimeMillis() - before));
+            log.info("New resource URL is {}", created);
         } catch (UnmodifiableOntologyCollectorException e) {
             throw new WebApplicationException(e, FORBIDDEN);
+        } catch (OWLOntologyCreationException e) {
+            log.error("FAILED parse with media type {}.", mt);
+            throw new WebApplicationException(e, BAD_REQUEST);
         }
-        log.debug("POST request for ontology addition completed in {} ms.",
-            (System.currentTimeMillis() - before));
-        ResponseBuilder rb = Response.ok();
         addCORSOrigin(servletContext, rb, headers);
         return rb.build();
     }
@@ -499,6 +542,7 @@ public class SessionResource extends Bas
     @Produces({TEXT_HTML, TEXT_PLAIN, RDF_XML, TURTLE, X_TURTLE, N3})
     public Response postOntology(FormDataMultiPart data, @Context HttpHeaders headers) {
         log.debug(" post(FormDataMultiPart data)");
+        long before = System.currentTimeMillis();
         ResponseBuilder rb;
 
         IRI location = null;
@@ -507,7 +551,7 @@ public class SessionResource extends Bas
         OntologyScope scope = null;
 
         for (BodyPart bpart : data.getBodyParts()) {
-            log.debug("is a {}", bpart.getClass());
+            log.debug("Found body part of type {}", bpart.getClass());
             if (bpart instanceof FormDataBodyPart) {
                 FormDataBodyPart dbp = (FormDataBodyPart) bpart;
                 String name = dbp.getName();
@@ -529,15 +573,24 @@ public class SessionResource extends Bas
         boolean fileOk = file != null && file.canRead() && file.exists();
         if (fileOk || location != null) { // File and location take precedence
             // Then add the file
-            OntologyInputSource<?,?> src = null;
+            OntologyInputSource<?> src = null;
             if (fileOk) { // File first
                 try {
                     // Use a buffered stream that can be reset for multiple attempts.
+                    long b4buf = System.currentTimeMillis();
                     InputStream content = new BufferedInputStream(new FileInputStream(file));
-                    src = new GraphContentInputSource(content, format);
+                    // new FileInputStream(file);
+                    log.debug("Streams created in {} ms", System.currentTimeMillis() - b4buf);
+                    log.debug("Creating ontology input source...");
+                    b4buf = System.currentTimeMillis();
+                    src = new GraphContentInputSource(content, format, provider.getStore());
+                    log.debug("Done in {} ms", System.currentTimeMillis() - b4buf);
+                    log.debug("SUCCESS parse with format {}.", format);
                 } catch (OntologyLoadingException e) {
+                    log.error("FAILURE parse with format {}.", format);
                     throw new WebApplicationException(e, BAD_REQUEST);
                 } catch (IOException e) {
+                    log.error("FAILURE parse with format {}.", format);
                     throw new WebApplicationException(e, BAD_REQUEST);
                 }
             } else if (location != null) {
@@ -554,22 +607,28 @@ public class SessionResource extends Bas
             }
 
             if (src != null) {
+                log.debug("Adding ontology from input source {}", src);
+                long b4add = System.currentTimeMillis();
                 String key = session.addOntology(src);
                 if (key == null || key.isEmpty()) throw new WebApplicationException(INTERNAL_SERVER_ERROR);
                 // 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];
-                if (uri != null && !uri.isEmpty()) {
-                    rb = Response.seeOther(URI.create("/ontonet/session/" + session.getID() + "/" + uri));
-                } else rb = Response.ok();
+                if (uri != null && !uri.isEmpty()) rb = Response.created(URI.create("/" + uri));
+                else rb = Response.ok();
             } else rb = Response.status(INTERNAL_SERVER_ERROR);
         } else if (scope != null) { // Scope comes next
-            session.attachScope(scope);
+            log.info("Attaching scope \"{}\" to session \"{}\".", scope.getID(), session.getID());
+            session.attachScope(scope.getID());
             rb = Response.seeOther(URI.create("/ontonet/session/" + session.getID()));
         } else {
+            log.error("Nothing to add to 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);
         return rb.build();
     }
 }

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=1363428&r1=1363427&r2=1363428&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 Thu Jul 19 17:10:05 2012
@@ -15,7 +15,13 @@
   limitations under the License.
 -->
 
-  <h3>Load an ontology</h3>
+  <!-- FIXME class names should be generic, and not bound to a specific functionality (here engines->reasoning services)-->
+  <div class="enginelisting">
+    <div class="collapsed">
+      <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>From a local file</legend>
@@ -26,7 +32,7 @@
           <option value="application/rdf+xml">RDF/XML</option>
           <option value="application/rdf+json">RDF/JSON</option>
           <option value="text/turtle">Turtle</option>
-          <option value="text/rdf+nt">N-TRIPLE</option>
+          <option value="text/rdf+nt">N-Triple</option>
           <option value="text/rdf+n3">N3</option>
           <!--
           <option value="application/owl+xml">OWL/XML</option>
@@ -51,17 +57,29 @@
   
   Note: OWL import targets will be included. Ontology loading is set to fail on missing imports.
 
+     </div>
+    </div> 
+  </div>
+
+  <script>
+    $(".enginelisting p").click(function () {
+      $(this).parents("div").toggleClass("collapsed");
+    });    
+  </script>
+
   <h3>Stored ontologies</h3>
   <#assign ontologies = it.ontologies>
   <div class="storeContents">
     <table id="allOntologies">
       <div>
         <tr>
-          <th>Name</th>
+          <th>ID</th>
+          <th>Direct handles</th>
         </tr>
         <#list it.ontologies as ontology>
           <tr>
             <td><a href="${it.publicBaseUri}ontonet/${ontology}">${ontology}</a></td>
+            <td>${it.getHandles(ontology)?size}</td>
           </tr>
         </#list>
       </div>

Modified: incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/OntologyNetworkResource/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/OntologyNetworkResource/index.ftl?rev=1363428&r1=1363427&r2=1363428&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/OntologyNetworkResource/index.ftl (original)
+++ incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/OntologyNetworkResource/index.ftl Thu Jul 19 17:10:05 2012
@@ -50,9 +50,9 @@
 		      <tr>
 			    <td>
 			    <#--
-                  <img src="${it.staticRootUrl}/contenthub/images/edit_icon_16.png" title="(not available yet) Edit this item" />
+                  <img src="${it.staticRootUrl}/ontonet/images/edit_icon_16.png" title="(not available yet) Edit this item" />
                 -->
-                  <img src="${it.staticRootUrl}/contenthub/images/delete_icon_16.png" title="Delete this item" onClick="javascript:deleteScope('${scope.ID}')"/>
+                  <img src="${it.staticRootUrl}/ontonet/images/delete_icon_16.png" title="Delete this item" onClick="javascript:deleteScope('${scope.ID}')"/>
                 </td>
                 <td><a href="${it.publicBaseUri}ontonet/ontology/${scope.ID}" title="${scope.ID}">${scope.ID}</a></td>
                 <td>${scope.locked?string("locked", "modifiable")}</td>

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=1363428&r1=1363427&r2=1363428&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 Thu Jul 19 17:10:05 2012
@@ -23,7 +23,13 @@
 	
     <div class="panel" id="webview">
   
-    <h3>Load ontologies</h3>
+  <!-- FIXME class names should be generic, and not bound to a specific functionality (here engines->reasoning services)-->
+  <div class="enginelisting">
+    <div class="collapsed">
+      <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>From a local file</legend>
@@ -62,9 +68,9 @@
       <legend>From a whole ontology library</legend>
       <p><b>Library ID:</b> 
         <select name="library">  
-        <option value="null">&lt;please select a library&gt;</option>
+          <option value="null">&lt;please select a library&gt;</option>
         <#list it.libraries as lib>
-        <option value="${lib.IRI}">${lib.name}</option>
+          <option value="${lib.IRI}">${lib.name}</option>
         </#list>
         </select>
         <input type="submit" value="Load"/>
@@ -74,6 +80,16 @@
   
   Note: OWL import targets will be included. Ontology loading is set to fail on missing imports.
 
+     </div>
+    </div> 
+  </div>
+
+  <script>
+    $(".enginelisting p").click(function () {
+      $(this).parents("div").toggleClass("collapsed");
+    });    
+  </script>
+  
   <h3>Stored ontologies</h3>
   <h4>Custom</h4>
   <#assign ontologies = it.customOntologies>