Create Logic to Assemble Price and Availability Data

In this section, you learn how to:

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

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.
  7. 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.

  8. 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.
  9. The availProcessor Web Service control instance is added to the Data Palette:

    image

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:

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:

image

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.
  3. The Method panel is populated with a list of the asynchronous send methods you can invoke on the priceProcessor control.

  4. Select the following method: void getPrice(int itemID)
  5. Click Send Data to open the second tab in the node builder.
  6. 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.

  7. Select Transformation to switch modes in the Send Data tab.
  8. image

    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.)

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

  11. In Step 2, click Create Transformation.
  12. 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.

  13. 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.
  14. image

    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.

  15. In the Application pane, double-click RequestQuote.jpd to return to your process.
  16. To close the Request Price node builder, click the X in the top right-hand corner of the node builder.
  17. 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.
  3. The Method panel is populated with a list of the asynchronous receive methods on the priceProcessor control.

  4. Select the following method from the list:
  5. void returnPrice(int itemID,float price) 
    
  6. Click Receive Data to open the second tab in the node builder.
  7. The Control Returns field is populated with the data types returned by the returnPrice(int itemID, float price) method on the priceProcessor Web service.

    image

    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.

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

  10. In Step 1, click Select Variable, then Create new variable.... The Create Variable dialog box is displayed.
  11. In the Variable Name field, enter price.
  12. In the Select variable Type pane, ensure that XML is selected.
  13. 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.
  14. image

  15. 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.
  16. 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.
  17. Map the elements in the Source pane to the elements in the Target pane, as shown in the following figure:
  18. itemID to widgetId
    price
    to price

    image

    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.

  19. To return to your business process, double-click RequestQuote.jpd in the Application pane.
  20. To close the Receive Price node builder, click the X in the top right-hand corner of the node builder.
  21. 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. image

  4. 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:
  5. image

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:
  2. XmlObject convertPriceXMLtoXMLObj(org.example.price.PriceRequestDocument _priceRequestDoc) 
    
  3. 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:
  4. image

  5. Double-click the Create PriceList node to open its node builder. The node builder opens on the General Settings tab.
  6. Confirm that the method you dragged onto the node is selected:
  7. XmlObject convertPriceXMLtoXMLObj(org.example.price.PriceRequestDocument _priceRequestDoc) 
    
  8. Click Send Data to open the second tab in the node builder.
  9. 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.

  10. Click the arrow on the field under Select variable to assign to display a list of variables, then select price (PriceRequestDocument).
  11. In this case, note that the data type of your price variable (PriceRequestDocument) matches that of the data expected by the priceAvailTransformations.

  12. Click Receive Data to open the third tab in the node builder.
  13. 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.

  14. Click the arrow on the field under Select variable to assign and select Create new variable .... The Create Variable dialog box opens.
  15. In the Variable Name field, enter priceList.
  16. 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).
  17. Select XmlObjectList and click OK.
  18. The priceList variable is created and assigned to receive the XmlObject data returned by the priceProcessor service.

    image

  19. To close the Create PriceList node builder, click the X in the top right-hand corner.
  20. 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.

  21. 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.
  3. The Method panel is populated with a list of the asynchronous send methods you can invoke on the availProcessor control.

  4. Select the following method from the list:
  5. void getAvail(int itemID, int quantity) 
    
  6. Click Send Data to open the second tab in the node builder.
  7. 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).

  8. Select Transformation to switch modes in the Send Data tab.
  9. image

    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).

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

  12. In Step 2, click Create Transformation.
  13. 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.

  14. Map the elements in the Source pane to the elements in the Target pane, as shown in the following figure:
  15. widgetID to itemID
    quantity
    to quantity

    image

    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.

  16. Double-click RequestQuote.jpd in the Application pane to return to your process.
  17. To close the Request Price node builder, click the X in the top right-hand corner of the node builder.
  18. 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.
  3. The Method panel is populated with a list of the asynchronous receive methods on the availProcessor control.

  4. Select the following method from the list:
  5. void avail(int itemID, int qty, boolean avail, String date) 
    
  6. Click Receive Data to open the second tab in the node builder.
  7. 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.

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

  10. Click Select Variable, then Create new variable.... The Create Variable dialog box is displayed.
  11. In the Variable Name field, enter avail.
  12. In the Select variable Type pane, ensure that XML is selected.
  13. 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.
  14. image

  15. 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.
  16. 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.
  17. Map the Source values to the Target elements as shown in the following:
  18. itemID to widgetId
    qty
    to requestedQuantity
    avail
    to quantityAvail
    date
    to shipDate)

    image

    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.

  19. Double-click RequestQuote.jpd in the Application pane to return to your business process.
  20. To close the Receive Availability node builder, click the X in the top right-hand corner of the node builder.
  21. 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:
  2. XmlObject convertAvailXMLtoXMLObj(org.example.avail.AvailRequestDocument _availRequestDoc) 
    
  3. 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:
  4. image

  5. Double-click the Create AvailList node. The node builder opens on the General Settings tab.
  6. 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:
  7. XmlObject convertAvailXMLtoXMLObj(org.example.AvailRequestDocument _availRequestDoc) 
    
  8. Click Send Data to open the second tab in the node builder.
  9. 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.

  10. Click the arrow on the field under Select variable to assign to display a list of variables. Select avail (AvailRequest).
  11. In this case, note that the data type of your avail variable (AvailRequest) matches that of the data expected by the priceAvailTransformations control.

  12. Click Receive Data to open the third tab in the node builder.
  13. 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.

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

  17. In the Select Variable Type pane, if necessary, select XML to display a representation of the XML data types in your application.
  18. Select XmlObjectList, then click OK.
  19. The availList variable is created and assigned to receive the XmlObject data returned by the availProcessor service.

    image

  20. To close the Create AvailList node builder, click the X in the top right-hand corner of the node builder.
  21. 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.

  22. 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

Previous Document Next Document