# Create Logic to Assemble Price and Availability Data

In this section, you learn how to:

- Invoke the price and availability services (via controls) from the parallel branches you created.
- Design callbacks on your branches to wait for and handle the responses from the controls.
- Construct an XML document, to which the response data from controls is appended for each iteration through the For Each loop. (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:

- To Create Instances of the PriceProcessor and AvailProcessor Controls in Your Project
- To Add Control Nodes to Your Business Process
- To Design the Activities on the Get Price Branch
- To Design the Activities on the Get Availability Branch

To Create Instances of the PriceProcessor and AvailProcessor Controls in Your Project

The Web service controls (PriceProcessorControl.jcx and AvailProcessorControl.jcx) are provided for you in your application's project (specifically in myapplications\Tutorial_Process_Application\Tutorial_Process_ApplicationWeb\requestquote\services folder, where myapplications represents the location at which you created your tutorial application). The goal of this section is to describe how to create the appropriate controls in your application, and then design the communication between your business process and these controls.

1. Click Add on the Data Palette Controls tab to display a list of controls that represent the resources with which your business process can interact.
2. Choose Web Service. The Insert Control dialog box is displayed.
3. In Step 1, enter priceProcessor as the variable name for this control.
4. In Step 2, ensure that the following option is selected: Use a Web Service control already defined by a JCX file.
5. Click Browse beside the JCX file field, browse to the \Tutorial_Process_ApplicationWeb\requestquote\services folder, choose PriceProcessorControl.jcx, then click Select. The file browser closes.
6. Click Create.

The Insert Control dialog box closes and an instance of the Web Service control is created in your project and displayed in the Data Palette.

7. Repeat steps 1 through 6, but enter availProcessor as the variable name for the control, and choose the AvailProcessorControl.jcx control, which is already defined in the following folder, as the control file on which to base your instance: \Tutorial_Process_ApplicationWeb\requestquote\services folder.

The availProcessor Web Service control instance is added to the Data Palette:

To Add Control Nodes to Your Business Process

You learned in Parts I and II that you can create Control nodes in your business process by dragging the methods from the appropriate control on the Data Palette onto the business process in the Design View. You can also create Control nodes by selecting Control Send, Control Receive, or Control Send with Return from the Palette and dragging them onto the business process. You subsequently bind the appropriate methods to the control node you created. In this section you will use the latter approach.

Add the following nodes from the Palette to each branch on your Parallel node:

- Control Send
- Control Receive
- Control Send with Return

In Design View, select each of the listed nodes, then drag and drop the node onto the business process, placing the nodes on the Parallel branches until you create a Parallel group as shown in the following figure:

In this way, each branch is designed for the following flow of execution:

1. Call a resource (via a control) from the Control Send node.
2. Wait for a response from the control at the Control Receive node.
3. Make a synchronous call to a control at the Control Send with Return node. At this node you call a Transformation that constructs an XML document. The response data from controls is appended to this XML document for each iteration through the For Each loop.

To Design the Activities on the Get Price Branch

1. Rename the nodes on the Get Price Branch (in the order in which they are executed) as follows: Request Price, Receive Price, Create PriceList.
2. Complete the following tasks:
3. To Design the Request Price Node
4. To Design the Receive Price Node
5. To Design the Create PriceList Node

To Design the Request Price Node

1. Double-click the Request Price node to open its node builder. The node builder opens on the General Settings tab.
2. Click the arrow beside the Control field to display a drop down list of the instances of the controls in your project and select priceProcessor.

The Method panel is populated with a list of the asynchronous send methods you can invoke on the priceProcessor control.

3. Select the following method: void getPrice(int itemID)
4. Click Send Data to open the second tab in the node builder.

By default, the Send Data tab opens on the Variable Assignment pane. (The Control Expects field is populated with the data type expected by the getPrice() method exposed by the priceProcessor Web service: int itemID.)

Note: The priceProcessor service takes the ID of the item requested as input, and returns the price of the widget.

5. Select Transformation to switch modes in the Send Data tab.

Note: In this case, you must switch modes because the data type required as input to the priceProcessor control is int, and the iter_forEach1 variable, which holds the value of widgetId in the For Each loop, is of type XML (WidgetRequestDocument valid against an XML Schema).
The iteration variable was created for you when you specified the repeating element over which the For Each loop iterates. At run time, it holds the current widgetRequest element—that is, the one currently being processed in the For Each loop. (See Design a For Each Loop in Your Business Process.)

6. In Step 1, click Select Variable to display the variables in your project, then choose iter_forEach1 (widgetRequest).

7. In Step 2, click Create Transformation.

The Transformation tool opens and displays a representation of the iter_forEach1 (widgetRequest) variable in the Source pane, and an int in the Target pane.

8. Click widgetID in the Source pane and drag your mouse over to int in the Target pane. A line is drawn between the widgetID and int elements in the map pane. It represents the transformation between the two data types.

As you draw the line in the map pane, WebLogic Workshop will display the following warning:

    The datatype of the source node: [widgetId] and target node: [int] do not match, a type conversion will be applied.

Note: Creating this transformation creates a new method under the RequestQuoteTransformation.dtf already created in your project and prebuilt for you in the tutorial application. It is available in the Tutorial_Process_ApplicationWeb\requestquote folder. A new XQ file, which contains the query for this transformation method, is also created. See Note About Transformations.

9. In the Application pane, double-click RequestQuote.jpd to return to your process.
10. To close the Request Price node builder, click the X in the top right-hand corner of the node builder.

This step completes the design of the Request Price node.

To Design the Receive Price Node

1. Double-click the Receive Price node to open its node builder. The node builder opens on the General Settings tab.
2. Click the arrow beside the Control field to display a list of the instances of controls in your project and select priceProcessor.

The Method panel is populated with a list of the asynchronous receive methods on the priceProcessor control.

3. Select the following method from the list:

    void returnPrice(int itemID,float price)

4. Click Receive Data to open the second tab in the node builder.

The Control Returns field is populated with the data types returned by the returnPrice(int itemID, float price) method on the priceProcessor Web service.

The PriceProcessor service takes the itemID (an int) as input and returns an int and a float—containing values for the itemID and the price, respectively.

In this case, you must switch from the Variable Assignment mode displayed in the preceding figure to the Transformation mode because you want to assign the data returned by the priceProcessor service to a variable of type XML. To do so, your business process must transform the Java data types returned from the priceProcessor service to typed XML.

5. Click Transformation. The Receive Data tab is displayed as shown in the following figure:

6. In Step 1, click Select Variable, then Create new variable.... The Create Variable dialog box is displayed.
7. In the Variable Name field, enter price.
8. In the Select variable Type pane, ensure that XML is selected.
9. Click the + beside priceQuote.xsd in XML Types to expand the list, then select priceRequest from the list. The Variable Type field is populated with org.example.price.PriceRequestDocument.

10. Click OK. The Create Variable dialog box closes and the new variable is displayed in the Receive Data tab. It is also listed as an XML Type variable in the Data Palette.
11. In Step 2 on the Receive Data tab, click Create Transformation. The Transformation tool opens and displays a representation of the int (itemID) and float (price) in the Source pane, and the price variable in the Target pane.
12. Map the elements in the Source pane to the elements in the Target pane, as shown in the following figure:

itemID to widgetId
price to price

Note: Creating this transformation creates a new method under the RequestQuoteTransformation.dtf already created in your project and prebuilt in the tutorial application. It is available in the Tutorial_Process_Application\Webrequestquote folder. A new XQ file, which contains the query for this transformation method, is also created.

13. To return to your business process, double-click RequestQuote.jpd in the Application pane.
14. To close the Receive Price node builder, click the X in the top right-hand corner of the node builder.

This step completes the design of the Receive Price node.

To Design the Create PriceList Node

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, as input from your business process, typed XML data and returns untyped XML (XmlObject). 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. (See Note About Using the XmlObjectList Data Type.)

Note: This transformation is prebuilt for you in the tutorial application. It is available in the Tutorial_Process_Application\Webrequestquote folder.
A description of how to create the PriceAvailTransform.dtf file is beyond the scope of this tutorial. To learn more about Transformations, see Note About Transformations.

To Create an Instance of the PriceAvailTransformations Control in Your Project

1. If the Data Palette pane is not visible in WebLogic Workshop, choose View —> Windows —> Data Palette from the menu bar.
2. On the Applications pane, click the priceAvailTransformations.dtf file.

3. Drag the PriceAvailTransformations.dtf file from the Applications pane onto the Controls pane of the Data Palette. The instance of your control (priceAvailTransformations) is created and displayed in the Data Palette as shown in the following figure:

To Design the Interaction of the Create PriceList Node With the Transformation

1. In the Data Palette, expand the priceAvailTransformations instance, as shown in the preceding figure, then click the following method:

    XmlObject convertPriceXMLtoXMLObj(org.example.price.PriceRequestDocument _priceRequestDoc)

2. Drag the method from the Data Palette and drop it on the Create PriceList node in the Design View. The Create Price List node changes to reflect the binding of the method, as shown in the following figure:

3. Double-click the Create PriceList node to open its node builder. The node builder opens on the General Settings tab.
4. Confirm that the method you dragged onto the node is selected:

    XmlObject convertPriceXMLtoXMLObj(org.example.price.PriceRequestDocument _priceRequestDoc)

5. Click Send Data to open the second tab in the node builder.

The Control Expects field is populated with the data type and name of the parameter expected by the convertPriceXMLtoXMLObj() method on the priceAvailTransformations control: PriceRequestDocument _priceRequestDoc.

6. Click the arrow on the field under Select variable to assign to display a list of variables, then select price (PriceRequestDocument).

In this case, note that the data type of your price variable (PriceRequestDocument) matches that of the data expected by the priceAvailTransformations.

7. Click Receive Data to open the third tab in the node builder.

The Control Returns field is populated with the data type of the parameter returned by the convertPriceXMLtoXMLObj() method on the priceAvailTransformations control: XmlObject.

An XmlObject is a Java data type that specifies data in untyped XML format. In other words, this data type represents XML data that is not valid against an XML Schema.

8. Click the arrow on the field under Select variable to assign and select Create new variable .... The Create Variable dialog box opens.
9. In the Variable Name field, enter priceList.
10. If necessary, in the Select Variable Type pane, select XML to display a representation of the XML data types in your application. (XmlObject is selected by default. You must change this selection in the following step).
11. Select XmlObjectList and click OK.

The priceList variable is created and assigned to receive the XmlObject data returned by the priceProcessor service.

12. To close the Create PriceList node builder, click the X in the top right-hand corner.

This step completes the design of the Get Price branch on the Parallel node. 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.

13. From the Workshop menu, select File —> Save All.

To Design the Activities on the Get Availability Branch

1. Rename the nodes on the Get Availability Branch (in the order in which they are executed) as follows: Request Availability, Receive Availability, Create AvailList.
2. Complete the following tasks:
3. To Design the Request Availability Node
4. To Design the Receive Availability Node
5. To Design the Create AvailList Node

To Design the Request Availability Node

1. Double-click the Request Availability node. The node builder opens on the General Settings tab.
2. Click the arrow beside the Control field to display a list of the instances of controls available in your project and select availProcessor.

The Method panel is populated with a list of the asynchronous send methods you can invoke on the availProcessor control.

3. Select the following method from the list:

    void getAvail(int itemID, int quantity)

4. Click Send Data to open the second tab in the node builder.

By default, the Send Data tab opens on the Variable Assignment pane. The Control Expects field is populated with 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 service takes, as input, the itemID (int) and the quantity (int) requested by the client. It returns the itemID (int), the quantity available (int), a boolean to indicate whether the widgets are in stock, and a ship date (String).

5. Select Transformation to switch modes in the Send Data tab.

Note: In this case, you must switch modes because you must transform the data you input to availProcessor. The availProcessor control requires its input as int data types, and the iter_forEach1 variable, which holds the value of widgetId and quantity in the For Each loop, is of type XML (WidgetRequestDocument valid against an XML Schema).

6. In Step 1, click Select Variable to display the variables in your project, then choose iter_forEach1 (WidgetRequest).

7. In Step 2, click Create Transformation.

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.

8. Map the elements in the Source pane to the elements in the Target pane, as shown in the following figure:

widgetID to itemID
quantity to quantity

A line is drawn between the elements in the map pane. It represents the transformation between the data types.

Note: Creating this transformation creates a new method under the RequestQuoteTransformation.dtf already created in your project and prebuilt in the tutorial application. It is available in the Tutorial_Process_ApplicationWeb/requestquote folder. A new XQ file, which contains the query for this transformation method, is also created.

9. Double-click RequestQuote.jpd in the Application pane to return to your process.
10. To close the Request Price node builder, click the X in the top right-hand corner of the node builder.

This step completes the design of the Request Availability node.

To Design the Receive Availability Node

1. Double-click the Receive Availability node. The node builder opens on the General Settings tab.
2. Click the arrow beside the Control field to display a list of the instances of controls available in your project and select availProcessor.

The Method panel is populated with a list of the asynchronous receive methods on the availProcessor control.

3. Select the following method from the list:

    void avail(int itemID, int qty, boolean avail, String date)

4. Click Receive Data to open the second tab in the node builder.

The Control Returns fields are populated with the data types and names of the parameters returned by the avail(int itemID, int qty, boolean avail, String date) 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 you want to assign the data returned by the availProcessor service to a variable of type XML. To do so, your process must transform the Java data types returned to typed-XML.

5. Click Transformation. The Receive Data tab is displayed as shown in the following figure:

6. Click Select Variable, then Create new variable.... The Create Variable dialog box is displayed.
7. In the Variable Name field, enter avail.
8. In the Select variable Type pane, ensure that XML is selected.
9. In XML Types, click the + beside availQuote.xsd to expand the list, then select availRequest from the list. The Variable Type field is populated with org.example.avail.AvailRequestDocument.

10. Click OK. The Create Variable dialog box is closed and your new variable is created and is listed as an XML Type variable in the Data Palette.
11. In Step 2, click Create Transformation to open the Transformation tool, which displays a representation of the data types returned by the availProcessor control in the Source pane, and the avail variable in the Target pane.
12. Map the Source values to the Target elements as shown in the following:

itemID to widgetId
qty to requestedQuantity
avail to quantityAvail
date to shipDate)

