Search in sources :

Example 6 with DmnDecisionTableInputImpl

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

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

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

the class DecisionTableEvaluationHandler method evaluateDecisionTable.

protected void evaluateDecisionTable(DmnDecisionTableImpl decisionTable, VariableContext variableContext, DmnDecisionTableEvaluationEventImpl evaluationResult) {
    int inputSize = decisionTable.getInputs().size();
    List<DmnDecisionTableRuleImpl> matchingRules = new ArrayList<DmnDecisionTableRuleImpl>(decisionTable.getRules());
    for (int inputIdx = 0; inputIdx < inputSize; inputIdx++) {
        // evaluate input
        DmnDecisionTableInputImpl input = decisionTable.getInputs().get(inputIdx);
        DmnEvaluatedInput evaluatedInput = evaluateInput(input, variableContext);
        evaluationResult.getInputs().add(evaluatedInput);
        // compose local variable context out of global variable context enhanced with the value of the current input.
        VariableContext localVariableContext = getLocalVariableContext(input, evaluatedInput, variableContext);
        // filter rules applicable with this input
        matchingRules = evaluateInputForAvailableRules(inputIdx, input, matchingRules, localVariableContext);
    }
    setEvaluationOutput(decisionTable, matchingRules, variableContext, evaluationResult);
}
Also used : DmnDecisionTableInputImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableInputImpl) DmnEvaluatedInput(org.camunda.bpm.dmn.engine.delegate.DmnEvaluatedInput) DmnDecisionTableRuleImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableRuleImpl) ArrayList(java.util.ArrayList) CompositeVariableContext(org.camunda.bpm.engine.variable.impl.context.CompositeVariableContext) VariableContext(org.camunda.bpm.engine.variable.context.VariableContext)

Aggregations

DmnDecisionTableInputImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableInputImpl)8 DmnDecisionTableRuleImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableRuleImpl)4 DmnExpressionImpl (org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl)4 DmnDecisionTableImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl)3 DmnEngineTest (org.camunda.bpm.dmn.engine.test.DmnEngineTest)3 Input (org.camunda.bpm.model.dmn.instance.Input)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 DmnDecisionTableOutputImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableOutputImpl)2 Rule (org.camunda.bpm.model.dmn.instance.Rule)2 HashSet (java.util.HashSet)1 DmnEvaluatedInput (org.camunda.bpm.dmn.engine.delegate.DmnEvaluatedInput)1 DmnDecisionImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionImpl)1 DefaultTypeDefinition (org.camunda.bpm.dmn.engine.impl.type.DefaultTypeDefinition)1 DecisionResource (org.camunda.bpm.dmn.engine.test.DecisionResource)1 VariableContext (org.camunda.bpm.engine.variable.context.VariableContext)1 CompositeVariableContext (org.camunda.bpm.engine.variable.impl.context.CompositeVariableContext)1 DecisionTable (org.camunda.bpm.model.dmn.instance.DecisionTable)1 InputEntry (org.camunda.bpm.model.dmn.instance.InputEntry)1 InputExpression (org.camunda.bpm.model.dmn.instance.InputExpression)1