Search in sources :

Example 6 with Input

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

Example 7 with Input

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

the class DmnModelElementInstanceCmdTest method testRepositoryService.

@Deployment(resources = "org/camunda/bpm/engine/test/repository/one.dmn")
public void testRepositoryService() {
    String decisionDefinitionId = repositoryService.createDecisionDefinitionQuery().decisionDefinitionKey(DECISION_KEY).singleResult().getId();
    DmnModelInstance modelInstance = repositoryService.getDmnModelInstance(decisionDefinitionId);
    assertNotNull(modelInstance);
    Collection<Decision> decisions = modelInstance.getModelElementsByType(Decision.class);
    assertEquals(1, decisions.size());
    Collection<DecisionTable> decisionTables = modelInstance.getModelElementsByType(DecisionTable.class);
    assertEquals(1, decisionTables.size());
    Collection<Input> inputs = modelInstance.getModelElementsByType(Input.class);
    assertEquals(1, inputs.size());
    Collection<Output> outputs = modelInstance.getModelElementsByType(Output.class);
    assertEquals(1, outputs.size());
    Collection<Rule> rules = modelInstance.getModelElementsByType(Rule.class);
    assertEquals(2, rules.size());
}
Also used : DecisionTable(org.camunda.bpm.model.dmn.instance.DecisionTable) Input(org.camunda.bpm.model.dmn.instance.Input) Output(org.camunda.bpm.model.dmn.instance.Output) Rule(org.camunda.bpm.model.dmn.instance.Rule) Decision(org.camunda.bpm.model.dmn.instance.Decision) DmnModelInstance(org.camunda.bpm.model.dmn.DmnModelInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 8 with Input

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

the class InputImpl method registerType.

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

        public Input newInstance(ModelTypeInstanceContext instanceContext) {
            return new InputImpl(instanceContext);
        }
    });
    typeBuilder.build();
}
Also used : Input(org.camunda.bpm.model.dmn.instance.Input) ModelElementTypeBuilder(org.camunda.bpm.model.xml.type.ModelElementTypeBuilder) ModelTypeInstanceContext(org.camunda.bpm.model.xml.impl.instance.ModelTypeInstanceContext) InputClause(org.camunda.bpm.model.dmn.instance.InputClause)

Example 9 with Input

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

the class ExampleTestCompatibility method shouldWriteElements.

