---
# System prepended metadata

title: Master Drools - Turn Complex Logic into Simple to Read Rules
tags: [Drools]

---

---
tags: Drools
---


# Master Drools - Turn Complex Logic into Simple to Read Rules

## Section 5: 5. Cross Products - Drools Version of SQL


I cloned the project presented to follow the course and when I executed Step 1 from Section 5, the results were different from the one shown in the lesson: Visa Applications with id 1 and 2 are verified and received FAILED as Validation, but they are re-checked and considered PASSED (as shown in the green square), even being in a stateful session.

## Local output vs. Lesson output

**Local output**
![](https://i.imgur.com/U3HHbOL.png)

**Lesson output** 
![](https://i.imgur.com/apNNYF8.png)
![](https://i.imgur.com/Aw0XhDN.png)
![](https://i.imgur.com/ffGFvkl.png)

### Environment setup

Operating System: Ubuntu 20.04.3 LTS
JVM: 16.0.2+7-67
JDK: "11.0.10" 2021-01-19
Drools: 7.58.0.Final

### Code I ran vs. Lesson code

Both source code looks the same to me.

#### VisaAppliationValidation.drl

Mine: https://github.com/aasaru/drools-training/blob/master/src/main/resources/io/github/aasaru/drools/section05/step1/VisaApplicationValidation.drl


From lesson: 
![](https://i.imgur.com/jsxveFF.png)

<!--
```java=
package io.github.aasaru.drools.section05.step1

import io.github.aasaru.drools.domain.Passport;
import io.github.aasaru.drools.domain.Validation;
import io.github.aasaru.drools.domain.VisaApplication;

import java.time.LocalDate;

rule "Invalidate visa application with invalid passport"
  dialect "mvel"
  when
    $passport: Passport( validation == Validation.FAILED )
    $visaApplication: VisaApplication( passportNumber == $passport.passportNumber )
  then
    System.out.println( "Set " + $visaApplication + " invalid as " + $passport + " hasn't passed validation");
    modify($visaApplication) {
      setValidation( Validation.FAILED )
    }
end

rule "Set application without validation info as passed"
  dialect "mvel"
  when
    $visaApplication: VisaApplication( validation == Validation.UNKNOWN )
  then
    System.out.println( $visaApplication + " is without validation info, consider OK for now" );
    modify($visaApplication) {
      setValidation( Validation.PASSED )
    }
end
```
-->

#### PassportValidation.drl

mine: https://github.com/aasaru/drools-training/blob/master/src/main/resources/io/github/aasaru/drools/section05/step1/PassportValidation.drl

From lesson:
![](https://i.imgur.com/5slRJ5w.png)

<!--
```java=
package io.github.aasaru.drools.section05.step1
 
import io.github.aasaru.drools.domain.Passport;
import io.github.aasaru.drools.domain.Validation;
import java.time.LocalDate;

rule "Expired passport"
	dialect "mvel"
	when
		$passport: Passport( isExpired()  )
	then
		System.out.println( $passport + " is INVALID because it is expired" );
		modify($passport) {
		  setValidation( Validation.FAILED ),
		  setCause( "passport is expired" )
		}
end

rule "Full passport"
	dialect "mvel"
	when
		$passport: Passport( unusedVisaPages == 0   )
	then
		System.out.println( $passport + " is INVALID because it has no space for visa" );
		modify($passport) {
		  setValidation( Validation.FAILED ),
		  setCause( "passport has no space for visa" )
		}
end

rule "Valid passport"
	dialect "mvel"
	when
		$passport: Passport( validation == Validation.UNKNOWN )
	then
		System.out.println( $passport + " is without validation info, consider CORRECT for now" );
		modify($passport) {
		  setValidation( Validation.PASSED )
		}
end
```
-->

![](https://i.imgur.com/y3IDnU7.png)


## VisaApplicationValidation.java

mine: https://github.com/aasaru/drools-training/blob/master/src/main/java/io/github/aasaru/drools/section05/VisaApplicationValidation.java

from lesson: ![](https://i.imgur.com/vWBImmE.png)

