Module | OpenWFE::StoreParticipantMixin |
In: |
lib/openwfe/worklist/storeparticipant.rb
|
A mixin gathering the methods a workitem store participant needs.
Two kinds of methods are involved here, the ones used by the engine (its participant map) and the ones used by ‘workflow clients’. Thus consume() and cancel() are triggered by the engine, and save() and forward() are at the disposal of ‘workflow clients’.
A ‘workflow client’ is supposed to use methods similar to hash methods to retrieve workitems, like in
storeparticipant.each do |fei, workitem| puts "workitem : #{fei.to_s}" do_some_work(workitem) end
store_name | [RW] | optional field (only used by the old rest interface for now) |
Called by the participant expression when this participant is ‘cancelled’ within a flow. The workitem then gets removed.
# File lib/openwfe/worklist/storeparticipant.rb, line 91 91: def cancel (cancelitem) 92: 93: ldebug do 94: "cancel() removing workitem #{cancelitem.flow_expression_id}" 95: end 96: 97: self.delete(cancelitem.flow_expression_id) 98: end
Called by the engine (the participant expression) when handing out a workitem (to this participant).
This method can also be used when delegating a workitem from one store participant to the other.
# File lib/openwfe/worklist/storeparticipant.rb, line 81 81: def consume (workitem) 82: 83: self[workitem.flow_expression_id] = workitem 84: end
A convenience method for delegating a workitem to another store participant.
# File lib/openwfe/worklist/storeparticipant.rb, line 147 147: def delegate (wi_or_fei, other_store_participant) 148: wi = delete(wi_or_fei) 149: other_store_participant.push(wi) 150: end
This delete() method accepts a workitem or simply its FlowExpressionId identifier.
# File lib/openwfe/worklist/storeparticipant.rb, line 136 136: def delete (wi_or_fei) 137: #fei = wi_or_fei 138: #fei = fei.fei if fei.is_a? InFlowWorkItem 139: #super fei 140: super extract_fei(wi_or_fei) 141: end
Returns the first workitem at hand. As a StoreParticipant is usually implemented with a hash, two consecutive calls to this method might not return the same workitem (except if the store is empty or contains 1! workitem).
# File lib/openwfe/worklist/storeparticipant.rb, line 174 174: def first_workitem 175: 176: result = nil 177: 178: self.each_value do |workitem| 179: result = workitem 180: break 181: end 182: 183: return result 184: end
The workflow client is done with the workitem, send it back to the engine and make sure it‘s not in the store participant anymore.
# File lib/openwfe/worklist/storeparticipant.rb, line 116 116: def forward (workitem) 117: 118: raise "Workitem not found in #{self.class}, cannot forward." \ 119: unless self.has_key? workitem.flow_expression_id 120: 121: #self.delete(workitem.flow_expression_id) 122: self.delete(workitem) 123: 124: reply_to_engine(workitem) 125: end
Returns all the workitems for a given workflow instance id. If no workflow_instance_id is given, all the workitems will be returned.
# File lib/openwfe/worklist/storeparticipant.rb, line 157 157: def list_workitems (workflow_instance_id=nil) 158: 159: result = [] 160: self.each_value do |workitem| 161: result << workitem \ 162: if (not workflow_instance_id) or workitem.fei.parent_wfid == workflow_instance_id 163: end 164: 165: result 166: end
The workitem is to be stored again within the store participant, it will probably be reused later. Don‘t send back to engine yet.
# File lib/openwfe/worklist/storeparticipant.rb, line 104 104: def save (workitem) 105: 106: raise "Workitem not found in #{self.class}, cannot save." \ 107: unless self.has_key? workitem.flow_expression_id 108: 109: self[workitem.flow_expression_id] = workitem 110: end