Class: BPMN::Process

Inherits:
Step show all
Defined in:
lib/bpmn/process.rb

Direct Known Subclasses

SubProcess

Instance Attribute Summary collapse

Attributes inherited from Step

#default, #default_ref, #incoming, #outgoing

Attributes inherited from Element

#extension_elements, #id, #name

Instance Method Summary collapse

Methods inherited from Step

#converging?, #diverging?, #input_mappings, #leave, #outgoing_flows, #output_mappings

Constructor Details

#initialize(attributes = {}) ⇒ Process



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/bpmn/process.rb', line 16

def initialize(attributes = {})
  super(attributes.slice(:id, :name, :extension_elements, :incoming, :outgoing, :default))

  @is_executable = attributes[:is_executable] == ("true" || true)

  @start_events = Array.wrap(attributes[:start_event]).map { |se| StartEvent.new(se) }
  @end_events = Array.wrap(attributes[:end_event]).map { |ee| EndEvent.new(ee) }
  @intermediate_catch_events = Array.wrap(attributes[:intermediate_catch_event]).map { |ice| IntermediateCatchEvent.new(ice) }
  @intermediate_throw_events = Array.wrap(attributes[:intermediate_throw_event]).map { |ite| IntermediateThrowEvent.new(ite) }
  @boundary_events = Array.wrap(attributes[:boundary_event]).map { |be| BoundaryEvent.new(be) }
  @tasks = Array.wrap(attributes[:task]).map { |t| Task.new(t) }
  @user_tasks = Array.wrap(attributes[:user_task]).map { |ut| UserTask.new(ut) }
  @service_tasks = Array.wrap(attributes[:service_task]).map { |st| ServiceTask.new(st) }
  @script_tasks = Array.wrap(attributes[:script_task]).map { |st| ScriptTask.new(st) }
  @business_rule_tasks = Array.wrap(attributes[:business_rule_task]).map { |brt| BusinessRuleTask.new(brt) }
  @call_activities = Array.wrap(attributes[:call_activity]).map { |ca| CallActivity.new(ca) }
  @sub_processes = Array.wrap(attributes[:sub_process]).map { |sp| SubProcess.new(sp) }
  @ad_hoc_sub_processes = Array.wrap(attributes[:ad_hoc_sub_processe]).map { |ahsp| AdHocSubProcess.new(ahsp) }
  @exclusive_gateways = Array.wrap(attributes[:exclusive_gateway]).map { |eg| ExclusiveGateway.new(eg) }
  @parallel_gateways = Array.wrap(attributes[:parallel_gateway]).map { |pg| ParallelGateway.new(pg) }
  @inclusive_gateways = Array.wrap(attributes[:inclusive_gateway]).map { |ig| InclusiveGateway.new(ig) }
  @event_based_gateways = Array.wrap(attributes[:event_based_gateway]).map { |ebg| EventBasedGateway.new(ebg) }
  @sequence_flows = Array.wrap(attributes[:sequence_flow]).map { |sf| SequenceFlow.new(sf) }
end

Instance Attribute Details

#ad_hoc_sub_processesObject

Returns the value of attribute ad_hoc_sub_processes.



9
10
11
# File 'lib/bpmn/process.rb', line 9

def ad_hoc_sub_processes
  @ad_hoc_sub_processes
end

#associationsObject

Returns the value of attribute associations.



10
11
12
# File 'lib/bpmn/process.rb', line 10

def associations
  @associations
end

#boundary_eventsObject

Returns the value of attribute boundary_events.



7
8
9
# File 'lib/bpmn/process.rb', line 7

def boundary_events
  @boundary_events
end

#business_rule_tasksObject

Returns the value of attribute business_rule_tasks.



8
9
10
# File 'lib/bpmn/process.rb', line 8

def business_rule_tasks
  @business_rule_tasks
end

#call_activitiesObject

Returns the value of attribute call_activities.



8
9
10
# File 'lib/bpmn/process.rb', line 8

def call_activities
  @call_activities
end

#complex_gatewaysObject

Returns the value of attribute complex_gateways.



12
13
14
# File 'lib/bpmn/process.rb', line 12

def complex_gateways
  @complex_gateways
end

#data_associationsObject

Returns the value of attribute data_associations.



10
11
12
# File 'lib/bpmn/process.rb', line 10

def data_associations
  @data_associations
end

#data_inputsObject

Returns the value of attribute data_inputs.



10
11
12
# File 'lib/bpmn/process.rb', line 10

def data_inputs
  @data_inputs
end

#data_objectsObject

Returns the value of attribute data_objects.



