Hi Edison,
I tried your suggestion but I received an exception when I pass a null
value.
The exception is:
Exception in thread "main" java.lang.NullPointerException
at java.math.BigDecimal.compareTo(BigDecimal.java:2461)
at
org.drools.base.evaluators.BigDecimalFactory$BigDecimalLessEvaluator.evaluate(BigDecimalFactory.java:235)
at
org.drools.rule.VariableRestriction.isAllowed(VariableRestriction.java:73)
at
org.drools.rule.VariableConstraint.isAllowed(VariableConstraint.java:67)
at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:137)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:318)
at
org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:162)
at org.drools.reteoo.Rete.assertObject(Rete.java:175)
at
org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:192)
at
org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorkingMemory.java:71)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:911)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:883)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:684)
I attach some file to test this.
Thank you
Nicola
Edson Tirelli ha scritto:
>
> You syntax is wrong. Fixing your syntax is as easy as saying:
>
> exists ExamDetail( authLimit != null )
>
> But I think that your rules can be simplified by simply writing:
>
> rule "Rule n.1"
> dialect "mvel"
> no-loop true
> salience 10
> when
> $examDetail : ExamDetail( $value: value < authLimit);
> then
> System.out.println( "1 Exam passed!" + $value);
> end
>
> rule "Rule n.2"
> dialect "mvel"
> no-loop true
> salience 10
> when
> not ExamDetail( value < authLimit );
> then
> System.out.println( "2 Exam passed! + $value);
> end
>
>
> This should cover both of your scenarios.
import ExamDetail;
rule "Rule n.1"
dialect "mvel"
no-loop true
salience 20
when
exists ExamDetail( authLimit != null );
$examDetail : ExamDetail( $value: value < authLimit);
then
System.out.println( "Rule 1: exam PASSED!" + $value);
end
import java.io.InputStreamReader;
import java.math.BigDecimal;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.StatefulSession;
import org.drools.audit.WorkingMemoryFileLogger;
import org.drools.compiler.PackageBuilder;
public class ExamCheck {
public static final void main(String[] args) throws Exception {
final PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( new InputStreamReader( ExamCheck.class.getResourceAsStream( "check.drl" ) ) );
final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( builder.getPackage() );
final StatefulSession session = ruleBase.newStatefulSession();
ExamDetail examDetail = new ExamDetail();
examDetail.setValue(new BigDecimal(12));
examDetail.setAuthLimit(null);
session.insert( examDetail );
session.fireAllRules();
logger.writeToDisk();
session.dispose();
}
}
import java.math.BigDecimal;
public class ExamDetail {
private BigDecimal authLimit;
private BigDecimal value;
public BigDecimal getAuthLimit() {
return authLimit;
}
public void setAuthLimit(BigDecimal authLimit) {
this.authLimit = authLimit;
}
public BigDecimal getValue() {
return value;
}
public void setValue(BigDecimal value) {
this.value = value;
}
}
_______________________________________________
rules-users mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-users