Data Management: Action Definition

Modeling Actions with WebRatio Platform
1,650 views Published on Apr 04, 2014 | Time 24 min
Applies to: 7.2 or higher

In a Web application, you often need to manage information that is shown to the user. Managing the information means to create, update, or delete information. With WebRatio Platform you can easily model an administration section so that the Web Application user can manage the application data. In this lesson we describe the best practices for modeling an "Action Definition" containing the business logic needed in order to save the information changes related to an object of the Domain Model. This lesson does not cover the complete IFML model, which is described in the "Data Management: IFML Model" lesson.

Transcript

Table of contents

The Actions in the Data Management IFML Model

For the Data Management Action Definition, let’s continue working on our "CRM" web project in which we already added the "Domain Model" composed of the "Company" and "Employee" entities, and the "Administration" site view containing the "Company" area. 
This area contains the IFML Model related to the Data Management.

As you can see there are two different Actions: "Save Company" and "Delete Company". Each action contains a reference to an Action Definition which contains the business logic to be execute when the user triggers the action.

As you can see in this project both Action Definitions are empty. Let's see how to model the Action Definitions.

Save Company Action Definition

The "Save Company" action definition contains the operation chain that stores the information provided by the Web application user in the form, for a specific "Domain Model Object". In this case, the "Domain Model Object" is the company object. This is a schema representing the flow chart of the "Action Definition". The flow of the execution is the following: first, the Web application must check whether the user wants to create a new company or to update an existing one. Then the operation chain creates or updates the information. This is the model of the "Action Definition" implementing the flow chart seen in the previous slide. The operation chain is composed of these main operations:

  • "Is Not Null" operation is an operation that checks whether a parameter value is null or not, and redirects the navigation flow in one direction or another. In our example the operation evaluates the "company key" parameter. If the parameter is null, then a new company must be created following the "KO Flow"; otherwise the company having that specific key is updated following the "OK Flow".
  • "Create" operation creates one or more new instances of a domain object. In our example the "Create" operation receives all the information about the new company to be created and stores it.
  • "Update" operation changes the value of one or more properties of a domain object instance. In our example the "Update Operation" receives all the information about the company to be updated and stores it. To work properly, the "Update Operation" requires a conditional expression. This is necessary in order to know which object is to be updated with the new information. When you add an "Update Operation" to the "Action Definition", by default you get a conditional expression composed of a "Key Condition".

How to Model the "Save Company" Action

From our "CRM" web project, select the "Save Company" action from the "Administration" site view. Move to the Properties View and press the "Jump to Action Definition" button next to the "Action Definition" property. Now we can model the operation chain related to the "Action Definition". In this sample project you already have the "Input Port", the "Success" OK Port and the "Failure" KO Port. Remember that, when you create a new "Action Definition", the ports must be defined explicitly. Let’s start adding all the input parameters needed by the "Action Definition". Right click on the "Input Port" and select the "Add" and then the "Input Port Parameter" option. Write a meaningful name for the parameter, for example “company key”. Using the same procedure let’s add the "company object" input parameter. In a very similar way we can also add the "Output Parameters".

Let’s suppose we want to provide as output the key of the managed company. Right click on the "Success" OK Port and select the "Add" and then "Output Port Parameter" option. Write a meaningful name for the parameter, for example "company key".

Once we have the main skeleton it’s time to model the business logic for saving the company information. To decide whether to create or update a company, let’s use an "Is Not Null Operation". Select the "Is Not Null" operation from the toolbar section related to "Control Flow Operations" and click in the work area. Double click on the operation and write a meaningful name, for example "Company Exists?".
To state that the "Is Not Null" operation is the first operation of the chain, let’s use an "OK Flow". Select the "OK Flow" item from the toolbar section related to "Flows" and click on the "Input Port" and then on the "Is Not Null" operation.

To create a new company let’s use a "Create Operation". Select the "Create" operation from the toolbar section related to "Operations" and click in the work area. Double click on the operation and write a meaningful name, for example "Create Company". Then move to the Properties View and press the “Select” button next to the “Entity” property. In the opening dialog choose the "Company" entity and press the “OK” button to confirm.
To state that the "Create" operation must be executed after the "Is Not Null" operation when the company does not exist, let’s use a "KO Flow". Select the "KO Flow" item from the toolbar section related to "Flows" and click on the "Is Not Null" operation and then on the "Create" operation.

