How to create Activiti Parallel Tasks with Spring JPA + Spring Boot Example
Tags: springboot, springjpa, activiti, parallel
Published: 2021-04-29 15:13:03

https://grokonez.com/java-integration/activiti-parallel-tasks-jpa-with-spring-boot-example

How to create Activiti Parallel Tasks with Spring JPA + Spring Boot Example

This tutorial shows you a Spring Boot example which is integrated with Activiti Parallel Tasks and Spring JPA.

Related Articles: 
- <a href="https://grokonez.com/java-integration/introduction-activity-java-bpm-engine">Introduction to Activiti – a Java BPM Engine</a>
- <a href="https://grokonez.com/java-integration/start-activiti-spring-jpa-spring-boot">How to start Activiti + Spring JPA with Spring Boot</a>

<!--more-->
<div id="tuttoc" class="jsa-toc"></div>

<div id="tutcontents">
<h2>I. Technology</h2>
- Java 1.8
- Maven 3.3.9
- Spring Tool Suite – Version 3.8.1.RELEASE
- Spring Boot: 1.5.3.RELEASE
<h2>II. Overview</h2>
<h3>1. Goal</h3>
To build a Spring Boot application that helps to manage process as below:
<img src="https://grokonez.com/wp-content/uploads/2017/05/activiti-parallel-spring-boot.png" alt="activiti-parallel-spring-boot" width="699" height="305" class="alignnone size-full wp-image-5179" />

- We will create a group of persons and use <strong>Spring JPA</strong> to store their information.
- Then we assign:
+ <strong>Check Hardware</strong> and <strong>Do Meeting</strong> to John.
+ <strong>Check Software</strong> and <strong>Check Firmware</strong> to David.
+ <strong>Write Report</strong> to Katherin.

- John's tasks and David's tasks can be handled in parallel. David doesn't need to wait for any task which is assigned to John be done.
- Katherin is the assignee of <strong>Write Report</strong> task only if <strong>Check Hardware</strong>, <strong>Check Software</strong> and <strong>Check Firmware</strong> are done.

- After report is done, 'notification' message will be shown in the System Console.
<h3>2. Project Structure</h3>
<img src="https://grokonez.com/wp-content/uploads/2017/05/activiti-parallel-spring-boot-structure.png" alt="activiti-parallel-spring-boot-structure" width="304" height="470" class="alignnone size-full wp-image-5181" />

- Process definition will be written under XML format in process/<strong>process.bpmn20.xml</strong> file.
- <strong>MyService</strong> provides service methods for <strong>Controller</strong> such as: <code>startProcess()</code>, <code>getTasks()</code>, <code>completeTask()</code>. Those functions can be done with help of some <strong>@Autowired</strong> objects which are instances of these classes:
+ RepositoryService
+ RuntimeService
+ TaskService
+ PersonRepository
- <strong>PersonRepository</strong> is an interface extends <strong>JpaRepository</strong> for implementing repository methods on <strong>Person</strong> entities.

- <strong>SpringParallelActivitiApplication</strong> class contains Bean that calls <strong>MyService</strong>'s creating persons method when starting the application.
- <strong>MyController</strong> is a REST Controller which has request mapping methods for RESTful requests such as: <em>/process</em>, <em>/tasks</em>, <em>/completetask</em>.

- <strong>pom.xml</strong> contains dependencies for:
+ Activiti Spring Boot Starter Basic, Activiti Spring Boot Starter JPA
+ Spring Boot Starter Web
+ H2 database
+ Groovy: scripting engine for running Script Task in process.
<div class="jsa-quote">
Notes: We must add Groovy Jar file (<a href="https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all/2.4.10" rel="nofollow">groovy-all-2.4.10.jar</a>) to make it work.
</div>

More at:

https://grokonez.com/java-integration/activiti-parallel-tasks-jpa-with-spring-boot-example

How to create Activiti Parallel Tasks with Spring JPA + Spring Boot Example