Note: Creating this transformation creates a new method under the RequestQuoteTransformation.dtf already created in your project and prebuilt in the tutorial application. It is available in the requestquote\Tutorial_Process_ApplicationWeb folder. A new XQ file, which contains the query for this transformation method, is also created.

13. Double-click RequestQuote.jpd in the Application pane to return to your business process.
14. To close the Receive Availability node builder, click the X in the top right-hand corner of the node builder.

This step completes the design of the Receive Availability node.

To Design the Create AvailList Node

In the same way as you designed the business process to append the price data to a single variable when you designed the Get Price branch of the Parallel node, in this step, you call a method on the priceAvailTransformations control to append the availability data returned to a single variable, of type XmlObjectList. (See Note About Using the XmlObjectList Data Type.)

1. If necessary, expand the priceAvailTransformations control instance in the Data Palette, then click the following method:

    XmlObject convertAvailXMLtoXMLObj(org.example.avail.AvailRequestDocument _availRequestDoc)

2. Drag the method from the Data Palette and drop it on the Create AvailList node in the Design View. The Create AvailList node changes to reflect the binding of the method, as shown in the following figure:

3. Double-click the Create AvailList node. The node builder opens on the General Settings tab.
4. Confirm that the priceAvailTransformations control is selected in the Control field, and that the method you dragged onto the node is selected in the Method field:

    XmlObject convertAvailXMLtoXMLObj(org.example.AvailRequestDocument _availRequestDoc)

