1

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
Steve
  • 9,270
  • 5
  • 47
  • 61
Nishant Prabhu
  • 85
  • 1
  • 2
  • 11
  • There is no way one can say whether the Java and DRL code as shown results in rule "Rule_Evaluation_15" ever being fired. If it is not fired, all Notification properties remain null, as you have observed. – laune Aug 29 '14 at 18:47
  • Thanks Laune.But want to understand how does it work when we execute the Junit and return exepcted results. – Nishant Prabhu Aug 30 '14 at 02:15
  • You'll have to examine all of the code you have NOT shown to learn the reason why. – laune Aug 30 '14 at 05:07

1 Answers1

0

The code seems to work perfectly fine. The incoming object had some typos which caused the rule matching to fail every time thereby causing the object to return null values.

Nishant Prabhu
  • 85
  • 1
  • 2
  • 11