Search in sources :

Example 1 with KieModuleModelImpl

use of org.drools.compiler.kproject.models.KieModuleModelImpl in project drools by kiegroup.

the class AbstractKnowledgeTest method createKieModule.

public KieModuleModel createKieModule(String namespace, boolean createJar, String version) throws IOException, ClassNotFoundException, InterruptedException {
    KieModuleModel kproj = new KieModuleModelImpl();
    KieBaseModel kieBaseModel1 = kproj.newKieBaseModel(namespace + ".KBase1").setEqualsBehavior(EqualityBehaviorOption.EQUALITY).setEventProcessingMode(EventProcessingOption.STREAM).addPackage(namespace + ".KBase1").setDefault(true);
    kieBaseModel1.newKieSessionModel(namespace + ".KSession1").setType(KieSessionType.STATELESS).setClockType(ClockTypeOption.get("realtime")).setDefault(true);
    kieBaseModel1.newKieSessionModel(namespace + ".KSession2").setType(KieSessionType.STATEFUL).setClockType(ClockTypeOption.get("pseudo"));
    kieBaseModel1.newKieSessionModel(namespace + ".KSessionDefault").setType(KieSessionType.STATEFUL).setClockType(ClockTypeOption.get("pseudo")).setDefault(true);
    KieBaseModel kieBaseModel2 = kproj.newKieBaseModel(namespace + ".KBase2").setEqualsBehavior(EqualityBehaviorOption.IDENTITY).addPackage(namespace + ".KBase2").setEventProcessingMode(EventProcessingOption.CLOUD);
    kieBaseModel2.newKieSessionModel(namespace + ".KSession3").setType(KieSessionType.STATEFUL).setClockType(ClockTypeOption.get("pseudo"));
    KieBaseModel kieBaseModel3 = kproj.newKieBaseModel(namespace + ".KBase3").addInclude(kieBaseModel1.getName()).addInclude(kieBaseModel2.getName()).setEqualsBehavior(EqualityBehaviorOption.IDENTITY).setEventProcessingMode(EventProcessingOption.CLOUD);
    kieBaseModel3.newKieSessionModel(namespace + ".KSession4").setType(KieSessionType.STATELESS).setClockType(ClockTypeOption.get("pseudo"));
    KieServices ks = KieServices.Factory.get();
    KieFileSystemImpl kfs = (KieFileSystemImpl) ks.newKieFileSystem();
    kfs.write("src/main/resources/META-INF/beans.xml", generateBeansXML());
    kfs.writeKModuleXML(((KieModuleModelImpl) kproj).toXML());
    ReleaseId releaseId = ks.newReleaseId(namespace, "art1", version);
    kfs.generateAndWritePomXML(releaseId);
    String kBase1R1 = getRule(namespace + ".test1", "rule1", version);
    String kBase1R2 = getRule(namespace + ".test1", "rule2", version);
    String kbase2R1 = getRule(namespace + ".test2", "rule1", version);
    String kbase2R2 = getRule(namespace + ".test2", "rule2", version);
    String fldKB1 = "src/main/resources/" + kieBaseModel1.getName().replace('.', '/');
    String fldKB2 = "src/main/resources/" + kieBaseModel2.getName().replace('.', '/');
    kfs.write(fldKB1 + "/rule1.drl", kBase1R1.getBytes());
    kfs.write(fldKB1 + "/rule2.drl", kBase1R2.getBytes());
    kfs.write(fldKB2 + "/rule1.drl", kbase2R1.getBytes());
    kfs.write(fldKB2 + "/rule2.drl", kbase2R2.getBytes());
    kfs.write("src/main/java/org/drools/compiler/cdi/test/KProjectTestClass" + namespace + ".java", generateKProjectTestClass(kproj, namespace));
    KieBuilder kBuilder = ks.newKieBuilder(kfs);
    kBuilder.buildAll();
    if (kBuilder.getResults().hasMessages(Level.ERROR)) {
        fail("should not have errors" + kBuilder.getResults());
    }
    MemoryKieModule kieModule = (MemoryKieModule) kBuilder.getKieModule();
    MemoryFileSystem trgMfs = kieModule.getMemoryFileSystem();
    if (createJar) {
        trgMfs.writeAsJar(fileManager.getRootDirectory(), namespace + "-" + version);
    } else {
        java.io.File file = fileManager.newFile(namespace + "-" + version);
        trgMfs.writeAsFs(file);
    }
    return kproj;
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) KieFileSystemImpl(org.drools.compiler.kie.builder.impl.KieFileSystemImpl) KieModuleModel(org.kie.api.builder.model.KieModuleModel) MemoryKieModule(org.drools.compiler.kie.builder.impl.MemoryKieModule) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieBuilder(org.kie.api.builder.KieBuilder) KieModuleModelImpl(org.drools.compiler.kproject.models.KieModuleModelImpl)

Aggregations

MemoryFileSystem (org.drools.compiler.compiler.io.memory.MemoryFileSystem)1 KieFileSystemImpl (org.drools.compiler.kie.builder.impl.KieFileSystemImpl)1 MemoryKieModule (org.drools.compiler.kie.builder.impl.MemoryKieModule)1 KieModuleModelImpl (org.drools.compiler.kproject.models.KieModuleModelImpl)1 KieServices (org.kie.api.KieServices)1 KieBuilder (org.kie.api.builder.KieBuilder)1 ReleaseId (org.kie.api.builder.ReleaseId)1 KieBaseModel (org.kie.api.builder.model.KieBaseModel)1 KieModuleModel (org.kie.api.builder.model.KieModuleModel)1