Search in sources :

Example 6 with ReleaseIdImpl

use of org.drools.compiler.kproject.ReleaseIdImpl in project drools by kiegroup.

the class KieModuleDeploymentHelperImpl method createKieJarAndDeployToMaven.

@Override
public void createKieJarAndDeployToMaven(String groupId, String artifactId, String version, String kbaseName, String ksessionName, List<String> resourceFilePaths) {
    ReleaseId releaseId = new ReleaseIdImpl(groupId, artifactId, version);
    internalCreateAndDeployKjarToMaven(releaseId, kbaseName, ksessionName, resourceFilePaths, null, null);
}
Also used : ReleaseIdImpl(org.drools.compiler.kproject.ReleaseIdImpl) ReleaseId(org.kie.api.builder.ReleaseId)

Example 7 with ReleaseIdImpl

use of org.drools.compiler.kproject.ReleaseIdImpl in project drools by kiegroup.

the class AccumulateTest method testImportAccumulateFunctionWithDeclaration.

@Test
public void testImportAccumulateFunctionWithDeclaration() throws Exception {
    // DROOLS-750
    String drl = "package org.foo.bar\n" + "import accumulate " + TestFunction.class.getCanonicalName() + " f;\n" + "import " + Person.class.getCanonicalName() + ";\n" + "declare Person \n" + "  @propertyReactive\n" + "end\n" + "rule X when\n" + "    accumulate( $s : String(),\n" + "                $v : f( $s ) )\n" + "then\n" + "end\n";
    ReleaseId releaseId = new ReleaseIdImpl("foo", "bar", "1.0");
    KieServices ks = KieServices.Factory.get();
    createAndDeployJar(ks, releaseId, drl);
    KieContainer kc = ks.newKieContainer(releaseId);
    KieSession ksession = kc.newKieSession();
    AgendaEventListener ael = mock(AgendaEventListener.class);
    ksession.addEventListener(ael);
    ksession.insert("x");
    ksession.fireAllRules();
    ArgumentCaptor<AfterMatchFiredEvent> ac = ArgumentCaptor.forClass(AfterMatchFiredEvent.class);
    verify(ael).afterMatchFired(ac.capture());
    assertThat((Integer) ac.getValue().getMatch().getDeclarationValue("$v"), is(Integer.valueOf(1)));
}
Also used : ReleaseIdImpl(org.drools.compiler.kproject.ReleaseIdImpl) AgendaEventListener(org.kie.api.event.rule.AgendaEventListener) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) AfterMatchFiredEvent(org.kie.api.event.rule.AfterMatchFiredEvent) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 8 with ReleaseIdImpl

use of org.drools.compiler.kproject.ReleaseIdImpl in project drools by kiegroup.

the class AccumulateTest method testImportAccumulateFunction.

@Test
public void testImportAccumulateFunction() throws Exception {
    String drl = "package org.foo.bar\n" + "import accumulate " + TestFunction.class.getCanonicalName() + " f\n" + "rule X when\n" + "    accumulate( $s : String(),\n" + "                $v : f( $s ) )\n" + "then\n" + "end\n";
    ReleaseId releaseId = new ReleaseIdImpl("foo", "bar", "1.0");
    KieServices ks = KieServices.Factory.get();
    createAndDeployJar(ks, releaseId, drl);
    KieContainer kc = ks.newKieContainer(releaseId);
    KieSession ksession = kc.newKieSession();
    AgendaEventListener ael = mock(AgendaEventListener.class);
    ksession.addEventListener(ael);
    ksession.insert("x");
    ksession.fireAllRules();
    ArgumentCaptor<AfterMatchFiredEvent> ac = ArgumentCaptor.forClass(AfterMatchFiredEvent.class);
    verify(ael).afterMatchFired(ac.capture());
    assertThat((Integer) ac.getValue().getMatch().getDeclarationValue("$v"), is(Integer.valueOf(1)));
}
Also used : ReleaseIdImpl(org.drools.compiler.kproject.ReleaseIdImpl) AgendaEventListener(org.kie.api.event.rule.AgendaEventListener) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) AfterMatchFiredEvent(org.kie.api.event.rule.AfterMatchFiredEvent) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 9 with ReleaseIdImpl

use of org.drools.compiler.kproject.ReleaseIdImpl in project drools by kiegroup.

the class KieBuilderTest method testInvalidPomXmlGAV.

