mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Integrate jBPM engine into the Alfresco Spring Context - .jars, beans, db connections & transactions.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3318 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
<import resource="classpath:alfresco/authentication-services-context.xml" />
|
||||
<import resource="classpath:alfresco/policy-context.xml" />
|
||||
<import resource="classpath:alfresco/import-export-context.xml" />
|
||||
<import resource="classpath:alfresco/workflow-context.xml" />
|
||||
<import resource="classpath:alfresco/bootstrap-context.xml" />
|
||||
<import resource="classpath:alfresco/jcr-api-context.xml" />
|
||||
<import resource="classpath*:alfresco/patch/*-context.xml" />
|
||||
|
@@ -32,11 +32,107 @@
|
||||
<bean id="sessionFactoryBase" abstract="true">
|
||||
<property name="mappingResources">
|
||||
<list>
|
||||
<!-- -->
|
||||
<!-- Alfresco Node Storage -->
|
||||
<!-- -->
|
||||
|
||||
<value>org/alfresco/repo/domain/hibernate/Node.hbm.xml</value>
|
||||
<value>org/alfresco/repo/domain/hibernate/Store.hbm.xml</value>
|
||||
<value>org/alfresco/repo/domain/hibernate/VersionCount.hbm.xml</value>
|
||||
<value>org/alfresco/repo/domain/hibernate/AppliedPatch.hbm.xml</value>
|
||||
<value>org/alfresco/repo/domain/hibernate/Permission.hbm.xml</value>
|
||||
|
||||
<!-- -->
|
||||
<!-- JBoss jBPM Workflow Engine -->
|
||||
<!-- -->
|
||||
<!-- TODO: Determine if it's possible to inject the following mappings -->
|
||||
<!-- from elsewhere -->
|
||||
<!-- -->
|
||||
<value>org/jbpm/graph/action/Script.hbm.xml</value>
|
||||
<value>org/jbpm/db/hibernate.queries.hbm.xml</value>
|
||||
<value>org/jbpm/graph/def/ProcessDefinition.hbm.xml</value>
|
||||
<value>org/jbpm/graph/def/Node.hbm.xml</value>
|
||||
<value>org/jbpm/graph/def/Transition.hbm.xml</value>
|
||||
<value>org/jbpm/graph/def/Event.hbm.xml</value>
|
||||
<value>org/jbpm/graph/def/Action.hbm.xml</value>
|
||||
<value>org/jbpm/graph/def/SuperState.hbm.xml</value>
|
||||
<value>org/jbpm/graph/def/ExceptionHandler.hbm.xml</value>
|
||||
<value>org/jbpm/instantiation/Delegation.hbm.xml</value>
|
||||
<value>org/jbpm/graph/node/StartState.hbm.xml</value>
|
||||
<value>org/jbpm/graph/node/EndState.hbm.xml</value>
|
||||
<value>org/jbpm/graph/node/ProcessState.hbm.xml</value>
|
||||
<value>org/jbpm/graph/node/Decision.hbm.xml</value>
|
||||
<value>org/jbpm/graph/node/Fork.hbm.xml</value>
|
||||
<value>org/jbpm/graph/node/Join.hbm.xml</value>
|
||||
<value>org/jbpm/graph/node/State.hbm.xml</value>
|
||||
<value>org/jbpm/graph/node/TaskNode.hbm.xml</value>
|
||||
<value>org/jbpm/context/def/ContextDefinition.hbm.xml</value>
|
||||
<value>org/jbpm/context/def/VariableAccess.hbm.xml</value>
|
||||
<value>org/jbpm/taskmgmt/def/TaskMgmtDefinition.hbm.xml</value>
|
||||
<value>org/jbpm/taskmgmt/def/Swimlane.hbm.xml</value>
|
||||
<value>org/jbpm/taskmgmt/def/Task.hbm.xml</value>
|
||||
<value>org/jbpm/taskmgmt/def/TaskController.hbm.xml</value>
|
||||
<value>org/jbpm/module/def/ModuleDefinition.hbm.xml</value>
|
||||
<value>org/jbpm/bytes/ByteArray.hbm.xml</value>
|
||||
<value>org/jbpm/file/def/FileDefinition.hbm.xml</value>
|
||||
<value>org/jbpm/scheduler/def/CreateTimerAction.hbm.xml</value>
|
||||
<value>org/jbpm/scheduler/def/CancelTimerAction.hbm.xml</value>
|
||||
<value>org/jbpm/graph/exe/Comment.hbm.xml</value>
|
||||
<value>org/jbpm/graph/exe/ProcessInstance.hbm.xml</value>
|
||||
<value>org/jbpm/graph/exe/Token.hbm.xml</value>
|
||||
<value>org/jbpm/graph/exe/RuntimeAction.hbm.xml</value>
|
||||
<value>org/jbpm/module/exe/ModuleInstance.hbm.xml</value>
|
||||
<value>org/jbpm/context/exe/ContextInstance.hbm.xml</value>
|
||||
<value>org/jbpm/context/exe/TokenVariableMap.hbm.xml</value>
|
||||
<value>org/jbpm/context/exe/VariableInstance.hbm.xml</value>
|
||||
<value>org/jbpm/context/exe/variableinstance/ByteArrayInstance.hbm.xml</value>
|
||||
<value>org/jbpm/context/exe/variableinstance/DateInstance.hbm.xml</value>
|
||||
<value>org/jbpm/context/exe/variableinstance/DoubleInstance.hbm.xml</value>
|
||||
<value>org/jbpm/context/exe/variableinstance/HibernateLongInstance.hbm.xml</value>
|
||||
<value>org/jbpm/context/exe/variableinstance/HibernateStringInstance.hbm.xml</value>
|
||||
<value>org/jbpm/context/exe/variableinstance/LongInstance.hbm.xml</value>
|
||||
<value>org/jbpm/context/exe/variableinstance/NullInstance.hbm.xml</value>
|
||||
<value>org/jbpm/context/exe/variableinstance/StringInstance.hbm.xml</value>
|
||||
<value>org/jbpm/msg/Message.hbm.xml</value>
|
||||
<value>org/jbpm/msg/db/TextMessage.hbm.xml</value>
|
||||
<value>org/jbpm/command/ExecuteActionCommand.hbm.xml</value>
|
||||
<value>org/jbpm/command/ExecuteNodeCommand.hbm.xml</value>
|
||||
<value>org/jbpm/command/SignalCommand.hbm.xml</value>
|
||||
<value>org/jbpm/command/TaskInstanceEndCommand.hbm.xml</value>
|
||||
<value>org/jbpm/taskmgmt/exe/TaskMgmtInstance.hbm.xml</value>
|
||||
<value>org/jbpm/taskmgmt/exe/TaskInstance.hbm.xml</value>
|
||||
<value>org/jbpm/taskmgmt/exe/PooledActor.hbm.xml</value>
|
||||
<value>org/jbpm/taskmgmt/exe/SwimlaneInstance.hbm.xml</value>
|
||||
<value>org/jbpm/scheduler/exe/Timer.hbm.xml</value>
|
||||
<value>org/jbpm/logging/log/ProcessLog.hbm.xml</value>
|
||||
<value>org/jbpm/logging/log/MessageLog.hbm.xml</value>
|
||||
<value>org/jbpm/logging/log/CompositeLog.hbm.xml</value>
|
||||
<value>org/jbpm/graph/log/ActionLog.hbm.xml</value>
|
||||
<value>org/jbpm/graph/log/NodeLog.hbm.xml</value>
|
||||
<value>org/jbpm/graph/log/ProcessInstanceCreateLog.hbm.xml</value>
|
||||
<value>org/jbpm/graph/log/ProcessInstanceEndLog.hbm.xml</value>
|
||||
<value>org/jbpm/graph/log/SignalLog.hbm.xml</value>
|
||||
<value>org/jbpm/graph/log/TokenCreateLog.hbm.xml</value>
|
||||
<value>org/jbpm/graph/log/TokenEndLog.hbm.xml</value>
|
||||
<value>org/jbpm/graph/log/TransitionLog.hbm.xml</value>
|
||||
<value>org/jbpm/context/log/VariableLog.hbm.xml</value>
|
||||
<value>org/jbpm/context/log/VariableCreateLog.hbm.xml</value>
|
||||
<value>org/jbpm/context/log/VariableDeleteLog.hbm.xml</value>
|
||||
<value>org/jbpm/context/log/VariableUpdateLog.hbm.xml</value>
|
||||
<value>org/jbpm/context/log/variableinstance/ByteArrayUpdateLog.hbm.xml</value>
|
||||
<value>org/jbpm/context/log/variableinstance/DateUpdateLog.hbm.xml</value>
|
||||
<value>org/jbpm/context/log/variableinstance/DoubleUpdateLog.hbm.xml</value>
|
||||
<value>org/jbpm/context/log/variableinstance/HibernateLongUpdateLog.hbm.xml</value>
|
||||
<value>org/jbpm/context/log/variableinstance/HibernateStringUpdateLog.hbm.xml</value>
|
||||
<value>org/jbpm/context/log/variableinstance/LongUpdateLog.hbm.xml</value>
|
||||
<value>org/jbpm/context/log/variableinstance/StringUpdateLog.hbm.xml</value>
|
||||
<value>org/jbpm/taskmgmt/log/TaskLog.hbm.xml</value>
|
||||
<value>org/jbpm/taskmgmt/log/TaskCreateLog.hbm.xml</value>
|
||||
<value>org/jbpm/taskmgmt/log/TaskAssignLog.hbm.xml</value>
|
||||
<value>org/jbpm/taskmgmt/log/TaskEndLog.hbm.xml</value>
|
||||
<value>org/jbpm/taskmgmt/log/SwimlaneLog.hbm.xml</value>
|
||||
<value>org/jbpm/taskmgmt/log/SwimlaneCreateLog.hbm.xml</value>
|
||||
<value>org/jbpm/taskmgmt/log/SwimlaneAssignLog.hbm.xml</value>
|
||||
</list>
|
||||
</property>
|
||||
<property name="hibernateProperties" ref="hibernateConfigProperties" />
|
||||
|
17
config/alfresco/workflow-context.xml
Normal file
17
config/alfresco/workflow-context.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
|
||||
|
||||
<beans>
|
||||
|
||||
<!-- jBPM configuration -->
|
||||
<bean id="jbpmConfiguration" class="org.springmodules.workflow.jbpm31.LocalJbpmConfigurationFactoryBean">
|
||||
<property name="sessionFactory" ref="sessionFactory"/>
|
||||
<property name="configuration" value="classpath:org/jbpm/default.jbpm.cfg.xml"/>
|
||||
</bean>
|
||||
|
||||
<!-- jBPM template -->
|
||||
<bean id="jbpmTemplate" class="org.springmodules.workflow.jbpm31.JbpmTemplate">
|
||||
<constructor-arg index="0" ref="jbpmConfiguration"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
187
source/java/org/alfresco/repo/workflow/jbpm/JBPMSpringTest.java
Normal file
187
source/java/org/alfresco/repo/workflow/jbpm/JBPMSpringTest.java
Normal file
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.workflow.jbpm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.util.BaseSpringTest;
|
||||
import org.jbpm.JbpmContext;
|
||||
import org.jbpm.db.GraphSession;
|
||||
import org.jbpm.graph.def.ProcessDefinition;
|
||||
import org.jbpm.graph.exe.ProcessInstance;
|
||||
import org.jbpm.graph.exe.Token;
|
||||
import org.springmodules.workflow.jbpm31.JbpmCallback;
|
||||
import org.springmodules.workflow.jbpm31.JbpmTemplate;
|
||||
|
||||
|
||||
/**
|
||||
* Test Usage of jBPM within Alfresco Spring Context
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class JBPMSpringTest extends BaseSpringTest
|
||||
{
|
||||
private JbpmTemplate jbpmTemplate;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onSetUpInTransaction() throws Exception
|
||||
{
|
||||
jbpmTemplate = (JbpmTemplate)applicationContext.getBean("jbpmTemplate");
|
||||
}
|
||||
|
||||
|
||||
public void testHelloWorld()
|
||||
throws Exception
|
||||
{
|
||||
// Between the 3 method calls below, all data is passed via the
|
||||
// database. Here, in this unit test, these 3 methods are executed
|
||||
// right after each other because we want to test a complete process
|
||||
// scenario. But in reality, these methods represent different
|
||||
// requests to a server.
|
||||
|
||||
// Since we start with a clean, empty in-memory database, we have to
|
||||
// deploy the process first. In reality, this is done once by the
|
||||
// process developer.
|
||||
deployProcessDefinition();
|
||||
|
||||
// Suppose we want to start a process instance (=process execution)
|
||||
// when a user submits a form in a web application...
|
||||
processInstanceIsCreatedWhenUserSubmitsWebappForm();
|
||||
|
||||
// Then, later, upon the arrival of an asynchronous message the
|
||||
// execution must continue.
|
||||
theProcessInstanceContinuesWhenAnAsyncMessageIsReceived();
|
||||
}
|
||||
|
||||
public void testStep0()
|
||||
throws Exception
|
||||
{
|
||||
deployProcessDefinition();
|
||||
setComplete();
|
||||
}
|
||||
|
||||
public void testStep1()
|
||||
throws Exception
|
||||
{
|
||||
processInstanceIsCreatedWhenUserSubmitsWebappForm();
|
||||
setComplete();
|
||||
}
|
||||
|
||||
public void testStep2()
|
||||
throws Exception
|
||||
{
|
||||
theProcessInstanceContinuesWhenAnAsyncMessageIsReceived();
|
||||
setComplete();
|
||||
}
|
||||
|
||||
private void deployProcessDefinition()
|
||||
{
|
||||
// This test shows a process definition and one execution
|
||||
// of the process definition. The process definition has
|
||||
// 3 nodes: an unnamed start-state, a state 's' and an
|
||||
// end-state named 'end'.
|
||||
final ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
|
||||
"<process-definition name='hello world'>" +
|
||||
" <start-state name='start'>" +
|
||||
" <transition to='s' />" +
|
||||
" </start-state>" +
|
||||
" <state name='s'>" +
|
||||
" <transition to='end' />" +
|
||||
" </state>" +
|
||||
" <end-state name='end' />" +
|
||||
"</process-definition>"
|
||||
);
|
||||
|
||||
jbpmTemplate.execute(new JbpmCallback()
|
||||
{
|
||||
public Object doInJbpm(JbpmContext context)
|
||||
{
|
||||
context.deployProcessDefinition(processDefinition);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void processInstanceIsCreatedWhenUserSubmitsWebappForm()
|
||||
{
|
||||
jbpmTemplate.execute(new JbpmCallback()
|
||||
{
|
||||
public Object doInJbpm(JbpmContext context)
|
||||
{
|
||||
GraphSession graphSession = context.getGraphSession();
|
||||
ProcessDefinition processDefinition = graphSession.findLatestProcessDefinition("hello world");
|
||||
|
||||
// With the processDefinition that we retrieved from the database, we
|
||||
// can create an execution of the process definition just like in the
|
||||
// hello world example (which was without persistence).
|
||||
ProcessInstance processInstance = new ProcessInstance(processDefinition);
|
||||
|
||||
Token token = processInstance.getRootToken();
|
||||
assertEquals("start", token.getNode().getName());
|
||||
// Let's start the process execution
|
||||
token.signal();
|
||||
// Now the process is in the state 's'.
|
||||
assertEquals("s", token.getNode().getName());
|
||||
|
||||
context.save(processInstance);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void theProcessInstanceContinuesWhenAnAsyncMessageIsReceived()
|
||||
{
|
||||
jbpmTemplate.execute(new JbpmCallback()
|
||||
{
|
||||
public Object doInJbpm(JbpmContext context)
|
||||
{
|
||||
GraphSession graphSession = context.getGraphSession();
|
||||
|
||||
// First, we need to get the process instance back out of the database.
|
||||
// There are several options to know what process instance we are dealing
|
||||
// with here. The easiest in this simple test case is just to look for
|
||||
// the full list of process instances. That should give us only one
|
||||
// result. So let's look up the process definition.
|
||||
ProcessDefinition processDefinition = graphSession.findLatestProcessDefinition("hello world");
|
||||
|
||||
// Now, we search for all process instances of this process definition.
|
||||
List processInstances = graphSession.findProcessInstances(processDefinition.getId());
|
||||
|
||||
// Because we know that in the context of this unit test, there is
|
||||
// only one execution. In real life, the processInstanceId can be
|
||||
// extracted from the content of the message that arrived or from
|
||||
// the user making a choice.
|
||||
ProcessInstance processInstance = (ProcessInstance) processInstances.get(0);
|
||||
|
||||
// Now we can continue the execution. Note that the processInstance
|
||||
// delegates signals to the main path of execution (=the root token).
|
||||
processInstance.signal();
|
||||
|
||||
// After this signal, we know the process execution should have
|
||||
// arrived in the end-state.
|
||||
assertTrue(processInstance.hasEnded());
|
||||
|
||||
// Now we can update the state of the execution in the database
|
||||
context.save(processInstance);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user