Skip to content

Commit 87e2047

Browse files
kcacademicpivovarit
authored andcommitted
Adding source files for the tutorial BAEL-2788 (eugenp#6699)
* Adding source files for the tutorial BAEL-2788 * Made changes to the code for the review comments
1 parent e89f5ac commit 87e2047

File tree

13 files changed

+354
-1
lines changed

13 files changed

+354
-1
lines changed

pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,8 @@
540540
<module>software-security/sql-injection-samples</module>
541541

542542
<module>tensorflow-java</module>
543-
543+
<module>spring-boot-flowable</module>
544+
544545
</modules>
545546

546547
</profile>
@@ -766,6 +767,7 @@
766767
<module>xstream</module>
767768

768769
<module>tensorflow-java</module>
770+
<module>spring-boot-flowable</module>
769771

770772
</modules>
771773

@@ -908,6 +910,8 @@
908910
<module>persistence-modules/spring-data-eclipselink</module>
909911
<module>persistence-modules/spring-data-solr</module>
910912
<module>persistence-modules/spring-hibernate-5</module>
913+
914+
<module>spring-boot-flowable</module>
911915
</modules>
912916

913917
</profile>

spring-boot-flowable/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Relevant articles
2+
3+
- [Introduction to Flowable](http://www.baeldung.com/flowable)

spring-boot-flowable/pom.xml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<artifactId>spring-boot-flowable</artifactId>
7+
<packaging>war</packaging>
8+
<name>spring-boot-flowable</name>
9+
<description>Spring Boot Flowable Module</description>
10+
<parent>
11+
<artifactId>parent-boot-2</artifactId>
12+
<groupId>com.baeldung</groupId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<relativePath>../parent-boot-2</relativePath>
15+
</parent>
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.springframework.boot</groupId>
19+
<artifactId>spring-boot-starter-web</artifactId>
20+
</dependency>
21+
<dependency>
22+
<groupId>com.h2database</groupId>
23+
<artifactId>h2</artifactId>
24+
<scope>runtime</scope>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.flowable</groupId>
28+
<artifactId>flowable-spring-boot-starter-rest</artifactId>
29+
<version>${flowable.version}</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.flowable</groupId>
33+
<artifactId>flowable-spring-boot-starter-actuator</artifactId>
34+
<version>${flowable.version}</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-starter-test</artifactId>
39+
<scope>test</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.junit.jupiter</groupId>
43+
<artifactId>junit-jupiter-engine</artifactId>
44+
<scope>test</scope>
45+
</dependency>
46+
</dependencies>
47+
<build>
48+
<plugins>
49+
<plugin>
50+
<groupId>org.springframework.boot</groupId>
51+
<artifactId>spring-boot-maven-plugin</artifactId>
52+
</plugin>
53+
</plugins>
54+
</build>
55+
<properties>
56+
<flowable.version>6.4.1</flowable.version>
57+
</properties>
58+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Application {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(Application.class, args);
11+
}
12+
13+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.baeldung.controller;
2+
3+
import java.util.List;
4+
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.PostMapping;
8+
import org.springframework.web.bind.annotation.RequestBody;
9+
import org.springframework.web.bind.annotation.RequestParam;
10+
import org.springframework.web.bind.annotation.RestController;
11+
12+
import com.baeldung.domain.Approval;
13+
import com.baeldung.domain.Article;
14+
import com.baeldung.service.ArticleWorkflowService;
15+
16+
@RestController
17+
public class ArticleWorkflowController {
18+
@Autowired
19+
private ArticleWorkflowService service;
20+
@PostMapping("/submit")
21+
public void submit(@RequestBody Article article) {
22+
service.startProcess(article);
23+
}
24+
@GetMapping("/tasks")
25+
public List<Article> getTasks(@RequestParam String assignee) {
26+
return service.getTasks(assignee);
27+
}
28+
@PostMapping("/review")
29+
public void review(@RequestBody Approval approval) {
30+
service.submitReview(approval);
31+
}
32+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.baeldung.domain;
2+
3+
public class Approval {
4+
5+
private String id;
6+
private boolean status;
7+
8+
public String getId() {
9+
return id;
10+
}
11+
12+
public void setId(String id) {
13+
this.id = id;
14+
}
15+
16+
public boolean isStatus() {
17+
return status;
18+
}
19+
20+
public void setStatus(boolean status) {
21+
this.status = status;
22+
}
23+
24+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.baeldung.domain;
2+
3+
public class Article {
4+
5+
private String id;
6+
private String author;
7+
private String url;
8+
9+
public Article() {
10+
}
11+
12+
public Article(String author, String url) {
13+
this.author = author;
14+
this.url = url;
15+
}
16+
17+
public Article(String id, String author, String url) {
18+
this.id = id;
19+
this.author = author;
20+
this.url = url;
21+
}
22+
23+
public String getId() {
24+
return id;
25+
}
26+
27+
public void setId(String id) {
28+
this.id = id;
29+
}
30+
31+
public String getAuthor() {
32+
return author;
33+
}
34+
35+
public void setAuthor(String author) {
36+
this.author = author;
37+
}
38+
39+
public String getUrl() {
40+
return url;
41+
}
42+
43+
public void setUrl(String url) {
44+
this.url = url;
45+
}
46+
47+
@Override
48+
public String toString() {
49+
return ("[" + this.author + " " + this.url + "]");
50+
}
51+
52+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.baeldung.service;
2+
3+
import java.util.HashMap;
4+
import java.util.List;
5+
import java.util.Map;
6+
import java.util.stream.Collectors;
7+
8+
import org.flowable.engine.RuntimeService;
9+
import org.flowable.engine.TaskService;
10+
import org.flowable.task.api.Task;
11+
import org.springframework.beans.factory.annotation.Autowired;
12+
import org.springframework.stereotype.Service;
13+
import org.springframework.transaction.annotation.Transactional;
14+
15+
import com.baeldung.domain.Approval;
16+
import com.baeldung.domain.Article;
17+
18+
@Service
19+
public class ArticleWorkflowService {
20+
@Autowired
21+
private RuntimeService runtimeService;
22+
@Autowired
23+
private TaskService taskService;
24+
25+
@Transactional
26+
public void startProcess(Article article) {
27+
Map<String, Object> variables = new HashMap<String, Object>();
28+
variables.put("author", article.getAuthor());
29+
variables.put("url", article.getUrl());
30+
runtimeService.startProcessInstanceByKey("articleReview", variables);
31+
}
32+
33+
@Transactional
34+
public List<Article> getTasks(String assignee) {
35+
List<Task> tasks = taskService.createTaskQuery()
36+
.taskCandidateGroup(assignee)
37+
.list();
38+
39+
List<Article> articles = tasks.stream()
40+
.map(task -> {
41+
Map<String, Object> variables = taskService.getVariables(task.getId());
42+
return new Article(
43+
task.getId(), (String) variables.get("author"), (String) variables.get("url"));
44+
})
45+
.collect(Collectors.toList());
46+
return articles;
47+
}
48+
49+
@Transactional
50+
public void submitReview(Approval approval) {
51+
Map<String, Object> variables = new HashMap<String, Object>();
52+
variables.put("approved", approval.isStatus());
53+
taskService.complete(approval.getId(), variables);
54+
}
55+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.baeldung.service;
2+
3+
import org.flowable.engine.delegate.DelegateExecution;
4+
import org.flowable.engine.delegate.JavaDelegate;
5+
6+
public class PublishArticleService implements JavaDelegate {
7+
public void execute(DelegateExecution execution) {
8+
System.out.println("Publishing the approved article.");
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.baeldung.service;
2+
3+
import org.flowable.engine.delegate.DelegateExecution;
4+
import org.flowable.engine.delegate.JavaDelegate;
5+
6+
public class SendMailService implements JavaDelegate {
7+
public void execute(DelegateExecution execution) {
8+
System.out.println("Sending rejection mail to author.");
9+
}
10+
}

0 commit comments

Comments
 (0)