Search in sources :

Example 1 with ElementCollection

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

the class ElementCollectionImpl method registerType.

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

        public ElementCollection newInstance(ModelTypeInstanceContext instanceContext) {
            return new ElementCollectionImpl(instanceContext);
        }
    });
    SequenceBuilder sequenceBuilder = typeBuilder.sequence();
    drgElementRefCollection = sequenceBuilder.elementCollection(DrgElementReference.class).uriElementReferenceCollection(DrgElement.class).build();
    typeBuilder.build();
}
Also used : DrgElementReference(org.camunda.bpm.model.dmn.instance.DrgElementReference) SequenceBuilder(org.camunda.bpm.model.xml.type.child.SequenceBuilder) ModelElementTypeBuilder(org.camunda.bpm.model.xml.type.ModelElementTypeBuilder) ElementCollection(org.camunda.bpm.model.dmn.instance.ElementCollection) ModelTypeInstanceContext(org.camunda.bpm.model.xml.impl.instance.ModelTypeInstanceContext) NamedElement(org.camunda.bpm.model.dmn.instance.NamedElement)

Example 2 with ElementCollection

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

ElementCollection (org.camunda.bpm.model.dmn.instance.ElementCollection)2 ArrayList (java.util.ArrayList)1 BusinessContextElement (org.camunda.bpm.model.dmn.instance.BusinessContextElement)1 Decision (org.camunda.bpm.model.dmn.instance.Decision)1 DecisionTable (org.camunda.bpm.model.dmn.instance.DecisionTable)1 Definitions (org.camunda.bpm.model.dmn.instance.Definitions)1 DrgElement (org.camunda.bpm.model.dmn.instance.DrgElement)1 DrgElementReference (org.camunda.bpm.model.dmn.instance.DrgElementReference)1 Import (org.camunda.bpm.model.dmn.instance.Import)1 Input (org.camunda.bpm.model.dmn.instance.Input)1 InputEntry (org.camunda.bpm.model.dmn.instance.InputEntry)1 InputExpression (org.camunda.bpm.model.dmn.instance.InputExpression)1 InputValues (org.camunda.bpm.model.dmn.instance.InputValues)1 ItemDefinition (org.camunda.bpm.model.dmn.instance.ItemDefinition)1 NamedElement (org.camunda.bpm.model.dmn.instance.NamedElement)1 Output (org.camunda.bpm.model.dmn.instance.Output)1 OutputEntry (org.camunda.bpm.model.dmn.instance.OutputEntry)1 OutputValues (org.camunda.bpm.model.dmn.instance.OutputValues)1 Rule (org.camunda.bpm.model.dmn.instance.Rule)1 ModelTypeInstanceContext (org.camunda.bpm.model.xml.impl.instance.ModelTypeInstanceContext)1