After a decision definition has been evaluated either from a BPMN process, CMMNcase or through the Decision Service, the inputs and outputs are saved in theHistory of the platform. The history entity is of typeHistoricDecisionInstance and has the event type evaluate.

For details about the history mechanism as such, refer to the History and AuditEvent Log.

History Level

History level FULL is required. Otherwise, no historyfor decisions is created.

Query for evaluated Decisions

The History Service can be used to query for HistoricDecisionInstances. Forexample, use the following query to get all history entries for a decisiondefinition with key checkOrder ordered by the time when the decision wasevaluated.

  1. List<HistoricDecisionInstance> historicDecisions = processEngine
  2. .getHistoryService()
  3. .createHistoricDecisionInstanceQuery()
  4. .decisionDefinitionKey("checkOrder")
  5. .orderByEvaluationTime()
  6. .asc()
  7. .list();

Decisions which were evaluated from a BPMN business rule task can befiltered by the process definition id or key and process instance id.

  1. HistoryService historyService = processEngine.getHistoryService();
  2. List<HistoricDecisionInstance> historicDecisionInstances = historyService
  3. .createHistoricDecisionInstanceQuery()
  4. .processDefinitionId("processDefinitionId")
  5. .list();
  6. historicDecisionInstances = historyService
  7. .createHistoricDecisionInstanceQuery()
  8. .processDefinitionKey("processDefinitionKey")
  9. .list();
  10. historicDecisionInstances = historyService
  11. .createHistoricDecisionInstanceQuery()
  12. .processInstanceId("processInstanceId")
  13. .list();

Decisions which were evaluated from a CMMN decision task can be filteredby the case definition id or key and case instance id.

  1. HistoryService historyService = processEngine.getHistoryService();
  2. List<HistoricDecisionInstance> historicDecisionInstances = historyService
  3. .createHistoricDecisionInstanceQuery()
  4. .caseDefinitionId("caseDefinitionId")
  5. .list();
  6. historicDecisionInstances = historyService
  7. .createHistoricDecisionInstanceQuery()
  8. .caseDefinitionKey("caseDefinitionKey")
  9. .list();
  10. historicDecisionInstances = historyService
  11. .createHistoricDecisionInstanceQuery()
  12. .caseInstanceId("caseInstanceId")
  13. .list();

Note that the inputs and outputs of a decision are not included in the queryresult by default. Call the methods includeInputs() and includeOutputs() onthe query to retrieve the inputs and outputs from the result.

  1. List<HistoricDecisionInstance> historicDecisions = processEngine
  2. .getHistoryService()
  3. .createHistoricDecisionInstanceQuery()
  4. .decisionDefinitionKey("checkOrder")
  5. .includeInputs()
  6. .includeOutputs()
  7. .list();

The Historic Decision Instance

The HistoricDecisionInstance contains information about a singleevaluation of a decision.

  1. HistoricDecisionInstance historicDecision = ...;
  2. // id of the decision definition
  3. String decisionDefinitionId = historicDecision.getDecisionDefinitionId();
  4. // key of the decision definition
  5. String decisionDefinitionKey = historicDecision.getDecisionDefinitionKey();
  6. // name of the decision
  7. String decisionDefinitionName = historicDecision.getDecisionDefinitionName();
  8. // time when the decision was evaluated
  9. Date evaluationTime = historicDecision.getEvaluationTime();
  10. // inputs of the decision (if includeInputs was specified in the query)
  11. List<HistoricDecisionInputInstance> inputs = historicDecision.getInputs();
  12. // outputs of the decision (if includeOutputs was specified in the query)
  13. List<HistoricDecisionOutputInstance> outputs = historicDecision.getOutputs();

In case the decision was evaluated from a process, information of the processdefinition, the process instance and the activity is set in theHistoricDecisionInstance. The same applies for decisions evaluated froma case, where the history instance will reference the corresponding caseinstances.

Additionally, if the decision is a decision table with hit policy collect andan aggregator function, then the result of the aggregation can be retrieved bythe getCollectResultValue() method.

For more information on supported hit policies please see the DMN 1.1reference.

Historic Decision Input Instance

The HistoricDecisionInputInstance represents one input of anevaluated decision (e.g., an input clause of a decision table).

  1. HistoricDecisionInputInstance input = ...;
  2. // id of the input clause
  3. String clauseId = input.getClauseId();
  4. // label of the input clause
  5. String clauseName = input.getClauseName();
  6. // evaluated value of the input expression
  7. Object value = input.getValue();
  8. // evaluated value of the input expression as typed value
  9. // which contains type information
  10. TypedValue typedValue = input.getTypedValue();

Note that the value may be the result of a type transformation in case theinput specifies a type.

Historic Decision Output Instance

The HistoricDecisionOutputInstance represents one output entry of anevaluated decision. If the decision is implemented as decision table, theHistoricDecisionInstance contains one HistoricDecisionOutputInstancefor each output clause and matched rule.

  1. HistoricDecisionOutputInstance output = ...;
  2. // id of the output clause
  3. String clauseId = output.getClauseId();
  4. // label of the output clause
  5. String clauseName = output.getClauseName();
  6. // evaluated value of the output entry
  7. Object value = output.getValue();
  8. // evaluated value of the output entry as typed value
  9. // which contains type information
  10. TypedValue typedValue = output.getTypedValue();
  11. // id of matched rule the output belongs to
  12. String ruleId = output.getRuleId();
  13. // the position of the rule in the list of matched rules
  14. Integer ruleOrder = output.getRuleOrder();
  15. // name of the output clause used as output variable identifier
  16. String variableName = output.getVariableName();

Note that the value may be the result of a type transformation in case theoutput specifies a type.

Cockpit

You can audit the evaluated decision definitions in the Cockpit webapp.

原文: https://docs.camunda.org/manual/7.9/user-guide/process-engine/decisions/history/