[jbpm-commits] JBoss JBPM SVN: r6455 - in jbpm4/trunk/modules: test-db/src/test/java/org/jbpm/test/timer and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Sat Jul 3 20:43:32 EDT 2010


Author: rebody
Date: 2010-07-03 20:43:32 -0400 (Sat, 03 Jul 2010)
New Revision: 6455

Modified:
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cal/Duration.java
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/timer/TimerTest.java
Log:
JBPM-2900 let duedate support String type EL

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-07-03 13:07:34 UTC (rev 6454)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cal/Duration.java	2010-07-04 00:43:32 UTC (rev 6455)
@@ -30,6 +30,7 @@
 import java.util.Map;
 import java.util.regex.Pattern;
 
+import org.jbpm.api.Execution;
 import org.jbpm.api.JbpmException;
 import org.jbpm.pvm.internal.el.Expression;
 import org.jbpm.pvm.internal.env.EnvironmentImpl;
@@ -125,19 +126,28 @@
           baseDate = (Date) result;
         } else if (result instanceof Calendar) {
           baseDate = ((Calendar) result).getTime();
+        } else if (result instanceof String) {
+          baseDate = Clock.getTime();
+          int endOfELIndex = durationExpression.indexOf("}");
+          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);
         } else {
           throw new JbpmException("Invalid basedate type: " + baseDateEL + " is of type "
                   + result.getClass().getName()
                   + ". Only Date and Calendar are supported");
         }
 
-        int endOfELIndex = durationExpression.indexOf("}");
-        if (endOfELIndex < (durationExpression.length() - 1)) {
-          durationSeparator = durationExpression.substring(endOfELIndex + 1).trim().charAt(0);
-          if (durationSeparator != '+' && durationSeparator != '-') {
-            throw new JbpmException("Invalid duedate, + or - missing after EL");
+        if (durationString == null) {
+          int endOfELIndex = durationExpression.indexOf("}");
+          if (endOfELIndex < (durationExpression.length() - 1)) {
+            durationSeparator = durationExpression.substring(endOfELIndex + 1).trim().charAt(0);
+            if (durationSeparator != '+' && durationSeparator != '-') {
+              throw new JbpmException("Invalid duedate, + or - missing after EL");
+            }
+            durationString = durationExpression.substring(endOfELIndex + 1).substring(2).trim();
           }
-          durationString = durationExpression.substring(endOfELIndex + 1).substring(2).trim();
         }
 
       } else {

Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/timer/TimerTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/timer/TimerTest.java	2010-07-03 13:07:34 UTC (rev 6454)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/timer/TimerTest.java	2010-07-04 00:43:32 UTC (rev 6455)
@@ -23,6 +23,7 @@
 
 import java.util.Calendar;
 import java.util.Collections;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -40,9 +41,10 @@
  * @author Tom Baeyens
  * @author Ronald Van Kuijk
  * @author Joram Barrez
+ * @author Huisheng Xu
  */
 public class TimerTest extends JbpmTestCase {
-  
+
   private static final String TEST_PROCESS_CUSTOM =
     "<process name='Insurance claim' key='ICL'>" +
     "  <start>" +
@@ -81,14 +83,14 @@
     Job job = managementService.createJobQuery()
       .processInstanceId(processInstance.getId())
       .uniqueResult();
-    
+
     managementService.executeJob(job.getId());
     assertProcessInstanceEnded(processInstance);
   }
-  
+
   /**
    * Test case for https://jira.jboss.org/jira/browse/JBPM-2517
-   * 
+   *
    * In this issue, it is stated that the calculations for the timer
    * will overflow if larger than 4 weeks due to integer limitations.
    */
@@ -110,20 +112,20 @@
     );
 
     ProcessInstance processInstance = executionService.startProcessInstanceByKey("theProcess");
-    
+
     Calendar now = Calendar.getInstance();
     int currentYear = now.get(Calendar.YEAR);
 
     Job job = managementService.createJobQuery()
       .processInstanceId(processInstance.getId())
       .uniqueResult();
-    
+
     Calendar jobDate = Calendar.getInstance();
     jobDate.setTime(job.getDuedate());
-    
+
     assertEquals(currentYear + 10, jobDate.get(Calendar.YEAR));
   }
