O'Reilly logo

Drools JBoss Rules 5.0 Developer's Guide by Michal Bali, Bogdan Brinzarea

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing transformation rules

Now that all of the objects are in the knowledge session, we can start writing some transformation rules. Let's imagine that in the legacy system, there are many duplicate addresses. We can write a rule that removes such duplication:

rule twoEqualAddressesDifferentInstance
   when
      $addressMap1 : Map( this["_type_"] == "Address" )
      $addressMap2 : Map( this["_type_"] == "Address", 
         eval( $addressMap1 != $addressMap2 ), 
         this == $addressMap1 )
   then
      retract( $addressMap2 );
      validationReport.addMessage(
         reportFactory.createMessage(Message.Type.WARNING, 
         kcontext.getRule().getName(), $addressMap2));
end

Code listing 5: Rule that removes redundant address (dataTransformation.drl file).

The rule matches two addresses. It checks that ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required