Search in sources :

Example 6 with ObjectFilter

use of org.kie.api.runtime.ObjectFilter in project jbpm by kiegroup.

the class RuleAwareProcessEventLister method getProcessInstanceFactHandle.

protected FactHandle getProcessInstanceFactHandle(final Long processInstanceId, KieRuntime kruntime) {
    if (store.containsKey(processInstanceId)) {
        return store.get(processInstanceId);
    }
    // else try to search for it in the working memory
    Collection<FactHandle> factHandles = kruntime.getFactHandles(new ObjectFilter() {

        public boolean accept(Object object) {
            if (WorkflowProcessInstance.class.isAssignableFrom(object.getClass())) {
                if (((WorkflowProcessInstance) object).getId() == processInstanceId) {
                    return true;
                }
            }
            return false;
        }
    });
    if (factHandles != null && factHandles.size() > 0) {
        FactHandle handle = factHandles.iterator().next();
        // put it into store for faster access
        store.put(processInstanceId, handle);
        return handle;
    }
    return null;
}
Also used : FactHandle(org.kie.api.runtime.rule.FactHandle) ObjectFilter(org.kie.api.runtime.ObjectFilter) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance)

Example 7 with ObjectFilter

use of org.kie.api.runtime.ObjectFilter in project jbpm by kiegroup.

the class IntermediateEventTest method testIntermediateCatchEventConditionRemovePIAfter.

@Test
public void testIntermediateCatchEventConditionRemovePIAfter() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchEventCondition.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(new RuleAwareProcessEventLister());
    ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent");
    assertProcessInstanceActive(processInstance);
    ksession = restoreSession(ksession, true);
    ksession.addEventListener(new RuleAwareProcessEventLister());
    Collection<? extends Object> processInstances = ksession.getObjects(new ObjectFilter() {

        @Override
        public boolean accept(Object object) {
            if (object instanceof ProcessInstance) {
                return true;
            }
            return false;
        }
    });
    assertThat(processInstances).isNotNull();
    assertThat(processInstances.size()).isEqualTo(1);
    // now activate condition
    Person person = new Person();
    person.setName("Jack");
    ksession.insert(person);
    assertProcessInstanceFinished(processInstance, ksession);
    processInstances = ksession.getObjects(new ObjectFilter() {

        @Override
        public boolean accept(Object object) {
            if (object instanceof ProcessInstance) {
                return true;
            }
            return false;
        }
    });
    assertThat(processInstances).isNotNull();
    assertThat(processInstances.size()).isEqualTo(0);
}
Also used : KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) ObjectFilter(org.kie.api.runtime.ObjectFilter) Person(org.jbpm.bpmn2.objects.Person) RuleAwareProcessEventLister(org.jbpm.process.instance.event.listeners.RuleAwareProcessEventLister) Test(org.junit.Test)

Aggregations

ObjectFilter (org.kie.api.runtime.ObjectFilter)7 Test (org.junit.Test)5 KieBase (org.kie.api.KieBase)5 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)5 FactHandle (org.kie.api.runtime.rule.FactHandle)4 Reader (java.io.Reader)3 StringReader (java.io.StringReader)3 ArrayList (java.util.ArrayList)3 ReaderResource (org.drools.core.io.impl.ReaderResource)3 Message (org.jbpm.integrationtests.test.Message)3 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)3 KieSession (org.kie.api.runtime.KieSession)3 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)3 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)3 Person (org.jbpm.bpmn2.objects.Person)2 RuleAwareProcessEventLister (org.jbpm.process.instance.event.listeners.RuleAwareProcessEventLister)2 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1