[rules-users] how to create local variable
Anstis, Michael (M.)
manstis1 at ford.com
Fri Jul 13 04:11:52 EDT 2007
Or what about having a rule that creates the substring?
Class SupplierCode {
private String code;
private SupplierView parent;
public SubString(SupplierView parent, String code) {
this.code = code;
this.parent = parent;
}
public String getCode() {
return this.code;
}
public SupplierView getParent() {
return this.parent;
}
}
rule "suppliercode"
when
$sv : SupplierView( $sc : suppCode )
then
insert(new SupplierCode($sv, $sc.substring(4, 6)));
end
rule "main"
when
$sv : SupplierView(corporate == true)
$sc : SupplierCode( code in ('25, '30'), parent == $cs )
then
ValidationErrorFacade.getInstance().registerError($cs, new
ValidationError("Headquarter Supplier Code should end on 25 or 30."));
end
This way you are also making the business rule as to what supplier codes
to accept a Drools rule (and no use of eval!)
(Sorry, a boring day at work and I felt an urge to contribute!)
Mike
________________________________
From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Manukyan,
Sergey
Sent: 12 July 2007 21:40
To: Rules Users List
Subject: RE: [rules-users] how to create local variable
Thank you Edson,
I liked the solution with matches, it is much cleaner....
-Sergey
________________________________
From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Edson Tirelli
Sent: Thursday, July 12, 2007 4:19 PM
To: Rules Users List
Subject: Re: [rules-users] how to create local variable
It is not possible to assign the result of an arbitrary
method call to a variable right now. So, your best option is probably to
do (please note the use of inline-eval):
rule "SupplierView: Headquarter Supplier Code should end on 25
or 30."
when
$cs : SupplierView(corporate == true, eval(
suppCode.substring(4, 6).equals( "25" ) || suppCode.substring(4,
6).equals( "30" ) ) )
then
ValidationErrorFacade.getInstance().registerError($cs, new
ValidationError("Headquarter Supplier Code should end on 25 or 30."));
end
A more clean solution is to use "matches" operator. If your
rule states that Supplier Code must END with 25 or 30, you can do:
rule "SupplierView: Headquarter Supplier Code should end on 25
or 30."
when
$cs : SupplierView(corporate == true, suppCode
matches ".*25" || matches ".*30" )
then
ValidationErrorFacade.getInstance().registerError($cs, new
ValidationError("Headquarter Supplier Code should end on 25 or 30."));
end
Hope it helps.
[]s
Edson
2007/7/12, Manukyan, Sergey < SManukyan at lear.com>:
Folks,
I have a rule where I am repeating part of it twice :
($cs.getSuppCode().substring(4, 6)), and I would like to replace it with
variable... how can I do that? The solution with "in" doesn't worl
because it is a java code needed to perform calculations for
variable.....
Please see the rule below:
rule "SupplierView: Headquarter Supplier Code should end on 25
or 30."
when
$cs : SupplierView(corporate == true)
eval($cs.getSuppCode().substring(4, 6) == "25" ||
$cs.getSuppCode().substring(4, 6) == "30")
then
ValidationErrorFacade.getInstance().registerError($cs, new
ValidationError("Headquarter Supplier Code should end on 25 or 30."));
end
Thanks,
-Sergey
**********************
** LEGAL DISCLAIMER **
**********************
This E-mail message and any attachments may contain
legally privileged, confidential or proprietary
information. If you are not the intended recipient(s),
or the employee or agent responsible for delivery of
this message to the intended recipient(s), you are
hereby notified that any dissemination, distribution
or copying of this E-mail message is strictly
prohibited. If you have received this message in
error, please immediately notify the sender and
delete this E-mail message from your computer.
_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Edson Tirelli
Software Engineer - JBoss Rules Core Developer
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070713/0091f3c3/attachment.html
More information about the rules-users
mailing list