Tuesday, August 12, 2014

Using a bean instanciated TaskListener in an Activiti Workflow

In Alfresco (ONE ~ ECM) Activiti you can use a Java TaskListener, which has the following advantages:
 - Is Java, preference for some, is more powerful in Alfresco
 - Compared to inline Activiti JS script, it is easier to reuse
 - Can be changed on running workflows (bug fixes etc.)
 - Can be reloaded dynamically using spring-loaded or JRebel

First you must create your TaskListener (different types exist):

public class StartTaskCreate extends TaskCreateListener {
  @Override
  public void notify(DelegateTask task) {
     // ... I can walk!

     // you stuff goes here ...
   super.notify(task); 
 }
}

Then yoiu must create a bean definition (using bean parent to init super class):

 <bean id="my.StartTaskCreate"
        class="my.StartTaskCreate"
        parent="activitiCreateTaskListener"/>


 Then you must let Activiti know about it (put into activitiBeanRegistry map):

<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>StartTaskCreate</value>
        <ref bean="my.StartTaskCreate" />
       </list>
    </property>
  </bean>


I use method invoking via Spring to add to existing bean-map, this makes the solution deployable as AMP (not tomcat/shared/..) and in a solution with many extensions more robust. Also Alfresco can change the orginal definition somewhat without this breaking, robust across Alfresco versions!

Then use it!
<process ...
...
<startEvent id="alfrescoStartevent1" name="Start" activiti:formKey="...">
  <extensionElements>
    <activiti:taskListener event="create" delegateExpression="${StartTaskCreate}"/>

...

Observe the key in activitiBeanRegistry is the word to use in the workflow delegate expression ~ delegateExpression="${StartTaskCreate}"

Monday, August 4, 2014

Override Alfresco Share action order

To override the action order in documentlibrary extensions, your can do so by defining the action group with new index for action.

EX:

<actionGroups> 
  <actionGroup id="document-browse">
    <action index="XYZ" id="document-move-to" />
...


An important rule is use three digits, always three digits! So to move an action up in the top (lower than index 100), so it will become visible document browsing use prefixes of zero (0) ~I think it probably does a string compare somewhere, would explain the behaviour.

EX:

<actionGroups>
  <actionGroup id="document-browse">
    <action index="099" id="document-move-to" />

...