Time for action – selecting the bookstore with the lowest quantity

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:

  • Compare the BookstoreA stock quantity to BookstoreB and AnotherBookstore. If the BookstoreA stock quantity is lower or equal in both cases, select BookstoreA.
  • Compare the BookstoreB stock quantity to BookstoreA and AnotherBookstore. If the BookstoreB stock quantity is lower or equal in both cases, select BookstoreB.
  • Compare the 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:

  1. We will need three branches. For the first, we will use <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:
    Time for action – selecting the bookstore with the lowest quantity
  2. Let us now add the conditions. Right-click on the first if, select Edit, and enter the condition as shown in the following screenshot:
    Time for action – selecting the bookstore with the lowest quantity
  3. In a similar way, you should add the other two conditions.

What just happened?

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:

What just happened?

To check whether BookstoreB has the lowest stock quantity, we have defined the following condition:

What just happened?

To check whether AnotherBookstore has the lowest stock quantity, we have defined the following condition:

What just happened?

Note

Please note that in the preceding code, we have used the &lt; entity, which is used in XML to represent the < sign, which cannot be used directly. The same holds true for >, which is represented as &gt;. 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.

VintageBookstore

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) &lt; 1970
  </condition>
  <!-- perform activities for books older than 1970 -->
 
  <else>
    <!-- perform activities for books published 1970 or after -->
  </else>
</if>
..................Content has been hidden....................

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