0

I am using the REST api for executing rules on Decision Server (Redhat Decision Manager 7.2) using a stateless kie session. I'm currently getting the number of triggered rules, but I also want to get the names of those rules. Is this possible?

KieServicesConfiguration conf = KieServicesFactory.newRestConfiguration(URL, USER, PASSWORD);

List<GenericCommand<?>> commands = new ArrayList<GenericCommand<?>>();

commands.add((GenericCommand<?>)
KieServices.Factory.get().getCommands().newInsert(applicant, "applicant"));

commands.add((GenericCommand<?>)
KieServices.Factory.get().getCommands().newInsert(loan, "loan"));

commands.add((GenericCommand<?>)KieServices.Factory.get().getCommands().newFireAllRules("numberOfFiredRules"));

KieCommands kieCommands = KieServices.Factory.get().getCommands();

BatchExecutionCommand batchCommand = kieCommands.newBatchExecution(commands, "default-stateless-ksession");

ServiceResponse<ExecutionResults> executeResponse = ruleServicesClient
                .executeCommandsWithResults("loan-application_1.2.0", batchCommand);

System.out.println("Number of fired rules:" executeResponse.getResult().getValue("numberOfFiredRules"));
Roddy of the Frozen Peas
  • 14,380
  • 9
  • 49
  • 99
kamilc
  • 15
  • 4

2 Answers2

0

You have to use an AgendaEventListener to keep track of rules exectioned. By implemnting org.kie.api.event.rule.AgendaEventListener interface you can capture these detials.

Abhijit Humbe
  • 1,563
  • 1
  • 12
  • 13
  • I am executing rules on the Decision Server, I have only serverUrl, containerName and BatchExecutionCommand. I dont have **KieSession** so ı dont able to do `kSession.addEventListener(new DefaultAgendaEventListener() { ...}`. Can you explain ı dont geti it. – kamilc May 07 '20 at 13:47
  • If you are using Decision-server for rule execution then you have to add custom AgendaListener class in classpath of kie-server.war file and register listener in kie-deployment-descriptor.xml file under eventListener tag – Abhijit Humbe May 07 '20 at 15:11
  • Listener will capture details at server side. There is no way we can get details about executed rules at client side – Abhijit Humbe May 07 '20 at 15:19
0

To know which rules are triggered I added an action column with custom code (Action BRL fragment) that writes the rule name in one of the field of my fact. You can get it from rule.name. Example:myFact.logMyRuleName(rule.name)

userp8975
  • 1
  • 1