rule "Item should have a valid status"
when
ItemVo (statusCode : itemStatusCode != null)
eval( !itemValidationDao.isValidItemStatus(statusCode) )
then
errors.addValidationError("invalidtemStatusCode","Item Status Code is invalid ");
end
Exception data: org.drools.RuntimeDroolsException: java.lang.NullPointerException
at org.drools.rule.EvalCondition.isAllowed(Unknown Source)
at org.drools.reteoo.EvalConditionNode.assertTuple(Unknown Source)
at org.drools.reteoo.LeftInputAdapterNode.createAndAssertTuple(Unknown Source)
at org.drools.reteoo.LeftInputAdapterNode.assertObject(Unknown Source)
at org.drools.reteoo.ObjectSource.propagateAssertObject(Unknown Source)
Can somebody please help .. thanksimport com.walmart.itemfile.item.vo.ItemVo;
import com.walmart.itemfile.item.dao.ItemDao;
import com.walmart.itemfile.item.dao.ItemValidationDao;
import java.lang.String;
global com.walmart.itemfile.item.dao.ItemValidationDao itemValidationDao;
global com.walmart.itemfile.rules.ValidationErrorMap errors;
rule "Item should have a valid status"
when
ItemVo( statusCode : itemStatusCode != null)
ItemVo( statusCode == true ) from itemValidationDao.isValidItemStatus(statusCode) .. 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 ..
then
errors.addValidationError("nullItemStatusCode","Item Status Code is null");
System.out.println("Item Base Defaults Called" + itemValidationDao.isValidItemStatus(statusCode));
System.out.println("Item Status Code is null");
end
Caused by: org.drools.rule.InvalidRulePackage: unknown:32:28 Unexpected token 'itemValidationDao'
thanks for the
help guys ..
Sanjay
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 ..
Look at this code once .. its very easy but it involves tons of if else blocks conditions ..
if( newItem.getItemStatusCode() == null){
//do something
}
else{
if( !valDao.isValidItemStatus(newItem.getItemStatusCode(),user) ){
//do something
}
if( newItem.getItemStatusCode().equals(ItemVo.DELETED)||getItemStatusCode().equals(ItemVo.INACTIVE) ){if( valDao.isCrossReferencePrime(newItem.getItemNbr(),user)){
//do something
}
else if( valDao.isFutrCrossReferencePrimeOrSecond(newItem.getItemNbr(),user) ){
//do something
}
else if( valDao.isComponentLink(newItem.getItemNbr(),user)){
//do something
}
else if( valDao.hasWhseOnHandsOrOnOrders(newItem.getItemNbr(),user)&&CountryCode().equals("CA") ){//do something
}
}
else{
if( valDao.isUnlikeAsstParentWithNonActiveChildren(newItemNbr,user) ){
//do something;
}else if (isLikeAssortmentBaby(newItemNbr,user)&&!alDao.isLikeAsstParentActive(newItemNbr, user)){//do something
}else{
//do something
}
}
}
}
What i am trying to understand is the right way of putting it in drl files ..
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 ?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
3.Can i call rules within other rules .. so something like in rule1 i want to call rule2 .. is that possible ?
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 ...
Thanks for all the help ...
Sanjay
*******************************************************************
*** This email and any files transmitted with it are confidential
and intended solely for the individual or entity to whom they are
addressed. If you have received this email in error destroy it
immediately. ******************************************************
**************** Wal-Mart Confidential ****************************
******************************************