Contional Expressions

4 views
Skip to first unread message

emil...@gmail.com

unread,
Jan 8, 2009, 11:37:25 AM1/8/09
to openwfe...@googlegroups.com
Hello John, all,

(and Happy New Year!)

While dealing with some workflow definitions, I have come across a number of
issues related to the OpenWFE language itself. I'm focused in doing all the
flow definitions using XML expressions, but unfortunately I have found that
most documentation of the expressions in
http://openwferu.rubyforge.org/expressions.html is Ruby-based. I have also
checked the original OpenWFE manual (http://www.openwfe.org/manual), and
after testing I have found that not everything is working (for example, the
<not> tag for a condition, or the <loop> with <until>).

I need to do some very basic things, such as loops and conditions, and it
would be of much help if you could indicate me the correct way to do a
comparison: to know if a field named "my_field" has a value of "25", which
one is the correct way?

A.
<if>
<equals field-value="my_field" other-value="25"/>
...
B.
<if>
<equals field="${f:my_field}" other-value="25"/>
...

C.
<if>
<equals field-value="${f:my_field}" other-value="25"/>
...

D.
<if test="${f:my_field} == 25" />
...

Or maybe "other-value" has to be another field?

The reason I'm asking this is because I have seen some conflicting
expressions in the documentation, and now I'm a bit confused. Can you help
me?

Thank you very much, and kind regards,

Emilio

John Mettraux

unread,
Jan 8, 2009, 7:03:39 PM1/8/09
to openwfe...@googlegroups.com
On Fri, Jan 9, 2009 at 1:37 AM, <emil...@gmail.com> wrote:
>
> While dealing with some workflow definitions, I have come across a number of
> issues related to the OpenWFE language itself. I'm focused in doing all the
> flow definitions using XML expressions, but unfortunately I have found that
> most documentation of the expressions in
> http://openwferu.rubyforge.org/expressions.html is Ruby-based.

Hi Emilio,

a Happy New Year to you as well.

In fact there is a 1 to 1 mapping from XML to Ruby. When you have
something like :

if :test => "${f:customer_class} == important" do
participant :ref => "${f:customer}"
end

It can be translated directly to :

<if test="${f:customer_class} == important">
<participant ref="${f:customer}"
</if>

There is only one "exception", this :

participant "toto", :if => "${f:contract} == signed"

will be translated to :

<participant if="${f:contract} == signed">toto</participant>

(this is equivalent to <participant ref="toto" if="${f:contract} == signed" />)

I have started right before Christmas a piece of documentation on the
relation between those two dialects (XML and Ruby), it's at

http://openwferu.rubyforge.org/definitions.html

Note that behind the scene, Ruote deals with trees of expressions, not
XML or Ruby directly. (that would mean that anything that can generate
those trees can produce process definitions, but that's another
story).


> I have also checked the original OpenWFE manual (http://www.openwfe.org/manual), and
> after testing I have found that not everything is working (for example, the
> <not> tag for a condition, or the <loop> with <until>).

Yes, when moving from OpenWFE to Ruote (OpenWFEru), I simplified the
<loop> by merging it with <cursor>. The loop is now simply a cursor
that always "rewind". Cursor and loop share the same subcommands back,
break, rewind, cancel, continue, jump, skip, as detailed at
http://openwferu.rubyforge.org/expressions.html#exp_cursor

<not> can be replaced by things like <if test="${f:my_field} != 25">...</if>


> I need to do some very basic things, such as loops and conditions, and it
> would be of much help if you could indicate me the correct way to do a
> comparison: to know if a field named "my_field" has a value of "25", which
> one is the correct way?
>
> A.
> <if>
> <equals field-value="my_field" other-value="25"/>

This is correct.

> B.
> <if>
> <equals field="${f:my_field}" other-value="25"/>

This is correct.

> C.
> <if>
> <equals field-value="${f:my_field}" other-value="25"/>

This will check if the field named with the value found in my_field
holds the value 25.

So if incidentally my_field holds the value 25, this piece of process
will be equivalent to

<equals field-value="25" other-value="25" />

> D.
> <if test="${f:my_field} == 25" />

This is correct.

> Or maybe "other-value" has to be another field?

If you want to check the value of two fields, you can write :

<equals field-value="field-a" other-field-value="field-b" />

or

<if test="${f:field-a} == ${f:field-b}>...</if>

There is an important distinction though. ${...} tests are done at the
string representation level, ie the values held by the fields will not
be compared directly, but their string representation will. By using
<equals field-value="..." other-field-value="..." /> a 'real' value
comparison is done.


Note that if you don't want to have to many "ifs" and conditions in
your process definition a good practice is to outsource decisions to a
decision participant. Some example documentation at

http://openwferu.rubyforge.org/decision.html
http://jmettraux.wordpress.com/2008/01/28/rufus-decision-csv-decision-tables/


The basic idea is to rewrite that can get out of control like :

<if test="${f:customer_class} == 'platinum'>
<salesman-1 />
<salesman-2 />
</if>

to :

<sequence>
<customer-attribution-participant />
<participant ref="${f:salesman}" />
</sequence>

So that you change the implementation (or the Excel sheet) of the
[decision] participant (here 'customer-attribution-participant') and
not the process definition when the company policy for customer
handling changes. (In this final sequence, the decision participant
sets the value of the field 'salesman', which is then reused as the
participant name).


I'm happy to help with your process definitions. Feel free to point at
points in the documentation that you find weak and I'll make them
better (or if you simply need an XML translation there).


Kind regards,

--
John Mettraux - http://jmettraux.wordpress.com

Reply all
Reply to author
Forward
0 new messages