i
Forms
The model class contains the properties with its getters and setters, while the service class contains the operations 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.
•Getters for each field for use in SQL shows from the Deyel SDK.
•Inner classes representing 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”() |
It allows to retrieve the FileReference object associated with the file field of the instance. |
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 |
|
Rich Text |
String |
|
Number |
Integer |
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.
In addition, the service class includes a specific method to execute SQL shows on the corresponding model.
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 retrieving the form instances that meet the search criteria. |
searchCriteria: Class that allows defining a set of criteria and search configuration parameters |
executeQuery(entity, queryCriteria) |
Executes the generated show on the model using the different available methods.
|
entity: Form model class queryCriteria: Class that allows defining an SQL show through a set of criteria. |
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() ; 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 ; |
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();
|
5. Delete a form instance
To delete an existing account, an instance of the "Account" model class is created, indicating its identifier using the corresponding setter. The delete(account) method of the service is then invoked to delete the instance.
Account account = new Account(); account = accountService.read(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 retrieval of 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 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.
|
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 using 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(); } } } |
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 |
Contain |
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: an 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.
|
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
|
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
// Ends with // Criteria.endsWith("dsCompany","Corporation"); // Criteria.nendsWith("dsCompany","Corporation");
// It is null // Criteria.isNull("CdStatus"); // Criteria.notNull("CdStatus"); |
3. Operations on the results object
The SearchResult object is iterative and as such, it 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(); |
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() ;
|