@Test
public void shouldWriteElements() throws Exception {
    modelInstance = Dmn.createEmptyModel();
    // Definitions
    Definitions definitions = generateNamedElement(Definitions.class, "definitions");
    definitions.setNamespace(TEST_NAMESPACE);
    modelInstance.setDocumentElement(definitions);
    // Decision
    Decision decision = generateNamedElement(Decision.class, "Check Order");
    definitions.addChildElement(decision);
    // Decision table
    DecisionTable decisionTable = generateElement(DecisionTable.class);
    decision.addChildElement(decisionTable);
    // 1. Input clause
    Input input = generateElement(Input.class, 1);
    input.setLabel("Customer Status");
    InputExpression inputExpression = generateElement(InputExpression.class, 1);
    inputExpression.setTypeRef("string");
    Text text = generateElement(Text.class);
    text.setTextContent("status");
    inputExpression.setText(text);
    input.setInputExpression(inputExpression);
    InputValues inputValues = generateElement(InputValues.class);
    text = generateElement(Text.class);
    text.setTextContent("\"bronze\",\"silver\",\"gold\"");
    inputValues.setText(text);
    input.setInputValues(inputValues);
    decisionTable.getInputs().add(input);
    // 2. Input clause
    input = generateElement(Input.class, 2);
    input.setLabel("Order Sum");
    inputExpression = generateElement(InputExpression.class, 2);
    inputExpression.setTypeRef("double");
    text = generateElement(Text.class);
    text.setTextContent("sum");
    inputExpression.setText(text);
    input.setInputExpression(inputExpression);
    decisionTable.getInputs().add(input);
    // 1. Output clause
    Output output = generateElement(Output.class, 1);
    output.setLabel("Check Result");
    output.setName("result");
    output.setTypeRef("string");
    OutputValues outputValues = generateElement(OutputValues.class);
    text = generateElement(Text.class);
    text.setTextContent("\"ok\",\"notok\"");
    outputValues.setText(text);
    output.setOutputValues(outputValues);
    decisionTable.getOutputs().add(output);
    // 2. Output clause
    output = generateElement(Output.class, 2);
    output.setLabel("Reason");
    output.setName("reason");
    output.setTypeRef("string");
    decisionTable.getOutputs().add(output);
    // 1. Rule
    Rule rule = generateElement(Rule.class, 1);
    InputEntry inputEntry = generateElement(InputEntry.class, 1);
    text = generateElement(Text.class);
    text.setTextContent("\"bronze\"");
    inputEntry.setText(text);
    rule.getInputEntries().add(inputEntry);
    inputEntry = generateElement(InputEntry.class, 2);
    text = generateElement(Text.class);
    text.setTextContent("");
    inputEntry.setText(text);
    rule.getInputEntries().add(inputEntry);
    OutputEntry outputEntry = generateElement(OutputEntry.class, 1);
    text = generateElement(Text.class);
    text.setTextContent("\"notok\"");
    outputEntry.setText(text);
    rule.getOutputEntries().add(outputEntry);
    outputEntry = generateElement(OutputEntry.class, 2);
    text = generateElement(Text.class);
    text.getDomElement().addCDataSection("\"work on your status first, as bronze you're not going to get anything\"");
    outputEntry.setText(text);
    rule.getOutputEntries().add(outputEntry);
    decisionTable.getRules().add(rule);
    // 2. Rule
    rule = generateElement(Rule.class, 2);
    inputEntry = generateElement(InputEntry.class, 3);
    text = generateElement(Text.class);
    text.setTextContent("\"silver\"");
    rule.getInputEntries().add(inputEntry);
    inputEntry.setText(text);
    inputEntry = generateElement(InputEntry.class, 4);
    text = generateElement(Text.class);
    text.getDomElement().addCDataSection("< 1000");
    inputEntry.setText(text);
    rule.getInputEntries().add(inputEntry);
    outputEntry = generateElement(OutputEntry.class, 3);
    text = generateElement(Text.class);
    text.setTextContent("\"ok\"");
    outputEntry.setText(text);
    rule.getOutputEntries().add(outputEntry);
    outputEntry = generateElement(OutputEntry.class, 4);
    text = generateElement(Text.class);
    text.setTextContent("\"you little fish will get what you want\"");
    outputEntry.setText(text);
    rule.getOutputEntries().add(outputEntry);
    decisionTable.getRules().add(rule);
    // 3. Rule
    rule = generateElement(Rule.class, 3);
    inputEntry = generateElement(InputEntry.class, 5);
    text = generateElement(Text.class);
    text.setTextContent("\"silver\"");
    inputEntry.setText(text);
    rule.getInputEntries().add(inputEntry);
    inputEntry = generateElement(InputEntry.class, 6);
    text = generateElement(Text.class);
    text.getDomElement().addCDataSection(">= 1000");
    inputEntry.setText(text);
    rule.getInputEntries().add(inputEntry);
    outputEntry = generateElement(OutputEntry.class, 5);
    text = generateElement(Text.class);
    text.setTextContent("\"notok\"");
    outputEntry.setText(text);
    rule.getOutputEntries().add(outputEntry);
    outputEntry = generateElement(OutputEntry.class, 6);
    text = generateElement(Text.class);
    text.setTextContent("\"you took too much man, you took too much!\"");
    outputEntry.setText(text);
    rule.getOutputEntries().add(outputEntry);
    decisionTable.getRules().add(rule);
    // 4. Rule
    rule = generateElement(Rule.class, 4);
    inputEntry = generateElement(InputEntry.class, 7);
    text = generateElement(Text.class);
    text.setTextContent("\"gold\"");
    inputEntry.setText(text);
    rule.getInputEntries().add(inputEntry);
    inputEntry = generateElement(InputEntry.class, 8);
    text = generateElement(Text.class);
    text.setTextContent("");
    inputEntry.setText(text);
    rule.getInputEntries().add(inputEntry);
    outputEntry = generateElement(OutputEntry.class, 7);
    text = generateElement(Text.class);
    text.setTextContent("\"ok\"");
    outputEntry.setText(text);
    rule.getOutputEntries().add(outputEntry);
    outputEntry = generateElement(OutputEntry.class, 8);
    text = generateElement(Text.class);
    text.setTextContent("\"you get anything you want\"");
    outputEntry.setText(text);
    rule.getOutputEntries().add(outputEntry);
    decisionTable.getRules().add(rule);
    assertModelEqualsFile(EXAMPLE_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 10 with Input

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

the class ExampleTestCompatibility method shouldGetElements.

@Test
public void shouldGetElements() {
    // Definitions
    Definitions definitions = modelInstance.getDefinitions();
    assertThat(definitions).isNotNull();
    assertThat(definitions.getId()).isEqualTo("definitions");
    assertThat(definitions.getName()).isEqualTo("definitions");
    assertThat(definitions.getNamespace()).isEqualTo(TEST_NAMESPACE);
    assertElementIsEqualToId(definitions, "definitions");
    // Imports
    Collection<Import> imports = definitions.getImports();
    assertThat(imports).isEmpty();
    // Item definitions
    Collection<ItemDefinition> itemDefinitions = definitions.getItemDefinitions();
    assertThat(itemDefinitions).isEmpty();
    // DRG elements
    Collection<DrgElement> drgElements = definitions.getDrgElements();
    assertThat(drgElements).isNotEmpty().hasSize(1);
    // Decision
    Decision decision = (Decision) drgElements.iterator().next();
    assertThat(decision).isNotNull();
    assertThat(decision.getId()).isEqualTo("decision");
    assertThat(decision.getName()).isEqualTo("Check Order");
    assertElementIsEqualToId(decision, "decision");
    // Decision table
    DecisionTable decisionTable = (DecisionTable) decision.getExpression();
    assertThat(decisionTable).isNotNull();
    assertThat(decisionTable.getId()).isEqualTo("decisionTable");
    assertElementIsEqualToId(decisionTable, "decisionTable");
    // Input clauses
    List<Input> inputs = new ArrayList<Input>(decisionTable.getInputs());
    assertThat(inputs).hasSize(2);
    Iterator<Input> inputIterator = inputs.iterator();
    // 1. Input clause
    Input input = inputIterator.next();
    assertThat(input.getId()).isEqualTo("input1");
    assertThat(input.getLabel()).isEqualTo("Customer Status");
    InputExpression inputExpression = input.getInputExpression();
    assertThat(inputExpression.getId()).isEqualTo("inputExpression1");
    assertThat(inputExpression.getTypeRef()).isEqualTo("string");
    assertThat(inputExpression.getText().getTextContent()).isEqualTo("status");
    InputValues inputValues = input.getInputValues();
    assertThat(inputValues.getText().getTextContent()).isEqualTo("\"bronze\",\"silver\",\"gold\"");
    // 2. Input clause
    input = inputIterator.next();
    assertThat(input.getId()).isEqualTo("input2");
    assertThat(input.getLabel()).isEqualTo("Order Sum");
    inputExpression = input.getInputExpression();
    assertThat(inputExpression.getId()).isEqualTo("inputExpression2");
    assertThat(inputExpression.getTypeRef()).isEqualTo("double");
    // Output clause
    List<Output> outputs = new ArrayList<Output>(decisionTable.getOutputs());
    assertThat(outputs).hasSize(2);
    // 1. Output clause
    Output output = outputs.get(0);
    assertThat(output.getId()).isEqualTo("output1");
    assertThat(output.getLabel()).isEqualTo("Check Result");
    assertThat(output.getName()).isEqualTo("result");
    assertThat(output.getTypeRef()).isEqualTo("string");
    OutputValues outputValues = output.getOutputValues();
    assertThat(outputValues.getText().getTextContent()).isEqualTo("\"ok\",\"notok\"");
    // 2. Output clause
    output = outputs.get(1);
    assertThat(output.getId()).isEqualTo("output2");
    assertThat(output.getLabel()).isEqualTo("Reason");
    assertThat(output.getName()).isEqualTo("reason");
    assertThat(output.getTypeRef()).isEqualTo("string");
    // Rules
    List<Rule> rules = new ArrayList<Rule>(decisionTable.getRules());
    // 1. Rule
    Rule rule = rules.get(0);
    assertThat(rule.getId()).isEqualTo("rule1");
    List<InputEntry> inputEntries = new ArrayList<InputEntry>(rule.getInputEntries());
    assertThat(inputEntries).hasSize(2);
    assertThat(inputEntries.get(0).getText().getTextContent()).isEqualTo("\"bronze\"");
    assertThat(inputEntries.get(1).getText().getTextContent()).isEmpty();
    List<OutputEntry> outputEntries = new ArrayList<OutputEntry>(rule.getOutputEntries());
    assertThat(outputEntries).hasSize(2);
    assertThat(outputEntries.get(0).getText().getTextContent()).isEqualTo("\"notok\"");
    assertThat(outputEntries.get(1).getText().getTextContent()).isEqualTo("\"work on your status first, as bronze you're not going to get anything\"");
    // 2. Rule
    rule = rules.get(1);
    assertThat(rule.getId()).isEqualTo("rule2");
    inputEntries = new ArrayList<InputEntry>(rule.getInputEntries());
    assertThat(inputEntries).hasSize(2);
    assertThat(inputEntries.get(0).getText().getTextContent()).isEqualTo("\"silver\"");
    assertThat(inputEntries.get(1).getText().getTextContent()).isEqualTo("< 1000");
    outputEntries = new ArrayList<OutputEntry>(rule.getOutputEntries());
    assertThat(outputEntries).hasSize(2);
    assertThat(outputEntries.get(0).getText().getTextContent()).isEqualTo("\"ok\"");
    assertThat(outputEntries.get(1).getText().getTextContent()).isEqualTo("\"you little fish will get what you want\"");
    // 3. Rule
    rule = rules.get(2);
    assertThat(rule.getId()).isEqualTo("rule3");
    inputEntries = new ArrayList<InputEntry>(rule.getInputEntries());
    assertThat(inputEntries).hasSize(2);
    assertThat(inputEntries.get(0).getText().getTextContent()).isEqualTo("\"silver\"");
    assertThat(inputEntries.get(1).getText().getTextContent()).isEqualTo(">= 1000");
    outputEntries = new ArrayList<OutputEntry>(rule.getOutputEntries());
    assertThat(outputEntries).hasSize(2);
    assertThat(outputEntries.get(0).getText().getTextContent()).isEqualTo("\"notok\"");
    assertThat(outputEntries.get(1).getText().getTextContent()).isEqualTo("\"you took too much man, you took too much!\"");
    // 4. Rule
    rule = rules.get(3);
    assertThat(rule.getId()).isEqualTo("rule4");
    inputEntries = new ArrayList<InputEntry>(rule.getInputEntries());
    assertThat(inputEntries).hasSize(2);
    assertThat(inputEntries.get(0).getText().getTextContent()).isEqualTo("\"gold\"");
    assertThat(inputEntries.get(1).getText().getTextContent()).isEmpty();
    outputEntries = new ArrayList<OutputEntry>(rule.getOutputEntries());
    assertThat(outputEntries).hasSize(2);
    assertThat(outputEntries.get(0).getText().getTextContent()).isEqualTo("\"ok\"");
    assertThat(outputEntries.get(1).getText().getTextContent()).isEqualTo("\"you get anything you want\"");
    // Element collections
    Collection<ElementCollection> elementCollections = definitions.getElementCollections();
    assertThat(elementCollections).isEmpty();
    // Business contexts
    Collection<BusinessContextElement> businessContextElements = definitions.getBusinessContextElements();
    assertThat(businessContextElements).isEmpty();
}
Also used : Import(org.camunda.bpm.model.dmn.instance.Import) OutputEntry(org.camunda.bpm.model.dmn.instance.OutputEntry) ItemDefinition(org.camunda.bpm.model.dmn.instance.ItemDefinition) ArrayList(java.util.ArrayList) BusinessContextElement(org.camunda.bpm.model.dmn.instance.BusinessContextElement) DecisionTable(org.camunda.bpm.model.dmn.instance.DecisionTable) InputValues(org.camunda.bpm.model.dmn.instance.InputValues) Input(org.camunda.bpm.model.dmn.instance.Input) Output(org.camunda.bpm.model.dmn.instance.Output) ElementCollection(org.camunda.bpm.model.dmn.instance.ElementCollection) Definitions(org.camunda.bpm.model.dmn.instance.Definitions) InputExpression(org.camunda.bpm.model.dmn.instance.InputExpression) Decision(org.camunda.bpm.model.dmn.instance.Decision) InputEntry(org.camunda.bpm.model.dmn.instance.InputEntry) DrgElement(org.camunda.bpm.model.dmn.instance.DrgElement) OutputValues(org.camunda.bpm.model.dmn.instance.OutputValues) Rule(org.camunda.bpm.model.dmn.instance.Rule) Test(org.junit.Test)

Aggregations

Input (org.camunda.bpm.model.dmn.instance.Input)11 DecisionTable (org.camunda.bpm.model.dmn.instance.DecisionTable)7 Output (org.camunda.bpm.model.dmn.instance.Output)7 Rule (org.camunda.bpm.model.dmn.instance.Rule)6 Test (org.junit.Test)6 Decision (org.camunda.bpm.model.dmn.instance.Decision)5 Definitions (org.camunda.bpm.model.dmn.instance.Definitions)5 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 DmnDecisionTableInputImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableInputImpl)3 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 DmnModelInstance (org.camunda.bpm.model.dmn.DmnModelInstance)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 DmnDecisionTableImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl)1 DmnDecisionTableOutputImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableOutputImpl)1 DmnDecisionTableRuleImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableRuleImpl)1