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

do-not-reply at jboss.org do-not-reply at jboss.org
Tue May 25 12:18:06 EDT 2010


Author: swiderski.maciej
Date: 2010-05-25 12:18:06 -0400 (Tue, 25 May 2010)
New Revision: 6375

Added:
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkJoinWithMutliplicityTest.java
Modified:
   jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinActivity.java
   jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinBinding.java
Log:
JBPM-2720: ends forked (but not joined) executions when multiplicity attribute on join activity is used, contains support for expression in multiplicity attribute of join node

Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinActivity.java	2010-05-25 03:45:03 UTC (rev 6374)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinActivity.java	2010-05-25 16:18:06 UTC (rev 6375)
@@ -31,6 +31,7 @@
 import org.jbpm.api.activity.ActivityExecution;
 import org.jbpm.api.model.Activity;
 import org.jbpm.api.model.Transition;
+import org.jbpm.pvm.internal.el.Expression;
 import org.jbpm.pvm.internal.env.EnvironmentImpl;
 import org.jbpm.pvm.internal.model.ExecutionImpl;
 
@@ -44,6 +45,7 @@
   
   int multiplicity = -1;
   LockMode lockMode = LockMode.UPGRADE;
+  Expression multiplicityExpression;
 
   public void execute(ActivityExecution execution) {
     execute((ExecutionImpl)execution);
@@ -52,6 +54,15 @@
   public void execute(ExecutionImpl execution) {
     Activity activity = execution.getActivity();
     
+    // evaluate multiplicity expression
+    if (multiplicityExpression != null) {
+      try {
+        multiplicity = Integer.valueOf(multiplicityExpression.evaluate(execution).toString());
+      } catch (Exception e) {
+        throw new JbpmException("Problem while evaluating multiplicity attribute: " + e.getMessage());
+      }
+    }
+    
     // if this is a single, non concurrent root
     if (Execution.STATE_ACTIVE_ROOT.equals(execution.getState())) {
       // just pass through
@@ -75,7 +86,19 @@
       
       if (isComplete(joinedExecutions, activity)) {
         endJoinedExecutions(joinedExecutions);
-
+        
+        if (multiplicity != -1) {
+          // remove forked but not joined executions only when multiplicity attribute was used
+          List<ExecutionImpl> forkedExecutionsToRemove = new ArrayList<ExecutionImpl>();
+          for (ExecutionImpl concurrentExecution : concurrentRoot.getExecutions()) {
+            //collect all executions from the parent that are forked
+            if ( (Execution.STATE_ACTIVE_CONCURRENT.equals(concurrentExecution.getState()))) {
+              forkedExecutionsToRemove.add(concurrentExecution);
+            }
+          }
+          // end all of found forked (but not joined) executions
+          endJoinedExecutions(forkedExecutionsToRemove);
+        }
         ExecutionImpl outgoingExecution = null;
         if (concurrentRoot.getExecutions().size()==0) {
           outgoingExecution = concurrentRoot;
@@ -125,10 +148,10 @@
     }
   }
 
-  public void setMultiplicity(int multiplicity) {
-    this.multiplicity = multiplicity;
-  }
   public void setLockMode(LockMode lockMode) {
     this.lockMode = lockMode;
+  }  
+  public void setMultiplicityExpression(Expression multiplicityExpression) {
+    this.multiplicityExpression = multiplicityExpression;
   }
 }

Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinBinding.java	2010-05-25 03:45:03 UTC (rev 6374)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinBinding.java	2010-05-25 16:18:06 UTC (rev 6375)
@@ -23,6 +23,7 @@
 
 import org.hibernate.LockMode;
 import org.jbpm.jpdl.internal.xml.JpdlParser;
+import org.jbpm.pvm.internal.el.Expression;
 import org.jbpm.pvm.internal.xml.Parse;
 import org.w3c.dom.Element;
 
@@ -45,12 +46,8 @@
                             
     if (element.hasAttribute(MULTIPLICITY)) {
       String multiplicictyText = element.getAttribute(MULTIPLICITY);
-      try {
-        int multiplicity = Integer.parseInt(multiplicictyText);
-        joinActivity.setMultiplicity(multiplicity);
-      } catch (NumberFormatException e) {
-        parse.addProblem(MULTIPLICITY + " " + multiplicictyText + " is not a valid integer", element);
-      }
+      Expression expression = Expression.create(multiplicictyText, Expression.LANGUAGE_UEL_VALUE);
+      joinActivity.setMultiplicityExpression(expression);
     }
 
     if (element.hasAttribute(LOCKMODE)) {

Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkJoinWithMutliplicityTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkJoinWithMutliplicityTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkJoinWithMutliplicityTest.java	2010-05-25 16:18:06 UTC (rev 6375)
@@ -0,0 +1,138 @@
+/*
+ * 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.activity.forkjoin;
+
+import java.util.HashMap;
+
+import org.jbpm.api.Execution;
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.history.HistoryProcessInstance;
+import org.jbpm.api.task.Task;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ * 
+ * @author Maciej Swiderski
+ *
+ */
+public class ForkJoinWithMutliplicityTest extends JbpmTestCase {
+
+  public void testForkWithMultiplicityOne() {
+    deployJpdlXmlString(""
+        + "<process name='ForkJoingMultiplicity' xmlns='http://jbpm.org/4.3/jpdl'>"
+        + "   <start g='179,17,32,29' name='start1'>"
+        + "      <transition g='-43,-18' name='to fork1' to='fork1'/>"
+        + "   </start>"
+        + "   <fork g='185,95,49,50' name='fork1' >"
+        + "      <transition name='left' to='task1' g='-44,-18'/>"
+        + "      <transition name='right' to='task2' g='-44,-18'/>"
+        + "   </fork>"
+        + "   <task name='task1' g='90,177,73,44' assignee='mike'>"
+        + "      <transition name='to join1' to='join1' g='-43,-18'/>"
+        + "   </task>"
+        + "   <task name='task2' g='90,177,73,44' assignee='alex'>"
+        + "      <transition name='to join1' to='join1' g='-43,-18'/>"
+        + "   </task>"
+        + "   <join name='join1' g='192,511,57,44' multiplicity='1'>"
+        + "      <transition name='to Big car' to='Big car' g='-42,-18'/>"
+        + "   </join>"
+        + "   <state name='Big car' > "
+        + "     <transition name='to end1' to='end1' g='-43,-18'/>"
+        + "   </state> "
+        + "   <end g='193,606,38,33' name='end1'/>"
+        + "</process>");
+
+    ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForkJoingMultiplicity");
+    
+    Task taskAlex = taskService.createTaskQuery().assignee("alex").uniqueResult();
+    assertNotNull(taskAlex);
+    assertEquals("task2", taskAlex.getActivityName());
+    
+    taskService.completeTask(taskAlex.getId());
+    
+    processInstance = executionService.findProcessInstanceById(processInstance.getId());
+
+
+    executionService.signalExecutionById(processInstance.getId());
+    
+
+    HistoryProcessInstance history = historyService
+        .createHistoryProcessInstanceQuery()
+        .processInstanceId(processInstance.getId())
+        .uniqueResult();
+
+    assertNotNull(history);
+    assertEquals(ProcessInstance.STATE_ENDED, history.getState());
+    assertEquals("end1", history.getEndActivityName());
+  }
+  
+  public void testForkWithMultiplicityAsExpression() {
+    deployJpdlXmlString(""
+        + "<process name='ForkJoingMultiplicity' xmlns='http://jbpm.org/4.3/jpdl'>"
+        + "   <start g='179,17,32,29' name='start1'>"
+        + "      <transition g='-43,-18' name='to fork1' to='fork1'/>"
+        + "   </start>"
+        + "   <fork g='185,95,49,50' name='fork1' >"
+        + "      <transition name='left' to='task1' g='-44,-18'/>"
+        + "      <transition name='right' to='task2' g='-44,-18'/>"
+        + "   </fork>"
+        + "   <task name='task1' g='90,177,73,44' assignee='mike'>"
+        + "      <transition name='to join1' to='join1' g='-43,-18'/>"
+        + "   </task>"
+        + "   <task name='task2' g='90,177,73,44' assignee='alex'>"
+        + "      <transition name='to join1' to='join1' g='-43,-18'/>"
+        + "   </task>"
+        + "   <join name='join1' g='192,511,57,44' multiplicity='#{multiplicity}'>"
+        + "      <transition name='to Big car' to='Big car' g='-42,-18'/>"
+        + "   </join>"
+        + "   <state name='Big car' > "
+        + "     <transition name='to end1' to='end1' g='-43,-18'/>"
+        + "   </state> "
+        + "   <end g='193,606,38,33' name='end1'/>"
+        + "</process>");
+
+    HashMap<String, Integer> variables = new HashMap<String, Integer>();
+    variables.put("multiplicity", 1);
+    ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForkJoingMultiplicity", variables);
+    
+    Task taskAlex = taskService.createTaskQuery().assignee("alex").uniqueResult();
+    assertNotNull(taskAlex);
+    assertEquals("task2", taskAlex.getActivityName());
+    
+    taskService.completeTask(taskAlex.getId());
+    
+    processInstance = executionService.findProcessInstanceById(processInstance.getId());
+
+
+    executionService.signalExecutionById(processInstance.getId());
+    
+
+    HistoryProcessInstance history = historyService
+        .createHistoryProcessInstanceQuery()
+        .processInstanceId(processInstance.getId())
+        .uniqueResult();
+
+    assertNotNull(history);
+    assertEquals(ProcessInstance.STATE_ENDED, history.getState());
+    assertEquals("end1", history.getEndActivityName());
+  }
+}



More information about the jbpm-commits mailing list