Package org.kie.api.builder

Examples of org.kie.api.builder.KieRepository


    private static boolean buildKieProject(InternalKieModule kModule, ResultsImpl messages, KieModuleKieProject kProject) {
        kProject.init();
        kProject.verify(messages);

        if ( messages.filterMessages( Level.ERROR ).isEmpty() ) {
            KieRepository kieRepository = KieServices.Factory.get().getRepository();
            kieRepository.addKieModule(kModule);
            for (InternalKieModule kDep : kModule.getKieDependencies().values()) {
                kieRepository.addKieModule(kDep);
            }
            return true;
        }
        return false;
    }
View Full Code Here


        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

        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

public class DefaultKieSessionFromFileExample {

    public void go(PrintStream out) {
        KieServices ks = KieServices.Factory.get();
        KieRepository kr = ks.getRepository();

        KieModule kModule = kr.addKieModule(ks.getResources().newFileSystemResource(getFile("default-kiesession")));

        KieContainer kContainer = ks.newKieContainer(kModule.getReleaseId());

        KieSession kSession = kContainer.newKieSession();
        kSession.setGlobal("out", out);
View Full Code Here

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

        setKbase( kieBase );
        return kieBase.newKieSession();
View Full Code Here

        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

    private static boolean buildKieProject(InternalKieModule kModule, ResultsImpl messages, KieModuleKieProject kProject) {
        kProject.init();
        kProject.verify(messages);

        if ( messages.filterMessages( Level.ERROR ).isEmpty() ) {
            KieRepository kieRepository = KieServices.Factory.get().getRepository();
            kieRepository.addKieModule(kModule);
            for (InternalKieModule kDep : kModule.getKieDependencies().values()) {
                kieRepository.addKieModule(kDep);
            }
            return true;
        }
        return false;
    }
View Full Code Here

        }

        KieServices ks = KieServices.Factory.get();

        try {
            KieRepository kr = ks.getRepository();
            InternalKieModule kModule = (InternalKieModule)kr.addKieModule(ks.getResources().newFileSystemResource(sourceFolder));
            for (InternalKieModule kmoduleDep : kmoduleDeps) {
                kModule.addKieDependency(kmoduleDep);
            }

            KieContainerImpl kContainer = (KieContainerImpl) ks.newKieContainer(kModule.getReleaseId());
View Full Code Here

public class KieModuleFromMultipleFilesExample {

    public void go(PrintStream out) {
        KieServices ks = KieServices.Factory.get();
        KieRepository kr = ks.getRepository();

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

        KieModule kModule = kr.addKieModule(ex1Res, ex2Res);
        KieContainer kContainer = ks.newKieContainer(kModule.getReleaseId());

        KieSession kSession = kContainer.newKieSession("ksession2");
        kSession.setGlobal("out", out);
View Full Code Here

        KieBuilder kb1 = createKieBuilder(kfs1);
        kb1.buildAll();       
        if ( kb1.getResults().hasMessages(Level.ERROR) ) {
            fail("Unable to build KieJar\n" + kb1.getResults( ).toString() );
        }
        KieRepository kr = ks.getRepository();
        KieModule kModule1 = kr.getKieModule(releaseId1);
        assertNotNull( kModule1 );
       
       
        String namespace2 = "org.kie.test2";
        ReleaseId releaseId2 = KieServices.Factory.get().newReleaseId(namespace2, "memory", "1.0-SNAPSHOT");
        KieModuleModel kProj2 = createKieProject(namespace2);       
        KieBaseModelImpl kieBase2 = ( KieBaseModelImpl ) kProj2.getKieBaseModels().get( namespace2 );
        kieBase2.addInclude( namespace1 );
       
        KieFileSystem kfs2 = KieServices.Factory.get().newKieFileSystem();
        generateAll(kfs2, namespace2, releaseId2, kProj2);
       

        KieBuilder kb2 = createKieBuilder(kfs2);
        kb2.setDependencies( kModule1 );
        kb2.buildAll();       
        if ( kb2.getResults().hasMessages(Level.ERROR) ) {
            fail("Unable to build KieJar\n" + kb2.getResults( ).toString() );
        }
        KieModule kModule2= kr.getKieModule(releaseId2);
        assertNotNull( kModule2);
       
        KieContainer kContainer = ks.newKieContainer(releaseId2);
        KieBase kBase = kContainer.getKieBase( namespace2 );
       
View Full Code Here

TOP

Related Classes of org.kie.api.builder.KieRepository

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.