use of org.camunda.bpm.dmn.engine.DmnDecision in project camunda-engine-dmn by camunda.
the class DmnTransformTest method shouldTransformDecisionRequirementsGraph.
@Test
public void shouldTransformDecisionRequirementsGraph() {
InputStream inputStream = IoUtil.fileAsStream(REQUIRED_DECISIONS_DMN);
DmnDecisionRequirementsGraph drg = dmnEngine.parseDecisionRequirementsGraph(inputStream);
assertThat(drg).isNotNull();
assertThat(drg.getKey()).isEqualTo("buy-decision");
assertThat(drg.getName()).isEqualTo("Buy Decision");
assertThat(drg.getDecisionKeys()).hasSize(3).contains("buyProduct", "buyComputer", "buyElectronic");
Collection<DmnDecision> decisions = drg.getDecisions();
assertThat(decisions).hasSize(3).extracting("key").contains("buyProduct", "buyComputer", "buyElectronic");
}
use of org.camunda.bpm.dmn.engine.DmnDecision in project camunda-engine-dmn by camunda.
the class DmnTransformTest method shouldTransformDecisions.
@Test
public void shouldTransformDecisions() {
List<DmnDecision> decisions = parseDecisionsFromFile(TRANSFORM_DMN);
assertThat(decisions).hasSize(2);
DmnDecision decision = decisions.get(0);
assertThat(decision).isNotNull();
assertThat(decision.getKey()).isEqualTo("decision1");
assertThat(decision.getName()).isEqualTo("camunda");
// decision2 should be ignored as it isn't supported by the DMN engine
decision = decisions.get(1);
assertThat(decision).isNotNull();
assertThat(decision.getKey()).isEqualTo("decision3");
assertThat(decision.getName()).isEqualTo("camunda");
}
use of org.camunda.bpm.dmn.engine.DmnDecision in project camunda-engine-dmn by camunda.
the class DmnTransformTest method shouldParseDecisionWithRequiredDecisions.
@Test
public void shouldParseDecisionWithRequiredDecisions() {
InputStream inputStream = IoUtil.fileAsStream(REQUIRED_DECISIONS_DMN);
DmnModelInstance modelInstance = Dmn.readModelFromStream(inputStream);
DmnDecision buyProductDecision = dmnEngine.parseDecision("buyProduct", modelInstance);
assertDecision(buyProductDecision, "buyProduct");
Collection<DmnDecision> buyProductrequiredDecisions = buyProductDecision.getRequiredDecisions();
assertThat(buyProductrequiredDecisions.size()).isEqualTo(1);
DmnDecision buyComputerDecision = getDecision(buyProductrequiredDecisions, "buyComputer");
assertThat(buyComputerDecision).isNotNull();
Collection<DmnDecision> buyComputerRequiredDecision = buyComputerDecision.getRequiredDecisions();
assertThat(buyComputerRequiredDecision.size()).isEqualTo(1);
DmnDecision buyElectronicDecision = getDecision(buyComputerRequiredDecision, "buyElectronic");
assertThat(buyElectronicDecision).isNotNull();
assertThat(buyElectronicDecision.getRequiredDecisions().size()).isEqualTo(0);
}
use of org.camunda.bpm.dmn.engine.DmnDecision in project camunda-engine-dmn by camunda.
the class DefaultDmnDecisionContext method evaluateDecision.
/**
* Evaluate a decision with the given {@link VariableContext}
*
* @param decision the decision to evaluate
* @param variableContext the available variable context
* @return the result of the decision evaluation
*/
public DmnDecisionResult evaluateDecision(DmnDecision decision, VariableContext variableContext) {
if (decision.getKey() == null) {
throw LOG.unableToFindAnyDecisionTable();
}
VariableMap variableMap = buildVariableMapFromVariableContext(variableContext);
List<DmnDecision> requiredDecisions = new ArrayList<DmnDecision>();
buildDecisionTree(decision, requiredDecisions);
List<DmnDecisionLogicEvaluationEvent> evaluatedEvents = new ArrayList<DmnDecisionLogicEvaluationEvent>();
DmnDecisionResult evaluatedResult = null;
for (DmnDecision evaluateDecision : requiredDecisions) {
DmnDecisionLogicEvaluationHandler handler = getDecisionEvaluationHandler(evaluateDecision);
DmnDecisionLogicEvaluationEvent evaluatedEvent = handler.evaluate(evaluateDecision, variableMap.asVariableContext());
evaluatedEvents.add(evaluatedEvent);
evaluatedResult = handler.generateDecisionResult(evaluatedEvent);
if (decision != evaluateDecision) {
addResultToVariableContext(evaluatedResult, variableMap, evaluateDecision);
}
}
generateDecisionEvaluationEvent(evaluatedEvents);
return evaluatedResult;
}
use of org.camunda.bpm.dmn.engine.DmnDecision in project camunda-engine-dmn by camunda.
the class DefaultDmnEngine method evaluateDecisionTable.
public DmnDecisionTableResult evaluateDecisionTable(String decisionKey, DmnModelInstance dmnModelInstance, VariableContext variableContext) {
ensureNotNull("decisionKey", decisionKey);
List<DmnDecision> decisions = parseDecisions(dmnModelInstance);
for (DmnDecision decision : decisions) {
if (decisionKey.equals(decision.getKey())) {
return evaluateDecisionTable(decision, variableContext);
}
}
throw LOG.unableToFindDecisionWithKey(decisionKey);
}
Aggregations