mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Add support for writing jBPM plug-in actions which have access to Spring context.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3321 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -4,14 +4,16 @@
|
|||||||
<beans>
|
<beans>
|
||||||
|
|
||||||
<!-- jBPM configuration -->
|
<!-- jBPM configuration -->
|
||||||
<bean id="jbpmConfiguration" class="org.springmodules.workflow.jbpm31.LocalJbpmConfigurationFactoryBean">
|
<bean id="jbpm.configuration" class="org.springmodules.workflow.jbpm31.LocalJbpmConfigurationFactoryBean">
|
||||||
<property name="sessionFactory" ref="sessionFactory"/>
|
<property name="sessionFactory" ref="sessionFactory"/>
|
||||||
<property name="configuration" value="classpath:org/jbpm/default.jbpm.cfg.xml"/>
|
<property name="configuration" value="classpath:org/jbpm/default.jbpm.cfg.xml"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- jBPM template -->
|
<!-- jBPM template -->
|
||||||
<bean id="jbpmTemplate" class="org.springmodules.workflow.jbpm31.JbpmTemplate">
|
<bean id="jbpm.template" class="org.springmodules.workflow.jbpm31.JbpmTemplate">
|
||||||
<constructor-arg index="0" ref="jbpmConfiguration"/>
|
<constructor-arg index="0" ref="jbpm.configuration"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.jbpm.graph.def.ActionHandler;
|
||||||
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
|
import org.springframework.beans.factory.access.BeanFactoryLocator;
|
||||||
|
import org.springframework.beans.factory.access.BeanFactoryReference;
|
||||||
|
import org.springmodules.workflow.jbpm31.JbpmFactoryLocator;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract base implementation of a Jbpm Action Hander with access to
|
||||||
|
* Alfresco Spring beans.
|
||||||
|
*
|
||||||
|
* @author davidc
|
||||||
|
*/
|
||||||
|
public abstract class JBPMSpringActionHandler implements ActionHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct
|
||||||
|
*/
|
||||||
|
protected JBPMSpringActionHandler()
|
||||||
|
{
|
||||||
|
// The following implementation is derived from Spring Modules v0.4
|
||||||
|
BeanFactoryLocator factoryLocator = new JbpmFactoryLocator();
|
||||||
|
BeanFactoryReference factory = factoryLocator.useBeanFactory(null);
|
||||||
|
initialiseHandler(factory.getFactory());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialise Action Handler
|
||||||
|
*
|
||||||
|
* @param factory Spring bean factory for accessing Alfresco beans
|
||||||
|
*/
|
||||||
|
protected abstract void initialiseHandler(BeanFactory factory);
|
||||||
|
|
||||||
|
}
|
@@ -18,6 +18,7 @@ package org.alfresco.repo.workflow.jbpm;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.alfresco.service.descriptor.DescriptorService;
|
||||||
import org.alfresco.util.BaseSpringTest;
|
import org.alfresco.util.BaseSpringTest;
|
||||||
import org.jbpm.JbpmContext;
|
import org.jbpm.JbpmContext;
|
||||||
import org.jbpm.db.GraphSession;
|
import org.jbpm.db.GraphSession;
|
||||||
@@ -35,13 +36,15 @@ import org.springmodules.workflow.jbpm31.JbpmTemplate;
|
|||||||
*/
|
*/
|
||||||
public class JBPMSpringTest extends BaseSpringTest
|
public class JBPMSpringTest extends BaseSpringTest
|
||||||
{
|
{
|
||||||
private JbpmTemplate jbpmTemplate;
|
JbpmTemplate jbpmTemplate;
|
||||||
|
DescriptorService descriptorService;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSetUpInTransaction() throws Exception
|
protected void onSetUpInTransaction() throws Exception
|
||||||
{
|
{
|
||||||
jbpmTemplate = (JbpmTemplate)applicationContext.getBean("jbpmTemplate");
|
jbpmTemplate = (JbpmTemplate)applicationContext.getBean("jbpm.template");
|
||||||
|
descriptorService = (DescriptorService)applicationContext.getBean("DescriptorService");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -100,13 +103,17 @@ public class JBPMSpringTest extends BaseSpringTest
|
|||||||
" <start-state name='start'>" +
|
" <start-state name='start'>" +
|
||||||
" <transition to='s' />" +
|
" <transition to='s' />" +
|
||||||
" </start-state>" +
|
" </start-state>" +
|
||||||
" <state name='s'>" +
|
" <node name='s'>" +
|
||||||
|
" <action class='org.alfresco.repo.workflow.jbpm.JBPMTestSpringActionHandler' config-type='bean'>" +
|
||||||
|
" <value>a test value</value>" +
|
||||||
|
" </action>" +
|
||||||
" <transition to='end' />" +
|
" <transition to='end' />" +
|
||||||
" </state>" +
|
" </node>" +
|
||||||
" <end-state name='end' />" +
|
" <end-state name='end' />" +
|
||||||
"</process-definition>"
|
"</process-definition>"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
jbpmTemplate.execute(new JbpmCallback()
|
jbpmTemplate.execute(new JbpmCallback()
|
||||||
{
|
{
|
||||||
public Object doInJbpm(JbpmContext context)
|
public Object doInJbpm(JbpmContext context)
|
||||||
@@ -137,6 +144,10 @@ public class JBPMSpringTest extends BaseSpringTest
|
|||||||
token.signal();
|
token.signal();
|
||||||
// Now the process is in the state 's'.
|
// Now the process is in the state 's'.
|
||||||
assertEquals("s", token.getNode().getName());
|
assertEquals("s", token.getNode().getName());
|
||||||
|
// Spring based action has been called, check the result by looking at the
|
||||||
|
// process variable set by the action
|
||||||
|
String result = "Repo: " + descriptorService.getServerDescriptor().getVersion() + ", Value: a test value, Node: s, Token: /";
|
||||||
|
assertEquals(result, processInstance.getContextInstance().getVariable("jbpm.test.action.result"));
|
||||||
|
|
||||||
context.save(processInstance);
|
context.save(processInstance);
|
||||||
return null;
|
return null;
|
||||||
|
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.alfresco.service.descriptor.DescriptorService;
|
||||||
|
import org.jbpm.graph.exe.ExecutionContext;
|
||||||
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test Spring based Jbpm Action Handler
|
||||||
|
*
|
||||||
|
* @author davidc
|
||||||
|
*/
|
||||||
|
public class JBPMTestSpringActionHandler extends JBPMSpringActionHandler
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = -7659883022289711381L;
|
||||||
|
|
||||||
|
private DescriptorService descriptorService;
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter accessible from jBPM jPDL
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
public void setValue(String value)
|
||||||
|
{
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.jbpm.graph.def.ActionHandler#execute(org.jbpm.graph.exe.ExecutionContext)
|
||||||
|
*/
|
||||||
|
public void execute(ExecutionContext arg0) throws Exception
|
||||||
|
{
|
||||||
|
String result = "Repo: " + descriptorService.getServerDescriptor().getVersion();
|
||||||
|
result += ", Value: " + value + ", Node: " + arg0.getNode().getName() + ", Token: " + arg0.getToken().getFullName();
|
||||||
|
arg0.getContextInstance().setVariable("jbpm.test.action.result", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initialiseHandler(BeanFactory factory)
|
||||||
|
{
|
||||||
|
descriptorService = (DescriptorService)factory.getBean("DescriptorService", DescriptorService.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user