-  
+
   public void testTimerELDate() {
     deployJpdlXmlString(
       "<process name='Insurance claim' key='ICL'>" +
@@ -140,22 +142,22 @@
       "  <end name='escalate' />" +
       "</process>"
     );
-    
+
     Map<String, Object> proc_vars = new HashMap<String, Object>();
     Calendar cal = Calendar.getInstance();
     cal.add(Calendar.DAY_OF_MONTH, 6);
     proc_vars.put("proc_var", cal.getTime());
     ProcessInstance processInstance = executionService.startProcessInstanceByKey("ICL", proc_vars, "82436");
-    
+
     Job job = managementService.createJobQuery()
       .processInstanceId(processInstance.getId())
       .uniqueResult();
-	    
+
     Calendar jobDate = Calendar.getInstance();
     jobDate.setTime(job.getDuedate());
-	    
+
     assertEquals(cal.get(Calendar.DAY_OF_MONTH), jobDate.get(Calendar.DAY_OF_MONTH));
-	    
+
     managementService.executeJob(job.getId());
     assertProcessInstanceEnded(processInstance);
   }
@@ -176,26 +178,59 @@
       "  <end name='escalate' />" +
       "</process>"
     );
-	    
+
     Map<String, Object> proc_vars = new HashMap<String, Object>();
     Calendar cal = Calendar.getInstance();
     cal.add(Calendar.DAY_OF_MONTH, 6);
     proc_vars.put("proc_var", cal);
     ProcessInstance processInstance = executionService.startProcessInstanceByKey("ICL", proc_vars, "82436");
-	    
+
     Job job = managementService.createJobQuery()
       .processInstanceId(processInstance.getId())
       .uniqueResult();
-    
+
     Calendar jobDate = Calendar.getInstance();
     jobDate.setTime(job.getDuedate());
-    
+
     assertEquals(cal.get(Calendar.DAY_OF_MONTH), jobDate.get(Calendar.DAY_OF_MONTH));
-    
+
     managementService.executeJob(job.getId());
     assertProcessInstanceEnded(processInstance);
   }
-  
+
+  public void testTimerELString() {
+    deployJpdlXmlString(
+      "<process name='Insurance claim' key='ICL'>" +
+      "  <start>" +
+      "    <transition to='a' />" +
+      "  </start>" +
+      "  <state name='a'>" +
+      "    <transition to='b' />" +
+      "    <transition name='timeout' to='escalate'>" +
+      "      <timer duedate='#{proc_var}' />" +
+      "    </transition>" +
+      "  </state>" +
+      "  <state name='b' />" +
+      "  <end name='escalate' />" +
+      "</process>"
+    );
+
+    Map<String, Object> proc_vars = new HashMap<String, Object>();
+    proc_vars.put("proc_var", "2 minutes");
+
+    ProcessInstance processInstance = executionService.startProcessInstanceByKey("ICL", proc_vars, "82436");
+
+    Job job = managementService.createJobQuery()
+      .processInstanceId(processInstance.getId())
+      .uniqueResult();
+
+    Date jobDate = job.getDuedate();
+    assertTrue("should less than 2 minutes", jobDate.getTime() - new Date().getTime() <= 2 * 60 * 1000);
+
+    managementService.executeJob(job.getId());
+    assertProcessInstanceEnded(processInstance);
+  }
+
   public void testTimerELCalendarAdd() {
     deployJpdlXmlString(
       "<process name='Insurance claim' key='ICL'>" +
@@ -253,7 +288,7 @@
     Map<String, Object> proc_vars = new HashMap<String, Object>();
     Calendar cal = Calendar.getInstance();
     cal.add(Calendar.DAY_OF_MONTH, 6);
-    
+
     proc_vars.put("proc_var", cal);
     ProcessInstance processInstance = executionService.startProcessInstanceByKey("ICL", proc_vars, "82436");
 
@@ -325,7 +360,7 @@
       "  <end name='escalate' />" +
       "</process>"
     );
-	    
+
     Map<String, Object> proc_vars = new HashMap<String, Object>();
     proc_vars.put("proc_var", new Long(0));
     try {
@@ -360,7 +395,7 @@
       fail("Should not happen, exception expected");
     } catch (Exception e) {}
   }
