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

The following examples show how to use org.camunda.bpm.model.dmn.instance.DecisionTable. 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: DmnHelper.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public static DmnModelInstance createSimpleDmnModel(final String decisionKey) {
  final DmnModelInstance modelInstance = Dmn.createEmptyModel();

  final Definitions definitions = generateNamedElement(Definitions.class, "definitions", modelInstance);
  definitions.setNamespace(TEST_NAMESPACE);

  modelInstance.setDefinitions(definitions);

  Decision decision = generateNamedElement(Decision.class, "decision1", modelInstance);
  decision.setId(decisionKey);
  DecisionTable decisionTable = generateElement(DecisionTable.class, modelInstance);
  decision.setExpression(decisionTable);
  Output output = generateElement(Output.class, modelInstance);
  decisionTable.getOutputs().add(output);
  definitions.addChildElement(decision);
  return modelInstance;
}
 
Example #2
Source File: DmnModelElementInstanceCmdTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #3
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 #4
Source File: XlsxDeploymentTest.java    From camunda-dmn-xlsx with Apache License 2.0 6 votes vote down vote up
@Test
public void testXlsxDeploymentWithMetaData() {
  // when
  deployment = rule.getRepositoryService()
    .createDeployment()
    .addClasspathResource("test1.xlsx")
    .addClasspathResource("test1.xlsx.yaml")
    .deploy()
    .getId();

  // then
  DecisionDefinition decisionDefinition = rule.getRepositoryService().createDecisionDefinitionQuery().singleResult();
  assertThat(decisionDefinition).isNotNull();

  DmnModelInstance dmnModel = rule.getRepositoryService().getDmnModelInstance(decisionDefinition.getId());
  Collection<DecisionTable> decisionTables = dmnModel.getModelElementsByType(DecisionTable.class);
  assertThat(decisionTables).hasSize(1);

  DecisionTable decisionTable = decisionTables.iterator().next();
  assertThat(decisionTable.getInputs()).hasSize(1);
  assertThat(decisionTable.getOutputs()).hasSize(1);

}
 
Example #5
Source File: XlsxWorksheetConverter.java    From camunda-dmn-xlsx with Apache License 2.0 6 votes vote down vote up
public DmnModelInstance convert() {

    DmnModelInstance dmnModel = initializeEmptyDmnModel();

    Decision decision = generateElement(dmnModel, Decision.class, worksheetContext.getName());
    decision.setName(spreadsheetAdapter.determineDecisionName(worksheetContext));
    dmnModel.getDefinitions().addChildElement(decision);

    DecisionTable decisionTable = generateElement(dmnModel, DecisionTable.class, "decisionTable");
    decision.addChildElement(decisionTable);

    setHitPolicy(decisionTable);
    convertInputsOutputs(dmnModel, decisionTable);
    convertRules(dmnModel, decisionTable, spreadsheetAdapter.determineRuleRows(worksheetContext));

    return dmnModel;
  }
 
