-
Notifications
You must be signed in to change notification settings - Fork 58
/
model_helper.go
67 lines (61 loc) · 1.89 KB
/
model_helper.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
package BPMN20
import (
"html"
"strings"
)
func FindSequenceFlows(sequenceFlows *[]TSequenceFlow, ids []string) (ret []TSequenceFlow) {
for _, flow := range *sequenceFlows {
for _, id := range ids {
if id == flow.Id {
ret = append(ret, flow)
}
}
}
return ret
}
func FindSourceRefs(sequenceFlows []TSequenceFlow, id string) (ret []string) {
for _, flow := range sequenceFlows {
if id == flow.Id {
ret = append(ret, flow.SourceRef)
}
}
return
}
func FindBaseElementsById(definitions TDefinitions, id string) (elements []BaseElement) {
appender := func(element BaseElement) {
if element.GetId() == id {
elements = append(elements, element)
}
}
for _, task := range definitions.Process.ServiceTasks {
appender(task)
}
for _, endEvent := range definitions.Process.EndEvents {
appender(endEvent)
}
for _, parallelGateway := range definitions.Process.ParallelGateway {
appender(parallelGateway)
}
for _, exclusiveGateway := range definitions.Process.ExclusiveGateway {
appender(exclusiveGateway)
}
for _, intermediateCatchEvent := range definitions.Process.IntermediateCatchEvent {
appender(intermediateCatchEvent)
}
for _, eventBasedGateway := range definitions.Process.EventBasedGateway {
appender(eventBasedGateway)
}
for _, startEvent := range definitions.Process.StartEvents {
appender(startEvent)
}
return elements
}
// HasConditionExpression returns true, if there's exactly 1 expression present (as by the spec)
// and there's some non-whitespace-characters available
func (flow TSequenceFlow) HasConditionExpression() bool {
return len(flow.ConditionExpression) == 1 && len(strings.TrimSpace(flow.GetConditionExpression())) > 0
}
// GetConditionExpression returns the embedded expression. There will be a panic thrown, in case none exists!
func (flow TSequenceFlow) GetConditionExpression() string {
return html.UnescapeString(flow.ConditionExpression[0].Text)
}