This repository has been archived by the owner on Aug 31, 2020. It is now read-only.
forked from hooopo/petri_flow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkflow_seed.rb
126 lines (116 loc) · 6.03 KB
/
workflow_seed.rb
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
# frozen_string_literal: true
Wf::Workflow.destroy_all
Wf::Case.destroy_all
Wf::Transition.destroy_all
Wf::Place.destroy_all
Wf::Arc.destroy_all
Wf::Form.destroy_all
form = Wf::Form.create(name: "From One")
name_field = form.fields.create!(name: :name, field_type: :string)
age_field = form.fields.create!(name: :age, field_type: :integer)
proc do
seq = Wf::Workflow.create(name: "Seq Workflow")
s = seq.places.create!(place_type: :start, name: "start")
e = seq.places.create!(place_type: :end, name: "end")
p = seq.places.create!(place_type: :normal, name: "p")
t1 = seq.transitions.create!(name: "t1")
t2 = seq.transitions.create!(name: "t2")
arc1 = seq.arcs.create!(direction: :in, transition: t1, place: s)
arc2 = seq.arcs.create!(direction: :out, transition: t1, place: p)
arc3 = seq.arcs.create!(direction: :in, transition: t2, place: p)
arc4 = seq.arcs.create!(direction: :out, transition: t2, place: e)
end.call
proc do
seq = Wf::Workflow.create(name: "Workflow with automatic transition")
s = seq.places.create!(place_type: :start, name: "start")
e = seq.places.create!(place_type: :end, name: "end")
p = seq.places.create!(place_type: :normal, name: "p")
t1 = seq.transitions.create!(name: "t1")
t2 = seq.transitions.create!(name: "t2", trigger_type: :automatic)
arc1 = seq.arcs.create!(direction: :in, transition: t1, place: s)
arc2 = seq.arcs.create!(direction: :out, transition: t1, place: p)
arc3 = seq.arcs.create!(direction: :in, transition: t2, place: p)
arc4 = seq.arcs.create!(direction: :out, transition: t2, place: e)
end.call
proc do
seq = Wf::Workflow.create(name: "Workflow with timed transition")
s = seq.places.create!(place_type: :start, name: "start")
e = seq.places.create!(place_type: :end, name: "end")
p = seq.places.create!(place_type: :normal, name: "p")
t1 = seq.transitions.create!(name: "t1")
t2 = seq.transitions.create!(name: "t2", trigger_type: :time, trigger_limit: 1)
arc1 = seq.arcs.create!(direction: :in, transition: t1, place: s)
arc2 = seq.arcs.create!(direction: :out, transition: t1, place: p)
arc3 = seq.arcs.create!(direction: :in, transition: t2, place: p)
arc4 = seq.arcs.create!(direction: :out, transition: t2, place: e)
end.call
proc do
seq = Wf::Workflow.create(name: "Workflow with timed split")
s = seq.places.create!(place_type: :start, name: "start")
e = seq.places.create!(place_type: :end, name: "end")
p = seq.places.create!(place_type: :normal, name: "p")
t1 = seq.transitions.create!(name: "t1")
t2 = seq.transitions.create!(name: "t2")
t3 = seq.transitions.create!(name: "t3", trigger_type: :time, trigger_limit: 1)
arc1 = seq.arcs.create!(direction: :in, transition: t1, place: s)
arc2 = seq.arcs.create!(direction: :in, transition: t3, place: s)
arc3 = seq.arcs.create!(direction: :out, transition: t1, place: p)
arc4 = seq.arcs.create!(direction: :in, transition: t2, place: p)
arc5 = seq.arcs.create!(direction: :out, transition: t2, place: e)
arc6 = seq.arcs.create!(direction: :out, transition: t3, place: e)
end.call
proc do
seq = Wf::Workflow.create(name: "Workflow with guard")
s = seq.places.create!(place_type: :start, name: "start")
e = seq.places.create!(place_type: :end, name: "end")
p1 = seq.places.create!(place_type: :normal, name: "p1")
p2 = seq.places.create!(place_type: :normal, name: "p2")
t1 = seq.transitions.create!(name: "t1", form: form)
t2 = seq.transitions.create!(name: "t2")
t3 = seq.transitions.create!(name: "t3")
arc2 = seq.arcs.create!(direction: :in, transition: t1, place: s)
arc3 = seq.arcs.create!(direction: :out, transition: t1, place: p1)
arc3 = seq.arcs.create!(direction: :out, transition: t1, place: p2)
arc4 = seq.arcs.create!(direction: :in, transition: t2, place: p1)
arc5 = seq.arcs.create!(direction: :in, transition: t3, place: p2)
arc6 = seq.arcs.create!(direction: :out, transition: t2, place: e)
arc7 = seq.arcs.create!(direction: :out, transition: t3, place: e)
arc3.guards.create!(fieldable: age_field, op: ">".to_sym, value: 18)
end.call
proc do
seq = Wf::Workflow.create(name: "Workflow with parallel routing")
s = seq.places.create!(place_type: :start, name: "start")
e = seq.places.create!(place_type: :end, name: "end")
p1 = seq.places.create!(place_type: :normal, name: "p1")
p2 = seq.places.create!(place_type: :normal, name: "p2")
p3 = seq.places.create!(place_type: :normal, name: "p3")
p4 = seq.places.create!(place_type: :normal, name: "p4")
t1 = seq.transitions.create!(name: "t1", form: form)
t2 = seq.transitions.create!(name: "t2")
t3 = seq.transitions.create!(name: "t3")
t4 = seq.transitions.create!(name: "t4")
arc1 = seq.arcs.create!(direction: :in, transition: t1, place: s)
arc2 = seq.arcs.create!(direction: :out, transition: t1, place: p1)
arc3 = seq.arcs.create!(direction: :out, transition: t1, place: p2)
arc4 = seq.arcs.create!(direction: :in, transition: t2, place: p1)
arc5 = seq.arcs.create!(direction: :in, transition: t3, place: p2)
arc6 = seq.arcs.create!(direction: :out, transition: t2, place: p3)
arc7 = seq.arcs.create!(direction: :out, transition: t3, place: p4)
arc8 = seq.arcs.create!(direction: :in, transition: t4, place: p3)
arc9 = seq.arcs.create!(direction: :in, transition: t4, place: p4)
arc10 = seq.arcs.create!(direction: :out, transition: t4, place: e)
end.call
proc do
seq = Wf::Workflow.create(name: "Workflow with iterative routing")
s = seq.places.create!(place_type: :start, name: "start")
e = seq.places.create!(place_type: :end, name: "end")
p = seq.places.create!(place_type: :normal, name: "p")
t1 = seq.transitions.create!(name: "t1", form: form)
t2 = seq.transitions.create!(name: "t2")
arc1 = seq.arcs.create!(direction: :in, transition: t1, place: s)
arc2 = seq.arcs.create!(direction: :out, transition: t1, place: p)
arc3 = seq.arcs.create!(direction: :in, transition: t2, place: p)
arc4 = seq.arcs.create!(direction: :out, transition: t2, place: e)
arc5 = seq.arcs.create!(direction: :out, transition: t1, place: s)
arc5.guards.create!(fieldable: age_field, op: ">".to_sym, value: 18)
end.call