Search in sources :

Example 1 with KnowledgeBase

use of org.drools.KnowledgeBase in project Activiti by Activiti.

the class RulesHelper method findKnowledgeBaseByDeploymentId.

public static KnowledgeBase findKnowledgeBaseByDeploymentId(String deploymentId) {
    DeploymentCache<Object> knowledgeBaseCache = Context.getProcessEngineConfiguration().getDeploymentManager().getKnowledgeBaseCache();
    KnowledgeBase knowledgeBase = (KnowledgeBase) knowledgeBaseCache.get(deploymentId);
    if (knowledgeBase == null) {
        DeploymentEntity deployment = Context.getCommandContext().getDeploymentEntityManager().findDeploymentById(deploymentId);
        if (deployment == null) {
            throw new ActivitiObjectNotFoundException("no deployment with id " + deploymentId, Deployment.class);
        }
        Context.getProcessEngineConfiguration().getDeploymentManager().deploy(deployment);
        knowledgeBase = (KnowledgeBase) knowledgeBaseCache.get(deploymentId);
        if (knowledgeBase == null) {
            throw new ActivitiException("deployment " + deploymentId + " doesn't contain any rules");
        }
    }
    return knowledgeBase;
}
Also used : DeploymentEntity(org.activiti.engine.impl.persistence.entity.DeploymentEntity) ActivitiException(org.activiti.engine.ActivitiException) KnowledgeBase(org.drools.KnowledgeBase) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 2 with KnowledgeBase

use of org.drools.KnowledgeBase in project sling by apache.

the class AbstractUsingBundleListMojo method rewriteBundleList.

private void rewriteBundleList(BundleList bundleList) throws MojoExecutionException {
    if (rewriteRuleFiles != null) {
        KnowledgeBase knowledgeBase = createKnowledgeBase(rewriteRuleFiles);
        StatefulKnowledgeSession session = knowledgeBase.newStatefulKnowledgeSession();
        try {
            session.setGlobal("mavenSession", mavenSession);
            session.setGlobal("mavenProject", project);
            session.insert(bundleList);
            session.fireAllRules();
        } finally {
            session.dispose();
        }
    }
}
Also used : KnowledgeBase(org.drools.KnowledgeBase) StatefulKnowledgeSession(org.drools.runtime.StatefulKnowledgeSession)

Example 3 with KnowledgeBase

use of org.drools.KnowledgeBase in project jBPM5-Developer-Guide by Salaboy.

the class ServiceTaskTest method initializeSession.

private void initializeSession() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(new ClassPathResource("HospitalInvokeInsuranceScenarioV1-data.bpmn"), ResourceType.BPMN2);
    if (kbuilder.hasErrors()) {
        KnowledgeBuilderErrors errors = kbuilder.getErrors();
        for (KnowledgeBuilderError error : errors) {
            System.out.println(">>> Error:" + error.getMessage());
        }
        throw new IllegalStateException(">>> Knowledge couldn't be parsed! ");
    }
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    session = kbase.newStatefulKnowledgeSession();
    KnowledgeRuntimeLoggerFactory.newConsoleLogger(session);
    session.addEventListener(new DefaultAgendaEventListener() {

        @Override
        public void afterRuleFlowGroupActivated(org.drools.event.rule.RuleFlowGroupActivatedEvent event) {
            session.fireAllRules();
        }
    });
}
Also used : KnowledgeBuilderError(org.drools.builder.KnowledgeBuilderError) KnowledgeBuilder(org.drools.builder.KnowledgeBuilder) KnowledgeBase(org.drools.KnowledgeBase) KnowledgeBuilderErrors(org.drools.builder.KnowledgeBuilderErrors) DefaultAgendaEventListener(org.drools.event.rule.DefaultAgendaEventListener) ClassPathResource(org.drools.io.impl.ClassPathResource)

Example 4 with KnowledgeBase

use of org.drools.KnowledgeBase in project jBPM5-Developer-Guide by Salaboy.

the class AsyncWorkItemDontWaitForCompletionTest method initializeSession.

