svn commit: r605258 - in /ofbiz/trunk/framework/service: servicedef/services.xml src/org/ofbiz/service/ServiceUtil.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r605258 - in /ofbiz/trunk/framework/service: servicedef/services.xml src/org/ofbiz/service/ServiceUtil.java

jaz-3
Author: jaz
Date: Tue Dec 18 09:12:58 2007
New Revision: 605258

URL: http://svn.apache.org/viewvc?rev=605258&view=rev
Log:
added new service to reset scheduled jobs

Modified:
    ofbiz/trunk/framework/service/servicedef/services.xml
    ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java

Modified: ofbiz/trunk/framework/service/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/servicedef/services.xml?rev=605258&r1=605257&r2=605258&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/servicedef/services.xml (original)
+++ ofbiz/trunk/framework/service/servicedef/services.xml Tue Dec 18 09:12:58 2007
@@ -53,6 +53,15 @@
         <auto-attributes entity-name="JobSandbox" include="pk" mode="IN" optional="false"/>        
     </service>
 
+    <service name="resetScheduledJob" engine="java"
+            location="org.ofbiz.service.ServiceUtil" invoke="resetJob" auth="true">
+        <description>Resets a stale job so it can be re-run</description>
+        <required-permissions join-type="AND">
+            <check-permission permission="SERVICE_INVOKE_ANY"/>
+        </required-permissions>
+        <auto-attributes entity-name="JobSandbox" include="pk" mode="IN" optional="false"/>
+    </service>
+
     <!-- Service Engine Interfaces -->
     <service name="permissionInterface" engine="interface">
         <description>Interface to describe base parameters for Permission Services</description>

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java?rev=605258&r1=605257&r2=605258&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java Tue Dec 18 09:12:58 2007
@@ -604,4 +604,45 @@
         }
         return UtilGenerics.checkMap(UtilMisc.toMap(args));
     }
+
+    public static Map resetJob(DispatchContext dctx, Map context) {
+        GenericDelegator delegator = dctx.getDelegator();
+        Security security = dctx.getSecurity();
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
+        Locale locale = getLocale(context);
+
+        if (!security.hasPermission("SERVICE_INVOKE_ANY", userLogin)) {
+            String errMsg = UtilProperties.getMessage(ServiceUtil.resource, "serviceUtil.no_permission_to_run", locale) + ".";
+            return ServiceUtil.returnError(errMsg);
+        }
+
+        String jobId = (String) context.get("jobId");
+        Map fields = UtilMisc.toMap("jobId", jobId);
+        GenericValue job;
+        try {
+            job = delegator.findByPrimaryKey("JobSandbox", fields);
+        } catch (GenericEntityException e) {
+            Debug.logError(e, module);
+            return ServiceUtil.returnError(e.getMessage());
+        }
+
+        // update the job
+        if (job != null) {
+            job.set("statusId", "SERVICE_PENDING");
+            job.set("startDateTime", null);
+            job.set("finishDateTime", null);
+            job.set("cancelDateTime", null);
+            job.set("runByInstanceId", null);
+
+            // save the job
+            try {
+                job.store();
+            } catch (GenericEntityException e) {
+                Debug.logError(e, module);
+                return ServiceUtil.returnError(e.getMessage());
+            }
+        }
+
+        return ServiceUtil.returnSuccess();
+    }
 }