Class: OpenWFE::Extras::AtomFeedParticipant

Inherits:
Object
  • Object
show all
Includes:
LocalParticipant, MonitorMixin, TemplateMixin
Defined in:
lib/openwfe/extras/participants/atomfeed_participants.rb

Overview

Stores the incoming workitem into an ‘atom feed’

An example :

feed0 = AtomFeedParticipant.new(
    20,                          # no more than 20 entries are kept
    """
    <p>
        <h1>${f:colour}</h1>
    </p>
    """)                         # the template for each entry

The ‘template’ parameter may contain an instance of File instead of an instance of String.

feed0 = AtomFeedParticipant.new(
    20, File.new("path/to/my/atom/template.txt")

The template can be passed as the second parameter (after the max entry count) or as a block :

feed1 = AtomFeedParticipant.new(20) do |flow_expression, atom_participant, workitem|
    #
    # usually only the workitem parameter is used
    # but the other two allow for advanced tricks...

    atom_participant.content_type = "xml"
        # by default, it's "xhtml"

    s = "<task>"
    s << "<name>#{workitem.task_name}</name>"
    s << "<assignee>#{workitem.task_assignee}</assignee>"
    s << "<duedate>#{workitem.task_duedate}</duedate>"
    s << "</task>"

    # the block is supposed to 'return' a string which is the
    # effective template
end

This participant uses “atom-tools” from code.necronomicorp.com/trac/atom-tools

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_item_count, template = nil, &block) ⇒ AtomFeedParticipant

Returns a new instance of AtomFeedParticipant.



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/openwfe/extras/participants/atomfeed_participants.rb', line 112

def initialize (max_item_count, template=nil, &block)

    super() # very important as this class includes MonitorMixin

    @template = template
    @max_item_count = max_item_count
    @block_template = block

    @feed = Atom::Collection.new("http://localhost")
    @content_type = "xhtml"
end

Instance Attribute Details

#content_typeObject

Made accessible so that blocks may set it.



110
111
112
# File 'lib/openwfe/extras/participants/atomfeed_participants.rb', line 110

def content_type
  @content_type
end

Instance Method Details

#consume(workitem) ⇒ Object



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

def consume (workitem)

    e = Atom::Entry.new

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

    e.title = workitem.atom_entry_title
    e.content = render(workitem)

    e.content["type"] = @content_type

    @feed << e

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

    publish workitem

    reply_to_engine workitem
end