Nonsense.
Rules engines can solve many problems much better than a monotonic programming. The
primary area where this is the case are the "watch for given conditions, then
act" problems: monitoring, command and control, models, and simulations. Rule
engines are particularly well suited for tackling those problems, as with the "just
do it in java" approach you usually end up first implementing a rules engine (badly)
and getting stuck twiddling with your engine when you could be solving the problem at
hand.
The business rules application of rules engines was just a way to get the technology
adopted, but it is by no means the only use of the technology.
--- On Mon, 2/6/12, Welsh, Armand <AWelsh(a)StateStreet.com> wrote:
From: Welsh, Armand <AWelsh(a)StateStreet.com>
Subject: Re: [rules-users] setting different value in consequence ( RHS part) based on a
conditional check
To: "Rules Users List" <rules-users(a)lists.jboss.org>
Date: Monday, February 6, 2012, 6:45 PM
As I suggested, if you wish to put conditional logic in the RHS of a rule, you would use a
function. I didn’t provide an example using the function, because
it did not appear to warrant the need for one, and because I consider this to be a very
simplified version of the actual rule.
Again, the decision on how to solve the challenge is up to the developer. Rules engines
are not really designed to solve programmer’s problems, they are designed
to solve business problems. And the use of functions to apply business logic obfuscates
the code, making it less readable by a business analyst, and complicates the development
of the code. Placing the decision logic in the LHS keeps the rules simple, and
thus more maintainable by a business analyst.
If only developers will ever look at the code, then I would question the use of drools at
all, since many of the challenges we solve with drools can be coded
more efficiently in straight JAVA code. But again, the decision is always on the
developers.
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org]
On Behalf Of Wolfgang Laun
Sent: Thursday, January 26, 2012 10:52 AM
To: Rules Users List
Subject: Re: [rules-users] setting different value in consequence ( RHS part) based on a
conditional check
Oh my, aren't we a wee bit too dogmatic? I've certainly been known as being a
stickler to style and best practice and what not, but in this particular case I'd use
a single rule and offload the earth-shaking
decision between 'Y' and 'N' into a function:
rule x
when
samplefact1( $status: status, state == "CA" )
then
fact0.setField1( yn( $status) );
end
Cheers
-W
On 26 January 2012 18:25, Welsh, Armand <AWelsh(a)statestreet.com> wrote:
You cannot, under normal circumstances, place conditional login in the RHS. This is by
design. Any conditional logic belongs in the LHS. If you need to perform conditional
logic in the RHS, this is usually an indicator that they rule
is not written correctly.
Now, with that said, there are times when you specifically want to put a decision
component in the RHS. I would do this using a function.
In your case, it really would make sense to use two rules, to represent your one case,
like this:
Rule 1
when
samplefact1( status == "active", state == "CA" )
then
Response fact0= new Response();
fact0.setField1( "Y" );
fact0.setName( "something " );
insert(fact0 );
end
Rule 2
when
samplefact1( status != "active", state == "CA" )
then
Response fact0= new Response();
fact0.setField1( "N" );
fact0.setName( "something " );
insert(fact0 );
end
These two rules are mutually exclusive, only one will fire, and you get the result you
want. It's really about changing the way you think about decision factors. You can
also achieve the same result like this:
Rule 1
when
samplefact1(state == "CA" )
then
Response fact0= new Response();
fact0.setName( "something " );
insert(fact0 );
end
Rule 2a
when
samplefact1( status == "active", state == "CA" )
$resp : Response ( field1 != "Y")
Then
modify( $resp ) { setField1( "Y" ) };end
Rule 2b
when
samplefact1( status != "active", state == "CA" )
$resp : Response ( field1 == "Y")
then
modify( $resp ) { setField1( "N" ) };
end
In this scenario, you are changing from hard data mapping to an event oriented rule.
Rule1 creates the basic Response fact, and Rules 2a&2b enrich the response fact based
on conditions that may arise throughout the processing of the rules, independent of the
initial creation step. Just whenever you have a response fact that is not Y, set it to
Y, and of course the inverse rule... This requires more processing for the rules, but in
a large rules based system this may be more in-line with what you really want.
Armand
-----Original Message-----
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On
Behalf Of vadlam
Sent: Thursday, January 26, 2012 8:11 AM
To: rules-users(a)lists.jboss.org
Subject: [rules-users] setting different value in consequence ( RHS part) based on a
conditional check
Hi,
we have an existing BRL rule in Guvnor whereby we set the value of some
fields in RHS based on some value checks in the condition part. we have
created several of these rules already in a previous release.
In the next release, we have new requirements to set the value of an
existing field in consequence to be of 2 different values based on a
specific conditional evaluation. the rest of the rule remains the same.
to clarify,
when
samplefact1( status== "active" , state=="CA" )
then
Response fact0= new Response();
fact0.setField1( "Y" );
fact0.setName( "something " );
insert(fact0 );
end
we now have to change this to set Field1 value to Y or N based on some
updated condition for status field.
lets say if status=="active" , Field1 has to be Y, but when status=closed,
then Field1 has to be N
Please keep in mind that the rest of the rule remains the same.
is there a way to set the value of Field1 to be Y or N within the
consequence part of same rule without having to create another rule .
will the use of functions or variables be of any help in this case?
--
View this message in context:
http://drools.46999.n3.nabble.com/setting-different-value-in-consequence-...
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
-----Inline Attachment Follows-----
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users