In the previous chapter, we introduced three bookstores into our composite BPEL application, BookstoreA
, BookstoreB
, and AnotherBookstore
. Let's now modify the conditions in the <if>
activity, where we select the bookstore with the lowest book quantity. We have to compare three book quantities of stores in the BookstoreAResponse
, BookstoreBResponse
, and AnotherBookstoreResponse
variables. To access the BookstoreAResponse
quantity, we should use the following XPath expression:
$BookstoreAResponse.payload/ns1:StockQuantity
Similarly, we would access the BookstoreB
and AnotherBookstore
stock quantities.
To select the lowest quantity, we should do the following comparisons:
BookstoreA
stock quantity to BookstoreB
and AnotherBookstore
. If the BookstoreA
stock quantity is lower or equal in both cases, select BookstoreA
.BookstoreB
stock quantity to BookstoreA
and AnotherBookstore
. If the BookstoreB
stock quantity is lower or equal in both cases, select BookstoreB
.AnotherBookstore
stock quantity to BookstoreA
and BookstoreB
. If the AnotherBookstore
stock quantity is lower or equal in both cases, select AnotherBookstore
.Let us now implement this in BPEL:
<if>
and for the other two, we will use <elseif>
. As with the three branches, we have covered all possibilities, and so we will not use the <else>
activity in this case:We have implemented the condition for selecting the bookstore with the lowest stock quantity. To get a better understanding, we should switch to the source code and carefully review it. To check whether BookstoreA
has the lowest stock quantity, we have defined the following condition:
To check whether BookstoreB
has the lowest stock quantity, we have defined the following condition:
To check whether AnotherBookstore
has the lowest stock quantity, we have defined the following condition:
Please note that in the preceding code, we have used the <
entity, which is used in XML to represent the <
sign, which cannot be used directly. The same holds true for >
, which is represented as >
. For more information on XML and HTML entities, please refer to http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references.
We have successfully added three complex conditions to our process. To demonstrate the conditions even better, we will introduce a new service called Vintage Bookstore in the next section.
Let's extend our example and add VintageBookstore
. The VintageBookstore
service will be responsible for selling older books. Older books are the books published before 1970. We will define a conditional branch, based on the publishing year of the book. The BPEL would look like this:
<if> <condition> xp20:year-from-dateTime($inputVariable.payload/client:BookData/ client:PublishingYear) < 1970 </condition> <!-- perform activities for books older than 1970 --> <else> <!-- perform activities for books published 1970 or after --> </else> </if>