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.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
management.endpoint.flowable.enabled=true
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<definitions
|
||||
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
|
||||
xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
|
||||
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"
|
||||
xmlns:flowable="http://flowable.org/bpmn"
|
||||
typeLanguage="http://www.w3.org/2001/XMLSchema"
|
||||
expressionLanguage="http://www.w3.org/1999/XPath"
|
||||
targetNamespace="http://www.flowable.org/processdef">
|
||||
<process id="articleReview"
|
||||
name="A simple process for article review." isExecutable="true">
|
||||
<startEvent id="start" />
|
||||
<sequenceFlow sourceRef="start" targetRef="reviewArticle" />
|
||||
<userTask id="reviewArticle"
|
||||
name="Review the submitted tutorial"
|
||||
flowable:candidateGroups="editors" />
|
||||
<sequenceFlow sourceRef="reviewArticle"
|
||||
targetRef="decision" />
|
||||
<exclusiveGateway id="decision" />
|
||||
<sequenceFlow sourceRef="decision"
|
||||
targetRef="tutorialApproved">
|
||||
<conditionExpression xsi:type="tFormalExpression">
|
||||
<![CDATA[
|
||||
${approved}
|
||||
]]>
|
||||
</conditionExpression>
|
||||
</sequenceFlow>
|
||||
<sequenceFlow sourceRef="decision"
|
||||
targetRef="tutorialRejected">
|
||||
<conditionExpression xsi:type="tFormalExpression">
|
||||
<![CDATA[
|
||||
${!approved}
|
||||
]]>
|
||||
</conditionExpression>
|
||||
</sequenceFlow>
|
||||
<serviceTask id="tutorialApproved"
|
||||
name="Publish the approved tutorial."
|
||||
flowable:class="com.baeldung.service.PublishArticleService" />
|
||||
<sequenceFlow sourceRef="tutorialApproved"
|
||||
targetRef="end" />
|
||||
<serviceTask id="tutorialRejected"
|
||||
name="Send out rejection email"
|
||||
flowable:class="com.baeldung.service.SendMailService" />
|
||||
<sequenceFlow sourceRef="tutorialRejected"
|
||||
targetRef="end" />
|
||||
<endEvent id="end" />
|
||||
</process>
|
||||
</definitions>
|
||||
Reference in New Issue
Block a user