org.camunda.bpm.model.dmn.instance.InputEntry Java Examples

The following examples show how to use org.camunda.bpm.model.dmn.instance.InputEntry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultElementTransformHandlerRegistry.java    From camunda-engine-dmn with Apache License 2.0 6 votes vote down vote up
protected static Map<Class<? extends DmnModelElementInstance>, DmnElementTransformHandler> getDefaultElementTransformHandlers() {
  Map<Class<? extends DmnModelElementInstance>, DmnElementTransformHandler> handlers = new HashMap<Class<? extends DmnModelElementInstance>, DmnElementTransformHandler>();

  handlers.put(Definitions.class, new DmnDecisionRequirementsGraphTransformHandler());
  handlers.put(Decision.class, new DmnDecisionTransformHandler());

  handlers.put(DecisionTable.class, new DmnDecisionTableTransformHandler());
  handlers.put(Input.class, new DmnDecisionTableInputTransformHandler());
  handlers.put(InputExpression.class, new DmnDecisionTableInputExpressionTransformHandler());
  handlers.put(Output.class, new DmnDecisionTableOutputTransformHandler());
  handlers.put(Rule.class, new DmnDecisionTableRuleTransformHandler());
  handlers.put(InputEntry.class, new DmnDecisionTableConditionTransformHandler());
  handlers.put(OutputEntry.class, new DmnLiternalExpressionTransformHandler());

  handlers.put(LiteralExpression.class, new DmnLiternalExpressionTransformHandler());
  handlers.put(Variable.class, new DmnVariableTransformHandler());

  return handlers;
}
 
Example #2
Source File: ExpressionLanguageTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #3
Source File: XslxToDmnConversionTest.java    From camunda-dmn-xlsx with Apache License 2.0 6 votes vote down vote up
@Test
public void testConversionWithRanges() {
  XlsxConverter converter = new XlsxConverter();
  InputStream inputStream = TestHelper.getClassPathResource("test5.xlsx");
  DmnModelInstance dmnModelInstance = converter.convert(inputStream);
  assertThat(dmnModelInstance).isNotNull();

  DecisionTable table = TestHelper.assertAndGetSingleDecisionTable(dmnModelInstance);
  assertThat(table).isNotNull();
  assertThat(table.getInputs()).hasSize(1);
  assertThat(table.getOutputs()).hasSize(1);
  assertThat(table.getRules()).hasSize(4);

  Rule firstRule = table.getRules().iterator().next();

  InputEntry inputEntry = firstRule.getInputEntries().iterator().next();
  String firstInput = inputEntry.getTextContent();
  assertThat(firstInput).isEqualTo("[1..2]");
}
 
Example #4
Source File: DefaultElementTransformHandlerRegistry.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected static Map<Class<? extends DmnModelElementInstance>, DmnElementTransformHandler> getDefaultElementTransformHandlers() {
  Map<Class<? extends DmnModelElementInstance>, DmnElementTransformHandler> handlers = new HashMap<Class<? extends DmnModelElementInstance>, DmnElementTransformHandler>();

  handlers.put(Definitions.class, new DmnDecisionRequirementsGraphTransformHandler());
  handlers.put(Decision.class, new DmnDecisionTransformHandler());

  handlers.put(DecisionTable.class, new DmnDecisionTableTransformHandler());
  handlers.put(Input.class, new DmnDecisionTableInputTransformHandler());
  handlers.put(InputExpression.class, new DmnDecisionTableInputExpressionTransformHandler());
  handlers.put(Output.class, new DmnDecisionTableOutputTransformHandler());
  handlers.put(Rule.class, new DmnDecisionTableRuleTransformHandler());
  handlers.put(InputEntry.class, new DmnDecisionTableConditionTransformHandler());
  handlers.put(OutputEntry.class, new DmnLiternalExpressionTransformHandler());

  handlers.put(LiteralExpression.class, new DmnLiternalExpressionTransformHandler());
  handlers.put(Variable.class, new DmnVariableTransformHandler());

  return handlers;
}
 
