Thomas,
as far as I understood, I don't have to use update(p), to update it :) After
using update method, there is infinite loop in my rules (I am talking about
DRL).
# this method doesn't change CProduct object
rule "Case A"
salience 1
activation-group "g1"
when
p : CProduct( name == "A" )
then
System.out.println("Special product: " + p.getName());
end
# this method doesn't change CProduct object
rule "Case B"
salience 1
activation-group "g1"
when
p : CProduct( name == "B" )
then
System.out.println("Special product: " + p.getName());
end
# this method changes CProduct object
rule "Case general"
salience 0
activation-group "g1"
when
p : CProduct( )
then
p.setValue(1000); # changes object's value
# I don't use update()
System.out.println("Normal product: " + p.getName());
end
# this method changes CProduct object
rule "New rule"
salience 0 # lower salience
activation-group "g1"
when
p : CProduct( )
then
p.setValue(-1); # I change object's value
# I don't use update()
System.out.println(p.getName() + " " + p.getValue());
end
In program, I use StatelessKnowledgeSession and execute method to use rules
on CProduct. And.... All normal products (name != A && name != B) have value
1000. Not -1. I don't use update function.
So: I use rules that update my object, but I don't get what am I to watch
out... For each object my activation-group fires only one rule. Rule "New
rule" never fires.
Thanks,
tom.
2010/7/28 Swindells, Thomas <TSwindells(a)nds.com>
There are two other solutions if you do need the p:
1. Change your condition to be “name matches $param”, this will
match as a regular expressions. Your general case can then be “.*”.
2. Merge your p:CProduct across two columns. Have a condition of
“this != $param” for the first column and give all the rows in this column
the value of null. Your second column can be name and then be missing in the
general clause. For the general clause this will evaluate to:
rule "Case general"
salience 0
activation-group "g1"
when
p : CProduct( this != null )
then
System.out.println("Normal product: " + p.getName());
end
which obviously will always evaluate to true for any CProduct.
The other general thing you need to watch out for with a spreadsheet of
this form is if you have any rules which update CProduct as these rules
would then be re-evaluated and re-executed again. In particular if you have
any rules of a lower salience that update the name then the activation group
doesn’t stop a different rule from being fired – activation groups are only
mutually exclusive at a given point in time when the activation occurs, they
don’t prevent different later re-activations.
Thomas
*From:* rules-users-bounces(a)lists.jboss.org [mailto:
rules-users-bounces(a)lists.jboss.org] *On Behalf Of *Mauricio Salatino
*Sent:* 28 July 2010 04:58
*To:* Rules Users List
*Subject:* Re: [rules-users] General rules in spreadsheet.
you can remove p, because in the spreadsheet you are not using it..
in the rules you use p to print the type of the product but in the
spreadsheet you are hardcoding the value in the "what to print" column
2010/7/27 tom ska <tiberium.linux(a)gmail.com>
Hello,
I want to use StatelessSession with spreadsheet. I wrote few rules in DRL,
but I cant do it in spreadsheet. First I want to present rules and class
that is used by rules:
public class CProduct {
private String name;
private int value;
public CProduct ()
{
name = "empty";
value = 0;
}
public CProduct (String name, int value)
{
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
}
Rules:
rule "Case A"
salience 1
activation-group "g1"
when
p : CProduct( name == "A" )
then
System.out.println("Special product: " + p.getName());
end
rule "Case B"
salience 1
activation-group "g1"
when
p : CProduct( name == "B" )
then
System.out.println("Special product: " + p.getName());
end
rule "Case general"
salience 0
activation-group "g1"
when
p : CProduct( )
then
System.out.println("Normal product: " + p.getName());
end
Using stateLessSession, salience, and activation-group I can determine,
that only one rule is going to be fired for each CProduct. And with salience
param, I can determine priority (it is important to get special products
first).
Now I am going to write those rules in spreadsheet. But I can't define rule
"Case general".
CONDITION
ACTION
ACTIVATION-GROUP
PRIORITY
p:CProduct
name
System.out.println("$param");
Rules names
Product name
what to print
Case A
A
Special A
G1
1
Case B
B
Special B
G1
1
General case
normal
G1
0
But when I am going to use the spreadsheet, I get this error:
"p cannot be resolved"
Problem disappears, when I fill "Product name" in "General case".
But I want it to be empty, because I want to fire rule "General case" when
rules "Case A" & "Case B" won't fire for any object's
name.
Thanks, Tom.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
- CTO @
http://www.plugtree.com
- MyJourney @
http://salaboy.wordpress.com
- Co-Founder @
http://www.jbug.com.ar
- Salatino "Salaboy" Mauricio -
------------------------------
**************************************************************************************
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
**************************************************************************************
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users