private void initializeSession() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    // We are using a proces containing a single Task. The task is configured
    // to avoid waiting until the completion of the external system.
    kbuilder.add(new ClassPathResource("async-work-item-nowait.bpmn"), ResourceType.BPMN2);
    if (kbuilder.hasErrors()) {
        KnowledgeBuilderErrors errors = kbuilder.getErrors();
        for (KnowledgeBuilderError error : errors) {
            System.out.println(">>> Error:" + error.getMessage());
        }
        throw new IllegalStateException(">>> Knowledge couldn't be parsed! ");
    }
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    session = kbase.newStatefulKnowledgeSession();
    KnowledgeRuntimeLoggerFactory.newConsoleLogger(session);
    session.addEventListener(new DefaultAgendaEventListener() {

        @Override
        public void afterRuleFlowGroupActivated(org.drools.event.rule.RuleFlowGroupActivatedEvent event) {
            session.fireAllRules();
        }
    });
}
Also used : KnowledgeBuilderError(org.drools.builder.KnowledgeBuilderError) KnowledgeBuilder(org.drools.builder.KnowledgeBuilder) KnowledgeBase(org.drools.KnowledgeBase) KnowledgeBuilderErrors(org.drools.builder.KnowledgeBuilderErrors) DefaultAgendaEventListener(org.drools.event.rule.DefaultAgendaEventListener) ClassPathResource(org.drools.io.impl.ClassPathResource)

Example 5 with KnowledgeBase

use of org.drools.KnowledgeBase in project jBPM5-Developer-Guide by Salaboy.

the class MyFirstjBPM5ProcessTest method test.

@Test
public void test() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(new ClassPathResource("firstDummyProcess.bpmn"), ResourceType.BPMN2);
    if (kbuilder.hasErrors()) {
        for (KnowledgeBuilderError error : kbuilder.getErrors()) {
            System.out.println(">>> Error:" + error.getMessage());
        }
        fail(">>> Knowledge couldn't be parsed! ");
    }
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    // Uncomment to see all the logs
    // KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
    // We have our Session, now let's play with our Dummy Process
    ProcessInstance processInstance = ksession.createProcessInstance("DummyProcess", null);
    assertEquals(processInstance.getState(), ProcessInstance.STATE_PENDING);
    ksession.startProcessInstance(processInstance.getId());
    assertEquals(processInstance.getState(), ProcessInstance.STATE_COMPLETED);
}
Also used : KnowledgeBuilderError(org.drools.builder.KnowledgeBuilderError) KnowledgeBuilder(org.drools.builder.KnowledgeBuilder) KnowledgeBase(org.drools.KnowledgeBase) StatefulKnowledgeSession(org.drools.runtime.StatefulKnowledgeSession) ProcessInstance(org.drools.runtime.process.ProcessInstance) ClassPathResource(org.drools.io.impl.ClassPathResource) Test(org.junit.Test)

Aggregations

KnowledgeBase (org.drools.KnowledgeBase)52 KnowledgeBuilder (org.drools.builder.KnowledgeBuilder)48 KnowledgeBuilderError (org.drools.builder.KnowledgeBuilderError)47 ClassPathResource (org.drools.io.impl.ClassPathResource)45 StatefulKnowledgeSession (org.drools.runtime.StatefulKnowledgeSession)28 HashMap (java.util.HashMap)20 ProcessInstance (org.drools.runtime.process.ProcessInstance)20 Person (com.salaboy.model.Person)16 Test (org.junit.Test)13 DefaultProcessEventListener (org.drools.event.process.DefaultProcessEventListener)11 DefaultAgendaEventListener (org.drools.event.rule.DefaultAgendaEventListener)11 KnowledgeBuilderErrors (org.drools.builder.KnowledgeBuilderErrors)9 QueryResults (org.drools.runtime.rule.QueryResults)9 Resources (com.salaboy.model.Resources)6 EntityManagerFactory (javax.persistence.EntityManagerFactory)6 ProcessNodeLeftEvent (org.drools.event.process.ProcessNodeLeftEvent)6 Customer (com.salaboy.model.Customer)5 RatesToday (com.salaboy.model.RatesToday)5 KnowledgeBaseConfiguration (org.drools.KnowledgeBaseConfiguration)5 FactHandle (org.drools.runtime.rule.FactHandle)5