bpmn 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,179 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SpotFlow
4
- module Bpmn
5
- class Process < Step
6
- attr_accessor :is_executable
7
-
8
- attr_accessor :start_events, :end_events, :intermediate_catch_events, :intermediate_throw_events, :boundary_events
9
- attr_accessor :tasks, :user_tasks, :service_tasks, :script_tasks, :send_tasks, :receive_tasks, :manual_tasks, :business_rule_tasks, :call_activities
10
- attr_accessor :sub_processes, :ad_hoc_sub_processes
11
- attr_accessor :sequence_flows, :message_flows, :associations, :data_associations, :data_inputs, :data_outputs
12
- attr_accessor :data_objects, :data_stores, :data_stores_references
13
- attr_accessor :gateways, :exclusive_gateways, :parallel_gateways, :inclusive_gateways, :event_based_gateways, :complex_gateways
14
-
15
- attr_accessor :parent
16
-
17
- def initialize(attributes = {})
18
- super(attributes.slice(:id, :name, :extension_elements, :incoming, :outgoing, :default))
19
-
20
- @is_executable = attributes[:is_executable] == ("true" || true)
21
-
22
- @start_events = Array.wrap(attributes[:start_event]).map { |se| StartEvent.new(se) }
23
- @end_events = Array.wrap(attributes[:end_event]).map { |ee| EndEvent.new(ee) }
24
- @intermediate_catch_events = Array.wrap(attributes[:intermediate_catch_event]).map { |ice| IntermediateCatchEvent.new(ice) }
25
- @intermediate_throw_events = Array.wrap(attributes[:intermediate_throw_event]).map { |ite| IntermediateThrowEvent.new(ite) }
26
- @boundary_events = Array.wrap(attributes[:boundary_event]).map { |be| BoundaryEvent.new(be) }
27
- @tasks = Array.wrap(attributes[:task]).map { |t| Task.new(t) }
28
- @user_tasks = Array.wrap(attributes[:user_task]).map { |ut| UserTask.new(ut) }
29
- @service_tasks = Array.wrap(attributes[:service_task]).map { |st| ServiceTask.new(st) }
30
- @script_tasks = Array.wrap(attributes[:script_task]).map { |st| ScriptTask.new(st) }
31
- @business_rule_tasks = Array.wrap(attributes[:business_rule_task]).map { |brt| BusinessRuleTask.new(brt) }
32
- @call_activities = Array.wrap(attributes[:call_activity]).map { |ca| CallActivity.new(ca) }
33
- @sub_processes = Array.wrap(attributes[:sub_process]).map { |sp| SubProcess.new(sp) }
34
- @ad_hoc_sub_processes = Array.wrap(attributes[:ad_hoc_sub_processe]).map { |ahsp| AdHocSubProcess.new(ahsp) }
35
- @exclusive_gateways = Array.wrap(attributes[:exclusive_gateway]).map { |eg| ExclusiveGateway.new(eg) }
36
- @parallel_gateways = Array.wrap(attributes[:parallel_gateway]).map { |pg| ParallelGateway.new(pg) }
37
- @inclusive_gateways = Array.wrap(attributes[:inclusive_gateway]).map { |ig| InclusiveGateway.new(ig) }
38
- @event_based_gateways = Array.wrap(attributes[:event_based_gateway]).map { |ebg| EventBasedGateway.new(ebg) }
39
- @sequence_flows = Array.wrap(attributes[:sequence_flow]).map { |sf| SequenceFlow.new(sf) }
40
- end
41
-
42
- def elements
43
- @elements ||= {}.tap do |elements|
44
- elements.merge!(start_events.index_by(&:id))
45
- elements.merge!(end_events.index_by(&:id))
46
- elements.merge!(intermediate_catch_events.index_by(&:id))
47
- elements.merge!(intermediate_throw_events.index_by(&:id))
48
- elements.merge!(boundary_events.index_by(&:id))
49
- elements.merge!(tasks.index_by(&:id))
50
- elements.merge!(user_tasks.index_by(&:id))
51
- elements.merge!(service_tasks.index_by(&:id))
52
- elements.merge!(script_tasks.index_by(&:id))
53
- elements.merge!(business_rule_tasks.index_by(&:id))
54
- elements.merge!(call_activities.index_by(&:id))
55
- elements.merge!(sub_processes.index_by(&:id))
56
- elements.merge!(ad_hoc_sub_processes.index_by(&:id))
57
- elements.merge!(exclusive_gateways.index_by(&:id))
58
- elements.merge!(parallel_gateways.index_by(&:id))
59
- elements.merge!(inclusive_gateways.index_by(&:id))
60
- elements.merge!(event_based_gateways.index_by(&:id))
61
- elements.merge!(sequence_flows.index_by(&:id))
62
- end
63
- end
64
-
65
- def wire_references(definitions)
66
- elements.values.each do |element|
67
- if element.is_a?(Step)
68
- element.incoming = element.incoming.map { |id| element_by_id(id) }
69
- element.outgoing = element.outgoing.map { |id| element_by_id(id) }
70
-
71
- if element.is_a?(Event)
72
-
73
- element.event_definitions.each do |event_definition|
74
- if event_definition.is_a?(MessageEventDefinition)
75
- event_definition.message = definitions.message_by_id(event_definition.message_ref)
76
- elsif event_definition.is_a?(SignalEventDefinition)
77
- event_definition.signal = definitions.signal_by_id(event_definition.signal_ref)
78
- elsif event_definition.is_a?(ErrorEventDefinition)
79
- event_definition.error = definitions.error_by_id(event_definition.error_ref)
80
- end
81
- end
82
-
83
- if element.is_a?(BoundaryEvent)
84
- host_element = element_by_id(element.attached_to_ref)
85
- host_element.attachments << element
86
- element.attached_to = host_element
87
- end
88
-
89
- end
90
-
91
- if element.is_a?(Gateway)
92
- element.default = element_by_id(element.default_ref)
93
- end
94
-
95
- if element.is_a?(SubProcess)
96
- element.wire_references(definitions)
97
- end
98
-
99
- elsif element.is_a?(SequenceFlow)
100
- element.source = element_by_id(element.source_ref)
101
- element.target = element_by_id(element.target_ref)
102
- end
103
-
104
- # Not handled participant process ref
105
- end
106
- end
107
-
108
- def element_by_id(id)
109
- elements[id]
110
- end
111
-
112
- def elements_by_type(type)
113
- elements.select { |e| e.class == type }
114
- end
115
-
116
- def default_start_event
117
- start_events.find { |se| se.event_definitions.empty? }
118
- end
119
-
120
- def execute(execution)
121
- start_event = execution.start_event_id ? element_by_id(execution.start_event_id) : default_start_event
122
- raise ExecutionErrorNew.new("Process must have at least one start event.") if start_event.blank?
123
- execution.execute_step(start_event)
124
- end
125
-
126
- def inspect
127
- parts = ["#<#{self.class.name.gsub(/SpotFlow::/, "")} @id=#{id.inspect} @name=#{name.inspect} @is_executable=#{is_executable.inspect}"]
128
- parts << "@parent=#{parent.inspect}" if parent
129
- event_attrs = (start_events + intermediate_catch_events + intermediate_throw_events + boundary_events + end_events).compact
130
- parts << "@events=#{event_attrs.inspect}" unless event_attrs.blank?
131
- activity_attrs = (tasks + user_tasks + service_tasks + script_tasks + business_rule_tasks + call_activities).compact
132
- parts << "@activities=#{activity_attrs.inspect}" unless activity_attrs.blank?
133
- gateway_attrs = (exclusive_gateways + parallel_gateways + inclusive_gateways + event_based_gateways).compact
134
- parts << "@gateways=#{gateway_attrs.inspect}" unless gateway_attrs.blank?
135
- sub_process_attrs = (sub_processes + ad_hoc_sub_processes).compact
136
- parts << "@sub_processes=#{sub_process_attrs.inspect}" unless sub_process_attrs.blank?
137
- parts << "@sequence_flows=#{sequence_flows.inspect}" unless sequence_flows.blank?
138
- parts.join(" ") + ">"
139
- end
140
- end
141
-
142
- class SubProcess < Process
143
- attr_accessor :triggered_by_event
144
-
145
- def initialize(attributes = {})
146
- super(attributes.except(:triggered_by_event))
147
-
148
- @is_executable = false
149
- @sub_processes = []
150
- @triggered_by_event = attributes[:triggered_by_event]
151
- end
152
-
153
- def execution_ended(execution)
154
- leave(execution)
155
- end
156
- end
157
-
158
- class AdHocSubProcess < SubProcess
159
-
160
- end
161
-
162
- class CallActivity < Activity
163
- attr_reader :process_id
164
-
165
- def execute(execution)
166
- if extension_elements&.called_element&.process_id&.start_with?("=")
167
- @process_id = SpotFeel.evaluate(extension_elements&.called_element&.process_id, variables: execution.variables)
168
- else
169
- @process_id = extension_elements&.called_element&.process_id
170
- end
171
-
172
- execution.wait
173
-
174
- process = execution.context.process_by_id(@process_id) if @process_id
175
- execution.execute_step(process.default_start_event) if process
176
- end
177
- end
178
- end
179
- end
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SpotFlow
4
- module Bpmn
5
- class Step < Element
6
- attr_accessor :incoming, :outgoing, :default, :default_ref
7
-
8
- def initialize(attributes = {})
9
- super(attributes.except(:incoming, :outgoing, :default))
10
-
11
- @incoming = Array.wrap(attributes[:incoming]) || []
12
- @outgoing = Array.wrap(attributes[:outgoing]) || []
13
- @default_ref = attributes[:default]
14
- end
15
-
16
- def diverging?
17
- outgoing.length > 1
18
- end
19
-
20
- def converging?
21
- incoming.length > 1
22
- end
23
-
24
- def leave(execution)
25
- execution.end(false)
26
- execution.take_all(outgoing_flows(execution))
27
- end
28
-
29
- def outgoing_flows(execution)
30
- flows = []
31
- outgoing.each do |flow|
32
- result = flow.evaluate(execution) unless default&.id == flow.id
33
- flows.push flow if result
34
- end
35
- flows = [default] if flows.empty? && default
36
- return flows
37
- end
38
-
39
- def input_mappings
40
- extension_elements&.io_mapping&.inputs || []
41
- end
42
-
43
- def output_mappings
44
- extension_elements&.io_mapping&.outputs || []
45
- end
46
- end
47
-
48
- class Activity < Step
49
- attr_accessor :attachments
50
-
51
- def initialize(attributes = {})
52
- super(attributes.except(:attachments))
53
-
54
- @attachments = []
55
- end
56
- end
57
- end
58
- end
@@ -1,128 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SpotFlow
4
- module Bpmn
5
- class Task < Activity
6
-
7
- def is_automated?
8
- false
9
- end
10
-
11
- def is_manual?
12
- true
13
- end
14
-
15
- def execute(execution)
16
- execution.wait
17
- end
18
-
19
- def signal(execution)
20
- leave(execution)
21
- end
22
-
23
- def result_to_variables(result)
24
- if result_variable
25
- return { "#{result_variable}": result }
26
- else
27
- if result.is_a? Hash
28
- result
29
- else
30
- {}.tap { |h| h[id.underscore] = result }
31
- end
32
- end
33
- end
34
- end
35
-
36
- class UserTask < Task
37
-
38
- def form_key
39
- extension_elements&.form_definition&.form_key
40
- end
41
-
42
- def assignee
43
- extension_elements&.assignment_definition&.assignee
44
- end
45
-
46
- def candidate_groups
47
- extension_elements&.assignment_definition&.candidate_groups
48
- end
49
-
50
- def candidate_users
51
- extension_elements&.assignment_definition&.candidate_users
52
- end
53
-
54
- def due_date
55
- extension_elements&.task_schedule&.due_date
56
- end
57
-
58
- def follow_up_date
59
- extension_elements&.task_schedule&.follow_up_date
60
- end
61
- end
62
-
63
- class ServiceTask < Task
64
- attr_accessor :service
65
-
66
- def is_automated?
67
- true
68
- end
69
-
70
- def is_manual?
71
- false
72
- end
73
-
74
- def execute(execution)
75
- execution.wait
76
- end
77
-
78
- def task_type
79
- extension_elements&.task_definition&.type
80
- end
81
-
82
- def task_retries
83
- extension_elements&.task_definition&.retries
84
- end
85
-
86
- def headers
87
- extension_elements&.task_headers&.headers
88
- end
89
-
90
- def run(execution)
91
- if defined?(task_type)
92
- klass = task_type.constantize
93
- klass.new.call(execution.parent.variables, headers || {})
94
- end
95
- end
96
- end
97
-
98
- class ScriptTask < ServiceTask
99
-
100
- def script
101
- extension_elements&.script&.expression
102
- end
103
-
104
- def result_variable
105
- extension_elements&.script&.result_variable
106
- end
107
-
108
- def run(execution)
109
- SpotFeel.evaluate(script.delete_prefix("="), variables: execution.parent.variables)
110
- end
111
- end
112
-
113
- class BusinessRuleTask < ServiceTask
114
-
115
- def decision_id
116
- extension_elements&.called_decision&.decision_id
117
- end
118
-
119
- def result_variable
120
- extension_elements&.called_decision&.result_variable
121
- end
122
-
123
- def run(execution)
124
- SpotFeel.decide(decision_id, definitions: execution.context.dmn_definitions_by_decision_id(decision_id), variables: execution.parent.variables)
125
- end
126
- end
127
- end
128
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "bpmn/element"
4
- require_relative "bpmn/extensions"
5
- require_relative "bpmn/extension_elements"
6
- require_relative "bpmn/step"
7
- require_relative "bpmn/flow"
8
- require_relative "bpmn/event_definition"
9
- require_relative "bpmn/event"
10
- require_relative "bpmn/gateway"
11
- require_relative "bpmn/task"
12
- require_relative "bpmn/process"
13
- require_relative "bpmn/definitions"
14
-
15
- module SpotFlow
16
- module Bpmn
17
- end
18
- end
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SpotFlow
4
- VERSION = "0.0.1"
5
- end