Home

In recent articles about JBPM workflows we had seen in one of the article regarding how to create listener class for JBPM workflow which is part of Alfresco. To get more details on importance of Actions class and how to create action class in JBPM workflow please refer this post.

Here we will see how to create similar action class in Activiti this is really important because in all new implementations clients are asking for Activiti rather than JBPM. Let’s get into implementation of this.

Step1:

Create your custom process definition file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?xml version="1.0" encoding="UTF-8" ?>
   expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://alfresco.org">
 
    <process isExecutable="true" id="activitiReview" name="Review And Approve Activiti Processssssss">
 
        <startEvent id="start"
            activiti:formKey="wf:submitReviewTask" />
 
        <sequenceFlow id='flow1'
            sourceRef='start'
            targetRef='reviewTask' />
 
        <userTask id="reviewTask" name="Review Task"
            activiti:formKey="wf:activitiReviewTask">
           <extensionElements>
               <activiti:taskListener event="create" class="com.test.CustomListener"></activiti:taskListener>
               <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
                  <activiti:field name="script">
                     <activiti:string>
                        if (typeof bpm_workflowDueDate != 'undefined') task.dueDate = bpm_workflowDueDate
                        if (typeof bpm_workflowPriority != 'undefined') task.priority = bpm_workflowPriority;      
                                                            
                     </activiti:string>
                  </activiti:field>
               </activiti:taskListener>
               <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
                  <activiti:field name="script">
                     <activiti:string>
                                execution.setVariable('wf_reviewOutcome', task.getVariable('wf_reviewOutcome'));
                     </activiti:string>
                  </activiti:field>
               </activiti:taskListener>
           </extensionElements>
            <humanPerformer>
                <resourceAssignmentExpression>
                    <formalExpression>${bpm_assignee.properties.userName}</formalExpression>
                </resourceAssignmentExpression>
            </humanPerformer>
        </userTask>
 
        <sequenceFlow id='flow2'
        sourceRef='reviewTask'
            targetRef='reviewDecision' />
 
        <exclusiveGateway  id="reviewDecision" name="Review Decision" />
 
        <sequenceFlow id='flow3' sourceRef='reviewDecision' targetRef='approved' >
            <conditionExpression xsi:type="tFormalExpression">${wf_reviewOutcome == 'Approve'}</conditionExpression>
        </sequenceFlow>
 
        <sequenceFlow id='flow4'
        sourceRef='reviewDecision'
            targetRef='rejected' />
 
       <userTask id="approved" name="Document Approved"
            activiti:formKey="wf:approvedTask" >
            <documentation>    The document was reviewed and approved.
            </documentation>
            <extensionElements>
              <activiti:taskListener event="create" class="com.test.CustomListener"></activiti:taskListener>
               <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
                  <activiti:field name="script">
                     <activiti:string>
                        if (typeof bpm_workflowDueDate != 'undefined') task.dueDate = bpm_workflowDueDate
                        if (typeof bpm_workflowPriority != 'undefined') task.priority = bpm_workflowPriority;
                             </activiti:string>
                  </activiti:field>
               </activiti:taskListener>
            </extensionElements>
            <humanPerformer>
                <resourceAssignmentExpression>
                    <formalExpression>${initiator.exists() ? initiator.properties.userName : 'admin'}</formalExpression>
                </resourceAssignmentExpression>
            </humanPerformer>
        </userTask>       
        <userTask id="rejected" name="Document Rejected"
            activiti:formKey="wf:rejectedTask" >
            <documentation>
                The document was reviewed and rejected.
            </documentation>
            <extensionElements>
               <activiti:taskListener event="create" class="com.test.CustomListener"></activiti:taskListener>
            </extensionElements>
            <humanPerformer>
                <resourceAssignmentExpression>
                    <formalExpression>${initiator.exists() ? initiator.properties.userName : 'admin'}</formalExpression>
                </resourceAssignmentExpression>
            </humanPerformer>
        </userTask>
        <sequenceFlow id='flow5' sourceRef='approved'       targetRef='end' />
        <sequenceFlow id='flow6' sourceRef='rejected'         targetRef='end' />
        <endEvent id="end" />
    </process>

I have just created simple workflow by copying most of the part from out of box review workflow of Alfresco.

*Note: you also need to create context file to register your custom workflow. To get more details on how to create custom workflow you can refer this post.

Step2:

Add custom listener class tag in process definition file. In this case I have added it in previous step only you can check highlighted text where it is referring to com.test.CustomListner class.

Step3:

Create new Java class called CustomListner class under package com.test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package com.test; 
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener; 
public class CustomListener implements TaskListener { 
                @Override
                public void notify(DelegateTask task) {
                System.out.println("CustomListener.notify()");
                                String ss="Take the appropriate action by clicking one of the links below:"+task.getName();
                                System.out.println(ss);
                
}

As you can see this class is extending Activiti engines TaskListener class and overriding notify method.

Step4:

Deploy everything

Workflow related xml files you can place under <TOMCAT_HOME>/shared/classes/alfresco/extension

For listener class you need to create jar file and place it inside <TOMCAT_HOME>/webapps/alfresco/WEB-INF/lib

Step5:

Restart your server and check changes.

Looking for quality Alfresco Web Hosting? Look no further than Arvixe Web Hosting!

Publicités

Laisser un commentaire

Choisissez une méthode de connexion pour poster votre commentaire:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion / Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion / Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion / Changer )

Photo Google+

Vous commentez à l'aide de votre compte Google+. Déconnexion / Changer )

Connexion à %s