lib/openwfe/expressions/fe_iterator.rb in openwferu-0.9.8 vs lib/openwfe/expressions/fe_iterator.rb in openwferu-0.9.9
- old
+ new
@@ -37,10 +37,11 @@
# "made in Japan"
#
# John Mettraux at openwfe.org
#
+require 'openwfe/expressions/wtemplate'
require 'openwfe/expressions/flowexpression'
module OpenWFE
@@ -55,56 +56,58 @@
# field="${user-name} comment"
# value="(please fill this field)"
# />
# </iterator>
#
- # Within the iteration, the workitem field "__ic__" contains the number
- # of elements in the iteration and the field "__ip__" the index of the
+ # Within the iteration, the workitem field "\_\_ic__" contains the number
+ # of elements in the iteration and the field "\_\_ip__" the index of the
# current iteration.
#
class IteratorExpression < WithTemplateExpression
names :iterator
- attr_accessor \
- :iterator
+ attr_accessor :iterator
def apply (workitem)
if @children.length < 1
reply_to_parent(workitem)
return
end
@iterator = Iterator.new(self, workitem)
- reply(workitem)
+ reply workitem
end
def reply (workitem)
unless @iterator.has_next?
reply_to_parent(workitem)
return
end
- @iterator.next(self, workitem)
+ vars = @iterator.next(self, workitem)
store_itself()
get_expression_pool.launch_template(
- self, @iterator.counter-1, @children[0], workitem, nil)
+ self, @iterator.index, @children[0], workitem, vars)
end
end
#
# Iterator instances keep track of the position of an iteration.
# This class is meant to be used both by <iterator> and
# <concurrent-iterator>.
#
class Iterator
+ ITERATOR_COUNT = "__ic__"
+ ITERATOR_POSITION = "__ip__"
+
attr_accessor \
:iteration_list,
:to_field,
:to_variable,
:value_separator,
@@ -127,11 +130,11 @@
raw_list = iterator_expression.lookup_vf_attribute(
workitem, :value, :on)
@iteration_list = extract_iteration_list(raw_list)
- workitem.attributes['__ic__'] = @iteration_list.length
+ workitem.attributes[ITERATOR_COUNT] = @iteration_list.length
end
#
# Has the iteration a next element ?
#
@@ -143,20 +146,30 @@
# Prepares the iterator expression and the workitem for the next
# iteration.
#
def next (iterator_expression, workitem)
+ result = {}
+
value = @iteration_list.pop
if @to_field
workitem.attributes[@to_field] = value
else
- iterator_expression.set_variable(@to_variable, value)
+ #iterator_expression.set_variable(@to_variable, value)
+ result[@to_variable] = value
end
- workitem.attributes['__ip__'] = @counter
+ workitem.attributes[ITERATOR_POSITION] = @counter
+ result[ITERATOR_POSITION] = @counter
@counter = @counter + 1
+
+ result
+ end
+
+ def index
+ return @counter - 1
end
protected
def extract_iteration_list (raw_list)