Package org.kie.api

Examples of org.kie.api.KieServices


    private static final String packageName = "org.drools.pmml.pmml_4_2";

    @Test
    public void testCompositeBuilding() throws Exception {
        KieServices ks = KieServices.Factory.get();
        KieFileSystem kfs = ks.newKieFileSystem();

        kfs.write( ResourceFactory.newClassPathResource( source1 ).setResourceType( ResourceType.PMML ) );
        kfs.write( ResourceFactory.newClassPathResource( source2 ).setResourceType( ResourceType.PMML ) );

        KieBuilder kb = ks.newKieBuilder( kfs );
        kb.buildAll();

        KieSession kSession = ks.newKieContainer( ks.getRepository().getDefaultReleaseId() ).newKieSession();

        kSession.fireAllRules();

        assertEquals( 2, kSession.getObjects( new ClassObjectFilter( ModelMarker.class ) ).size() );
        assertEquals( 11, kSession.getObjects( new ClassObjectFilter( kSession.getKieBase().getFactType( packageName, "Synapse" ).getFactClass() ) ).size() );
View Full Code Here


    @Test
    public void testIncrementalBuilding() throws Exception {
        ReleaseId releaseId1 = KieServices.Factory.get().newReleaseId( "org.test", "test", "1.0.0-SNAPSHOT" );

        KieServices ks = KieServices.Factory.get();
        KieFileSystem kfs = ks.newKieFileSystem();
        KieBuilder kb = ks.newKieBuilder( kfs );

        kfs.generateAndWritePomXML( releaseId1 );
        kfs.write( ResourceFactory.newClassPathResource( source1 ).setResourceType( ResourceType.PMML ) );
        kb.buildAll();

        KieContainer kc = ks.newKieContainer( releaseId1 );
        KieSession kSession = kc.newKieSession();
        kSession.fireAllRules();


        kfs.write( ResourceFactory.newClassPathResource( source2 ).setResourceType( ResourceType.PMML ) );
View Full Code Here

                          "" +
                          "rule Log when $x : MockColdTrait() then System.out.println( \"IN \" + $x ); end " +
                          "rule Log2 when $x : Cold() then System.out.println( \"OUT \" + $x ); end "
                ;

        KieServices ks = KieServices.Factory.get();
        KieFileSystem kfs = ks.newKieFileSystem();

        kfs.write( ResourceFactory.newClassPathResource( pmmlSource ).setResourceType( ResourceType.PMML ) );
        kfs.write( ResourceFactory.newByteArrayResource( extraDrl.getBytes() )
                           .setSourcePath( "rules.drl" )
                           .setResourceType( ResourceType.DRL ) );

        Results res = ks.newKieBuilder( kfs ).buildAll().getResults();
        if ( res.hasMessages( Message.Level.ERROR ) ) {
            System.out.println( res.getMessages( Message.Level.ERROR ) );
        }
        assertEquals( 0, res.getMessages( Message.Level.ERROR ).size() );

        KieSession kSession = ks.newKieContainer( ks.getRepository().getDefaultReleaseId() ).newKieSession();

        kSession.insert( "trigger" );
        kSession.fireAllRules();

        System.out.println( reportWMObjects( kSession ) );
View Full Code Here


    @Test
    public void testKieBaseCompilation() {

        KieServices ks = KieServices.Factory.get();
        Results rs = ks.getKieClasspathContainer().verify();
        System.out.println( rs.getMessages() );
        assertFalse( rs.hasMessages( Message.Level.ERROR ) );

    }
View Full Code Here

    }


    @Test
    public void testErrorDuringGeneration() {
        KieServices ks = KieServices.Factory.get();
        KieFileSystem kfs = ks.newKieFileSystem();

        kfs.write( ResourceFactory.newByteArrayResource( pmlm.getBytes() )
                           .setResourceType( ResourceType.PMML )
                           .setSourcePath( "pmlm.pmml" )
        );

        KieBuilder kb = ks.newKieBuilder( kfs );
        kb.buildAll();
        assertEquals( 1, kb.getResults().getMessages( Message.Level.ERROR ).size() );
    }
View Full Code Here

        assertEquals( 1, kb.getResults().getMessages( Message.Level.ERROR ).size() );
    }

    @Test
    public void testNoErrorDuringGeneration() {
        KieServices ks = KieServices.Factory.get();
        KieFileSystem kfs = ks.newKieFileSystem();

        kfs.write( ResourceFactory.newByteArrayResource( pmml.getBytes() )
                           .setResourceType( ResourceType.PMML )
                           .setSourcePath( "pmml.pmml" )
        );

        KieBuilder kb = ks.newKieBuilder( kfs );
        kb.buildAll();
        assertEquals( 0, kb.getResults().getMessages( Message.Level.ERROR ).size() );
    }