5. Click Send Data to open the second tab in the node builder.

The Control Expects field is populated with AvailRequestDocument, which is the data type expected by the convertAvailXMLtoXMLObj(org.example.avail.AvailRequestDocument _availRequestDoc) method on the priceAvailTransformations control.

6. Click the arrow on the field under Select variable to assign to display a list of variables. Select avail (AvailRequest).

In this case, note that the data type of your avail variable (AvailRequest) matches that of the data expected by the priceAvailTransformations control.

7. Click Receive Data to open the third tab in the node builder.

The Control Returns field is populated with XmlObject, which is the data type returned by the convertAvailXMLtoXMLObj() method on the priceAvailTransformations control.

An XmlObject is a Java data type that specifies data in untyped XML format. In other words, this data type represents XML data that is not valid against an XML Schema.

8. Click the arrow on the field under Select variable to assign and select Create new variable .... The Create Variable dialog box is displayed.
9. In the Variable Name field, enter availList.

10. In the Select Variable Type pane, if necessary, select XML to display a representation of the XML data types in your application.
11. Select XmlObjectList, then click OK.

The availList variable is created and assigned to receive the XmlObject data returned by the availProcessor service.

12. To close the Create AvailList node builder, click the X in the top right-hand corner of the node builder.

This step completes the design of the Get Availability branch on the Parallel node. At run time, by executing this branch, your business process appends the XmlObject, which contains the data returned by the availProcessor control (during the current iteration through the For Each loop), to the availList variable.

13. From the Workshop menu, select File —> Save All.

Note About Using the XmlObjectList Data Type

On each iteration through the For Each loop, the priceProcessor service returns price data, which is assigned to the price variable; and the availProcessor service returns availability data, which is assigned to the avail variable. 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.

An XmlObjectList is a Java data type that specifies a sequence of untyped XML format data. In other words, 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 your Parallel node, your business process assigns the data from the price variable to the priceList variable (of type XmlObjectList). In this way, a single variable holds the price data for each of the widgets in the Request for Quote over which the For Each loop iterates. In the same way, a single variable holds the availability data for each widget.

To learn how the XmlObjectList variable is used, see To Design the Create PriceList Node and To Design the Create AvailList Node.

Related Topics

Note About Transformations

Creating Maps

Testing Maps in the Test View

Guide to Data Transformation

Understanding Parallel Execution in Your Business Process