Drools Filip notes

From Training Material
Jump to navigation Jump to search


Preparing jbpm installer

  • copy jbpm-installer.full.fresh to jbpm-installer

Adding German keyboard in Ubuntu

  • cogwheel -> System Settings -> Keybord layout -> Add

Adding clipboard sharing

KIE

No internet solution

Connection to the internet is required (downloading examples from git repository)

  • go to jbpm-installer folder
  • open build.xml in text editor
  • find kie.demo
  • change all values to false
<arg value="-Dorg.kie.demo=false" />
  • in a console type (remove GIT repository)
rm .niogit/ -R -f
  • start demo again

Important java command :)

killall java

Ex1

http://training-course-material.com/training/Drools_Kie_-_Example

Eclipse

Frist Rule

package np01stateless
import com.nobleprog.Applicant;
rule "Is of valid age"
when
  $a : Applicant( age < 18 )
then
  $a.setValid( false );
end
when
 $a : Applicant( age < 18 )

2 conditions:

  • there is an Applicant
  • whose age is < 18

We don't need to use '$'

Shopping Cart Exercise

Show TDD

  • Create test first (modify previous example)
ShoppingCart sc = new ShoppingCart(12000.00);
 assertFalse( sc.getDiscount() == 0.1);
 kSession.execute( sc );
 assertTrue( sc.getDiscount() == 0.1);
  • Add Java class
    • Generate setters/getters

If you want to test more ShoppingCart objects you can:

  • execute the rule twice or more
  • use some kind of structure - list to pass objects
  • create another test method

Modify totalPrice

  • truth maintenance

How to avoid it:

  • no-loop attribute (between rule and when)
  • create flag (another field in the Class) e.g. discountApplied=true/false