use of org.camunda.bpm.dmn.engine.impl.DmnDecisionLiteralExpressionImpl in project camunda-engine-dmn by camunda.
the class DecisionLiteralExpressionEvaluationHandler method evaluate.
@Override
public DmnDecisionLogicEvaluationEvent evaluate(DmnDecision decision, VariableContext variableContext) {
DmnDecisionLiteralExpressionEvaluationEventImpl evaluationResult = new DmnDecisionLiteralExpressionEvaluationEventImpl();
evaluationResult.setDecision(decision);
evaluationResult.setExecutedDecisionElements(1);
DmnDecisionLiteralExpressionImpl dmnDecisionLiteralExpression = (DmnDecisionLiteralExpressionImpl) decision.getDecisionLogic();
DmnVariableImpl variable = dmnDecisionLiteralExpression.getVariable();
DmnExpressionImpl expression = dmnDecisionLiteralExpression.getExpression();
Object evaluateExpression = evaluateLiteralExpression(expression, variableContext);
TypedValue typedValue = variable.getTypeDefinition().transform(evaluateExpression);
evaluationResult.setOutputValue(typedValue);
evaluationResult.setOutputName(variable.getName());
return evaluationResult;
}
use of org.camunda.bpm.dmn.engine.impl.DmnDecisionLiteralExpressionImpl 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.DmnDecisionLiteralExpressionImpl in project camunda-engine-dmn by camunda.
the class DefaultDmnTransform method transformDecision.
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;
}
use of org.camunda.bpm.dmn.engine.impl.DmnDecisionLiteralExpressionImpl 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;
}
use of org.camunda.bpm.dmn.engine.impl.DmnDecisionLiteralExpressionImpl in project camunda-engine-dmn by camunda.
the class ExpressionLanguageTest method testGlobalExpressionLanguageDecisionLiteralExpression.
@Test
@DecisionResource(resource = GROOVY_DECISION_LITERAL_EXPRESSION_DMN)
public void testGlobalExpressionLanguageDecisionLiteralExpression() {
DmnDecisionLiteralExpressionImpl decisionLiteralExpression = (DmnDecisionLiteralExpressionImpl) decision.getDecisionLogic();
assertThat(decisionLiteralExpression.getExpression().getExpressionLanguage()).isEqualTo("groovy");
dmnEngine.evaluateDecision(decision, Variables.createVariables().putValue("a", 2).putValue("b", 3));
verify(scriptEngineResolver, atLeastOnce()).getScriptEngineForLanguage("groovy");
verify(scriptEngineResolver, never()).getScriptEngineForLanguage(JUEL);
}
Aggregations