View Full Code Here

    protected KieSession getModelSession(String pmmlSource, boolean verbose) {
        return getModelSession(new String[] {pmmlSource}, verbose);
    }

    protected KieSession getModelSession( String[] pmmlSources, boolean verbose ) {
        KieServices ks = KieServices.Factory.get();
        KieRepository kr = ks.getRepository();
        KieFileSystem kfs = ks.newKieFileSystem();

        for ( int j = 0; j < pmmlSources.length; j++ ) {
            Resource res = ResourceFactory.newClassPathResource( pmmlSources[ j ] ).setResourceType( ResourceType.PMML );
            kfs.write( res );
        }

        KieModuleModel model = ks.newKieModuleModel();
        KieBaseModel kbModel = model.newKieBaseModel( DEFAULT_KIEBASE )
                .setDefault( true )
                .addPackage( BASE_PACK )
                .setEventProcessingMode( EventProcessingOption.STREAM )
                ;

        kfs.writeKModuleXML( model.toXML() );

        KieBuilder kb = ks.newKieBuilder( kfs );

        kb.buildAll();
        if ( kb.getResults().hasMessages( Message.Level.ERROR ) ) {
            throw new RuntimeException( "Build Errors:\n" + kb.getResults().toString() );
        }

        KieContainer kContainer = ks.newKieContainer( kr.getDefaultReleaseId() );

        KieBase kieBase = kContainer.getKieBase();
        return kieBase.newKieSession();
    }
View Full Code Here

    private static KieBase readKnowledgeBase( InputStream theory ) {
        return readKnowledgeBase( Arrays.asList( theory ) );
    }

    private static KieBase readKnowledgeBase( List<InputStream> theory ) {
        KieServices ks = KieServices.Factory.get();
        KieRepository kr = ks.getRepository();
        KieFileSystem kfs = ks.newKieFileSystem();

        for ( int j = 0; j < theory.size(); j++ ) {
            Resource res = ks.getResources().newInputStreamResource( theory.get( j ) );
            kfs.write( RESOURCE_PATH + "source_" + j + ".drl", res );
        }

        KieModuleModel model = ks.newKieModuleModel();
        KieBaseModel kbModel = model.newKieBaseModel( DEFAULT_KIEBASE )
                .setDefault( true )
                .addPackage( BASE_PACK )
                .setEventProcessingMode( EventProcessingOption.STREAM );

        kfs.writeKModuleXML( model.toXML() );

        KieBuilder kb = ks.newKieBuilder( kfs );

        kb.buildAll();
        if ( kb.getResults().hasMessages( Message.Level.ERROR ) ) {
            throw new RuntimeException( "Build Errors:\n" + kb.getResults().toString() );
        }

        KieContainer kContainer = ks.newKieContainer( kr.getDefaultReleaseId() );

        return kContainer.getKieBase();
    }
View Full Code Here

import java.io.PrintStream;

public class KieModuleModelExample {

    public void go(PrintStream out) {
        KieServices ks = KieServices.Factory.get();
        KieFileSystem kfs = ks.newKieFileSystem();

        Resource ex1Res = ks.getResources().newFileSystemResource(getFile("named-kiesession"));
        Resource ex2Res = ks.getResources().newFileSystemResource(getFile("kiebase-inclusion"));

        ReleaseId rid = ks.newReleaseId("org.drools", "kiemodulemodel-example", Drools.getFullVersion());
        kfs.generateAndWritePomXML(rid);

        KieModuleModel kModuleModel = ks.newKieModuleModel();
        kModuleModel.newKieBaseModel("kiemodulemodel")
                    .addInclude("kbase1")
                    .addInclude("kbase2")
                    .newKieSessionModel("ksession6");

        kfs.writeKModuleXML(kModuleModel.toXML());
        kfs.write("src/main/resources/kiemodulemodel/HAL6.drl", getRule());

        KieBuilder kb = ks.newKieBuilder(kfs);
        kb.setDependencies(ex1Res, ex2Res);
        kb.buildAll(); // kieModule is automatically deployed to KieRepository if successfully built.
        if (kb.getResults().hasMessages(Level.ERROR)) {
            throw new RuntimeException("Build Errors:\n" + kb.getResults().toString());
        }

        KieContainer kContainer = ks.newKieContainer(rid);

        KieSession kSession = kContainer.newKieSession("ksession6");
        kSession.setGlobal("out", out);

        Object msg1 = createMessage(kContainer, "Dave", "Hello, HAL. Do you read me, HAL?");
View Full Code Here

public class IncrementalCompilationTest {

    @Test
    public void testDuplicateXLSResources() throws Exception {

        KieServices ks = KieServices.Factory.get();

        KieFileSystem kfs = ks.newKieFileSystem();

        InputStream in1 = null;
        InputStream in2 = null;

        try {

            //Add XLS decision table
            in1 = this.getClass().getResourceAsStream( "incrementalBuild.dtable.xls" );
            kfs.write( "src/main/resources/incrementalBuild1.dtable.xls",
                       KieServices.Factory.get().getResources().newInputStreamResource( in1 ) );

            //Add the same XLS decision table again as a different resource
            in2 = this.getClass().getResourceAsStream( "incrementalBuild.dtable.xls" );
            kfs.write( "src/main/resources/incrementalBuild2.dtable.xls",
                       KieServices.Factory.get().getResources().newInputStreamResource( in2 ) );

            //Check errors on a full build
            assertEquals( 2, ks.newKieBuilder( kfs ).buildAll().getResults().getMessages().size() );

        } finally {
            if ( in1 != null ) {
                in1.close();
            }
View Full Code Here

TOP

Related Classes of org.kie.api.KieServices

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.