Search in sources :

Example 6 with DmnDecision

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");
}
Also used : InputStream(java.io.InputStream) DmnDecisionRequirementsGraph(org.camunda.bpm.dmn.engine.DmnDecisionRequirementsGraph) DmnDecision(org.camunda.bpm.dmn.engine.DmnDecision) Test(org.junit.Test) DmnEngineTest(org.camunda.bpm.dmn.engine.test.DmnEngineTest)

Example 7 with DmnDecision

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");
}
Also used : DmnDecision(org.camunda.bpm.dmn.engine.DmnDecision) Test(org.junit.Test) DmnEngineTest(org.camunda.bpm.dmn.engine.test.DmnEngineTest)

Example 8 with DmnDecision

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);
}
Also used : InputStream(java.io.InputStream) DmnModelInstance(org.camunda.bpm.model.dmn.DmnModelInstance) DmnDecision(org.camunda.bpm.dmn.engine.DmnDecision) Test(org.junit.Test) DmnEngineTest(org.camunda.bpm.dmn.engine.test.DmnEngineTest)

Example 9 with DmnDecision

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;
}
Also used : DmnDecisionResult(org.camunda.bpm.dmn.engine.DmnDecisionResult) DmnDecisionLogicEvaluationHandler(org.camunda.bpm.dmn.engine.impl.evaluation.DmnDecisionLogicEvaluationHandler) VariableMap(org.camunda.bpm.engine.variable.VariableMap) DmnDecisionLogicEvaluationEvent(org.camunda.bpm.dmn.engine.delegate.DmnDecisionLogicEvaluationEvent) ArrayList(java.util.ArrayList) DmnDecision(org.camunda.bpm.dmn.engine.DmnDecision)

Example 10 with DmnDecision

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);
}
Also used : DmnDecision(org.camunda.bpm.dmn.engine.DmnDecision)

Aggregations

DmnDecision (org.camunda.bpm.dmn.engine.DmnDecision)27 DmnEngineTest (org.camunda.bpm.dmn.engine.test.DmnEngineTest)9 Test (org.junit.Test)9 InputStream (java.io.InputStream)8 Decision (org.camunda.bpm.model.dmn.instance.Decision)7 ArrayList (java.util.ArrayList)5 DmnModelInstance (org.camunda.bpm.model.dmn.DmnModelInstance)5 DmnDecisionImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionImpl)3 DmnDecisionLiteralExpressionImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionLiteralExpressionImpl)2 DmnDecisionTableImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl)2 Definitions (org.camunda.bpm.model.dmn.instance.Definitions)2 List (java.util.List)1 DmnDecisionRequirementsGraph (org.camunda.bpm.dmn.engine.DmnDecisionRequirementsGraph)1 DmnDecisionResult (org.camunda.bpm.dmn.engine.DmnDecisionResult)1 DmnEngine (org.camunda.bpm.dmn.engine.DmnEngine)1 DmnDecisionLogicEvaluationEvent (org.camunda.bpm.dmn.engine.delegate.DmnDecisionLogicEvaluationEvent)1 DmnDecisionRequirementsGraphImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionRequirementsGraphImpl)1 DmnExpressionImpl (org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl)1 DmnVariableImpl (org.camunda.bpm.dmn.engine.impl.DmnVariableImpl)1 DmnDecisionLogicEvaluationHandler (org.camunda.bpm.dmn.engine.impl.evaluation.DmnDecisionLogicEvaluationHandler)1