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