Search in sources :

Example 1 with DmnDecisionTableImpl

use of org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl in project camunda-engine-dmn by camunda.

the class DmnTransformTest method shouldTransformRules.

@Test
public void shouldTransformRules() {
    DmnDecisionImpl decisionEntity = (DmnDecisionImpl) parseDecisionFromFile("decision1", TRANSFORM_DMN);
    DmnDecisionTableImpl decisionTable = (DmnDecisionTableImpl) decisionEntity.getDecisionLogic();
    List<DmnDecisionTableRuleImpl> rules = decisionTable.getRules();
    assertThat(rules).hasSize(1);
    DmnDecisionTableRuleImpl rule = rules.get(0);
    List<DmnExpressionImpl> conditions = rule.getConditions();
    assertThat(conditions).hasSize(2);
    DmnExpressionImpl condition = conditions.get(0);
    assertThat(condition.getId()).isEqualTo("inputEntry");
    assertThat(condition.getName()).isEqualTo("camunda");
    assertThat(condition.getExpressionLanguage()).isEqualTo("camunda");
    assertThat(condition.getExpression()).isEqualTo("camunda");
    condition = conditions.get(1);
    assertThat(condition.getId()).isNull();
    assertThat(condition.getName()).isNull();
    assertThat(condition.getExpressionLanguage()).isNull();
    assertThat(condition.getExpression()).isNull();
    List<DmnExpressionImpl> conclusions = rule.getConclusions();
    assertThat(conclusions).hasSize(2);
    DmnExpressionImpl dmnOutputEntry = conclusions.get(0);
    assertThat(dmnOutputEntry.getId()).isEqualTo("outputEntry");
    assertThat(dmnOutputEntry.getName()).isEqualTo("camunda");
    assertThat(dmnOutputEntry.getExpressionLanguage()).isEqualTo("camunda");
    assertThat(dmnOutputEntry.getExpression()).isEqualTo("camunda");
    dmnOutputEntry = conclusions.get(1);
    assertThat(dmnOutputEntry.getId()).isNull();
    assertThat(dmnOutputEntry.getName()).isNull();
    assertThat(dmnOutputEntry.getExpressionLanguage()).isNull();
    assertThat(dmnOutputEntry.getExpression()).isNull();
}
Also used : DmnDecisionTableImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl) DmnExpressionImpl(org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl) DmnDecisionImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionImpl) DmnDecisionTableRuleImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableRuleImpl) Test(org.junit.Test) DmnEngineTest(org.camunda.bpm.dmn.engine.test.DmnEngineTest)

Example 2 with DmnDecisionTableImpl

use of org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl in project camunda-engine-dmn by camunda.

the class ExpressionLanguageTest method testGlobalExpressionLanguageDecisionTable.

@Test
@DecisionResource(resource = GROOVY_DECISION_TABLE_DMN)
public void testGlobalExpressionLanguageDecisionTable() {
    DmnDecisionTableImpl decisionTable = (DmnDecisionTableImpl) decision.getDecisionLogic();
    for (DmnDecisionTableInputImpl dmnInput : decisionTable.getInputs()) {
        assertThat(dmnInput.getExpression().getExpressionLanguage()).isEqualTo("groovy");
    }
    for (DmnDecisionTableRuleImpl dmnRule : decisionTable.getRules()) {
        for (DmnExpressionImpl condition : dmnRule.getConditions()) {
            assertThat(condition.getExpressionLanguage()).isEqualTo("groovy");
        }
        for (DmnExpressionImpl conclusion : dmnRule.getConclusions()) {
            assertThat(conclusion.getExpressionLanguage()).isEqualTo("groovy");
        }
    }
    assertExample(dmnEngine, decision);
    verify(scriptEngineResolver, atLeastOnce()).getScriptEngineForLanguage("groovy");
    verify(scriptEngineResolver, never()).getScriptEngineForLanguage(JUEL);
}
Also used : DmnDecisionTableInputImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableInputImpl) DmnDecisionTableImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl) DmnExpressionImpl(org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl) DmnDecisionTableRuleImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableRuleImpl) Test(org.junit.Test) DmnEngineTest(org.camunda.bpm.dmn.engine.test.DmnEngineTest) DecisionResource(org.camunda.bpm.dmn.engine.test.DecisionResource)

