首页 > 解决方案 > 使用rest调用规则服务时如何在json中分配规则流组

问题描述

我在使用规则流组定义的 brms7 中使用 rest 触发规则,我放置的 json 数据如下所示:

{        

 "commands": [
                {
                        "insert": {
                                "object": {
                                        "com.myspace.driver_department_traffic_violations.Violation": {
                                                "speedLimit": 40,
                                                "type": "Speed",
                                                "actualSpeed": 55
                                        }
                                }
                        }
                },             
                {
                        "fire-all-rules": {}
                },
                {
                        "get-objects": {
                                "out-identifier": "violation"
                        }
                },
                {
                        "dispose": {}
                }
        ]}

问题是如何在 json 数据中分配规则流组?服务器中的规则已分配规则流组,我需要在 json 中分配规则流组名称来触发规则。

提前谢谢了!

此致

标签: droolsredhat-brms

解决方案


我知道这个问题已经存在了一段时间,所以我只是在这里抛出答案,以防有人来寻找答案。

对于我的示例,规则流组称为“事件”。

{
  "lookup": "defaultKieSession",
  "commands": [
    {
      "insert": {
        "object": {
          "com.myspace.driver_department_traffic_violations.Violation": {
            "speedLimit": 40,
            "type": "Speed",
            "actualSpeed": 55
          }
        },
        "out-identifier": "violation"

      }
    },
    {
      "set-focus": {
        "name": "incident"
      }
    },
    {
      "fire-all-rules": {}
    }
  ]
}

对于决策服务器上的远程执行,您的代码应如下所示:

List<Command<?>> commands = new ArrayList<>();
KieServices kieServices = KieServices.Factory.get();
KieCommands commandFactory = kieServices.getCommands();
commands.add(commandFactory.newAgendaGroupSetFocus("incident"));

如果您想知道,AgendaGroups 也会以同样的方式处理。您可以从文档中阅读关于 SO 的摘录。


推荐阅读