[rules-users] Write Assumptions for NESTED List<Object>

Wolfgang Laun wolfgang.laun at gmail.com
Tue Jun 26 05:34:15 EDT 2012


The Java code as shown has a somewhat unlikely flavour, with
OrderLineMeasure containing the field List<OrderLineMeasure>. And the
names used in the rules don't match the Java code, e.g.,
getUBLRuleEnginePriority().

And why should a String field quantity indicate the size of a List?

But see below for a (better) way of writing these rules.


On 26/06/2012, aliosha79 <alex_orl1079 at yahoo.it> wrote:
> Hi i have these simple three POJO class. The first is an OrderType that
> cointains a List or OrderLineType and each orderline cointains a list
> of measures.
> ________________________________________________________
> /public class OrderType {
>      protected List<OrderLineType> OrderLine;
>      protected String priority;
>
>      public void   set ....
>      public List<OrderlineType> get ....
>
>      public    getPriority()...
>      public    setPriority()...
> }
>
>
>
> public class OrderLineType {
>
>      protected String Quantity;
>      protected List<OrderLineMeasure> OrderLineMeasure;
>
>      public void   set ....
>      public List<OrderLineMeasure> get ....
>
>      public    getQuantity()...
>      public    setQuantity()...
> }
>
>
> public class OrderLineMeasure {
>
>      protected int measure;
>      protected List<OrderLineMeasure> OrderLineMeasure;
>
>      public    getMeasure()...
>      public    setMeasure()...
> } /
> ________________________________________________________
>
> I want to write an assumption stating that:
> *If an ORDER contains at least 3 orderLine... the order must have the High
> Priority.* In can do that writing this rule:
>
> _______________________________________________________________
>
> /when
>     $Order : OrderType ($orderLineList :orderLine)
>     OrderLineType(Quantity.Value >= 3 ) from $orderLineList
>
> then
>    $Order.getUBLRuleEnginePriority().setValue("high");
> end/

Your rule would fire once for each OrderLine containing a quantity of
more than 2, which is quite another thing than an order with at least
3 order lines.


rule moreThanThree
when
   $order : OrderType( orderLines.size() >= 3, priority != "high" )
then
   modify( $order ){ setPriority( "high" ) }
end

You can access orderLines.size() without the need for "from". Testing
priority != "high" ensures that the rule does not loop if you use
modify to notify the Engine that something has changed (which you
probably should do).


> ________________________________________________________________
>
> Now how can i write the assumption? if i want  a rule stating:
> *If an ORDER contains at least 3 orderLine and Each OrderLine contains more
> than 12 measures... the order must have the High Priority.*
> Really thanks for your help.
> Regards.
> Alessio
>

rule moreThanThreeTwelve
when
   $order: OrderType( orderLines.size() >= 3, priority != "high" )
   not OrderLineType( measures.size() < 12 ) from $order.getOrderLines()
then
   System.out.println( "3/12" );
   modify( $order ){ setPriority( "high" ) }
end

Here "from" is required to extract the OrderLineType objects. The
"not" checks that they all have a List with at least 12 elements.

-W

> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Write-Assumptions-for-NESTED-List-Object-tp4018241.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>


More information about the rules-users mailing list