Class: OpenWFE::Extras::Workitem
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- OpenWFE::Extras::Workitem
- Defined in:
- lib/openwfe/extras/participants/activeparticipants.rb
Overview
The ActiveRecord version of an OpenWFEru workitem (InFlowWorkItem).
One can very easily build a worklist based on a participant name via :
wl = OpenWFE::Extras::Workitem.find_all_by_participant_name("toto")
puts "found #{wl.size} workitems for participant 'toto'"
These workitems are not OpenWFEru workitems directly. But the conversion is pretty easy. Note that you probaly won’t need to do the conversion by yourself, except for certain advanced scenarii.
awi = OpenWFE::Extras::Workitem.find_by_participant_name("toto")
#
# returns the first workitem in the database whose participant
# name is 'toto'.
owi = awi.as_owfe_workitem
#
# Now we have a copy of the reference as a OpenWFEru
# InFlowWorkItem instance.
awi = OpenWFE::Extras::Workitem.from_owfe_workitem(owi)
#
# turns an OpenWFEru InFlowWorkItem instance into an
# 'active workitem'.
Class Method Summary collapse
-
.find_in_stores(storename_list) ⇒ Object
Returns all the workitems belonging to the stores listed in the parameter storename_list.
-
.find_just_launched(wfid, participant_name) ⇒ Object
Not really about ‘just launched’, but rather about finding the first workitem for a given process instance (wfid) and a participant.
-
.from_owfe_workitem(wi, store_name = nil) ⇒ Object
Generates a (new) Workitem from an OpenWFEru InFlowWorkItem instance.
-
.search(search_string, storename_list = nil) ⇒ Object
A kind of ‘google search’ among workitems.
Instance Method Summary collapse
-
#as_owfe_workitem ⇒ Object
Turns the densha Workitem into an OpenWFEru InFlowWorkItem.
-
#field(key) ⇒ Object
Returns the Field instance with the given key.
-
#fields_hash ⇒ Object
Returns a hash version of the ‘fields’ of this workitem.
-
#full_fei ⇒ Object
Returns the flow expression id of this work (its unique OpenWFEru identifier) as a FlowExpressionId instance.
-
#replace_fields(fhash) ⇒ Object
Replaces the current fields of this workitem with the given hash.
-
#reply(engine) ⇒ Object
(also: #forward, #proceed)
A shortcut method, replies to the workflow engine and removes self from the database.
-
#touch ⇒ Object
Simply sets the ‘last_modified’ field to now.
Class Method Details
.find_in_stores(storename_list) ⇒ Object
Returns all the workitems belonging to the stores listed in the parameter storename_list. The result is a Hash whose keys are the store names and whose values are list of workitems.
350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 350 def self.find_in_stores (storename_list) workitems = find_all_by_store_name(storename_list) result = {} workitems.each do |wi| (result[wi.store_name] ||= []) << wi end result end |
.find_just_launched(wfid, participant_name) ⇒ Object
Not really about ‘just launched’, but rather about finding the first workitem for a given process instance (wfid) and a participant. It deserves its own method because the workitem could be in a subprocess, thus escaping the vanilla find_by_wfid_and_participant()
407 408 409 410 411 412 413 414 415 |
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 407 def self.find_just_launched (wfid, participant_name) find( :first, :conditions => [ "wfid LIKE ? AND participant_name = ?", "#{wfid}%", participant_name ]) end |
.from_owfe_workitem(wi, store_name = nil) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 177 def Workitem.from_owfe_workitem (wi, store_name=nil) i = nil MUTEX.synchronize do i = Workitem.new i.fei = wi.fei.to_s i.wfid = wi.fei.wfid i.wf_name = wi.fei.workflow_definition_name i.wf_revision = wi.fei.workflow_definition_revision i.participant_name = wi.participant_name i.dispatch_time = wi.dispatch_time i.last_modified = nil i.store_name = store_name # This is a field set by the active participant immediately # before calling this method. # the default behavior is "use field method" if wi.attributes["compact_workitems"] wi.attributes.delete("compact_workitems") i.yattributes= wi.attributes else i.yattributes= nil wi.attributes.each do |k, v| i.fields << Field.new_field(k, v) end end i.save! # making sure to throw an exception in case of trouble end i end |
.search(search_string, storename_list = nil) ⇒ Object
A kind of ‘google search’ among workitems
Note
when this is used on compact_workitems, it will not be able to search info within the fields, because they aren’t used by this kind of workitems. In this case the search will be limited to participant_name
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 372 def self.search (search_string, storename_list=nil) #t = OpenWFE::Timer.new storename_list = Array(storename_list) if storename_list # participant_name result = find( :all, :conditions => conditions( "participant_name", search_string, storename_list), :order => "participant_name") # :limit => 10) ids = result.collect { |wi| wi.id } # search in fields fields = Field.search search_string, storename_list merge_search_results ids, result, fields #puts "... took #{t.duration} ms" # over. result end |
Instance Method Details
#as_owfe_workitem ⇒ Object
Turns the densha Workitem into an OpenWFEru InFlowWorkItem.
222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 222 def as_owfe_workitem wi = OpenWFE::InFlowWorkItem.new wi.fei = full_fei wi.participant_name = participant_name wi.attributes = fields_hash # don't care about dispatch_time and last_modified wi.db_id = self.id wi end |
#field(key) ⇒ Object
Returns the Field instance with the given key. This method accept symbols as well as strings as its parameter.
wi.field("customer_name")
wi.field :customer_name
286 287 288 289 290 291 292 293 |
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 286 def field (key) if self.yattributes return self.yattributes[key.to_s] end fields.find_by_fkey key.to_s end |
#fields_hash ⇒ Object
Returns a hash version of the ‘fields’ of this workitem.
(Each time this method is called, it returns a new hash).
241 242 243 244 245 246 247 248 249 |
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 241 def fields_hash return self.yattributes if self.yattributes fields.inject({}) do |r, f| r[f.fkey] = f.value r end end |
#full_fei ⇒ Object
Returns the flow expression id of this work (its unique OpenWFEru identifier) as a FlowExpressionId instance. (within the Workitem it’s just stored as a String).
163 164 165 166 |
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 163 def full_fei OpenWFE::FlowExpressionId.from_s(fei) end |
#replace_fields(fhash) ⇒ Object
Replaces the current fields of this workitem with the given hash.
This method modifies the content of the db.
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 256 def replace_fields (fhash) if self.yattributes self.yattributes = fhash else fields.delete_all fhash.each do |k, v| fields << Field.new_field(k, v) end end #f = Field.new_field("___map_type", "smap") # # an old trick for backward compatibility with OpenWFEja save! # making sure to throw an exception in case of trouble end |
#reply(engine) ⇒ Object Also known as: forward, proceed
A shortcut method, replies to the workflow engine and removes self from the database. Handy for people who don’t want to play with an ActiveParticipant instance when just consuming workitems (that an active participant pushed in the database).
302 303 304 305 306 |
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 302 def reply (engine) engine.reply self.as_owfe_workitem self.destroy end |
#touch ⇒ Object
Simply sets the ‘last_modified’ field to now. (Doesn’t save the workitem though).
315 316 317 318 |
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 315 def touch self.last_modified = Time.now end |