@Test
public void testInvalidPomXmlGAV() throws ClassNotFoundException, InterruptedException, IOException {
    String namespace = "org.kie.test";
    KieModuleModel kProj = createKieProject(namespace);
    ReleaseId releaseId = new ReleaseIdImpl("", "", "");
    KieFileSystem kfs = KieServices.Factory.get().newKieFileSystem();
    generatePomXML(kfs, releaseId);
    generateMessageClass(kfs, namespace);
    generateRule(kfs, namespace);
    MemoryFileSystem mfs = ((KieFileSystemImpl) kfs).asMemoryFileSystem();
    KieBuilder kieBuilder = createKieBuilder(kfs);
    kieBuilder.buildAll();
    assertTrue(kieBuilder.getResults().hasMessages(Level.ERROR));
}
Also used : ReleaseIdImpl(org.drools.compiler.kproject.ReleaseIdImpl) MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) KieFileSystem(org.kie.api.builder.KieFileSystem) KieFileSystemImpl(org.drools.compiler.kie.builder.impl.KieFileSystemImpl) KieModuleModel(org.kie.api.builder.model.KieModuleModel) ReleaseId(org.kie.api.builder.ReleaseId) KieBuilder(org.kie.api.builder.KieBuilder) Test(org.junit.Test)

Example 10 with ReleaseIdImpl

use of org.drools.compiler.kproject.ReleaseIdImpl in project drools by kiegroup.

the class DroolsAbstractPMMLTest method createExecutor.

protected RuleUnitExecutor createExecutor(String sourceName) {
    KieServices ks = KieServices.Factory.get();
    KieRepository kr = ks.getRepository();
    ReleaseId releaseId = new ReleaseIdImpl("org.kie:pmmlTest:1.0-SNAPSHOT");
    ((KieRepositoryImpl) kr).setDefaultGAV(releaseId);
    Resource res = ResourceFactory.newClassPathResource(sourceName);
    kbase = new KieHelper().addResource(res, ResourceType.PMML).build();
    assertNotNull(kbase);
    RuleUnitExecutor executor = RuleUnitExecutor.create().bind(kbase);
    KieContainer kc = ((KnowledgeBaseImpl) ((InternalRuleUnitExecutor) executor).getKieSession().getKieBase()).getKieContainer();
    InternalKieModule ikm = (InternalKieModule) kr.getKieModule(releaseId);
    try (FileOutputStream fos = new FileOutputStream("/tmp/outputModule.jar")) {
        fos.write(ikm.getBytes());
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    kc.getKieBaseNames().forEach(n -> {
        System.out.println(n);
    });
    data = executor.newDataSource("request");
    resultData = executor.newDataSource("results");
    pmmlData = executor.newDataSource("pmmlData");
    return executor;
}
Also used : InternalRuleUnitExecutor(org.drools.core.impl.InternalRuleUnitExecutor) ReleaseIdImpl(org.drools.compiler.kproject.ReleaseIdImpl) KieRepository(org.kie.api.builder.KieRepository) Resource(org.kie.api.io.Resource) FileNotFoundException(java.io.FileNotFoundException) KieHelper(org.kie.internal.utils.KieHelper) KieServices(org.kie.api.KieServices) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) ReleaseId(org.kie.api.builder.ReleaseId) IOException(java.io.IOException) InternalRuleUnitExecutor(org.drools.core.impl.InternalRuleUnitExecutor) RuleUnitExecutor(org.kie.api.runtime.rule.RuleUnitExecutor) KieRepositoryImpl(org.drools.compiler.kie.builder.impl.KieRepositoryImpl) FileOutputStream(java.io.FileOutputStream) KieContainer(org.kie.api.runtime.KieContainer) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Aggregations

ReleaseIdImpl (org.drools.compiler.kproject.ReleaseIdImpl)13 ReleaseId (org.kie.api.builder.ReleaseId)9 Test (org.junit.Test)8 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)3 KieServices (org.kie.api.KieServices)3 KieModule (org.kie.api.builder.KieModule)3 KieContainer (org.kie.api.runtime.KieContainer)3 CyclicBarrier (java.util.concurrent.CyclicBarrier)2 ExecutorService (java.util.concurrent.ExecutorService)2 KieBuilder (org.kie.api.builder.KieBuilder)2 KieFileSystem (org.kie.api.builder.KieFileSystem)2 ComparableVersion (org.kie.api.builder.ReleaseIdComparator.ComparableVersion)2 AfterMatchFiredEvent (org.kie.api.event.rule.AfterMatchFiredEvent)2 AgendaEventListener (org.kie.api.event.rule.AgendaEventListener)2 KieSession (org.kie.api.runtime.KieSession)2 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 DependencyDescriptor (org.appformer.maven.integration.DependencyDescriptor)1