Dynamic indexing of the variables

In situations where we have information in a list of the same elements, it is not possible to access a variable by name. Rather, we use indexing to access the variable data from a list.

Getting ready

We will examine dynamic indexing of the variables in the Manipulate1_1 BPEL process from the Assigning date or time to the variables recipe.

First, let's extend the BPEL process by defining a new element in the Manipulate1_1 schema file as follows:

<element name = "ChildrenElementType">
  <complexType>
    <sequence>
      <element name = "child" type = "string" minOccurs = "1" maxOccurs = "unbounded"/>
    </sequence>
  </complexType>
</element>

The Element-type variable is defined as an array of the <child> strings.

Also, we modify the request and response messages of the BPEL process. We amend the request message with the following element:

<element name = "child_no" type = "integer"/>

We will use this to input the element in the child list we want to query. We add the following element to the response message:

<element name = "child_selection" type = "string"/>

The Element-type variable will contain information about the selected child from the list.

How to do it…

In order to dynamically index the variable contet, we perform the following steps:

  1. We start by adding the assign scope (DynamicScope) and sequence activity (DynamicSequence) into our BPEL process.
  2. Inside the scope, we define two local variables. The ChildSelection variable holds information about the list. We define index to perform the dynamic query in the list.
    <variables>
      <variable name = "ChildSelection" element = "client:ChildrenElementType"/>
      <variable name = "index" type = "xsd:integer"/>
    </variables>
  3. We need to fill up the content into the input parameter variable. For that purpose, we add an assign activity (InitChildren) to initialize the list of information as follows:
    <assign name = "InitChildren">
      <copy>
        <from><client:ChildrenElementType xmlns:client = "http://xmlns.oracle.com/Variables/Global/Manipulate1_1">
          <client:child>Ajda</client:child>
          <client:child>Urban</client:child>
          </client:ChildrenElementType></from>
        <to variable = "ChildSelection"/>
      </copy>
    </assign>
  4. Next, we build up the logic for the input variable validation. The building blocks consist of the switch activity with two decision branches. The positive branch checks if the child_no element is set in the request message and in the specified range.
    <case condition = "bpws:getVariableData('inputVariable','payload', '/client:process/client:child_no') &lt; 3 and bpws:getVariableData('inputVariable','payload', '/client:process/client:child_no') > 0">
  5. If true, we retrieve the queried child element as follows:
    <assign name = "GetDynamic">
      <copy>
        <from variable = "inputVariable" part = "payload" query = "/client:process/client:child_no"/>
        <to variable = "index"/>
      </copy>
      <copy>
        <from expression = "bpws:getVariableData('ChildSelection','/client:ChildrenElementType')/client:child[bpws:getVariableData('index')]"/>
        <to variable = "outputVariable" part = "payload" query = "/client:processResponse/client:child_selection"/>
      </copy>
    </assign>
  6. Otherwise, we gracefully return the message to the caller as follows:
    <assign name = "AssignNoAction">
      <copy>
        <from expression = "'No value for selection or selection out of bounds'"/>
        <to variable = "outputVariable" part = "payload" query = "/client:processResponse/client:child_selection"/>
      </copy>
    </assign>
  7. Deploy the BPEL process to Oracle SOA Suite and run an instance of it. As an input, insert the following data:
    <inputVariable>
      <part name = "payload" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance">
        <ns1:process xmlns:ns1 = "http://xmlns.oracle.com/Variables/Global/Manipulate1_1">
          <ns1:input>Jurij</ns1:input>
          <ns1:item>PC</ns1:item>
          <ns1:priceVAT>1234</ns1:priceVAT>
          <ns1:child_no>2</ns1:child_no>
        </ns1:process>
      </part>
    </inputVariable>
  8. We receive the following response from the BPEL process:
    <outputVariable>
      <part name = "payload" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance">
        <processResponse xmlns = "http://xmlns.oracle.com/Variables/Global/Manipulate1_1">
          <result>Jurij</result>
          <priceNet>1028.33</priceNet>
          <vat>205.67</vat>
          <child_selection>Urban</child_selection>
        </processResponse>
      </part>
    </outputVariable>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset