-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathactiivty.go
More file actions
164 lines (139 loc) · 6.46 KB
/
Copy pathactiivty.go
File metadata and controls
164 lines (139 loc) · 6.46 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package bpmn_engine
import (
"github.com/nitram509/lib-bpmn-engine/pkg/spec/BPMN20"
"slices"
)
// ActivityState as per BPMN 2.0 spec, section 13.2.2 Activity, page 428, State diagram:
//
// (Inactive)
// O
// |
// A Token v
// Arrives ┌─────┐
// │Ready│
// └─────┘
// v Activity Interrupted An Alternative Path For
// O -------------------------------------->O----------------------------+
// Data InputSet v | Event Gateway Selected |
// Available ┌──────┐ Interrupting| |
// │Active│ Event | |
// └──────┘ | v
// v Activity Interrupted v An Alternative Path For┌─────────┐
// O -------------------------------------->O ---------------------->│Withdrawn│
// Activity's work v | Event Gateway Selected └─────────┘
// completed ┌──────────┐ Interrupting| |
// │Completing│ Event | The Process|
// └──────────┘ | Ends |
// v Activity Interrupted v Non-Error |
// Completing O -------------------------------------->O--------------+ |
// Requirements Done v Error v v |
// Assignments ┌─────────┐ ┌───────┐ ┌───────────┐ |
// Completed │Completed│ │Failing│ │Terminating│ |
// └─────────┘ └───────┘ └───────────┘ |
// v Compensation ┌────────────┐ v v |
// O ------------->│Compensating│ O <-------------O Terminating |
// | Occurs └────────────┘ v v Requirements Done
// The Process | Compensation v Compensation | ┌──────────┐ |
// Ends | +--------------O----------------/|\--------->│Terminated│ |
// | | Completes | Interrupted | └──────────┘ |
// | v | v | |
// | ┌───────────┐ |Compensation┌──────┐ | |
// | │Compensated│ +----------->│Failed│ | |
// | └─────┬─────┘ Failed └──────┘ | |
// | | | | |
// v / The Process Ends / Process Ends / |
// O<--------------------------------------------------------------------+
// (Closed)
type ActivityState string
const (
Active ActivityState = "ACTIVE"
Compensated ActivityState = "COMPENSATED"
Compensating ActivityState = "COMPENSATING"
Completed ActivityState = "COMPLETED"
Completing ActivityState = "COMPLETING"
Failed ActivityState = "FAILED"
Failing ActivityState = "FAILING"
Ready ActivityState = "READY"
Terminated ActivityState = "TERMINATED"
Terminating ActivityState = "TERMINATING"
Withdrawn ActivityState = "WITHDRAWN"
)
type activity interface {
Key() int64
State() ActivityState
SetState(state ActivityState)
Element() *BPMN20.BaseElement
}
type elementActivity struct {
key int64
state ActivityState
element *BPMN20.BaseElement
}
func (a elementActivity) Key() int64 {
return a.key
}
func (a elementActivity) State() ActivityState {
return a.state
}
func (a *elementActivity) SetState(state ActivityState) {
a.state = state
}
func (a elementActivity) Element() *BPMN20.BaseElement {
return a.element
}
// -------------------------------------------------------------------------
type gatewayActivity struct {
key int64
state ActivityState
element *BPMN20.BaseElement
parallel bool
inboundFlowIdsCompleted []string
}
func (ga *gatewayActivity) Key() int64 {
return ga.key
}
func (ga *gatewayActivity) State() ActivityState {
return ga.state
}
func (ga *gatewayActivity) Element() *BPMN20.BaseElement {
return ga.element
}
func (ga *gatewayActivity) AreInboundFlowsCompleted() bool {
for _, association := range (*ga.element).GetIncomingAssociation() {
if !slices.Contains(ga.inboundFlowIdsCompleted, association) {
return false
}
}
return true
}
func (ga *gatewayActivity) SetInboundFlowCompleted(flowId string) {
ga.inboundFlowIdsCompleted = append(ga.inboundFlowIdsCompleted, flowId)
}
func (ga *gatewayActivity) SetState(state ActivityState) {
ga.state = state
}
// -------------------------------------------------------------------------
type eventBasedGatewayActivity struct {
key int64
state ActivityState
element *BPMN20.BaseElement
OutboundActivityCompleted string
}
func (ebg *eventBasedGatewayActivity) Key() int64 {
return ebg.key
}
func (ebg *eventBasedGatewayActivity) State() ActivityState {
return ebg.state
}
func (ebg *eventBasedGatewayActivity) SetState(state ActivityState) {
ebg.state = state
}
func (ebg *eventBasedGatewayActivity) Element() *BPMN20.BaseElement {
return ebg.element
}
func (ebg *eventBasedGatewayActivity) SetOutboundCompleted(id string) {
ebg.OutboundActivityCompleted = id
}
func (ebg *eventBasedGatewayActivity) OutboundCompleted() bool {
return len(ebg.OutboundActivityCompleted) > 0
}