Search in sources :

Example 1 with DmnDecisionLiteralExpressionImpl

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

the class DecisionLiteralExpressionEvaluationHandler method evaluate.

@Override
public DmnDecisionLogicEvaluationEvent evaluate(DmnDecision decision, VariableContext variableContext) {
    DmnDecisionLiteralExpressionEvaluationEventImpl evaluationResult = new DmnDecisionLiteralExpressionEvaluationEventImpl();
    evaluationResult.setDecision(decision);
    evaluationResult.setExecutedDecisionElements(1);
    DmnDecisionLiteralExpressionImpl dmnDecisionLiteralExpression = (DmnDecisionLiteralExpressionImpl) decision.getDecisionLogic();
    DmnVariableImpl variable = dmnDecisionLiteralExpression.getVariable();
    DmnExpressionImpl expression = dmnDecisionLiteralExpression.getExpression();
    Object evaluateExpression = evaluateLiteralExpression(expression, variableContext);
    TypedValue typedValue = variable.getTypeDefinition().transform(evaluateExpression);
    evaluationResult.setOutputValue(typedValue);
    evaluationResult.setOutputName(variable.getName());
    return evaluationResult;
}
Also used : DmnVariableImpl(org.camunda.bpm.dmn.engine.impl.DmnVariableImpl) DmnExpressionImpl(org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl) DmnDecisionLiteralExpressionEvaluationEventImpl(org.camunda.bpm.dmn.engine.impl.delegate.DmnDecisionLiteralExpressionEvaluationEventImpl) DmnDecisionLiteralExpressionImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionLiteralExpressionImpl) TypedValue(org.camunda.bpm.engine.variable.value.TypedValue)

Example 2 with DmnDecisionLiteralExpressionImpl

use of org.camunda.bpm.dmn.engine.impl.DmnDecisionLiteralExpressionImpl 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 3 with DmnDecisionLiteralExpressionImpl

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

the class DefaultDmnTransform method transformDecision.

protected DmnDecisionImpl transformDecision(Decision decision) {
    DmnElementTransformHandler<Decision, DmnDecisionImpl> handler = handlerRegistry.getHandler(Decision.class);
    DmnDecisionImpl dmnDecision = handler.handleElement(this, decision);
    this.decision = dmnDecision;
    // validate decision id
    if (dmnDecision.getKey() == null) {
        throw LOG.decisionIdIsMissing(dmnDecision);
    }
    Expression expression = decision.getExpression();
    if (expression == null) {
        LOG.decisionWithoutExpression(decision);
        return null;
    }
    if (expression instanceof DecisionTable) {
        DmnDecisionTableImpl dmnDecisionTable = transformDecisionTable((DecisionTable) expression);
        dmnDecision.setDecisionLogic(dmnDecisionTable);
    } else if (expression instanceof LiteralExpression) {
        DmnDecisionLiteralExpressionImpl dmnDecisionLiteralExpression = transformDecisionLiteralExpression(decision, (LiteralExpression) expression);
        dmnDecision.setDecisionLogic(dmnDecisionLiteralExpression);
    } else {
        LOG.decisionTypeNotSupported(expression, decision);
        return null;
    }
    return dmnDecision;
}
Also used : DecisionTable(org.camunda.bpm.model.dmn.instance.DecisionTable) DmnDecisionTableImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl) LiteralExpression(org.camunda.bpm.model.dmn.instance.LiteralExpression) InputExpression(org.camunda.bpm.model.dmn.instance.InputExpression) Expression(org.camunda.bpm.model.dmn.instance.Expression) DmnDecisionImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionImpl) LiteralExpression(org.camunda.bpm.model.dmn.instance.LiteralExpression) DmnDecisionLiteralExpressionImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionLiteralExpressionImpl) DmnDecision(org.camunda.bpm.dmn.engine.DmnDecision) Decision(org.camunda.bpm.model.dmn.instance.Decision)

Example 4 with DmnDecisionLiteralExpressionImpl

use of org.camunda.bpm.dmn.engine.impl.DmnDecisionLiteralExpressionImpl 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)

Example 5 with DmnDecisionLiteralExpressionImpl

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

the class ExpressionLanguageTest method testGlobalExpressionLanguageDecisionLiteralExpression.

@Test
@DecisionResource(resource = GROOVY_DECISION_LITERAL_EXPRESSION_DMN)
public void testGlobalExpressionLanguageDecisionLiteralExpression() {
    DmnDecisionLiteralExpressionImpl decisionLiteralExpression = (DmnDecisionLiteralExpressionImpl) decision.getDecisionLogic();
    assertThat(decisionLiteralExpression.getExpression().getExpressionLanguage()).isEqualTo("groovy");
    dmnEngine.evaluateDecision(decision, Variables.createVariables().putValue("a", 2).putValue("b", 3));
    verify(scriptEngineResolver, atLeastOnce()).getScriptEngineForLanguage("groovy");
    verify(scriptEngineResolver, never()).getScriptEngineForLanguage(JUEL);
}
Also used : DmnDecisionLiteralExpressionImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionLiteralExpressionImpl) Test(org.junit.Test) DmnEngineTest(org.camunda.bpm.dmn.engine.test.DmnEngineTest) DecisionResource(org.camunda.bpm.dmn.engine.test.DecisionResource)

Aggregations

DmnDecisionLiteralExpressionImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionLiteralExpressionImpl)5 DmnExpressionImpl (org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl)3 DmnVariableImpl (org.camunda.bpm.dmn.engine.impl.DmnVariableImpl)3 DmnDecision (org.camunda.bpm.dmn.engine.DmnDecision)2 DmnEngineTest (org.camunda.bpm.dmn.engine.test.DmnEngineTest)2 Test (org.junit.Test)2 DmnDecisionImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionImpl)1 DmnDecisionTableImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl)1 DmnDecisionLiteralExpressionEvaluationEventImpl (org.camunda.bpm.dmn.engine.impl.delegate.DmnDecisionLiteralExpressionEvaluationEventImpl)1 DecisionResource (org.camunda.bpm.dmn.engine.test.DecisionResource)1 TypedValue (org.camunda.bpm.engine.variable.value.TypedValue)1 Decision (org.camunda.bpm.model.dmn.instance.Decision)1 DecisionTable (org.camunda.bpm.model.dmn.instance.DecisionTable)1 Expression (org.camunda.bpm.model.dmn.instance.Expression)1 InputExpression (org.camunda.bpm.model.dmn.instance.InputExpression)1 LiteralExpression (org.camunda.bpm.model.dmn.instance.LiteralExpression)1 Variable (org.camunda.bpm.model.dmn.instance.Variable)1