<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Hi.</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.2963" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=016132522-03042007>Since i could not get the earlier code running i tried
using eval in LHS side for Dao calls but i keep on getting NullPointerException
...</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=016132522-03042007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT><SPAN class=016132522-03042007>
<P><FONT face=Arial color=#0000ff size=2>rule "Item should have a valid
status"</FONT></P>
<P><FONT face=Arial color=#0000ff size=2>when</FONT></P>
<P><FONT face=Arial color=#0000ff size=2>ItemVo (statusCode : itemStatusCode !=
null)</FONT></P>
<P><FONT face=Arial color=#0000ff size=2>eval(<SPAN class=016132522-03042007>
</SPAN><SPAN
class=016132522-03042007>!</SPAN>itemValidationDao.isValidItemStatus(statusCode)<SPAN
class=016132522-03042007> </SPAN>)</FONT></P>
<P><FONT face=Arial color=#0000ff size=2>then</FONT></P>
<P><FONT face=Arial color=#0000ff size=2>errors.addValidationError("<SPAN
class=016132522-03042007>invalid</SPAN>temStatusCode","Item Status Code
is <SPAN class=016132522-03042007>invalid </SPAN>");</FONT></P>
<P>
<P><FONT face=Arial color=#0000ff size=2></FONT></P><FONT face=Arial
color=#0000ff size=2>end</FONT></P><FONT face=Arial color=#0000ff size=2><FONT
color=#0000ff size=2>
<P><FONT color=#ff0000>Exception data: org.drools.RuntimeDroolsException:
java.lang.NullPointerException</FONT></P>
<P><FONT color=#ff0000>at org.drools.rule.EvalCondition.isAllowed(Unknown
Source)</FONT></P>
<P><FONT color=#ff0000>at
org.drools.reteoo.EvalConditionNode.assertTuple(Unknown Source)</FONT></P>
<P><FONT color=#ff0000>at
org.drools.reteoo.LeftInputAdapterNode.createAndAssertTuple(Unknown
Source)</FONT></P>
<P><FONT color=#ff0000>at
org.drools.reteoo.LeftInputAdapterNode.assertObject(Unknown Source)</FONT></P>
<P><FONT color=#ff0000>at
org.drools.reteoo.ObjectSource.propagateAssertObject(Unknown Source)</FONT></P>
<P></FONT></FONT><SPAN class=016132522-03042007><FONT face=Arial color=#0000ff
size=2>Can somebody please help .. thanks</FONT></SPAN></P>
<P></SPAN></FONT>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Sanjay Singh - s0singh <BR><B>Sent:</B>
Tuesday, April 03, 2007 11:01 AM<BR><B>To:</B> 'Anstis, Michael (M.)'; Rules
Users List<BR><B>Subject:</B> RE: Hi.<BR></FONT><BR></P></DIV>
<DIV></DIV>
<DIV dir=ltr align=left><SPAN class=300315015-03042007><FONT face=Arial
color=#0000ff size=2>Thanks for getting back to me Mike and Edson and Sorry for
the delayed response.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=300315015-03042007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=300315015-03042007><FONT face=Arial
color=#0000ff size=2>I looked at your examples Mike and i felt better as you
said that we can make dao calls in LHS .. And Edson suggested not to be afraid
of suggesting the same constraint for more than one rule .. i guess i was
looking at it more procedural way and dint want any repetition of those
conditions as the top level IF block but looks like it won't hurt to
mention these constraints in all the rules related to this check ...so i can
include this check in all the rules .. hmm ..</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=300315015-03042007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=300315015-03042007><FONT face=Arial
color=#0000ff size=2>Here is a quick test i was trying to do for calling the dao
in LHS but it fails .. what am i missing .. </FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=300315015-03042007><FONT color=#0000ff><FONT
face=Arial size=2></FONT></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=300315015-03042007><FONT color=#0000ff><FONT
face=Arial size=2>package com.walmart.itemfile.item.rules</FONT></DIV>
<DIV dir=ltr align=left>
<P><FONT face=Arial size=2>import
com.walmart.itemfile.item.vo.ItemVo;</FONT></P>
<P><FONT face=Arial size=2>import
com.walmart.itemfile.item.dao.ItemDao;</FONT></P>
<P><FONT face=Arial size=2>import
com.walmart.itemfile.item.dao.ItemValidationDao;</FONT></P>
<P><FONT face=Arial size=2>import java.lang.String;</FONT></P>
<P><FONT face=Arial size=2>global
com.walmart.itemfile.item.dao.ItemValidationDao itemValidationDao;</FONT></P>
<P><FONT face=Arial size=2>global com.walmart.itemfile.rules.ValidationErrorMap
errors;</FONT></P>
<P><FONT face=Arial size=2>rule "Item should have a valid status"</FONT></P>
<P><FONT face=Arial size=2>when</FONT></P>
<P><FONT face=Arial size=2>ItemVo( statusCode : itemStatusCode !=
null)</FONT></P>
<P><FONT face=Arial><FONT color=#ff0000><FONT size=2><STRONG><FONT
color=#00ff00>ItemVo( statusCode<SPAN class=300315015-03042007> ==
true</SPAN> )</FONT> from
itemValidationDao.isValidItemStatus(statusCode)</STRONG><SPAN
class=300315015-03042007><STRONG> ..</STRONG> <FONT color=#000000>my
isValidItemStatus method returns a boolean (not collection of codes) and i need
to check if thats true than go to the RHS side .. is the line in green even
right .. in any case it does not recognize itemValidationDao to begin with in
LHS side .. RHS same call works .. </FONT></SPAN></FONT></FONT></FONT></P>
<P><FONT face=Arial size=2>then</FONT></P>
<P><FONT face=Arial size=2>errors.addValidationError("nullItemStatusCode","Item
Status Code is null");</FONT></P>
<P><FONT face=Arial size=2>System.out.println("Item Base Defaults Called" +
itemValidationDao.isValidItemStatus(statusCode));</FONT></P>
<P><FONT face=Arial size=2>System.out.println("Item Status Code is
null");</FONT></P>
<P><FONT face=Arial size=2>end</FONT></P>
<DIV dir=ltr align=left><SPAN class=300315015-03042007><FONT face=Arial
color=#800000 size=2>
<P>Caused by: org.drools.rule.InvalidRulePackage: unknown:32:28 Unexpected token
'itemValidationDao'</P></FONT></SPAN></DIV>
<P><BR><FONT face=Arial size=2><SPAN class=300315015-03042007>thanks for the
help guys .. </SPAN></FONT></P>
<P><FONT face=Arial size=2><SPAN
class=300315015-03042007>Sanjay</SPAN></FONT></P></FONT></SPAN></DIV>
<DIV dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Anstis, Michael (M.)
[mailto:manstis1@ford.com] <BR><B>Sent:</B> Monday, March 26, 2007 8:57
AM<BR><B>To:</B> Rules Users List<BR><B>Cc:</B> Sanjay Singh -
s0singh<BR><B>Subject:</B> RE: Hi.<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2>Hi Sanjay,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2>To firstly answer your questions (in my
opinion):</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2>1. You can't do nested whens in the LHS but you can do
nested if / else in the RHS (although you'd fore go the benefits of a
RETE-based inference engine; but possible if you've got very few rules and
facts...). I believe that there is work to have an "otherwise" statement for
rule syntax, how progressed this is and how it will work I don't know - over to
Mark and team?!?</FONT></SPAN><SPAN class=283283213-26032007> </SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2>2. Yes, take a look at the "from" statement (new for
3.1-M1, see <A
href="http://wiki.jboss.org/wiki/Wiki.jsp?page=3.1M1ReleaseNotes">http://wiki.jboss.org/wiki/Wiki.jsp?page=3.1M1ReleaseNotes</A>)</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2>3. Yes, take a look at rule-flow at <A
href="http://labs.jboss.com/portal/index.html?ctrl:cmd=render&ctrl:window=default.blog.PrjBlogPortletWindowDefaultBlog&project=jbossrules&from=1&link=RuleFlow_%28Kris_Verlaenen%29#RuleFlow_%28Kris_Verlaenen%29">http://labs.jboss.com/portal/index.html?ctrl:cmd=render&ctrl:window=default.blog.PrjBlogPortletWindowDefaultBlog&project=jbossrules&from=1&link=RuleFlow_%28Kris_Verlaenen%29#RuleFlow_%28Kris_Verlaenen%29</A> (although
I don't know if this is complete if 3.1-M1 - I think it's not). Although I don't
think your rules really need rule-flow; you just need to identify and isolate
the patterns (IF's) that would cause each "Do Something" to be ran and create a
rule for each - this has the benefit of separating each action into a separate
rule making maintenance a whole bunch easier).</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2>Anyway, I'd try some rules like the following examples (the
rest are based upon these):-</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2>Rule "Rule 1"</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2>when</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2> NewItem ( itemStatusCode == null)
</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2>then</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007> <FONT
face=Arial color=#0000ff size=2>//do something</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2>end</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2>Rule "Rule 2"</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2>when</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007> <FONT
face=Arial color=#0000ff size=2>$u : User( )</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007> <FONT
face=Arial><FONT color=#0000ff size=2>$ni : NewItem ( $isc : itemStatusCode !=
null )</FONT></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007> <FONT
face=Arial><FONT color=#0000ff size=2>not Codes ( codes contains $isc ) from
valDao.getValidItemStatusCodesForUser($u)</FONT></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2>then</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2> //Do something</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2>end</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2>Rule "Rule 3"</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2>when</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN
class=283283213-26032007> <FONT face=Arial color=#0000ff
size=2>$u : User( )</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN
class=283283213-26032007> <FONT face=Arial><FONT
color=#0000ff size=2>$ni : NewItem( itemStatusCode == ItemVO.DELETED
)</FONT></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN
class=283283213-26032007> <FONT face=Arial color=#0000ff
size=2>Codes ( codes contains $isc )
from valDao.getValidCrossReferencePrimeCodesForUser($u)</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2>then</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN
class=283283213-26032007> <FONT face=Arial color=#0000ff
size=2>//Do something</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2>end</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2>I've posted to the news group so everyone can
contribute - don't be shy ;-)</FONT> </SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2>With kind regards,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2>Mike</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=283283213-26032007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left>
<HR tabIndex=-1>
</DIV>
<DIV dir=ltr align=left><FONT face=Tahoma size=2><B>From:</B> Sanjay Singh -
s0singh [mailto:Sanjay.Singh@wal-mart.com] <BR><B>Sent:</B> 26 March 2007
14:24<BR><B>To:</B> Anstis, Michael (M.)<BR><B>Subject:</B>
Hi.<BR></FONT><BR></DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV></DIV><!-- Converted from text/rtf format -->
<P><FONT face="Courier New" size=2>Hey Mike ... I am sorry to bother you but
you seemed to be pretty good with rules and i just could not think of anyone
else to ask abt it ... I am sorry if i am taking much of your time .. Here is
my problem if you can have a quick look .. </FONT></P>
<P><FONT face="Courier New" size=2>Look at this code once .. its very easy but
it involves tons of if else blocks conditions .. </FONT></P>
<P>
<FONT face="Courier New" size=2>if(
newItem.getItemStatusCode() == null){</FONT>
<BR>
<FONT face="Courier New"
size=2>//do something</FONT> <BR>
<FONT face="Courier New"
size=2>}</FONT> <BR>
<FONT face="Courier New"
size=2>else{</FONT> <BR>
<B> <FONT face="Courier New"
color=#ff0000 size=2>if(
!valDao.isValidItemStatus(newItem.getItemStatusCode(),user) ){</FONT></B>
<BR><B>
<FONT face="Courier New"
color=#ff0000 size=2>//do something</FONT></B>
<BR><B>
<FONT face="Courier New"
color=#ff0000 size=2>}</FONT></B>
<BR><B>
<FONT face="Courier New"
color=#ff0000 size=2>if(
newItem.getItemStatusCode().equals(ItemVo.DELETED)||getItemStatusCode().equals(ItemVo.INACTIVE)
){</FONT></B></P>
<P><B>
<FONT face="Courier New"
color=#0000ff size=2>if(
valDao.isCrossReferencePrime(newItem.getItemNbr(),user)){</FONT></B>
<BR><B>
<FONT face="Courier New"
color=#0000ff size=2>//do something</FONT></B>
<BR><B>
<FONT face="Courier New"
color=#0000ff size=2>}</FONT></B>
<BR><B>
<FONT face="Courier New"
color=#0000ff size=2>else if(
valDao.isFutrCrossReferencePrimeOrSecond(newItem.getItemNbr(),user)
){</FONT></B> <BR><B>
<FONT face="Courier New"
color=#0000ff size=2>//do something</FONT></B>
<BR><B>
<FONT face="Courier New"
color=#0000ff size=2>}</FONT></B>
<BR><B>
<FONT face="Courier New"
color=#0000ff size=2>else if(
valDao.isComponentLink(newItem.getItemNbr(),user)){</FONT></B>
<BR><B>
<FONT face="Courier New"
color=#0000ff size=2>//do something</FONT></B>
<BR><B>
<FONT face="Courier New"
color=#0000ff size=2>}</FONT></B>
<BR><B>
<FONT face="Courier New"
color=#0000ff size=2>else if(
valDao.hasWhseOnHandsOrOnOrders(newItem.getItemNbr(),user)&&CountryCode().equals("CA")
){</FONT></B></P>
<P><B>
<FONT face="Courier New"
color=#0000ff size=2>//do something</FONT></B>
<BR><B>
<FONT face="Courier New"
color=#0000ff size=2>}</FONT></B>
<BR><B>
<FONT face="Courier New"
color=#ff0000 size=2>}</FONT></B>
<BR><B>
<FONT face="Courier New"
color=#ff0000 size=2>else{</FONT></B>
<BR><B>
<FONT face="Courier New"
color=#800000 size=2>if(
valDao.isUnlikeAsstParentWithNonActiveChildren(newItemNbr,user) ){</FONT></B>
<BR><B>
<FONT face="Courier New"
color=#800000 size=2>//do something;</FONT></B>
<BR><B>
<FONT face="Courier New"
color=#800000 size=2>}else if
(isLikeAssortmentBaby(newItemNbr,user)&&!alDao.isLikeAsstParentActive(newItemNbr,
user)){</FONT></B></P>
<P><B>
<FONT face="Courier New"
color=#800000 size=2>//do something
</FONT></B><BR><B>
<FONT face="Courier New"
color=#800000 size=2>}else{</FONT></B>
<BR><B>
<FONT face="Courier New"
color=#800000 size=2>//do something</FONT></B>
<BR><B>
<FONT face="Courier New"
color=#800000 size=2>}</FONT></B>
<BR><B>
<FONT face="Courier New"
color=#800000 size=2>}</FONT></B>
<BR><B>
<FONT face="Courier New"
color=#ff0000 size=2>}</FONT></B>
<BR><B>
</B> <FONT face="Courier New"
size=2>}</FONT><B> </B></P><BR><BR>
<P><FONT face="Courier New" size=2>What i am trying to understand is the right
way of putting it in drl files .. </FONT><BR><FONT face="Courier New"
size=2>1.What are the options for putting if else conditions ? Will i have to
write all the rules anyway and they will be called as well all the time
depending on the criteria ... or is there a way where when my first if check
which was if item number is null failed i should not go for any other rules ..
Is there a way where we could have like "when" inside "when" .. kinda looping
of conditions so if one does not meet you dont go to the next .. jsut like in
above blocks ? Whats the good way of doing it ?</FONT></P>
<P><FONT face="Courier New" size=2>2.Is it possible to make database calls
like from my dao instance in LHS (condition) .. i know we can do it in RHS and
i have tested that as well but can we do it in LHS as sometimes we need to do
that ..like with null checks for the item status code we also want to check
something from the database like a boolean value and if that meets the
criteria we will run the rules ..as u can see above we have basic state check
with nulls etc plus we have some dao calls as well in the condition part and
then we //do something</FONT></P>
<P><FONT face="Courier New" size=2>3.Can i call rules within other rules .. so
something like in rule1 i want to call rule2 .. is that possible ?</FONT> </P>
<P><FONT face="Courier New" size=2>Can you suggest a decent way of doing these
if else blocks .. this is the core stuff which we do for our rules here .. if
i can handle this kind of conditions i guess i can handle anything out here
... </FONT></P>
<P><FONT face="Courier New" size=2>Thanks for all the help ...</FONT> </P>
<P><FONT face="Courier New" size=2>Sanjay</FONT> </P><BR><BR><BR><BR>
<P>
<HR SIZE=1>
<P></P><BR>
<P><STRONG><BR>*******************************************************************<BR>***
This email and any files transmitted with it are confidential<BR>and intended
solely for the individual or entity to whom they are<BR>addressed. If you have
received this email in error destroy it<BR>immediately.
******************************************************<BR>****************
Wal-Mart Confidential
****************************<BR>******************************************<BR></STRONG></P></BLOCKQUOTE></BODY></HTML>
<HTML><BODY><P><hr size=1></P><br>
<P><STRONG><br>
*******************************************************************<br>
*** This email and any files transmitted with it are confidential<br>
and intended solely for the individual or entity to whom they are<br>
addressed. If you have received this email in error destroy it<br>
immediately. ******************************************************<br>
**************** Wal-Mart Confidential ****************************<br>
******************************************<br>
</STRONG></P></BODY></HTML>