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
- You have installed and configured Z Refactoring Assistant as instructed in Getting started.
- You have built the GenApp project in IBM AD Build Client as described in Prerequisite: Building the GenApp project.
Procedures
- Launch your browser and go to https://<hostname>:9443. By default, you will be on the Workspaces tab.
- Click the Create workspace button on the upper right corner of the Workspaces page.
- In the
Create workspace
dialog, type a name for the workspace that you want to create, for example, GenApp. - From the AD project drop-down list, select the project that you built with IBM AD Build Client.
- Click Create to create the workspace. When the creation is completed, the
Graph view of the
GenApp
workspace is displayed. - Type MOTOR in the search box. You will see
MOTOR - Db2® table
in the results. - 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 typeTable
. 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.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.
- Click the Action Menu (
) 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
- Select Identify conditional statements. A new workbook page is displayed, which takes you to the source file of LGUPDB01 and presents the conditional statements in this particular program.
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. - 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 asConditional statements
orParagraphs
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.After further investigation on the code, you determine that the
WHEN '01UMOT'
statement is the code portion that you want to extract. - Right-click the
WHEN '01UMOT'
and then select Slice on conditional statement to new workbook. ASlice to new workbook
dialog is displayed. - Type a name for the workbook you create, for example, type test 1.
- 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. - Click Save to create the workbook.
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.
- Click the Graph tab on the upper right corner to navigate to the closure view.
- Click the LGUPDB01 program node and then you will see that the
LGUPOL01 program invokes LGUPDB01.
- Click the Action Menu (
) icon on the upper right corner of the LGUPOL01 program node.
- Select Identify conditional statements to inspect the
conditional statements for LGUPOL01.
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. - Right-click
WHEN '01UMOT'
and then select Slice on conditional statement to current workbook.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 theWHEN '01UMOT'
statements in LGUPOL01 are attached to the list of code blocks.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.
- 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.
- 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 isExport workbook test 1
dialog in this tutorial. - 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
- COBOL option to export your workbook as a
- Specify a name for the workbook to export in the File name field, for example, test 1.
- Click Save to export and save the workbook as a
.json
or.cbl
file.