-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflow_wiring.go
155 lines (140 loc) · 4.88 KB
/
flow_wiring.go
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
/*
Copyright 2023 The bpmn Authors
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library;
*/
package bpmn
import (
"fmt"
"sync"
"github.com/olive-io/bpmn/schema"
"github.com/olive-io/bpmn/v2/pkg/data"
"github.com/olive-io/bpmn/v2/pkg/errors"
"github.com/olive-io/bpmn/v2/pkg/event"
"github.com/olive-io/bpmn/v2/pkg/id"
"github.com/olive-io/bpmn/v2/pkg/tracing"
)
// Wiring holds all necessary "wiring" for functioning of
// flow nodes: definitions, process, sequence flow, event management,
// tracer, flow node mapping and a flow wait group
type Wiring struct {
ProcessInstanceId id.Id
FlowNodeId schema.Id
Definitions *schema.Definitions
Incoming []SequenceFlow
Outgoing []SequenceFlow
EventIngress event.IConsumer
EventEgress event.ISource
Tracer tracing.ITracer
Process schema.Element
FlowNodeMapping *FlowNodeMapping
FlowWaitGroup *sync.WaitGroup
EventDefinitionInstanceBuilder event.IDefinitionInstanceBuilder
Locator data.IFlowDataLocator
}
func sequenceFlows(process schema.Element,
flows *[]schema.QName) (result []SequenceFlow, err error) {
result = make([]SequenceFlow, len(*flows))
for i := range result {
identifier := (*flows)[i]
exactId := schema.ExactId(string(identifier))
if element, found := process.FindBy(func(e schema.Element) bool {
_, ok := e.(*schema.SequenceFlow)
return ok && exactId(e)
}); found {
result[i] = MakeSequenceFlow(element.(*schema.SequenceFlow), process)
} else {
err = errors.NotFoundError{Expected: identifier}
return
}
}
return
}
func NewWiring(
processInstanceId id.Id,
process schema.Element,
definitions *schema.Definitions,
flowNode *schema.FlowNode,
eventIngress event.IConsumer,
eventEgress event.ISource,
tracer tracing.ITracer,
flowNodeMapping *FlowNodeMapping,
flowWaitGroup *sync.WaitGroup,
eventDefinitionInstanceBuilder event.IDefinitionInstanceBuilder,
locator data.IFlowDataLocator,
) (node *Wiring, err error) {
incoming, err := sequenceFlows(process, flowNode.Incomings())
if err != nil {
return
}
outgoing, err := sequenceFlows(process, flowNode.Outgoings())
if err != nil {
return
}
ownIdPtr, present := flowNode.Id()
if !present {
err = errors.NotFoundError{
Expected: fmt.Sprintf("flow node %#v to have an ID", flowNode),
}
return
}
ownId := *ownIdPtr
node = &Wiring{
ProcessInstanceId: processInstanceId,
FlowNodeId: ownId,
Definitions: definitions,
Incoming: incoming,
Outgoing: outgoing,
EventIngress: eventIngress,
EventEgress: eventEgress,
Tracer: tracer,
Process: process,
FlowNodeMapping: flowNodeMapping,
FlowWaitGroup: flowWaitGroup,
EventDefinitionInstanceBuilder: eventDefinitionInstanceBuilder,
Locator: locator,
}
return
}
// CloneFor copies receiver, overriding FlowNodeId, Incoming, Outgoing for a given flowNode
func (wiring *Wiring) CloneFor(flowNode *schema.FlowNode) (result *Wiring, err error) {
incoming, err := sequenceFlows(wiring.Process, flowNode.Incomings())
if err != nil {
return
}
outgoing, err := sequenceFlows(wiring.Process, flowNode.Outgoings())
if err != nil {
return
}
ownIdPtr, present := flowNode.Id()
if !present {
err = errors.NotFoundError{
Expected: fmt.Sprintf("flow node %#v to have an ID", flowNode),
}
return
}
ownId := *ownIdPtr
result = &Wiring{
ProcessInstanceId: wiring.ProcessInstanceId,
FlowNodeId: ownId,
Definitions: wiring.Definitions,
Incoming: incoming,
Outgoing: outgoing,
EventIngress: wiring.EventIngress,
EventEgress: wiring.EventEgress,
Tracer: wiring.Tracer,
Process: wiring.Process,
FlowNodeMapping: wiring.FlowNodeMapping,
FlowWaitGroup: wiring.FlowWaitGroup,
EventDefinitionInstanceBuilder: wiring.EventDefinitionInstanceBuilder,
}
return
}