Example 3 with DmnDecisionTableImpl

use of org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl in project camunda-engine-dmn by camunda.

the class DmnTransformTest method shouldTransformOutputs.

@Test
public void shouldTransformOutputs() {
    DmnDecisionImpl decisionEntity = (DmnDecisionImpl) parseDecisionFromFile("decision1", TRANSFORM_DMN);
    DmnDecisionTableImpl decisionTable = (DmnDecisionTableImpl) decisionEntity.getDecisionLogic();
    List<DmnDecisionTableOutputImpl> outputs = decisionTable.getOutputs();
    assertThat(outputs).hasSize(2);
    DmnDecisionTableOutputImpl output = outputs.get(0);
    assertThat(output.getId()).isEqualTo("output1");
    assertThat(output.getName()).isEqualTo("camunda");
    assertThat(output.getOutputName()).isEqualTo("camunda");
    assertThat(output.getTypeDefinition()).isNotNull();
    assertThat(output.getTypeDefinition().getTypeName()).isEqualTo("string");
    output = outputs.get(1);
    assertThat(output.getId()).isEqualTo("output2");
    assertThat(output.getName()).isNull();
    assertThat(output.getOutputName()).isEqualTo("out2");
    assertThat(output.getTypeDefinition()).isNotNull();
    assertThat(output.getTypeDefinition()).isEqualTo(new DefaultTypeDefinition());
}
Also used : DmnDecisionTableOutputImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableOutputImpl) DefaultTypeDefinition(org.camunda.bpm.dmn.engine.impl.type.DefaultTypeDefinition) DmnDecisionTableImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl) DmnDecisionImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionImpl) Test(org.junit.Test) DmnEngineTest(org.camunda.bpm.dmn.engine.test.DmnEngineTest)

Example 4 with DmnDecisionTableImpl

use of org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl in project camunda-engine-dmn by camunda.

the class DefaultDmnTransform method transformDecisionTable.

protected DmnDecisionTableImpl transformDecisionTable(DecisionTable decisionTable) {
    DmnElementTransformHandler<DecisionTable, DmnDecisionTableImpl> handler = handlerRegistry.getHandler(DecisionTable.class);
    DmnDecisionTableImpl dmnDecisionTable = handler.handleElement(this, decisionTable);
    for (Input input : decisionTable.getInputs()) {
        parent = dmnDecisionTable;
        this.decisionTable = dmnDecisionTable;
        DmnDecisionTableInputImpl dmnInput = transformDecisionTableInput(input);
        if (dmnInput != null) {
            dmnDecisionTable.getInputs().add(dmnInput);
            notifyTransformListeners(input, dmnInput);
        }
    }
    boolean needsName = decisionTable.getOutputs().size() > 1;
    Set<String> usedNames = new HashSet<String>();
    for (Output output : decisionTable.getOutputs()) {
        parent = dmnDecisionTable;
        this.decisionTable = dmnDecisionTable;
        DmnDecisionTableOutputImpl dmnOutput = transformDecisionTableOutput(output);
        if (dmnOutput != null) {
            // validate output name
            String outputName = dmnOutput.getOutputName();
            if (needsName && outputName == null) {
                throw LOG.compoundOutputsShouldHaveAnOutputName(dmnDecisionTable, dmnOutput);
            }
            if (usedNames.contains(outputName)) {
                throw LOG.compoundOutputWithDuplicateName(dmnDecisionTable, dmnOutput);
            }
            usedNames.add(outputName);
            dmnDecisionTable.getOutputs().add(dmnOutput);
            notifyTransformListeners(output, dmnOutput);
        }
    }
    for (Rule rule : decisionTable.getRules()) {
        parent = dmnDecisionTable;
        this.decisionTable = dmnDecisionTable;
        DmnDecisionTableRuleImpl dmnRule = transformDecisionTableRule(rule);
        if (dmnRule != null) {
            dmnDecisionTable.getRules().add(dmnRule);
            notifyTransformListeners(rule, dmnRule);
        }
    }
    return dmnDecisionTable;
}
Also used : DmnDecisionTableImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl) DmnDecisionTableInputImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableInputImpl) DmnDecisionTableOutputImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableOutputImpl) DecisionTable(org.camunda.bpm.model.dmn.instance.DecisionTable) Input(org.camunda.bpm.model.dmn.instance.Input) Output(org.camunda.bpm.model.dmn.instance.Output) DmnDecisionTableRuleImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableRuleImpl) Rule(org.camunda.bpm.model.dmn.instance.Rule) HashSet(java.util.HashSet)

