Drools5 Community Training HandsOn 1 Drools DRL Syntax

Mauricio (Salaboy) Salatino
Mauricio (Salaboy) SalatinoPrincipal Software Engineer at LearnK8s
 
                               
Drools5 Community Training
Hands On Playing with Rules
      Sponsored by Plugtree
Hands On 1: Drools Expert
   Playing with Rules
   Drools5 Community Training
      version: 1.0-SNAPSHOT
     Release Date: 09/05/2011
Under The Creative Common License
Hands On 1: Drools Expert
   Playing with Rules
 Drools5 Community Training Course
  by Mauricio "Salaboy" Salatino and
  Esteban Aliverti is licensed under a
  Creative Commons Attribution 3.0
            Unported License.
Based on a work at salaboy.wordpress.
                  com.
 Permissions beyond the scope of this
   license may be available at http:
       //salaboy.wordpress.com/.
Overview

● Drools Expert Examples
   ○ Introduction examples
   ○ Conditional elements examples
   ○ Rules Attributes examples
Introduction Examples

● Project: drools5/01-DroolsExpert-Introduction
● Test: SimpleRulesExampleTest.java
● Rules: src/main/resources/rules/rules.drl
● Kbuilder, Kbase and Ksession (createKSession() method)
   ○ Take a look at the addEventListener() method
● DRL syntax in the rule file:
   ○ Take a look at the LHS
   ○ Take a look at the RHS
● Rules activation and execution (you can activate the logger)
Introduction Examples

● Exercise
   ○ Find a way to get "Warn when we have a POP songs and
     Playlist" Rule activated but not fired.
   ○ Find a way to get "Warn when we have a POP songs and
     Playlist" Rule activated and fired.
Conditional Elements examples
● Project: drools5/02-DroolsExpert-ConditionalElements
● Simple Rules Example:
   ○ Test Class: SimpleRulesExampleTest.java
   ○ Rules: SimpleRules.drl
   ○ Conditional Elements on LHS
   ○ from Conditional Element
● Advanced from Examples:
   ○ Test Class: AdvancedFromRulesExampleTest.java
   ○ Rules: AdvancedFromRules.drl
   ○ collect, accumulate, accumulate custom function, Using
     Hibernate session in from CE
Conditional Elements Examples

● Exercise 1
   ○ Replace "Add Playlists that contains songs with letter 'a'
     in their titles to the list using the accumulate conditional
     elements defining init, action, reverse and result functions.
     i.e:
             from accumulate(
     $s: Song() from $songs,
     init(),
     action(),
     reverse(),
     result()
 )
Conditional Elements examples

Solution:
rule "Playlists that contains songs with letter 'a' in their titles."
when
        $playlist: Playlist($songs: songs)
        $match: java.util.List(empty == false) from accumulate(
           $s: Song() from $songs,
           init( java.util.List result = new java.util.ArrayList();),
           action( if ($s.getTitle().contains("a")) result.add($s); ),
           result( result )
        )
then
        System.out.println("Playlist found: "+$playlist);
        for (int i=0; i<$match.size(); i++){
           System.out.println("t--"+$match.get(i));
        }
end
Conditional Elements examples

● Exercise 2
   ○ Create a custom accumulate function to collect random
     songs from a playlist.
   ○ Copy the SongsWithALetterOnTheirTitlesFunction.java implementation
Conditional Elements Examples

● eval Example:
    ○ Test Class: EvalRulesExampleTest.java
    ○ Rules: /rules/EvalRules.drl
    ○ use of eval in LHS

● exists Example:
    ○ Test Class: ExistsRulesExampleTest.java
    ○ Rules: ExistsRules.drl
    ○ use of exists and not in the LHS
Conditional Elements Examples

● Exercise
   ○ Replace "Warn when we have a Playlist longer than 9000
     seconds" with an equivalent Rule without using eval
Conditional Elements Examples

Solution
rule "Playlist longer than 9000 seconds without eval"
when
$playlist: Playlist($songs: songs) AND
       $n : Number(intValue > 9000) from accumulate(
             $s : Song() from $songs,
             sum($s.getDuration()))
