You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by en...@apache.org on 2011/11/23 18:19:54 UTC

svn commit: r1205499 - in /incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main: java/org/apache/stanbol/reasoners/web/resources/ java/org/apache/stanbol/reasoners/web/utils/ resources/org/apache/stanbol/reasoners/web/templates/org/apache/st...

Author: enridaga
Date: Wed Nov 23 17:19:52 2011
New Revision: 1205499

URL: http://svn.apache.org/viewvc?rev=1205499&view=rev
Log:
* Fixed the generation of the job location when output is not ready (404)
* Added html description in case of 404 and on job creation
(STANBOL-343)

Added:
    incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/JobsResource/404.ftl
      - copied, changed from r1205460, incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/JobsResource/result.ftl
    incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/created.ftl
Modified:
    incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/JobsResource.java
    incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java
    incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/utils/ReasoningServiceExecutor.java
    incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/JobsResource/result.ftl
    incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/result.ftl

Modified: incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/JobsResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/JobsResource.java?rev=1205499&r1=1205498&r2=1205499&view=diff
==============================================================================
--- incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/JobsResource.java (original)
+++ incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/JobsResource.java Wed Nov 23 17:19:52 2011
@@ -36,6 +36,8 @@ import org.apache.stanbol.reasoners.web.
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.sun.jersey.api.view.Viewable;
+
 /**
  * Return the result of a reasoners background job
  * 
@@ -48,6 +50,8 @@ public class JobsResource extends BaseSt
     private ServletContext context;
     private HttpHeaders headers;
 
+    private String jobLocation = "";
+    
     public JobsResource(@Context ServletContext servletContext,@Context HttpHeaders headers) {
         this.context = servletContext;
         this.headers = headers;
@@ -102,11 +106,10 @@ public class JobsResource extends BaseSt
                 /**
                  * We return 404 with additional info
                  */
-                String jobService = new StringBuilder().append(getPublicBaseUri()).append("/jobs/").append(id).toString();
-                StringBuilder b = new StringBuilder();
-                b.append("Result not ready.\n");
-                b.append("See: ").append(jobService);
-                return Response.status(404).header("Content-Location", jobService).entity( b.toString() ).build();
+                String jobService = new StringBuilder().append(getPublicBaseUri()).append("jobs/").append(id).toString();
+                this.jobLocation = jobService;
+                Viewable viewable = new Viewable("404.ftl",this);
+                return Response.status(404).header("Content-Location", jobService).header("Content-type","text/html").entity( viewable ).build();
             }
         } else {
             log.info("No job found with id {}", id);
@@ -115,6 +118,15 @@ public class JobsResource extends BaseSt
     }
 
     /**
+     * If the output is not ready, this field contains the location of the job to be rendered in the viewable.
+     * 
+     * @return
+     */
+    public String getJobLocation(){
+        return this.jobLocation;
+    }
+    
+    /**
      * Gets the job manager
      * 
      * @return

Modified: incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java?rev=1205499&r1=1205498&r2=1205499&view=diff
==============================================================================
--- incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java (original)
+++ incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java Wed Nov 23 17:19:52 2011
@@ -105,7 +105,8 @@ public class ReasoningServiceTaskResourc
     private ONManager onm;
     private RuleStore ruleStore;
     private boolean job = false;
-
+    private String jobLocation="";
+    
     public ReasoningServiceTaskResource(@PathParam(value = "service") String serviceID,
                                         @PathParam(value = "task") String taskID,
                                         @PathParam(value = "job") String job,
@@ -255,11 +256,14 @@ public class ReasoningServiceTaskResourc
         ReasoningServiceExecutor executor = new ReasoningServiceExecutor(tcManager, imngr,
                 getCurrentService(), getCurrentTask(), target, parameters);
         String jid = getJobManager().execute(executor);
+        URI location = URI.create(getPublicBaseUri() + "jobs/"+jid);
+        this.jobLocation = location.toString();
         /**
          * If everything went well, we return 201 Created
          * We include the header Location: with the Job URL
          */
-        return Response.created(URI.create(getPublicBaseUri() + "jobs/"+jid)).build();   
+        Viewable view = new Viewable("created", this);
+        return Response.created(location).entity(view).build();   
     }
     
     private Response processRealTimeRequest(){
@@ -469,6 +473,15 @@ public class ReasoningServiceTaskResourc
     }
 
     /**
+     * If this resource created a job, this field contains the location to be rendered in the viewable.
+     * 
+     * @return
+     */
+    public String getJobLocation(){
+       return this.jobLocation; 
+    }
+    
+    /**
      * The list of supported tasks. We include CHECK, which is managed directly by the endpoint.
      */
     public List<String> getSupportedTasks() {

Modified: incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/utils/ReasoningServiceExecutor.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/utils/ReasoningServiceExecutor.java?rev=1205499&r1=1205498&r2=1205499&view=diff
==============================================================================
--- incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/utils/ReasoningServiceExecutor.java (original)
+++ incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/utils/ReasoningServiceExecutor.java Wed Nov 23 17:19:52 2011
@@ -361,7 +361,7 @@ public class ReasoningServiceExecutor im
 
     @Override
     public String buildResultLocation(String jobId) {
-        return "/reasoners/jobs/" + jobId;
+        return "reasoners/jobs/" + jobId;
     }
 
 }

Copied: incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/JobsResource/404.ftl (from r1205460, incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/JobsResource/result.ftl)
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/JobsResource/404.ftl?p2=incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/JobsResource/404.ftl&p1=incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/JobsResource/result.ftl&r1=1205460&r2=1205499&rev=1205499&view=diff
==============================================================================
--- incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/JobsResource/result.ftl (original)
+++ incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/JobsResource/404.ftl Wed Nov 23 17:19:52 2011
@@ -16,12 +16,9 @@
 -->
 <#import "/imports/common.ftl" as common>
 <#escape x as x?html>
-<@common.page title="Reasoners: Background Job Result" hasrestapi=false> 
-		
- <div class="panel">
-<pre>
-${it.result}
-</pre>
-</div>
+<@common.page title="Reasoners: Job output not ready yet" hasrestapi=false> 	
+    <div class="panel">
+<p>See: <a href="${it.jobLocation}">${it.jobLocation}</a></p>
+    </div>
   </...@common.page>
 </#escape>
\ No newline at end of file

Modified: incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/JobsResource/result.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/JobsResource/result.ftl?rev=1205499&r1=1205498&r2=1205499&view=diff
==============================================================================
--- incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/JobsResource/result.ftl (original)
+++ incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/JobsResource/result.ftl Wed Nov 23 17:19:52 2011
@@ -16,12 +16,12 @@
 -->
 <#import "/imports/common.ftl" as common>
 <#escape x as x?html>
-<@common.page title="Reasoners: Background Job Result" hasrestapi=false> 
-		
+<@common.page title="Reasoners: Job output" hasrestapi=false>	
  <div class="panel">
-<pre>
-${it.result}
-</pre>
-</div>
+	<pre>
+	${it.result}
+	</pre>
+ </div>
+
   </...@common.page>
 </#escape>
\ No newline at end of file

Added: incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/created.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/created.ftl?rev=1205499&view=auto
==============================================================================
--- incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/created.ftl (added)
+++ incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/created.ftl Wed Nov 23 17:19:52 2011
@@ -0,0 +1,24 @@
+<#--
+  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="Reasoners: job created" hasrestapi=false> 
+ <div class="panel">
+  <p>Job created: <a href="${it.jobLocation}">${it.jobLocation}</a></p>
+ </div>
+  </...@common.page>
+</#escape>
\ No newline at end of file

Modified: incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/result.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/result.ftl?rev=1205499&r1=1205498&r2=1205499&view=diff
==============================================================================
--- incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/result.ftl (original)
+++ incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/result.ftl Wed Nov 23 17:19:52 2011
@@ -16,8 +16,7 @@
 -->
 <#import "/imports/common.ftl" as common>
 <#escape x as x?html>
-<@common.page title="Reasoners: Result" hasrestapi=false> 
-		
+<@common.page title="Reasoners: Result" hasrestapi=false>	
  <div class="panel">
 <pre>
 ${it.result}