Search in sources :

Example 1 with DecisionTable

use of org.camunda.bpm.model.dmn.instance.DecisionTable in project camunda-dmn-model by camunda.

the class DecisionTableImpl method registerType.

public static void registerType(ModelBuilder modelBuilder) {
    ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(DecisionTable.class, DMN_ELEMENT_DECISION_TABLE).namespaceUri(DMN11_NS).extendsType(Expression.class).instanceProvider(new ModelTypeInstanceProvider<DecisionTable>() {

        public DecisionTable newInstance(ModelTypeInstanceContext instanceContext) {
            return new DecisionTableImpl(instanceContext);
        }
    });
    hitPolicyAttribute = typeBuilder.namedEnumAttribute(DMN_ATTRIBUTE_HIT_POLICY, HitPolicy.class).defaultValue(HitPolicy.UNIQUE).build();
    aggregationAttribute = typeBuilder.enumAttribute(DMN_ATTRIBUTE_AGGREGATION, BuiltinAggregator.class).build();
    preferredOrientationAttribute = typeBuilder.namedEnumAttribute(DMN_ATTRIBUTE_PREFERRED_ORIENTATION, DecisionTableOrientation.class).defaultValue(DecisionTableOrientation.Rule_as_Row).build();
    outputLabelAttribute = typeBuilder.stringAttribute(DMN_ATTRIBUTE_OUTPUT_LABEL).build();
    SequenceBuilder sequenceBuilder = typeBuilder.sequence();
    inputCollection = sequenceBuilder.elementCollection(Input.class).build();
    outputCollection = sequenceBuilder.elementCollection(Output.class).required().build();
    ruleCollection = sequenceBuilder.elementCollection(Rule.class).build();
    typeBuilder.build();
}
Also used : DecisionTable(org.camunda.bpm.model.dmn.instance.DecisionTable) Expression(org.camunda.bpm.model.dmn.instance.Expression) HitPolicy(org.camunda.bpm.model.dmn.HitPolicy) SequenceBuilder(org.camunda.bpm.model.xml.type.child.SequenceBuilder) Output(org.camunda.bpm.model.dmn.instance.Output) ModelElementTypeBuilder(org.camunda.bpm.model.xml.type.ModelElementTypeBuilder) ModelTypeInstanceContext(org.camunda.bpm.model.xml.impl.instance.ModelTypeInstanceContext) DecisionTableOrientation(org.camunda.bpm.model.dmn.DecisionTableOrientation)

Example 2 with DecisionTable

use of org.camunda.bpm.model.dmn.instance.DecisionTable 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 DecisionTable

use of org.camunda.bpm.model.dmn.instance.DecisionTable in project camunda-dmn-model by camunda.

the class ExpressionLanguageTest method shouldReadExpressionLanguage.

@Test
@DmnModelResource(resource = EXPRESSION_LANGUAGE_DMN)
public void shouldReadExpressionLanguage() {
    Definitions definitions = modelInstance.getDefinitions();
    assertThat(definitions.getExpressionLanguage()).isEqualTo(EXPRESSION_LANGUAGE);
    DecisionTable decisionTable = modelInstance.getModelElementById("decisionTable");
    Input input = decisionTable.getInputs().iterator().next();
    assertThat(input.getInputExpression().getExpressionLanguage()).isEqualTo(EXPRESSION_LANGUAGE);
    assertThat(input.getInputValues().getExpressionLanguage()).isEqualTo(EXPRESSION_LANGUAGE);
    Output output = decisionTable.getOutputs().iterator().next();
    assertThat(output.getOutputValues().getExpressionLanguage()).isEqualTo(EXPRESSION_LANGUAGE);
    Rule rule = decisionTable.getRules().iterator().next();
    InputEntry inputEntry = rule.getInputEntries().iterator().next();
    assertThat(inputEntry.getExpressionLanguage()).isEqualTo(EXPRESSION_LANGUAGE);
    OutputEntry outputEntry = rule.getOutputEntries().iterator().next();
    assertThat(outputEntry.getExpressionLanguage()).isEqualTo(EXPRESSION_LANGUAGE);
}
Also used : DecisionTable(org.camunda.bpm.model.dmn.instance.DecisionTable) Input(org.camunda.bpm.model.dmn.instance.Input) OutputEntry(org.camunda.bpm.model.dmn.instance.OutputEntry) Definitions(org.camunda.bpm.model.dmn.instance.Definitions) Output(org.camunda.bpm.model.dmn.instance.Output) Rule(org.camunda.bpm.model.dmn.instance.Rule) InputEntry(org.camunda.bpm.model.dmn.instance.InputEntry) Test(org.junit.Test) DmnModelResource(org.camunda.bpm.model.dmn.util.DmnModelResource)