then
System.out.println("We have found a Playlist
                     longer than 9000 seconds");
end
Rule Attributes examples

● Project: drools/03-DroolsExpert-RulesAttributes
● Test Class: RuleAttributesExampleTest.java
● Attributes:
   ○ salience
   ○ no-loop:
       ■ Test: noLoop() Rules: /rules/NoLoopRules.drl
   ○ lock-on-active:
       ■ Test: lockOnActive() Rules: /rules/LockOnActiveRules.drl
   ○ agenda-group:
       ■ Test: agendaGroup() Rules: /rules/AgendaGroupRules.drl
 
              
Questions?
Enjoy! Questions and Feedback are
always appreciated!
 
                     
    Contact us at
www.plugtree.com
1 of 17

Recommended

Drools5 Community Training Module 3 Drools Expert DRL Syntax by
Drools5 Community Training Module 3 Drools Expert DRL SyntaxDrools5 Community Training Module 3 Drools Expert DRL Syntax
Drools5 Community Training Module 3 Drools Expert DRL SyntaxMauricio (Salaboy) Salatino
3.9K views39 slides
Scala - den smarta kusinen by
Scala - den smarta kusinenScala - den smarta kusinen
Scala - den smarta kusinenRedpill Linpro
306 views89 slides
Invertible-syntax 入門 by
Invertible-syntax 入門Invertible-syntax 入門
Invertible-syntax 入門Hiromi Ishii
2.3K views101 slides
Solr @ Etsy - Apache Lucene Eurocon by
Solr @ Etsy - Apache Lucene EuroconSolr @ Etsy - Apache Lucene Eurocon
Solr @ Etsy - Apache Lucene EuroconGiovanni Fernandez-Kincade
1.6K views56 slides
Xlab #1: Advantages of functional programming in Java 8 by
Xlab #1: Advantages of functional programming in Java 8Xlab #1: Advantages of functional programming in Java 8
Xlab #1: Advantages of functional programming in Java 8XSolve
708 views64 slides
Scala by
ScalaScala
Scalasuraj_atreya
778 views21 slides

More Related Content

What's hot

Electrify your code with PHP Generators by
Electrify your code with PHP GeneratorsElectrify your code with PHP Generators
Electrify your code with PHP GeneratorsMark Baker
3.7K views49 slides
Looping the Loop with SPL Iterators by
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsMark Baker
240 views142 slides
はじめてのGroovy by
はじめてのGroovyはじめてのGroovy
はじめてのGroovyTsuyoshi Yamamoto
690 views31 slides
Miracle of std lib by
Miracle of std libMiracle of std lib
Miracle of std libJedsada Tiwongvokul
489 views22 slides
Crazy things done on PHP by
Crazy things done on PHPCrazy things done on PHP
Crazy things done on PHPTaras Kalapun
14K views33 slides

What's hot(20)

Electrify your code with PHP Generators by Mark Baker
Electrify your code with PHP GeneratorsElectrify your code with PHP Generators
Electrify your code with PHP Generators
Mark Baker3.7K views
Looping the Loop with SPL Iterators by Mark Baker
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL Iterators
Mark Baker240 views
Crazy things done on PHP by Taras Kalapun
Crazy things done on PHPCrazy things done on PHP
Crazy things done on PHP
Taras Kalapun14K views
Teaching Your Machine To Find Fraudsters by Ian Barber
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
Ian Barber1.5K views
Debugging: Rules And Tools - PHPTek 11 Version by Ian Barber
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 Version
Ian Barber1.5K views
Php 102: Out with the Bad, In with the Good by Jeremy Kendall
Php 102: Out with the Bad, In with the GoodPhp 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the Good
Jeremy Kendall3.4K views
Leveraging the Power of Graph Databases in PHP by Jeremy Kendall
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
Jeremy Kendall890 views
Clojure: Practical functional approach on JVM by sunng87
Clojure: Practical functional approach on JVMClojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVM
sunng871.7K views
Leveraging the Power of Graph Databases in PHP by Jeremy Kendall
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
Jeremy Kendall1.1K views
PrettyDump Perl 6 (London.pm) by brian d foy
PrettyDump Perl 6 (London.pm)PrettyDump Perl 6 (London.pm)
PrettyDump Perl 6 (London.pm)
brian d foy5.3K views
Things I Believe Now That I'm Old by Ross Tuck
Things I Believe Now That I'm OldThings I Believe Now That I'm Old
Things I Believe Now That I'm Old
Ross Tuck6.6K views
Backbone.js: Run your Application Inside The Browser by Howard Lewis Ship
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
Howard Lewis Ship2.7K views
JavaScript Classes and Inheritance by marcheiligers
JavaScript Classes and InheritanceJavaScript Classes and Inheritance
JavaScript Classes and Inheritance
marcheiligers1.6K views
Intro to Advanced JavaScript by ryanstout
Intro to Advanced JavaScriptIntro to Advanced JavaScript
Intro to Advanced JavaScript
ryanstout599 views

Similar to Drools5 Community Training HandsOn 1 Drools DRL Syntax

The Ring programming language version 1.5.4 book - Part 78 of 185 by
The Ring programming language version 1.5.4 book - Part 78 of 185The Ring programming language version 1.5.4 book - Part 78 of 185
The Ring programming language version 1.5.4 book - Part 78 of 185Mahmoud Samir Fayed
9 views10 slides
Performance Tuning and Optimization by
Performance Tuning and OptimizationPerformance Tuning and Optimization
Performance Tuning and OptimizationMongoDB
3.9K views31 slides
The Ring programming language version 1.10 book - Part 17 of 212 by
The Ring programming language version 1.10 book - Part 17 of 212The Ring programming language version 1.10 book - Part 17 of 212
The Ring programming language version 1.10 book - Part 17 of 212Mahmoud Samir Fayed
17 views10 slides
Lecture 4 - Object Interaction and Collections by
Lecture 4 - Object Interaction and CollectionsLecture 4 - Object Interaction and Collections
Lecture 4 - Object Interaction and CollectionsSyed Afaq Shah MACS CP
267 views34 slides
The Ring programming language version 1.5.4 book - Part 74 of 185 by
The Ring programming language version 1.5.4 book - Part 74 of 185The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185Mahmoud Samir Fayed
7 views10 slides
Searching for AI - Leveraging Solr for classic Artificial Intelligence tasks by
Searching for AI - Leveraging Solr for classic Artificial Intelligence tasksSearching for AI - Leveraging Solr for classic Artificial Intelligence tasks
Searching for AI - Leveraging Solr for classic Artificial Intelligence tasksAlexandre Rafalovitch
1.9K views30 slides

Similar to Drools5 Community Training HandsOn 1 Drools DRL Syntax(20)

The Ring programming language version 1.5.4 book - Part 78 of 185 by Mahmoud Samir Fayed
The Ring programming language version 1.5.4 book - Part 78 of 185The Ring programming language version 1.5.4 book - Part 78 of 185
The Ring programming language version 1.5.4 book - Part 78 of 185
Performance Tuning and Optimization by MongoDB
Performance Tuning and OptimizationPerformance Tuning and Optimization
Performance Tuning and Optimization
MongoDB3.9K views
The Ring programming language version 1.10 book - Part 17 of 212 by Mahmoud Samir Fayed
The Ring programming language version 1.10 book - Part 17 of 212The Ring programming language version 1.10 book - Part 17 of 212
The Ring programming language version 1.10 book - Part 17 of 212
The Ring programming language version 1.5.4 book - Part 74 of 185 by Mahmoud Samir Fayed
The Ring programming language version 1.5.4 book - Part 74 of 185The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185
Searching for AI - Leveraging Solr for classic Artificial Intelligence tasks by Alexandre Rafalovitch
Searching for AI - Leveraging Solr for classic Artificial Intelligence tasksSearching for AI - Leveraging Solr for classic Artificial Intelligence tasks
Searching for AI - Leveraging Solr for classic Artificial Intelligence tasks
The Ring programming language version 1.5.4 book - Part 79 of 185 by Mahmoud Samir Fayed
The Ring programming language version 1.5.4 book - Part 79 of 185The Ring programming language version 1.5.4 book - Part 79 of 185
The Ring programming language version 1.5.4 book - Part 79 of 185
Java 2 chapter 10 - basic oop in java by let's go to study
Java 2   chapter 10 - basic oop in javaJava 2   chapter 10 - basic oop in java
Java 2 chapter 10 - basic oop in java
let's go to study1.2K views
The Ring programming language version 1.6 book - Part 42 of 189 by Mahmoud Samir Fayed
The Ring programming language version 1.6 book - Part 42 of 189The Ring programming language version 1.6 book - Part 42 of 189
The Ring programming language version 1.6 book - Part 42 of 189
The Ring programming language version 1.6 book - Part 76 of 189 by Mahmoud Samir Fayed
The Ring programming language version 1.6 book - Part 76 of 189The Ring programming language version 1.6 book - Part 76 of 189
The Ring programming language version 1.6 book - Part 76 of 189
The Ring programming language version 1.10 book - Part 93 of 212 by Mahmoud Samir Fayed
The Ring programming language version 1.10 book - Part 93 of 212The Ring programming language version 1.10 book - Part 93 of 212
The Ring programming language version 1.10 book - Part 93 of 212
New features in jdk8 iti by Ahmed mar3y
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 iti
Ahmed mar3y79 views
Introducing Command Line Applications with Ruby by Nikhil Mungel
Introducing Command Line Applications with RubyIntroducing Command Line Applications with Ruby
Introducing Command Line Applications with Ruby
Nikhil Mungel2.9K views
2nd Proj. Update: Integrating SWI-Prolog for Semantic Reasoning in Bioclipse by Samuel Lampa
2nd Proj. Update: Integrating SWI-Prolog for Semantic Reasoning in Bioclipse2nd Proj. Update: Integrating SWI-Prolog for Semantic Reasoning in Bioclipse
2nd Proj. Update: Integrating SWI-Prolog for Semantic Reasoning in Bioclipse
Samuel Lampa828 views
Rails 3 generators by joshsmoore
Rails 3 generatorsRails 3 generators
Rails 3 generators
joshsmoore2.3K views

More from Mauricio (Salaboy) Salatino

Devoxx UK - Platforms on top of K8s by
Devoxx UK - Platforms on top of K8sDevoxx UK - Platforms on top of K8s
Devoxx UK - Platforms on top of K8sMauricio (Salaboy) Salatino
222 views39 slides
WTF_is_SRE_DeveloperEnabledPlatforms.pdf by
WTF_is_SRE_DeveloperEnabledPlatforms.pdfWTF_is_SRE_DeveloperEnabledPlatforms.pdf
WTF_is_SRE_DeveloperEnabledPlatforms.pdfMauricio (Salaboy) Salatino
124 views29 slides
Lessons Learnt from creating platforms on Kubernetes @ Rejekts by
Lessons Learnt from creating platforms on Kubernetes @ RejektsLessons Learnt from creating platforms on Kubernetes @ Rejekts
Lessons Learnt from creating platforms on Kubernetes @ RejektsMauricio (Salaboy) Salatino
31 views53 slides
Building Developer Experiences for the Cloud .pdf by
Building Developer Experiences for the Cloud .pdfBuilding Developer Experiences for the Cloud .pdf
Building Developer Experiences for the Cloud .pdfMauricio (Salaboy) Salatino
38 views28 slides
The Challenges of building Cloud Native Platforms by
The Challenges of building Cloud Native PlatformsThe Challenges of building Cloud Native Platforms
The Challenges of building Cloud Native PlatformsMauricio (Salaboy) Salatino
701 views31 slides
Functions Working Group Update - August 2022.pdf by
Functions Working Group Update - August 2022.pdfFunctions Working Group Update - August 2022.pdf
Functions Working Group Update - August 2022.pdfMauricio (Salaboy) Salatino
70 views8 slides

More from Mauricio (Salaboy) Salatino(20)

KubeCon NA - 2021 Tools That I Wish Existed 3 Years Ago To Build a SaaS Offering by Mauricio (Salaboy) Salatino
KubeCon NA - 2021 Tools That I Wish Existed 3 Years Ago To Build a SaaS OfferingKubeCon NA - 2021 Tools That I Wish Existed 3 Years Ago To Build a SaaS Offering
KubeCon NA - 2021 Tools That I Wish Existed 3 Years Ago To Build a SaaS Offering

Recently uploaded

LLMs in Production: Tooling, Process, and Team Structure by
LLMs in Production: Tooling, Process, and Team StructureLLMs in Production: Tooling, Process, and Team Structure
LLMs in Production: Tooling, Process, and Team StructureAggregage
57 views77 slides
"Node.js Development in 2024: trends and tools", Nikita Galkin by
"Node.js Development in 2024: trends and tools", Nikita Galkin "Node.js Development in 2024: trends and tools", Nikita Galkin
"Node.js Development in 2024: trends and tools", Nikita Galkin Fwdays
33 views38 slides
State of the Union - Rohit Yadav - Apache CloudStack by
State of the Union - Rohit Yadav - Apache CloudStackState of the Union - Rohit Yadav - Apache CloudStack
State of the Union - Rohit Yadav - Apache CloudStackShapeBlue
303 views53 slides
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue by
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueWhat’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueShapeBlue
265 views23 slides
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlueShapeBlue
152 views23 slides
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And... by
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...ShapeBlue
108 views12 slides

Recently uploaded(20)

LLMs in Production: Tooling, Process, and Team Structure by Aggregage
LLMs in Production: Tooling, Process, and Team StructureLLMs in Production: Tooling, Process, and Team Structure
LLMs in Production: Tooling, Process, and Team Structure
Aggregage57 views
"Node.js Development in 2024: trends and tools", Nikita Galkin by Fwdays
"Node.js Development in 2024: trends and tools", Nikita Galkin "Node.js Development in 2024: trends and tools", Nikita Galkin
"Node.js Development in 2024: trends and tools", Nikita Galkin
Fwdays33 views
State of the Union - Rohit Yadav - Apache CloudStack by ShapeBlue
State of the Union - Rohit Yadav - Apache CloudStackState of the Union - Rohit Yadav - Apache CloudStack
State of the Union - Rohit Yadav - Apache CloudStack
ShapeBlue303 views
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue by ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueWhat’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
ShapeBlue265 views
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
ShapeBlue152 views
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And... by ShapeBlue
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
ShapeBlue108 views
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online by ShapeBlue
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineKVM Security Groups Under the Hood - Wido den Hollander - Your.Online
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online
ShapeBlue225 views
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue by ShapeBlue
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlueVNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue
ShapeBlue207 views
Digital Personal Data Protection (DPDP) Practical Approach For CISOs by Priyanka Aash
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOs
Priyanka Aash162 views
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... by ShapeBlue
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
ShapeBlue183 views
The Power of Generative AI in Accelerating No Code Adoption.pdf by Saeed Al Dhaheri
The Power of Generative AI in Accelerating No Code Adoption.pdfThe Power of Generative AI in Accelerating No Code Adoption.pdf
The Power of Generative AI in Accelerating No Code Adoption.pdf
Saeed Al Dhaheri39 views
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading... by The Digital Insurer
Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading...
The Role of Patterns in the Era of Large Language Models by Yunyao Li
The Role of Patterns in the Era of Large Language ModelsThe Role of Patterns in the Era of Large Language Models
The Role of Patterns in the Era of Large Language Models
Yunyao Li91 views
NTGapps NTG LowCode Platform by Mustafa Kuğu
NTGapps NTG LowCode Platform NTGapps NTG LowCode Platform
NTGapps NTG LowCode Platform
Mustafa Kuğu437 views
Transcript: Redefining the book supply chain: A glimpse into the future - Tec... by BookNet Canada
Transcript: Redefining the book supply chain: A glimpse into the future - Tec...Transcript: Redefining the book supply chain: A glimpse into the future - Tec...
Transcript: Redefining the book supply chain: A glimpse into the future - Tec...
BookNet Canada41 views
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023 by BookNet Canada
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023Redefining the book supply chain: A glimpse into the future - Tech Forum 2023
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023
BookNet Canada44 views
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
ShapeBlue139 views
Business Analyst Series 2023 - Week 4 Session 8 by DianaGray10
Business Analyst Series 2023 -  Week 4 Session 8Business Analyst Series 2023 -  Week 4 Session 8
Business Analyst Series 2023 - Week 4 Session 8
DianaGray10145 views
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by ShapeBlue
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
ShapeBlue196 views
Why and How CloudStack at weSystems - Stephan Bienek - weSystems by ShapeBlue
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsWhy and How CloudStack at weSystems - Stephan Bienek - weSystems
Why and How CloudStack at weSystems - Stephan Bienek - weSystems
ShapeBlue247 views

Drools5 Community Training HandsOn 1 Drools DRL Syntax

  • 1.     Drools5 Community Training Hands On Playing with Rules Sponsored by Plugtree
  • 2. Hands On 1: Drools Expert Playing with Rules Drools5 Community Training version: 1.0-SNAPSHOT Release Date: 09/05/2011 Under The Creative Common License
  • 3. Hands On 1: Drools Expert Playing with Rules Drools5 Community Training Course by Mauricio "Salaboy" Salatino and Esteban Aliverti is licensed under a Creative Commons Attribution 3.0 Unported License. Based on a work at salaboy.wordpress. com. Permissions beyond the scope of this license may be available at http: //salaboy.wordpress.com/.
  • 4. Overview ● Drools Expert Examples ○ Introduction examples ○ Conditional elements examples ○ Rules Attributes examples
  • 5. Introduction Examples ● Project: drools5/01-DroolsExpert-Introduction ● Test: SimpleRulesExampleTest.java ● Rules: src/main/resources/rules/rules.drl ● Kbuilder, Kbase and Ksession (createKSession() method) ○ Take a look at the addEventListener() method ● DRL syntax in the rule file: ○ Take a look at the LHS ○ Take a look at the RHS ● Rules activation and execution (you can activate the logger)
  • 6. Introduction Examples ● Exercise ○ Find a way to get "Warn when we have a POP songs and Playlist" Rule activated but not fired. ○ Find a way to get "Warn when we have a POP songs and Playlist" Rule activated and fired.
  • 7. Conditional Elements examples ● Project: drools5/02-DroolsExpert-ConditionalElements ● Simple Rules Example: ○ Test Class: SimpleRulesExampleTest.java ○ Rules: SimpleRules.drl ○ Conditional Elements on LHS ○ from Conditional Element ● Advanced from Examples: ○ Test Class: AdvancedFromRulesExampleTest.java ○ Rules: AdvancedFromRules.drl ○ collect, accumulate, accumulate custom function, Using Hibernate session in from CE
  • 8. Conditional Elements Examples ● Exercise 1 ○ Replace "Add Playlists that contains songs with letter 'a' in their titles to the list using the accumulate conditional elements defining init, action, reverse and result functions. i.e: from accumulate( $s: Song() from $songs, init(), action(), reverse(), result() )
  • 9. Conditional Elements examples Solution: rule "Playlists that contains songs with letter 'a' in their titles." when $playlist: Playlist($songs: songs) $match: java.util.List(empty == false) from accumulate( $s: Song() from $songs, init( java.util.List result = new java.util.ArrayList();), action( if ($s.getTitle().contains("a")) result.add($s); ), result( result ) ) then System.out.println("Playlist found: "+$playlist); for (int i=0; i<$match.size(); i++){ System.out.println("t--"+$match.get(i)); } end
  • 10. Conditional Elements examples ● Exercise 2 ○ Create a custom accumulate function to collect random songs from a playlist. ○ Copy the SongsWithALetterOnTheirTitlesFunction.java implementation
  • 11. Conditional Elements Examples ● eval Example: ○ Test Class: EvalRulesExampleTest.java ○ Rules: /rules/EvalRules.drl ○ use of eval in LHS ● exists Example: ○ Test Class: ExistsRulesExampleTest.java ○ Rules: ExistsRules.drl ○ use of exists and not in the LHS
  • 12. Conditional Elements Examples ● Exercise ○ Replace "Warn when we have a Playlist longer than 9000 seconds" with an equivalent Rule without using eval
  • 13. Conditional Elements Examples Solution rule "Playlist longer than 9000 seconds without eval" when $playlist: Playlist($songs: songs) AND $n : Number(intValue > 9000) from accumulate( $s : Song() from $songs, sum($s.getDuration())) then System.out.println("We have found a Playlist longer than 9000 seconds"); end
  • 14. Rule Attributes examples ● Project: drools/03-DroolsExpert-RulesAttributes ● Test Class: RuleAttributesExampleTest.java ● Attributes: ○ salience ○ no-loop: ■ Test: noLoop() Rules: /rules/NoLoopRules.drl ○ lock-on-active: ■ Test: lockOnActive() Rules: /rules/LockOnActiveRules.drl ○ agenda-group: ■ Test: agendaGroup() Rules: /rules/AgendaGroupRules.drl
  • 15.     Questions?
  • 16. Enjoy! Questions and Feedback are always appreciated!
  • 17.     Contact us at www.plugtree.com