Search in sources :

Example 6 with DmnExpressionImpl

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

the class DecisionTableEvaluationHandler method evaluateOutputEntries.

protected Map<String, DmnEvaluatedOutput> evaluateOutputEntries(List<DmnDecisionTableOutputImpl> decisionTableOutputs, DmnDecisionTableRuleImpl matchingRule, VariableContext variableContext) {
    Map<String, DmnEvaluatedOutput> outputEntries = new LinkedHashMap<String, DmnEvaluatedOutput>();
    for (int outputIdx = 0; outputIdx < decisionTableOutputs.size(); outputIdx++) {
        // evaluate output entry, skip empty expressions
        DmnExpressionImpl conclusion = matchingRule.getConclusions().get(outputIdx);
        if (isNonEmptyExpression(conclusion)) {
            Object value = evaluateOutputEntry(conclusion, variableContext);
            // transform to output type
            DmnDecisionTableOutputImpl decisionTableOutput = decisionTableOutputs.get(outputIdx);
            TypedValue typedValue = decisionTableOutput.getTypeDefinition().transform(value);
            // set on result
            DmnEvaluatedOutputImpl evaluatedOutput = new DmnEvaluatedOutputImpl(decisionTableOutput, typedValue);
            outputEntries.put(decisionTableOutput.getOutputName(), evaluatedOutput);
        }
    }
    return outputEntries;
}
Also used : DmnDecisionTableOutputImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableOutputImpl) DmnExpressionImpl(org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl) DmnEvaluatedOutput(org.camunda.bpm.dmn.engine.delegate.DmnEvaluatedOutput) DmnEvaluatedOutputImpl(org.camunda.bpm.dmn.engine.impl.delegate.DmnEvaluatedOutputImpl) LinkedHashMap(java.util.LinkedHashMap) TypedValue(org.camunda.bpm.engine.variable.value.TypedValue)

Example 7 with DmnExpressionImpl

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

the class DmnTransformTest method shouldTransformDecisionWithLiteralExpression.

@Test
public void shouldTransformDecisionWithLiteralExpression() {
    List<DmnDecision> decisions = parseDecisionsFromFile(DECISION_WITH_LITERAL_EXPRESSION_DMN);
    assertThat(decisions).hasSize(1);
    DmnDecision decision = decisions.get(0);
    assertThat(decision).isNotNull();
    assertThat(decision.getKey()).isEqualTo("decision");
    assertThat(decision.getName()).isEqualTo("Decision");
    assertThat(decision.getDecisionLogic()).isNotNull().isInstanceOf(DmnDecisionLiteralExpressionImpl.class);
    DmnDecisionLiteralExpressionImpl dmnDecisionLiteralExpression = (DmnDecisionLiteralExpressionImpl) decision.getDecisionLogic();
    DmnVariableImpl variable = dmnDecisionLiteralExpression.getVariable();
    assertThat(variable).isNotNull();
    assertThat(variable.getId()).isEqualTo("v1");
    assertThat(variable.getName()).isEqualTo("c");
    assertThat(variable.getTypeDefinition()).isNotNull();
    assertThat(variable.getTypeDefinition().getTypeName()).isEqualTo("integer");
    DmnExpressionImpl dmnExpression = dmnDecisionLiteralExpression.getExpression();
    assertThat(dmnExpression).isNotNull();
    assertThat(dmnExpression.getId()).isEqualTo("e1");
    assertThat(dmnExpression.getExpressionLanguage()).isEqualTo("groovy");
    assertThat(dmnExpression.getExpression()).isEqualTo("a + b");
    assertThat(dmnExpression.getTypeDefinition()).isNull();
}
Also used : DmnVariableImpl(org.camunda.bpm.dmn.engine.impl.DmnVariableImpl) DmnExpressionImpl(org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl) DmnDecisionLiteralExpressionImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionLiteralExpressionImpl) DmnDecision(org.camunda.bpm.dmn.engine.DmnDecision) Test(org.junit.Test) DmnEngineTest(org.camunda.bpm.dmn.engine.test.DmnEngineTest)

Example 8 with DmnExpressionImpl

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

the class DmnTransformTest method shouldTransformInputs.

