[rules-users] All the values from one list must be present in other

Wolfgang Laun wolfgang.laun at gmail.com
Mon Aug 20 15:06:48 EDT 2012


See inline.

On 20/08/2012, Suvek <suvek.shah at gmail.com> wrote:
> Thanks laune!!!
> I think I did not explain properly and duplicate name "FOREIGN_BUSINESS"
> added more to the confusion...  still you understood my problem , I will
> try
> putting more flesh on the bones in terms of classes to explain further
> details...
>
> public class TaxPayer {
> ...
>  ArrayList<Address> addersses;
>  TaxpayerType taxpayerType;
> ...
> }
>
> public class Address {
> 	...
>    AddressType addressType;
> 	...
> }
>
> public enum AddressType{
> UNKNOWN,
> BUSINESS,
> FOREIGN_BUSINESS_ADDRESS,
> RENTED,
> OWNED,
> ....
> }
>
> public enum TaxpayerType{
> BUSINESS,
> FOREIGN_BUSINESS,
> INDIVIDUAL,
> FAMILY,
> PROPRITER
> ....
> }
>
> Now based on the taxpayerType say FOREIGN_BUSINESS, the taxpayer must have
> atleast 2 Addresses (BUSINESS and FOREIGN_BUSINESS_ADDRESS).
>

Agreed, to of the above.


> I will have seperate rule for each type of tax payer, I am not passing in
> the AddressTypes (BUSINESS and FOREIGN_BUSINESS_ADDRESS) to be verified
> against as the facts, I want to set these values in the rule.

Why? They are static, aren't they?

There is no really convenient way to define a constant Set (or any
other Collection) in DRL syntax. You can write an array, but then
you'll need a way of doing set operations (like containsAll() ) with
an array as one operand.


> So ideally I
> want something like
>
> rule "Validate Foreign Business"
> when 	
>     $tpType: List() from [ AddressType.BUSINESS,
> AddressType.FOREIGN_BUSINESS_ADDRESS ] //This line is incorrect
>     Taxpayer( $name: name, taxpayerType == $tpType, $addrs: addresses )
>     accumulate( Address( $addrType: addressType ) from $addrs,
>                 $addrTypeSet: collectSet( $addrType ) )
>     eval( ! $addrTypeSet.containsAll( $addressTypes ) )
> then
>     System.out.println( $name + " is not OK" );
> end
>
> Also is it possible to show which address type is missing? say
> AddressType.BUSINESS is not present in the list

The answer to this would be a Set. It can be computed by applying
method removeAll(x) to the required Set, where x is the Set resulting
from accumulate.

I strongly suggest you use my approach with defining the static
AddressType Sets as an attribute of TaxpayerType!

-W

>
> thanks in advance for your help
>
>
>
>
>
>
>
>
>
>
>
> the rule is always resolving to success irrespective of weather the
> addresses are present or not.
>
>
>
>
> the only change that I have done is
> replaced
> $tpType: TaxpayerType( $addressTypes: addressTypes )
> with
> $tpType:
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/All-the-values-from-one-list-must-be-present-in-other-tp4019276p4019280.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