[rules-users] LHS compare two lists

Wolfgang Laun wolfgang.laun at gmail.com
Sun Sep 19 11:27:25 EDT 2010


The idea of the rule given below is to collect a List<AcquiredCertification>
from a certain User that's contained in the Position object's list of
requiredCertifications, and then to compare the sizes. Equality means that
User meets all requirements.

rule "meets requirements"
dialect "mvel"
when
    Position( $certifications: requiredCertifications )
    User( $name: name, $profile: profile )
    $got: List() from collect (  AcquiredCertification( certification
memberOf $certifications ) from $profile.userCertifications )
    eval($certifications.size == $got.size  )
then
    System.out.println( "Hire " + $name );
end

-W

On 19 September 2010 01:26, lnguyen <mzspdrcr at gmail.com> wrote:

>
> Hi,
>
> I'm trying to determine if a user has the required certifications for a
> position. So I'm comparing the list of required certifications to the list
> of User Certifications but I'm throwing a nullPointerException even though
> I
> check to make sure the list are not null on their respective objects. How
> do
> I iterate between both list?
>
> rule "Determine if the user has the required certifications"
> dialect 'mvel'
>    no-loop true
>    salience 80
> when
>    $user : User()
>    $profile : UserProfile($userCertifications : userCertifications,
> eval(userCertifications != null)) from $user.userProfile
>    $position : Position($certifications : requiredCertifications,
> eval(requiredCertifications != null))
>    exists ($certification: Certification() from $certifications and
> UserCertification(certification == $certification) from
> $userCertifications)
> then
>    System.out.println("The user has the required certifications");
>
> end
>
> public UserProfile
> {
>
>    List<UserCertification> userCertifications;
>    //more fields
> }
>
> public Position
> {
>    List<Certification> requiredCertifications;
>   //more fields
> }
>
> public Certification
> {
>    Long id;
>
>    String name;
>    //more fields
> }
>
> public UserCertification
> {
>
>    Long id;
>
>    Date certificationDate;
>
>    Certification certification;
>    //more fields
> }
> --
> View this message in context:
> http://drools-java-rules-engine.46999.n3.nabble.com/LHS-compare-two-lists-tp1521979p1521979.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/20100919/53d914d7/attachment.html 


More information about the rules-users mailing list