触发规则后,以某种方式未设置操作对象(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

最佳答案

该代码似乎可以正常工作。传入的对象有一些错字,导致每次规则匹配失败,从而导致对象返回空值。

关于java - 未设置Drools Action 对象成员变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25569131/

10-12 00:37
查看更多