Author: enridaga
Date: Mon Aug 22 16:58:42 2011
New Revision: 1160332

URL: http://svn.apache.org/viewvc?rev=1160332&view=rev
Log:
Few steps on STANBOL-185.
* The path of a reasoning service can be configured via OSGi console
* Added a asImmutableSet() method to the ReasoningServiceManager to provide an 
immutable set of services (for utility, example in a template to iterate the 
list of available services)
* Added owlapi and jena modules to the web in pom.xml
* Created a new resource ReasoningServiceTaskResource, to start understanding 
how to bind rest requests to reasoning services in a smart way. A basic try 
have been done get() method.
* An initial writer for Jena Model have been added.

Added:
    
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java
    
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/writers/
    
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/writers/JenaModelWriter.java
    
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/
    
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/index.ftl
    
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/jena-model.ftl
    
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServicesResource/
    
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServicesResource/index.ftl
Modified:
    
incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/main/java/org/apache/stanbol/reasoners/hermit/HermitReasoningService.java
    
incubator/stanbol/branches/jena-reasoners/reasoners/jena/src/main/java/org/apache/stanbol/reasoners/jena/JenaOWLMiniReasoningService.java
    
incubator/stanbol/branches/jena-reasoners/reasoners/jena/src/main/java/org/apache/stanbol/reasoners/jena/JenaOWLReasoningService.java
    
incubator/stanbol/branches/jena-reasoners/reasoners/jena/src/main/java/org/apache/stanbol/reasoners/jena/JenaRDFSReasoningService.java
    
incubator/stanbol/branches/jena-reasoners/reasoners/manager/src/main/java/org/apache/stanbol/reasoners/manager/ReasoningServicesManagerImpl.java
    
incubator/stanbol/branches/jena-reasoners/reasoners/servicesapi/src/main/java/org/apache/stanbol/reasoners/servicesapi/ReasoningServicesManager.java
    incubator/stanbol/branches/jena-reasoners/reasoners/web/pom.xml
    
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/ReasonersFragment.java
    
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServicesResource.java

Modified: 
incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/main/java/org/apache/stanbol/reasoners/hermit/HermitReasoningService.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/main/java/org/apache/stanbol/reasoners/hermit/HermitReasoningService.java?rev=1160332&r1=1160331&r2=1160332&view=diff
==============================================================================
--- 
incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/main/java/org/apache/stanbol/reasoners/hermit/HermitReasoningService.java
 (original)
+++ 
incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/main/java/org/apache/stanbol/reasoners/hermit/HermitReasoningService.java
 Mon Aug 22 16:58:42 2011
@@ -1,11 +1,13 @@
 package org.apache.stanbol.reasoners.hermit;
 
+import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.stanbol.reasoners.owlapi.AbstractOWLApiReasoningService;
 import org.apache.stanbol.reasoners.owlapi.OWLApiReasoningService;
 import org.apache.stanbol.reasoners.servicesapi.ReasoningService;
+import org.osgi.service.component.ComponentContext;
 import org.semanticweb.HermiT.Configuration;
 import org.semanticweb.HermiT.Reasoner.ReasonerFactory;
 import org.semanticweb.owlapi.model.OWLOntology;