To update an existing company let’s use the "Update" operation. Select the "Update" operation from the toolbar section related to "Operations" and click in the work area. Double click on the operation and write a meaningful name, for example “Update Company”. Then move to the Properties View and press the "Select" button next to the "Entity" property. In the opening dialog choose the "Company" entity and press the "OK" button to confirm. To state that the "Update" operation must be executed after the "Is Not Null" operation when the company exists, let’s use an "OK Flow". Select the "OK Flow" item from the toolbar section related to "Flows" and click on the "Is Not Null" operation and then on the "Update" operation.

If an error occurs, after the execution of the "Create" operation or of the "Update" operation the "Action Definition" must exit through the "Failure" KO Port. Let’s use the "KO" flows for this purpose.
Select the "KO Flow" item from the toolbar section related to “Flows” and create two flows: for the first one click on the "Create" operation and then on the "Failure" KO Port; for the second one click on the "Update" operation and then on the "Failure" KO Port.

When the execution of the operations is successful, the "Action Definition" must exit through the "Success" OK Port. Let’s use the "OK" flows for this purpose. Select the "OK Flow" item from the toolbar section related to "Flows" and create two flows: for the first one click on the "Create" Operation and then on the "Success" OK Port; for the second one click on the "Update" operation and then on the "Success" OK Port.

Finally let’s use two Data Flows to bind the information on the "Create" operation and "Update" operation. Select the "Flow" item from the toolbar section related to "Flows" and create two flows: for the first one click on the "Input Port" and then on the "Create" operation; for the second one click on the "Input Port" and then on the "Update" operation. Press the "Next" button to proceed.

Parameter binding

Right now we have modeled the execution flow of the operation but the binding of information is missing. Click on each highlighted flow to learn which is the binding to be done.

Delete Company Action Definition

This is the model of the "Action Definition" that implements the company deletion. The operation chain consists of a single operation: the Delete operation.

  • The "Delete" operation deletes one or more instances of a domain object. In our example the operation uses the “company key” parameter in order to retrieve the company to be deleted.

How to Model the "Delete Company" Action Definition

From our "CRM" web project, select the "Delete Company" action from the "Administration" site view. Move to the Properties View and press the "Go to Action Definition" button next to the "Action Definition" property. Now we can model the operation chain related to the "Action Definition". In this sample project you already have the "Input Port" and the "Success" OK Port and "Failure" KO Port. Remember that, when you create a new "Action Definition", the ports must be defined explicitly.

Let’s start adding all the "Input Parameters" needed by the "Action Definition". Right click on the "Input Port" and select the "Add" and then the "Input Port Parameter" option. Write a meaningful name for the parameter, for example "company key". Once we have the main skeleton it’s time to model the business logic for saving the company information.

To delete an existing company let’s use the "Delete Operation". Select the "Delete" operation from the toolbar section related to "Operations" and click in the work area. Double click on the operation and write a meaningful name, for example "Delete Company". Then move to the Properties View and press the "Select" button next to the “Entity” property. In the opening dialog choose the "Company" entity and press the "OK" button to confirm.

To state that the "Delete" operation is the first operation of the chain, let’s use an "OK Flow". Select the "OK Flow" item from the toolbar section related to “Flows” and click on the "Input Port" and then on the "Delete" Operation. Double click on the "OK Flow" to make the binding. In the opening dialog, uncheck the "Enable Default Binding" property and bind the "company key" parameter provided by the Input Port with the "KeyCondition" parameter provided by the Delete Operation. Then press the OK button to confirm.

After the execution of the "Delete" operation, if an error occurs then the "Action Definition" must exit through the "Failure" KO port. Let’s use the "KO" flows for this purpose.
Select the "KO Flow" item from the toolbar section related to "Flows" and click on the "Delete" operation and then on the "Failure" KO Port.

When the execution of the "Delete" operation is successful, the "Action Definition" must exit through the "Success" OK Port. Let’s use the "OK" flows for this purpose. Select the "OK Flow" item from the toolbar section related to "Flows" and click on the "Delete" Operation and then on the "Success" OK Port. For this "Action Definition" only one binding is necessary and it must be defined on the "OK Flow" connecting the "Input Port" to the "Delete" operation. The binding provides the “company key” Input Parameter to the "Key Condition" of the "Delete" operation. Press the "Next" button to proceed.