Workflow with Activiti

cancel
Showing results for 
Search instead for 
Did you mean: 

Workflow with Activiti

resplin
Intermediate
1 2 28.8K

Obsolete Pages{{Obsolete}}

The official documentation is at: http://docs.alfresco.com



Workflow

Back to Workflow.


Introduction


Starting from Alfresco Community 3.4.e, you can deploy Activiti process definitions to specify workflows. The Activiti BPMN 2.0 BPM engine is now embedded in Alfresco in addition to the current jBPM engine. Both workflow engines are  encapsulated in the workflow service that provides a standard interface to the underlying workflow engine itself.
Activiti process definitions are written in BPMN 2.0 and are deployed and managed in exactly the same way as the current jBPM process definitions.
Alfresco provides the same set of pre-defined process templates for Activiti, and for jBPM. In Alfresco Community 3.4.e, this feature is provided as a technology preview only.













Activiti
jBPM
Process definition LanguageBPMN 2.0jPDL
Embedded in Alfresco?YesYes
Pre-defined workflows?YesYes
Workflow process designerActiviti Eclipse Designer, or any other BPMN 2.0 compliant modelerJBoss jBPM Process Designer

What is Activiti?


Activiti is a light-weight workflow and Business Process Management (BPM) Platform targeted at business people, developers and system administrators. It provides a fast and reliable BPMN 2 process engine for Java. It is open-source and distributed under an Apache license. Activiti is lightweight, based on open standards and is designed to integrate well with Spring applications, like Alfresco. You can learn more about Activiti on the Activiti website.


What is BPMN 2.0?


BPMN 2.0 (Business Process Modeling Notation) is an open standard developed by the Object Management Group (OMG)
to provide a notation that is easily understandable by all business users:  business
analysts designing processes, developers implementing technology to  perform those processes, and,  business people managing  and monitoring those
processes. BPMN creates a standardized bridge for the gap between the business process design and process.

The first version BPMN specification defined graphical notation only, and became quickly popular within the business analyst audience .It defined how concepts such as a human task, an executable script, an automated decision are visualized in a vendor-neutral, standardized way. The second version extended the standard to include execution semantics and a common exchange format. This means that BPMN 2.0 process definition models can be exchanged between graphical editors, and  executed  on any BPMN 2.0 compliant engine such as Activiti.
You can learn more about BPMN on the OMG website.


Working with workflows


For a user, tasks for working with workflows in Afresco Share remain the same. The only change is in the
in the contents of the Workflow list displayed on the Start Workflow page where you select the type of workflow you want to define. Out of the box, Share now includes the following preconfigured workflows for both Activiti and jBPM:-


Adhoc
Enables you to assign a task to a single user
Group Review & Approve
Enables you to set up review and approval of content, assigning the workflow task to a single group
Parallel Review & Approve
Enables you to set up review and approval of content, assigning the workflow task to multiple users.
Pooled Review & Approve
Enables you to set up review and approval of content, assigning the workflow task to multiple users. One user can take ownership of the task at a time, completing it or returning it to the pool to be claimed by another user associated with the task.
Review & Approve
Enables you to set up review and approval of content, assigning the workflow task to a single user

You can see more on working with workflows in the Alfresco Documentation.


Creating and managing workflows


In Alfresco, a workflow consists a number of artifacts. The diagram below shows the artifacts and the relationship between them:-
none|Workflow Definition


Process Definition
Activiti process definitions describe the events, activities (tasks) and gateways (choices) of a workflow.  Tasks may be user tasks or script (system) tasks.  User tasks are assigned to  human performers (users).  System tasks perform some kind of operation against the Alfresco repository.  Both are described and implemented in the Process Definition.

The embedded Activiti process engine accepts process definitions written in BPMN 2.0. A process definition is an xml document.


Task Model
The Task Model provides a description for each of the user tasks in the workflow.  Each task description consists of:

  • Name and Title
  • Properties and Associations (e.g. the information attached to the task)

The description is used to drive the user interface dialog for viewing and managing the Task.

Alfresco provides a 'Data Dictionary' for describing types of object to store, view and edit.  This mechanism is also used to describe Workflow Tasks.


Share Workflow UI

You can customize the presentation of Tasks to the user in  Alfresco Share.

Customizing allows:


  • Control over which Task properties are displayed
  • Control over which Task properties are read-only and required
  • Control over how each Task property is rendered in the forms

There is more information in Custom Share Workflow UI.


Resource Bundle (optional)

A workflow resource bundle provides all the human-readable messages displayed in the user interface for managing the workflow.  Messages include Task titles, task property names, task choices etc.

Alfresco supports full localisation of  Alfresco Share, including workflow.  Therefore, the same Alfresco Share resource bundle configuration extends to workflow too.


Creating a process definition


You can create the BPMN 2.0 process definition manually in a text or XML editor, or by using a  BPMN 2.0 compliant business process modeler such as  Activiti Eclipse Designer. You can use the process definitions supplied in Alfresco for the preconfigured workflows as examples. These can be found in webapps/alfresco/WEB-INF/classes/alfresco/workflow.














Process Definition File
Workflow
adhoc.bpmn20.xmlAdhoc Activiti Process
parallel-review-group.bpmn20.xmlParallel Group Review And Approve Activiti Process
parallel-review.bpmn20.xmlParallel Review And Approve Activiti Process
review-pooled.bpmn20.xmlPooled Review And Approve Activiti Process
review.bpmn20.xmlReview And Approve Activiti Process

Further information on creating BPMN 2.0 process definitions can be found on the omg website, and in the Activiti 5.3 User Guide. The example listing below shows the adhoc Activiti process definition:-



