cancel
Showing results for 
Search instead for 
Did you mean: 

Number of task , given a execution id of a process

burn83
Champ in-the-making
Champ in-the-making
Hello…can i count (and, eventually, create a list) of each single task that is included in my process…

In particular, this istruction:

List<Task> lst_task = taskservice.createTaskQuery().executionId(processelected).list();

can be represents my solution?!?!
The problem is that it returns only one task, i.e. the task that must be completed at this time..


is it a bug?!
3 REPLIES 3

mmaker1234
Champ in-the-making
Champ in-the-making
Hello,

The TaskService "knows" only about the run time state of a process instance.

What you need is probably the tasks in your process definition. In this case you will need to reach the process definition (deployed in the engine) and analyze it.

(I'm sorry I can not give you more details because I also have no experience but I hope the above correction of the direction for your investigation is enough and you will reach results easily).

frederikherema1
Star Contributor
Star Contributor
mmaker1234 is right. The TaskService only returns tasks that are active. If you want to look at the future tasks in the process, you'll have to inspect the process-definition.

As of activiti 5.12 (released this week), this is easy using the BPMN 2.0 Pojo-model. Use the repository-service for this:


/**
   * Returns the {@link BpmnModel} corresponding with the process definition with
   * the provided process definition id. The {@link BpmnModel} is a pojo versions
   * of the BPMN 2.0 xml and can be used to introspect the process definition
   * using regular Java.
   */
  BpmnModel getBpmnModel(String processDefinitionId);

From this BPMNModel, you'll be able to navigate through the process and look for upcoming tasks or other interesting stuff…

burn83
Champ in-the-making
Champ in-the-making
oh..thanks to all for any reply…

my solution is (for now..):


String process_def_id = processDefinition.getDeploymentId();
String deploymentID = process_def_id;
List<String> deploymentResourceNames = repositoryService.getDeploymentResourceNames(deploymentID);
String toString = deploymentResourceNames.get(0).toString();
InputStream Diagram_1 = new FileInputStream(toString);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();   
Document docDiagram1 = dBuilder.parse(Diagram_1); 
docDiagram1.getDocumentElement().normalize();   
Element nListDiagram1 = (Element) docDiagram1.getElementsByTagName("process").item(0);
int contatore=0;
for(int g=0;g<nListDiagram1.getChildNodes().getLength();g++){
          Node currentNode = nListDiagram1.getChildNodes().item(g);
          if((currentNode.getNodeName() != "sequenceFlow")){
                  if(currentNode.getNodeName() != "#text"){
                       System.out.println(currentNode.getNodeName());
                       contatore++;
                  }
          }
}
System.out.println(contatore);