Search in sources :

Example 1 with DmnDecisionTableInputImpl

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

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

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

the class DmnDecisionTableInputTransformHandler method createFromInput.

protected DmnDecisionTableInputImpl createFromInput(DmnElementTransformContext context, Input input) {
    DmnDecisionTableInputImpl decisionTableInput = createDmnElement(context, input);
    decisionTableInput.setId(input.getId());
    decisionTableInput.setName(input.getLabel());
    decisionTableInput.setInputVariable(input.getCamundaInputVariable());
    return decisionTableInput;
}
Also used : DmnDecisionTableInputImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableInputImpl)

Example 4 with DmnDecisionTableInputImpl

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

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

the class DmnTransformListenerTest method shouldVerifyTransformedInput.

@Test
public void shouldVerifyTransformedInput() {
    dmnEngine.parseDecisionRequirementsGraph(IoUtil.fileAsStream(DECISION_TRANSFORM_DMN));
    DmnDecisionTableInputImpl dmnInput = listener.getDmnInput();
    Input input = listener.getInput();
    assertThat(dmnInput.getId()).isEqualTo(input.getId()).isEqualTo("input1");
}
Also used : DmnDecisionTableInputImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableInputImpl) Input(org.camunda.bpm.model.dmn.instance.Input) Test(org.junit.Test) DmnEngineTest(org.camunda.bpm.dmn.engine.test.DmnEngineTest)

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