i

Please enable JavaScript to view this site.

Documentation 8.5

The model class contains the properties with its getters and setters, 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 constructor.

Getters and setters of its fields.

Inner classes that represent the “Multiple occurrences” containers model, if any.

Specific method of the model class

 

In addition to the getters and setters, there are specific methods related to fields.

 

 

Operation

Description

Parameters

getReference_”idFileTypeField”()

Allows to retrieve the FileReference object associated with the file field of the instance.


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)

Create 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

 

readCases(entity)

Allows to retrieve the case instances associated with a form instance.

 

Returns a list of cases since a form instance can be related to more than one case.

entity: Form model class

bind(entity,case)

Allows to associate a case to a form instance.

entity: Form model class

case : Case model class

shortDescription()

It allows retrieving the short description of the instance sent by parameter.

FormInstance

 

get“idField”_description()

It allows retrieving the descriptive value of the indicated field.

FormInstance

 

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. Service creation

 

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 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 getters. 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 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 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. The delete(account) method of the service is then invoked to delete the instance.

 

 

Account account = new Account();
account.setIdAccount(50000);

account = accountService.read(account);
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 containers of multiple occurrences.

 

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 phones1= new Account.PhoneLine();
phones1.setNrPhone("0115123987");
phones1.setTpPhone("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);
 

 

 

8. Reading of cases associated with form instances

 

The example retrieves the case associated with a form instance and executes that case.

 

To use this example in addition to the "Account" (Account) form, the "Account Registration" (Account Registration) process that uses that form must be modeled. The case can be started manually or by Deyel SDK methods.

 

To read cases associated with a form instance, an instance of the "Account" model class is created, indicating the identifier chosen by means of the corresponding setter. The "AccountService" service is instantiated and using the readCases(account) method, the "Cases" list is retrieved with the cases associated with the instance with identifier 10.

Having the “Cases” list, it is possible to iterate through it to retrieve some or all of its cases. The “AccountRegistration” service is instantiated and using the execute(accountRegistrationCase) method, the first associated case is executed.

 

Both the form instance and the case instance must be created.

 

 

Account account = new Account();

account.setId(10);

 

AccountService accountService = new AccountService(getApiClient());

List<Cases> listOfCases = accountService.readCases(account);

 

AccountRegistration  accountRegistrationCase = new AccountRegistration(listOfCases.get(0));

 

AccountRegistrationService accountRegistrationService = AccountRegistrationService(getApiClient());

accountRegistrationService.execute(accountRegistrationCase);

 

 

 

9. Associate a case with a form instance

 

In the example, a case associated with an "Account" form instance is read to then associate such case to a "Contact" form instance, leaving both instances associated with the same case.

 

The case associated with the "Account" form instance is read with the readCases(account) method, described in example 8.

The case is associated with the "Contact" form instance, with the bind(contact,accountRegistrationCase) method.

 

A case can only be linked to a form instance if there is a relation between the form and the process to which the case to be associated belongs.

 

 

Account account = new Account();

account.setId(10);

 

AccountService accountService = new AccountService(getApiClient());

List<Cases> listOfCases = accountService.readCases(account);

 

AccountRegistration accountRegistrationCase = (AccountRegistration) listOfCases.get(0);

AccountRegistrationService accountRegistrationService = AccountRegistrationService(getApiClient());

 

Contact contact = new Contact();

contact.setId(20);

 

ContactService contactService = new ContactService(getApiClient());

 

contactService.bind(contact,accountRegistrationCase);

 

 

 

10. Retrieve the code and description of the field value associated with a value list

 

In order to use this example, the “States” value list should be modeled in Deyel and values should have been entered to this list.

 

Code

Descriptive Value

1

Active

2

Inactive

 

 

It is required to relate an “Account” form field with the “States” value list.

 

When a field has a relation defined, the content can use its code or its descriptive value.

 

 

This example retrieves the field code associated with the value list.

 

 

String stateCode = account.getAccountState();

//Returns: 1

 

 

 

While in the following example, the description of the field associated with the value list is retrieved.

 

 

String stateDescription = accountService.getAccountSate_description(account); 

//Returns: Active

 

 

The code is retrieved through the model object and the description is retrieved through the service object.

 

 

11. Updating form instances with commit or rollback

 

This example declares a variable that represents the service of the object to be updated. By using it, the list of existing instances is retrieved and traversed with the FOR statement. For each of them, the service is redefined, obtaining its own API client, the VAT value is calculated and updated, and an attempt is made to perform a commit command or a rollback command to the connected database, as appropriate.

 

 

protected void run() throws java.lang.Exception{

    TestFormService xTestFormService = new TestFormService(getApiClient());

    SearchCriteria xSearchCriteria = new SearchCriteria();

    List<TestForm> xListResult = xTestFormService.search(xSearchCriteria).getResult();

    for(int j = 0; j < xListResult.size(); j++) {

        try {

            xTestFormService = new TestFormService(getOwnApiClient());

            TestForm xElement = xListResult.get(j);

            xElement.setValueOfVAT((vatrate * entryamount) / 100);

            xTestFormService.update(xElement);

            ownConnectionCommit();

        } catch (Exception e) {

            ownConnectionRollback();

        }

    }

}

Search

 

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

endsWith

Ends with

nendsWith

Does not end with

isNull

It is null

notNull

It is not null

 

 

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.

Search Examples

 

1. Search

 

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", "between and allows equals", "out of range", "contains", "does not contain", "starts with", "does not start with", "included", "not included", "ends with", "does not end with", "is null", "is not null".

 

 

// 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" ));

 

// Ends with
// Criteria criteria =

// Criteria.endsWith("dsCompany","Corporation");
 
// Does not end with
// Criteria criteria =

// Criteria.nendsWith("dsCompany","Corporation");

 

// It is null
// Criteria criteria =

// Criteria.isNull("CdStatus");
 
// It is not null
// Criteria criteria =

// Criteria.notNull("CdStatus");
 

 

 

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();
 

Browsing 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.

Next, an instance of the "Account" model class is created indicating the identifier retrieved from the contact in the setter 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 comments
Share on X Share on Linkedin Send by Email Print