How To listen to Claim event in Java

I have extended ServletProcessApplication in Java class to listen to different events happening in Tasks. But I am not able to get when a user ‘claim’ a task.

Following is the way I am getting other events like start, end of a task.

execution.getBpmnModelElementInstance().getElementType().getTypeName()
.trim()

Thanks in advance,
Kulapradip Bharali.

Hi @kulapradip,

could you post your implementation of the ServletProcessApplication?

Do you know the execution / task listener concept?
You can add a task listener to an user task. In this implementation, it is possible to react on different events.

For more information see:
https://docs.camunda.org/manual/7.7/user-guide/process-engine/delegation-code/#task-listener

Cheers
kristin

Hi Kristin,

Thank you for your reply. I have created a listener Java class as shown below. But it is not coming inside that when a claim task happens. My question is after having this Java class where to register this class, in which xml ? Should I have it configured somewhere in my bpmn flow xml ?

public class TaskCreateListener implements TaskListener {

public void notify(DelegateTask delegateTask) {
System.out.println(" delegeate task assignee :"+delegateTask.getAssignee());
}

}

My Process application looks like this.

@ProcessApplication(“myApp”)
public class LeadManagementProcessListener extends ServletProcessApplication{
static CaseRestImpl accessor = CaseRestAccessorSingleton.getInstance();;
// Map<String, String> caseStartInfoMap = new HashMap<String, String>();
// Map<String, String> taskInfoLookupMap = new HashMap<String, String>();

static final String CASE_INFO = "caseInfo";
static final String CASE_ID = "caseId";
static final String CASE_CREATETIME = "caseCreateTime";
static final String CURRENT_TASK_ID = "currentTaskId";
static final String CURRENT_TASK_CREATE_TIME = "taskCreateTime";



public ExecutionListener getExecutionListener() {
	
	ProcessEngineConfiguration configuration = new StandaloneInMemProcessEngineConfiguration() {
		  {
		    // register the plugin
		    this.getProcessEnginePlugins().add(CamundaReactor.plugin());
		  }
		};
	
	System.out.println("--------------------------------------------------inside execution listener");
	try {

		return new ExecutionListener() {
			public void notify(DelegateExecution execution) throws Exception {

				
				

				String baseType = execution.getBpmnModelElementInstance().getElementType().getBaseType()
						.getTypeName();
				System.out.println(">>> baseType :" + baseType);

Hi @kulapradip,

you have to add your TaskListener class to the user task in your BPMN xml. See the example below.

 <bpmn:userTask id="userTask" name="userTask>
    <bpmn:extensionElements>
      <camunda:taskListener class="com.camunda.bpm.workflow.TaskCreateListener" event="assignment" />
    </bpmn:extensionElements>
 </bpmn:userTask>

If you use the Camunda Modeler to model your process, you can add the listener via the properties panel.

Cheers
kristin

1 Like

Hi @kristin,

Thank You very much. I will try with this. One more question though

  • If I have multiple user Tasks, this way I have to go to modeller and add the listener in all of the tasks. But If my implementation is generalised, can I use same listener for all the user tasks instead of configuring for each tasks in bpmn ?

Hi @kulapradip

you can use the reactor plugin. Just implement a global Listener like this:

@CamundaSelector(type = "userTask", event = TaskListener.EVENTNAME_ASSIGNMENT)
public class GlobalUserTaskAssignmentListener extends ReactorTaskListener {

    public void notify(DelegateTask delegateTask) {
        // ... do some generalised stuff
    }

}
1 Like