[jbpm-commits] JBoss JBPM SVN: r5958 - in jbpm4/trunk/modules: pvm/src/main/java/org/jbpm/pvm/internal/history/events and 5 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Dec 15 04:41:08 EST 2009


Author: jbarrez
Date: 2009-12-15 04:41:08 -0500 (Tue, 15 Dec 2009)
New Revision: 5958

Added:
   jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/historysessionchain/
   jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/historysessionchain/DummyProcessEndListener.java
   jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/historysessionchain/DummyProcessStartListener.java
   jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/historysessionchain/HistorySessionChainTest.java
   jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/historysessionchain/
   jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/historysessionchain/jbpm.cfg.xml
Modified:
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/HistoryEvent.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/HistorySessionChain.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/ActivityEnd.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/DecisionEnd.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/ProcessInstanceMigration.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskActivityStart.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskAssign.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskComplete.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskCreated.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskDelete.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskUpdated.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/VariableCreate.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/VariableUpdate.java
   jbpm4/trunk/modules/pvm/src/main/resources/jbpm.wire.bindings.xml
Log:
JBPM-2576: extending HistorySession and introducing the HistorySessionChain

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/HistoryEvent.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/HistoryEvent.java	2009-12-12 08:41:58 UTC (rev 5957)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/HistoryEvent.java	2009-12-15 09:41:08 UTC (rev 5958)
@@ -22,6 +22,8 @@
 package org.jbpm.pvm.internal.history;
 
 import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.jbpm.pvm.internal.env.EnvironmentImpl;
 import org.jbpm.pvm.internal.model.ExecutionImpl;
@@ -55,11 +57,25 @@
   public static void fire(HistoryEvent historyEvent, ExecutionImpl execution) {
     EnvironmentImpl environment = EnvironmentImpl.getCurrent();
     if (environment!=null) {
+      
       HistorySession historySession = environment.get(HistorySession.class);
-      if (historySession!=null) {
+      HistorySessionChain historySessionChain = environment.get(HistorySessionChain.class);
+      
+      // Merge default history session (if defined) and the history session chain (if defined)
+      List<HistorySession> historySessions = new ArrayList<HistorySession>();
+      if (historySessionChain != null) {
+        historySessions.addAll(historySessionChain.getHistorySessionDelegates());
+      }
+      if (historySession != null) {
+        historySessions.add(historySession);
+      }
+      
+      // Delegate history event to all defined history sessions
+      for (HistorySession hs : historySessions) {
         historyEvent.setExecution(execution);
-        historySession.process(historyEvent);
+        hs.process(historyEvent);        
       }
+      
     }
   }
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/HistorySessionChain.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/HistorySessionChain.java	2009-12-12 08:41:58 UTC (rev 5957)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/HistorySessionChain.java	2009-12-15 09:41:08 UTC (rev 5958)
@@ -43,4 +43,9 @@
   public void addLogSession(HistorySession historySession) {
     delegates.add(historySession);
   }
+  
+  public List<HistorySession> getHistorySessionDelegates() {
+    return delegates;
+  }
+  
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/ActivityEnd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/ActivityEnd.java	2009-12-12 08:41:58 UTC (rev 5957)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/ActivityEnd.java	2009-12-15 09:41:08 UTC (rev 5958)
@@ -61,4 +61,9 @@
   protected Class<? extends HistoryActivityInstanceImpl> getHistoryActivityInstanceClass() {
     return HistoryActivityInstanceImpl.class;
   }
+  
+  public String getTransitionName() {
+    return transitionName;
+  }
+  
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/DecisionEnd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/DecisionEnd.java	2009-12-12 08:41:58 UTC (rev 5957)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/DecisionEnd.java	2009-12-15 09:41:08 UTC (rev 5958)
@@ -42,4 +42,9 @@
   protected HistoryActivityInstanceImpl createHistoryActivityInstance(HistoryProcessInstance historyProcessInstanceImpl) {
     return new HistoryDecisionInstanceImpl(historyProcessInstanceImpl, execution, transitionName);
   }
+
+  public String getTransitionName() {
+    return transitionName;
+  }
+  
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/ProcessInstanceMigration.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/ProcessInstanceMigration.java	2009-12-12 08:41:58 UTC (rev 5957)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/ProcessInstanceMigration.java	2009-12-15 09:41:08 UTC (rev 5958)
@@ -68,4 +68,13 @@
     
     dbSession.save(historyProcessInstanceMigration);
   }
+  
+  public ProcessInstance getProcessInstance() {
+    return processInstance;
+  }
+
+  public ProcessDefinition getProcessDefinition() {
+    return processDefinition;
+  }
+  
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskActivityStart.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskActivityStart.java	2009-12-12 08:41:58 UTC (rev 5957)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskActivityStart.java	2009-12-15 09:41:08 UTC (rev 5958)
@@ -69,4 +69,8 @@
     execution.setHistoryActivityInstanceDbid(historyActivityInstance.getDbid());
   }
 
