Skip to content
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# Intended audience
This book as its title suggest is for newcomers to drools. As explained in the drools tutorial, when using drools you will change the classical development paradigm you are using going from procedurale to declarative programming. The shift is not complex to accomplish but there is a need for a onboarding set of tutorials that will help you to jump into implementing algorith/business rules wiht drools with no difficulty.
As a regular trainer of drools, I can only encourage you to do the exercices completely by yourself and try not to go the solutions directly.
This book, as its title suggests, is for newcomers to drools. As explained in the drools tutorial, when using drools you will change the classical development paradigm you are using, going from procedural to declarative programming. The shift is not complex to accomplish, but there is a need for an onboarding set of tutorials that will help you to jump into implementing algorithm/business rules with drools with no difficulty.
As a regular trainer of drools, I can only encourage you to do the exercises completely by yourself and try not to go the solutions directly.
By doing so, the learning curve will be a little longer but so much easier at the end. By going directly to the solution, you will miss 50% of the training content.

# drools On Boarding

You can find here all the materials that goes with this book.
You can find here all the materials that go with this book.
The book is also on github [ here ](https://github.com/nheron/droolsonboarding).

Here is the [content](SUMMARY.md) of the book
Here is the [content](SUMMARY.md) of the book.

## How to edit the docs

* go to [Drools Onboarding book](https://www.gitbook.com/book/nheron/droolsonboarding/details)
* There you can clone and edit the document
* You can do it from github also
* Go to [Drools Onboarding book](https://www.gitbook.com/book/nheron/droolsonboarding/details).
* There you can clone and edit the document.
* You can do it from [github](https://github.com/nheron/droolsonboarding) also.

## How to run the tutorial and examples

* the source code for the tutorials and examples can be found on [github](https://github.com/nheron/droolscourse)
* there is a virtual box appliance available with all included that you can find here \(TODO\)
* The source code for the tutorials and examples can be found on [github](https://github.com/nheron/droolscourse).
* There is a virtual box appliance available with all included that you can find here. \(TODO\)

58 changes: 29 additions & 29 deletions gettingStarted/data_model_used_in_the_tutorial.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Data Model used in the tutorial

We are first going to write java code that we are going to use through all the drooks tutorial.
Here is the model we are going to use \(taken from presentation done during conferences by drools members\)
We are first going to write Java code that we are going to use through all the drools tutorial.
Here is the model we are going to use \(taken from presentations done during conferences by drools members\).
We are in a bank that handles accounts \(2\) and on each account there can be movements \(1\). The purpose is to calculate the account balance between an accounting period \(3\) of all accounts given the movements it has.
We will run all examples in junit Tests.
This data model is the same as you can find in the reference model in the drools documentation.
![](drools/dataModel_fig1.jpeg)

## Implement the pojo model

We have to create an AccountProject of type drools as previously describes.
Then we shall create a java package that we can name droolscours package in src/main/java \(to respect maven definition\) by doing on src/main/java right click and new Package, gibe him a name and push the finish button.
We have to create an AccountProject of type drools as previously described.
Then we shall create a java package that we can name droolscourse package in src/main/java \(to respect maven definition\) by doing on src/main/java a right click and New Package, give it a name and push the Finish button.

![](drools/dataModel_fig2.jpeg)

and we are going to create 3 java classes : Account, AccountingPeriod and CashFlow by right-clicking on the new package just created and new Class
And we are going to create 3 java classes: Account, AccountingPeriod and CashFlow by right-clicking on the new package just created and New Class.

![](drools/dataModel_fig3.jpeg)

Expand All @@ -31,7 +31,7 @@ and for CashFlow

![](drools/dataModel_fig7.png)

# Add JUnit library
## Add JUnit library

To be able to use junit, we have to add the junit library.
Select the project, right click and select BuildPath/Configure BuildPath
Expand All @@ -40,71 +40,71 @@ Select the project, right click and select BuildPath/Configure BuildPath

Click on the Libraries tab and select the "Add library" button.
![](drools/dataModel_fig9.png)
Select the Junit library and push the next button
Select the Junit library and push the Next button.

![](drools/dataModel_fig10.png)
On the next screen, push the Finish Button
On the next screen, push the Finish button
![](drools/dataModel_fig11.png)
and the the Ok button
and the the Ok button.

![](drools/dataModel_fig12.png)
The Junit libray is now part of the project
The Junit libray is now part of the project.
![](drools/dataModel_fig13.png)

We now have to create some directory.
Select the src directory and right click button new Directory.
We now have to create a directory.
Right click on the src directory and click New Directory.

![](drools/dataModel_fig14.png)
Enter test/java in the folder name and press finish.
Do the same but test/rules.
The folder part should look like that :
Enter test/java in the folder name and press Finish.
Do the same with test/rules.
The folder part should look like this:
![](drools/dataModel_fig15.png)

now Select src/test/java and right click buildpath/use as source folder
Now right click src/test/java and click Buildpath/Use as source folder.

![](drools/dataModel_fig16.png)

Do the same with src/test/rules
now the project should look like this :
Do the same with src/test/rules and
now the project should look like this:

![](drools/dataModel_fig17.png)

# Create a Helper Class
## Create a Helper Class

To simplify the writing of tests, we shall write a helper class.
To do, we first create a package called util and in there create a class that we shall all KnowledgeSessionHelper
To do this, we first create a package called util and in there create a class that we shall call KnowledgeSessionHelper .

![](drools/dataModel_fig18.png)

![](drools/dataModel_fig20.png)
Then create a new class called KnowledgeSessionHelper
Then create a new class called KnowledgeSessionHelper .

![](drools/dataModel_fig21.png)

![](drools/dataModel_fig22.png)
In the Class, the content should look like here
In the class, the content should look like here
![](drools/dataModel_fig23.png)

# Create the first test case
## Create the first test case

Select the src/test/java package and Right click Other and type junit. Select Junit Test case
Right click the src/test/java package, click Other and type junit. Select JUnit Test Case.

![](drools/dataModel_fig24.png)

Push the next Button.
In the next screen, enter droolscours as package name and FirstTry as Name
In the next screen, enter droolscourse as the package name and FirstTry as the Name.

![](drools/dataModel_fig25.png)

And push the Finish Button
And push the Finish Button.

the code should be entered like this :
The code should be entered like this :

![](drools/dataModel_fig26.png)
Select the open class, Right click and run as JUnit Test :
Select the open class, right click and run as JUnit Test :

![](drools/dataModel_fig27.png)
And the Junit Window should appear as above. \(of course no rules were fired\).
And the JUnit window should appear as above. \(of course no rules were fired\).

We are now ready to start the lessons.

8 changes: 4 additions & 4 deletions gettingStarted/drools.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
When working with drools, there are things you have to define :

1\) The data model on which the rules applies. As we are working in the java language, a data model is a set of java classes.
1\) The data model on which the rules apply. As we are working in the Java language, a data model is a set of Java classes.

2\) Rules which are going on one side \(called left side or LHS\) express constraints on the data model, which here class name and their attributes and on the other side \(called right side or RHS\) which will act on the facts which are in the working memory.
2\) Rules which are going on one side \(called left side or LHS\) express constraints on the data model, which are class name and their attributes and on the other side \(called right side or RHS\) which will act on the facts which are in the working memory.

When you want to apply some rules on some data, you will instantiate a java class and give it to the rule engine. This instance is called a Fact object.
When you want to apply some rules on some data, you will instantiate a Java class and give it to the rule engine. This instance is called a Fact object.

To work with the rule engine, we have to instantiate a KieContainer. We will see later how to program it. This kieContainer contains a set of rules. The KieContainer allows also to contain other types of artifacts are is common to other components like jbpm and optoplanner.
To work with the rule engine, we have to instantiate a KieContainer. We will see later how to program it. This KieContainer contains a set of rules. The KieContainer allows also to contain other types of artifacts that are common to other components like jbpm and optoplanner.

When you want to work with drools, you have to get a KieSession from the KieContainer. This KieSession will allow you to give facts to the rule engine and to ask to fire rules.

Loading