use of org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl 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;
}
use of org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl in project camunda-engine-dmn by camunda.
the class DmnTransformTest method shouldTransformDecisionWithLiteralExpression.
@Test
public void shouldTransformDecisionWithLiteralExpression() {
List<DmnDecision> decisions = parseDecisionsFromFile(DECISION_WITH_LITERAL_EXPRESSION_DMN);
assertThat(decisions).hasSize(1);
DmnDecision decision = decisions.get(0);
assertThat(decision).isNotNull();
assertThat(decision.getKey()).isEqualTo("decision");
assertThat(decision.getName()).isEqualTo("Decision");
assertThat(decision.getDecisionLogic()).isNotNull().isInstanceOf(DmnDecisionLiteralExpressionImpl.class);
DmnDecisionLiteralExpressionImpl dmnDecisionLiteralExpression = (DmnDecisionLiteralExpressionImpl) decision.getDecisionLogic();
DmnVariableImpl variable = dmnDecisionLiteralExpression.getVariable();
assertThat(variable).isNotNull();
assertThat(variable.getId()).isEqualTo("v1");
assertThat(variable.getName()).isEqualTo("c");
assertThat(variable.getTypeDefinition()).isNotNull();
assertThat(variable.getTypeDefinition().getTypeName()).isEqualTo("integer");
DmnExpressionImpl dmnExpression = dmnDecisionLiteralExpression.getExpression();
assertThat(dmnExpression).isNotNull();
assertThat(dmnExpression.getId()).isEqualTo("e1");
assertThat(dmnExpression.getExpressionLanguage()).isEqualTo("groovy");
assertThat(dmnExpression.getExpression()).isEqualTo("a + b");
assertThat(dmnExpression.getTypeDefinition()).isNull();
}
use of org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl in project camunda-engine-dmn by camunda.
the class DmnTransformTest method shouldTransformInputs.
@Test
public void shouldTransformInputs() {
DmnDecisionImpl decisionEntity = (DmnDecisionImpl) parseDecisionFromFile("decision1", TRANSFORM_DMN);
DmnDecisionTableImpl decisionTable = (DmnDecisionTableImpl) decisionEntity.getDecisionLogic();
List<DmnDecisionTableInputImpl> inputs = decisionTable.getInputs();
assertThat(inputs).hasSize(2);
DmnDecisionTableInputImpl input = inputs.get(0);
assertThat(input.getId()).isEqualTo("input1");
assertThat(input.getName()).isEqualTo("camunda");
assertThat(input.getInputVariable()).isEqualTo("camunda");
DmnExpressionImpl inputExpression = input.getExpression();
assertThat(inputExpression).isNotNull();
assertThat(inputExpression.getId()).isEqualTo("inputExpression");
assertThat(inputExpression.getName()).isNull();
assertThat(inputExpression.getExpressionLanguage()).isEqualTo("camunda");
assertThat(inputExpression.getExpression()).isEqualTo("camunda");
assertThat(inputExpression.getTypeDefinition()).isNotNull();
assertThat(inputExpression.getTypeDefinition().getTypeName()).isEqualTo("string");
input = inputs.get(1);
assertThat(input.getId()).isEqualTo("input2");
assertThat(input.getName()).isNull();
assertThat(input.getInputVariable()).isEqualTo(DmnDecisionTableInputImpl.DEFAULT_INPUT_VARIABLE_NAME);
inputExpression = input.getExpression();
assertThat(inputExpression).isNotNull();
assertThat(inputExpression.getId()).isNull();
assertThat(inputExpression.getName()).isNull();
assertThat(inputExpression.getExpressionLanguage()).isNull();
assertThat(inputExpression.getExpression()).isNull();
assertThat(inputExpression.getTypeDefinition()).isNotNull();
assertThat(inputExpression.getTypeDefinition()).isEqualTo(new DefaultTypeDefinition());
}
use of org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl in project camunda-engine-dmn by camunda.
the class DefaultDmnTransform method transformDecisionTableInput.
protected DmnDecisionTableInputImpl transformDecisionTableInput(Input input) {
DmnElementTransformHandler<Input, DmnDecisionTableInputImpl> handler = handlerRegistry.getHandler(Input.class);
DmnDecisionTableInputImpl dmnInput = handler.handleElement(this, input);
// validate input id
if (dmnInput.getId() == null) {
throw LOG.decisionTableInputIdIsMissing(decision, dmnInput);
}
InputExpression inputExpression = input.getInputExpression();
if (inputExpression != null) {
parent = dmnInput;
DmnExpressionImpl dmnExpression = transformInputExpression(inputExpression);
if (dmnExpression != null) {
dmnInput.setExpression(dmnExpression);
}
}
return dmnInput;
}
use of org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl in project camunda-engine-dmn by camunda.
the class DefaultDmnTransform method transformDecisionLiteralExpression.
protected DmnDecisionLiteralExpressionImpl transformDecisionLiteralExpression(Decision decision, LiteralExpression literalExpression) {
DmnDecisionLiteralExpressionImpl dmnDecisionLiteralExpression = new DmnDecisionLiteralExpressionImpl();
Variable variable = decision.getVariable();
if (variable == null) {
throw LOG.decisionVariableIsMissing(decision.getId());
}
DmnVariableImpl dmnVariable = transformVariable(variable);
dmnDecisionLiteralExpression.setVariable(dmnVariable);
DmnExpressionImpl dmnLiteralExpression = transformLiteralExpression(literalExpression);
dmnDecisionLiteralExpression.setExpression(dmnLiteralExpression);
return dmnDecisionLiteralExpression;
}
Aggregations