+  public TaskImpl getTask() {
+    return task;
+  }
+
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskAssign.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskAssign.java	2009-12-12 08:41:58 UTC (rev 5957)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskAssign.java	2009-12-15 09:41:08 UTC (rev 5958)
@@ -48,4 +48,13 @@
         dbSession.get(HistoryTaskImpl.class, task.getDbid());
     historyTaskInstance.setAssignee(assignee);
   }
+  
+  public TaskImpl getTask() {
+    return task;
+  }
+
+  public String getAssignee() {
+    return assignee;
+  }
+  
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskComplete.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskComplete.java	2009-12-12 08:41:58 UTC (rev 5957)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskComplete.java	2009-12-15 09:41:08 UTC (rev 5958)
@@ -59,4 +59,9 @@
 
     session.update(historyTaskInstance);
   }
+
+  public String getOutcome() {
+    return outcome;
+  }
+  
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskCreated.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskCreated.java	2009-12-12 08:41:58 UTC (rev 5957)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskCreated.java	2009-12-15 09:41:08 UTC (rev 5958)
@@ -51,4 +51,9 @@
       superHistoryTask.addSubTask(historyTask);
     }
   }
+
+  public TaskImpl getTask() {
+    return task;
+  }
+  
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskDelete.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskDelete.java	2009-12-12 08:41:58 UTC (rev 5957)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskDelete.java	2009-12-15 09:41:08 UTC (rev 5958)
@@ -62,4 +62,13 @@
   protected Class<? extends HistoryActivityInstanceImpl> getHistoryActivityInstanceClass() {
     return HistoryTaskInstanceImpl.class;
   }
+  
+  public TaskImpl getTask() {
+    return task;
+  }
+
+  public String getReason() {
+    return reason;
+  }
+  
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskUpdated.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskUpdated.java	2009-12-12 08:41:58 UTC (rev 5957)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskUpdated.java	2009-12-15 09:41:08 UTC (rev 5958)
@@ -46,4 +46,9 @@
     HistoryTaskImpl historyTask = dbSession.get(HistoryTaskImpl.class, task.getDbid());
     historyTask.updated(task);
   }
+
+  public TaskImpl getTask() {
+    return task;
+  }
+  
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/VariableCreate.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/VariableCreate.java	2009-12-12 08:41:58 UTC (rev 5957)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/VariableCreate.java	2009-12-15 09:41:08 UTC (rev 5958)
@@ -69,4 +69,9 @@
     HistoryVariableImpl historyVariable = new HistoryVariableImpl(historyProcessInstance, historyTask, variable);
     dbSession.save(historyVariable);
   }
+
+  public Variable getVariable() {
+    return variable;
+  }
+  
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/VariableUpdate.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/VariableUpdate.java	2009-12-12 08:41:58 UTC (rev 5957)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/VariableUpdate.java	2009-12-15 09:41:08 UTC (rev 5958)
@@ -47,4 +47,9 @@
     HistoryVariableImpl historyVariable = dbSession.get(HistoryVariableImpl.class, variable.getDbid());
     historyVariable.updated(variable);
   }
+
+  public Variable getVariable() {
+    return variable;
+  }
+  
 }

Modified: jbpm4/trunk/modules/pvm/src/main/resources/jbpm.wire.bindings.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/resources/jbpm.wire.bindings.xml	2009-12-12 08:41:58 UTC (rev 5957)
+++ jbpm4/trunk/modules/pvm/src/main/resources/jbpm.wire.bindings.xml	2009-12-15 09:41:08 UTC (rev 5958)
@@ -50,6 +50,7 @@
   <binding class="org.jbpm.pvm.internal.wire.binding.MessageSessionBinding" />
   <binding class="org.jbpm.pvm.internal.wire.binding.TimerSessionBinding" />
   <binding class="org.jbpm.pvm.internal.wire.binding.HistorySessionBinding" />
+  <binding class="org.jbpm.pvm.internal.wire.binding.HistorySessionChainBinding" />
   <binding class="org.jbpm.pvm.internal.wire.binding.IdentitySessionBinding" />
   <binding class="org.jbpm.pvm.internal.wire.binding.JbossIdmIdentitySessionFactoryBinding" />
   <binding class="org.jbpm.pvm.internal.wire.binding.JbossIdmIdentitySessionBinding" />