-  
+
   public void testTimerELSubtractPastFail() {
     deployJpdlXmlString(
       "<process name='Insurance claim' key='ICL'>" +
@@ -417,19 +452,19 @@
   public void testTimerSignalCustom() {
     deployJpdlXmlString(TEST_PROCESS_CUSTOM);
     ProcessInstance processInstance = executionService.startProcessInstanceByKey("ICL");
-    
+
     Job async = managementService.createJobQuery().messages().processInstanceId(processInstance.getId()).uniqueResult();
     managementService.executeJob(async.getId());
-    
+
     int beforeTimer = MyCustomWait.nrOfTimesCalled;
     Job timer = managementService.createJobQuery().timers().processInstanceId(processInstance.getId()).uniqueResult();
     managementService.executeJob(timer.getId());
     int afterTimer = MyCustomWait.nrOfTimesCalled;
     assertEquals(beforeTimer + 1, afterTimer);
-    
+
     assertProcessInstanceEnded(processInstance);
   }
-  
+
   public void testTimerRepeat() {
     deployJpdlXmlString(
       "<process name='Insurance claim' key='ICL'>" +
@@ -455,26 +490,26 @@
     Job job = managementService.createJobQuery()
       .processInstanceId(processInstance.getId())
       .uniqueResult();
-    
+
     managementService.executeJob(job.getId());
-    
-    
+
+
     job = managementService.createJobQuery()
     .processInstanceId(processInstance.getId())
     .uniqueResult();
-  
+
     managementService.executeJob(job.getId());
-    
+
     processInstance = executionService.findProcessInstanceById(processInstance.getId());
     String processInstanceId = processInstance.findActiveExecutionIn("a").getId();
-  
+
     processInstance = executionService.signalExecutionById(processInstanceId);
-    
+
     processInstance = executionService.signalExecutionById(processInstance.getId());
-    
+
     assertProcessInstanceEnded(processInstance);
   }
-  
+
   public void testTimerELRepeat() {
     deployJpdlXmlString(
       "<process name='Insurance claim' key='ICL'>" +
@@ -501,30 +536,30 @@
     Job job = managementService.createJobQuery()
       .processInstanceId(processInstance.getId())
       .uniqueResult();
-    
+
     managementService.executeJob(job.getId());
-    
-    
+
+
     job = managementService.createJobQuery()
     .processInstanceId(processInstance.getId())
     .uniqueResult();
-  
+
     managementService.executeJob(job.getId());
-    
+
     processInstance = executionService.findProcessInstanceById(processInstance.getId());
     String processInstanceId = processInstance.findActiveExecutionIn("a").getId();
-  
+
     processInstance = executionService.signalExecutionById(processInstanceId);
-    
+
     processInstance = executionService.signalExecutionById(processInstance.getId());
-    
+
     assertProcessInstanceEnded(processInstance);
   }
 
   public static class MyCustomWait implements ExternalActivityBehaviour, EventListener {
 
     private static final long serialVersionUID = 1L;
-    
+
     static int nrOfTimesCalled;
 
     public void execute(ActivityExecution execution) throws Exception {



More information about the jbpm-commits mailing list