Modified: 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=1161037&r1=1161036&r2=1161037&view=diff ============================================================================== --- incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java (original) +++ incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java Wed Aug 24 10:13:27 2011 @@ -36,7 +36,6 @@ import org.apache.clerezza.rdf.core.acce 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.ontologymanager.ontonet.api.ONManager; import org.apache.stanbol.owl.transformation.JenaToClerezzaConverter; import org.apache.stanbol.owl.transformation.OWLAPIToClerezzaConverter; import org.apache.stanbol.reasoners.jena.JenaReasoningService; @@ -46,7 +45,7 @@ import org.apache.stanbol.reasoners.serv import org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException; import org.apache.stanbol.reasoners.servicesapi.ReasoningServicesManager; import org.apache.stanbol.reasoners.servicesapi.UnboundReasoningServiceException; -import org.apache.stanbol.rules.base.api.RuleStore; +import org.apache.stanbol.reasoners.servicesapi.UnsupportedTaskException; import org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxOntologyFormat; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.io.OWLOntologyCreationIOException; @@ -65,30 +64,36 @@ 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.hp.hpl.jena.reasoner.rulesys.Rule; +import com.sun.jersey.api.core.HttpRequestContext; import com.sun.jersey.api.view.Viewable; import com.sun.jersey.multipart.FormDataParam; +/** + * Endpoint for reasoning services. Services can be invoked using the service name and task in the request + * path. The concrete execution is delegated to the SCR service. + * + * Two different kind of implementation of {@see ReasoningService} are supported: {@see JenaReasoningService} + * and {@see OWLApiReasonngService}. + * + * This class includes methods to prepare the input and dispatch the output (back to the client in the + * requested format or saved in the triple store). + * + */ @Path("/reasoners/services/{service}/{task}") public class ReasoningServiceTaskResource extends BaseStanbolResource { private Logger log = LoggerFactory.getLogger(getClass()); private ServletContext context; private HttpHeaders headers; - /** - * 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; - private RuleStore ruleStore; - private ONManager onManager; private TcManager tcManager; + private HttpRequestContext requestContext; public ReasoningServiceTaskResource(@PathParam(value = "service") String serviceID, @PathParam(value = "task") String taskID, @Context ServletContext servletContext, - @Context HttpHeaders headers) { + @Context HttpHeaders headers, + @Context HttpRequestContext request) { super(); log.info("Called service {} to perform task {}", service, taskID); // ServletContext @@ -97,11 +102,8 @@ public class ReasoningServiceTaskResourc // HttpHeaders this.headers = headers; - // Retrieve the rule store - this.ruleStore = (RuleStore) ContextHelper.getServiceFromContext(RuleStore.class, servletContext); - - // Retrieve the ontology network manager - this.onManager = (ONManager) ContextHelper.getServiceFromContext(ONManager.class, servletContext); + // HttpRequestContext + this.requestContext = request; // Clerezza storage this.tcManager = (TcManager) ContextHelper.getServiceFromContext(TcManager.class, servletContext); @@ -115,7 +117,7 @@ public class ReasoningServiceTaskResourc } // Check if the task is allowed - if (Arrays.asList(TASKS).contains(taskID)) { + if (this.service.supportsTask(taskID)) { this.taskID = taskID; } else { log.error("Unsupported task (not found): {}", taskID); @@ -317,7 +319,7 @@ public class ReasoningServiceTaskResourc } /** - * Execute the JenaReasoningService + * Execute a JenaReasoningService * * TODO: Add parameter to decide if the graph must be deleted if exists * @@ -349,14 +351,7 @@ public class ReasoningServiceTaskResourc } } try { - Set<Statement> result = null; - if (getCurrentTask().equals("classify")) { - log.debug("Task is 'classify'"); - result = s.classify(input); - } else if (getCurrentTask().equals("enrich")) { - log.debug("Task is: 'enrich'"); - result = s.enrich(input); - } + Set<Statement> result = s.runTask(getCurrentTask(), input); if (result == null) { log.error("Result is null"); throw new WebApplicationException(); @@ -385,6 +380,9 @@ public class ReasoningServiceTaskResourc } catch (InconsistentInputException e) { log.debug("The input is not consistent"); return Response.status(Status.NO_CONTENT).build(); + } catch (UnsupportedTaskException e) { + log.error("Error thrown: {}", e); + throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR); } } @@ -422,13 +420,8 @@ public class ReasoningServiceTaskResourc OWLOntologyManager manager = input.getOWLOntologyManager(); try { OWLOntology output = manager.createOntology(); - if (getCurrentTask().equals("classify")) { - log.debug("Task is 'classify'"); - manager.addAxioms(output, s.classify(input)); - } else if (getCurrentTask().equals("enrich")) { - log.debug("Task is 'enrich'"); - manager.addAxioms(output, s.enrich(input)); - } + manager.addAxioms(output, s.runTask(getCurrentTask(), input)); + if (targetGraphID == null) { if (isHTML()) { ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -452,6 +445,8 @@ public class ReasoningServiceTaskResourc throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR); } catch (OWLOntologyStorageException e) { throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR); + } catch (UnsupportedTaskException e) { + throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR); } } @@ -492,6 +487,7 @@ public class ReasoningServiceTaskResourc // We should set the manager to use a service to lookup for ontologies, instead of trying on the web // directly OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + // FIXME Which is the other way of doing this? manager.setSilentMissingImportsHandling(true); // Listening for missing imports manager.addMissingImportListener(new MissingImportListener() { @@ -534,7 +530,7 @@ public class ReasoningServiceTaskResourc * The list of supported tasks. */ public List<String> getSupportedTasks() { - return Arrays.asList(ReasoningServiceTaskResource.TASKS); + return getCurrentService().getSupportedTasks(); } /**
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=1161037&r1=1161036&r2=1161037&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 Wed Aug 24 10:13:27 2011 @@ -34,11 +34,7 @@ public class ReasoningServicesResource e } public String getCurrentPath() { - return uriInfo.getPath().replaceAll("[\\/]*$",""); - } - - public String[] getTasks() { - return ReasoningServiceTaskResource.TASKS; + return uriInfo.getPath().replaceAll("[\\/]*$", ""); } @GET Modified: 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=1161037&r1=1161036&r2=1161037&view=diff ============================================================================== --- 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 (original) +++ 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 Wed Aug 24 10:13:27 2011 @@ -35,7 +35,7 @@ <#list it.activeServices as service> <li><b>${service.path}</b>: - <#list it.tasks as task> + <#list service.supportedTasks as task> <a href="/${it.currentPath}/${service.path}/${task}" title="${service.class.name} Task: ${task}">${task}</a> </#list> </li>
