cancel
Showing results for 
Search instead for 
Did you mean: 

how to add a custom task listener through java code?

goutham_pn
Champ in-the-making
Champ in-the-making

I'm building the usertask and servicetask dynamically

default UserTask createUserTask(String id, String name, String assignee) {
UserTask userTask = new UserTask();
userTask.setName(name);
userTask.setId(id);
userTask.setAssignee(assignee);
return userTask;
}

default ServiceTask createServiceTask(String id, String name, boolean asyn) {
ServiceTask serviceTask = new ServiceTask();
serviceTask.setName(name);
serviceTask.setId(id);
serviceTask.setAsynchronous(asyn);
ActivitiListener al = new ActivitiListener();

ExtensionAttribute ea = new ExtensionAttribute("activti", "abc");
// serviceTask.setExecutionListeners(executionListeners);
return serviceTask;
}

how to add 

<extensionElements>
<activiti:taskListener event="create" class="com.xy.z.TaskAssignmentHandler"></activiti:taskListener>
</extensionElements>

This dynamically using java code?

1 ACCEPTED ANSWER

nikmenke
Confirmed Champ
Confirmed Champ

Hi Goutham P N,

this should resolve your issue:

ActivitiListener activitiListener = new ActivitiListener();

activitiListener.setEvent("create");
activitiListener.setImplementation("com.xy.z.TaskAssignmentHandler");
activitiListener.setImplementationType("class");

Now you just have to add it to the service task.

Niklas

View answer in original post

3 REPLIES 3

nikmenke
Confirmed Champ
Confirmed Champ

Hi Goutham P N,

this should resolve your issue:

ActivitiListener activitiListener = new ActivitiListener();

activitiListener.setEvent("create");
activitiListener.setImplementation("com.xy.z.TaskAssignmentHandler");
activitiListener.setImplementationType("class");

Now you just have to add it to the service task.

Niklas

goutham_pn
Champ in-the-making
Champ in-the-making

Thanks Niklas.

How about adding expressions? something like this,

<serviceTask id="st-approve-action" name="Approve Action" activiti:expression="${xyz.Service.send(postDetails)}"></serviceTask>

And

<sequenceFlow id="flow1" sourceRef="gw-accept-reject" targetRef="exclusivegateway1">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${approver1 == false}]]></conditionExpression>
</sequenceFlow>

Thanks,

Goutham

Hi Goutham,

service task:

serviceTask.setImplementation("${xyz.Service.send(postDetails)}");
serviceTask.setImplementationType("expression");

sequence flow:

sequenceFlow.setConditionExpression("${approver1 == false}");