Search in sources :

Example 1 with DmnDecisionImpl

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

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

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

the class DmnEngineApiTest method shouldFailEvaluatingDecisionIfDecisionLogicIsNotSupported.

@Test
public void shouldFailEvaluatingDecisionIfDecisionLogicIsNotSupported() {
    DmnDecisionImpl decision = new DmnDecisionImpl();
    decision.setKey("decision");
    decision.setDecisionLogic(mock(DmnDecisionLogic.class));
    try {
        dmnEngine.evaluateDecision(decision, variables);
        failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
    } catch (DmnEngineException e) {
        assertThat(e).hasMessageStartingWith("DMN-01012");
    }
}
Also used : DmnDecisionImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionImpl) DmnDecisionLogic(org.camunda.bpm.dmn.engine.DmnDecisionLogic) DmnEngineException(org.camunda.bpm.dmn.engine.DmnEngineException) Test(org.junit.Test) DmnEngineTest(org.camunda.bpm.dmn.engine.test.DmnEngineTest)

Example 4 with DmnDecisionImpl

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

the class DefaultDmnTransform method transformDecisions.

protected List<DmnDecision> transformDecisions(Collection<Decision> decisions) {
    Map<String, DmnDecisionImpl> dmnDecisions = transformIndividualDecisions(decisions);
    buildDecisionRequirements(decisions, dmnDecisions);
    List<DmnDecision> dmnDecisionList = new ArrayList<DmnDecision>(dmnDecisions.values());
    for (Decision decision : decisions) {
        DmnDecision dmnDecision = dmnDecisions.get(decision.getId());
        notifyTransformListeners(decision, dmnDecision);
    }
    ensureNoLoopInDecisions(dmnDecisionList);
    return dmnDecisionList;
}
Also used : DmnDecisionImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionImpl) ArrayList(java.util.ArrayList) DmnDecision(org.camunda.bpm.dmn.engine.DmnDecision) Decision(org.camunda.bpm.model.dmn.instance.Decision) DmnDecision(org.camunda.bpm.dmn.engine.DmnDecision)

Example 5 with DmnDecisionImpl

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

Aggregations

DmnDecisionImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionImpl)8 DmnDecisionTableImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl)4 DmnEngineTest (org.camunda.bpm.dmn.engine.test.DmnEngineTest)4 Test (org.junit.Test)4 DmnDecision (org.camunda.bpm.dmn.engine.DmnDecision)3 Decision (org.camunda.bpm.model.dmn.instance.Decision)3 DmnExpressionImpl (org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl)2 DefaultTypeDefinition (org.camunda.bpm.dmn.engine.impl.type.DefaultTypeDefinition)2 ArrayList (java.util.ArrayList)1 DmnDecisionLogic (org.camunda.bpm.dmn.engine.DmnDecisionLogic)1 DmnEngineException (org.camunda.bpm.dmn.engine.DmnEngineException)1 DmnDecisionLiteralExpressionImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionLiteralExpressionImpl)1 DmnDecisionTableInputImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableInputImpl)1 DmnDecisionTableOutputImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableOutputImpl)1 DmnDecisionTableRuleImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableRuleImpl)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