Search in sources :

Example 1 with ObjectFilter

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

the class IntermediateEventTest method testIntermediateCatchEventConditionSetVariableAfter.

@Test
public void testIntermediateCatchEventConditionSetVariableAfter() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchEventConditionSetVariableAfter.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)

Example 2 with ObjectFilter

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

the class ProcessActionTest method testActionContextJava.

@Test
public void testActionContextJava() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    Reader source = new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + "         xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + "         xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + "         type=\"RuleFlow\" name=\"flow\" id=\"org.drools.actions\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + "  <header>\n" + "    <imports>\n" + "      <import name=\"org.jbpm.integrationtests.test.Message\" />\n" + "    </imports>\n" + "    <globals>\n" + "      <global identifier=\"list\" type=\"java.util.List\" />\n" + "    </globals>\n" + "    <variables>\n" + "      <variable name=\"variable\" >\n" + "        <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "        <value>SomeText</value>\n" + "      </variable>\n" + "    </variables>\n" + "  </header>\n" + "\n" + "  <nodes>\n" + "    <start id=\"1\" name=\"Start\" />\n" + "    <actionNode id=\"2\" name=\"MyActionNode\" >\n" + "      <action type=\"expression\" dialect=\"java\" >System.out.println(\"Triggered\");\n" + "String myVariable = (String) kcontext.getVariable(\"variable\");\n" + "list.add(myVariable);\n" + "String nodeName = kcontext.getNodeInstance().getNodeName();\n" + "list.add(nodeName);\n" + "insert( new Message() );\n" + "</action>\n" + "    </actionNode>\n" + "    <end id=\"3\" name=\"End\" />\n" + "  </nodes>\n" + "\n" + "  <connections>\n" + "    <connection from=\"1\" to=\"2\" />\n" + "    <connection from=\"2\" to=\"3\" />\n" + "  </connections>\n" + "\n" + "</process>");
    kbuilder.add(new ReaderResource(source), ResourceType.DRF);
    KieBase kbase = kbuilder.newKieBase();
    KieSession ksession = kbase.newKieSession();
    List<String> list = new ArrayList<String>();
    ksession.setGlobal("list", list);
    ProcessInstance processInstance = ksession.startProcess("org.drools.actions");
    assertEquals(2, list.size());
    assertEquals("SomeText", list.get(0));
    assertEquals("MyActionNode", list.get(1));
    Collection<FactHandle> factHandles = ksession.getFactHandles(new ObjectFilter() {

        public boolean accept(Object object) {
            return object instanceof Message;
        }
    });
    assertFalse(factHandles.isEmpty());
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : Message(org.jbpm.integrationtests.test.Message) FactHandle(org.kie.api.runtime.rule.FactHandle) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) ReaderResource(org.drools.core.io.impl.ReaderResource) ObjectFilter(org.kie.api.runtime.ObjectFilter) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) KieBase(org.kie.api.KieBase) StringReader(java.io.StringReader) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 3 with ObjectFilter

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

the class ProcessActionTest method testActionContextMVEL.

@Test
public void testActionContextMVEL() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    Reader source = new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + "         xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + "         xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + "         type=\"RuleFlow\" name=\"flow\" id=\"org.drools.actions\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + "  <header>\n" + "    <imports>\n" + "      <import name=\"org.jbpm.integrationtests.test.Message\" />\n" + "    </imports>\n" + "    <globals>\n" + "      <global identifier=\"list\" type=\"java.util.List\" />\n" + "    </globals>\n" + "    <variables>\n" + "      <variable name=\"variable\" >\n" + "        <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "        <value>SomeText</value>\n" + "      </variable>\n" + "    </variables>\n" + "  </header>\n" + "\n" + "  <nodes>\n" + "    <start id=\"1\" name=\"Start\" />\n" + "    <actionNode id=\"2\" name=\"MyActionNode\" >\n" + "      <action type=\"expression\" dialect=\"mvel\" >System.out.println(\"Triggered\");\n" + "System.out.println(kcontext.getKnowledgeRuntime());\n" + "String myVariable = (String) kcontext.getVariable(\"variable\");\n" + "list.add(myVariable);\n" + "String nodeName = kcontext.getNodeInstance().getNodeName();\n" + "list.add(nodeName);\n" + "insert( new Message() );\n" + "</action>\n" + "    </actionNode>\n" + "    <end id=\"3\" name=\"End\" />\n" + "  </nodes>\n" + "\n" + "  <connections>\n" + "    <connection from=\"1\" to=\"2\" />\n" + "    <connection from=\"2\" to=\"3\" />\n" + "  </connections>\n" + "\n" + "</process>");
    kbuilder.add(new ReaderResource(source), ResourceType.DRF);
    if (kbuilder.hasErrors()) {
        fail(kbuilder.getErrors().toString());
    }
    KieBase kbase = kbuilder.newKieBase();
    KieSession ksession = kbase.newKieSession();
    List<String> list = new ArrayList<String>();
    ksession.setGlobal("list", list);
    ProcessInstance processInstance = ksession.startProcess("org.drools.actions");
    assertEquals(2, list.size());
    assertEquals("SomeText", list.get(0));
    assertEquals("MyActionNode", list.get(1));
    Collection<FactHandle> factHandles = ksession.getFactHandles(new ObjectFilter() {

        public boolean accept(Object object) {
            return object instanceof Message;
        }
    });
    assertFalse(factHandles.isEmpty());
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : Message(org.jbpm.integrationtests.test.Message) FactHandle(org.kie.api.runtime.rule.FactHandle) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) ReaderResource(org.drools.core.io.impl.ReaderResource) ObjectFilter(org.kie.api.runtime.ObjectFilter) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) KieBase(org.kie.api.KieBase) StringReader(java.io.StringReader) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 4 with ObjectFilter

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