11
12
13
# File 'lib/bpmn/process.rb', line 11

def data_objects
  @data_objects
end

#data_outputsObject

Returns the value of attribute data_outputs.



10
11
12
# File 'lib/bpmn/process.rb', line 10

def data_outputs
  @data_outputs
end

#data_storesObject

Returns the value of attribute data_stores.



11
12
13
# File 'lib/bpmn/process.rb', line 11

def data_stores
  @data_stores
end

#data_stores_referencesObject

Returns the value of attribute data_stores_references.



11
12
13
# File 'lib/bpmn/process.rb', line 11

def data_stores_references
  @data_stores_references
end

#end_eventsObject

Returns the value of attribute end_events.



7
8
9
# File 'lib/bpmn/process.rb', line 7

def end_events
  @end_events
end

#event_based_gatewaysObject

Returns the value of attribute event_based_gateways.



12
13
14
# File 'lib/bpmn/process.rb', line 12

def event_based_gateways
  @event_based_gateways
end

#exclusive_gatewaysObject

Returns the value of attribute exclusive_gateways.



12
13
14
# File 'lib/bpmn/process.rb', line 12

def exclusive_gateways
  @exclusive_gateways
end

#gatewaysObject

Returns the value of attribute gateways.



12
13
14
# File 'lib/bpmn/process.rb', line 12

def gateways
  @gateways
end

#inclusive_gatewaysObject

Returns the value of attribute inclusive_gateways.



12
13
14
# File 'lib/bpmn/process.rb', line 12

def inclusive_gateways
  @inclusive_gateways
end

#intermediate_catch_eventsObject

Returns the value of attribute intermediate_catch_events.



7
8
9
# File 'lib/bpmn/process.rb', line 7

def intermediate_catch_events
  @intermediate_catch_events
end

#intermediate_throw_eventsObject

Returns the value of attribute intermediate_throw_events.



7
8
9
# File 'lib/bpmn/process.rb', line 7

def intermediate_throw_events
  @intermediate_throw_events
end

#is_executableObject

Returns the value of attribute is_executable.



5
6
7
# File 'lib/bpmn/process.rb', line 5

def is_executable
  @is_executable
end

#manual_tasksObject

Returns the value of attribute manual_tasks.



8
9
10
# File 'lib/bpmn/process.rb', line 8

def manual_tasks
  @manual_tasks
end

#message_flowsObject

Returns the value of attribute message_flows.



10
11
12
# File 'lib/bpmn/process.rb', line 10

def message_flows
  @message_flows
end

#parallel_gatewaysObject

Returns the value of attribute parallel_gateways.



12
13
14
# File 'lib/bpmn/process.rb', line 12

def parallel_gateways
  @parallel_gateways
end

#parentObject

Returns the value of attribute parent.



14
15
16
# File 'lib/bpmn/process.rb', line 14

def parent
  @parent
end

#receive_tasksObject

Returns the value of attribute receive_tasks.



8
9
10
# File 'lib/bpmn/process.rb', line 8

def receive_tasks
  @receive_tasks
end

#script_tasksObject

Returns the value of attribute script_tasks.



8
9
10
# File 'lib/bpmn/process.rb', line 8

def script_tasks
  @script_tasks
end

#send_tasksObject

Returns the value of attribute send_tasks.



8
9
10
# File 'lib/bpmn/process.rb', line 8

def send_tasks
  @send_tasks
end

#sequence_flowsObject

Returns the value of attribute sequence_flows.



10
11
12
# File 'lib/bpmn/process.rb', line 10

def sequence_flows
  @sequence_flows
end

#service_tasksObject

Returns the value of attribute service_tasks.



8
9
10
# File 'lib/bpmn/process.rb', line 8

def service_tasks
  @service_tasks
end

#start_eventsObject

Returns the value of attribute start_events.



7
8
9
# File 'lib/bpmn/process.rb', line 7

def start_events
  @start_events
end

#sub_processesObject

Returns the value of attribute sub_processes.



9
10
11
# File 'lib/bpmn/process.rb', line 9

def sub_processes
  @sub_processes
end

#tasksObject

Returns the value of attribute tasks.



8
9
10
# File 'lib/bpmn/process.rb', line 8

def tasks
  @tasks
end

#user_tasksObject

Returns the value of attribute user_tasks.



8
9
10
# File 'lib/bpmn/process.rb', line 8

def user_tasks
  @user_tasks
end

Instance Method Details

#default_start_eventObject



115
116
117
# File 'lib/bpmn/process.rb', line 115

def default_start_event
  start_events.find { |se| se.event_definitions.empty? }
end

#element_by_id(id) ⇒ Object



