# Implementing the initial step

## Implementing the initial step

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZXPoGMA--Pbh5qv%2Faction01.png?generation=1580825236853880\&alt=media)

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZXR3F_iA4akNUFk%2Faction02.png?generation=1580825241810604\&alt=media) ![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZXTKD6c5SeZYMro%2Faction03.png?generation=1580825237569316\&alt=media)

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZXVaRNNfoW1_AqW%2Faction04.png?generation=1580825235669176\&alt=media)

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZXXL9ADY-Z4ZIBK%2Faction06.png?generation=1580825241051905\&alt=media)

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZXZViUgesjbDQ89%2Faction07.png?generation=1580825240380827\&alt=media)

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZXa5-TZawL9-L7z%2Faction08.png?generation=1580825237776846\&alt=media)

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZXcN-ZGamVAJHFX%2Faction09.png?generation=1580825235747724\&alt=media)

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZXeIF2UJO6hEetS%2Faction10.png?generation=1580825238178268\&alt=media)

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZXgcatknYoJu_KZ%2Faction11.png?generation=1580825242764515\&alt=media)

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZXiwC8HbQ1l6Ffw%2Faction12.png?generation=1580825238571918\&alt=media)

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZXkddggwHrVreFx%2Faction13.png?generation=1580825241344090\&alt=media)

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZXmVkigZ2WnYdAL%2Faction14.png?generation=1580825239361904\&alt=media)

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZXoUJX6ay7bhtod%2Faction15.png?generation=1580825238341501\&alt=media)

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZXqSr2wjobZCFix%2Faction16.png?generation=1580825236236051\&alt=media)

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZXst5OhrH2Bkrb3%2Faction17.png?generation=1580825242374306\&alt=media)

Then you shall obtain the rule as follows. Notice that the stringValue of the calculatedAttribute as a formula. So you should select the formula not a litteral. And also that we had to create a binding varialble "bd" for attribute birthdate of call Person.

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZXur7DOR-1nFlMk%2Faction18.png?generation=1580825242032445\&alt=media) Notice that we test there is not already a calculated attribute for that person with the same key

Notice that we have to add to the list of calculated attribute of the person and then tell the rule engine the list was updated.

## Test the initial step

The workbench allows to test the rule we do. Create a new item of type "Test scenario" like follows :

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZXwoci_c9ao_cvT%2Faction02.png?generation=1580825237364942\&alt=media)

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZXywAB9GqdDwwyf%2Faction01.png?generation=1580825239235891\&alt=media)

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZY-MUqDlPgFq3h7%2Faction03.png?generation=1580825237981532\&alt=media)

Click on the "Given" Cross and add a new fact as follows :

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZY10ral9pGnN9-S%2Faction04.png?generation=1580825239615486\&alt=media)

Then click on the "Add Field" text.

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZY3P5ItA6e4INcg%2Faction05.png?generation=1580825237251194\&alt=media) Select the field "quoteDate" :

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZY56LDKciQU4nVG%2Faction06.png?generation=1580825242139713\&alt=media)

Click on the "Literal value" button

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZY7p2mdRAQcWOlw%2Faction07.png?generation=1580825236961883\&alt=media)

As the attribute is of type date, you can select a date with the date picker.

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZY9aXNEC1woGS5Y%2Faction08.png?generation=1580825240174535\&alt=media)

Select a date and then add another instance of type Person

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZYBxVKqKIBhaubA%2Faction10.png?generation=1580825243364797\&alt=media) and add a field and select birthdate. ![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZYD9gFQa8Ut9Ozs%2Faction11.png?generation=1580825236449280\&alt=media) Select literal value.

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZYFVUPDaj2CidWn%2Faction12.png?generation=1580825240806491\&alt=media)

And select a date as for the quote date but on same day (here June 30th? ![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZYHpKJ3Q6woRhsn%2Faction13.png?generation=1580825240563499\&alt=media) then add a expectatation by clicking on the Cross near Expect ![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZYJJywZeMSHDGo9%2Faction14.png?generation=1580825235991743\&alt=media)

Add a fact of type CalculatedAttribute

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZYLYz-EHS4I9aiA%2Faction16bis.png?generation=1580825241588407\&alt=media)

and Click on the "A fact of type... " Then chose the StringValue field

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZYNpIHpLb7X8en1%2Faction15.png?generation=1580825236572256\&alt=media)

And then enter the value true

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZYPxBDVNeWvdqYB%2Faction16ter.png?generation=1580825241210182\&alt=media)

And as the rule we want to test is in ruleflow group init. Click on the cross near the "Given" cross and enter "init" in the activate rule flow group part.

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZYR1HW-mWtGu3GA%2Faction16.png?generation=1580825238960058\&alt=media)

The test scenario should then look like this :

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZYTlMdGCcO0Ixvz%2Faction17.png?generation=1580825242687524\&alt=media) Then click the "Run scenario" button twice and you should see the screeen as follows ![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZYVNNnc7Uxy9516%2Faction18.png?generation=1580825238813330\&alt=media)

## Calculate person age

We shall calculate the person age based on his birthday and the curDay attribute of the quote. At the same time, we shall initialize the price attribute with a BigDecimal. in the function.drl, add the "import java.math.BigDecimal"

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZYXlu0uPK-zAjWn%2Faction03.png?generation=1580825239767924\&alt=media) First add the two classes on which we shall apply the rule. ![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZYZkF9x0HPeKOPR%2Faction01.png?generation=1580825239994164\&alt=media) Then we should create the rule like that.

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZYaAnAzESX8oHEB%2Faction04.png?generation=1580825243101420\&alt=media)

We added two options : the ruleflow group.

Then we can create a test scenario to verify our rule.

![](https://2162667257-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-FWW6zn6BoLbrPp_j8%2F-M-FWXeF2rB74vmY-cqZ%2F-M-FWZYc5NW0ZGxxn_C-%2Faction05.png?generation=1580825243178224\&alt=media)
