我是 Kie Workbench 的新手。我正在使用 Java Rest 调用来触发 kie 工作台中的规则。请在下面找到代码:
public class RuleEngineConnector {
@Value("${brms.execution.server.url}")
private String SERVER_URL;
@Value("${brms.execution.server.username}")
private String USER;
@Value("${brms.execution.server.password}")
private String PASSWORD;
@Value("${brms.containerId}")
private String CONTAINER_ID;
private static final MarshallingFormat FORMAT = MarshallingFormat.JAXB;
public String getAdapter(AdapterRuleDO adapterRule) {
KieServicesConfiguration cfg = KieServicesFactory.newRestConfiguration(SERVER_URL, USER, PASSWORD);
cfg.setMarshallingFormat(FORMAT);
Set<Class<?>> extraClasses = new HashSet<Class<?>>();
extraClasses.add(AdapterRuleDO.class);
cfg.addJaxbClasses(extraClasses);
KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(cfg);
ServiceResponse<ExecutionResults> response = getRulesResponse(adapterRule, kieServicesClient);
List<AdapterRuleDO> listOfObjects = (List<AdapterRuleDO>) response.getResult().getValue("get-adapter");//to be changed
return listOfObjects.get(0).getAdapterName();
}
private ServiceResponse<ExecutionResults> getRulesResponse(AdapterRuleDO adapterRule, KieServicesClient kieServicesClient) {
List<Command<?>> commands = new ArrayList<Command<?>>();
KieCommands commandsFactory = KieServices.Factory.get().getCommands();
commands.add(commandsFactory.newInsert(adapterRule, "adapterRule"));
commands.add(commandsFactory.newFireAllRules());
commands.add(commandsFactory.newGetObjects("get-adapter"));
BatchExecutionCommand batchExecution = commandsFactory.newBatchExecution(commands);
RuleServicesClient ruleServicesClient = kieServicesClient.getServicesClient(RuleServicesClient.class);
ServiceResponse<ExecutionResults> response = ruleServicesClient.executeCommandsWithResults(CONTAINER_ID, batchExecution);
return response;
}
}
我正在正确触发规则,并且在触发规则后,AdapterRuleDO 类中的值会正确更新。一个问题是,当我再次调用此方法以第二次执行规则时,我收到两个 AdapterRuleDO 对象,并且对于每个后续调用,我都会获得一个额外的对象。似乎会话中的对象已存储,并且每次调用都不会被清除。我怎样才能为每次调用实现这一点,我只会得到一个 AdapterRuleDO 对象作为回报?
请注意,我只有一个这样的决策表,其中使用了这一事实。