asaizu
March 18, 2021, 9:24am
1
Hello! I am trying to understand how the Historic Decision are retrieved.
I am first executing a rule decision:
dmnRuleService.createExecuteDecisionBuilder().decisionKey(DECISION_KEY)
.variables(flowableQuery)
.executeWithAuditTrail()
.getDecisionResult()
And after that I am trying to get the history for the above executed decision
List<DmnHistoricDecisionExecution> history = dmnHistoryService.createHistoricDecisionExecutionQuery()
.decisionKey(DECISION_KEY).list();
And this list comes empty.
Am I missing something?
joram
March 18, 2021, 9:38am
2
That looks like it should work. Where/how are you calling these methods? Could it be you’re calling this at a moment the transaction of the first method hasn’t completed yet (e.g in a JavaDelegate)?
asaizu
March 18, 2021, 9:40am
3
I am doing it inside a test, should I try and give it some time to finish the transaction?
joram
March 18, 2021, 9:44am
4
No, that shoud be ok. Can you share your test?
asaizu
March 18, 2021, 9:47am
5
Sure!
@MicronautTest
@Testcontainers
@Property(name = "flowable.rules-location", value = "rules/dummy_risk_locations.dmn")
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class FlowableDummyRulesTest {
public static final String COUNTRY = "country";
public static final String CONTRACT_TYPE = "contractType";
public static final String CLASS_OF_BUSINESS = "classOfBusiness";
public static final String EXISTING_COUNTRY = "US";
public static final String EXISTING_CONTRACT_TYPE = "INSURANCE";
public static final String EXISTING_CLASS_OF_BUSINESS = "MOVEABLE";
private static final String DECISION_KEY = "RISK_LOCATIONS";
@Inject
DmnHistoryService dmnHistoryService;
@Inject
DmnRuleService dmnRuleService;
@Test
void executeRuleWithResult() {
List<Map<String, Object>> decisionResult = queryFlowable(buildQueryMap());
List<DmnHistoricDecisionExecution> history = dmnHistoryService.createHistoricDecisionExecutionQuery()
.decisionKey(DECISION_KEY).list();
assertFalse(decisionResult.isEmpty());
assertFalse(history.isEmpty());
}
private List<Map<String, Object>> queryFlowable(Map<String, Object> flowableQuery) {
return dmnRuleService.createExecuteDecisionBuilder().decisionKey(DECISION_KEY)
.variables(flowableQuery)
.executeWithAuditTrail()
.getDecisionResult();
}
private Map<String, Object> buildQueryMap() {
return Map.of(COUNTRY, EXISTING_COUNTRY,
CONTRACT_TYPE, EXISTING_CONTRACT_TYPE,
CLASS_OF_BUSINESS, EXISTING_CLASS_OF_BUSINESS);
}
}