@@ -19,8 +21,10 @@ import org.semanticweb.owlapi.reasoner.O
 @Service
 public class HermitReasoningService extends AbstractOWLApiReasoningService
                implements OWLApiReasoningService, ReasoningService {
-       @Property(value = "hermit")
-       private static final String PATH = ReasoningService.SERVICE_PATH;
+       public static final String _DEFAULT_PATH = "hermit";
+
+       @Property(name = ReasoningService.SERVICE_PATH, value = _DEFAULT_PATH)
+       private String path;
 
        @Override
        protected OWLReasoner getReasoner(OWLOntology ontology) {
@@ -32,6 +36,10 @@ public class HermitReasoningService exte
 
        @Override
        public String getPath() {
-               return PATH;
+               return path;
+       }
+       @Activate
+       public void activate(ComponentContext context){
+               this.path = (String) 
context.getProperties().get(ReasoningService.SERVICE_PATH);
        }
 }

Modified: 
incubator/stanbol/branches/jena-reasoners/reasoners/jena/src/main/java/org/apache/stanbol/reasoners/jena/JenaOWLMiniReasoningService.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/jena/src/main/java/org/apache/stanbol/reasoners/jena/JenaOWLMiniReasoningService.java?rev=1160332&r1=1160331&r2=1160332&view=diff
==============================================================================
--- 
incubator/stanbol/branches/jena-reasoners/reasoners/jena/src/main/java/org/apache/stanbol/reasoners/jena/JenaOWLMiniReasoningService.java
 (original)
+++ 
incubator/stanbol/branches/jena-reasoners/reasoners/jena/src/main/java/org/apache/stanbol/reasoners/jena/JenaOWLMiniReasoningService.java
 Mon Aug 22 16:58:42 2011
@@ -1,9 +1,11 @@
 package org.apache.stanbol.reasoners.jena;
 
+import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.stanbol.reasoners.servicesapi.ReasoningService;
+import org.osgi.service.component.ComponentContext;
 
 import com.hp.hpl.jena.reasoner.ReasonerRegistry;
 
@@ -14,8 +16,10 @@ import com.hp.hpl.jena.reasoner.Reasoner
 @Service
 public class JenaOWLMiniReasoningService extends AbstractJenaReasoningService
                implements ReasoningService {
-       @Property(value = "owlmini")
-       private static final String PATH = ReasoningService.SERVICE_PATH;
+       public static final String _DEFAULT_PATH = "owlmini";
+
+       @Property(name = ReasoningService.SERVICE_PATH, value = _DEFAULT_PATH)
+       private String path;
 
        public JenaOWLMiniReasoningService() {
                super(ReasonerRegistry.getOWLMiniReasoner());
@@ -23,6 +27,11 @@ public class JenaOWLMiniReasoningService
 
        @Override
        public String getPath() {
-               return PATH;
+               return path;
+       }
+               
+       @Activate
+       public void activate(ComponentContext context){
+               this.path = (String) 
context.getProperties().get(ReasoningService.SERVICE_PATH);
        }
 }

Modified: 
incubator/stanbol/branches/jena-reasoners/reasoners/jena/src/main/java/org/apache/stanbol/reasoners/jena/JenaOWLReasoningService.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/jena/src/main/java/org/apache/stanbol/reasoners/jena/JenaOWLReasoningService.java?rev=1160332&r1=1160331&r2=1160332&view=diff
==============================================================================
--- 
incubator/stanbol/branches/jena-reasoners/reasoners/jena/src/main/java/org/apache/stanbol/reasoners/jena/JenaOWLReasoningService.java
 (original)
+++ 
incubator/stanbol/branches/jena-reasoners/reasoners/jena/src/main/java/org/apache/stanbol/reasoners/jena/JenaOWLReasoningService.java
 Mon Aug 22 16:58:42 2011
@@ -1,9 +1,11 @@
 package org.apache.stanbol.reasoners.jena;
 
+import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.stanbol.reasoners.servicesapi.ReasoningService;
+import org.osgi.service.component.ComponentContext;
 
 import com.hp.hpl.jena.reasoner.ReasonerRegistry;
 
@@ -14,9 +16,10 @@ import com.hp.hpl.jena.reasoner.Reasoner
 @Service
 public class JenaOWLReasoningService extends AbstractJenaReasoningService
                implements ReasoningService {
-
-       @Property(value = "owl")
-       private static final String PATH = ReasoningService.SERVICE_PATH;
+       public static final String _DEFAULT_PATH = "owl";
+       
+       @Property(name = ReasoningService.SERVICE_PATH, value = _DEFAULT_PATH)
+       private String path;
        
        public JenaOWLReasoningService() {
                super(ReasonerRegistry.getOWLReasoner());
@@ -24,6 +27,10 @@ public class JenaOWLReasoningService ext
 
        @Override
        public String getPath() {
-               return PATH;
+               return path;
+       }
+       @Activate
+       public void activate(ComponentContext context){
+               this.path = (String) 
context.getProperties().get(ReasoningService.SERVICE_PATH);
        }
 }

Modified: 
incubator/stanbol/branches/jena-reasoners/reasoners/jena/src/main/java/org/apache/stanbol/reasoners/jena/JenaRDFSReasoningService.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/jena/src/main/java/org/apache/stanbol/reasoners/jena/JenaRDFSReasoningService.java?rev=1160332&r1=1160331&r2=1160332&view=diff
==============================================================================
--- 
incubator/stanbol/branches/jena-reasoners/reasoners/jena/src/main/java/org/apache/stanbol/reasoners/jena/JenaRDFSReasoningService.java
 (original)
+++ 
incubator/stanbol/branches/jena-reasoners/reasoners/jena/src/main/java/org/apache/stanbol/reasoners/jena/JenaRDFSReasoningService.java
 Mon Aug 22 16:58:42 2011
@@ -1,9 +1,11 @@
 package org.apache.stanbol.reasoners.jena;
 
+import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.stanbol.reasoners.servicesapi.ReasoningService;
+import org.osgi.service.component.ComponentContext;
 
 import com.hp.hpl.jena.reasoner.ReasonerRegistry;
 
@@ -17,9 +19,10 @@ import com.hp.hpl.jena.reasoner.Reasoner
 @Service
 public class JenaRDFSReasoningService extends AbstractJenaReasoningService
                implements ReasoningService {
+       public static final String _DEFAULT_PATH = "rdfs";
 
-       @Property(value = "rdfs")
-       private static final String PATH = ReasoningService.SERVICE_PATH;
+       @Property(name = ReasoningService.SERVICE_PATH, value = _DEFAULT_PATH)
+       private String path;
 
        public JenaRDFSReasoningService() {
                super(ReasonerRegistry.getRDFSReasoner());
@@ -27,6 +30,10 @@ public class JenaRDFSReasoningService ex
 
        @Override
        public String getPath() {
-               return PATH;
+               return path;
+       }
+       @Activate
+       public void activate(ComponentContext context){
+               this.path = (String) 
context.getProperties().get(ReasoningService.SERVICE_PATH);
        }
 }

Modified: 
incubator/stanbol/branches/jena-reasoners/reasoners/manager/src/main/java/org/apache/stanbol/reasoners/manager/ReasoningServicesManagerImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/manager/src/main/java/org/apache/stanbol/reasoners/manager/ReasoningServicesManagerImpl.java?rev=1160332&r1=1160331&r2=1160332&view=diff
==============================================================================
--- 
incubator/stanbol/branches/jena-reasoners/reasoners/manager/src/main/java/org/apache/stanbol/reasoners/manager/ReasoningServicesManagerImpl.java
 (original)
+++ 
incubator/stanbol/branches/jena-reasoners/reasoners/manager/src/main/java/org/apache/stanbol/reasoners/manager/ReasoningServicesManagerImpl.java
 Mon Aug 22 16:58:42 2011
@@ -1,5 +1,6 @@
 package org.apache.stanbol.reasoners.manager;
 
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -25,16 +26,16 @@ public class ReasoningServicesManagerImp
 
        public void bindReasoningService(ReasoningService service) {
                services.add(service);
-               log.info("Reasoning service {} added to path {}", service,
+               log.debug("Reasoning service {} added to path {}", service,
                                service.getPath());
-               log.info("{} services bound.", services.size());
+               log.debug("{} services bound.", services.size());
        }
 
        public void unbindReasoningService(ReasoningService service) {
                services.remove(service);
-               log.info("Reasoning service {} removed from path {}", service,
+               log.debug("Reasoning service {} removed from path {}", service,
                                service.getPath());
-               log.info("{} services bound.", services.size());
+               log.debug("{} services bound.", services.size());
        }
 
        /*
@@ -50,11 +51,17 @@ public class ReasoningServicesManagerImp
        @Override
        public ReasoningService get(String path) throws 
UnboundReasoningServiceException {
                for (ReasoningService service : services) {
+                       log.debug("Does service {} match path 
{}?",service,path);
                        if (service.getPath().equals(path)) {
                                return service;
                        }
                }
                throw new UnboundReasoningServiceException();
        }
+       
+       @Override
+       public Set<ReasoningService> asUnmodifiableSet(){
+               return Collections.unmodifiableSet(services);
+       }
 }
 

Modified: 
incubator/stanbol/branches/jena-reasoners/reasoners/servicesapi/src/main/java/org/apache/stanbol/reasoners/servicesapi/ReasoningServicesManager.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/servicesapi/src/main/java/org/apache/stanbol/reasoners/servicesapi/ReasoningServicesManager.java?rev=1160332&r1=1160331&r2=1160332&view=diff
==============================================================================
--- 
incubator/stanbol/branches/jena-reasoners/reasoners/servicesapi/src/main/java/org/apache/stanbol/reasoners/servicesapi/ReasoningServicesManager.java
 (original)
+++ 
incubator/stanbol/branches/jena-reasoners/reasoners/servicesapi/src/main/java/org/apache/stanbol/reasoners/servicesapi/ReasoningServicesManager.java
 Mon Aug 22 16:58:42 2011
@@ -1,5 +1,7 @@
 package org.apache.stanbol.reasoners.servicesapi;
 
+import java.util.Set;
+
 public interface ReasoningServicesManager {
 
        public abstract int size();
@@ -7,4 +9,6 @@ public interface ReasoningServicesManage
        public abstract ReasoningService get(String path)
                        throws UnboundReasoningServiceException;
 
+       public abstract Set<ReasoningService> asUnmodifiableSet();
+
 }

Modified: incubator/stanbol/branches/jena-reasoners/reasoners/web/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/web/pom.xml?rev=1160332&r1=1160331&r2=1160332&view=diff
==============================================================================
--- incubator/stanbol/branches/jena-reasoners/reasoners/web/pom.xml (original)
+++ incubator/stanbol/branches/jena-reasoners/reasoners/web/pom.xml Mon Aug 22 
16:58:42 2011
@@ -347,7 +347,16 @@
     <artifactId>org.apache.stanbol.reasoners.servicesapi</artifactId>
     <version>0.1</version>
     </dependency>
-    
+    <dependency>
+    <groupId>org.apache.stanbol</groupId>
+    <artifactId>org.apache.stanbol.reasoners.jena</artifactId>
+    <version>0.1</version>
+    </dependency>
+    <dependency>
+    <groupId>org.apache.stanbol</groupId>
+    <artifactId>org.apache.stanbol.reasoners.owlapi</artifactId>
+    <version>0.1</version>
+    </dependency>    
     <dependency>
       <groupId>com.hp.hpl.jena</groupId>
       <artifactId>jena</artifactId>

Modified: 
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/ReasonersFragment.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/ReasonersFragment.java?rev=1160332&r1=1160331&r2=1160332&view=diff
==============================================================================
--- 
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/ReasonersFragment.java
 (original)
+++ 
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/ReasonersFragment.java
 Mon Aug 22 16:58:42 2011
@@ -37,7 +37,9 @@ import org.apache.stanbol.reasoners.web.
 import org.apache.stanbol.reasoners.web.resources.ConsistentRefactoring;
 import org.apache.stanbol.reasoners.web.resources.Enrichment;
 import org.apache.stanbol.reasoners.web.resources.ReasonersResource;
+import org.apache.stanbol.reasoners.web.resources.ReasoningServiceTaskResource;
 import org.apache.stanbol.reasoners.web.resources.ReasoningServicesResource;
+import org.apache.stanbol.reasoners.web.writers.JenaModelWriter;
 import org.apache.stanbol.rules.base.api.RuleStore;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.component.ComponentContext;
@@ -88,8 +90,12 @@ public class ReasonersFragment implement
         classes.add(ConsistentRefactoring.class);
         classes.add(Classify.class);
         classes.add(Enrichment.class);
+        
         classes.add(ReasoningServicesResource.class);
+        classes.add(ReasoningServiceTaskResource.class);
         
+        // Writer
+        classes.add(JenaModelWriter.class);
         return classes;
     }
 

Added: 
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java?rev=1160332&view=auto
==============================================================================
--- 
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java
 (added)
+++ 
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java
 Mon Aug 22 16:58:42 2011
@@ -0,0 +1,210 @@
+package org.apache.stanbol.reasoners.web.resources;
+
+import static javax.ws.rs.core.MediaType.MULTIPART_FORM_DATA;
+import static javax.ws.rs.core.MediaType.TEXT_HTML;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.stanbol.commons.web.base.ContextHelper;
+import org.apache.stanbol.commons.web.base.format.KRFormat;
+import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
+import org.apache.stanbol.reasoners.jena.JenaReasoningService;
+import org.apache.stanbol.reasoners.owlapi.OWLApiReasoningService;
+import org.apache.stanbol.reasoners.servicesapi.ReasoningService;
+import org.apache.stanbol.reasoners.servicesapi.ReasoningServicesManager;
+import 
org.apache.stanbol.reasoners.servicesapi.UnboundReasoningServiceException;
+import org.apache.stanbol.reasoners.web.writers.JenaModelWriter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.Statement;
+import com.sun.jersey.api.view.Viewable;
+import com.sun.jersey.multipart.FormDataParam;
+
+@Path("/reasoners/services/{service}/{task}")
+public class ReasoningServiceTaskResource extends BaseStanbolResource {
+       private Logger log = LoggerFactory.getLogger(getClass());
+       private ServletContext context;
+
+       /**
+        * TODO: We may want to extend the possible tasks in the future, 
demanding
+        * the execution to some delegate...
+        */
+       public static final String[] TASKS = { "enrich", "classify", "check" };
+
+       private ReasoningService service;
+       private String taskID;
+
+       public ReasoningServiceTaskResource(
+                       @PathParam(value = "service") String serviceID,
+                       @PathParam(value = "task") String taskID,
+                       @Context ServletContext servletContext) {
+               super();
+               this.context = servletContext;
+               // Retrieve the service
+               try {
+                       service = getService(serviceID);
+               } catch (UnboundReasoningServiceException e) {
+                       log.error("Service not found: {}", serviceID);
+                       throw new WebApplicationException(e, 
Response.Status.NOT_FOUND);
+               }
+               // Check if the task is allowed
+               if (Arrays.asList(TASKS).contains(taskID)) {
+                       this.taskID = taskID;
+               } else {
+                       log.error("Unsupported task (not found): {}", taskID);
+                       throw new WebApplicationException(new Exception(
+                                       "Unsupported task (not found): " + 
taskID),
+                                       Response.Status.BAD_REQUEST);
+               }
+
+               // Now we check if the service implementation is supported
+               if (getCurrentService() instanceof JenaReasoningService) {
+               } else if (getCurrentService() instanceof 
OWLApiReasoningService) {
+               } else {
+                       log.error(
+                                       "This implementation of 
ReasoningService is not supported: {}",
+                                       getCurrentService().getClass());
+                       throw new WebApplicationException(new Exception(
+                                       "This implementation of 
ReasoningService is not supported: "
+                                                       + 
getCurrentService().getClass()),
+                                       Response.Status.INTERNAL_SERVER_ERROR);
+               }
+       }
+
+       @POST
+       @Consumes({ MULTIPART_FORM_DATA })
+       @Produces({ TEXT_HTML, KRFormat.RDF_XML, KRFormat.TURTLE, 
KRFormat.OWL_XML })
+       public Response postData(@FormDataParam("file") File file) {
+               log.info("Called POST on service {} to perform task {}", 
service,
+                               taskID);
+               log.info("on input file: {}", file);
+               return Response.ok(new Viewable("index", this), 
TEXT_HTML).build();
+       }
+
+       @GET
+       @Produces({ TEXT_HTML, "text/plain", KRFormat.RDF_XML, KRFormat.TURTLE,
+                       "text/turtle", "text/n3" })
+       public Response get(@QueryParam("url") String url,
+                       @Context HttpHeaders headers) {
+               log.info("Called GET on service {} to perform task {}", 
service, taskID);
+               log.info("on input url: {}", url);
+               //
+               if (getCurrentService() instanceof JenaReasoningService) {
+                       JenaReasoningService s = (JenaReasoningService) 
getCurrentService();
+
+                       if (getCurrentTask().equals("check")) {
+                               log.info("Task is 'check'");
+                               boolean isConsistent;
+                               isConsistent = 
s.isConsistent(ModelFactory.createDefaultModel()
+                                               .read(url));
+                               if (isConsistent) {
+                                       log.info("Is consistent");
+                                       return Response.ok().build();
+                               } else {
+                                       log.info("Is not consistent");
+                                       return 
Response.status(Status.NO_CONTENT).build();
+                               }
+                       }
+
+                       Set<Statement> result = null;
+                       if (getCurrentTask().equals("classify")) {
+                               result = s
+                                               
.classify(ModelFactory.createDefaultModel().read(url));
+                       } else if (getCurrentTask().equals("enrich")) {
+                               log.info("Task is: 'enrich'");
+                               result = 
s.enrich(ModelFactory.createDefaultModel().read(url));
+                       }
+                       if (result == null) {
+                               log.error("Result is null");
+                               throw new WebApplicationException();
+                       }
+                       log.info("Returning {} statements", result.size());
+                       Model outputModel = ModelFactory.createDefaultModel();
+                       outputModel.add(result.toArray(new 
Statement[result.size()]));
+                       
+                       // We only want to state if HTML format is the 
preferred format
+                       // requested
+                       Set<String> htmlformats = new HashSet<String>();
+                       htmlformats.add(TEXT_HTML);
+                       Set<String> rdfformats = new HashSet<String>();
+                       String[] formats = { TEXT_HTML, "text/plain", 
KRFormat.RDF_XML, KRFormat.TURTLE,
+                                       "text/turtle", "text/n3" };
+                       rdfformats.addAll(Arrays.asList(formats));
+                       List<MediaType> mediaTypes = 
headers.getAcceptableMediaTypes();
+                       for (MediaType t : mediaTypes) {
+                               String strty = t.toString();
+                               log.info("Acceptable is {}", t);
+                               if (htmlformats.contains(strty)) {
+                                       log.info("EQUAL!!! is {}", t);
+                                       return Response.ok(
+                                                       new 
Viewable("jena-model",
+                                                                       new 
JenaModelWriter().toStream(outputModel,
+                                                                               
        "text/n3")), TEXT_HTML).build();
+                               }else if(rdfformats.contains(strty)){
+                                       return 
Response.ok(outputModel).build();                                        
+                               }
+                       }
+
+               } else if (getCurrentService() instanceof 
OWLApiReasoningService) {
+                       // TODO
+                       throw new WebApplicationException(new Exception(
+                                       "Unsupported implementation"),
+                                       Response.Status.INTERNAL_SERVER_ERROR);
+               }
+               throw new WebApplicationException(new Exception(
+                               "Unsupported implementation"),
+                               Response.Status.INTERNAL_SERVER_ERROR);
+       }
+
+       public ReasoningService getCurrentService() {
+               return this.service;
+       }
+
+       public String getCurrentTask() {
+               return this.taskID;
+       }
+
+       public List<String> getSupportedTasks() {
+               return Arrays.asList(ReasoningServiceTaskResource.TASKS);
+       }
+
+       private ReasoningService getService(String servicePath)
+                       throws UnboundReasoningServiceException {
+               return getServicesManager().get(servicePath);
+       }
+
+       private ReasoningServicesManager getServicesManager() {
+               log.debug("(getServicesManager()) ");
+               return (ReasoningServicesManager) 
ContextHelper.getServiceFromContext(
+                               ReasoningServicesManager.class, this.context);
+       }
+
+       public Set<ReasoningService> getActiveServices() {
+               log.debug("(getActiveServices()) There are {} reasoning 
services",
+                               getServicesManager().size());
+               return getServicesManager().asUnmodifiableSet();
+       }
+}

Modified: 
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServicesResource.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServicesResource.java?rev=1160332&r1=1160331&r2=1160332&view=diff
==============================================================================
--- 
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServicesResource.java
 (original)
+++ 
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServicesResource.java
 Mon Aug 22 16:58:42 2011
@@ -2,13 +2,15 @@ package org.apache.stanbol.reasoners.web
 
 import static javax.ws.rs.core.MediaType.TEXT_HTML;
 
+import java.util.Set;
+
 import javax.servlet.ServletContext;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
 
 import org.apache.stanbol.commons.web.base.ContextHelper;
 import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
@@ -17,24 +19,45 @@ import org.apache.stanbol.reasoners.serv
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.sun.jersey.api.view.ImplicitProduces;
 import com.sun.jersey.api.view.Viewable;
 
 @Path("/reasoners/services")
-@ImplicitProduces(MediaType.TEXT_HTML)
 public class ReasoningServicesResource extends BaseStanbolResource {
        private Logger log = LoggerFactory.getLogger(getClass());
        private ServletContext context;
-
-       public ReasoningServicesResource(@Context ServletContext 
servletContext) {
+       private UriInfo uriInfo;
+       
+       public ReasoningServicesResource(@Context ServletContext 
servletContext, @Context UriInfo uriInfo) {
+               super();
                this.context = servletContext;
+               this.uriInfo = uriInfo;
+       }
+
+       public String getCurrentPath(){
+               return uriInfo.getPath();
+       }
+       
+       public String[] getTasks(){
+               return ReasoningServiceTaskResource.TASKS;
        }
 
        @GET
        @Produces(TEXT_HTML)
-       public Response getView() {
-               ReasoningServicesManager services = (ReasoningServicesManager) 
ContextHelper.getServiceFromContext(
-                               ReasoningServicesManager.class, this.context);
-               return Response.ok("Services: " + services.size(), 
TEXT_HTML).build();
+       public Response getDocumentation() {
+               return Response.ok(new Viewable("index", this), 
TEXT_HTML).build();
        }
+
+       
+       private ReasoningServicesManager getServicesManager(){
+               log.debug("(getServicesManager()) ");
+               return  (ReasoningServicesManager) ContextHelper
+                               
.getServiceFromContext(ReasoningServicesManager.class,
+                                               this.context);
+       }
+       public Set<ReasoningService> getActiveServices() {
+               log.debug("(getActiveServices()) There are {} reasoning 
services",
+                               getServicesManager().size());
+               return getServicesManager().asUnmodifiableSet();
+       }
+
 }

Added: 
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/writers/JenaModelWriter.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/writers/JenaModelWriter.java?rev=1160332&view=auto
==============================================================================
--- 
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/writers/JenaModelWriter.java
 (added)
+++ 
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/writers/JenaModelWriter.java
 Mon Aug 22 16:58:42 2011
@@ -0,0 +1,79 @@
+package org.apache.stanbol.reasoners.web.writers;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.RDFWriter;
+
+@Provider
+@Produces({"application/rdf+xml","text/turtle","text/n3","text/plain","application/turtle"})
+public class JenaModelWriter implements MessageBodyWriter<Model> {
+       private final Logger log = LoggerFactory.getLogger(getClass());
+
+       @Override
+       public boolean isWriteable(Class<?> type, Type genericType,
+                       Annotation[] annotations, MediaType mediaType) {
+               return Model.class.isAssignableFrom(type);
+       }
+
+       private ByteArrayOutputStream stream = null;
+
+       @Override
+       public long getSize(Model t, Class<?> type, Type genericType,
+                       Annotation[] annotations, MediaType mediaType) {
+               log.debug("Called size of item");
+               stream = toStream(t, mediaType.toString());
+               log.error("Returning {} bytes",stream.size());
+               return Integer.valueOf(stream.toByteArray().length).longValue();
+       }
+
+       public ByteArrayOutputStream toStream(Model t, String mediaType) {
+               log.info("Serializing model to {}. Statements are 
{}",mediaType, t.listStatements().toSet().size());
+               ByteArrayOutputStream stream = new ByteArrayOutputStream();
+               if (mediaType.equals("application/rdf+xml")) {
+                       t.write(stream);
+               }else if (mediaType.equals("application/turtle")){
+                       //t.write(stream, "TURTLE");
+                       RDFWriter writer = t.getWriter("TURTLE");
+                       log.info("Writer for TURTLE: {}",writer);
+                       writer.write(t, stream, null);
+               }else if (mediaType.equals("text/turtle")){
+                       t.write(stream, "TURTLE");
+               }else if (mediaType.equals("text/plain")){
+                       t.write(stream, "TURTLE");
+               }else if (mediaType.equals("text/n3")){
+                       t.write(stream, "N3");
+               }
+               log.info("Written {} bytes to 
stream",stream.toByteArray().length);
+               return stream;
+       }
+
+       @Override
+       public void writeTo(Model t, Class<?> type, Type genericType,
+                       Annotation[] annotations, MediaType mediaType,
+                       MultivaluedMap<String, Object> httpHeaders,
+                       OutputStream entityStream) throws IOException,
+                       WebApplicationException {
+               if (stream == null) {
+                       toStream(t, mediaType.toString()).writeTo(entityStream);
+               } else {
+                       stream.writeTo(entityStream);
+                       stream = null;
+               }
+       }
+
+}

Added: 
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/index.ftl
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/index.ftl?rev=1160332&view=auto
==============================================================================
--- 
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/index.ftl
 (added)
+++ 
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/index.ftl
 Mon Aug 22 16:58:42 2011
@@ -0,0 +1,35 @@
+<#--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<#import "/imports/common.ftl" as common>
+<#escape x as x?html>
+<@common.page title="Apache Stanbol Reasoners: Service 
/${it.currentService.path}/${it.currentTask}" hasrestapi=false> 
+               
+ <div class="panel" id="webview">
+       <p><em>Service type:</em> ${it.currentService.class.name}</p>
+       <p><em>Path:</em> ${it.currentService.path}</p>
+       <p><em>Task:</em> ${it.currentTask}</p>
+ </div>
+
+    <#-- We disable this at the moment -->
+    <!--
+    <div class="panel" id="restapi" style="display: none;">
+          
+    </div>
+    -->
+
+  </@common.page>
+</#escape>
\ No newline at end of file

Added: 
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/jena-model.ftl
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/jena-model.ftl?rev=1160332&view=auto
==============================================================================
--- 
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/jena-model.ftl
 (added)
+++ 
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/jena-model.ftl
 Mon Aug 22 16:58:42 2011
@@ -0,0 +1,26 @@
+<#--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<#escape x as x?html>
+<html>
+<head></head>
+<body>
+<pre>
+${it}
+</pre>
+</body>
+</html>
+</#escape>
\ No newline at end of file

Added: 
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServicesResource/index.ftl
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServicesResource/index.ftl?rev=1160332&view=auto
==============================================================================
--- 
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServicesResource/index.ftl
 (added)
+++ 
incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServicesResource/index.ftl
 Mon Aug 22 16:58:42 2011
@@ -0,0 +1,66 @@
+<#--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<#import "/imports/common.ftl" as common>
+<#import "/imports/reasonersDescription.ftl" as reasonersDescription>
+<#escape x as x?html>
+<@common.page title="Apache Stanbol Reasoners: Services" hasrestapi=false> 
+               
+ <div class="panel" id="webview">
+ <#if it.activeServices?size == 0>
+   <p><em>There is no reasoning services. Administrators can install and
+   configure new reasoning services using the
+    <a href="/system/console/components" target="_blank">OSGi 
console</a>.</em></p>
+ <#else>
+ <!-- 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">There are currently
+   <strong>${it.activeServices?size}</strong> active services.</p>
+   <div class="collapsable">
+    <ul>
+
+     <#list it.activeServices as service>
+      <li><b>.../${service.path}</b>:<br/>Tasks:
+        <#list it.tasks as task> 
+               <a href="/${it.currentPath}/${service.path}/${task}" 
title="${service.class.name} Task: ${task}">${task}</a>
+        </#list>
+      </li>
+     </#list>
+    </ul>
+    
+  <p class="note">Administrators can enable, disable and deploy reasoning 
services using the
+    <a href="/system/console/components" target="_blank">OSGi console</a>.</p>
+   </div>
+   
+  </div> 
+ </div>
+
+<script>
+$(".enginelisting p").click(function () {
+  $(this).parents("div").toggleClass("collapsed");
+});    
+</script>
+ </#if>
+       </div>
+
+    <!-- We disable this at the moment -->
+    <!--div class="panel" id="restapi" style="display: none;">
+          
+    </div -->
+
+</@common.page>
+</#escape>
\ No newline at end of file


Reply via email to