lib/openwfe/expressions/fe_value.rb in openwferu-0.9.7 vs lib/openwfe/expressions/fe_value.rb in openwferu-0.9.8

- old
+ new

@@ -39,30 +39,38 @@ # John Mettraux at openwfe.org # require 'openwfe/workitem' require 'openwfe/flowexpressionid' -require 'openwfe/expressions/condition' require 'openwfe/expressions/flowexpression' -require 'openwfe/expressions/fe_utils' # # expressions like 'set' and 'unset' and their utility methods # module OpenWFE + # + # The 'set' expression is used to set the value of a (process) variable or + # a (workitem) field. + # + # <set field="price" value="CHF 12.00" /> + # <set variable="/stage" value="3" /> + # <set variable="/stage" field-value="f_stage" /> + # <set field="stamp" value="${r:Time.now.to_i}" /> + # + # (Notice the usage of the dollar notation in the last exemple). + # class SetValueExpression < FlowExpression names :set def apply (workitem) if @children.length < 1 - workitem.attributes[FIELD_RESULT] = \ - OpenWFE::lookup_value(self, workitem) + workitem.attributes[FIELD_RESULT] = lookup_value(workitem) reply(workitem) return end child = @children[0] @@ -71,12 +79,11 @@ handle_child(child, workitem) return end #workitem.attributes[FIELD_RESULT] = child.to_s - workitem.attributes[FIELD_RESULT] = \ - OpenWFE::fetch_text_content(self, workitem) + workitem.attributes[FIELD_RESULT] = fetch_text_content(workitem) reply(workitem) end def reply (workitem) @@ -121,14 +128,20 @@ # return "nada" # else # return child # end # end - # return OpenWFE::lookup_value(self, workitem) + # return lookup_value(workitem) #end end + # + # 'unset' removes a field or a variable. + # + # unset :field => "price" + # unset :variable => "eval_result" + # class UnsetValueExpression < FlowExpression names :unset def apply (workitem) @@ -147,123 +160,9 @@ reply_to_parent(workitem) end #def reply (workitem) #end - end - - class ComparisonExpression < FlowExpression - - def apply (workitem) - - value_a = OpenWFE::lookup_value(self, workitem) - value_b = OpenWFE::lookup_value(self, workitem, 'other') - - result = compare(value_a, value_b) - - ldebug { "apply() result is '#{result}' #{@fei.to_debug_s}" } - - OpenWFE::set_result(workitem, result) - - reply_to_parent(workitem) - end - - protected - - def compare (a, b) - raise "not yet implemented : '#{@fei.expressionName}'" - end - end - - # - # <equals/> - # - class EqualsExpression < ComparisonExpression - - names :equals - - protected - - def compare (a, b) - #ldebug { "compare() #{fei.to_debug_s}" } - #ldebug { "compare() '#{a}' == '#{b}'" } - return a == b - end - end - - # - # <if/> - # - class IfExpression < FlowExpression - include ConditionMixin - - names :if - - attr_accessor \ - :condition_replied - - def apply (workitem) - - reply_to_parent(workitem) if @children.length < 1 - - test = eval_condition(:test, workitem) - - @condition_replied = (test != nil) - # - # if the "test" attribute is not used, test will be null - - store_itself() - - if test != nil - apply_consequence(test, workitem, 0) - else - get_expression_pool.apply(@children[0], workitem) - end - end - - def reply (workitem) - - if @condition_replied - reply_to_parent(workitem) - return - end - - result = workitem.attributes[FIELD_RESULT] - - @condition_replied = true - - store_itself() - - apply_consequence(result, workitem) - end - - def reply_to_parent(workitem) - clean_children() - super(workitem) - end - - protected - - def apply_consequence (index, workitem, offset=1) - - if index == true - index = 0 - elsif index == false - index = 1 - elsif index == nil - index = 1 - elsif not index.integer? - index = 0 - end - - index = index + offset - - if index >= @children.length - reply_to_parent(workitem) - else - get_expression_pool.apply(@children[index], workitem) - end - end end end