├── .DS_Store
├── README.md
├── executor-service
├── .idea
│ ├── .gitignore
│ ├── codeStyles
│ │ ├── Project.xml
│ │ └── codeStyleConfig.xml
│ ├── compiler.xml
│ ├── google-java-format.xml
│ ├── misc.xml
│ ├── sbt.xml
│ ├── uiDesigner.xml
│ └── vcs.xml
├── README.md
├── executor-service.iml
├── logs
│ └── logs1.txt
├── output.txt
├── pom.xml
├── src
│ └── main
│ │ └── java
│ │ └── com
│ │ └── anurag
│ │ └── executor
│ │ ├── Application.java
│ │ ├── Exception.java
│ │ └── ExceptionFileProcessor.java
└── target
│ └── classes
│ └── com
│ └── anurag
│ └── executor
│ ├── Application.class
│ ├── Exception.class
│ └── ExceptionFileProcessor.class
├── flowable-tut
├── .gitignore
├── README.md
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── org
│ │ └── example
│ │ └── tut
│ │ └── flowable
│ │ ├── Application.java
│ │ ├── HolidayController.java
│ │ ├── HolidayService.java
│ │ ├── dto
│ │ ├── HolidayRequest.java
│ │ ├── ProcessInstanceResponse.java
│ │ └── TaskDetails.java
│ │ └── handler
│ │ ├── HolidayApprovalHandler.java
│ │ └── HolidayRejectionHandler.java
│ └── resources
│ ├── application-local.properties
│ └── holiday-request.bpmn20.xml
└── visitor
├── .gitignore
├── .idea
├── .gitignore
├── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── compiler.xml
├── google-java-format.xml
├── misc.xml
└── vcs.xml
├── pom.xml
├── src
└── main
│ └── java
│ └── org
│ └── example
│ └── visitor
│ ├── Application.java
│ ├── ClothItem.java
│ ├── FoodItem.java
│ ├── GroceryItem.java
│ ├── Item.java
│ ├── ItemType.java
│ ├── ItemVisitor.java
│ ├── ItemVisitorImpl.java
│ └── enumImpl
│ └── ItemType.java
├── target
└── classes
│ └── org
│ └── example
│ └── visitor
│ ├── Application$1.class
│ ├── Application.class
│ ├── ClothItem.class
│ ├── FoodItem.class
│ ├── GroceryItem.class
│ ├── Item.class
│ ├── ItemType.class
│ └── ItemVisitor.class
└── visitor.iml
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anuragsidana/java-tutorials/418ea182786e24730aa376aaceb571c503fd0198/.DS_Store
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # java-tutorials
2 | Java Lectures
3 |
4 | [Video Tutorials:](https://www.youtube.com/playlist?list=PLgkvQA5zy_iG_3PS0kSohWkmXE3Yxsqmi)
5 |
--------------------------------------------------------------------------------
/executor-service/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /workspace.xml
--------------------------------------------------------------------------------
/executor-service/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
9 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/executor-service/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/executor-service/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/executor-service/.idea/google-java-format.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/executor-service/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/executor-service/.idea/sbt.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/executor-service/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
8 | -
9 |
10 |
11 | -
12 |
13 |
14 | -
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 |
23 | -
24 |
25 |
26 |
27 |
28 |
29 | -
30 |
31 |
32 |
33 |
34 |
35 | -
36 |
37 |
38 |
39 |
40 |
41 | -
42 |
43 |
44 |
45 |
46 | -
47 |
48 |
49 |
50 |
51 | -
52 |
53 |
54 |
55 |
56 | -
57 |
58 |
59 |
60 |
61 | -
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 |
70 |
71 | -
72 |
73 |
74 | -
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
97 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/executor-service/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/executor-service/README.md:
--------------------------------------------------------------------------------
1 | Write a program which takes list of log files as input and outputs number of exceptions grouped by time range and exception type. At any moment x files should be processed simultaneously if more than x files are remaining. For input assume 20 log files and x(no of files to be processed simultaneously) to be 5.
2 |
3 | The format of the log file is as following:-
4 |
5 |
6 | requestId timeStamp text
7 |
8 | 586763334343 1523718907817 NullPointerException
9 |
10 | 586763434443 1523718907818 IllegalAgrumentsException
11 |
12 |
13 |
14 | The fields are separated by space. You can assume that the text field in the file contains only exception name and the file only contains exceptions. The output should be grouped by time range(15 mins) and exception type.
15 |
16 |
17 | For parallel processing use ExecutorService.
18 |
19 |
20 | Output Format:-
21 |
22 |
23 | 15:00-15:15 NullPointerException 30
24 |
25 | 15:00-15:15 IllegalAgrumentsException 25
--------------------------------------------------------------------------------
/executor-service/executor-service.iml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/executor-service/logs/logs1.txt:
--------------------------------------------------------------------------------
1 | requestId timeStamp text
2 | 586763334343 1523718907817 NullPointerException
3 | 586763334343 1523718907818 IllegalAgrumentsException
--------------------------------------------------------------------------------
/executor-service/output.txt:
--------------------------------------------------------------------------------
1 | Sat Apr 14 20:45:00 IST 2018-Sat Apr 14 21:00:00 IST 2018 NullPointerException 1
2 | Sat Apr 14 20:45:00 IST 2018-Sat Apr 14 21:00:00 IST 2018 IllegalAgrumentsException 1
3 |
--------------------------------------------------------------------------------
/executor-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.example
8 | executor-service
9 | 1.0-SNAPSHOT
10 |
11 |
12 |
13 | org.apache.maven.plugins
14 | maven-compiler-plugin
15 |
16 | 8
17 | 8
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | org.projectlombok
26 | lombok
27 | 1.18.4
28 | provided
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/executor-service/src/main/java/com/anurag/executor/Application.java:
--------------------------------------------------------------------------------
1 | package com.anurag.executor;
2 |
3 | import java.io.BufferedWriter;
4 | import java.io.File;
5 | import java.io.FileWriter;
6 | import java.io.IOException;
7 | import java.util.ArrayList;
8 | import java.util.List;
9 | import java.util.Map;
10 | import java.util.concurrent.ConcurrentHashMap;
11 | import java.util.concurrent.ExecutorService;
12 | import java.util.concurrent.Executors;
13 | import java.util.concurrent.atomic.AtomicInteger;
14 |
15 | public class Application {
16 |
17 | static ExecutorService executorService;
18 |
19 | static Map exceptionCountMap= new ConcurrentHashMap<>();
20 |
21 | public static void main(String[] args) throws InterruptedException, IOException {
22 |
23 | executorService=Executors.newFixedThreadPool(5);
24 |
25 |
26 | // getAll the files inside logs folder
27 |
28 | File file=new File("logs");
29 |
30 | file.listFiles();
31 |
32 | List exceptionFileProcessorList=new ArrayList();
33 |
34 | for(File curr:file.listFiles()){
35 |
36 | exceptionFileProcessorList.add(new ExceptionFileProcessor(curr,exceptionCountMap));
37 | }
38 |
39 |
40 | executorService.invokeAll(exceptionFileProcessorList);
41 |
42 | String formatExceptions = formatExceptions(exceptionCountMap);
43 |
44 | writeContentToFile("output.txt", formatExceptions);
45 |
46 | }
47 |
48 | private static String formatExceptions(Map exceptionCountMap) {
49 |
50 |
51 |
52 | String formattedString = "";
53 | for (Map.Entry currEntry : exceptionCountMap.entrySet()) {
54 | Exception currException = currEntry.getKey();
55 |
56 | formattedString +=
57 | currException.getLowerTimeBound() + "-" + currException.getUpperTimeBound() + " "
58 | + currException.getType() + " " + currEntry.getValue();
59 | formattedString += "\n";
60 |
61 | }
62 | System.out.println(formattedString);
63 | return formattedString;
64 |
65 | }
66 |
67 | private static void writeContentToFile(String fileName, String content) throws IOException {
68 |
69 | BufferedWriter output = null;
70 | try {
71 | File file = new File(fileName);
72 | output = new BufferedWriter(new FileWriter(file));
73 | output.write(content);
74 | } catch (IOException e) {
75 | e.printStackTrace();
76 | } finally {
77 | if (output != null) {
78 | output.close();
79 | }
80 | }
81 |
82 | }
83 |
84 |
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/executor-service/src/main/java/com/anurag/executor/Exception.java:
--------------------------------------------------------------------------------
1 | package com.anurag.executor;
2 |
3 | import java.util.Date;
4 | import java.util.Objects;
5 |
6 | import lombok.Getter;
7 |
8 | @Getter
9 | public class Exception {
10 |
11 | private final long timeRange = 15;
12 | private long timeStamp;
13 | private Date lowerTimeBound;
14 | private Date upperTimeBound;
15 | private String type;
16 | private String requestId;
17 |
18 | public Exception setTimeStamp(long timeStamp) {
19 | this.timeStamp = timeStamp;
20 | this.lowerTimeBound = getLowerTimeForGivenTimeRange(timeStamp, timeRange);
21 | this.upperTimeBound = new Date(this.lowerTimeBound.getTime() + timeRange * 60 * 1000);
22 | return this;
23 | }
24 |
25 | private Date getLowerTimeForGivenTimeRange(long timeMs, long range) {
26 | long time = Math.round(((double) timeMs / (double) (range * 60 * 1000))) * (range * 60 * 1000);
27 | return new Date(time);
28 | }
29 |
30 |
31 | public Exception setType(String type) {
32 | this.type = type;
33 | return this;
34 | }
35 |
36 |
37 | public Exception setRequestId(String requestId) {
38 | this.requestId = requestId;
39 | return this;
40 | }
41 |
42 | @Override
43 | public boolean equals(Object o) {
44 | if (this == o) {
45 | return true;
46 | }
47 | if (!(o instanceof Exception)) {
48 | return false;
49 | }
50 | Exception that = (Exception) o;
51 | return Objects.equals(getLowerTimeBound(), that.getLowerTimeBound()) &&
52 | Objects.equals(getType(), that.getType());
53 | }
54 |
55 | @Override
56 | public int hashCode() {
57 | return Objects.hash(getLowerTimeBound(), getType());
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/executor-service/src/main/java/com/anurag/executor/ExceptionFileProcessor.java:
--------------------------------------------------------------------------------
1 | package com.anurag.executor;
2 |
3 | import java.io.File;
4 | import java.io.FileNotFoundException;
5 | import java.util.Map;
6 | import java.util.Scanner;
7 | import java.util.concurrent.Callable;
8 | import java.util.concurrent.atomic.AtomicInteger;
9 |
10 | public class ExceptionFileProcessor implements Callable {
11 |
12 |
13 | private File file;
14 |
15 | private Map requestExceptionCount;
16 |
17 | public ExceptionFileProcessor(File file,
18 | Map requestExceptionCount) {
19 | this.file = file;
20 | this.requestExceptionCount = requestExceptionCount;
21 | }
22 |
23 |
24 | public Boolean call() throws FileNotFoundException {
25 |
26 | // process current file
27 |
28 | // process each line in the file
29 |
30 | // create the excpetion object
31 |
32 | // check if the object is already there in the global map
33 |
34 | // if there increment the count, if not then put with count 1
35 |
36 |
37 |
38 | Scanner sc = new Scanner(file);
39 | //skip header
40 | sc.nextLine();
41 | while (sc.hasNext()) {
42 | String[] currError = sc.nextLine().split(" ");
43 |
44 | Exception exception = new Exception()
45 | .setRequestId(currError[0])
46 | .setTimeStamp(Long.parseLong(currError[1]))
47 | .setType(currError[2]);
48 |
49 | requestExceptionCount.putIfAbsent(exception, new AtomicInteger(0));
50 | requestExceptionCount.get(exception).getAndIncrement();
51 | }
52 |
53 | return true;
54 | }
55 |
56 |
57 |
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/executor-service/target/classes/com/anurag/executor/Application.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anuragsidana/java-tutorials/418ea182786e24730aa376aaceb571c503fd0198/executor-service/target/classes/com/anurag/executor/Application.class
--------------------------------------------------------------------------------
/executor-service/target/classes/com/anurag/executor/Exception.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anuragsidana/java-tutorials/418ea182786e24730aa376aaceb571c503fd0198/executor-service/target/classes/com/anurag/executor/Exception.class
--------------------------------------------------------------------------------
/executor-service/target/classes/com/anurag/executor/ExceptionFileProcessor.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anuragsidana/java-tutorials/418ea182786e24730aa376aaceb571c503fd0198/executor-service/target/classes/com/anurag/executor/ExceptionFileProcessor.class
--------------------------------------------------------------------------------
/flowable-tut/.gitignore:
--------------------------------------------------------------------------------
1 | *#
2 | *.iml
3 | *.ipr
4 | *.iws
5 | *.jar
6 | *.sw?
7 | *~
8 | .#*
9 | .*.md.html
10 | .DS_Store
11 | .classpath
12 | .factorypath
13 | .gradle
14 | .idea
15 | .metadata
16 | .project
17 | .recommenders
18 | .settings
19 | .springBeans
20 | /code
21 | MANIFEST.MF
22 | _site/
23 | activemq-data
24 | bin
25 | build
26 | !/**/src/**/bin
27 | !/**/src/**/build
28 | build.log
29 | dependency-reduced-pom.xml
30 | dump.rdb
31 | interpolated*.xml
32 | lib/
33 | manifest.yml
34 | out
35 | overridedb.*
36 | target
37 | transaction-logs
38 | .flattened-pom.xml
39 | secrets.yml
40 | .gradletasknamecache
41 | .sts4-cache
--------------------------------------------------------------------------------
/flowable-tut/README.md:
--------------------------------------------------------------------------------
1 | # Implementation of flowable-engine using spring boot
2 |
3 | [Video Tutorial](https://youtu.be/SBTifzavMaM)
4 |
--------------------------------------------------------------------------------
/flowable-tut/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.example
8 | flowable-tut
9 | 1.0-SNAPSHOT
10 |
11 |
12 |
13 | org.springframework.boot
14 | spring-boot-starter-web
15 | 2.1.3.RELEASE
16 |
17 |
18 | org.flowable
19 | flowable-spring-boot-starter
20 | 6.4.1
21 |
22 |
23 | com.h2database
24 | h2
25 | runtime
26 | 2.0.206
27 |
28 |
29 | org.projectlombok
30 | lombok
31 | 1.18.12
32 |
33 |
34 |
35 |
36 |
37 |
38 | org.apache.maven.plugins
39 | maven-compiler-plugin
40 |
41 | 1.8
42 | 1.8
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/flowable-tut/src/main/java/org/example/tut/flowable/Application.java:
--------------------------------------------------------------------------------
1 | package org.example.tut.flowable;
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 | }
14 |
--------------------------------------------------------------------------------
/flowable-tut/src/main/java/org/example/tut/flowable/HolidayController.java:
--------------------------------------------------------------------------------
1 | package org.example.tut.flowable;
2 |
3 | import java.util.List;
4 |
5 | import lombok.AccessLevel;
6 | import lombok.AllArgsConstructor;
7 | import lombok.experimental.FieldDefaults;
8 | import org.example.tut.flowable.dto.HolidayRequest;
9 | import org.example.tut.flowable.dto.ProcessInstanceResponse;
10 | import org.example.tut.flowable.dto.TaskDetails;
11 | import org.springframework.web.bind.annotation.GetMapping;
12 | import org.springframework.web.bind.annotation.PathVariable;
13 | import org.springframework.web.bind.annotation.PostMapping;
14 | import org.springframework.web.bind.annotation.RequestBody;
15 | import org.springframework.web.bind.annotation.RestController;
16 |
17 | @RestController
18 | @FieldDefaults(level = AccessLevel.PRIVATE)
19 | @AllArgsConstructor
20 | public class HolidayController {
21 |
22 | HolidayService holidayService;
23 |
24 | //********************************************************** deployment endpoints **********************************************************
25 | @PostMapping("/deploy")
26 | public void deployWorkflow() {
27 | holidayService.deployProcessDefinition();
28 | }
29 |
30 | //********************************************************** process endpoints **********************************************************
31 | @PostMapping("/holiday/apply")
32 | public ProcessInstanceResponse applyHoliday(@RequestBody HolidayRequest holidayRequest) {
33 | return holidayService.applyHoliday(holidayRequest);
34 | }
35 |
36 |
37 | @GetMapping("/manager/tasks")
38 | public List getTasks() {
39 | return holidayService.getManagerTasks();
40 | }
41 |
42 |
43 | @PostMapping("/manager/approve/tasks/{taskId}/{approved}")
44 | public void approveTask(@PathVariable("taskId") String taskId,@PathVariable("approved") Boolean approved){
45 | holidayService.approveHoliday(taskId,approved);
46 | }
47 |
48 | @PostMapping("/user/accept/{taskId}")
49 | public void acceptHoliday(@PathVariable("taskId") String taskId){
50 | holidayService.acceptHoliday(taskId);
51 | }
52 |
53 | @GetMapping("/user/tasks")
54 | public List getUserTasks() {
55 | return holidayService.getUserTasks();
56 | }
57 |
58 |
59 | @GetMapping("/process/{processId}")
60 | public void checkState(@PathVariable("processId") String processId){
61 | holidayService.checkProcessHistory(processId);
62 | }
63 |
64 |
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/flowable-tut/src/main/java/org/example/tut/flowable/HolidayService.java:
--------------------------------------------------------------------------------
1 | package org.example.tut.flowable;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | import lombok.AccessLevel;
9 | import lombok.AllArgsConstructor;
10 | import lombok.experimental.FieldDefaults;
11 | import org.example.tut.flowable.dto.HolidayRequest;
12 | import org.example.tut.flowable.dto.ProcessInstanceResponse;
13 | import org.example.tut.flowable.dto.TaskDetails;
14 | import org.flowable.engine.HistoryService;
15 | import org.flowable.engine.ProcessEngine;
16 | import org.flowable.engine.RepositoryService;
17 | import org.flowable.engine.RuntimeService;
18 | import org.flowable.engine.TaskService;
19 | import org.flowable.engine.history.HistoricActivityInstance;
20 | import org.flowable.engine.repository.Deployment;
21 | import org.flowable.engine.runtime.ProcessInstance;
22 | import org.flowable.task.api.Task;
23 | import org.springframework.beans.factory.annotation.Autowired;
24 | import org.springframework.stereotype.Service;
25 |
26 | @Service
27 | @FieldDefaults(level = AccessLevel.PRIVATE)
28 | @AllArgsConstructor(onConstructor = @__(@Autowired))
29 | public class HolidayService {
30 |
31 | public static final String TASK_CANDIDATE_GROUP = "managers";
32 | public static final String PROCESS_DEFINITION_KEY = "holidayRequest";
33 | public static final String EMP_NAME = "empName";
34 | RuntimeService runtimeService;
35 | TaskService taskService;
36 | ProcessEngine processEngine;
37 | RepositoryService repositoryService;
38 |
39 | //********************************************************** deployment service methods **********************************************************
40 |
41 | public void deployProcessDefinition() {
42 |
43 | Deployment deployment =
44 | repositoryService
45 | .createDeployment()
46 | .addClasspathResource("holiday-request.bpmn20.xml")
47 | .deploy();
48 |
49 |
50 | }
51 |
52 |
53 | //********************************************************** process service methods **********************************************************
54 |
55 | public ProcessInstanceResponse applyHoliday(HolidayRequest holidayRequest) {
56 |
57 | Map variables = new HashMap();
58 | variables.put("employee", holidayRequest.getEmpName());
59 | variables.put("noOfHolidays", holidayRequest.getNoOfHolidays());
60 | variables.put("description", holidayRequest.getRequestDescription());
61 |
62 | ProcessInstance processInstance =
63 | runtimeService.startProcessInstanceByKey(PROCESS_DEFINITION_KEY, variables);
64 |
65 | return new ProcessInstanceResponse(processInstance.getId(), processInstance.isEnded());
66 | }
67 |
68 |
69 | public List getManagerTasks() {
70 | List tasks =
71 | taskService.createTaskQuery().taskCandidateGroup(TASK_CANDIDATE_GROUP).list();
72 | List taskDetails = getTaskDetails(tasks);
73 |
74 | return taskDetails;
75 | }
76 |
77 | private List getTaskDetails(List tasks) {
78 | List taskDetails = new ArrayList<>();
79 | for (Task task : tasks) {
80 | Map processVariables = taskService.getVariables(task.getId());
81 | taskDetails.add(new TaskDetails(task.getId(), task.getName(), processVariables));
82 | }
83 | return taskDetails;
84 | }
85 |
86 |
87 | public void approveHoliday(String taskId,Boolean approved) {
88 |
89 | Map variables = new HashMap();
90 | variables.put("approved", approved.booleanValue());
91 | taskService.complete(taskId, variables);
92 | }
93 |
94 | public void acceptHoliday(String taskId) {
95 | taskService.complete(taskId);
96 | }
97 |
98 |
99 | public List getUserTasks() {
100 |
101 | List tasks = taskService.createTaskQuery().taskCandidateOrAssigned(EMP_NAME).list();
102 | List taskDetails = getTaskDetails(tasks);
103 |
104 | return taskDetails;
105 | }
106 |
107 |
108 | public void checkProcessHistory(String processId) {
109 |
110 | HistoryService historyService = processEngine.getHistoryService();
111 |
112 | List activities =
113 | historyService
114 | .createHistoricActivityInstanceQuery()
115 | .processInstanceId(processId)
116 | .finished()
117 | .orderByHistoricActivityInstanceEndTime()
118 | .asc()
119 | .list();
120 |
121 | for (HistoricActivityInstance activity : activities) {
122 | System.out.println(
123 | activity.getActivityId() + " took " + activity.getDurationInMillis() + " milliseconds");
124 | }
125 |
126 | System.out.println("\n \n \n \n");
127 | }
128 |
129 | }
130 |
--------------------------------------------------------------------------------
/flowable-tut/src/main/java/org/example/tut/flowable/dto/HolidayRequest.java:
--------------------------------------------------------------------------------
1 | package org.example.tut.flowable.dto;
2 |
3 | import lombok.Data;
4 |
5 | @Data
6 | public class HolidayRequest {
7 |
8 | String empName;
9 |
10 | Long noOfHolidays;
11 |
12 | String requestDescription;
13 |
14 |
15 | }
--------------------------------------------------------------------------------
/flowable-tut/src/main/java/org/example/tut/flowable/dto/ProcessInstanceResponse.java:
--------------------------------------------------------------------------------
1 | package org.example.tut.flowable.dto;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Value;
5 |
6 | @Value
7 | @AllArgsConstructor
8 | public class ProcessInstanceResponse {
9 | String processId;
10 | boolean isEnded;
11 | }
12 |
--------------------------------------------------------------------------------
/flowable-tut/src/main/java/org/example/tut/flowable/dto/TaskDetails.java:
--------------------------------------------------------------------------------
1 | package org.example.tut.flowable.dto;
2 |
3 | import java.util.Map;
4 |
5 | import lombok.AllArgsConstructor;
6 | import lombok.Data;
7 |
8 | @Data
9 | @AllArgsConstructor
10 | public class TaskDetails {
11 |
12 | String taskId;
13 | String taskName;
14 | Map taskData;
15 | }
16 |
--------------------------------------------------------------------------------
/flowable-tut/src/main/java/org/example/tut/flowable/handler/HolidayApprovalHandler.java:
--------------------------------------------------------------------------------
1 | package org.example.tut.flowable.handler;
2 |
3 | import lombok.Data;
4 | import org.flowable.engine.delegate.DelegateExecution;
5 | import org.flowable.engine.delegate.JavaDelegate;
6 |
7 | @Data
8 | public class HolidayApprovalHandler implements JavaDelegate {
9 |
10 | @Override
11 | public void execute(DelegateExecution execution) {
12 |
13 | System.out.println("Approved, sending an email");
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/flowable-tut/src/main/java/org/example/tut/flowable/handler/HolidayRejectionHandler.java:
--------------------------------------------------------------------------------
1 | package org.example.tut.flowable.handler;
2 |
3 | import lombok.Data;
4 | import lombok.extern.slf4j.Slf4j;
5 | import org.flowable.engine.delegate.DelegateExecution;
6 | import org.flowable.engine.delegate.JavaDelegate;
7 |
8 | @Data
9 | @Slf4j
10 | public class HolidayRejectionHandler implements JavaDelegate {
11 | @Override
12 | public void execute(DelegateExecution execution) {
13 |
14 | log.info("Holiday has been rejected, sending an email ");
15 |
16 | }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/flowable-tut/src/main/resources/application-local.properties:
--------------------------------------------------------------------------------
1 | spring.h2.console.enabled=true
2 |
3 | #h2 db url: jdbc:h2:mem:test
4 |
--------------------------------------------------------------------------------
/flowable-tut/src/main/resources/holiday-request.bpmn20.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
23 |
24 |
25 |
26 |
27 |
30 |
31 |
32 |
33 |
35 |
36 |
37 |
38 |
39 |
40 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/visitor/.gitignore:
--------------------------------------------------------------------------------
1 | *#
2 | *.iml
3 | *.ipr
4 | *.iws
5 | *.jar
6 | *.sw?
7 | *~
8 | .#*
9 | .*.md.html
10 | .DS_Store
11 | .classpath
12 | target
13 | .factorypath
14 | .gradle
15 | .idea
16 | .metadata
17 | .project
18 | .recommenders
19 | .settings
20 | .springBeans
21 | /code
22 | MANIFEST.MF
23 | _site/
24 | activemq-data
25 | bin
26 | build
27 | !/**/src/**/bin
28 | !/**/src/**/build
29 | build.log
30 | dependency-reduced-pom.xml
31 | dump.rdb
32 | interpolated*.xml
33 | lib/
34 | manifest.yml
35 | out
36 | overridedb.*
37 | target
38 | transaction-logs
39 | .flattened-pom.xml
40 | secrets.yml
41 | .gradletasknamecache
42 | .sts4-cache
--------------------------------------------------------------------------------
/visitor/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /workspace.xml
--------------------------------------------------------------------------------
/visitor/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/visitor/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/visitor/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/visitor/.idea/google-java-format.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/visitor/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/visitor/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/visitor/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.example
8 | visitor
9 | 1.0-SNAPSHOT
10 |
11 |
12 | 2.10.5.1
13 |
14 |
15 |
16 | com.fasterxml.jackson.core
17 | jackson-databind
18 | ${jackson.version}
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/visitor/src/main/java/org/example/visitor/Application.java:
--------------------------------------------------------------------------------
1 | package org.example.visitor;
2 |
3 | public class Application {
4 |
5 | public static void main(String[] args) {
6 |
7 | FoodItem foodItem = new FoodItem();
8 | GroceryItem groceryItem = new GroceryItem();
9 | ClothItem clothItem = new ClothItem();
10 |
11 | testVisitor(foodItem);
12 | testVisitor(groceryItem);
13 | testVisitor(clothItem);
14 | }
15 |
16 | // This method doesn't know whether this item param is of Cloth, food or Grocery type
17 | private static void testVisitor(Item item) {
18 | item.accept(
19 | new ItemVisitor