BAEL-20869 Move remaining spring boot modules
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package com.baeldung;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.baeldung.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.baeldung.domain.Approval;
|
||||
import com.baeldung.domain.Article;
|
||||
import com.baeldung.service.ArticleWorkflowService;
|
||||
|
||||
@RestController
|
||||
public class ArticleWorkflowController {
|
||||
@Autowired
|
||||
private ArticleWorkflowService service;
|
||||
@PostMapping("/submit")
|
||||
public void submit(@RequestBody Article article) {
|
||||
service.startProcess(article);
|
||||
}
|
||||
@GetMapping("/tasks")
|
||||
public List<Article> getTasks(@RequestParam String assignee) {
|
||||
return service.getTasks(assignee);
|
||||
}
|
||||
@PostMapping("/review")
|
||||
public void review(@RequestBody Approval approval) {
|
||||
service.submitReview(approval);
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.domain;
|
||||
|
||||
public class Approval {
|
||||
|
||||
private String id;
|
||||
private boolean status;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public boolean isStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(boolean status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package com.baeldung.domain;
|
||||
|
||||
public class Article {
|
||||
|
||||
private String id;
|
||||
private String author;
|
||||
private String url;
|
||||
|
||||
public Article() {
|
||||
}
|
||||
|
||||
public Article(String author, String url) {
|
||||
this.author = author;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public Article(String id, String author, String url) {
|
||||
this.id = id;
|
||||
this.author = author;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ("[" + this.author + " " + this.url + "]");
|
||||
}
|
||||
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.baeldung.service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.flowable.engine.RuntimeService;
|
||||
import org.flowable.engine.TaskService;
|
||||
import org.flowable.task.api.Task;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.baeldung.domain.Approval;
|
||||
import com.baeldung.domain.Article;
|
||||
|
||||
@Service
|
||||
public class ArticleWorkflowService {
|
||||
@Autowired
|
||||
private RuntimeService runtimeService;
|
||||
@Autowired
|
||||
private TaskService taskService;
|
||||
|
||||
@Transactional
|
||||
public void startProcess(Article article) {
|
||||
Map<String, Object> variables = new HashMap<String, Object>();
|
||||
variables.put("author", article.getAuthor());
|
||||
variables.put("url", article.getUrl());
|
||||
runtimeService.startProcessInstanceByKey("articleReview", variables);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<Article> getTasks(String assignee) {
|
||||
List<Task> tasks = taskService.createTaskQuery()
|
||||
.taskCandidateGroup(assignee)
|
||||
.list();
|
||||
|
||||
List<Article> articles = tasks.stream()
|
||||
.map(task -> {
|
||||
Map<String, Object> variables = taskService.getVariables(task.getId());
|
||||
return new Article(
|
||||
task.getId(), (String) variables.get("author"), (String) variables.get("url"));
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
return articles;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void submitReview(Approval approval) {
|
||||
Map<String, Object> variables = new HashMap<String, Object>();
|
||||
variables.put("approved", approval.isStatus());
|
||||
taskService.complete(approval.getId(), variables);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.baeldung.service;
|
||||
|
||||
import org.flowable.engine.delegate.DelegateExecution;
|
||||
import org.flowable.engine.delegate.JavaDelegate;
|
||||
|
||||
public class PublishArticleService implements JavaDelegate {
|
||||
public void execute(DelegateExecution execution) {
|
||||
System.out.println("Publishing the approved article.");
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.baeldung.service;
|
||||
|
||||
import org.flowable.engine.delegate.DelegateExecution;
|
||||
import org.flowable.engine.delegate.JavaDelegate;
|
||||
|
||||
public class SendMailService implements JavaDelegate {
|
||||
public void execute(DelegateExecution execution) {
|
||||
System.out.println("Sending rejection mail to author.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user