use of org.camunda.bpm.dmn.engine.DmnDecisionResult in project camunda-engine-dmn by camunda.
the class DefaultDmnDecisionContext method evaluateDecision.
/**
* Evaluate a decision with the given {@link VariableContext}
*
* @param decision the decision to evaluate
* @param variableContext the available variable context
* @return the result of the decision evaluation
*/
public DmnDecisionResult evaluateDecision(DmnDecision decision, VariableContext variableContext) {
if (decision.getKey() == null) {
throw LOG.unableToFindAnyDecisionTable();
}
VariableMap variableMap = buildVariableMapFromVariableContext(variableContext);
List<DmnDecision> requiredDecisions = new ArrayList<DmnDecision>();
buildDecisionTree(decision, requiredDecisions);
List<DmnDecisionLogicEvaluationEvent> evaluatedEvents = new ArrayList<DmnDecisionLogicEvaluationEvent>();
DmnDecisionResult evaluatedResult = null;
for (DmnDecision evaluateDecision : requiredDecisions) {
DmnDecisionLogicEvaluationHandler handler = getDecisionEvaluationHandler(evaluateDecision);
DmnDecisionLogicEvaluationEvent evaluatedEvent = handler.evaluate(evaluateDecision, variableMap.asVariableContext());
evaluatedEvents.add(evaluatedEvent);
evaluatedResult = handler.generateDecisionResult(evaluatedEvent);
if (decision != evaluateDecision) {
addResultToVariableContext(evaluatedResult, variableMap, evaluateDecision);
}
}
generateDecisionEvaluationEvent(evaluatedEvents);
return evaluatedResult;
}
use of org.camunda.bpm.dmn.engine.DmnDecisionResult in project camunda-engine-dmn by camunda.
the class DefaultDmnEngine method evaluateDecisionTable.
public DmnDecisionTableResult evaluateDecisionTable(DmnDecision decision, VariableContext variableContext) {
ensureNotNull("decision", decision);
ensureNotNull("variableContext", variableContext);
if (decision instanceof DmnDecisionImpl && decision.isDecisionTable()) {
DefaultDmnDecisionContext decisionContext = new DefaultDmnDecisionContext(dmnEngineConfiguration);
DmnDecisionResult decisionResult = decisionContext.evaluateDecision(decision, variableContext);
return DmnDecisionTableResultImpl.wrap(decisionResult);
} else {
throw LOG.decisionIsNotADecisionTable(decision);
}
}
use of org.camunda.bpm.dmn.engine.DmnDecisionResult in project camunda-bpm-platform by camunda.
the class DecisionDefinitionRestServiceInteractionTest method testEvaluateDecisionById.
@Test
public void testEvaluateDecisionById() {
DmnDecisionResult decisionResult = MockProvider.createMockDecisionResult();
when(decisionEvaluationBuilderMock.evaluate()).thenReturn(decisionResult);
Map<String, Object> json = new HashMap<String, Object>();
json.put("variables", VariablesBuilder.create().variable("amount", 420).variable("invoiceCategory", "MISC").getVariables());
given().pathParam("id", MockProvider.EXAMPLE_DECISION_DEFINITION_ID).contentType(POST_JSON_CONTENT_TYPE).body(json).then().expect().statusCode(Status.OK.getStatusCode()).when().post(EVALUATE_DECISION_URL);
Map<String, Object> expectedVariables = new HashMap<String, Object>();
expectedVariables.put("amount", 420);
expectedVariables.put("invoiceCategory", "MISC");
verify(decisionEvaluationBuilderMock).variables(expectedVariables);
verify(decisionEvaluationBuilderMock).evaluate();
}
use of org.camunda.bpm.dmn.engine.DmnDecisionResult in project camunda-bpm-platform by camunda.
the class DecisionDefinitionRestServiceInteractionTest method testEvaluateDecisionMultipleDecisionValues.
@Test
public void testEvaluateDecisionMultipleDecisionValues() {
DmnDecisionResult decisionResult = new MockDecisionResultBuilder().resultEntries().entry("status", Variables.stringValue("gold")).entry("assignee", Variables.stringValue("manager")).build();
when(decisionEvaluationBuilderMock.evaluate()).thenReturn(decisionResult);
Map<String, Object> json = new HashMap<String, Object>();
json.put("variables", Collections.emptyMap());
given().pathParam("id", MockProvider.EXAMPLE_DECISION_DEFINITION_ID).contentType(POST_JSON_CONTENT_TYPE).body(json).then().expect().statusCode(Status.OK.getStatusCode()).body("size()", is(1)).body("[0].size()", is(2)).body("[0].status.value", is("gold")).body("[0].assignee.value", is("manager")).when().post(EVALUATE_DECISION_URL);
}
use of org.camunda.bpm.dmn.engine.DmnDecisionResult in project camunda-bpm-platform by camunda.
the class DecisionServiceTest method evaluateDecisionByKeyAndVersion.
@Deployment(resources = DMN_DECISION_LITERAL_EXPRESSION)
@Test
public void evaluateDecisionByKeyAndVersion() {
testRule.deploy(DMN_DECISION_LITERAL_EXPRESSION_V2);
DmnDecisionResult decisionResult = decisionService.evaluateDecisionByKey(DECISION_DEFINITION_KEY).version(1).variables(createVariables()).evaluate();
assertThatDecisionHasResult(decisionResult, RESULT_OF_FIRST_VERSION);
}
Aggregations