2017-10-10 216 views
0

我在一個項目中有兩個指導決策表。我的要求是隻執行那些在任何給定時間點屬於一個決策表的規則。我試圖在FireAllRulesCommand類中使用RuleNameEndsWithAgendaFilter(「some suffix」),但Kie服務器沒有根據傳遞的AgendaFilter過濾規則。它每次都運行所有規則。Drools Kie服務器忽略AgendaFilter

Drools工作臺版本7.2.0.Final和Drools Kie服務器版本7.2.0.Final。

下面是相同的代碼片段:

KieServicesConfiguration configuration = KieServicesFactory.newRestConfiguration(serverUrl, user, password); 
Set<Class<?>> allClasses = new HashSet<Class<?>>(); 
allClasses.add(OrderItem.class); 
configuration.addExtraClasses(allClasses); 
configuration.setMarshallingFormat(MarshallingFormat.JAXB); 

OrderItem oi = new OrderItem("Mobile", 7000.00, 0.00, ""); 

KieServicesClient client = KieServicesFactory.newKieServicesClient(configuration); 

// work with rules 
List<ExecutableCommand<?>> commands = new ArrayList<ExecutableCommand<?>>(); 
BatchExecutionCommandImpl executionCommand = new BatchExecutionCommandImpl(commands, "defaultKieSession"); 

InsertObjectCommand insertObjectCommand = new InsertObjectCommand(); 
insertObjectCommand.setOutIdentifier("orderItem"); 
insertObjectCommand.setObject(oi); 

FireAllRulesCommand fireAllRulesCommand = new FireAllRulesCommand(); 
fireAllRulesCommand.setAgendaFilter(new RuleNameEndsWithAgendaFilter("MyRuleSuffix", true)); 

commands.add(insertObjectCommand); 
commands.add(fireAllRulesCommand); 

RuleServicesClient ruleClient = client.getServicesClient(RuleServicesClient.class); 

ServiceResponse<String> response = ruleClient.executeCommands(containerId, executionCommand); 
System.out.println(response.getResult()); 
+0

除非您提供議程過濾器的代碼,否則如何判斷這是否正確?此外,您的規則表的頂部行,也許作爲一個CSV文本。 – laune

+0

它是drools-core jar(版本:7.2.0.Final)的默認實現 –

回答

0

您不能使用標準類RuleNameEndsWithAgendaFilter用於過濾決策表的規則,因爲從一個表中的規則不具有相同的結局。

嘗試RuleNameStartsWithAgendaFilter,可能在重命名錶後。

+0

在我的情況下,RuleNameEndsWithAgendaFilter應該像我的規則名稱一樣工作,「Row 1 MyProject」,「Row 2 MyProject」,「Row 3 MyProject「..」Row n MyProject「。因此,RuleNameEndsWithAgendaFilter(「MyProject」)應該可以工作。 –

+0

那麼,如果你更清楚一切,爲什麼你會問問題? - 您是否嘗試在「RuleNameEndsWithAgendaFilter」的修改版本中打印實際規則名稱? - 不知道該規則表的文本是什麼樣子的,以及規則名稱是如何生成的。 – laune