i
Forms
The model class contains the properties with its getter and setter methods, while the service class contains the operations to be performed with the model.
For example, if the "Account (CRM_ACCOUNT)" form from the CRM application is used, when downloading the form Java sources, an account.java file is obtained, representing the model and another accountService.java file with the available operations of the service.
Model Class Content
A form model contains:
•Model builder.
•Set of getter and setter methods of its fields.
•Inner classes that represent the “Multiple occurrences” containers model, if any.
Model properties for a form can have the following data types.
Equivalence between form field data types and Java model is shown.
Control |
Data Type |
Java |
---|---|---|
Text |
Alphanumeric (length) |
String |
Alphanumeric Uppercase (length) |
String |
|
Large Alphanumeric |
String |
|
Enriched Text |
String |
|
Integer |
Number |
Integer |
Large Integer |
Long |
|
Decimal |
Double |
|
Time |
Time |
java.sql.Time |
Local Time |
java.sql.Time |
|
Date |
Date |
java.sql.Date |
Date and Time |
java.sql.Timestamp |
|
Local Date |
java.sql.Timestamp |
|
Date and Local Time |
java.sql.Timestamp |
|
Image |
Image in Folder |
String |
Image in Database |
String |
|
File |
File in Database |
String |
Check |
Boolean |
Boolean |
The service allows to perform the following CRUD (Create, Read, Update, Delete) and search (search) operations, as well as containing specific methods, for example to retrieve files from the form.
Operation |
Description |
Parameters |
---|---|---|
create(entity) |
Creates a form instance. |
entity: Form model class
|
read(entity) |
Reads a form instance. |
entity: Form model class
|
update(entity) |
Updates a form instance. |
entity: Form model class
|
delete(entity) |
Deletes a form instance. |
entity: Form model class
|
search(searchCriteria) |
Allows to retrieve the form instances that meet the search criteria. |
searchCriteria: Class that allows defining a set of criteria and search configuration parameters. |
Examples of Use
The examples use the "Account (CRM_ACCOUNT)" form of the CRM application and each example contains the use of "Account" model class and "AccountService" service class.
1. Create service
This service is created only once in the rule and is reused in different operations.
AccountService accountService = new AccountService(getApiClient()); |
2. Create a form instance
An instance of “Account” model class is created, values are assigned to its properties. Using the “AccountService” service class, the new account is saved with the assigned values through the create (account) method.
Account account = new Account() ; Integer accountNumber = accountService.create(account); log("Account created with account number:"+ accountNumber);
|
3. Read a form instance
To obtain data from an existing account, an "Account" model class instance is created, an identifier chosen through the corresponding setter method is indicated and such instance is read using the read(account) method of the “AccountService” service class. The instance contains all its properties which can be queried using the corresponding getter methods. The example reads the dsCompany, dtOpening, dtStore, and dtLastUpdate properties.
Account account = new Account(); Integer readAccountNumber = 50000 ; |
4. Modify a form instance
To modify data from an existing account, an "Account" model class instance is created, an identifier chosen through the corresponding setter method is indicated and such instance is read using the read(account) method of the “AccountService” service class. The dsCompany property is then modified using the corresponding setter method and the update(account) method of the service is invoked to update the account.
Account account = new Account();
|
5. Delete a form instance
To delete an existing account, an instance of the "Account" model class is created, indicating its identifier by means of the corresponding setter method. The delete(account) method of the service is then invoked to delete the instance.
Account account = new Account();
|
6. Use of file and image type fields
To retrieve a file related to a form instance, use the corresponding get+<fieldname>+(entity) method of the "AccountService" service class.
In this example, the getFlLogo(account) method of the "AccountService" service class is invoked, which allows to retrieve the file corresponding to a logo associated with a File object.
Account account = new Account(); |
7. Use of internal objects
Internal objects represent the set of fields modeled in iterative containers.
In this example, two new “Account.PhoneLine” internal objects are instantiated and values are assigned to their nrPhone and tpPhone properties.
A new list of “Account.PhoneLine” objects can be saved with the setPhoneLine(lsPhones) method or by adding two instances of the “Account.PhoneLine” object to the current list.
|
Searchs
Searches on form instances can be performed using the following objects.
Criteria- represents search criteria on form data. It is made up of elements that can be fields and values, connected by operators.
Operator |
Description |
---|---|
eq |
Equal |
neq |
Different |
gt |
Greater |
gte |
Greater equal |
lt |
Less |
lte |
Less equal |
between |
Between |
betweene |
Between and admits equals |
nbetween |
Out of range |
like |
Contains |
nlike |
It does not contain |
startsWith |
Starts with |
nstartsWith |
It does not start with |
in |
Included |
nin |
Not included |
SearchCriteria: object that groups search criteria (Criteria object), it also allows parameterizing the order of the result, the size of the reading page and the number of pages to be retrieved. Reading by pages is used since the data volume on a form can be very large.
.
Form Service: service class of the form on which the search is being carried out. Contains the search(searchCriteria) operation that must receive the SearchCriteria object as a parameter and returns the SearchResult object.
Example:
SearchResult searchResult = accountService.search(searchCriteria);
SearchResult: object that contains the search results. Contains a list of form instances, which are instances of the corresponding model, for example "Account". This object allows to know the total number of reading pages resulting from the search, the size of each page and the number of pages to retrieve.
Examples
1. Searchs
This example retrieves a list of accounts with active state, where such state corresponds to code "1". A quantity of 15 lines per reading page and the number of pages to retrieve are defined. The results are ordered by company name in ascending order.
|
2. Constructor types for search criteria
This example creates a Criteria object and defines different search conditions using the equal, different, greater, greater equal, less, less equal, between, among, and allows equals, out of range, and contains operators.
// Equal cdStatus= 1 corresponds to an active account
|
Deyel uses the data type java.sql.Date for "date" type fields, so the transformation from java.util.Date to java.sql.Date must be done, when it is required to create an object with this type of data.
// Contains |
3. Operations on the results object
The SearchResult object is an iterative object and as such can be scrolled through in different ways.
The example uses a FOR statement to iterate over each of the instances that meet the search conditions of the dsIndustry and qtScore properties, retrieving the idAccount and dsCompany properties.
SearchCriteria searchCriteria = new SearchCriteria(); |
Navigation between Related Entities
In the CRM application, the “Contact (CRM_CONTACT)” form has a relation with the “Account (CRM_ACCOUNT)” form and the related account can be retrieved from a business rule, from a contact.
An instance of the “Contact” model class is created and the account identifier is retrieved using the corresponding getter method.
Next, an instance of the "Account" model class is created indicating the identifier retrieved from the contact in the setter method and the account instance is read using the read(myAccount) method of the "AccountService" service class.
Contact contact = new Contact() ;
|