Search in sources :

Example 1 with DmnDecisionTableOutputImpl

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

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

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

the class DmnTransformListenerTest method shouldVerifyTransformedOutput.

@Test
public void shouldVerifyTransformedOutput() {
    dmnEngine.parseDecisionRequirementsGraph(IoUtil.fileAsStream(DECISION_TRANSFORM_DMN));
    DmnDecisionTableOutputImpl dmnOutput = listener.getDmnOutput();
    Output output = listener.getOutput();
    assertThat(dmnOutput.getId()).isEqualTo(output.getId()).isEqualTo("output1");
}
Also used : DmnDecisionTableOutputImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableOutputImpl) Output(org.camunda.bpm.model.dmn.instance.Output) Test(org.junit.Test) DmnEngineTest(org.camunda.bpm.dmn.engine.test.DmnEngineTest)

Example 4 with DmnDecisionTableOutputImpl

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

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

Aggregations

DmnDecisionTableOutputImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableOutputImpl)8 DmnDecisionTableRuleImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableRuleImpl)3 Output (org.camunda.bpm.model.dmn.instance.Output)3 ArrayList (java.util.ArrayList)2 DmnDecisionTableImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl)2 DmnDecisionTableInputImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableInputImpl)2 DmnExpressionImpl (org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl)2 DmnEngineTest (org.camunda.bpm.dmn.engine.test.DmnEngineTest)2 Rule (org.camunda.bpm.model.dmn.instance.Rule)2 Test (org.junit.Test)2 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 DmnEvaluatedDecisionRule (org.camunda.bpm.dmn.engine.delegate.DmnEvaluatedDecisionRule)1 DmnEvaluatedOutput (org.camunda.bpm.dmn.engine.delegate.DmnEvaluatedOutput)1 DmnDecisionImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionImpl)1 DmnEvaluatedOutputImpl (org.camunda.bpm.dmn.engine.impl.delegate.DmnEvaluatedOutputImpl)1 DefaultTypeDefinition (org.camunda.bpm.dmn.engine.impl.type.DefaultTypeDefinition)1 TypedValue (org.camunda.bpm.engine.variable.value.TypedValue)1 DecisionTable (org.camunda.bpm.model.dmn.instance.DecisionTable)1 Input (org.camunda.bpm.model.dmn.instance.Input)1