Search in sources :

Example 1 with DmnExpressionImpl

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

the class DefaultDmnTransform method transformDecisionTableRule.

protected DmnDecisionTableRuleImpl transformDecisionTableRule(Rule rule) {
    DmnElementTransformHandler<Rule, DmnDecisionTableRuleImpl> handler = handlerRegistry.getHandler(Rule.class);
    DmnDecisionTableRuleImpl dmnRule = handler.handleElement(this, rule);
    // validate rule id
    if (dmnRule.getId() == null) {
        throw LOG.decisionTableRuleIdIsMissing(decision, dmnRule);
    }
    List<DmnDecisionTableInputImpl> inputs = this.decisionTable.getInputs();
    List<InputEntry> inputEntries = new ArrayList<InputEntry>(rule.getInputEntries());
    if (inputs.size() != inputEntries.size()) {
        throw LOG.differentNumberOfInputsAndInputEntries(inputs.size(), inputEntries.size(), dmnRule);
    }
    for (InputEntry inputEntry : inputEntries) {
        parent = dmnRule;
        DmnExpressionImpl condition = transformInputEntry(inputEntry);
        dmnRule.getConditions().add(condition);
    }
    List<DmnDecisionTableOutputImpl> outputs = this.decisionTable.getOutputs();
    List<OutputEntry> outputEntries = new ArrayList<OutputEntry>(rule.getOutputEntries());
    if (outputs.size() != outputEntries.size()) {
        throw LOG.differentNumberOfOutputsAndOutputEntries(outputs.size(), outputEntries.size(), dmnRule);
    }
    for (OutputEntry outputEntry : outputEntries) {
        parent = dmnRule;
        DmnExpressionImpl conclusion = transformOutputEntry(outputEntry);
        dmnRule.getConclusions().add(conclusion);
    }
    return dmnRule;
}
Also used : OutputEntry(org.camunda.bpm.model.dmn.instance.OutputEntry) ArrayList(java.util.ArrayList) InputEntry(org.camunda.bpm.model.dmn.instance.InputEntry) DmnDecisionTableInputImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableInputImpl) DmnDecisionTableOutputImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableOutputImpl) DmnExpressionImpl(org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl) DmnDecisionTableRuleImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableRuleImpl) Rule(org.camunda.bpm.model.dmn.instance.Rule)

Example 2 with DmnExpressionImpl

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

the class ExpressionCachingTest method testElExpressionCaching.

@Test
public void testElExpressionCaching() {
    // given
    DmnExpressionImpl expression = createExpression("1 > 2", "juel");
    // when
    expressionEvaluationHandler.evaluateExpression("juel", expression, emptyVariableContext());
    // then
    InOrder inOrder = inOrder(expression, elProviderSpy);
    inOrder.verify(expression, atLeastOnce()).getCachedExpression();
    inOrder.verify(elProviderSpy, times(1)).createExpression(anyString());
    inOrder.verify(expression, times(1)).setCachedExpression(any(ElExpression.class));
    // when (2)
    expressionEvaluationHandler.evaluateExpression("juel", expression, emptyVariableContext());
    // then (2)
    inOrder.verify(expression, atLeastOnce()).getCachedExpression();
    inOrder.verify(elProviderSpy, times(0)).createExpression(anyString());
}
Also used : DmnExpressionImpl(org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl) InOrder(org.mockito.InOrder) ElExpression(org.camunda.bpm.dmn.engine.impl.spi.el.ElExpression) Test(org.junit.Test)

Example 3 with DmnExpressionImpl

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

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

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

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