After firing rules, somehow the action object (notificationObj
) member variable values are not set. However when I execute it via Junit test class it returns values as expected. But when the war gets deployed it returns null values. Can you please let m know what could be wrong?
List<Attribute> auxiliaryList = eventObject.getAuxiliary();
Attribute attributeObj = new Attribute();
Notification notificationObj = new Notification();
KnowledgeBase kBase = kBuilderUtility.buildKBase(resourceName, workSheetName);
StatefulKnowledgeSession kSession = kBase.newStatefulKnowledgeSession();
FactHandle eventObjHandle = kSession.insert(eventObject);
FactHandle attributeObjHandle = kSession.insert(attributeObj);
FactHandle notificationObjHandle = kSession.insert(notificationObj);
for (Attribute attribute : auxiliaryList) {
if (createNewNotificationObject) {
notificationObj = new Notification();
}
attributeObj.setName(attribute.getName());
attributeObj.setValue(attribute.getValue());
kSession.update(eventObjHandle, eventObject);
kSession.update(attributeObjHandle, attributeObj);
kSession.update(notificationObjHandle, notificationObj);
kSession.setGlobal("eventObj", eventObject);
kSession.setGlobal("attributeObj", attributeObj);
kSession.setGlobal("notificationObj", notificationObj);
kSession.fireAllRules();
LOGGER.debug(notificationObj.getCommunicationType());
eventObject.getNotificationCollection().add(notificationObj);
createNewNotificationObject = true;
}
The rule sheet produces DRL string as expected as given below. Rule values at C15, header at C9:
rule "Rule_Evaluation_15"
when
$eventObj: Event(eventType=="ABC", sourceSystem=="ABC")
$attributeObj: Attribute(name=="old_status", value=="XYS")
then
notificationObj.setMsgDescription("ABC");;
notificationObj.setSourceSystem("XYZ");;
notificationObj.setTemplateId("12345AB");;
notificationObj.setCommunicationType("Email");;
notificationObj.setLanguage("English");;
notificationObj.setEmailAddress("test@gmail.com");;
notificationObj.setActionRouter("SendNowRouter");;
end