use of org.camunda.bpm.dmn.engine.impl.DmnDecisionTableRuleImpl in project camunda-engine-dmn by camunda.
the class DmnTransformListenerTest method shouldVerifyTransformedRule.
@Test
public void shouldVerifyTransformedRule() {
dmnEngine.parseDecisionRequirementsGraph(IoUtil.fileAsStream(DECISION_TRANSFORM_DMN));
DmnDecisionTableRuleImpl dmnRule = listener.getDmnRule();
Rule rule = listener.getRule();
assertThat(dmnRule.getId()).isEqualTo(rule.getId()).isEqualTo("rule");
}
use of org.camunda.bpm.dmn.engine.impl.DmnDecisionTableRuleImpl in project camunda-engine-dmn by camunda.
the class DmnTransformTest method shouldTransformRules.
@Test
public void shouldTransformRules() {
DmnDecisionImpl decisionEntity = (DmnDecisionImpl) parseDecisionFromFile("decision1", TRANSFORM_DMN);
DmnDecisionTableImpl decisionTable = (DmnDecisionTableImpl) decisionEntity.getDecisionLogic();
List<DmnDecisionTableRuleImpl> rules = decisionTable.getRules();
assertThat(rules).hasSize(1);
DmnDecisionTableRuleImpl rule = rules.get(0);
List<DmnExpressionImpl> conditions = rule.getConditions();
assertThat(conditions).hasSize(2);
DmnExpressionImpl condition = conditions.get(0);
assertThat(condition.getId()).isEqualTo("inputEntry");
assertThat(condition.getName()).isEqualTo("camunda");
assertThat(condition.getExpressionLanguage()).isEqualTo("camunda");
assertThat(condition.getExpression()).isEqualTo("camunda");
condition = conditions.get(1);
assertThat(condition.getId()).isNull();
assertThat(condition.getName()).isNull();
assertThat(condition.getExpressionLanguage()).isNull();
assertThat(condition.getExpression()).isNull();
List<DmnExpressionImpl> conclusions = rule.getConclusions();
assertThat(conclusions).hasSize(2);
DmnExpressionImpl dmnOutputEntry = conclusions.get(0);
assertThat(dmnOutputEntry.getId()).isEqualTo("outputEntry");
assertThat(dmnOutputEntry.getName()).isEqualTo("camunda");
assertThat(dmnOutputEntry.getExpressionLanguage()).isEqualTo("camunda");
assertThat(dmnOutputEntry.getExpression()).isEqualTo("camunda");
dmnOutputEntry = conclusions.get(1);
assertThat(dmnOutputEntry.getId()).isNull();
assertThat(dmnOutputEntry.getName()).isNull();
assertThat(dmnOutputEntry.getExpressionLanguage()).isNull();
assertThat(dmnOutputEntry.getExpression()).isNull();
}
use of org.camunda.bpm.dmn.engine.impl.DmnDecisionTableRuleImpl in project camunda-engine-dmn by camunda.
the class ExpressionLanguageTest method testGlobalExpressionLanguageDecisionTable.
@Test
@DecisionResource(resource = GROOVY_DECISION_TABLE_DMN)
public void testGlobalExpressionLanguageDecisionTable() {
DmnDecisionTableImpl decisionTable = (DmnDecisionTableImpl) decision.getDecisionLogic();
for (DmnDecisionTableInputImpl dmnInput : decisionTable.getInputs()) {
assertThat(dmnInput.getExpression().getExpressionLanguage()).isEqualTo("groovy");
}
for (DmnDecisionTableRuleImpl dmnRule : decisionTable.getRules()) {
for (DmnExpressionImpl condition : dmnRule.getConditions()) {
assertThat(condition.getExpressionLanguage()).isEqualTo("groovy");
}
for (DmnExpressionImpl conclusion : dmnRule.getConclusions()) {
assertThat(conclusion.getExpressionLanguage()).isEqualTo("groovy");
}
}
assertExample(dmnEngine, decision);
verify(scriptEngineResolver, atLeastOnce()).getScriptEngineForLanguage("groovy");
verify(scriptEngineResolver, never()).getScriptEngineForLanguage(JUEL);
}
use of org.camunda.bpm.dmn.engine.impl.DmnDecisionTableRuleImpl 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;
}
use of org.camunda.bpm.dmn.engine.impl.DmnDecisionTableRuleImpl in project camunda-engine-dmn by camunda.
the class DefaultDmnTransform method transformDecisionTableRule.
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;
}
Aggregations