Module: OpenWFE::StoreParticipantMixin

Includes:
FeiMixin, LocalParticipant
Included in:
HashParticipant, YamlParticipant
Defined in:
lib/openwfe/worklist/storeparticipant.rb

Overview

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

Instance Attribute Summary collapse

Attributes included from Contextual

#application_context

Instance Method Summary collapse

Methods included from LocalParticipant

#call_block, #get_flow_expression, #reply_to_engine

Methods included from Contextual

#get_work_directory, #init_service, #lookup

Methods included from Logging

#ldebug, #ldebug_callstack, #lerror, #lfatal, #linfo, #llog, #lunknown, #lwarn

Methods included from OwfeServiceLocator

#get_engine, #get_error_journal, #get_expool, #get_expression_map, #get_expression_pool, #get_expression_storage, #get_expression_storages, #get_journal, #get_participant_map, #get_scheduler, #get_wfid_generator

Instance Attribute Details

#store_nameObject

optional field (only used by the old rest interface for now)



72
73
74
# File 'lib/openwfe/worklist/storeparticipant.rb', line 72

def store_name
  @store_name
end

Instance Method Details

#cancel(cancelitem) ⇒ Object

Called by the participant expression when this participant is ‘cancelled’ within a flow. The workitem then gets removed.



91
92
93
94
95
96
97
98
# File 'lib/openwfe/worklist/storeparticipant.rb', line 91

def cancel (cancelitem)

    ldebug do 
        "cancel() removing workitem  #{cancelitem.flow_expression_id}"
    end

    self.delete(cancelitem.flow_expression_id)
end

#consume(workitem) ⇒ Object Also known as: push

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.



81
82
83
84
# File 'lib/openwfe/worklist/storeparticipant.rb', line 81

def consume (workitem)

    self[workitem.flow_expression_id] = workitem
end

#delegate(wi_or_fei, other_store_participant) ⇒ Object

A convenience method for delegating a workitem to another store participant.



147
148
149
150
# File 'lib/openwfe/worklist/storeparticipant.rb', line 147

def delegate (wi_or_fei, other_store_participant)
    wi = delete(wi_or_fei)
    other_store_participant.push(wi)
end

#delete(wi_or_fei) ⇒ Object

This delete() method accepts a workitem or simply its FlowExpressionId identifier.



136
137
138
139
140
141
# File 'lib/openwfe/worklist/storeparticipant.rb', line 136

def delete (wi_or_fei)
    #fei = wi_or_fei
    #fei = fei.fei if fei.is_a? InFlowWorkItem
    #super fei
    super extract_fei(wi_or_fei)
end

#first_workitemObject

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).



174
175
176
177
178
179
180
181
182
183
184
# File 'lib/openwfe/worklist/storeparticipant.rb', line 174

def first_workitem

    result = nil

    self.each_value do |workitem|
        result = workitem
        break
    end

    return result
end

#forward(workitem) ⇒ Object Also known as: proceed

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.



116
117
118
119
120
121
122
123
124
125
# File 'lib/openwfe/worklist/storeparticipant.rb', line 116

def forward (workitem)

    raise "Workitem not found in #{self.class}, cannot forward." \
        unless self.has_key? workitem.flow_expression_id

    #self.delete(workitem.flow_expression_id)
    self.delete(workitem)

    reply_to_engine(workitem)
end

#list_workitems(workflow_instance_id = nil) ⇒ Object

Returns all the workitems for a given workflow instance id. If no workflow_instance_id is given, all the workitems will be returned.



157
158
159
160
161
162
163
164
165
166
# File 'lib/openwfe/worklist/storeparticipant.rb', line 157

def list_workitems (workflow_instance_id=nil)

    result = []
    self.each_value do |workitem|
        result << workitem \
            if (not workflow_instance_id) or workitem.fei.parent_wfid == workflow_instance_id
    end

    result
end

#save(workitem) ⇒ Object

The workitem is to be stored again within the store participant, it will probably be reused later. Don’t send back to engine yet.



104
105
106
107
108
109
110
# File 'lib/openwfe/worklist/storeparticipant.rb', line 104

def save (workitem)

    raise "Workitem not found in #{self.class}, cannot save." \
        unless self.has_key? workitem.flow_expression_id

    self[workitem.flow_expression_id] = workitem
end