2013-11-18

XPath Expression As Action Parameters

A new feature in the latest edition of OpenGroupware Coils [0.1.49rc67] is support for using XPath expressions as parameters for work-flow actions.  When a work-flow action parameter begins with "$XPath:" the input message (which must be XML) is interrogated for the corresponding value prior to the action being performed.  Evaluation of the XPath is performed after label substution allowing wild cards to be used to construct the query expression.
One use-case where this is frequently useful is when processing the "current" message within a foreach construct.

<foreach name="foreachActivity" id="1ee1e121"
         extensionAttributes="SendSomeNotifications/1ee1e121"
         select="/ResultSet/row/dispatched_to[text()!='none']/..">
  <source property="NotificationData"/>
  <attributes/>
  <action name="actionActivity" id="04334"
           extensionAttributes="SendSomeNotifications/04334">
    <output><source property="current"/></output>
    <attributes xmlns="">
      <extension name="activityName">sendMailAction</extension>
      <extension name="bodyText">$XPath:/row/message/text()</extension>
      <extension name="subject">$XPath:/row/subject/text()</extension>
      <extension name="from">opengroupware@example.com</extension>
      <extension name="to">$XPath:/row/dispatched_to/text()</extension>
      <extension name="asAttachment">NO</extension>
    </attributes>
  </action>
</foreach>

Via the XPath expression values can be retrieved from "current" as parameters to the action allowing the elements of the current iteration to drive work-flow actions.  In this example StandardXML rows [such as from an sqlSelectAction] are iterated producing e-mail messages based on the content of the rows.  The select element of the foreach construct chooses only those rows with a "dispathed_to" value other than "none".  The sendMailAction is then performed selecting the message body, subject, and target address from the element being iterated [the "current" message].
For efficiency the action's input message is deserialized only if an XPath expression is used,and it is only deserialized once for each iteration regardless of the number of XPath expressions used.

No comments:

Post a Comment