the class DecisionTreeTest method getToken.

protected Object getToken(KieSession kSession, String treeModelName) {
    String className = AbstractModel.PMML_JAVA_PACKAGE_NAME + "." + treeModelName + "TreeToken";
    Collection objects = kSession.getObjects(new ObjectFilter() {

        @Override
        public boolean accept(Object object) {
            return object.getClass().getName().equals(className);
        }
    });
    assertNotNull(objects);
    assertEquals(1, objects.size());
    Iterator iter = objects.iterator();
    assert (iter.hasNext());
    return iter.next();
}
Also used : Iterator(java.util.Iterator) Collection(java.util.Collection) ObjectFilter(org.kie.api.runtime.ObjectFilter)

Example 5 with ObjectFilter

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

the class ProcessActionTest method testActionContextJavaBackwardCheck.

@Test
public void testActionContextJavaBackwardCheck() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    Reader source = new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + "         xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + "         xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + "         type=\"RuleFlow\" name=\"flow\" id=\"org.drools.actions\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + "  <header>\n" + "    <imports>\n" + "      <import name=\"org.jbpm.integrationtests.test.Message\" />\n" + "    </imports>\n" + "    <globals>\n" + "      <global identifier=\"list\" type=\"java.util.List\" />\n" + "    </globals>\n" + "    <variables>\n" + "      <variable name=\"variable\" >\n" + "        <type name=\"org.drools.core.process.core.datatype.impl.type.StringDataType\" />\n" + "        <value>SomeText</value>\n" + "      </variable>\n" + "    </variables>\n" + "  </header>\n" + "\n" + "  <nodes>\n" + "    <start id=\"1\" name=\"Start\" />\n" + "    <actionNode id=\"2\" name=\"MyActionNode\" >\n" + "      <action type=\"expression\" dialect=\"java\" >System.out.println(\"Triggered\");\n" + "String myVariable = (String) kcontext.getVariable(\"variable\");\n" + "list.add(myVariable);\n" + "String nodeName = kcontext.getNodeInstance().getNodeName();\n" + "list.add(nodeName);\n" + "insert( new Message() );\n" + "</action>\n" + "    </actionNode>\n" + "    <end id=\"3\" name=\"End\" />\n" + "  </nodes>\n" + "\n" + "  <connections>\n" + "    <connection from=\"1\" to=\"2\" />\n" + "    <connection from=\"2\" to=\"3\" />\n" + "  </connections>\n" + "\n" + "</process>");
    kbuilder.add(new ReaderResource(source), ResourceType.DRF);
    KieBase kbase = kbuilder.newKieBase();
    KieSession ksession = kbase.newKieSession();
    List<String> list = new ArrayList<String>();
    ksession.setGlobal("list", list);
    ProcessInstance processInstance = ksession.startProcess("org.drools.actions");
    assertEquals(2, list.size());
    assertEquals("SomeText", list.get(0));
    assertEquals("MyActionNode", list.get(1));
    Collection<FactHandle> factHandles = ksession.getFactHandles(new ObjectFilter() {

        public boolean accept(Object object) {
            return object instanceof Message;
        }
    });
    assertFalse(factHandles.isEmpty());
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : Message(org.jbpm.integrationtests.test.Message) FactHandle(org.kie.api.runtime.rule.FactHandle) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) ReaderResource(org.drools.core.io.impl.ReaderResource) ObjectFilter(org.kie.api.runtime.ObjectFilter) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) KieBase(org.kie.api.KieBase) StringReader(java.io.StringReader) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

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