Hi Thomas,
Just wanted to let you know that the eval soution finally worked. I create a
'containsCode' method on my Line bean and then used that to see if the Line
contained a given code. Then finally used 'eval' to check if the 'code'
exists from within a decision table.
Got what I needed.
Thanks for the solution.
Gurvinder
Swindells, Thomas wrote:
Hi Gurvinder.
Not sure where new lines have gone from your email - it makes it very hard
to read!
I've also been working on a project which uses decision tables and I
couldn't find any way to use from statements either. I'm hoping to get
some time within the project to work on the drools decision table code to
add some improvements, providing support for the from clause is one of
these however I'm not sure whether I will get time or not.
However I think you may be able to restructure your code so that you don't
need the from cause however I've not fully tested it. The code relies on
their existing a constructor which takes the promotion code and the equals
is defined that P1.equals(P2) when P1.code.equals(P2.code).
If you wanted to match that a promotion of a particular name exists then I
think you can use the rule
Rule "existsPromotion" when
Line(promos contains (new Promotion("HOTBUY"))) then ...
However the expression language doesn't support "not contains" which means
you have to full back to use java:
rule " contains d"
when
line : Line(eval(!line.getPromos().contains(new
Promotion("HOTBUY"))))
then
...
end
If you prefer you could also define a method on Line
containsPromotionWithCode(code) which would let you choose how to do the
match.
As a spreadsheet the above would then look something like the following:
RuleTable Hotbuys
NAME
CONDITION
ACTION
l :Line
eval(!l.getPromos().contains(new Promotion("$param")))
System.out.println("$param");
Rule Name
Number Directors
Warning
example1
Hotbuys
Hotbuys missing
Hope that helps,
Thomas
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of groovenarula
Sent: 03 December 2009 06:51
To: rules-users(a)lists.jboss.org
Subject: [rules-users] Can we use 'from' CE in Decision Tables ?
Hello all, Is it possible to define the follow rule in a decision table :
rule "Activate Promotion" when l : Line( ) not ( Promotion ( code ==
"HOTBUY" ) from l.promos ) then #do some action end The rule above works
perfectly for what I need when defined in a rule file. However, when I try
to define it in a decision table so that the 'code' can be feed from a
spreadsheet, I use the following values in the rules cells : RuleTable
HOTBUYS CONDITION ACTION l : Line not ( Promotion ( code == "$param" )
from l.promos ) System.out.println("$param added"); PROMOTION PROMOTION
HOTBUY BESTBUY I'm getting the following parser errors [10,17]: [ERR 101]
Line 10:17 no viable alternative at input 'Promotion' in rule "_11" in
pattern Line [10,29]: [ERR 101] Line 10:29 no viable alternative at input
'code' in rule "_11" [10,63]: [ERR 102] Line 10:63 mismatched input
')'
expecting 'then' in rule "_11" java.lang.IllegalArgumentException:
Could
not parse knowledge. at
com.sample.DecisionTableTest.readKnowledgeBase(DecisionTableTest.java:85)
at com.sample.DecisionTableTest.main(DecisionTableTest.java:28) Also in
Eclipse IDE, I get the following error : "Unknown error while parsing.
This is a bug. Please contact the Development team." NewPromotions.xls Is
it possible to use 'from' conditional element in decision tables ? If so,
what am I doing wrong. If not, then what's the best approach to implement
the rule above in a decision table. I'm running Drools 5.1.0M1 in Eclipse.
Help truly appreciated. Gurvinder
________________________________
View this message in context: Can we use 'from' CE in Decision Tables
?<http://n3.nabble.com/Can-we-use-from-CE-in-Decision-Tables-tp67005p67005.html>
Sent from the Drools - User mailing list
archive<http://n3.nabble.com/Drools-User-f47000.html> at
Nabble.com.
________________________________
**************************************************************************************
This message is confidential and intended only for the addressee. If you
have received this message in error, please immediately notify the
postmaster(a)nds.com and delete it from your system as well as any copies.
The content of e-mails as well as traffic data may be monitored by NDS for
employment and security purposes. To protect the environment please do not
print this e-mail unless necessary.
NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18
4EX, United Kingdom. A company registered in England and Wales. Registered
no. 3080780. VAT no. GB 603 8808 40-00
**************************************************************************************
________________________________
This message is confidential and intended only for the addressee. If you
have received this message in error, please immediately notify the
postmaster(a)nds.com and delete it from your system as well as any copies.
The content of e-mails as well as traffic data may be monitored by NDS for
employment and security purposes.
To protect the environment please do not print this e-mail unless
necessary.
An NDS Group Limited company.
www.nds.com
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users