Class: Wf::CaseCommand::StartWorkitem

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workitem, user) ⇒ StartWorkitem

Returns a new instance of StartWorkitem.



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

def initialize(workitem, user)
  @workitem = workitem
  @user     = user
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user.



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

def user
  @user
end

#workitemObject (readonly)

Returns the value of attribute workitem.



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

def workitem
  @workitem
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/wf/case_command/start_workitem.rb', line 12

def call
  raise("The workitem can not run by user.") unless workitem.real?
  raise("The workitem is not in state #{workitem.state}") unless workitem.enabled?

  # TODO: holding timeout
  Wf::ApplicationRecord.transaction do
    workitem.update!(state: :started, holding_user: user)

    workitem.transition.arcs.in.each do |arc|
      LockToken.call(workitem.case, arc.place, workitem)
    end
  end
  workitem
end