Create Unit

From WebRatio WebML Wiki

Jump to: navigation, search


Contents

Introduction

The Create Unit

The Create Unit is an Operation Unit and it's used to create instances of an Entity. When the Create Unit is activated it physically creates one or more new rows of the physical table related to the selected Entity storing the data received as input.

Properties

The Properties View of the Create Unit


  • Id: The unique key automatically assigned by WebRatio to identify the Unit (e.g. cru1).
  • Name: A meaningful name for the Unit, used as label (e.g. Create Employee).
  • Bulk: A flag stating that the Unit is able to perform multiple Entity instance creations at once (expecting arrays as input parameters).
  • Entity: The Data Model Entity on which the Unit is based (e.g. employee).
  • Avoid Blank Records: A flag stating that the Unit should avoid the creation of records in case the provided input values are NULLs or empty.
  • Blank Attributes: The list of Entity attributes used to verify the Avoid Blank Records condition (enabled only if the "Avoid Blank Records Property" is checked). In the case no attribute is selected the avoid blank records condition is verified for all Entity attributes.
  • Delete All Before: A flag stating that the Unit removes all the already stored Entity instances before its execution (available only for volatile Entities).
  • Home: A flag stating that the Create Unit must be executed as the first operation when the user enters in the related Site View.
  • Default: A flag stating that the Create Unit must be executed as the first operation when the user enters the Area containing the Unit.
  • Landmark: A flag stating that the link shown in the corresponding Landmark menu that will activate the Unit. If the operation or the operation chain has no outgoing link, the final target page will be the last page visited.
  • Protected: A flag stating that the access to the Create Unit is granted only to users belonging to groups entitled to access to it.
  • Secure: A flag stating that all the links that can activate the Create Unit are implemented using the Secure HTTP protocol, instead of the HTTP protocol.
  • Custom Descriptor: A flag stating that the Unit uses a Custom Descriptor.
  • Custom URL Name: The Custom URL Name of the Unit. It is possible to define a custom name that will be used as URL to reach the Create Unit, instead of the standard Id (used by default). The custom URL name must not contain whitespaces, non-ascii characters or other special characters like /, ?.


Configuration

A Create Unit can be configured through a context menu that can be reached right clicking on the Unit either in the Work Area or in the Outline View. The context menu contains the following options:

The Context Menu of the Create Unit
  • Add Link: Adds an outgoing link (of Transport type) to the Unit, which can be used to transport information to other elements.
  • Add OK Link: Adds an outgoing OK Link to the Unit. The OK Link is activated when the Unit performs its operation correctly and can be used to transport information. Moreover, the OK Link will cause the execution of its target element (opens a target page or activates other Operation Units).
  • Add KO Link: Adds an outgoing KO Link to the Unit. The KO Link is activated when the Unit isn't able to perform its operation correctly and can be used to transport information. Moreover, the KO Link will cause the execution of its target element (opens a target page or activates other Operation Units).
  • Add Property: Adds a custom property to the Unit. A Property is composed by Name and Value and permits to mark the element for different purposes.


Input and Output

The Input and the Output of the Unit are accessible through the Parameters Coupling window of incoming and outgoing Links respectively.

Input

Input configuration of the Create Unit with a relationship item

The input of the Create Unit consists of all the Attributes and 1:N Relationship Roles of the Entity on which the Unit is defined. To access the input parameters, open the Parameters Coupling dialog with a double click or by selecting the "Coupling" property on an incoming link to the Create Unit. Here all the Entity attributes and 1:N Relationship Roles are listed.

Input configuration of the Create Unit with a BLOB item

In case of BLOB attributes the unit exposes an additional input parameter named "<attribute-name> [file name]" which permits to specify an alternative file name (valid only if the BLOB value is provided in input).

In case of bulk creation, the rules driving the creation of instances are the following:

  • if all the attribute values are arrays of length L, the unit exactly creates L different instances.
  • if arrays of length L are inter-mixed with either arrays of length one or plain values, again L different instances are created; single values are replicated all over the L instances.
  • if arrays with different lengths (greater than one) are provided to the unit an error will be returned.


Output

Output configuration of the Create Unit

The output of the Create Unit consists of all the Attributes of the selected Entity representing the actual values of the current Entity Instance. To access the Output Parameters, open the Parameters Coupling dialog with a double click or by selecting the "Coupling" property on an outgoing link from the Create Unit.

Here all the Output Parameters can be coupled with the Input Parameters of the target element.


Examples

The purpose of this section is to show the usage of the Create Unit through examples. This example is based on the Data Model shown in the following image.

The Data Model used in the example
This Data Model consists of two Entities : "Company" and "Employee".

The "Company" entity has many attributes, such as "Name", "E-mail", "Nationality", and so on.

The "Employee" entity has attributes such as "Name", "Surname", "Email", "Role" and so on.

An Employee belongs to one Company while, obviously, a Company has many Employees. This is represented with the 1:N Relationship "Company_Employee".

Example 1: Insert New Employee