Example #5
Source File: DecisionRuleImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public static void registerType(ModelBuilder modelBuilder) {
  ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(DecisionRule.class, DMN_ELEMENT_DECISION_RULE)
    .namespaceUri(DMN11_NS)
    .extendsType(DmnElement.class)
    .instanceProvider(new ModelTypeInstanceProvider<DecisionRule>() {
      public DecisionRule newInstance(ModelTypeInstanceContext instanceContext) {
        return new DecisionRuleImpl(instanceContext);
      }
    });

  SequenceBuilder sequenceBuilder = typeBuilder.sequence();

  inputEntryCollection = sequenceBuilder.elementCollection(InputEntry.class)
    .build();

  outputEntryCollection = sequenceBuilder.elementCollection(OutputEntry.class)
    .required()
    .build();

  typeBuilder.build();
}
 
Example #6
Source File: DefaultDmnTransform.java    From camunda-engine-dmn with Apache License 2.0 5 votes vote down vote up
protected DmnDecisionTableRuleImpl transformDecisionTableRule(Rule rule) {
  DmnElementTransformHandler<Rule, DmnDecisionTableRuleImpl> handler = handlerRegistry.getHandler(Rule.class);
  DmnDecisionTableRuleImpl dmnRule = handler.handleElement(this, rule);

  // validate rule id
  if (dmnRule.getId() == null) {
    throw LOG.decisionTableRuleIdIsMissing(decision, dmnRule);
  }

  List<DmnDecisionTableInputImpl> inputs = this.decisionTable.getInputs();
  List<InputEntry> inputEntries = new ArrayList<InputEntry>(rule.getInputEntries());
  if (inputs.size() != inputEntries.size()) {
    throw LOG.differentNumberOfInputsAndInputEntries(inputs.size(), inputEntries.size(), dmnRule);
  }

  for (InputEntry inputEntry : inputEntries) {
    parent = dmnRule;

    DmnExpressionImpl condition = transformInputEntry(inputEntry);
    dmnRule.getConditions().add(condition);
  }

  List<DmnDecisionTableOutputImpl> outputs = this.decisionTable.getOutputs();
  List<OutputEntry> outputEntries = new ArrayList<OutputEntry>(rule.getOutputEntries());
  if (outputs.size() != outputEntries.size()) {
    throw LOG.differentNumberOfOutputsAndOutputEntries(outputs.size(), outputEntries.size(), dmnRule);
  }

  for (OutputEntry outputEntry : outputEntries) {
    parent = dmnRule;
    DmnExpressionImpl conclusion = transformOutputEntry(outputEntry);
    dmnRule.getConclusions().add(conclusion);
  }

  return dmnRule;
}
 
Example #7
Source File: DmnDecisionTableConditionTransformHandler.java    From camunda-engine-dmn with Apache License 2.0 5 votes vote down vote up
protected DmnExpressionImpl createFromInputEntry(DmnElementTransformContext context, InputEntry inputEntry) {
  DmnExpressionImpl condition = createDmnElement(context, inputEntry);

  condition.setId(inputEntry.getId());
  condition.setName(inputEntry.getLabel());
  condition.setExpressionLanguage(getExpressionLanguage(context, inputEntry));
  condition.setExpression(getExpression(inputEntry));

  return condition;
}
 
