Using DmnHistoryService

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?

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)?

I am doing it inside a test, should I try and give it some time to finish the transaction?

No, that shoud be ok. Can you share your test?

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);
    }

}

Found anything? :smile: