Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get tasks in Activiti process definition without creating a process instance?

Tags:

java

activiti

I have to expose the Activiti API process using a service of my project.

My requirement is as under:

I want to know the details about Tasks in Activiti Process Definition, using Java, before running the Process, ie. before creating the Activiti ProcessInstance. Is there any way to achieve this?

I have gone through the Java docs and User guide of Activiti API lots of times but couldn't find a way.

Any help will be appreciated, Thanks.

like image 367
OutOfMind Avatar asked Jan 07 '23 13:01

OutOfMind


1 Answers

You can use the getBpmnModel(processDefinitionId) method available in the RepositoryService interface.

The result is a Pojo that you can use in o order to introspect the process. The initial pojo represents the model, which can have multiple Processes (but usually only one). From a given Process, you can find all tasks using the findFlowElementsOfType(Class type).

For instance, this snippet should get you a list of UserTasks in a process (not tested but should give you an idea of what is needed):

BpmnModel model = processEngine.getRepositoryService().getBpmnModel(someProcessId);
List<Process> processes = model.getProcesses();
List<UserTask> userTasks = new ArrayList<>();
for( Process p : processes ) {
     userTasks.addAll( p.findFlowElementsOfType(UserTask.class))    
}
like image 191
Philippe Sevestre Avatar answered Mar 23 '23 03:03

Philippe Sevestre