< Previous | Next >

Adding a snippet to assign the OutputStockPortfolio variable

Take the stock information gathered from the stock quote web service and add it to the stock portfolio.

To add a snippet to assign the OutputStockPortfolio variable to the process:
  1. Create an activity that adds stock values to the stock portfolio:
    1. In the process editor, click Invoke icon on the palette, and then Snippet icon.
    2. Click in the WhileLoop activity below the getQuote activity. The Snippet activity was added.
    3. Rename Snippet to Assign OutputStockPortfolio by typing over the highlighted text.
  2. Assign the share price received from the stock quote web service to a variable:
    1. In the Properties view, click the Details tab.
    2. Add the existing getQuoteOutput variable to the canvas.
    3. Add the existing stockInfo variable to the canvas, click on the label and select stockInfo > pricePerShare.
    4. Connect the getQuoteOutput figure to the stockInfo.pricePerShare figure.
      Get the stock price and assign to a variable
  3. Now that we have both the price per share and the quantity of the stock in question, take the product of those two values and add it to the stock portfolio's value:
    1. Add the stockInfo.pricePerShare variable to the canvas again.
    2. Add stockInfo one more time to the canvas, click on the label and select stockInfo > quantity.
    3. Click Standard icon on the palette, which is the Standard icon. The Add a Standard Visual Snippet window opens.
    4. In the navigation tree, click math > multiply and click OK. Click the canvas to add the activity.
    5. Connect the stockInfo.pricePerShare and stockInfo.quantity figures to the multiply figure. This activity will now multiply the price per share received from the web service with the quantity stated in InputStockPortfolio.
    6. Add the existing OutputStockPortfolio to the canvas, click on the label and select OutputStockPortfolio > value.
    7. Click Standard icon on the palette. The Add a Standard Visual Snippet window opens.
    8. In the navigation tree, click math > add and click OK. Click the canvas to add the activity.
    9. Add the existing OutputStockPortfolio to the canvas and drill into OutputStockPortfolio.value.
    10. Connect the multiply and the first OutputStockPortfolio.value figures to the add figure.
    11. Connect the add figure to the second OutputStockPortfolio.value figure. This will add the total value of the stock to the stock portfolio's value.
      Get the total value of a stock
  4. Create a copy of the stock information:
    1. Add the existing stockInfo variable to the canvas.
    2. Click Standard icon on the palette. The Add a Standard Visual Snippet window opens.
    3. In the navigation tree, click SCA services > copy BO and click OK. Click the canvas to add the activity.
    4. Click Expression icon on the palette. Add the expression to the canvas and type stockInfoCopy as the label.
    5. Right-click the stockInfoCopy figure and from the pop-up menu, select Set Type > Business Object . The Data Type Selection window opens.
    6. In the Filter by type, namespace, or file (? = any character, * = any String) field, type StockInfoBO.
    7. Click StockInfoBO and click OK.
    8. Connect the stockInfo figure to the copyBO figure.
    9. Connect the copy BO figure to the stockInfoCopy figure.
      Copy the stock information
  5. Add the acquired stock information to the stock portfolio:
    1. Add the existing OutputStockPortfolio to the canvas, click on the label and select OutputStockPortfolio > stockInfoList.
    2. Click Java icon on the palette. The Select a Java Visual Snippet window opens.
    3. In the Specify a type (? = any character, * = any String) field, type java.util.List.
    4. Click List.
    5. Click java.util - <WSInstallDir>/runtimes/bi_v6/java/jre/lib/core.jar.
    6. Click add(Object) and click OK. Click the canvas to add the activity.
    7. Connect the OutputStockPortfolio.stockInfoList figure to the add figure.
    8. Connect the stockInfoCopy figure to the add figure. This will add the stock information to the stock list in the portfolio.
      Add the stock information to the portfolio
  6. Increment the counter representing the index of the stock in the stock list:
    1. Add the existing counter variable to the canvas.
    2. Click Expression icon on the palette, which is the Expression icon.
    3. Add the expression to the canvas and type 1 as the value.
    4. Click Standard icon on the palette. The Add a Standard Visual Snippet window opens.
    5. In the navigation tree, click math > add and click OK. Click the canvas to add the activity.
    6. Add the existing counter variable to the canvas.
    7. Connect the first counter figure to the add figure.
    8. Connect the 1 figure to the add figure.
    9. Connect the add figure to the second counter figure. This will increment the value of counter by 1.
      Increment the counter for the next stock
You should now have the following visual snippet:
Completed snippet
With the assignment of the output variable, the activities within the WhileLoop activity are now complete. The combination of the three activities serve to grab stock quotes by invoking the web service, and then calculating the stock portfolio's value based on the new information. All of the assignments and calculations within the process are performed by the visual snippets that you've created.

Feedback
(C) Copyright IBM Corporation 2005, 2007. All Rights Reserved.
< Previous | Next >