younis alomoush
younis alomoush

Reputation: 71

Calling spring bean from alfresco activiti process

Within alfresco activiti, could I call a spring bean using the servicetask like :

<serviceTask id="assignApplicationId" name="Assign Application Id" 
  activiti:expression="${sequenceUtil.getOutboundId(task.id)}" 
  activiti:resultVariable="OutboundWF_ApplicationNumber"/>

however, in my custom context I declared the sequenceUtil as the following:

<bean id="sequenceUtil" name="sequenceUtil" class="com.tts.mersal.presentation.bean.dialog.util.SequenceUtil">
    <property name="searchService">
        <ref bean="searchService" />
    </property>
    <property name="nodeService">
        <ref bean="nodeService" />
    </property>
    <property name="workflowService">
        <ref bean="WorkflowService" />
    </property>     
</bean>

Actually I got the following exception

org.activiti.engine.impl.javax.el.PropertyNotFoundException: Cannot resolve identifier 'sequenceUtil'
at org.activiti.engine.impl.juel.AstIdentifier.eval(AstIdentifier.java:83)
at org.activiti.engine.impl.juel.AstMethod.invoke(AstMethod.java:79)
at org.activiti.engine.impl.juel.AstMethod.eval(AstMethod.java:75)
at org.activiti.engine.impl.juel.AstEval.eval(AstEval.java:50)
at org.activiti.engine.impl.juel.AstNode.getValue(AstNode.java:26)
at org.activiti.engine.impl.juel.TreeValueExpression.getValue(TreeValueExpression.java:114)
at org.activiti.engine.impl.el.JuelExpression.getValue(JuelExpression.java:46)

Upvotes: 4

Views: 4608

Answers (2)

Cherry
Cherry

Reputation: 33554

There is a much better way to map bean names to el epressions. At least for alfresco 5.2.

Originally activitiProcessEngineConfiguration defined like that:

<bean id="activitiProcessEngineConfiguration" class="org.alfresco.repo.workflow.activiti.AlfrescoProcessEngineConfiguration">

        <!-- Limit the visible beans in expressions -->
        <property name="beans" ref="activitiBeanRegistry" />
</bean>

Where activitiBeanRegistry defined like that:

<util:map id="activitiBeanRegistry" map-class="java.util.HashMap">
    <entry key="services" value-ref="ServiceRegistry" />
</util:map>

So you can easy add your beans with names without touching original activitiProcessEngineConfiguration. Like that:

<bean id="my.activitiBeanRegistry"  class="org.springframework.beans.factory.config.MethodInvokingFactoryBean" depends-on="activitiBeanRegistry">
<property name="targetObject">
  <ref bean="activitiBeanRegistry" />
</property>
<property name="targetMethod" value="put" />
<property name="arguments">
  <list>
    <value>sequenceUtil</value>
    <ref bean="sequenceUtil" />
   </list>
</property>

Open for extension closed for modification :)

Full source can be found here

See also activiti-context.xml

Upvotes: 2

younis alomoush
younis alomoush

Reputation: 71

I got it :)

I have to override the activitiProcessEngineConfiguration bean to include my custom bean within beans property

<!-- -->
<!-- Activiti Process Engine -->
<!-- -->
<bean id="activitiProcessEngineConfiguration"
    class="org.alfresco.repo.workflow.activiti.AlfrescoProcessEngineConfiguration">
    <property name="dataSource" ref="wrappedDataSource" />
    <property name="transactionManager" ref="transactionManager" />
    <property name="databaseSchemaUpdate" value="${db.schema.update}" />
    <property name="history" value="full" />
    <property name="jobExecutorActivate" value="true" />

<!-- Limit the visible beans in expressions -->


<property name="beans">
    <map>
        <entry key="services" value-ref="ServiceRegistry" />
        <entry key="sequenceUtil" value-ref="sequenceUtil" />
    </map>    
</property>

    <property name="customTypes">
        <list>
            <ref bean="activitiScriptNodeType" />
            <ref bean="activitiScriptNodeListType" />
        </list>
    </property>
    <property name="customPreBPMNParseListeners">
        <list>
            <ref bean="activitiParseListener" />
        </list>
    </property>
</bean>

Upvotes: 2

Related Questions