Example 4 with DecisionTable

use of org.camunda.bpm.model.dmn.instance.DecisionTable in project camunda-dmn-model by camunda.

the class ExpressionLanguageTest method shouldWriteExpressionLanguage.

@Test
public void shouldWriteExpressionLanguage() throws Exception {
    modelInstance = Dmn.createEmptyModel();
    Definitions definitions = generateNamedElement(Definitions.class, "definitions");
    definitions.setNamespace(TEST_NAMESPACE);
    definitions.setExpressionLanguage(EXPRESSION_LANGUAGE);
    modelInstance.setDocumentElement(definitions);
    Decision decision = generateNamedElement(Decision.class, "Check Order");
    definitions.addChildElement(decision);
    DecisionTable decisionTable = generateElement(DecisionTable.class);
    decision.addChildElement(decisionTable);
    Input input = generateElement(Input.class);
    decisionTable.getInputs().add(input);
    InputExpression inputExpression = generateElement(InputExpression.class);
    inputExpression.setExpressionLanguage(EXPRESSION_LANGUAGE);
    input.setInputExpression(inputExpression);
    InputValues inputValues = generateElement(InputValues.class);
    inputValues.setExpressionLanguage(EXPRESSION_LANGUAGE);
    inputValues.setText(generateElement(Text.class));
    input.setInputValues(inputValues);
    Output output = generateElement(Output.class);
    decisionTable.getOutputs().add(output);
    OutputValues outputValues = generateElement(OutputValues.class);
    outputValues.setExpressionLanguage(EXPRESSION_LANGUAGE);
    outputValues.setText(generateElement(Text.class));
    output.setOutputValues(outputValues);
    Rule rule = generateElement(Rule.class);
    decisionTable.getRules().add(rule);
    InputEntry inputEntry = generateElement(InputEntry.class);
    inputEntry.setExpressionLanguage(EXPRESSION_LANGUAGE);
    inputEntry.setText(generateElement(Text.class));
    rule.getInputEntries().add(inputEntry);
    OutputEntry outputEntry = generateElement(OutputEntry.class);
    outputEntry.setExpressionLanguage(EXPRESSION_LANGUAGE);
    rule.getOutputEntries().add(outputEntry);
    assertModelEqualsFile(EXPRESSION_LANGUAGE_DMN);
}
Also used : DecisionTable(org.camunda.bpm.model.dmn.instance.DecisionTable) InputValues(org.camunda.bpm.model.dmn.instance.InputValues) Input(org.camunda.bpm.model.dmn.instance.Input) OutputEntry(org.camunda.bpm.model.dmn.instance.OutputEntry) OutputValues(org.camunda.bpm.model.dmn.instance.OutputValues) Definitions(org.camunda.bpm.model.dmn.instance.Definitions) Output(org.camunda.bpm.model.dmn.instance.Output) Text(org.camunda.bpm.model.dmn.instance.Text) Rule(org.camunda.bpm.model.dmn.instance.Rule) InputExpression(org.camunda.bpm.model.dmn.instance.InputExpression) Decision(org.camunda.bpm.model.dmn.instance.Decision) InputEntry(org.camunda.bpm.model.dmn.instance.InputEntry) Test(org.junit.Test)