Example 5 with DmnDecisionTableImpl

use of org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl in project camunda-engine-dmn by camunda.

the class DecisionTableEvaluationHandler method evaluate.

@Override
public DmnDecisionLogicEvaluationEvent evaluate(DmnDecision decision, VariableContext variableContext) {
    DmnDecisionTableEvaluationEventImpl evaluationResult = new DmnDecisionTableEvaluationEventImpl();
    evaluationResult.setDecisionTable(decision);
    DmnDecisionTableImpl decisionTable = (DmnDecisionTableImpl) decision.getDecisionLogic();
    evaluationResult.setExecutedDecisionElements(calculateExecutedDecisionElements(decisionTable));
    evaluateDecisionTable(decisionTable, variableContext, evaluationResult);
    // apply hit policy
    decisionTable.getHitPolicyHandler().apply(evaluationResult);
    // notify listeners
    for (DmnDecisionTableEvaluationListener evaluationListener : evaluationListeners) {
        evaluationListener.notify(evaluationResult);
    }
    return evaluationResult;
}
Also used : DmnDecisionTableImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl) DmnDecisionTableEvaluationEventImpl(org.camunda.bpm.dmn.engine.impl.delegate.DmnDecisionTableEvaluationEventImpl) DmnDecisionTableEvaluationListener(org.camunda.bpm.dmn.engine.delegate.DmnDecisionTableEvaluationListener)

Aggregations

DmnDecisionTableImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl)10 DmnEngineTest (org.camunda.bpm.dmn.engine.test.DmnEngineTest)5 Test (org.junit.Test)5 DmnDecisionImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionImpl)4 DmnDecisionTableInputImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableInputImpl)3 DmnDecisionTableRuleImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableRuleImpl)3 DmnExpressionImpl (org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl)3 DmnDecision (org.camunda.bpm.dmn.engine.DmnDecision)2 DmnDecisionTableOutputImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableOutputImpl)2 DefaultTypeDefinition (org.camunda.bpm.dmn.engine.impl.type.DefaultTypeDefinition)2 DecisionTable (org.camunda.bpm.model.dmn.instance.DecisionTable)2 HashSet (java.util.HashSet)1 DmnDecisionTableEvaluationListener (org.camunda.bpm.dmn.engine.delegate.DmnDecisionTableEvaluationListener)1 DmnDecisionLiteralExpressionImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionLiteralExpressionImpl)1 DmnDecisionTableEvaluationEventImpl (org.camunda.bpm.dmn.engine.impl.delegate.DmnDecisionTableEvaluationEventImpl)1 DmnHitPolicyHandler (org.camunda.bpm.dmn.engine.impl.spi.hitpolicy.DmnHitPolicyHandler)1 DecisionResource (org.camunda.bpm.dmn.engine.test.DecisionResource)1 Decision (org.camunda.bpm.model.dmn.instance.Decision)1 Expression (org.camunda.bpm.model.dmn.instance.Expression)1 Input (org.camunda.bpm.model.dmn.instance.Input)1