@Test
public void shouldTransformInputs() {
    DmnDecisionImpl decisionEntity = (DmnDecisionImpl) parseDecisionFromFile("decision1", TRANSFORM_DMN);
    DmnDecisionTableImpl decisionTable = (DmnDecisionTableImpl) decisionEntity.getDecisionLogic();
    List<DmnDecisionTableInputImpl> inputs = decisionTable.getInputs();
    assertThat(inputs).hasSize(2);
    DmnDecisionTableInputImpl input = inputs.get(0);
    assertThat(input.getId()).isEqualTo("input1");
    assertThat(input.getName()).isEqualTo("camunda");
    assertThat(input.getInputVariable()).isEqualTo("camunda");
    DmnExpressionImpl inputExpression = input.getExpression();
    assertThat(inputExpression).isNotNull();
    assertThat(inputExpression.getId()).isEqualTo("inputExpression");
    assertThat(inputExpression.getName()).isNull();
    assertThat(inputExpression.getExpressionLanguage()).isEqualTo("camunda");
    assertThat(inputExpression.getExpression()).isEqualTo("camunda");
    assertThat(inputExpression.getTypeDefinition()).isNotNull();
    assertThat(inputExpression.getTypeDefinition().getTypeName()).isEqualTo("string");
    input = inputs.get(1);
    assertThat(input.getId()).isEqualTo("input2");
    assertThat(input.getName()).isNull();
    assertThat(input.getInputVariable()).isEqualTo(DmnDecisionTableInputImpl.DEFAULT_INPUT_VARIABLE_NAME);
    inputExpression = input.getExpression();
    assertThat(inputExpression).isNotNull();
    assertThat(inputExpression.getId()).isNull();
    assertThat(inputExpression.getName()).isNull();
    assertThat(inputExpression.getExpressionLanguage()).isNull();
    assertThat(inputExpression.getExpression()).isNull();
    assertThat(inputExpression.getTypeDefinition()).isNotNull();
    assertThat(inputExpression.getTypeDefinition()).isEqualTo(new DefaultTypeDefinition());
}
Also used : DmnDecisionTableInputImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableInputImpl) DefaultTypeDefinition(org.camunda.bpm.dmn.engine.impl.type.DefaultTypeDefinition) DmnDecisionTableImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl) DmnExpressionImpl(org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl) DmnDecisionImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionImpl) Test(org.junit.Test) DmnEngineTest(org.camunda.bpm.dmn.engine.test.DmnEngineTest)

Example 9 with DmnExpressionImpl

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

the class DefaultDmnTransform method transformDecisionTableInput.

protected DmnDecisionTableInputImpl transformDecisionTableInput(Input input) {
    DmnElementTransformHandler<Input, DmnDecisionTableInputImpl> handler = handlerRegistry.getHandler(Input.class);
    DmnDecisionTableInputImpl dmnInput = handler.handleElement(this, input);
    // validate input id
    if (dmnInput.getId() == null) {
        throw LOG.decisionTableInputIdIsMissing(decision, dmnInput);
    }
    InputExpression inputExpression = input.getInputExpression();
    if (inputExpression != null) {
        parent = dmnInput;
        DmnExpressionImpl dmnExpression = transformInputExpression(inputExpression);
        if (dmnExpression != null) {
            dmnInput.setExpression(dmnExpression);
        }
    }
    return dmnInput;
}
Also used : DmnDecisionTableInputImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableInputImpl) DmnExpressionImpl(org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl) Input(org.camunda.bpm.model.dmn.instance.Input) InputExpression(org.camunda.bpm.model.dmn.instance.InputExpression)

Example 10 with DmnExpressionImpl

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

the class DefaultDmnTransform method transformDecisionLiteralExpression.

protected DmnDecisionLiteralExpressionImpl transformDecisionLiteralExpression(Decision decision, LiteralExpression literalExpression) {
    DmnDecisionLiteralExpressionImpl dmnDecisionLiteralExpression = new DmnDecisionLiteralExpressionImpl();
    Variable variable = decision.getVariable();
    if (variable == null) {
        throw LOG.decisionVariableIsMissing(decision.getId());
    }
    DmnVariableImpl dmnVariable = transformVariable(variable);
    dmnDecisionLiteralExpression.setVariable(dmnVariable);
    DmnExpressionImpl dmnLiteralExpression = transformLiteralExpression(literalExpression);
    dmnDecisionLiteralExpression.setExpression(dmnLiteralExpression);
    return dmnDecisionLiteralExpression;
}
Also used : DmnVariableImpl(org.camunda.bpm.dmn.engine.impl.DmnVariableImpl) DmnExpressionImpl(org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl) Variable(org.camunda.bpm.model.dmn.instance.Variable) DmnDecisionLiteralExpressionImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionLiteralExpressionImpl)

Aggregations

DmnExpressionImpl (org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl)16 Test (org.junit.Test)6 DmnDecisionTableInputImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableInputImpl)4 DmnEngineTest (org.camunda.bpm.dmn.engine.test.DmnEngineTest)4 DmnDecisionLiteralExpressionImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionLiteralExpressionImpl)3 DmnDecisionTableImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl)3 DmnDecisionTableRuleImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableRuleImpl)3 DmnVariableImpl (org.camunda.bpm.dmn.engine.impl.DmnVariableImpl)3 TypedValue (org.camunda.bpm.engine.variable.value.TypedValue)3 DmnDecisionImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionImpl)2 DmnDecisionTableOutputImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableOutputImpl)2 InOrder (org.mockito.InOrder)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 CompiledScript (javax.script.CompiledScript)1 DmnDecision (org.camunda.bpm.dmn.engine.DmnDecision)1 DmnEvaluatedOutput (org.camunda.bpm.dmn.engine.delegate.DmnEvaluatedOutput)1 DmnDecisionLiteralExpressionEvaluationEventImpl (org.camunda.bpm.dmn.engine.impl.delegate.DmnDecisionLiteralExpressionEvaluationEventImpl)1 DmnEvaluatedInputImpl (org.camunda.bpm.dmn.engine.impl.delegate.DmnEvaluatedInputImpl)1 DmnEvaluatedOutputImpl (org.camunda.bpm.dmn.engine.impl.delegate.DmnEvaluatedOutputImpl)1