Class: OpenWFE::Extras::ActivityFeedService

Inherits:
Object
  • Object
show all
Includes:
OwfeServiceLocator, ServiceMixin
Defined in:
lib/openwfe/extras/misc/activityfeed.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_name, application_context) ⇒ ActivityFeedService

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.



110
111
112
113
114
115
116
117
118
119
120
# File 'lib/openwfe/extras/misc/activityfeed.rb', line 110

def initialize (service_name, application_context)

    super()

    service_init service_name, application_context

    @entries = []
    @max_item_count = 100

    get_participant_map.add_observer ".*", self
end

Instance Attribute Details

#max_item_countObject

Returns the value of attribute max_item_count.



99
100
101
# File 'lib/openwfe/extras/misc/activityfeed.rb', line 99

def max_item_count
  @max_item_count
end

Instance Method Details

#call(channel, *args) ⇒ Object

This is the method call by the expression pool each time a workitem reaches a participant.



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/openwfe/extras/misc/activityfeed.rb', line 126

def call (channel, *args)

    ldebug "call() c '#{channel}' entries count : #{@entries.size}"

    e = Entry.new

    e.participant_name = channel
    e.upon = args[0]
    e.workitem = args[1].dup

    e.id = \
        "#{e.workitem.participant_name} - #{e.upon} " +
        "#{e.workitem.fei.workflow_instance_id}--" +
        "#{e.workitem.fei.expression_id}"

    @entries << e

    @entries = @entries[0, @max_item_count] \
        if @entries.length > @max_item_count
end

#get_feed(participant_regex, options = {}) ⇒ Object

Returns an Atom feed of all the workitem activity for the participants whose name matches the given regular expression.

Options :

:upon

can be set to either nil, :apply, :reply. :apply states that the returned feed should only contain entries about participant getting applied, :reply only about participant replying.

:feed_uri

the URI for the feed. Defaults to ‘localhost/feed

:feed_title

the title for the feed. Defaults to ‘OpenWFEru engine activity feed’

:format

yaml|text|json



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/openwfe/extras/misc/activityfeed.rb', line 164

def get_feed (participant_regex, options={})

    participant_regex = Regexp.compile(participant_regex) \
        if participant_regex.is_a?(String)

    upon = options[:upon]
    feed_uri = options[:feed_uri] || "http://localhost/feed"
    title = options[:feed_title] || "OpenWFEru engine activity feed"

    feed = Atom::Collection.new feed_uri
    feed.title = title

    format = options[:format]
    format = validate_format(format)

    @entries.each do |e|

        next unless participant_regex.match(e.participant_name)
        next if upon and upon != e.upon

        feed.updated = e.updated \
            if feed.updated == nil or e.updated > feed.updated

        feed << as_atom_entry(format, e)
    end

    feed
end