Class: Wf::CaseCommand::FinishedP

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wf_case) ⇒ FinishedP

Returns a new instance of FinishedP.



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

def initialize(wf_case)
  @wf_case = wf_case
end

Instance Attribute Details

#wf_caseObject (readonly)

Returns the value of attribute wf_case.



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

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

def call
  return true if wf_case.finished?

  end_place = wf_case.workflow.places.end.first
  end_place_token_num = Wf::ApplicationRecord.uncached { wf_case.tokens.where(place: end_place).count }
  if end_place_token_num == 0
    false
  else
    free_and_locked_token_num = wf_case.tokens.where(place: end_place).where(state: %i[free locked]).count
    raise("The workflow net is misconstructed: Some parallel executions have not finished.") if free_and_locked_token_num > 1

    ConsumeToken.call(wf_case, end_place)
    unless wf_case.finished?
      wf_case.finished!
      if started_by_workitem = wf_case.started_by_workitem
        Wf::CaseCommand::FinishWorkitem.call(started_by_workitem)
      end
    end
    true
  end
end