lib/openwfe/expressions/fe_equals.rb in ruote-0.9.18 vs lib/openwfe/expressions/fe_equals.rb in ruote-0.9.19
- old
+ new
@@ -1,34 +1,34 @@
#
#--
# Copyright (c) 2006-2008, John Mettraux, OpenWFE.org
# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
+#
+# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
-#
+#
# . Redistributions of source code must retain the above copyright notice, this
-# list of conditions and the following disclaimer.
-#
-# . Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
+# list of conditions and the following disclaimer.
+#
+# . Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
-#
+#
# . Neither the name of the "OpenWFE" nor the names of its contributors may be
# used to endorse or promote products derived from this software without
# specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#++
#
#
@@ -46,246 +46,246 @@
# expressions like 'set' and 'unset' and their utility methods
#
module OpenWFE
- #
- # A Mixin shared by CompareExpression and DefinedExpression.
- #
- module LookupMixin
+ #
+ # A Mixin shared by CompareExpression and DefinedExpression.
+ #
+ module LookupMixin
- protected
+ protected
- def lookup_var_value (workitem, suffix=nil)
+ def lookup_var_value (workitem, suffix=nil)
- v = lookup_var workitem, suffix
+ v = lookup_var workitem, suffix
- return lookup_variable(v) if v
-
- nil
- end
+ return lookup_variable(v) if v
- def lookup_field_value (workitem, suffix=nil)
+ nil
+ end
- f = lookup_field workitem, suffix
+ def lookup_field_value (workitem, suffix=nil)
- return workitem.attributes[f] if f
+ f = lookup_field workitem, suffix
- nil
- end
+ return workitem.attributes[f] if f
- def lookup_var (workitem, suffix=nil)
+ nil
+ end
- do_lookup workitem, suffix, [ :variable, :var, :v ]
- end
+ def lookup_var (workitem, suffix=nil)
- def lookup_field (workitem, suffix=nil)
+ do_lookup workitem, suffix, [ :variable, :var, :v ]
+ end
- do_lookup workitem, suffix, [ :field, :f ]
- end
+ def lookup_field (workitem, suffix=nil)
- def do_lookup (workitem, suffix, atts)
+ do_lookup workitem, suffix, [ :field, :f ]
+ end
- atts.each do |a|
- a = a.to_s + '-' + suffix if suffix
- v = lookup_string_attribute a, workitem
- return v if v
- end
+ def do_lookup (workitem, suffix, atts)
- nil
- end
- end
+ atts.each do |a|
+ a = a.to_s + '-' + suffix if suffix
+ v = lookup_string_attribute a, workitem
+ return v if v
+ end
- #
- # A parent class for the 'equals' expression.
- #
- # (there should be a 'greater-than' and a 'lesser-than' expression,
- # but there are not that needed for now).
- #
- class ComparisonExpression < FlowExpression
- include LookupMixin
+ nil
+ end
+ end
- def apply (workitem)
+ #
+ # A parent class for the 'equals' expression.
+ #
+ # (there should be a 'greater-than' and a 'lesser-than' expression,
+ # but there are not that needed for now).
+ #
+ class ComparisonExpression < FlowExpression
+ include LookupMixin
- #
- # preparing for children handling... later...
- #
+ def apply (workitem)
- reply workitem
- end
+ #
+ # preparing for children handling... later...
+ #
- def reply (workitem)
+ reply workitem
+ end
- value_a, value_b = lookup_values workitem
+ def reply (workitem)
- result = compare value_a, value_b
+ value_a, value_b = lookup_values workitem
- ldebug { "apply() result is '#{result}' #{@fei.to_debug_s}" }
+ result = compare value_a, value_b
- workitem.set_result result
+ ldebug { "apply() result is '#{result}' #{@fei.to_debug_s}" }
- reply_to_parent workitem
- end
+ workitem.set_result result
- protected
+ reply_to_parent workitem
+ end
- #
- # The bulk job of looking up the values to compare
- #
- def lookup_values (workitem)
+ protected
- value_a = lookup_value workitem
- value_b = lookup_value workitem, :prefix => 'other'
+ #
+ # The bulk job of looking up the values to compare
+ #
+ def lookup_values (workitem)
- value_c = lookup_variable_or_field_value workitem
+ value_a = lookup_value workitem
+ value_b = lookup_value workitem, :prefix => 'other'
- if not value_a and value_b
- value_a = value_c
- elsif value_a and not value_b
- value_b = value_c
- end
+ value_c = lookup_variable_or_field_value workitem
- [ value_a, value_b ]
- end
+ if not value_a and value_b
+ value_a = value_c
+ elsif value_a and not value_b
+ value_b = value_c
+ end
- #
- # Returns the value pointed at by the variable attribute or by
- # the field attribute, in that order.
- #
- def lookup_variable_or_field_value (workitem)
+ [ value_a, value_b ]
+ end
- lookup_var_value(workitem) || lookup_field_value(workitem)
- end
- end
+ #
+ # Returns the value pointed at by the variable attribute or by
+ # the field attribute, in that order.
+ #
+ def lookup_variable_or_field_value (workitem)
- #
- # The 'equals' expression compares two values. If those values are equal,
- # the field (attribute) of the workitem named '__result__' will be
- # set to true (else false).
- #
- # Usually, this expression is used within the 'if' expression.
- #
- # <if>
- # <equals field-value="customer_name" other-value="Dupont" />
- # <!-- then -->
- # <participant ref="special_salesman" />
- # <!-- else -->
- # <participant ref="ordinary_salesman" />
- # </if>
- #
- # (The 'if' expression reads the '__result__' field to route the flow
- # either towards the then branch, either towards the else one).
- #
- #
- # With a Ruby process definition, a variation on the same 'equals' :
- #
- # equals :field_value => "phone", :other_value => "090078367"
- # equals :field_val => "phone", :other_value => "090078367"
- # equals :f_value => "phone", :other_value => "090078367"
- # equals :f_val => "phone", :other_value => "090078367"
- # equals :f_val => "phone", :other_val => "090078367"
- #
- # Thus, note that 'variable' in an expression attribute can be
- # shortened to 'var' or 'v'. 'value' can be shortened to 'val' and
- # 'field' to 'f'.
- #
- # Usually, the "test" attribute of the "if" expression is preferred
- # over this 'equals' expression, like in :
- #
- # <if test="${f:customer_name} == Dupont">
- # <!-- then -->
- # <participant ref="special_salesman" />
- # <!-- else -->
- # <participant ref="ordinary_salesman" />
- # </if>
- #
- # Another shortcut : the 'participant' and the 'subprocess' expressions
- # accept an optional 'if' (or 'unless') attribute, so that ifs can be
- # contracted to :
- #
- # participant :ref => "toto", :if => "${f:customer_name} == Alfred"
- # subprocess :ref => "special_delivery", :if => "'${f:special}' != ''"
- #
- # This also works with the implicit form of the participant and the
- # subprocess :
- #
- # toto :if => "${f:customer_name} == Alfred"
- # special_delivery :if => "'${f:special}' != ''"
- #
- class EqualsExpression < ComparisonExpression
+ lookup_var_value(workitem) || lookup_field_value(workitem)
+ end
+ end
- names :equals
+ #
+ # The 'equals' expression compares two values. If those values are equal,
+ # the field (attribute) of the workitem named '__result__' will be
+ # set to true (else false).
+ #
+ # Usually, this expression is used within the 'if' expression.
+ #
+ # <if>
+ # <equals field-value="customer_name" other-value="Dupont" />
+ # <!-- then -->
+ # <participant ref="special_salesman" />
+ # <!-- else -->
+ # <participant ref="ordinary_salesman" />
+ # </if>
+ #
+ # (The 'if' expression reads the '__result__' field to route the flow
+ # either towards the then branch, either towards the else one).
+ #
+ #
+ # With a Ruby process definition, a variation on the same 'equals' :
+ #
+ # equals :field_value => "phone", :other_value => "090078367"
+ # equals :field_val => "phone", :other_value => "090078367"
+ # equals :f_value => "phone", :other_value => "090078367"
+ # equals :f_val => "phone", :other_value => "090078367"
+ # equals :f_val => "phone", :other_val => "090078367"
+ #
+ # Thus, note that 'variable' in an expression attribute can be
+ # shortened to 'var' or 'v'. 'value' can be shortened to 'val' and
+ # 'field' to 'f'.
+ #
+ # Usually, the "test" attribute of the "if" expression is preferred
+ # over this 'equals' expression, like in :
+ #
+ # <if test="${f:customer_name} == Dupont">
+ # <!-- then -->
+ # <participant ref="special_salesman" />
+ # <!-- else -->
+ # <participant ref="ordinary_salesman" />
+ # </if>
+ #
+ # Another shortcut : the 'participant' and the 'subprocess' expressions
+ # accept an optional 'if' (or 'unless') attribute, so that ifs can be
+ # contracted to :
+ #
+ # participant :ref => "toto", :if => "${f:customer_name} == Alfred"
+ # subprocess :ref => "special_delivery", :if => "'${f:special}' != ''"
+ #
+ # This also works with the implicit form of the participant and the
+ # subprocess :
+ #
+ # toto :if => "${f:customer_name} == Alfred"
+ # special_delivery :if => "'${f:special}' != ''"
+ #
+ class EqualsExpression < ComparisonExpression
- protected
+ names :equals
- def compare (a, b)
+ protected
- (a == b)
- end
- end
+ def compare (a, b)
- #
- # This expression class actually implements 'defined' and 'undefined'.
- #
- # They are some kind of 'equals' for validating the presence or not
- # of a variable or a workitem field (attribute).
- #
- # <if>
- # <defined field="customer">
- # <!-- then -->
- # <subprocess ref="call_customer" />
- # </if>
- #
- # Since OpenWFEru 0.9.17, 'defined' and 'undefined' can be easily replaced
- # by the "is [not ]set" suffix in the dollar notation :
- #
- # <if test="${f:customer_name} is set">
- # <!-- then -->
- # <subprocess ref="call_customer" />
- # </if>
- #
- class DefinedExpression < FlowExpression
- include LookupMixin
+ (a == b)
+ end
+ end
- names :defined, :undefined
+ #
+ # This expression class actually implements 'defined' and 'undefined'.
+ #
+ # They are some kind of 'equals' for validating the presence or not
+ # of a variable or a workitem field (attribute).
+ #
+ # <if>
+ # <defined field="customer">
+ # <!-- then -->
+ # <subprocess ref="call_customer" />
+ # </if>
+ #
+ # Since OpenWFEru 0.9.17, 'defined' and 'undefined' can be easily replaced
+ # by the "is [not ]set" suffix in the dollar notation :
+ #
+ # <if test="${f:customer_name} is set">
+ # <!-- then -->
+ # <subprocess ref="call_customer" />
+ # </if>
+ #
+ class DefinedExpression < FlowExpression
+ include LookupMixin
- def apply (workitem)
+ names :defined, :undefined
- fname = lookup_field(workitem, 'value') || lookup_field(workitem)
+ def apply (workitem)
- fmatch = lookup_string_attribute(:field_match, workitem)
+ fname = lookup_field(workitem, 'value') || lookup_field(workitem)
- vname = lookup_var(workitem, 'value') || lookup_var(workitem)
+ fmatch = lookup_string_attribute(:field_match, workitem)
- result = if fname
- workitem.has_attribute?(fname)
- elsif vname
- lookup_variable(vname) != nil
- elsif fmatch
- field_match?(workitem, fmatch)
- else
- false # when in doubt, say 'no' (even when 'undefined' ?)
- end
+ vname = lookup_var(workitem, 'value') || lookup_var(workitem)
- result = ( ! result) \
- if result != nil and fei.expression_name == 'undefined'
+ result = if fname
+ workitem.has_attribute?(fname)
+ elsif vname
+ lookup_variable(vname) != nil
+ elsif fmatch
+ field_match?(workitem, fmatch)
+ else
+ false # when in doubt, say 'no' (even when 'undefined' ?)
+ end
- workitem.set_result result
+ result = ( ! result) \
+ if result != nil and fei.expression_name == 'undefined'
- reply_to_parent workitem
- end
+ workitem.set_result result
- protected
+ reply_to_parent workitem
+ end
- def field_match? (workitem, regex)
+ protected
- workitem.attributes.each do |k, v|
+ def field_match? (workitem, regex)
- return true if k.match(regex)
- end
+ workitem.attributes.each do |k, v|
- false
- end
- end
+ return true if k.match(regex)
+ end
+
+ false
+ end
+ end
end