i

Please enable JavaScript to view this site.

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.

Data Type

 

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

Service Class Content

 

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() ;
account.setNuIdentifNumber("010000123");
account.setDsIndustry("1");              // 1 = Agriculture
account.setDsSource("7");                // 7 = Social Networking
account.setDsCompany("Trees Company");
account.setDtOpening((Date) new java.util.Date());
account.setFlLogo(new File("/photo.png"));
account.setCdStatus("1");                // 1 = Active

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 ;
account.setIdAccount(readAccountNumber);
account = accountService.read(account) ;
 
// Once read, continue working
String dscompany = account.getDsCompany();
Date dtopening = account.getDtOpening();
 
// Audit data
Timestamp dtStore = account.getDtStore();
Timestamp dtLastUpdate = account.getDtLastUpdate();
 

 

 

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();
account.setIdAccount(50000);
account = accountService.read(account);
 
// Once read, update
account.setDsCompany("Trees Company");
accountService.update(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();
account.setIdAccount(50000);
accountService.delete(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();
account.setIdAccount(50000);
 
// Account reading
account = accountService.read(account);
 
// Logo image reading
File logo = accoountService.getFlLogo(account);
 
// Assign a new logo to the account
account.setFlLogo(new File("Path"));
accountService.update(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.

 

 
Account.PhoneLine phones= new Account.PhoneLine();
phones.setNrPhone("01149834589");
phones.setTpPhone("Line phone");
 
Account.PhoneLine phones= new Account.PhoneLine();
phones1.setNrPhone("0115123987");
phones1.setNrPhone("Cell phone");
 
List<Account.PhoneLine> lsPhones = new ArrayList();
lsPhones.add(phones);
lsPhones.add(phones1);
account.setPhoneLine(lsPhones);
 
// Another option is
account.getPhoneLine().add(phones);
account.getPhoneLine().add(phones1);
 

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.

 

 
SearchCriteria searchCriteria = new SearchCriteria();
 Criteria criteria1 =
          Criteria.eq("CdStatus","1");
 searchCriteria.addCriteria(criteria1);
 searchCriteria.setPageSize(15);
 searchCriteria.setPage(1);
 searchCriteria.addOrderAsc("DsCompany");
 
 
SearchResult searchResult =
             accountService.search(searchCriteria);
 List<Account> instancesResult = searchResult.getResult();
 

 

 

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
 Criteria criteria = Criteria.eq("CdStatus""1");
 
// Different cdStatus= 1 corresponds to an active account
// Criteria criteria =  Criteria.neq ("CdStatus","1");
 
// Greater
// Criteria criteria = Criteria.gt ("qtScore", 20) ;
 
// Greater equal
// Criteria criteria = Criteria.gte ("qtScore", 20) ;
 
// Less
// Criteria criteria = Criteria.It ("qtStore", 50) ;
 
// Less equal
// Criteria criteria = Criteria.Ite ("qtStore", 50) ;
 
// Between
// Criteria criteria = Criteria.between ("dtOpening",
// Date.valueOf("01/01/1990"), Date.valueOf ("01/01/2020"));
 
// Between and admits equals
// Criteria criteria = Criteria.between("dtOpening",
// Date.valueOf("01/01/1990"), Date.valueOf("01/01/2020"));
 
// Out of range
// Format YYYY-MM-DD is used
// SimpleDateFormat format =
//      new SimpleDateFormat("yyyy-MM-dd");
// Date dateFrom =
//      new Date (format.parse( "1990-01-01" ).getTime());
// Date dateTo =
//      new Date(format.parse( "2020-01-01" ).getTime());
//
// Criteria criteria =
//        Criteria.nbetween ("dtOpening", dateFrom, dateTo );
 
// Contains In an internal object
// Criteria criteria = Criteria.like("eMailLine/dsEmail",
//         "yahoo.com.ar");

 

 

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
// Criteria criteria = Criteria.like("dsCompany","Inc.");
 
// It does not contain
// Criteria criteria = Criteria.nlike("dsCompany","Inc.");
 
// Starts with
// Criteria criteria = Criteria.startsWith("dsCompany","The");
 
// It does not start with
// Criteria criteria = Criteria.nstartsWith("dsCompany","The");
 
// Included dsIndustry = 6 is Communications, 8 is Education
// Criteria criteria =
// Criteria.in("dsIndustry", Arrays.asList("6", "8" ));
 
// Not Included dsIndustry 6 is Communications, 8 is Education
// Criteria criteria =
// Criteria.nin("dsIndustry", Arrays.asList("6", "8" ));
 

 

 

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();
 searchCriteria.setPageSize(15);
 searchCriteria.addOrderDesc("idAccount");
 
 // Accounts with industry equal to communications
 searchCriteria.addCriteria
 Criteria.eq("dsIndustry""6"));
 
// Accounts with a score greater than 20
 searchCriteria.addCriteria
 (Criteria.gt("qtScore"20)  );
 
 // Scrolls through all the accounts in the search result
 String stringData1 = "";
 for (Account account: searchResult) {
 stringData1 += " - " + account.getIdAccount()
                  + " - " + account.getDsCompany();
 }
 // If I only need the first results sheet
 SearchResult<Account> resultFirstPage =
 accountService.search(searchCriteria);
 List<Account> firstList = resultFirstPage .getResult();
 
 String stringData = "";
 stringData += " Amount of data " + firstList.size();
 stringData += " Pages " + resultFirstPage .getPages();
 stringData += " Actual Page " +
 resultFirstPage .getCurrentPage();
 

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() ;
Integer idAccount = contact.getIdCompany();
// Retrieve the id of a contact account
// and I read the account with that id
 
Account myAccount = new Account();
myAccount.setIdAccount(idAccount);
myAccount = accountService.read(myAccount);

 

Send us your comment
Share on Twitter Share on Linkedin Send by Email Print