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.<br>
<br>rule "meets requirements"<br>dialect "mvel"<br>when<br> Position( $certifications: requiredCertifications )<br> User( $name: name, $profile: profile )<br> $got: List() from collect ( AcquiredCertification( certification memberOf $certifications ) from $profile.userCertifications )<br>
eval($certifications.size == $got.size )<br>then<br> System.out.println( "Hire " + $name );<br>end<br><br>-W<br><br><div class="gmail_quote">On 19 September 2010 01:26, lnguyen <span dir="ltr"><<a href="mailto:mzspdrcr@gmail.com">mzspdrcr@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
Hi,<br>
<br>
I'm trying to determine if a user has the required certifications for a<br>
position. So I'm comparing the list of required certifications to the list<br>
of User Certifications but I'm throwing a nullPointerException even though I<br>
check to make sure the list are not null on their respective objects. How do<br>
I iterate between both list?<br>
<br>
rule "Determine if the user has the required certifications"<br>
dialect 'mvel'<br>
no-loop true<br>
salience 80<br>
when<br>
$user : User()<br>
$profile : UserProfile($userCertifications : userCertifications,<br>
eval(userCertifications != null)) from $user.userProfile<br>
$position : Position($certifications : requiredCertifications,<br>
eval(requiredCertifications != null))<br>
exists ($certification: Certification() from $certifications and<br>
UserCertification(certification == $certification) from $userCertifications)<br>
then<br>
System.out.println("The user has the required certifications");<br>
<br>
end<br>
<br>
public UserProfile<br>
{<br>
<br>
List<UserCertification> userCertifications;<br>
//more fields<br>
}<br>
<br>
public Position<br>
{<br>
List<Certification> requiredCertifications;<br>
//more fields<br>
}<br>
<br>
public Certification<br>
{<br>
Long id;<br>
<br>
String name;<br>
//more fields<br>
}<br>
<br>
public UserCertification<br>
{<br>
<br>
Long id;<br>
<br>
Date certificationDate;<br>
<br>
Certification certification;<br>
//more fields<br>
}<br>
<font color="#888888">--<br>
View this message in context: <a href="http://drools-java-rules-engine.46999.n3.nabble.com/LHS-compare-two-lists-tp1521979p1521979.html" target="_blank">http://drools-java-rules-engine.46999.n3.nabble.com/LHS-compare-two-lists-tp1521979p1521979.html</a><br>
Sent from the Drools - User mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br>