In the previous step, you created a For Each loop to iterate through a set of repeating elements in an RFQ document. In this step, you design the activities to be performed within each iteration of the For Each loop.
When your business process interacts with multiple systems, as is the case for price and availability processing in this scenario, you can use Parallel nodes to create two or more parallel branches of execution.
Note: | Parallel branches of execution in a business process are logically parallel; physically, the branches are executed serially. Business processes benefit from this logical parallelism when communication with external systems involves waiting for responses from those external systems. While one branch of execution is waiting for a response, another branch of execution in the parallel flow can progress. |
Note: | For more information, see Creating Parallel Paths of Execution in Guide to Building Business Processes. |
In our example scenario, the business process must determine both price and availability information so that a quote can be prepared and returned to the client. This business process can benefit from parallelism because it communicates with two external systems: one each for price calculation and availability calculation. The business process expects a response from each of the external systems.
The external systems can be any resource – other business processes, web services, EJBs, databases, file systems, and so on – that returns the information your business process requires. Business processes interact with the resources through controls.
This tutorial uses two web services: one returns the price for each widgetID
specified in the client’s RFQ document; a second service returns availability information based on the widgetID
and the quantity
specified in the request document.
The controls with which the business process interacts are provided in the \Tutorial_Process_ApplicationWeb\requestquote.services
folder. The controls are PriceProcessor.java
and AvailProcessor.java
.
RequestQuote.java
) is displayed in the Design View.The Design view is updated as shown in the following figure:
By default, Parallel nodes specify an AND join condition, represented by the icon at the intersection of the parallel branch lines, indicating that the activities on all the branches must be completed for execution to proceed to the next node after the parallel node.
For this business process, since both price calculation and availability checking must be completed before proceeding to the next node, leave the AND join condition as is.
Note: | If an OR join condition is specified, when the activities on one branch are completed, execution of activities on all the other branches terminates, and the flow of execution proceeds to the node following the parallel node. The OR join condition is represented by the icon in the Design view. |
Note: | In the Design view, you can view and edit the join condition property in the JPD Configuration view. |
In this section, you learn how to do the following:
Note: | Review your business process in Design View: your Parallel node is within the For Each loop, meaning that the flow of execution is through the Parallel node for each iteration through the loop. |
To design the Parallel node to interact with the price and availability web services, complete the following tasks:
The PriceProcessor.java
and AvailProcessor.java
controls are available in the Tutorial_Process_Application_Web\src\requestquote.services
folder in the Package Explorer view.
The goal of this section is to create the appropriate controls in your application and then design the communication between the business process and the controls.
A list of controls, which represent the resources with which your business process can interact, is displayed.
The Insert Control dialog box is displayed.
priceProcessor
in the Field Name field and click Finish. availProcessor
.
The priceProcessor
and availProcessor
web service control instances are added to the Data Palette:
You learned earlier in the tutorial that you can create control nodes in your business process by dragging the methods for the appropriate control from the Data Palette to the business process in the Design view.
You can also create control nodes by dragging Control Send, Control Receive, or Control Send with Return from the Node Palette to the business process. You subsequently bind the appropriate methods to the control node you created. This is the approach that you use in this section.
Add the following nodes from the Node Palette to each branch of the parallel node:
Drag each of the listed nodes from the Node Palette to the Design view, and drop the node on parallel branches.
The resulting business process is as shown in the following figure.
In this way, each branch is designed for the following flow of execution:
The node builder opens on the General Settings tab.
The Method panel shows a list of the asynchronous send methods that you can invoke on the priceProcessor.
void getPrice(int itemID_arg)
method.
By default, the Send Data tab opens on the Variable Assignment pane. The Control Expects field contains the data type (int itemID
) that is expected by the getPrice()
method exposed by the priceProcessor web service.
Note: | The priceProcessor web service takes the ID of the item requested as the input and returns the price of the item. |
Note: | This step is necessary because the data type required as input for priceProcessor is int , whereas the iter_forEach1 variable, which holds the value of widgetId in the For Each loop, is of type XML (WidgetRequestDocument is valid against an XML schema). |
The transformation tool opens and displays a representation of the iter_forEach1 (widgetRequest)
variable in the Source pane, and int
in the Target pane.
A connecting line is drawn between the widgetID and int elements. The line represents the transformation between the two data types.
As you draw the mapping line, the following warning is displayed:
The datatype of the source node: [widgetId] and target node: [int] do not match, a type conversion will be applied.
Note: | This transformation creates a new method under RequestQuoteTransformation.java , which was created in your project and prebuilt in the tutorial application. It is available in the Tutorial_Process_Application_Web\requestquote folder. A new XQ file called RequestQuotepriceProcessorGetPrice.xq , which contains the query for this transformation method, is also created. |
Select void returnPrice(int itemID_arg, float price_arg)
.
The Control Returns field shows the data types returned by the returnPrice(int itemID, float price)
method on the priceProcessor
web service.
The priceProcessor
web service takes itemID
(an int
value) as input and returns an int
value for the item ID and a float
value for the price.
Next, you must switch from the Variable Assignment mode to the Transformation mode because the data returned by the priceProcessor
web service must be assigned to a typed XML variable. To do this, your process must transform the Java data types returned from the priceProcessor
web service to typed XML.
The Receive Data tab is displayed as shown in the following figure.
The Create Variable dialog box is displayed.
The Type Name field shows org.example.price.PriceRequestDocument
.
itemID
and price
variables in the Source pane, and the price
variable in the Target pane.Note: | This transformation creates a new method under RequestQuoteTransformation.java in the Tutorial_Process_Application_Web\requestquote folder. A new XQ file, which contains the query for this transformation method, is also created. |
In this step, you use a transformation control (PriceAvailTransformations) provided in your project to append the price data returned from the priceProcessor control (on each iteration through the For Each loop) to a single variable.
Previously, when you designed nodes in the business process, you created transformation methods on a transformation, as necessary, to map the data your business process sent to or received from clients and controls. In this case, you also use a transformation, but in a different way. In the case of the Create PriceList node, the data is not sent to a client or control. Instead, the transformation takes typed XML data as input from your business process, and returns untyped XML (XmlObject
) data. The business process must append the data returned on every iteration of the For Each loop to a single variable, thus creating a repeating sequence of XML data. A variable that can hold this type of repeating sequence of XML data in a For Each loops is of type XmlObjectList
. Both typed and XmlObject
variables can be appended to variables of type XmlObjectList
.
For more information, see XmlObjectList Data Type.
Note: | This transformation is prebuilt for you in the tutorial application. It is available in the Tutorial_Process_Application_Web\requestquote folder. A description of how to create the PriceAvailTransform.java file is beyond the scope of this tutorial. |
priceAvailTransformations
) is created and displayed in the Data Palette.XmlObject convertPriceXMLtoXMLObj
(org.example.price.PriceRequestDocument _priceRequestDoc)
The node builder opens on the General Settings tab.
The Control Expects field contains the data type and name of the parameter expected by the convertPriceXMLtoXMLObj()
method on the priceAvailTransformations
control: PriceRequestDocument _priceRequestDoc
.
In this case, note that the data type of the price
variable (PriceRequestDocument
) matches that of the data expected by priceAvailTransformations
.
The Control Returns field contains the data type of the parameter returned by the convertPriceXMLtoXMLObj()
method on the priceAvailTransformations control: XmlObject
.
Note: | An XmlObject is a Java data type that specifies data in untyped XML format (data that is not valid against any XML schema). |
The Create Variable dialog box is displayed.
XmlObject is selected by default. You must change this selection in the following step.
The priceList
variable is created and assigned to receive the XmlObject
data returned by the priceProcessor
service.
This step completes the design of the Get Price branch on the Parallel node in your business process.
At run time, by executing this branch, your business process appends the XmlObject
, which contains the data returned by the priceProcessor
control during the current iteration through the For Each loop, to the priceList
variable.
availProcessor
control.
Select void getAvail(int itemID_arg, int quantity_arg)
.
By default, the Send Data tab opens on the Variable Assignment pane. The Control Expects field shows the data types and names of the parameters expected by the getAvail()
method exposed by the availProcessor
web service: int itemID
and int quantity
.
Note: | The availProcessor web service takes the item ID (int) and quantity (int) as input. It returns the item ID (int), quantity available (int), a boolean to indicate whether the items are available in stock, and a ship date (String). |
Note: | In this case, you must switch modes because the data that you provide as input to availProcessor must be transformed. The availProcessor control requires int data types as input, whereas the iter_forEach1 variable, which holds the value of widgetId and quantity in the For Each loop, is a typed XML variable (WidgetRequestDocument is valid against an XML schema). |
The transformation tool opens and displays a representation of the iter_forEach1
variable in the Source pane, and the integer arguments to the availProcessor
transformation method in the Target pane.
widgetID
to itemID_arg
quantity
to quantity_arg
Note: | This transformation creates a new method under the RequestQuoteTransformation.java . It is available in the Tutorial_Process_Application_Web/requestquote folder. A new XQ file, which contains the query for this transformation method, is also created. |
This step completes the design of the Request Availability node.
void avail(int itemID_arg, int qty_arg, boolean avail_arg, String date_arg)
The Control Returns fields are populated with the data types and names of the parameters returned by the avail()
method on the availProcessor
web service.
Note: | In this case, you must switch from the Variable Assignment mode to the Transformation mode on the Receive Data tab because the data returned by the availProcessor web service must be assigned to a typed XML variable. For this, your process must transform the Java data types returned to typed XML data. |
The Create Variable dialog box is displayed.
The Type Name field shows org.example.avail.AvailRequestDocument
.
The Create Variable dialog box is closed and your new variable is created and listed as an XML type variable in the Data Palette.
availProcessor
in the Source pane, and the avail
variable in the Target pane.itemID_arg
to widgetId
qty_arg
to requestedQuantity
avail_arg
to quantityAvail
date_arg
to shipDate
Note: | This transformation creates a new method under the RequestQuoteTransformation.java in the requestquote\Tutorial_Process_Application_Web folder. A new XQ file, which contains the query for this transformation method, is also created. |
This step completes the design of the Receive Availability node.
In this step, you call a method on the priceAvailTransformations
control to append availability data to a single variable of type XmlObjectList
.
Note: | For more information about the XmlObjectList data type, see XmlObjectList Data Type. |
priceAvailTransformations
control instance in the Data Palette and select the XmlObject convertAvailXMLtoXMLObj()
method.priceAvailTransformations
control is selected in the Control field, and that the method you dragged onto the node is selected in the Method field:
The Control Expects field contains AvailRequestDocument
, which is the data type expected by the convertAvailXMLtoXMLObj()
method on the priceAvailTransformations
control.
In this case, note that the data type of the avail
variable (AvailRequest
) matches that of the data expected by the priceAvailTransformations
control.
The Control Returns has XmlObject
, which is the data type returned by the convertAvailXMLtoXMLObj
() method on the priceAvailTransformations control.
Note: | XmlObject is a Java data type that specifies data in untyped XML format (data that is not valid against any XML schema) |
The Create Variable dialog box is displayed.
The availList
variable is created and assigned to receive the XmlObject
data returned by the availProcessor
web service.
At run time, the process appends XmlObject
, which contains the data returned by the availProcessor
control during the current iteration through the For Each loop, to the availList
variable.
On each iteration through the For Each loop,
Your business process must collect the price data returned on each iteration and create a list of price data; one item is assigned to the list for each iteration through the loop. Similarly, a list of availability data is created on the Get Availability branch of the Parallel node for each iteration through the loop.
XmlObjectList
is a Java data type that specifies a sequence of untyped XML format data. This data type represents a sequence of XML elements (a set of repeating elements). As the final step of each iteration through the Get Price branch in the Parallel node, the business process assigns the data from the price
variable to the priceList
variable (type: XmlObjectList
). In this way, a single variable holds the price data for each item for which the For Each loop iterates. Similarly, a single variable holds the availability data for each item.
For information about how the XmlObjectList
variable is used, see Design “Create PriceList” Node and Design “Create AvailList” Node.