Applying mathematical calculations on data in the variables

JDeveloper provides the standard set of mathematical calculations that can be used in the BPEL processes. We will use the mathematical calculations on numerically defined variables.

Getting ready

This recipe continues the discussion of the BPEL process Manipulate1_1 from the Assigning numerical values to the variables recipe.

We extend the request and response message structure in Manipulate1_1.xsd. The request message is extended with the item and priceVAT elements as follows:

<element name = "process">
  <complexType>
    <sequence>
      <element name = "input" type = "string"/>
      <element name = "item" type = "string"/>
      <element name = "priceVAT" type = "decimal"/>
      <element name = "child_no" type = "integer"/>
    </sequence>
  </complexType>
</element>

The response message is extended with the priceNet and vat elements as follows:

<element name = "processResponse">
  <complexType>
    <sequence>
      <element name = "result" type = "string"/>
      <element name = "priceNet" type = "decimal"/>
      <element name = "vat" type = "decimal"/>
      <element name = "child_selection" type = "string"/>
    </sequence>
  </complexType>
</element>

In this recipe, we will look at the calculation needed to insert the gross price of an item. In the BPEL process, we will calculate the net price of the item along with the VAT included in the gross price. We assume that the VAT included in the gross price is always 20 percent.

How to do it…

  1. Open the BPEL process and add the assign activity (MathCalc).
  2. We will now calculate the net price of the item. For that purpose, we use the divide, round, and multiply mathematical functions. Next, we calculate the VAT included in the gross price of the item.
    How to do it…
  3. Deploy the BPEL process and run the instance of it on Oracle SOA Suite for the following input request:
    <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>100</ns1:priceVAT>
        </ns1:process>
      </part>
    </inputVariable>
  4. We receive the corresponding response from the BPEL process as follows:
    <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>83.33</priceNet>
          <vat>16.67</vat>
        </processResponse>
      </part>
    </outputVariable>

How it works…

We can utilize the following most common mathematical functions from within the JDeveloper GUI:

Mathematical function

Source code signature

Function returns

abs

xp20:abs()

Absolute value.

add

+

Addition of two numbers.

ceiling

ceiling()

The smallest number that is not less than the argument and is of integer type.

count

count()

The number of nodes.

divide

div

The division of two numbers.

floor

floor()

The largest number that is not greater than the argument and is of integer type.

mod

mod

Reminder of the truncation division.

multiply

*

Multiplication of two arguments.

round

round()

Rounds the argument to the nearest integer number.

square-root

oraext:square-root()

Square root of the argument.

subtract

-

Subtraction of two numbers.

sum

sum()

Sum of all the arguments (nodes).

unary

-()

Invert the operation of the argument.

..................Content has been hidden....................

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