Author: jvdrean
Date: 2008-02-25 16:53:04 +0100 (Mon, 25 Feb 2008)
New Revision: 7932

Modified:
   
xwiki-platform/xwiki-plugins/trunk/scheduler/src/main/java/com/xpn/xwiki/plugin/scheduler/GroovyJob.java
   
xwiki-platform/xwiki-plugins/trunk/scheduler/src/main/java/com/xpn/xwiki/plugin/scheduler/SchedulerPlugin.java
Log:
XASCH-16 : The scheduler should pass an unwrapped context to the jobs

Modified: 
xwiki-platform/xwiki-plugins/trunk/scheduler/src/main/java/com/xpn/xwiki/plugin/scheduler/GroovyJob.java
===================================================================
--- 
xwiki-platform/xwiki-plugins/trunk/scheduler/src/main/java/com/xpn/xwiki/plugin/scheduler/GroovyJob.java
    2008-02-25 15:17:56 UTC (rev 7931)
+++ 
xwiki-platform/xwiki-plugins/trunk/scheduler/src/main/java/com/xpn/xwiki/plugin/scheduler/GroovyJob.java
    2008-02-25 15:53:04 UTC (rev 7932)
@@ -19,6 +19,8 @@
  */
 package com.xpn.xwiki.plugin.scheduler;
 
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.doc.XWikiDocument;
 import com.xpn.xwiki.api.Context;
 import com.xpn.xwiki.objects.BaseObject;
 import groovy.lang.Binding;
@@ -46,26 +48,31 @@
      * XWiki context passed in the Quartz's Job execution context. The XWiki 
Task object is looked
      * for in the current document that was set in the context at the time the 
Job was scheduled.
      *
-     * @param context the Quartz execution context containing the XWiki 
context from which the
+     * @param jobContext the Quartz execution context containing the XWiki 
context from which the
      * script to execute is retrieved
      * @throws JobExecutionException if the script fails to execute or if the 
user didn't have
      * programming rights when the Job was scheduled
      * @see Job#execute(org.quartz.JobExecutionContext)
      */
-    public void execute(JobExecutionContext context) throws 
JobExecutionException
+    public void execute(JobExecutionContext jobContext) throws 
JobExecutionException
     {
         try {
-            JobDataMap data = context.getJobDetail().getJobDataMap();
+            JobDataMap data = jobContext.getJobDetail().getJobDataMap();
 
             // The XWiki context was saved in the Job execution data map. Get 
it as we'll retrieve
             // the script to execute from it.
-            Context xcontext = (Context) data.get("context");
+            XWikiContext context = (XWikiContext) data.get("context");         
   
 
-            if (xcontext.hasProgrammingRights()) {
+            // Get the job XObject to be executed
+            BaseObject object = (BaseObject) data.get("xjob");
 
-                // Get the job XObject to be executed
-                BaseObject object = (BaseObject) data.get("xjob");
+            // Force context document
+            XWikiDocument jobDocument = 
context.getWiki().getDocument(object.getName(), context);
+            context.setDoc(jobDocument);
+            context.put("sdoc", jobDocument);
 
+            if 
(context.getWiki().getRightService().hasProgrammingRights(context)) {
+
                 // Make the Job execution data available to the Groovy script
                 Binding binding = new Binding(data.getWrappedMap());
 
@@ -73,13 +80,13 @@
                 GroovyShell shell = new GroovyShell(binding);
                 shell.evaluate(object.getLargeStringValue("script"));
             } else {
-                throw new JobExecutionException("The user [" + 
xcontext.getUser() + "] didn't have "
-                    + "programming rights when the job [" + 
context.getJobDetail().getName()
+                throw new JobExecutionException("The user [" + 
context.getUser() + "] didn't have "
+                    + "programming rights when the job [" + 
jobContext.getJobDetail().getName()
                     + "] was scheduled.");
             }
         } catch (CompilationFailedException e) {
             throw new JobExecutionException("Failed to execute script for job 
["
-                + context.getJobDetail().getName() + "]", e, true);
+                + jobContext.getJobDetail().getName() + "]", e, true);
         }
         catch (Exception e) {
             e.printStackTrace();

Modified: 
xwiki-platform/xwiki-plugins/trunk/scheduler/src/main/java/com/xpn/xwiki/plugin/scheduler/SchedulerPlugin.java
===================================================================
--- 
xwiki-platform/xwiki-plugins/trunk/scheduler/src/main/java/com/xpn/xwiki/plugin/scheduler/SchedulerPlugin.java
      2008-02-25 15:17:56 UTC (rev 7931)
+++ 
xwiki-platform/xwiki-plugins/trunk/scheduler/src/main/java/com/xpn/xwiki/plugin/scheduler/SchedulerPlugin.java
      2008-02-25 15:53:04 UTC (rev 7932)
@@ -329,9 +329,8 @@
 
 // Let's prepare an execution context...
             XWikiContext stubContext = prepareJobStubContext(object, context);
-            Context stub = new Context(stubContext);
 
-            data.put("context", stub);
+            data.put("context", stubContext);
             data.put("xwiki", new com.xpn.xwiki.api.XWiki(context.getWiki(), 
stubContext));
             data.put("xjob", object);
 

_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications

Reply via email to