Class: Wf::CaseCommand::FireTransitionInternal

Inherits:
Object
  • Object
show all
Includes:
SimpleCommand
Defined in:
app/models/wf/case_command/fire_transition_internal.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workitem) ⇒ FireTransitionInternal

Returns a new instance of FireTransitionInternal.



7
8
9
# File 'app/models/wf/case_command/fire_transition_internal.rb', line 7

def initialize(workitem)
  @workitem = workitem
end

Instance Attribute Details

#workitemObject (readonly)

Returns the value of attribute workitem.



6
7
8
# File 'app/models/wf/case_command/fire_transition_internal.rb', line 6

def workitem
  @workitem
end

Instance Method Details

#callObject



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
# File 'app/models/wf/case_command/fire_transition_internal.rb', line 11

def call
  if workitem.enabled?
    locked_item = nil
  elsif workitem.started?
    locked_item = workitem
  else
    raise("can not fire the transition if it is not in state enabled or started.")
  end
  Wf::ApplicationRecord.transaction do
    workitem.update!(finished_at: Time.zone.now, state: :finished)
    # TODO: only in?
    workitem.transition.arcs.each do |arc|
      ConsumeToken.call(workitem.case, arc.place, locked_item)
    end
    # last arc without guard -> pass
    has_passed = false
    workitem.transition.arcs.out.order("guards_count DESC").each do |arc|
      if workitem.transition.explicit_or_split?
        if workitem.pass_guard?(arc, has_passed)
          has_passed = true
          AddToken.call(workitem.case, arc.place)
        end
      else
        AddToken.call(workitem.case, arc.place)
      end
    end
    workitem.transition.fire_callback.constantize.new(workitem.id).perform_now
  end
end