As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
<bean id="externalReviewNotification" class="com.someco.bpm.ExternalReviewNotification"> <property name="actionService"> <ref bean="ActionService" /> </property> </bean>
<activiti:taskListener event="create" delegateExpression="${externalReviewNotification}"></activiti:taskListener>
<util:map id="activitiBeanRegistry" map-class="java.util.HashMap"> <entry key="services" value-ref="ServiceRegistry" /> <entry key="simpleLoggerServiceTask" value-ref="simpleLoggerServiceTask" /> </util:map>
<activiti:taskListener event="create" class="com.someco.bpm.ExternalReviewNotification"></activiti:taskListener>
protected ServiceRegistry getServiceRegistry() { ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration(); if (config != null) { // Fetch the registry that is injected in the activiti spring-configuration ServiceRegistry registry = (ServiceRegistry) config.getBeans().get(ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY); if (registry == null) { throw new RuntimeException( "Service-registry not present in ProcessEngineConfiguration beans, expected ServiceRegistry with key" + ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY); } return registry; } throw new IllegalStateException("No ProcessEngineCOnfiguration found in active context"); }
According to them, it's not the spring bean id the one we need to put in the delegateExpression property but the base name of the java class (for Jeff's example if would be ExternalReviewNotification)
I faced the same problem and found the same work around (register the bean manually overriding the activitiBeanRegistry).This is not the best solution as if you have more than one module, and want to register beans within the AMP file not in shared/classes/alfresco/extension… There'll be a workflow that won't work.I've already raised a ticket with Alfresco Support, fingers crossed they fix that!Regards,Adei
Sorry, didn't create a JIRA ticket, I meant an Alfresco Support ticket
I tried to implement similar thing as you, but using Activiti ServiceTask, and had the same problems as you.'activiti:class' way worked fine….
<process id="MySampleServiceTask" name="MySampleServiceTask"> <startEvent id="alfrescoStartevent1" name="Alfresco start" activiti:formKey="bpm:startTask"></startEvent> <serviceTask id="servicetask1" name="Service Task" activiti:class="workflow.sample.serviceTask.HelloWorldServiceTask"></serviceTask> <endEvent id="endevent1" name="End"></endEvent> <sequenceFlow id="flow1" name="" sourceRef="servicetask1" targetRef="endevent1"></sequenceFlow> <sequenceFlow id="flow2" name="" sourceRef="alfrescoStartevent1" targetRef="servicetask1"></sequenceFlow> </process>
package workflow.sample.serviceTask; import org.activiti.engine.delegate.DelegateExecution; import org.activiti.engine.delegate.JavaDelegate; public class HelloWorldServiceTask implements JavaDelegate { public HelloWorldServiceTask() { System.out.println("HelloWorldServiceTask created"); } @Override public void execute(DelegateExecution arg0) throws Exception { System.out.println("Hello Wolrd!"); } }
<bean id="AbstractWorkflowDelegate" parent="baseJavaDelegate" abstract="true" depends-on="activitiBeanRegistry"/> <bean id="MyCustomClass" parent="AbstractWorkflowDelegate" class="com.bluefishgroup.alf.workflow.MyCustomClass"/> <!– A bunch of additional classes defined as well –>
import org.alfresco.repo.workflow.activiti.BaseJavaDelegate; public class MyCustomClass extends BaseJavaDelegate
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'> <beans> <bean id="AbstractWorkflowDelegate" parent="baseJavaDelegate" abstract="true" depends-on="activitiBeanRegistry" /> <bean id="MyIssuePost" class="com.epnet.alfresco.metadata.listener.MyIssuePost" parent="AbstractWorkflowDelegate"> <property name="serviceRegistry" ref="ServiceRegistry" /> </bean> <!– this didn't work either <bean id="com.epnet.metadata.listener.MyIssuePost" class="com.epnet.alfresco.metadata.listener.MyIssuePost"> <property name="serviceRegistry" ref="ServiceRegistry" /> </bean> –> </beans>
public abstract class DmsCommonListener { final static protected String DMS_LOG_MARKER = "### DMS ###"; @Autowired @Qualifier("ServiceRegistry") private ServiceRegistry serviceRegistry; /** * @param serviceRegistry * the serviceRegistry to set */ @Required //I combined it to just somehow make it work:-) public void setServiceRegistry(ServiceRegistry serviceRegistry) { this.serviceRegistry = serviceRegistry; } /** * @return the serviceRegistry */ public ServiceRegistry getServiceRegistry() { return serviceRegistry; } <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:annotation-config /> <context:component-scan base-package="com.tieto" /> <bean id="DmsCustomMailer" class="com.tieto.workflow.util.DmsCustomMailer"></bean> <bean id="DmsCommonListenerBean" class="com.tieto.workflow.DmsCommonListener" abstract="true"> <property name="workflowService"> <ref bean="WorkflowService" /> </property> <property name="serviceRegistry"> <ref bean="ServiceRegistry" /> </property> </bean> <bean id="DmsCommonTaskListenerBean" class="com.tieto.workflow.DmsCommonTaskListener" abstract="true" parent="DmsCommonListenerBean" /> <bean id="DmsCommonExecutionListenerBean" class="com.tieto.workflow.DmsCommonExecutionListener" abstract="true" parent="DmsCommonListenerBean" /> <!– INIT –> <bean id="InitTaskListenerBean" class="com.tieto.workflow.init.TaskListener" parent="DmsCommonTaskListenerBean" /> <bean id="InitExecutionListenerBean" class="com.tieto.workflow.init.ExecutionListener" parent="DmsCommonExecutionListenerBean" /> <!– ELABORATION –> <bean id="ElaborationTaskListenerBean" class="com.tieto.workflow.elaboration.TaskListener" parent="DmsCommonTaskListenerBean" />
<?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="Examples"> <process id="MyTest" name="MyTest"> <startEvent id="theStart" name="Start"> </startEvent> <serviceTask id="javaService" name="Java service invocation" activiti:class="org.activiti.examples.bpmn.test.manager2.SetterTest"> <extensionElements> <activiti:field name="text"> <activiti:string>Success</activiti:string> </activiti:field> <activiti:taskListener event="create" class="org.activiti.examples.bpmn.test.manager2.SetterTest"> </activiti:taskListener> </extensionElements> </serviceTask> <userTask id="usertask1" name="User Task" activiti:candidateGroups="user"></userTask> <endEvent id="theEnd" name="End"></endEvent> <sequenceFlow id="flow1" name="" sourceRef="theStart" targetRef="javaService"></sequenceFlow> <sequenceFlow id="flow2" name="" sourceRef="javaService" targetRef="usertask1"></sequenceFlow> <sequenceFlow id="flow4" name="" sourceRef="usertask1" targetRef="theEnd"></sequenceFlow> </process> </definitions>
package org.activiti.examples.bpmn.test.manager2; import … ………. public class SetterTest implements JavaDelegate { private static final String VARIABLE_NAME = "testVariable"; private Expression text; ServiceRegistry serviceRegistry=null; //public ServiceRegistry getServiceRegistry() {return serviceRegistry;} protected ServiceRegistry getServiceRegistry() { ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration(); if (config != null) { ServiceRegistry registry = (ServiceRegistry) config.getBeans().get(ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY); if (registry == null) { throw new RuntimeException( "Service-registry not present in ProcessEngineConfiguration beans, expected ServiceRegistry with key" + ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY); } else System.out.println("————— config =null"); return registry; } throw new IllegalStateException("No ProcessEngineCOnfiguration found in active context"); } public void setServiceRegistry(ServiceRegistry serviceRegistry) {this.serviceRegistry = serviceRegistry;} public void execute(DelegateExecution execution) { if (serviceRegistry==null) System.out.println("serviceRegistry is null!!"); } }