Search in sources :

Example 11 with DmnDecisionResult

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;
}
Also used : DmnDecisionResult(org.camunda.bpm.dmn.engine.DmnDecisionResult) DmnDecisionLogicEvaluationHandler(org.camunda.bpm.dmn.engine.impl.evaluation.DmnDecisionLogicEvaluationHandler) VariableMap(org.camunda.bpm.engine.variable.VariableMap) DmnDecisionLogicEvaluationEvent(org.camunda.bpm.dmn.engine.delegate.DmnDecisionLogicEvaluationEvent) ArrayList(java.util.ArrayList) DmnDecision(org.camunda.bpm.dmn.engine.DmnDecision)

Example 12 with DmnDecisionResult

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);
    }
}
Also used : DmnDecisionResult(org.camunda.bpm.dmn.engine.DmnDecisionResult)

Example 13 with DmnDecisionResult

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();
}
Also used : DmnDecisionResult(org.camunda.bpm.dmn.engine.DmnDecisionResult) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 14 with DmnDecisionResult

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);
}
Also used : DmnDecisionResult(org.camunda.bpm.dmn.engine.DmnDecisionResult) MockDecisionResultBuilder(org.camunda.bpm.engine.rest.helper.MockDecisionResultBuilder) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 15 with DmnDecisionResult

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);
}
Also used : DmnDecisionResult(org.camunda.bpm.dmn.engine.DmnDecisionResult) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

DmnDecisionResult (org.camunda.bpm.dmn.engine.DmnDecisionResult)54 Test (org.junit.Test)40 DmnEngineTest (org.camunda.bpm.dmn.engine.test.DmnEngineTest)29 DecisionResource (org.camunda.bpm.dmn.engine.test.DecisionResource)25 HashMap (java.util.HashMap)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 Matchers.anyString (org.mockito.Matchers.anyString)6 Deployment (org.camunda.bpm.engine.test.Deployment)5 DmnDecisionResultEntries (org.camunda.bpm.dmn.engine.DmnDecisionResultEntries)4 DecisionDefinition (org.camunda.bpm.engine.repository.DecisionDefinition)4 VariableContext (org.camunda.bpm.engine.variable.context.VariableContext)4 TypedValue (org.camunda.bpm.engine.variable.value.TypedValue)4 DmnEngine (org.camunda.bpm.dmn.engine.DmnEngine)3 DefaultDmnEngineConfiguration (org.camunda.bpm.dmn.engine.impl.DefaultDmnEngineConfiguration)3 MockDecisionResultBuilder (org.camunda.bpm.engine.rest.helper.MockDecisionResultBuilder)3 DmnDecisionRequirementsGraph (org.camunda.bpm.dmn.engine.DmnDecisionRequirementsGraph)2 DmnDecisionResultException (org.camunda.bpm.dmn.engine.impl.DmnDecisionResultException)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 DmnDecision (org.camunda.bpm.dmn.engine.DmnDecision)1