i

Please enable JavaScript to view this site.

Documentation 8.3

Navigation: User Manual > Modeler > Rules Modeling > Business Rules > Advanced Rules > Deyel SDK for Java

Programming Advanced Rules with a Java IDE

To develop an advanced rule using an IDE, a series of steps must be followed.

 

Once the rule is created in the advanced rules modeler, it is downloaded to be included in the IDE project, it is developed and, once finished, it is imported from the context menu into the Deyel modeler.

Example of Use

 

This example describes the steps to develop the "getCostsWithTax" rule in the IDE.

 

A rule named "getCostsWithTax" is created. It receives a list of amounts as input parameter. Such list is added and the VAT cost is obtained. Returns the total VAT and the total amount of the sum as output parameter.

 

The “getCostsWithTax'' rule invokes the "taxCalculation" rule, which receives the sum of amounts as an input parameter, in the "inputAmount" field. Returns the VAT value as an output parameter, in the "taxValue" field.

 

For the example, the "taxCalculation" rule is assumed to be available within the environment.        

Step 1: Create the "getCostsWithTax" rule

 

In the rule modeler, a rule is created with the "getCostsWithTax" descriptive name.

The previously created adapter is selected, enter a description and press "Create Rule".

 

An input parameter is defined:

 

Name

Data Type

"amountList"

Double[]

 

 

Defined as output parameters:

 

Name

Data Type

"totalAmount"

Double

"AmountOfTaxApplied"

Double

 

 

This rule should be related to the "taxCalculation" rule using the wizard to include related objects, from the advanced properties tab.

 

Once the parameters have been entered and the new relation has been added, select the "Save" option from the top toolbar.

Step 2: Download the "getCostsWithTax" rule

 

From the top toolbar of the rule modeler, select the “Download” option.

The rule download includes the Java sources for developing and testing the rule.

Step 3: Setup the local environment

 

To develop the rule you need to have a local environment to work with Java.

Step 4: Include the "getCostsWithTax" rule in the Java IDE project

 

The rule download generates a file with a zip extension containing a "src" folder that respects the structure of Maven projects.

 

The file with zip extension should be copied to the project folder and decompressed in the same folder.

 

The structure of the project already configured is shown:

 

CM0051~1_img1

Step 5: Rule development

 

When the “getCostsWithTax” rule is included in the Java IDE project, two classes are obtained:

 

Name

Description

getCostsWithTax_1

Includes the rule logic

getCostsWithTax_1_Test

Includes the values to test from the IDE

 

The following code is defined in the getCostsWithTax_1 class:

 

 
 public class getCostsWithTax_1 extends
 getCostsWithTax_1_abstract{
   protected void run() throws java.lang.Exception{
   // The sum of the amounts is calculated
   totalAmount = 0.0 ;
   for (Double amount: AmountList
       totalAmount += amount;
   }
   // 21% VAT on the amount entered is calculated
 taxCalculationService myService =
           new taxCalculationService(getApiClient());
 taxCalculation myRule = new taxCalculation();
 myRule.setInputAmount(totalAmount);
 myRule.setTaxRate(new Double(21.0));
 myRule = myService.execute(myRule);
   // Gets the amount of VAT applied
   amountOfTaxApplied = myRule.getTaxValue() ;
 
   }
}

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