Tutorial for the Web UI: Isolating or extracting the Update Motor Policy functionality as a service

Perform the tutorial based on the sample project GenApp to explore how to isolate or extract a functionality as a service.

Tutorial scenario

Application refactoring is essential in the journey to application modernization. To tap into the full potential of an existing application and ensure that it evolves over time for growing business needs, usually developers have to refactor an existing application into modular services. IBM® watsonx Code Assistant™ for Z Refactoring Assistant comes to developers' aid in such scenarios and help them identify parts of an application to refactor into services. In this tutorial, you will learn how to isolate or extract the functionality of a sample application as a service.

Assumption

The following tutorial assumes that you need to create a service for the functionality of Updating Motor Policy to meet your business needs. Therefore, to begin with, you want to use Z Refactoring Assistant to extract the relevant portions of the code that perform the functionality. Check the following instructions to learn how to use Z Refactoring Assistant to get the relevant parts of the GenApp application involved in the functionality of Updating Motor Policy.

Prerequisites

Procedures

Complete the following steps to perform the tutorial:
  1. Launch your browser and go to https://<hostname>:9443. By default, you will be on the Workspaces tab.
  2. Click the Create workspace button on the upper right corner of the Workspaces page.
  3. In the Create workspace dialog, type a name for the workspace that you want to create, for example, GenApp.
  4. From the AD project drop-down list, select the project that you built with IBM AD Build Client.
  5. Click Create to create the workspace. When the creation is completed, the Graph view of the GenApp workspace is displayed.
  6. Type MOTOR in the search box. You will see MOTOR - Db2® table in the results.
    The image shows the search results when you type MOTOR.
  7. Click the result item MOTOR - Db2 table and then press Enter. This operation computes a table closure by taking the Motor Policy as the seed that is of type Table. A table closure provides the programs that perform some kind of operations on the table that is provided as a seed, and then it shows the call chain of those programs all the way till transactions. Closures help you narrow the focus to the artifacts of relevance as a starting point.
    The image shows the table closure that takes the Motor Policy as the seed.

    Three programs are involved in the Motor Db2 table: LGUPDB01, LGIPDB01, and LGAPDB01. With the graph, you can further check the relevant chains from programs to specific transactions.

    So far, with Z Refactoring Assistant, you have narrowed down the large number of artifacts for GenApp to the preceding three programs that perform the functionality about Motor Policy. However, based on the naming convention, you decide to explore further with the program LGUPDB01 first since it seems more relevant to the functionality of Updating Motor Policy.

  8. Click the Action Menu (The image shows the Action Menu icon.) icon on the upper right corner of the LGUPDB01 program node. You will see the following options available:
    • View properties option to view more details of the artifact
    • Identify conditional statements option to see the conditional statements of the program as the drivers of business functionality
    • Identify paragraphs option to identify the paragraphs of the program that can be service candidates
    • Identify table/file access statements option to identify the table or file access statements of the program
    The following steps of the tutorial will illustrate the Identify conditional statements option in more details.
  9. Select Identify conditional statements.
    The image shows the Identify conditional statements option.
    A new workbook page is displayed, which takes you to the source file of LGUPDB01 and presents the conditional statements in this particular program.
    The image shows the Workbook details page.

    In the Key conditions pane, you will see a list of all the key conditions that are identified in the program. The key conditions are listed in descending order of importance score, instead of the sequential order of the statements. The importance score indicates how relevant and useful the highlighted statement could be for the program that you selected. Therefore, you can analyze the top few statements as a starting point to investigate the key conditional statements.

  10. From the Key conditions pane, click the conditional statement that you want to investigate further, which scrolls the source code view to the location of the selected conditional statement. To filter the key conditions, select a key condition type such as Conditional statements or Paragraphs to narrow down the key conditions to a specific type. If you will, you can also scroll down the page and check the highlighted conditions that have been identified.

    In this example, you can click any of the top two conditional statements to take you to the main logic in LGUPDB01 program.

    Based on the code comments and your knowledge, you will find that the following piece of code seems to have the code for Updating Motor Policy.
    The image shows a piece of source code.

    After further investigation on the code, you determine that the WHEN '01UMOT' statement is the code portion that you want to extract.

  11. Right-click the WHEN '01UMOT' and then select Slice on conditional statement to new workbook. A Slice to new workbook dialog is displayed.
    The image shows the Slice on conditional statement to new workbook option.
  12. Type a name for the workbook you create, for example, type test 1.
  13. Optional: Specify a tag for the workbook and press Enter. Since you are slicing on conditional statements to the workbook, a conditional tag is added by default.
  14. Click Save to create the workbook.
    The image shows the Workbook details page with the list of code blocks.
    A new workbook pane is displayed on the left, which shows the service code blocks for the test 1 workbook that you created. You will find the WHEN '01UMOT' code block that you just sliced and all the subsequent code blocks that are involved.

    Now you have extracted the code portions from the LGUPDB01 program that are related to the functionality of Updating Motor Policy. Next, you will explore further with the program that invokes LGUPDB01.

  15. Click the Graph tab on the upper right corner to navigate to the closure view.
  16. Click the LGUPDB01 program node and then you will see that the LGUPOL01 program invokes LGUPDB01.
    The image shows the LGUPDB01 program node.
  17. Click the Action Menu (The image shows the Action Menu icon.) icon on the upper right corner of the LGUPOL01 program node.
  18. Select Identify conditional statements to inspect the conditional statements for LGUPOL01.
    The image shows the Identify conditional statements option.

    Based on your investigation with LGUPDB01 and knowledge, you determine that WHEN '01UMOT' is the relevant statement. Therefore, you can slice it and add it into the workbook you created in the previous steps.

  19. Right-click WHEN '01UMOT' and then select Slice on conditional statement to current workbook.
    The image shows the Slice on conditional statement to current workbook option.
    Note: To add new code blocks at the end of the current workbook, you must ensure that no code blocks in the current workbook are selected first, and then slice on the conditional statement.
    Then you will see that the WHEN '01UMOT' statements in LGUPOL01 are attached to the list of code blocks.
    The image shows the code block list.

    You can click on those code blocks and edit the statements based on your needs. Further more, you can move the code blocks up and down to organize the order of code blocks.

    Now you have explored how to slice the highlighted code portions from programs into a workbook. Next, you can even manually add those statements that are not highlighted but considered as useful for the services that you want to create.

  20. Select the non-highlighted lines that you want to add, right-click, and then select Copy selected lines to current workbook or Copy selected lines to new workbook.
  21. You can repeat the process of getting the code blocks from more programs in the call chain till you are satisfied with the coverage. When all the code blocks that you need are settled, click Export workbook to export all the code blocks that you extracted. A Export workbook <your workbook name> dialog is displayed. For example, it is Export workbook test 1 dialog in this tutorial.
    The image shows the Export workbook dialog.
  22. Select one of the following options from the Export format drop-down list to export your workbook as needed.
    • COBOL option to export your workbook as a .cbl file
    • JSON option to export your workbook as a .json file
  23. Specify a name for the workbook to export in the File name field, for example, test 1.
  24. Click Save to export and save the workbook as a .json or .cbl file.