use of org.camunda.bpm.dmn.engine.impl.DmnDecisionTableOutputImpl 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;
}
use of org.camunda.bpm.dmn.engine.impl.DmnDecisionTableOutputImpl 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.DmnDecisionTableOutputImpl in project camunda-engine-dmn by camunda.
the class DmnTransformListenerTest method shouldVerifyTransformedOutput.
@Test
public void shouldVerifyTransformedOutput() {
dmnEngine.parseDecisionRequirementsGraph(IoUtil.fileAsStream(DECISION_TRANSFORM_DMN));
DmnDecisionTableOutputImpl dmnOutput = listener.getDmnOutput();
Output output = listener.getOutput();
assertThat(dmnOutput.getId()).isEqualTo(output.getId()).isEqualTo("output1");
}
use of org.camunda.bpm.dmn.engine.impl.DmnDecisionTableOutputImpl in project camunda-engine-dmn by camunda.
the class DmnTransformTest method shouldTransformOutputs.
@Test
public void shouldTransformOutputs() {
DmnDecisionImpl decisionEntity = (DmnDecisionImpl) parseDecisionFromFile("decision1", TRANSFORM_DMN);
DmnDecisionTableImpl decisionTable = (DmnDecisionTableImpl) decisionEntity.getDecisionLogic();
List<DmnDecisionTableOutputImpl> outputs = decisionTable.getOutputs();
assertThat(outputs).hasSize(2);
DmnDecisionTableOutputImpl output = outputs.get(0);
assertThat(output.getId()).isEqualTo("output1");
assertThat(output.getName()).isEqualTo("camunda");
assertThat(output.getOutputName()).isEqualTo("camunda");
assertThat(output.getTypeDefinition()).isNotNull();
assertThat(output.getTypeDefinition().getTypeName()).isEqualTo("string");
output = outputs.get(1);
assertThat(output.getId()).isEqualTo("output2");
assertThat(output.getName()).isNull();
assertThat(output.getOutputName()).isEqualTo("out2");
assertThat(output.getTypeDefinition()).isNotNull();
assertThat(output.getTypeDefinition()).isEqualTo(new DefaultTypeDefinition());
}
use of org.camunda.bpm.dmn.engine.impl.DmnDecisionTableOutputImpl in project camunda-engine-dmn by camunda.
the class DecisionTableEvaluationHandler method evaluateOutputEntries.
protected Map<String, DmnEvaluatedOutput> evaluateOutputEntries(List<DmnDecisionTableOutputImpl> decisionTableOutputs, DmnDecisionTableRuleImpl matchingRule, VariableContext variableContext) {
Map<String, DmnEvaluatedOutput> outputEntries = new LinkedHashMap<String, DmnEvaluatedOutput>();
for (int outputIdx = 0; outputIdx < decisionTableOutputs.size(); outputIdx++) {
// evaluate output entry, skip empty expressions
DmnExpressionImpl conclusion = matchingRule.getConclusions().get(outputIdx);
if (isNonEmptyExpression(conclusion)) {
Object value = evaluateOutputEntry(conclusion, variableContext);
// transform to output type
DmnDecisionTableOutputImpl decisionTableOutput = decisionTableOutputs.get(outputIdx);
TypedValue typedValue = decisionTableOutput.getTypeDefinition().transform(value);
// set on result
DmnEvaluatedOutputImpl evaluatedOutput = new DmnEvaluatedOutputImpl(decisionTableOutput, typedValue);
outputEntries.put(decisionTableOutput.getOutputName(), evaluatedOutput);
}
}
return outputEntries;
}
Aggregations