Drools未设置的操作对象成员变量

时间:2014-08-29 13:18:59

标签: java drools

触发规则后,不会设置动作对象(notificationObj)成员变量值。但是,当我通过Junit测试类执行它时,它会按预期返回值。但是当部署战争时,它会返回空值。你能告诉我可能出现的问题吗?

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;
}

规则表按预期产生DRL字符串,如下所示。 C15处的规则值,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

1 个答案:

答案 0 :(得分:0)

代码似乎完全正常。传入的对象有一些拼写错误导致规则匹配每次都失败,从而导致对象返回空值。