DMN Validation in Custom WebController

81 views
Skip to first unread message

Rhett S

unread,
Oct 13, 2021, 5:46:56 AM10/13/21
to Kogito development mailing list
Hi Kogito Team,
(as always. thanks for the support.)

I am attempting to write a custom controller in my Kogito project that will return back validation details on specific DMNs if triggered by client request.

My controller utilizes the Application bean from the auto-generated Kogito code.

@org.springframework.stereotype.Component
@RestController
@ComponentScan("org.kie.kogito.app")
public class HomeController {

@org.springframework.beans.factory.annotation.Autowired() @Qualifier("application")
Application application;


In a java method, I'm attempting to run the DMNValidator on the Traffic%20Violation DMN that I pull from the DecisionModel bean. I know that the Traffic%20Violation DMN has a couple validation warnings. (I can see them @ compile time.) But, in the red code, I get no output from the DMN Validation. What am I doing wrong? Grateful for help, and eager for a response, Rhett

        org.kie.kogito.decision.DecisionModel decision = application.get(org.kie.kogito.decision.DecisionModels.class).getDecisionModel("https://github.com/kiegroup/drools/kie-dmn/_A4BCA8B8-CF08-433F-93B2-A2598F19ECFF", "Traffic Violation");
        
        Set<DecisionNode> nodes = decision.getDMNModel().getDecisions();
        map.put("dmn-name", decision.getDMNModel().getName());

//this works! :-)
        int i = 0;
        for (DecisionNode n : nodes)
        {
            map.put("var" + String.valueOf(i), n.getName());
            System.out.println(n.getName());
        }

//this works! :-)
        Definitions definitions = decision.getDMNModel().getDefinitions();
        for (ItemDefinition item : definitions.getItemDefinition())
        {
            System.out.println(item.getName());
        }

//this doesn't work. validation warnings do not output. 
        DMNValidator validator = DMNValidatorFactory.newValidator();
        List<DMNMessage> messages = validator.validate(definitions);
        System.out.println("validation stuff");
        for (DMNMessage m : messages)
        {
            System.out.println(m.getText());
        }





Rhett S

unread,
Oct 17, 2021, 8:32:32 PM10/17/21
to Kogito development mailing list
Hi All, I was able to fulfill my need by using the JITRunner + Validator. thx. 
Reply all
Reply to author
Forward
0 new messages