Example 5 with DecisionTable

use of org.camunda.bpm.model.dmn.instance.DecisionTable in project camunda-bpm-platform by camunda.

the class DecisionDefinitionDeployerTest method createDmnModelInstance.

protected static DmnModelInstance createDmnModelInstance() {
    DmnModelInstance modelInstance = Dmn.createEmptyModel();
    Definitions definitions = modelInstance.newInstance(Definitions.class);
    definitions.setId(DmnModelConstants.DMN_ELEMENT_DEFINITIONS);
    definitions.setName(DmnModelConstants.DMN_ELEMENT_DEFINITIONS);
    definitions.setNamespace(DmnModelConstants.CAMUNDA_NS);
    modelInstance.setDefinitions(definitions);
    Decision decision = modelInstance.newInstance(Decision.class);
    decision.setId("Decision-1");
    decision.setName("foo");
    decision.setCamundaHistoryTimeToLive(5);
    modelInstance.getDefinitions().addChildElement(decision);
    DecisionTable decisionTable = modelInstance.newInstance(DecisionTable.class);
    decisionTable.setId(DmnModelConstants.DMN_ELEMENT_DECISION_TABLE);
    decisionTable.setHitPolicy(HitPolicy.FIRST);
    decision.addChildElement(decisionTable);
    Input input = modelInstance.newInstance(Input.class);
    input.setId("Input-1");
    input.setLabel("Input");
    decisionTable.addChildElement(input);
    InputExpression inputExpression = modelInstance.newInstance(InputExpression.class);
    inputExpression.setId("InputExpression-1");
    Text inputExpressionText = modelInstance.newInstance(Text.class);
    inputExpressionText.setTextContent("input");
    inputExpression.setText(inputExpressionText);
    inputExpression.setTypeRef("string");
    input.setInputExpression(inputExpression);
    Output output = modelInstance.newInstance(Output.class);
    output.setName("output");
    output.setLabel("Output");
    output.setTypeRef("string");
    decisionTable.addChildElement(output);
    return modelInstance;
}
Also used : DecisionTable(org.camunda.bpm.model.dmn.instance.DecisionTable) Input(org.camunda.bpm.model.dmn.instance.Input) Definitions(org.camunda.bpm.model.dmn.instance.Definitions) Output(org.camunda.bpm.model.dmn.instance.Output) Text(org.camunda.bpm.model.dmn.instance.Text) InputExpression(org.camunda.bpm.model.dmn.instance.InputExpression) Decision(org.camunda.bpm.model.dmn.instance.Decision) DmnModelInstance(org.camunda.bpm.model.dmn.DmnModelInstance)

Aggregations

DecisionTable (org.camunda.bpm.model.dmn.instance.DecisionTable)11 Output (org.camunda.bpm.model.dmn.instance.Output)10 Decision (org.camunda.bpm.model.dmn.instance.Decision)8 Definitions (org.camunda.bpm.model.dmn.instance.Definitions)7 Input (org.camunda.bpm.model.dmn.instance.Input)7 Rule (org.camunda.bpm.model.dmn.instance.Rule)6 Test (org.junit.Test)6 InputExpression (org.camunda.bpm.model.dmn.instance.InputExpression)5 InputEntry (org.camunda.bpm.model.dmn.instance.InputEntry)4 OutputEntry (org.camunda.bpm.model.dmn.instance.OutputEntry)4 InputValues (org.camunda.bpm.model.dmn.instance.InputValues)3 OutputValues (org.camunda.bpm.model.dmn.instance.OutputValues)3 Text (org.camunda.bpm.model.dmn.instance.Text)3 DmnDecisionTableImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl)2 DmnModelInstance (org.camunda.bpm.model.dmn.DmnModelInstance)2 Expression (org.camunda.bpm.model.dmn.instance.Expression)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 DmnDecision (org.camunda.bpm.dmn.engine.DmnDecision)1 DmnDecisionImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionImpl)1