Class | OpenWFE::Extras::ActivityFeedService |
In: |
lib/openwfe/extras/misc/activityfeed.rb
|
Parent: | Object |
This feed registers as an observer to the ParticipantMap. Each time a workitem is delivered to a participant or comes back from/for it, an AtomEntry is generated. The get_feed() method produces an atom feed of participant activity.
max_item_count | [RW] |
This service is generally tied to an engine by doing :
engine.init_service 'activityFeed', ActivityFeedService
The init_service() will take care of calling the constructor implemented here.
# File lib/openwfe/extras/misc/activityfeed.rb, line 110 110: def initialize (service_name, application_context) 111: 112: super() 113: 114: service_init service_name, application_context 115: 116: @entries = [] 117: @max_item_count = 100 118: 119: get_participant_map.add_observer ".*", self 120: end
This is the method call by the expression pool each time a workitem reaches a participant.
# File lib/openwfe/extras/misc/activityfeed.rb, line 126 126: def call (channel, *args) 127: 128: ldebug "call() c '#{channel}' entries count : #{@entries.size}" 129: 130: e = Entry.new 131: 132: e.participant_name = channel 133: e.upon = args[0] 134: e.workitem = args[1].dup 135: 136: e.id = \ 137: "#{e.workitem.participant_name} - #{e.upon} " + 138: "#{e.workitem.fei.workflow_instance_id}--" + 139: "#{e.workitem.fei.expression_id}" 140: 141: @entries << e 142: 143: @entries = @entries[0, @max_item_count] \ 144: if @entries.length > @max_item_count 145: end
Returns an Atom feed of all the workitem activity for the participants whose name matches the given regular expression.
Options :
# File lib/openwfe/extras/misc/activityfeed.rb, line 164 164: def get_feed (participant_regex, options={}) 165: 166: participant_regex = Regexp.compile(participant_regex) \ 167: if participant_regex.is_a?(String) 168: 169: upon = options[:upon] 170: feed_uri = options[:feed_uri] || "http://localhost/feed" 171: title = options[:feed_title] || "OpenWFEru engine activity feed" 172: 173: feed = Atom::Collection.new feed_uri 174: feed.title = title 175: 176: format = options[:format] 177: format = validate_format(format) 178: 179: @entries.each do |e| 180: 181: next unless participant_regex.match(e.participant_name) 182: next if upon and upon != e.upon 183: 184: feed.updated = e.updated \ 185: if feed.updated == nil or e.updated > feed.updated 186: 187: feed << as_atom_entry(format, e) 188: end 189: 190: feed 191: end
# File lib/openwfe/extras/misc/activityfeed.rb, line 206 206: def as_atom_entry (render, entry) 207: 208: send( 209: render, 210: entry.as_atom_entry, 211: entry.participant_name, 212: entry.upon, 213: entry.workitem) 214: end
Renders the workitem as a JSON string.
# File lib/openwfe/extras/misc/activityfeed.rb, line 250 250: def as_json (atom_entry, participant_name, upon, workitem) 251: 252: atom_entry.title = "#{participant_name} - #{upon}" 253: 254: atom_entry.content = workitem.to_json 255: atom_entry.content['type'] = "text/plain" 256: 257: atom_entry 258: end
A basic rendition of a workitem as text.
# File lib/openwfe/extras/misc/activityfeed.rb, line 237 237: def as_text (atom_entry, participant_name, upon, workitem) 238: 239: atom_entry.title = "#{participant_name} - #{upon}" 240: 241: atom_entry.content = workitem.to_s 242: atom_entry.content['type'] = "text/plain" 243: 244: atom_entry 245: end
A basic rendition of a workitem as a YAML string
# File lib/openwfe/extras/misc/activityfeed.rb, line 219 219: def as_yaml (atom_entry, participant_name, upon, workitem) 220: 221: atom_entry.title = "#{participant_name} - #{upon}" 222: atom_entry.content = workitem.to_yaml 223: atom_entry.content['type'] = "text/plain" 224: 225: atom_entry 226: end