I’m trying the following example (camunda examples git hub)
/dmn-engine/dmn-engine-java-main-method
to create my own simulator
camunda.com dmn simulator
(trying to highlight the rules that are satisfied for the given input)
Where/How can i get the list of rules that got executed/satisfied for the given input (All meta data that is related to the current execution)
JBoss DROOLS Equivalent will be something like below
stackoverflow.com \ questions\ 19951880 \ drools-how-to-find-out-which-all-rules-were-matched
soarer
August 23, 2020, 4:44pm
2
Hello Mallesh,
After we talked about the listener in JBoss drools during dinner last night, you got me thinking. Did a little bit of digging into Camunda’s code base and found this Listener
DmnDecisionEvaluationListener that receives this event DmnDecisionEvaluationEvent from which you can get DmnDecisionLogicEvaluationEvent which has getExecutedDecisionElements method that seems to be returning what we are looking for. Did not try this but seems promising…
try running this test…
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.camunda.bpm.dmn.engine.delegate;
import static org.assertj.core.api.Assertions.assertThat;
This file has been truncated. show original
Confirming. This is working. Pl see below code
// create a new default DMN engine
DefaultDmnEngineConfiguration dmnEngineConfiguration = (DefaultDmnEngineConfiguration)
DmnEngineConfiguration.createDefaultDmnEngineConfiguration();
dmnEngineConfiguration.customPostDecisionTableEvaluationListeners(Collections.singletonList(
new DmnDecisionTableEvaluationListener(){
@Override
public void notify(DmnDecisionTableEvaluationEvent event)
{
Map<String, TypedValue> inputVars = event.getInputs().stream().collect(Collectors.toMap(DmnEvaluatedInput::getName, DmnEvaluatedInput::getValue));
System.out.println("InputVars :"+inputVars);
}
}));
//DmnEngine dmnEngine = DmnEngineConfiguration.createDefaultDmnEngineConfiguration().buildEngine();
DmnEngine dmnEngine = dmnEngineConfiguration.buildEngine();
// parse decision from resource input stream
InputStream inputStream = DishDecider.class.getResourceAsStream("dish-decision.dmn11.xml");
try {
// Mallesh
List<DmnDecision> decisions = dmnEngine.parseDecisions(inputStream);
//DmnDecision decision = dmnEngine.parseDecision("decision", inputStream);
DmnDecision decision = decisions.get(0);
if(decision.isDecisionTable()) {
//HitPolicy hitPolicy = decisionTable.getHitPolicy();
}
// evaluate decision
DmnDecisionTableResult result = dmnEngine.evaluateDecisionTable(decision, variables);
// print result
String desiredDish = result.getSingleResult().getSingleEntry();
System.out.println("Dish Decision:\n\tI would recommend to serve: " + desiredDish);
}
finally {
try {
inputStream.close();
}
catch (IOException e) {
System.err.println("Could not close stream: "+e.getMessage());
}
}