<definitions id='adhoc-definitions'
             typeLanguage='http://www.w3.org/2001/XMLSchema'
             expressionLanguage='http://www.w3.org/1999/XPath'
             targetNamespace='http://activiti.org/bpmn20'
             xmlns='http://www.omg.org/spec/BPMN/20100524/MODEL'
             xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
             xmlns:activiti='http://activiti.org/bpmn'>

    <process id='activitiAdhoc' name='Adhoc Activiti Process'>

        <startEvent id='start'
            activiti:formKey='wf:submitAdhocTask' />

        <sequenceFlow id='flow1'
            sourceRef='start'
            targetRef='adhocTask' />

        <userTask id='adhocTask' name='Adhoc Task'
            activiti:formKey='wf:adhocTask'>
           <extensionElements>
               <activiti:taskListener event='create'
                      class='org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener'>
                  <activiti:field name='script'>
                     <activiti:string>
                      if (typeof bpm_workflowDueDate !=
                             'undefined') task.setVariableLocal('bpm_dueDate', bpm_workflowDueDate);
                      if (typeof bpm_workflowPriority != 'undefined')
                                                       task.priority = bpm_workflowPriority;
                     </activiti:string>
                  </activiti:field>
               </activiti:taskListener>
           </extensionElements>
            <humanPerformer>
                <resourceAssignmentExpression>
                    <formalExpression>${bpm_assignee.properties.userName}</formalExpression>
                </resourceAssignmentExpression>
            </humanPerformer>
        </userTask>

        <sequenceFlow id='flow2'
        sourceRef='adhocTask'
            targetRef='verifyTaskDone' />

        <userTask id='verifyTaskDone' name='Verify Adhoc Task Completed.'
            activiti:formKey='wf:completedAdhocTask' >
            <documentation>
                Verify the arbitrary task was completed.
            </documentation>
            <extensionElements>
               <activiti:taskListener event='create'
                    class='org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener'>
                  <activiti:field name='script'>
                     <activiti:string>
                    if (typeof bpm_workflowDueDate !=
                                   'undefined') task.setVariableLocal('bpm_dueDate',
                                                                                bpm_workflowDueDate);
                    if (typeof bpm_workflowPriority != 'undefined')
                                                                    task.priority = bpm_workflowPriority;
                       
                     if (wf_notifyMe)
               {
                var mail = actions.create('mail');
                mail.parameters.to = initiator.properties.email;
                mail.parameters.subject = 'Adhoc Task ' + bpm_workflowDescription;
                mail.parameters.from = bpm_assignee.properties.email;
                mail.parameters.text = 'It's done';
                mail.execute(bpm_package);
               }
                     </activiti:string>
                  </activiti:field>
               </activiti:taskListener>
           </extensionElements>
            <humanPerformer>
                <resourceAssignmentExpression>
                    <formalExpression>${initiator.properties.userName}</formalExpression>
                </resourceAssignmentExpression>
            </humanPerformer>
        </userTask>

        <sequenceFlow id='flow3' sourceRef='verifyTaskDone'
            targetRef='theEnd' />

        <endEvent id='theEnd' />

    </process>

</definitions>

Note in particular the activiti:formKey attribute of the startEvent element.



activiti:formKey='wf:submitAdhocTask'

This attribute tells Alfresco which form to display when the user selects a workflow in Workflow list displayed on the Start Workflow page in Alfresco Share. In jBPM this is achieved using a task element in a start-state element. You can see this difference between an Activiti process definition and a jBPM process definition my comparing  adhoc.bpmn20.xml and adhoc_processdefinition.xml in webapps/alfresco/WEB-INF/classes/alfresco/workflow.


Creating a task model


A task model is a content model as supported by the Data Dictionary.
For each task in the process definition the task model can associate a task description. The description specifies the information that may be attached to a task: properties (name and datatype) and associations (name and type of associated object). A user can view and edit this information in the My Tasks dashlet  or the My Tasks page component on their dashboard in Alfresco Share. You can see more information on the My Tasks page component in the Alfresco Documentation.
To create a Task Model:


  1. Create a new Content Model for the Process Definition
  2. Create a Type for each Task
  3. For each Type, describe the properties and associations (information) required for the task

You can see the standard task model in workflowModel.xml in webapps/alfresco/WEB-INF/classes/alfresco/workflow.
Examining the file, you can see that the same underlying content model is shared by both jBPM and Activiti.
You will notice there is only one new type introduced by Activiti, activitiReviewTask. This defines a list of values for the task's transitions. This shows a difference between BPMN 2.0 and jPDL. In jPDL an explicit list of transitions are given from each task in the workflow. in BPMN 2.0 the route taken through the workflow is calculated differently, expressions use the values of variables in the workflow to decide which route to take. This is explained in more detail in Activiti Workflows with decision points.


Deploying a process definition


You can use the workflowDeployer bean to deploy process definitions (refer to the following code snippet).
The bean must be in a file in the <extension> directory. Note the the engineId property must be set to activiti for BPMN 2.0 process definitions.



<bean id='myworkflows.workflowBootstrap' parent='workflowDeployer'>
  <property name='workflowDefinitions'>
    <list>
      <props>
        <prop key='engineId'>activiti</prop>
        <prop key='location'>alfresco/workflow/adhoc.bpmn20.xml</prop>
        <prop key='mimetype'>text/xml</prop>
      </props>
    </list>
  </property>
</bean>

Deploying a task model


You can use one of two methods to deploy a task model:-


  • Using the workflowDeployer bean
  • Deploying as a content model

Both methods are described in the Alfresco Documentation.


References


  1.   Creation of workflow in Alfresco using Activiti step by step
2 Comments