[rules-users] How to activate/deactivate a rule.

Wolfgang Laun wolfgang.laun at gmail.com
Fri Sep 17 03:30:17 EDT 2010


I think this overly complex (unless other things have to be considered as
well.

As I interpret these three rules, it is required to compute the sum
of all values ABC.C with equal ABC.A

declare DistinctAT
    d_auditT : String
    d_sum: Double
end

rule "create DistinctAT on first ABC"
when
    ABC( $a:A )
    not DistinctAT( d_auditT == $a )
then
    DistinctAT $disAT = new DistinctAT();
    $disAT.setD_auditT($AT);
    insert( $disAT );
end

rule "update d_sum in DistinctAT"
when
    $disAT: DistinctAT( $a: d_auditT )
    ABC( A == $a, $c:C )
then
    $disAT.setD_sum( $disAT.getD_sum() + $c*0.13 );
end

Notice that I do not update/modify $disAT in the second rule since this
would cause a loop.
If you need the update to fire other rules, add "no-loop true".

To get all results, you can use a query; run it after all ABCs have been
inserted.

-W


On 17 September 2010 08:35, Ritesh <ritesh.khot at sungard.com> wrote:

>
> Hi,
>
> I have 3 rules in my drl file and want the last one should get fired only
> after all the facts in rule1 and rule2 gets inserted in working memory.
> Please see below code for more understanding. Please suggest.
>
> Thanks
>
> declare DistinctAT
>     d_auditT : String
> end
>
> declare ActualSum
>     auditT : String
>     sumOfThree : BigDecimal
> end
>
> rule "insert combined sum"
>        dialect 'java'
> when
>    ABC( $a:A, $b:B, $c:C )
>
> then
>        BigDecimal actSum = $c.multiply(0.13);
>        ActualSum $as = new ActualSum();
>        $as.setAuditT($a);
>        $as.setSumOfThree(actSum);
>        insert($as);
>        System.out.println("AT :" + $movAuditT);
> end
>
> rule "insert distinct AT"
>
>        dialect 'java'
> when
>    $a : ActualSum( $AT : auditT )
>        not DistinctAT( d_auditT == $AT )
> then
>        DistinctAT $disAT = new DistinctAT();
>        $disAT.setD_auditT($AT);
>        insert($disAT);
>        System.out.println("Done!");
> end
>
> rule "Get Sum Group by AT"
>
>        dialect 'java'
> when
>
> DistinctAT( $dAT: d_auditT )
>
> $total : Double()
> from accumulate( ActualSum( auditT == $dAT, $actSum_Main : sumOfThree ),
> sum( $actSum_Main ) )
>
> eval(
>        chkRuleExpre( $total,$lfna_SEI,$r_SEI )
> )
>
> then
>        System.out.println("Done Main Rule, total :" + $total);
> end
>
> --
> View this message in context:
> http://drools-java-rules-engine.46999.n3.nabble.com/How-to-activate-deactivate-a-rule-tp1516088p1516088.html
> Sent from the Drools - User mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100917/3a77888f/attachment.html 


More information about the rules-users mailing list