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