Added: jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/historysessionchain/DummyProcessEndListener.java
===================================================================
--- jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/historysessionchain/DummyProcessEndListener.java	                        (rev 0)
+++ jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/historysessionchain/DummyProcessEndListener.java	2009-12-15 09:41:08 UTC (rev 5958)
@@ -0,0 +1,45 @@
+/*
+ * 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.historysessionchain;
+
+import org.jbpm.pvm.internal.history.HistoryEvent;
+import org.jbpm.pvm.internal.history.HistorySession;
+import org.jbpm.pvm.internal.history.events.ProcessInstanceEnd;
+
+/**
+ * @author Joram Barrez
+ */
+public class DummyProcessEndListener implements HistorySession {
+  
+  public static int nrOfProcessesEnded;
+
+  public void process(HistoryEvent historyEvent) {
+    if (historyEvent instanceof ProcessInstanceEnd) {
+      DummyProcessEndListener.nrOfProcessesEnded++;
+    }
+  }
+
+  public int getNrOfProcessesEnded() {
+    return DummyProcessEndListener.nrOfProcessesEnded;
+  }
+  
+}

Added: jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/historysessionchain/DummyProcessStartListener.java
===================================================================
--- jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/historysessionchain/DummyProcessStartListener.java	                        (rev 0)
+++ jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/historysessionchain/DummyProcessStartListener.java	2009-12-15 09:41:08 UTC (rev 5958)
@@ -0,0 +1,45 @@
+/*
+ * 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.historysessionchain;
+
+import org.jbpm.pvm.internal.history.HistoryEvent;
+import org.jbpm.pvm.internal.history.HistorySession;
+import org.jbpm.pvm.internal.history.events.ProcessInstanceCreate;
+
+/**
+ * @author Joram Barrez
+ */
+public class DummyProcessStartListener implements HistorySession {
+  
+  public static int nrOfProcessesStarted;
+  
+  public void process(HistoryEvent historyEvent) {
+    if (historyEvent instanceof ProcessInstanceCreate) {
+      DummyProcessStartListener.nrOfProcessesStarted++;
+    }
+  }
+
+  public int getNrOfProcessesStarted() {
+    return DummyProcessStartListener.nrOfProcessesStarted;
+  }  
+
+}

Added: jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/historysessionchain/HistorySessionChainTest.java
===================================================================
--- jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/historysessionchain/HistorySessionChainTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/historysessionchain/HistorySessionChainTest.java	2009-12-15 09:41:08 UTC (rev 5958)
@@ -0,0 +1,62 @@
+/*
+ * 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.historysessionchain;
+
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.test.JbpmCustomCfgTestCase;
+
+/**
+ * Simple test for the <history-session-chain> construct.
+ * Currently in this test, only the delegation to the custom
+ * history event listeners is tested.
+ * 
+ * @author Joram Barrez
+ */
+public class HistorySessionChainTest extends JbpmCustomCfgTestCase {
+  
+  private static final String TEST_PROCESS =
+    "<process name='testProcess'>" +
+    "  <start>" +
+    "    <transition to='wait' />" +
+    "  </start>" +
+    "  <state name='wait'>" +
+    "    <transition to='theEnd' />" +
+    "  </state>" +
+    "  <end name='theEnd' />" +
+    "</process>";
+  
+  public void testCustomHistoryEventListeners() {
+    deployJpdlXmlString(TEST_PROCESS);
+    ProcessInstance pi = executionService.startProcessInstanceByKey("testProcess");
+    
+    // After process start, the ProcessStartListener should have been notified
+    assertEquals(1, DummyProcessStartListener.nrOfProcessesStarted);
+    assertEquals(0, DummyProcessEndListener.nrOfProcessesEnded);
+    
+    // After process end the ProcessEndListener should have been notified
+    executionService.signalExecutionById(pi.findActiveExecutionIn("wait").getId());
+    assertProcessInstanceEnded(pi);
+    assertEquals(1, DummyProcessStartListener.nrOfProcessesStarted);
+    assertEquals(1, DummyProcessEndListener.nrOfProcessesEnded);
+  }
+
+}

Added: jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/historysessionchain/jbpm.cfg.xml
===================================================================
--- jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/historysessionchain/jbpm.cfg.xml	                        (rev 0)
+++ jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/historysessionchain/jbpm.cfg.xml	2009-12-15 09:41:08 UTC (rev 5958)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<jbpm-configuration>
+
+  <import resource="jbpm.default.cfg.xml" />
+  <import resource="jbpm.businesscalendar.cfg.xml" />
+  <import resource="jbpm.tx.hibernate.cfg.xml" />
+  <import resource="jbpm.jpdl.cfg.xml" />
+  <import resource="jbpm.bpmn.cfg.xml" />
+  <import resource="jbpm.identity.cfg.xml" />
+  
+  <transaction-context>
+    <history-session-chain>
+      <object class="org.jbpm.test.historysessionchain.DummyProcessStartListener" />
+      <object class="org.jbpm.test.historysessionchain.DummyProcessEndListener" />
+    </history-session-chain>
+  </transaction-context>
+
+</jbpm-configuration>



More information about the jbpm-commits mailing list