[jbpm-commits] JBoss JBPM SVN: r6556 - in jbpm4/trunk/modules: pvm/src/main/java/org/jbpm/pvm/internal/job and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Aug 9 13:22:14 EDT 2010


Author: swiderski.maciej
Date: 2010-08-09 13:22:14 -0400 (Mon, 09 Aug 2010)
New Revision: 6556

Added:
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/timer/StartProcessTimerTest.java
Modified:
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cal/Duration.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/TimerImpl.java
Log:
JBPM-2913: support for timer expressions on process level - event attached to process not an activity

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cal/Duration.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cal/Duration.java	2010-08-09 03:04:06 UTC (rev 6555)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cal/Duration.java	2010-08-09 17:22:14 UTC (rev 6556)
@@ -34,6 +34,7 @@
 import org.jbpm.api.JbpmException;
 import org.jbpm.pvm.internal.el.Expression;
 import org.jbpm.pvm.internal.env.EnvironmentImpl;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
 import org.jbpm.pvm.internal.util.Clock;
 
 /**
@@ -110,6 +111,10 @@
   }
 
   public static Date calculateDueDate(String durationExpression) {
+    return calculateDueDate(durationExpression, null);
+  }
+
+  public static Date calculateDueDate(String durationExpression, ExecutionImpl executionImpl) {
     Date duedate = null;
     if (durationExpression != null) {
 
@@ -120,7 +125,7 @@
       if (durationExpression.startsWith("#")) {
 
         String baseDateEL = durationExpression.substring(0, durationExpression.indexOf("}") + 1);
-        Object result = Expression.create(baseDateEL).evaluate();
+        Object result = Expression.create(baseDateEL).evaluate(executionImpl);
 
         if (result instanceof Date) {
           baseDate = (Date) result;
@@ -132,7 +137,7 @@
           if (endOfELIndex < (durationExpression.length() - 1)) {
             throw new JbpmException("Invalid duedate, didnot support + or - in String type EL.");
           }
-          durationString = (String) Expression.create(durationExpression, null).evaluate((Execution) null);
+          durationString = (String) Expression.create(durationExpression, null).evaluate(executionImpl);
         } else {
           throw new JbpmException("Invalid basedate type: " + baseDateEL + " is of type "
                   + result.getClass().getName()

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/TimerImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/TimerImpl.java	2010-08-09 03:04:06 UTC (rev 6555)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/TimerImpl.java	2010-08-09 17:22:14 UTC (rev 6556)
@@ -40,7 +40,7 @@
 
 /**
  * a runtime timer instance.
- * 
+ *
  * @author Tom Baeyens
  * @author Pascal Verdage
  * @author Alejandro Guizar
@@ -71,7 +71,7 @@
 
   public void setDueDateDescription(String dueDateDescription) {
     if (dueDateDescription != null) {
-      dueDate = Duration.calculateDueDate(dueDateDescription);
+      dueDate = Duration.calculateDueDate(dueDateDescription, this.execution);
     }
   }
 

Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/timer/StartProcessTimerTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/timer/StartProcessTimerTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/timer/StartProcessTimerTest.java	2010-08-09 17:22:14 UTC (rev 6556)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, !
 or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.test.timer;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.job.Job;
+import org.jbpm.api.listener.EventListener;
+import org.jbpm.api.listener.EventListenerExecution;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ *
+ * @author Maciej Swiderski
+ *
+ */
+public class StartProcessTimerTest  extends JbpmTestCase {
+
+
+
+  public void testTimerTimeout() {
+    deployJpdlXmlString(
+      "<process name='Insurance claim' key='ICL'>" +
+      "    <on event='timeout'>" +
+      "     <timer duedate='#{duedate}' />" +
+      "     <event-listener class='" + MyCustomEvent.class.getName() + "' />" +
+      "   </on>" +
+      "  <start>" +
+      "    <transition to='a' />" +
+      "  </start>" +
+      "  <state name='a'>" +
+      "    <transition to='b' />" +
+      "    <on event='timeout'>" +
+      "     <timer duedate='#{du!
 edate}' />" +
+      "     <event-listener class='" + MyCustom!
 Event.cl
ass.getName() + "' />" +
+      "   </on>" +
+      "  </state>" +
+      "  <state name='b' >" +
+      "    <transition to='escalate' />" +
+      "  </state>" +
+      "  <end name='escalate' />" +
+      "</process>"
+    );
+    Map<String, String> variables = new HashMap<String, String>();
+    variables.put("duedate", "24 business minutes");
+    ProcessInstance processInstance = executionService.startProcessInstanceByKey("ICL", variables, "82436");
+
+    List<Job> job = managementService.createJobQuery()
+      .processInstanceId(processInstance.getId())
+      .list();
+
+    assertEquals(2, job.size());
+
+    managementService.executeJob(job.get(0).getId());
+
+    managementService.executeJob(job.get(1).getId());
+
+    String executionId = processInstance.findActiveExecutionIn("a").getId();
+
+    processInstance = executionService.signalExecutionById(executionId);
+    executionService.signalExecutionById(processInstance.getId());
+
+    assertProcessInstanceE!
 nded(processInstance);
+  }
+
+  public static class MyCustomEvent implements EventListener {
+
+    private static final long serialVersionUID = 1L;
+
+    static int nrOfTimesCalled;
+
+    public void notify(EventListenerExecution execution) throws Exception {
+      nrOfTimesCalled++;
+    }
+  }
+
+}
\ No newline at end of file



More information about the jbpm-commits mailing list