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.
360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 360 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()
417 418 419 420 421 422 423 424 425 |
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 417 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 218 219 220 221 222 223 224 225 |
# 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 i.save! # save workitem before adding any field # making sure it has an id... # 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 # # damn, insert then update :( #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
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 382 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.
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 230 def as_owfe_workitem wi = OpenWFE::InFlowWorkItem.new wi.fei = full_fei wi.participant_name = participant_name wi.attributes = fields_hash wi.dispatch_time = dispatch_time wi.last_modified = 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
296 297 298 299 300 301 302 303 |
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 296 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).
251 252 253 254 255 256 257 258 259 |
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 251 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.
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 266 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).
312 313 314 315 316 |
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 312 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).
325 326 327 328 |
# File 'lib/openwfe/extras/participants/activeparticipants.rb', line 325 def touch self.last_modified = Time.now end |