i

Please enable JavaScript to view this site.

Documentation 8.8

The model class contains getters and setters for each of the parameters defined in an advanced rule, while the service class contains the operation to be performed with the model.

 

The model name as well as the service name are determined by the property SDK Class Name, specified when modeling the advanced rule.

 

For example, if the "taxCalculation" advanced rule is used when downloading the Java sources of the rule, you get a taxCalculation.java file that represents the model and another taxCalculationService.java file with the available operation of the service.

Model Class Content

 

An advanced rule model contains:

 

Model constructor.

General getters.

Set of getters and setters of its parameters. The output parameters only have getters.

 

General getters

 

 

Operation

Description

Parameter

getCdRule()

Gets the identifier of the rule.


getCdVersion()

Gets the version of the rule.


 

Data Type

 

The parameters of an advanced rule have their equivalence with the data types of form fields.

Service Class Content

 

The service allows the following operations to be performed:

 

 

Operation

Description

Parameter

execute(rule)

Executes an advanced rule.

Rule rule: Model of the rule to be executed

Example of Use

 

The example invokes the "taxCalculation" advanced rule, using the model and service classes.

 

Values for "amount" and "taxRate" input parameters are defined in the model using its setters. Next, the execute(myRule) method of the service is executed and a VAT value is obtained from the getter of the "taxValue" parameter.

 

 

// Calculation of 21% VAT from the Entered Amount
taxCalculationService myService =
        new taxCalculationService (getApiClient());
taxCalculation myRule = new taxCalculation() ;
myRule.setAmount(new Double(100.12));
myRule.setTaxRate(new Double(21.00));
 
myRule = myService.execute(myRule);
// Gets the Amount of VAT Applied
Double doubleResult = myRule.getTaxValue();
log("The result of the tax value is:"
                                + doubleResult);
 

 

Rules Related to Fields

 

When a rule is enabled to be used in the relation to a field of an entity or of a page., two predefined parameters (input and output) are automatically generated. These parameters require certain considerations for the correct implementation of the rule.

 

Pagination is a fundamental requirement to ensure fluid navigation between results and guarantee their correct presentation and access.

 

Autocomplete implementation is necessary so that the related field can display suggestions in real time. If not implemented, users will not receive results while typing.

 

Input parameters can be of any data type compatible with rule modeling, except for arrays or lists, which are not allowed.

Example of Implementation of the Rule “getUsersByName”

 

The purpose of this rule is to return a list of users whose names partially match the text entered in the related field. Additionally, as an extra filter, the condition is applied that the last name contains the text received in the input parameter “last name”.".

 

For example, if the user enters "Ju" in the related field and the input parameter “last name” is "Perez", the valid results could include users like: “Juana Perez”, “Juan Perez”, “Julian Costa Perez”.

 

Use of the following input and output parameters:

 

Input parameters

input: Object of type RuleRelationInput, containing the search and pagination criteria.

last name: Text string (String) used as a filter to search for a match with users' last names.

 

Output parameters

output: Object of type RuleRelationOutput, which returns the list of results along with the pagination information.

 

Java Implementation Code

 

Below is an example of how to implement the rule "getUsersByName" in Java, which filters users by first and last name using the search and pagination criteria defined in the input parameters.

 

 

// Initializing the output parameter

output = new RuleRelationOutput();

 

UserService userService = new UserService(getApiClient());

SearchCriteria searchCriteria = new SearchCriteria();

 

// Apply selection criteria based on currentValues

if (!input.getCurrentValues().isEmpty()) {

           searchCriteria.addCriteria(Criteria.in("cdUser", input.getCurrentValues()));

}

// Apply auto-complete criteria

if (input.getLikeValue() != null) {

   searchCriteria.addCriteria(

   Criteria.like("dsFirstName", input.getLikeValue()));

}

// Apply additional user-defined criteria

if (lastname != null) {

   searchCriteria.addCriteria(Criteria.like("dsLastName", lastname));

}

 

// Apply pagination parameters

searchCriteria.setPage(input.getPage());

searchCriteria.setPageSize(input.getPageSize());

 

SearchResult<User> SearchResult = userService.search(searchCriteria);

for (User user : searchResult.getResult()) {

    // Generating output values

    RuleValue ruleValue = new RuleValue();

    ruleValue.setCode(user.getUserCode());

    ruleValue.setValue(userService._shortDescription(user));

    output.getResults().add(ruleValue);

}

 

// Configure pagination data in the response

int page = searchResult.getCurrentPage();

int pageSize = searchResult.getSearchCriteria().getPageSize();

int total = searchResult.getTotal();

output.setPaging(new Paging(page, pageSize, total));

 

Send us your comments
Share on X Share on Linkedin Send by Email Print