Example #6
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 #7
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 #8
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 #9
Source File: InputOutputDetectionStrategyTest.java    From camunda-dmn-xlsx with Apache License 2.0 5 votes vote down vote up
@Test
public void testStaticDetectionStrategy() {
  XlsxConverter converter = new XlsxConverter();
  converter.setIoDetectionStrategy(new StaticInputOutputDetectionStrategy(Collections.singleton("B"), Collections.singleton("D")));
  InputStream inputStream = TestHelper.getClassPathResource("test2.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);
}
 
Example #10
Source File: DecisionDefinitionDeployerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #11
Source File: GenerateIdTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldGenerateIdsOnCreate() {
  DmnModelInstance modelInstance = Dmn.createEmptyModel();
  Definitions definitions = modelInstance.newInstance(Definitions.class);
  assertThat(definitions.getId()).isNotNull();

  Decision decision = modelInstance.newInstance(Decision.class);
  assertThat(decision.getId()).isNotNull();

  DecisionTable decisionTable = modelInstance.newInstance(DecisionTable.class);
  assertThat(decisionTable.getId()).isNotNull();

  Output output = modelInstance.newInstance(Output.class);
  assertThat(output.getId()).isNotNull();
}
 
Example #12
Source File: GenerateIdTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotGenerateIdsOnRead() {
  DmnModelInstance modelInstance = Dmn.readModelFromStream(GenerateIdTest.class.getResourceAsStream("GenerateIdTest.dmn"));
  Definitions definitions = modelInstance.getDefinitions();
  assertThat(definitions.getId()).isNull();

  Decision decision = modelInstance.getModelElementsByType(Decision.class).iterator().next();
  assertThat(decision.getId()).isNull();

  DecisionTable decisionTable = modelInstance.getModelElementsByType(DecisionTable.class).iterator().next();
  assertThat(decisionTable.getId()).isNull();

  Output output = modelInstance.getModelElementsByType(Output.class).iterator().next();
  assertThat(output.getId()).isNull();
}
 
Example #13
Source File: DecisionTableImpl.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(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();
}
 
Example #14
Source File: DefaultDmnTransform.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected DmnDecisionImpl transformDecision(Decision decision) {

    DmnElementTransformHandler<Decision, DmnDecisionImpl> handler = handlerRegistry.getHandler(Decision.class);
    DmnDecisionImpl dmnDecision = handler.handleElement(this, decision);
    this.decision = dmnDecision;
    // validate decision id
    if (dmnDecision.getKey() == null) {
      throw LOG.decisionIdIsMissing(dmnDecision);
    }

    Expression expression = decision.getExpression();
    if (expression == null) {
      LOG.decisionWithoutExpression(decision);
      return null;
    }

    if (expression instanceof DecisionTable) {
      DmnDecisionTableImpl dmnDecisionTable = transformDecisionTable((DecisionTable) expression);
      dmnDecision.setDecisionLogic(dmnDecisionTable);

    } else if (expression instanceof LiteralExpression) {
      DmnDecisionLiteralExpressionImpl dmnDecisionLiteralExpression = transformDecisionLiteralExpression(decision, (LiteralExpression) expression);
      dmnDecision.setDecisionLogic(dmnDecisionLiteralExpression);

    } else {
      LOG.decisionTypeNotSupported(expression, decision);
      return null;
    }

    return dmnDecision;
  }
 
Example #15
Source File: DmnDecisionTableTransformHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected DmnHitPolicyHandler getHitPolicyHandler(DmnElementTransformContext context, DecisionTable decisionTable, DmnDecisionTableImpl dmnDecisionTable) {
  HitPolicy hitPolicy = decisionTable.getHitPolicy();
  if (hitPolicy == null) {
    // use default hit policy
    hitPolicy = HitPolicy.UNIQUE;
  }
  BuiltinAggregator aggregation = decisionTable.getAggregation();
  DmnHitPolicyHandler hitPolicyHandler = context.getHitPolicyHandlerRegistry().getHandler(hitPolicy, aggregation);
  if (hitPolicyHandler != null) {
    return hitPolicyHandler;
  }
  else {
    throw LOG.hitPolicyNotSupported(dmnDecisionTable, hitPolicy, aggregation);
  }
}
 
Example #16
Source File: TestHelper.java    From camunda-dmn-xlsx with Apache License 2.0 5 votes vote down vote up
public static DecisionTable assertAndGetSingleDecisionTable(DmnModelInstance dmnModel) {
  assertThat(dmnModel.getDefinitions()).isNotNull();
  Collection<Decision> decisions = dmnModel.getDefinitions().getChildElementsByType(Decision.class);
  assertThat(decisions).hasSize(1);

  Decision decision = decisions.iterator().next();
  assertThat(decision).isNotNull();

  Collection<DecisionTable> decisionTables = decision.getChildElementsByType(DecisionTable.class);
  assertThat(decisionTables).hasSize(1);

  return decisionTables.iterator().next();
}
 
Example #17
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 #18
Source File: XslxToDmnConversionTest.java    From camunda-dmn-xlsx with Apache License 2.0 5 votes vote down vote up
@Test
public void testConversionOfNullTitleOfParts() {
  XlsxConverter converter = new XlsxConverter();
  InputStream inputStream = TestHelper.getClassPathResource("test4.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(1);
  assertThat(table.getRules()).hasSize(1);
}
 
Example #19
Source File: DmnDecisionTableTransformHandler.java    From camunda-engine-dmn with Apache License 2.0 5 votes vote down vote up
protected DmnHitPolicyHandler getHitPolicyHandler(DmnElementTransformContext context, DecisionTable decisionTable, DmnDecisionTableImpl dmnDecisionTable) {
  HitPolicy hitPolicy = decisionTable.getHitPolicy();
  if (hitPolicy == null) {
    // use default hit policy
    hitPolicy = HitPolicy.UNIQUE;
  }
  BuiltinAggregator aggregation = decisionTable.getAggregation();
  DmnHitPolicyHandler hitPolicyHandler = context.getHitPolicyHandlerRegistry().getHandler(hitPolicy, aggregation);
  if (hitPolicyHandler != null) {
    return hitPolicyHandler;
  }
  else {
    throw LOG.hitPolicyNotSupported(dmnDecisionTable, hitPolicy, aggregation);
  }
}
 
Example #20
Source File: DefaultDmnTransform.java    From camunda-engine-dmn with Apache License 2.0 5 votes vote down vote up
protected DmnDecisionImpl transformDecision(Decision decision) {

    DmnElementTransformHandler<Decision, DmnDecisionImpl> handler = handlerRegistry.getHandler(Decision.class);
    DmnDecisionImpl dmnDecision = handler.handleElement(this, decision);
    this.decision = dmnDecision;
    // validate decision id
    if (dmnDecision.getKey() == null) {
      throw LOG.decisionIdIsMissing(dmnDecision);
    }

    Expression expression = decision.getExpression();
    if (expression == null) {
      LOG.decisionWithoutExpression(decision);
      return null;
    }

    if (expression instanceof DecisionTable) {
      DmnDecisionTableImpl dmnDecisionTable = transformDecisionTable((DecisionTable) expression);
      dmnDecision.setDecisionLogic(dmnDecisionTable);

    } else if (expression instanceof LiteralExpression) {
      DmnDecisionLiteralExpressionImpl dmnDecisionLiteralExpression = transformDecisionLiteralExpression(decision, (LiteralExpression) expression);
      dmnDecision.setDecisionLogic(dmnDecisionLiteralExpression);

    } else {
      LOG.decisionTypeNotSupported(expression, decision);
      return null;
    }

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

  DecisionTable table = TestHelper.assertAndGetSingleDecisionTable(dmnModelInstance);
  assertThat(table).isNotNull();
  assertThat(table.getInputs()).hasSize(3);
  assertThat(table.getOutputs()).hasSize(1);
  assertThat(table.getRules()).hasSize(4);
}
 
Example #22
Source File: XslxToDmnConversionTest.java    From camunda-dmn-xlsx with Apache License 2.0 5 votes vote down vote up
@Test
public void testConversionOfMixedNumberAndStringColumns() {
  XlsxConverter converter = new XlsxConverter();
  InputStream inputStream = TestHelper.getClassPathResource("test2.xlsx");
  DmnModelInstance dmnModelInstance = converter.convert(inputStream);
  assertThat(dmnModelInstance).isNotNull();

  DecisionTable table = TestHelper.assertAndGetSingleDecisionTable(dmnModelInstance);
  assertThat(table).isNotNull();
  assertThat(table.getInputs()).hasSize(3);
  assertThat(table.getOutputs()).hasSize(1);
  assertThat(table.getRules()).hasSize(4);
}
 
Example #23
Source File: XslxToDmnConversionTest.java    From camunda-dmn-xlsx with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleConversion() {
  XlsxConverter converter = new XlsxConverter();
  InputStream inputStream = TestHelper.getClassPathResource("test1.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(1);
  assertThat(table.getRules()).hasSize(4);
}
 
Example #24
Source File: DmnDecisionTableTransformHandler.java    From camunda-engine-dmn with Apache License 2.0 4 votes vote down vote up
public DmnDecisionTableImpl handleElement(DmnElementTransformContext context, DecisionTable decisionTable) {
  return createFromDecisionTable(context, decisionTable);
}
 
Example #25
Source File: DmnDecisionTableTransformHandler.java    From camunda-engine-dmn with Apache License 2.0 4 votes vote down vote up
protected DmnDecisionTableImpl createDmnElement(DmnElementTransformContext context, DecisionTable decisionTable) {
  return new DmnDecisionTableImpl();
}
 
Example #26
Source File: DefaultDmnTransform.java    From camunda-engine-dmn with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example #27
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 #28
Source File: XlsxWorksheetConverter.java    From camunda-dmn-xlsx with Apache License 2.0 4 votes vote down vote up
protected void setHitPolicy(DecisionTable decisionTable) {
  HitPolicy hitPolicy = spreadsheetAdapter.determineHitPolicy(worksheetContext);
  if (hitPolicy != null) {
    decisionTable.setHitPolicy(hitPolicy);
  }
}
 
Example #29
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 #30
Source File: XlsxWorksheetConverter.java    From camunda-dmn-xlsx with Apache License 2.0 4 votes vote down vote up
protected void convertRules(DmnModelInstance dmnModel, DecisionTable decisionTable, List<SpreadsheetRow> rulesRows) {
  for (SpreadsheetRow rule : rulesRows) {
    convertRule(dmnModel, decisionTable, rule);
  }
}