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

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Jul 6 16:37:12 EDT 2010


Author: swiderski.maciej
Date: 2010-07-06 16:37:11 -0400 (Tue, 06 Jul 2010)
New Revision: 6465

Modified:
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryVariableImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariableTest.java
Log:
JBPM-2506: fix for updating history variables when execution variable is updated

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryVariableImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryVariableImpl.java	2010-07-06 06:46:35 UTC (rev 6464)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryVariableImpl.java	2010-07-06 20:37:11 UTC (rev 6465)
@@ -75,6 +75,7 @@
     if ( (value==null && newValue!=null)
          || (value!=null && (!value.equals(newValue)))
        ) {
+      this.value = newValue;
       addDetail(new HistoryVariableUpdateImpl(value, newValue));
     }
   }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java	2010-07-06 06:46:35 UTC (rev 6464)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java	2010-07-06 20:37:11 UTC (rev 6465)
@@ -82,6 +82,11 @@
       if (!converter.supports(value, scopeInstance, this)) {
         throw new JbpmException("the converter '"+converter.getClass().getName()+"' in variable instance '"+this.getClass().getName()+"' does not support values of type '"+value.getClass().getName()+"'.  to change the type of a variable, you have to delete it first");
       }
+      // default set of text value required for BlobVariable to be set before converting
+      // for other types will be reset by setObject method
+      if (value != null) {
+        this.textValue = value.toString();
+      }
       value = converter.convert(value, scopeInstance, this);
     }
     if (value!=null && !isStorable(value)) {

Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariableTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariableTest.java	2010-07-06 06:46:35 UTC (rev 6464)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariableTest.java	2010-07-06 20:37:11 UTC (rev 6465)
@@ -7,6 +7,9 @@
 import java.util.Set;
 
 import org.jbpm.api.JbpmException;
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.listener.EventListener;
+import org.jbpm.api.listener.EventListenerExecution;
 import org.jbpm.test.JbpmTestCase;
 
 public class HistoryVariableTest extends JbpmTestCase {
@@ -264,4 +267,165 @@
         assertEquals("variableNames is null", e.getMessage());
       }
     }
