Java Code Examples for org.kie.api.builder.Results#getMessages()

The following examples show how to use org.kie.api.builder.Results#getMessages() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KieSessionUtils.java    From hacep with Apache License 2.0 6 votes vote down vote up
public static void logResults(Results results) {
    for (Message result : results.getMessages()) {
        switch (result.getLevel()) {
            case ERROR:
                LOGGER.error(result.toString());
                break;
            case WARNING:
                LOGGER.warn(result.toString());
                break;
            case INFO:
                LOGGER.info(result.toString());
                break;
            default:
                LOGGER.warn(result.toString());
        }
    }
}
 
Example 2
Source File: BaseTest.java    From iot-ocp with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
    KieServices kieServices = KieServices.Factory.get();

    KieContainer kContainer = kieServices.getKieClasspathContainer();
    Results verifyResults = kContainer.verify();
    for (Message m : verifyResults.getMessages()) {
        LOG.debug("Kie container message: {}", m);
    }

    KieBase kieBase = kContainer.getKieBase();
    LOG.debug("Created kieBase");

    for ( KiePackage kp : kieBase.getKiePackages() ) {
        for (Rule rule : kp.getRules()) {
            LOG.debug("kp " + kp + " rule " + rule.getName());
        }
    }

    session = kieBase.newKieSession();
    LOG.info(session.getGlobals().toString());
    Logger kieLogger = LoggerFactory.getLogger(this.getClass());
   // session.setGlobal("logger",kieLogger);
}
 
Example 3
Source File: RulesConfiguration.java    From cia with Apache License 2.0 6 votes vote down vote up
/**
 * Kie container.
 *
 * @return the kie container
 */
@Bean
public KieContainer kieContainer() {
	final KieServices kieServices = KieServices.Factory.get();

	final KieContainer kContainer = kieServices.getKieClasspathContainer();
	LOGGER.info("Using classloader {}, parent {}",kContainer.getClassLoader(),kContainer.getClassLoader().getParent());
	
	final Results verifyResults = kContainer.verify();
	for (final Message m : verifyResults.getMessages()) {
		LOGGER.warn("Kie container message: {}", m);
	}

	final KieBase kieBase = kContainer.getKieBase();
	for (final KiePackage kp : kieBase.getKiePackages()) {
		for (final Rule rule : kp.getRules()) {
			LOGGER.info("Loadded Rule: {} {}", kp, rule.getName());
		}
	}
	

	return kContainer;
}
 
Example 4
Source File: KieSessionUtils.java    From fw-spring-cloud with Apache License 2.0 5 votes vote down vote up
public static KieSession createKieSessionFromDRL(String drl) throws Exception{
    KieHelper kieHelper = new KieHelper();
    kieHelper.addContent(drl, ResourceType.DRL);
    Results results = kieHelper.verify();
    if (results.hasMessages(Message.Level.WARNING, Message.Level.ERROR)) {
        List<Message> messages = results.getMessages(Message.Level.WARNING, Message.Level.ERROR);
        for (Message message : messages) {
            System.out.println("Error: "+message.getText());
        }
        // throw new IllegalStateException("Compilation errors were found. Check the logs.");
    }
    return kieHelper.build().newKieSession();
}
 
Example 5
Source File: PhreakInspector.java    From drools-workshop with Apache License 2.0 5 votes vote down vote up
private void assertBuildResults(Results results) {
    if (results.hasMessages(Message.Level.WARNING, Message.Level.ERROR)) {
        List<Message> messages = results.getMessages(Message.Level.WARNING, Message.Level.ERROR);
        for (Message message : messages) {
            System.out.printf("[%s] - %s[%s,%s]: %s", message.getLevel(), message.getPath(), message.getLine(), message.getColumn(), message.getText());
        }

        throw new IllegalStateException("Compilation errors were found. Check the logs.");
    }
}