Example #8
Source File: XslxToDmnConversionTest.java    From camunda-dmn-xlsx with Apache License 2.0 5 votes vote down vote up
@Test
public void testConversionWithComplexHeaders() {
  XlsxConverter converter = new XlsxConverter();
  converter.setIoDetectionStrategy(new AdvancedSpreadsheetAdapter());
  InputStream inputStream = TestHelper.getClassPathResource("test6.xlsx");
  DmnModelInstance dmnModelInstance = converter.convert(inputStream);
  assertThat(dmnModelInstance).isNotNull();

  DecisionTable table = TestHelper.assertAndGetSingleDecisionTable(dmnModelInstance);
  assertThat(table).isNotNull();
  assertThat(table.getInputs()).hasSize(2);
  assertThat(table.getOutputs()).hasSize(2);
  assertThat(table.getRules()).hasSize(2);
  assertThat(table.getHitPolicy()).isEqualTo(HitPolicy.FIRST);

  Iterator<Input> inputIterator = table.getInputs().iterator();
  Input input = inputIterator.next();

  assertThat(input.getId()).isEqualTo("input1");
  assertThat(input.getLabel()).isEqualTo("InputLabel1");
  assertThat(input.getInputExpression().getTypeRef()).isEqualTo("string");
  assertThat(input.getTextContent()).isEqualTo("Exp1");

  input = inputIterator.next();
  assertThat(input.getId()).isEqualTo("input2");
  assertThat(input.getLabel()).isEqualTo("InputLabel2");
  assertThat(input.getInputExpression().getTypeRef()).isEqualTo("integer");
  assertThat(input.getInputExpression().getExpressionLanguage()).isEqualTo("javascript");
  assertThat(input.getInputExpression().getTextContent()).isEqualTo(JAVASCRIPT_SNIPPET);

  Iterator<Rule> ruleIterator = table.getRules().iterator();
  Rule rule = ruleIterator.next();
  assertThat(rule.getDescription().getTextContent()).isEqualTo("Comment1");

  InputEntry inputEntry = rule.getInputEntries().iterator().next();
  assertThat(inputEntry.getTextContent()).isEqualTo("\"Foo\"");

  rule = ruleIterator.next();
  assertThat(rule.getDescription().getTextContent()).isEqualTo("Another Comment");
}
 
Example #9
Source File: DefaultDmnTransform.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected DmnDecisionTableRuleImpl transformDecisionTableRule(Rule rule) {
  DmnElementTransformHandler<Rule, DmnDecisionTableRuleImpl> handler = handlerRegistry.getHandler(Rule.class);
  DmnDecisionTableRuleImpl dmnRule = handler.handleElement(this, rule);

  // validate rule id
  if (dmnRule.getId() == null) {
    throw LOG.decisionTableRuleIdIsMissing(decision, dmnRule);
  }

  List<DmnDecisionTableInputImpl> inputs = this.decisionTable.getInputs();
  List<InputEntry> inputEntries = new ArrayList<InputEntry>(rule.getInputEntries());
  if (inputs.size() != inputEntries.size()) {
    throw LOG.differentNumberOfInputsAndInputEntries(inputs.size(), inputEntries.size(), dmnRule);
  }

  for (InputEntry inputEntry : inputEntries) {
    parent = dmnRule;

    DmnExpressionImpl condition = transformInputEntry(inputEntry);
    dmnRule.getConditions().add(condition);
  }

  List<DmnDecisionTableOutputImpl> outputs = this.decisionTable.getOutputs();
  List<OutputEntry> outputEntries = new ArrayList<OutputEntry>(rule.getOutputEntries());
  if (outputs.size() != outputEntries.size()) {
    throw LOG.differentNumberOfOutputsAndOutputEntries(outputs.size(), outputEntries.size(), dmnRule);
  }

  for (OutputEntry outputEntry : outputEntries) {
    parent = dmnRule;
    DmnExpressionImpl conclusion = transformOutputEntry(outputEntry);
    dmnRule.getConclusions().add(conclusion);
  }

  return dmnRule;
}
 
Example #10
Source File: InputEntryImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static void registerType(ModelBuilder modelBuilder) {
  ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(InputEntry.class, DMN_ELEMENT_INPUT_ENTRY)
    .namespaceUri(DMN11_NS)
    .extendsType(UnaryTests.class)
    .instanceProvider(new ModelTypeInstanceProvider<InputEntry>() {
      public InputEntry newInstance(ModelTypeInstanceContext instanceContext) {
        return new InputEntryImpl(instanceContext);
      }
    });

  typeBuilder.build();
}
 
Example #11
Source File: DmnDecisionTableConditionTransformHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected DmnExpressionImpl createFromInputEntry(DmnElementTransformContext context, InputEntry inputEntry) {
  DmnExpressionImpl condition = createDmnElement(context, inputEntry);

  condition.setId(inputEntry.getId());
  condition.setName(inputEntry.getLabel());
  condition.setExpressionLanguage(getExpressionLanguage(context, inputEntry));
  condition.setExpression(getExpression(inputEntry));

  return condition;
}
 
Example #12
Source File: ExpressionLanguageTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example #13
Source File: DmnWriterTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
/**
 * <p>There is an issue in JDK 9+ that changes how CDATA section are serialized:
 *
 * <p>https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8223291
 *
 * <p>&lt; JDK9:
 *
 * <pre>
 * &lt;inputEntry id="inputEntry1"&gt;
 *   &lt;text&gt;&lt;![CDATA[&gt;= 1000]]&gt;&lt;/text&gt;
 * &lt;/inputEntry&gt;
 * </pre>
 *
 * <p>(the text element has one child node, a CDATA section)
 *
 * <p>&gt;= JDK9:
 *
 * <pre>
 * &lt;inputEntry id="inputEntry1"&gt;
 *   &lt;text&gt;
 *     &lt;![CDATA[&gt;= 1000]]&gt;
 *   &lt;/text&gt;
 * &lt;/inputEntry&gt;
 * </pre>
 *
 * <p>(the text element has three child nodes, a text node, a CDATA section and another text node)
 *
 * <p>This test ensures, that a JDK9-formatted model can be read
 * and the text content method returns the CDATA value only
 */
@Test
public void shouldReadJDK9StyleModel()
{
  DmnModelInstance modelInstance =
      Dmn.readModelFromStream(ExampleCompatibilityTest.class.getResourceAsStream("JDK9-style-CDATA.dmn"));

  Decision decision = (Decision) modelInstance.getDefinitions().getDrgElements().iterator().next();

  DecisionTable decisionTable = (DecisionTable) decision.getExpression();

  Rule rule = decisionTable.getRules().iterator().next();
  InputEntry inputEntry = rule.getInputEntries().iterator().next();
  String textContent = inputEntry.getText().getTextContent();
  assertThat(textContent).isEqualTo(">= 1000");
}
 
Example #14
Source File: DecisionRuleImpl.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public Collection<InputEntry> getInputEntries() {
  return inputEntryCollection.get(this);
}
 
Example #15
Source File: DmnDecisionTableConditionTransformHandler.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected DmnExpressionImpl createDmnElement(DmnElementTransformContext context, InputEntry inputEntry) {
  return new DmnExpressionImpl();
}
 
Example #16
Source File: DmnDecisionTableConditionTransformHandler.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public DmnExpressionImpl handleElement(DmnElementTransformContext context, InputEntry inputEntry) {
  return createFromInputEntry(context, inputEntry);
}
 
Example #17
Source File: DefaultDmnTransform.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected DmnExpressionImpl transformInputEntry(InputEntry inputEntry) {
  DmnElementTransformHandler<InputEntry, DmnExpressionImpl> handler = handlerRegistry.getHandler(InputEntry.class);
  return handler.handleElement(this, inputEntry);
}
 
Example #18
Source File: DmnDecisionTableConditionTransformHandler.java    From camunda-engine-dmn with Apache License 2.0 4 votes vote down vote up
protected DmnExpressionImpl createDmnElement(DmnElementTransformContext context, InputEntry inputEntry) {
  return new DmnExpressionImpl();
}
 
Example #19
Source File: DmnDecisionTableConditionTransformHandler.java    From camunda-engine-dmn with Apache License 2.0 4 votes vote down vote up
public DmnExpressionImpl handleElement(DmnElementTransformContext context, InputEntry inputEntry) {
  return createFromInputEntry(context, inputEntry);
}
 
Example #20
Source File: DefaultDmnTransform.java    From camunda-engine-dmn with Apache License 2.0 4 votes vote down vote up
protected DmnExpressionImpl transformInputEntry(InputEntry inputEntry) {
  DmnElementTransformHandler<InputEntry, DmnExpressionImpl> handler = handlerRegistry.getHandler(InputEntry.class);
  return handler.handleElement(this, inputEntry);
}