Search in sources :

Example 1 with DmnDecision

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

the class DefaultDmnTransform method transformDefinitions.

protected DmnDecisionRequirementsGraph transformDefinitions(Definitions definitions) {
    DmnElementTransformHandler<Definitions, DmnDecisionRequirementsGraphImpl> handler = handlerRegistry.getHandler(Definitions.class);
    DmnDecisionRequirementsGraphImpl dmnDrg = handler.handleElement(this, definitions);
    // validate id of drd
    if (dmnDrg.getKey() == null) {
        throw LOG.drdIdIsMissing(dmnDrg);
    }
    Collection<Decision> decisions = definitions.getChildElementsByType(Decision.class);
    List<DmnDecision> dmnDecisions = transformDecisions(decisions);
    for (DmnDecision dmnDecision : dmnDecisions) {
        dmnDrg.addDecision(dmnDecision);
    }
    notifyTransformListeners(definitions, dmnDrg);
    return dmnDrg;
}
Also used : Definitions(org.camunda.bpm.model.dmn.instance.Definitions) DmnDecisionRequirementsGraphImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionRequirementsGraphImpl) DmnDecision(org.camunda.bpm.dmn.engine.DmnDecision) Decision(org.camunda.bpm.model.dmn.instance.Decision) DmnDecision(org.camunda.bpm.dmn.engine.DmnDecision)

Example 2 with DmnDecision

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

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

the class DefaultDmnTransform method ensureNoLoopInDecision.

protected void ensureNoLoopInDecision(DmnDecision decision, List<String> parentDecisionList, List<String> visitedDecisions) {
    if (visitedDecisions.contains(decision.getKey())) {
        return;
    }
    parentDecisionList.add(decision.getKey());
    for (DmnDecision requiredDecision : decision.getRequiredDecisions()) {
        if (parentDecisionList.contains(requiredDecision.getKey())) {
            throw LOG.requiredDecisionLoopDetected(requiredDecision.getKey());
        }
        ensureNoLoopInDecision(requiredDecision, new ArrayList<String>(parentDecisionList), visitedDecisions);
    }
    visitedDecisions.add(decision.getKey());
}
Also used : DmnDecision(org.camunda.bpm.dmn.engine.DmnDecision)

Example 4 with DmnDecision

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

the class DefaultDmnTransform method transformDecisions.

@SuppressWarnings("unchecked")
public <T extends DmnDecision> List<T> transformDecisions() {
    try {
        Definitions definitions = modelInstance.getDefinitions();
        Collection<Decision> decisions = definitions.getChildElementsByType(Decision.class);
        return (List<T>) transformDecisions(decisions);
    } catch (Exception e) {
        throw LOG.errorWhileTransformingDecisions(e);
    }
}
Also used : Definitions(org.camunda.bpm.model.dmn.instance.Definitions) ArrayList(java.util.ArrayList) List(java.util.List) DmnDecision(org.camunda.bpm.dmn.engine.DmnDecision) Decision(org.camunda.bpm.model.dmn.instance.Decision) DmnModelException(org.camunda.bpm.model.dmn.DmnModelException)

Example 5 with DmnDecision

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

the class DmnTransformListenerTest method shouldVerifyTransformedDmnDecision.

@Test
public void shouldVerifyTransformedDmnDecision() {
    InputStream inputStream = IoUtil.fileAsStream(DECISION_TRANSFORM_DMN);
    DmnModelInstance modelInstance = Dmn.readModelFromStream(inputStream);
    dmnEngine.parseDecisionRequirementsGraph(modelInstance);
    DmnDecision dmnDecision = listener.getDmnDecision();
    Decision decision = listener.getDecision();
    assertThat(dmnDecision.getKey()).isEqualTo(decision.getId()).isEqualTo("decision1");
    assertThat(dmnDecision.getName()).isEqualTo(decision.getName()).isEqualTo("camunda");
}
Also used : InputStream(java.io.InputStream) DmnDecision(org.camunda.bpm.dmn.engine.DmnDecision) Decision(org.camunda.bpm.model.dmn.instance.Decision) DmnModelInstance(org.camunda.bpm.model.dmn.DmnModelInstance) DmnDecision(org.camunda.bpm.dmn.engine.DmnDecision) Test(org.junit.Test) DmnEngineTest(org.camunda.bpm.dmn.engine.test.DmnEngineTest)

Aggregations

DmnDecision (org.camunda.bpm.dmn.engine.DmnDecision)27 DmnEngineTest (org.camunda.bpm.dmn.engine.test.DmnEngineTest)9 Test (org.junit.Test)9 InputStream (java.io.InputStream)8 Decision (org.camunda.bpm.model.dmn.instance.Decision)7 ArrayList (java.util.ArrayList)5 DmnModelInstance (org.camunda.bpm.model.dmn.DmnModelInstance)5 DmnDecisionImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionImpl)3 DmnDecisionLiteralExpressionImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionLiteralExpressionImpl)2 DmnDecisionTableImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl)2 Definitions (org.camunda.bpm.model.dmn.instance.Definitions)2 List (java.util.List)1 DmnDecisionRequirementsGraph (org.camunda.bpm.dmn.engine.DmnDecisionRequirementsGraph)1 DmnDecisionResult (org.camunda.bpm.dmn.engine.DmnDecisionResult)1 DmnEngine (org.camunda.bpm.dmn.engine.DmnEngine)1 DmnDecisionLogicEvaluationEvent (org.camunda.bpm.dmn.engine.delegate.DmnDecisionLogicEvaluationEvent)1 DmnDecisionRequirementsGraphImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionRequirementsGraphImpl)1 DmnExpressionImpl (org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl)1 DmnVariableImpl (org.camunda.bpm.dmn.engine.impl.DmnVariableImpl)1 DmnDecisionLogicEvaluationHandler (org.camunda.bpm.dmn.engine.impl.evaluation.DmnDecisionLogicEvaluationHandler)1