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

The following examples show how to use org.kie.api.builder.Results#hasMessages() . 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: AbductionTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
protected KieSession getSessionFromString( String drlString, KieBaseConfiguration kbConf ) {
    KieHelper kieHelper = new KieHelper();
    kieHelper.addContent( drlString, ResourceType.DRL );

    Results res = kieHelper.verify();
    if ( res.hasMessages( Message.Level.ERROR ) ) {
        fail( res.getMessages( Message.Level.ERROR ).toString() );
    }

    if ( kbConf == null ) {
        kbConf = KieServices.Factory.get().newKieBaseConfiguration();
    }
    kbConf.setOption( EqualityBehaviorOption.EQUALITY );
    KieBase kieBase = kieHelper.build( kbConf );


    KieSessionConfiguration ksConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
    ((SessionConfiguration) ksConf).setBeliefSystemType( BeliefSystemType.DEFEASIBLE );
    return kieBase.newKieSession( ksConf, null );
}
 
Example 2
Source File: CommonTestMethodBase.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
public static byte[] createJar(KieServices ks, String kmoduleContent, Predicate<String> classFilter, ReleaseId releaseId, Resource... resources) {
    KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).writeKModuleXML(kmoduleContent);
    for (int i = 0; i < resources.length; i++) {
        if (resources[i] != null) {
            kfs.write(resources[i]);
        }
    }
    KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    ((InternalKieBuilder) kieBuilder).buildAll(classFilter);
    Results results = kieBuilder.getResults();
    if (results.hasMessages(Message.Level.ERROR)) {
        throw new IllegalStateException(results.getMessages(Message.Level.ERROR).toString());
    }
    InternalKieModule kieModule = (InternalKieModule) ks.getRepository()
            .getKieModule(releaseId);
    byte[] jar = kieModule.getBytes();
    return jar;
}
 
Example 3
Source File: RulesManager.java    From hacep with Apache License 2.0 6 votes vote down vote up
public boolean updateToVersion(String version) {
    checkStatus();
    if (StringUtils.isEmpty(version)) {
        throw new IllegalArgumentException("Update to version cannot accept an empty version");
    }
    ReleaseId releaseId = kieServices.newReleaseId(
            rulesConfiguration.getGroupId(),
            rulesConfiguration.getArtifactId(),
            version);
    Results results = kieContainer.updateToVersion(releaseId);
    this.releaseId = kieContainer.getReleaseId();
    KieSessionUtils.logResults(results);
    if (results.hasMessages(Message.Level.ERROR)) {
        LOGGER.error("Update to version {} aborted due to errors", version);
        return false;
    }
    LOGGER.info("Update to version {} completed", version);
    return true;
}
 
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: KieHelper.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public KieContainer getKieContainer() {
    KieBuilder kieBuilder = ks.newKieBuilder( kfs, classLoader ).buildAll();
    Results results = kieBuilder.getResults();
    if (results.hasMessages(Message.Level.ERROR)) {
        throw new RuntimeException(results.getMessages().toString());
    }
    KieContainer kieContainer = ks.newKieContainer( ks.getRepository().getDefaultReleaseId(), classLoader );
    return kieContainer;
}
 
Example 6
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.");
    }
}
 
Example 7
Source File: KieAPITestUtils.java    From hacep with Apache License 2.0 4 votes vote down vote up
public static void hasErrors(Results results) {
    if (results.hasMessages(Message.Level.ERROR)) {
        throw new RuntimeException("Build errors\n" + results.toString());
    }
}