+
+  public void testDeclaredVariableWithHistoryAndUpdateBySignal() {
+    deployJpdlXmlString("<process name='var'>"
+      + " <variable name='test' type='integer' init-expr='#{testV}' history='true'/>"
+      + "  <start name='a'>"
+      + "    <transition to='b' />"
+      + "  </start>"
+      + "  <state name='b'>"
+      + "    <transition to='c' />"
+      + "  </state>"
+      + "  <state name='c'/>"
+      + "</process>");
+
+    Map<String, ?> vars = Collections.singletonMap("testV", 35);
+    ProcessInstance pi = executionService.startProcessInstanceByKey("var", vars, "one");
+
+    Set<String> variableNames = executionService.getVariableNames("var.one");
+    assertEquals(2, variableNames.size());
+    assertEquals("test", variableNames.iterator().next());
+
+    Integer executionValue = (Integer) executionService.getVariable("var.one", "test");
+    assertEquals(35, executionValue.intValue());
+    
+    // signal to next state
+    executionService.signalExecutionById(pi.getId(), Collections.singletonMap("test", 55));
+
+    Set<String> historyVariables = historyService.getVariableNames("var.one");
+    assertEquals(1, historyVariables.size());
+    assertEquals("test", historyVariables.iterator().next());
+
+    String historyValue = (String) historyService.getVariable("var.one", "test");
+    assertEquals("55", historyValue);
+    }
+  
+  public void testDeclaredVariableWithHistoryAndUpdateByExecService() {
+    deployJpdlXmlString("<process name='var'>"
+      + " <variable name='test' type='integer' init-expr='#{testV}' history='true'/>"
+      + "  <start name='a'>"
+      + "    <transition to='b' />"
+      + "  </start>"
+      + "  <state name='b'>"
+      + "    <transition to='c' />"
+      + "  </state>"
+      + "  <state name='c'/>"
+      + "</process>");
+
+    Map<String, ?> vars = Collections.singletonMap("testV", 35);
+    ProcessInstance pi = executionService.startProcessInstanceByKey("var", vars, "one");
+
+    Set<String> variableNames = executionService.getVariableNames("var.one");
+    assertEquals(2, variableNames.size());
+    assertEquals("test", variableNames.iterator().next());
+
+    Integer executionValue = (Integer) executionService.getVariable("var.one", "test");
+    assertEquals(35, executionValue.intValue());
+    
+    executionService.setVariable(pi.getId(), "test", 55);
+    
+    // signal to next state
+    executionService.signalExecutionById(pi.getId());
+
+    Set<String> historyVariables = historyService.getVariableNames("var.one");
+    assertEquals(1, historyVariables.size());
+    assertEquals("test", historyVariables.iterator().next());
+
+    String historyValue = (String) historyService.getVariable("var.one", "test");
+    assertEquals("55", historyValue);
+  }
+  
+  public void testDeclaredSerializableVariableWithHistoryAndUpdateByExecService() {
+    deployJpdlXmlString("<process name='var'>"
+      + "  <variable name='test' type='serializable' history='true'>"
+      + "    <object class='"+SetVariableListener.class.getName()+"'>"
+      + "    </object>"
+      + "  </variable>"
+      + "  <start name='a'>"
+      + "    <transition to='b' />"
+      + "  </start>"
+      + "  <state name='b'>"
+      + "    <transition to='c' />"
+      + "  </state>"
+      + "  <state name='c'/>"
+      + "</process>");
+
+    Map<String, ?> vars = Collections.singletonMap("testV", 35);
+    ProcessInstance pi = executionService.startProcessInstanceByKey("var", vars, "one");
+
+    Set<String> variableNames = executionService.getVariableNames("var.one");
+    assertEquals(2, variableNames.size());
+    assertEquals("test", variableNames.iterator().next());
+
+    SetVariableListener executionValue = (SetVariableListener) executionService.getVariable("var.one", "test");
+    assertEquals("test value", executionValue.toString());
+    SetVariableListener newInstance = new SetVariableListener();
+    newInstance.setSimpleValue("value test");
+    executionService.setVariable(pi.getId(), "test", newInstance);
+    
+    // signal to next state
+    executionService.signalExecutionById(pi.getId());
+
+    Set<String> historyVariables = historyService.getVariableNames("var.one");
+    assertEquals(1, historyVariables.size());
+    assertEquals("test", historyVariables.iterator().next());
+
+    String historyValue = (String) historyService.getVariable("var.one", "test");
+    assertEquals("value test", historyValue);
+  }
+  
+  public void testDeclaredVariableWithHistoryAndUpdateByEvent() {
+    deployJpdlXmlString("<process name='var'>"
+      + " <variable name='test' type='integer' init-expr='#{testV}' history='true'/>"
+      + "  <start name='a'>"
+      + "    <transition to='b' />"
+      + "  </start>"
+      + "  <state name='b'>"
+      + "    <on event='end'>"
+      + "      <event-listener class='"+SetVariableListener.class.getName()+"' />" 
+      + "    </on>" 
+      + "    <transition to='c' />"
+      + "  </state>"
+      + "  <state name='c'/>"
+      + "</process>");
+
+    Map<String, ?> vars = Collections.singletonMap("testV", 35);
+    ProcessInstance pi = executionService.startProcessInstanceByKey("var", vars, "one");
+
+    Set<String> variableNames = executionService.getVariableNames("var.one");
+    assertEquals(2, variableNames.size());
+    assertEquals("test", variableNames.iterator().next());
+
+    Integer executionValue = (Integer) executionService.getVariable("var.one", "test");
+    assertEquals(35, executionValue.intValue());
+    
+    // signal to next state
+    executionService.signalExecutionById(pi.getId());
+
+    Set<String> historyVariables = historyService.getVariableNames("var.one");
+    assertEquals(1, historyVariables.size());
+    assertEquals("test", historyVariables.iterator().next());
+
+    String historyValue = (String) historyService.getVariable("var.one", "test");
+    assertEquals("55", historyValue);
+    }
+  
+  public static class SetVariableListener implements EventListener {
+    private static final long serialVersionUID = 1L;
+    private String simpleValue = "test value";
+    public void notify(EventListenerExecution execution) {
+      execution.setVariable("test", 55);
+    }
+    
+    public void setSimpleValue(String value) {
+      this.simpleValue = value;
+    }
+    
+    public String toString() {
+      return this.simpleValue;
+    }
+  }
+  
+  
 }



More information about the jbpm-commits mailing list