Our goal is to give the possibility to the user to store new employees data in the application. The user will be able to define all the new employee data and save them in the Data Model. In order to accomplish this example, it is necessary to go through the following steps:

  1. Add a Page to the Site View: select the "Page" icon from the palette, and place it on the Site View. Change the page name (setting "Insert a new Employee") and other properties in the Properties View (such as "Home" or "Landmark" properties) to make the page accessible.
  2. Add an Entry Unit to the page: select the Entry Unit icon from the palette and place it inside the page. Change the "Name" property in "Employee Data".
  3. Define the Entry Unit fields:right click on the Entry Unit and select the Field Wizard option. In the opened dialog pane, select the Employee Entity. In the next pane, select the "name", "surname", "email", "birth date", "hire date" and "role" attributes. In order to choose the Company the new employee belongs to, select the "EmployeeToCompany [1:N]" Relationship Role.
  4. Add a Selector Unit to the page: select the Selector Unit icon from the palette and place it inside the page. Change the "Name" property in "All Companies".
  5. Set the Entity on which the Selector Unit is based: click on the "Edit" button next to the "Entity" property in the Properties View. Then choose the "Company" Entity from the opened dialog pane.
  6. Define the sort criteria of the Selector Unit: click on the "Edit" button next to the "Sort Attributes" property, then choose the "name" attribute and the "ascending" sort criteria.
  7. Draw a transport link between the "All Companies" Selector Unit and the "Employee Data" Entry Unit: select the Link button from the palette and click on the "All Companies" Selector Unit (the Source of the Link) and then on the "Employee Data" Entry Unit (the Target of the Link). Set the Name property of the newly created Link to "Companies data passing" and the Type property to "transport".
  8. Define the parameters coupling: open the Parameters Coupling window of the newly created link in order to define the coupling between the output parameters of the source Unit and the input parameters of the target Unit.In the Parameters Coupling dialog, couple the "oid" Attribute of the Selector Unit with the "Company [output]" Selection Field Slot of the Entry Unit and the "name" Attribute of the Selector Unit with the "Company [label]" Selection Field Slot of the Entry Unit.
  9. Add a Data Unit to the page: select the Data Unit icon from the palette and place it inside the page. Change the "Name" property in "New Employee".
  10. Set the Entity on which the Data Unit is based: click on the "Edit" button next to the "Entity" property in the Properties View. Then choose the "Employee" Entity from the opened dialog pane.
  11. Choose which attributes of the selected Entity must be shown: click on the "Edit" button of the "Display Attributes" property. Then choose the Data Unit attributes from the opened dialog.
  12. Add a Create Unit: select the Create Unit icon from the palette and place it inside the Web Model. Change the "Name" property in "Create a new Employee".
  13. Set the Entity on which the Create Unit is based: click on the "Edit" button next to the "Entity" property in the Properties View. Then choose the "Employee" Entity from the opened dialog pane.
  14. Draw a normal link between the "Employee Data" Entry Unit and the "Create a new Employee" Create Unit: select the Link button from the palette and click on the "Employee Data" Entry Unit (the Source of the Link) and then on the "Create a new Employee" Create Unit (the Target of the Link). Set the Name property of the newly created Link to "Save" and the Type property to "normal".
  15. Define the parameters coupling: open the Parameters Coupling window of the newly created link in order to define the coupling between the output parameters of the source Unit and the input parameters of the target Unit.In the Parameters Coupling dialog, press the Guess Coupling button. WebRatio will automatically couple all the Input Parameters with the Output Parameters.
    Nota The Guess Coupling functionality will perform a name comparison between Input and Output Parameters guessing possible coupling. It is particularly useful to use it with the Field Wizard functionality, since it will create the Fields with the same names of the Entity Attributes.
  16. Draw an OK link between the "Create a new Employee" Create Unit and the "New Employee" Data Unit: select the Link button from the palette and click on the "Create a new Employee" Create Unit (the Source of the OK Link) and then on the "New Employee" Data Unit (the Target of the OK Link). Set the Name property of the newly created OK Link to "Employee created".
  17. Define the parameters coupling: open the Parameters Coupling window of the newly created link in order to define the coupling between the output parameters of the source Unit and the input parameters of the target Unit.In the Parameters Coupling dialog, couple the "oid" Attribute of the Selector Unit with the "Company [output]" Selection Field Slot of the Entry Unit and the "name" Attribute of the Selector Unit with the "Company [label]" Selection Field Slot of the Entry Unit.
  18. Generate the Web application: click on "Generate Full Web Project" on the WebRatio Menu Bar. Once the generation process has completed, it is possible to start the application server and test the Web application.
The Web Model of the example
The Properties View of the Entry Unit
The Properties View of the Selector Unit
The Parameters Coupling window of the transport link
The Properties View of the Data Unit
The Properties View of the Create Unit
The Parameters Coupling window of the normal link
The Parameters Coupling window of the OK link
The generated Web application



Related articles:
Category Difficulty Refers
Connect Unit Web Model Beginner Connect Unit
Context Parameters Web Model Beginner Get Unit
Set Unit
Reset Unit
Create Unit Web Model Beginner Create Unit
Create a "Simple data centric" web application Web Model Beginner Site View
WebML
WebRatio
Custom Locations and Master pages Web Model Beginner Master Page
Custom Location
… further results












Did you find this article useful? Please rate it!

Rating: 4.5/5 (4 votes cast)

Personal tools