如何在调用 kie api 容器时使用激活组?



我一直在尝试使用激活组,但我不知道如何从 Api rest 调用激活组?请帮助我如何在下面的请求中添加激活组。


package com.myteam.arduinodevre2;
//from row number: 1
rule "Row 1 Rulduino"
activation-group "gold"
dialect "mvel"
when
f1 : ArduinoEntity( switchOn == true , voltaj >= 1000 , voltaj < 2000 )
then
modify( f1 ) {
setLightOn( true )
}
end
//from row number: 2
rule "Row 2 Rulduino"
activation-group "gold"
dialect "mvel"
when
f1 : ArduinoEntity( switchOn == true , voltaj >= 5000.0 , voltaj < 10000.0 )
then
modify( f1 ) {
setLightOn( false )
}
end
//from row number: 3
rule "Row 3 Rulduino"
activation-group "gold"
dialect "mvel"
when
f1 : ArduinoEntity( switchOn == false )
then
modify( f1 ) {
setLightOn( false )
}
end
//from row number: 4
rule "Row 4 Rulduino"
activation-group "silver"
dialect "mvel"
when
f1 : ArduinoEntity( switchOn == true , voltaj >= 1.0 , voltaj < 3.0 )
then
modify( f1 ) {
setLightOn( false )
}
end

{
"commands": [
{
"insert": {
"object": {
"com.myteam.arduinodevre2.ArduinoEntity": {
"switchOn": true,
"voltaj": 1100
}
},
"out-identifier": "ArduinoEntity",
"return-object": true
}
},
{
"fire-all-rules": "" ,
"fire-targetgroup": "silver"
}
]
}

我怎样才能通过使用这个东西的亲属来触发我的目标激活组 ->"触发所有规则":"银" 但我无法通过谷歌搜索找到有价值的答案。

您可以从 KieSession 获取 ActivationGroup,而不是从 KieContainer 获取。您需要从 KieContainer 创建一个 KieSession,然后使用kieSession.getAgenda((.getActivationGroup("(.setfocus(( 方法来获取 ActivationGroup。您可以查看此链接以检查方法返回类型以及与之相关的其他方法。

您不调用激活组。您可能指的是议程组。您可以将焦点设置在议程组上,该议程组的所有规则都有资格触发。

您可以更进一步,将激活组添加到规则中,这将只触发该组中的一个规则。

为了从 REST API "调用"议程组,您需要像这样设置焦点:

{
"commands": [
{
"set-focus": "myAgendaGroup"
},
{
"insert": {
"object": {
"com.myteam.arduinodevre2.ArduinoEntity": {
"switchOn": true,
"voltaj": 1100
}
}
}
},
{
"fire-all-rules": {}
}
]
}

最新更新