Java api in order to list all the tasks in the model

I am using the following java api to get all the tasks in the model but Its always listing down the sequence flows

BpmnModelInstance modelInstance = Bpmn.readModelFromFile(file);
	ModelElementType taskType = modelInstance.getModel().getType(UserTask.class);
	System.out.println(taskType.getTypeName());
	Collection<ModelElementInstance> taskInstances = modelInstance.getModelElementsByType(taskType);
	for (Iterator<ModelElementInstance> iterator = taskInstances.iterator(); iterator.hasNext()) {
        System.out.println("value= " + (iterator.next()).getTextContent()+"   ");
        }
  }

Hi yacky,

the method getTextContent() will return all the text contents of the child elements of the user task concatenated. For example if your user task has an incoming and outgoing sequence flow like this:

<userTask id="userTask_bd90facf-866f-4629-a65b-d3594c7b9347">
  <incoming>sequenceFlow_c2d794e8-3a60-4c35-a156-3b28f240ce65</incoming>
  <outgoing>sequenceFlow_e63b046f-dd04-43ca-9a3f-0a4786529512</outgoing>
</userTask>

it will return only the text content of the child sequence flows:

sequenceFlow_c2d794e8-3a60-4c35-a156-3b28f240ce65sequenceFlow_e63b046f-dd04-43ca-9a3f-0a4786529512

What information of the user tasks do you want to collect? You can use the getters of the UserTask class to access the properties of the task, i.e.:

Collection<UserTask> userTasks = modelInstance.getModelElementsByType(UserTask.class);
for (UserTask userTask : userTasks) {
  System.out.println("Id: " + userTask.getId() + " Name: " + userTask.getName());
}

Cheers,
Sebastian

I want to list out all the tasks from the deployed bpmn,both active and inactive ,which includes the intermediate events also.

I want to list out all the tasks from the deployed bpmn

But what information from the task do you need? You can get the id using userTask.getId(), see the example from my last comment.

both active and inactive, which includes the intermediate events also

I’m not sure what you mean with that. The BPMN model does not contain any runtime information, like the current active tasks. Also user tasks are not events, what do you mean with intermediate events?

By intermediate event I mean email events ,which will be known by activity type,and I wanted the information from the deployed bpmn. Is there any common api in order to get the external tasks and user tasks

Please post the XML of one of your processes and which values you want to extract. Than I maybe able to give you a code snippet how to do this. Otherwise I’m not sure what you want to achieve.

including the email event

I assume you mean the intermediate throw events.

BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File("sample.bpmn"));

for (Task task : modelInstance.getModelElementsByType(Task.class)) {
  System.out.println(task.getName());
}

for (IntermediateThrowEvent event: modelInstance.getModelElementsByType(IntermediateThrowEvent.class)) {
  System.out.println(event.getName());
}