107
108
109
# File 'lib/bpmn/process.rb', line 107

def element_by_id(id)
  elements[id]
end

#elementsObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/bpmn/process.rb', line 41

def elements
  @elements ||= {}.tap do |elements|
    elements.merge!(start_events.index_by(&:id))
    elements.merge!(end_events.index_by(&:id))
    elements.merge!(intermediate_catch_events.index_by(&:id))
    elements.merge!(intermediate_throw_events.index_by(&:id))
    elements.merge!(boundary_events.index_by(&:id))
    elements.merge!(tasks.index_by(&:id))
    elements.merge!(user_tasks.index_by(&:id))
    elements.merge!(service_tasks.index_by(&:id))
    elements.merge!(script_tasks.index_by(&:id))
    elements.merge!(business_rule_tasks.index_by(&:id))
    elements.merge!(call_activities.index_by(&:id))
    elements.merge!(sub_processes.index_by(&:id))
    elements.merge!(ad_hoc_sub_processes.index_by(&:id))
    elements.merge!(exclusive_gateways.index_by(&:id))
    elements.merge!(parallel_gateways.index_by(&:id))
    elements.merge!(inclusive_gateways.index_by(&:id))
    elements.merge!(event_based_gateways.index_by(&:id))
    elements.merge!(sequence_flows.index_by(&:id))
  end
end

#elements_by_type(type) ⇒ Object



111
112
113
# File 'lib/bpmn/process.rb', line 111

def elements_by_type(type)
  elements.select { |e| e.class == type }
end

#execute(execution) ⇒ Object

Raises:

  • (ExecutionErrorNew)


119
120
121
122
123
# File 'lib/bpmn/process.rb', line 119

def execute(execution)
  start_event = execution.start_event_id ? element_by_id(execution.start_event_id) : default_start_event
  raise ExecutionErrorNew.new("Process must have at least one start event.") if start_event.blank?
  execution.execute_step(start_event)
end

#inspectObject



125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/bpmn/process.rb', line 125

def inspect
  parts = ["#<#{self.class.name.gsub(/BPMN::/, "")} @id=#{id.inspect} @name=#{name.inspect} @is_executable=#{is_executable.inspect}"]
  parts << "@parent=#{parent.inspect}" if parent
  event_attrs = (start_events + intermediate_catch_events + intermediate_throw_events + boundary_events + end_events).compact
  parts << "@events=#{event_attrs.inspect}" unless event_attrs.blank?
  activity_attrs = (tasks + user_tasks + service_tasks + script_tasks + business_rule_tasks + call_activities).compact
  parts << "@activities=#{activity_attrs.inspect}" unless activity_attrs.blank?
  gateway_attrs = (exclusive_gateways + parallel_gateways + inclusive_gateways + event_based_gateways).compact
  parts << "@gateways=#{gateway_attrs.inspect}" unless gateway_attrs.blank?
  sub_process_attrs = (sub_processes + ad_hoc_sub_processes).compact
  parts << "@sub_processes=#{sub_process_attrs.inspect}" unless sub_process_attrs.blank?
  parts << "@sequence_flows=#{sequence_flows.inspect}" unless sequence_flows.blank?
  parts.join(" ") + ">"
end

#wire_references(definitions) ⇒ Object



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
# File 'lib/bpmn/process.rb', line 64

def wire_references(definitions)
  elements.values.each do |element|
    if element.is_a?(Step)
      element.incoming = element.incoming.map { |id| element_by_id(id) }
      element.outgoing = element.outgoing.map { |id| element_by_id(id) }

      if element.is_a?(Event)

        element.event_definitions.each do |event_definition|
          if event_definition.is_a?(MessageEventDefinition)
            event_definition.message = definitions.message_by_id(event_definition.message_ref)
          elsif event_definition.is_a?(SignalEventDefinition)
            event_definition.signal = definitions.signal_by_id(event_definition.signal_ref)
          elsif event_definition.is_a?(ErrorEventDefinition)
            event_definition.error = definitions.error_by_id(event_definition.error_ref)
          end
        end

        if element.is_a?(BoundaryEvent)
          host_element = element_by_id(element.attached_to_ref)
          host_element.attachments << element
          element.attached_to = host_element
        end

      end

      if element.is_a?(Gateway)
        element.default = element_by_id(element.default_ref)
      end

      if element.is_a?(SubProcess)
        element.wire_references(definitions)
      end

    elsif element.is_a?(SequenceFlow)
      element.source = element_by_id(element.source_ref)
      element.target = element_by_id(element.target_ref)
    end

    # Not handled participant process ref
  end
end