1
在触发规则之后,不知何故操作对象(notificationObj
)成员变量值未设置。但是,当我通过Junit测试类执行它时,它会按预期返回值。但是当战争部署时,它会返回空值。你能让我知道什么可能是错的?Drools操作对象成员变量未设置
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("[email protected]");;
notificationObj.setActionRouter("SendNowRouter");;
end
没有办法说出Java和DRL代码是否会导致规则“Rule_Evaluation_15”被触发。如果它没有被触发,所有通知属性都保持为空,就像你所观察到的那样。 – laune 2014-08-29 18:47:51
感谢Laune.But想知道当我们执行Junit并返回预期结果时它是如何工作的。 – 2014-08-30 02:15:12
您必须检查所有未显示的代码才能了解原因。 – laune 2014-08-30 05:07:56