use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class ProcessActionTest method testOnEntryExit.
@Test
public void testOnEntryExit() {
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" + " <globals>\n" + " <global identifier=\"list\" type=\"java.util.List\" />\n" + " </globals>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <workItem id=\"2\" name=\"HumanTask\" >\n" + " <work name=\"Human Task\" >\n" + " <parameter name=\"ActorId\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>John Doe</value>\n" + " </parameter>\n" + " <parameter name=\"TaskName\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>Do something</value>\n" + " </parameter>\n" + " <parameter name=\"Priority\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " <parameter name=\"Comment\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " </work>\n" + " <onEntry>\n" + " <action type=\"expression\" name=\"Print\" dialect=\"mvel\" >list.add(\"Executing on entry action\");</action>\n" + " </onEntry>\n" + " <onExit>\n" + " <action type=\"expression\" name=\"Print\" dialect=\"java\" >list.add(\"Executing on exit action1\");</action>\n" + " <action type=\"expression\" name=\"Print\" dialect=\"java\" >list.add(\"Executing on exit action2\");</action>\n" + " </onExit>\n" + " </workItem>\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();
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
ProcessInstance processInstance = ksession.startProcess("org.drools.actions");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
WorkItem workItem = handler.getWorkItem();
assertNotNull(workItem);
assertEquals(1, list.size());
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertEquals(3, list.size());
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class ProcessHumanTaskTest method testHumanTask.
@Test
public void testHumanTask() {
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.humantask\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + " <header>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <humanTask id=\"2\" name=\"HumanTask\" >\n" + " <work name=\"Human Task\" >\n" + " <parameter name=\"ActorId\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>John Doe</value>\n" + " </parameter>\n" + " <parameter name=\"TaskName\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>Do something</value>\n" + " </parameter>\n" + " <parameter name=\"Priority\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " <parameter name=\"Comment\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " </work>\n" + " </humanTask>\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>");
builder.addRuleFlow(source);
KieSession workingMemory = createKieSession(builder.getPackages());
TestWorkItemHandler handler = new TestWorkItemHandler();
workingMemory.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ProcessInstance processInstance = (ProcessInstance) workingMemory.startProcess("org.drools.humantask");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
WorkItem workItem = handler.getWorkItem();
assertNotNull(workItem);
workingMemory.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class ProcessMarshallingTest method testMarshallingWithMultipleHumanTasks.
@Test
public void testMarshallingWithMultipleHumanTasks() throws Exception {
String process = "<?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=\"ruleflow\" id=\"com.sample.ruleflow\" package-name=\"com.sample\" >\n" + "\n" + " <header>\n" + " <variables>\n" + " <variable name=\"list\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.ObjectDataType\" className=\"java.util.List\" />\n" + " </variable>\n" + " </variables>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <forEach id=\"4\" name=\"ForEach\" variableName=\"item\" collectionExpression=\"list\" >\n" + " <nodes>\n" + " <humanTask id=\"1\" name=\"Human Task\" >\n" + " <work name=\"Human Task\" >\n" + " <parameter name=\"Comment\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " <parameter name=\"ActorId\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " <parameter name=\"Priority\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " <parameter name=\"TaskName\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>Do something: #{item}</value>\n" + " </parameter>\n" + " </work>\n" + " </humanTask>\n" + " <humanTask id=\"2\" name=\"Human Task Again\" >\n" + " <work name=\"Human Task\" >\n" + " <parameter name=\"Comment\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " <parameter name=\"ActorId\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " <parameter name=\"Priority\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " <parameter name=\"TaskName\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>Do something else: #{item}</value>\n" + " </parameter>\n" + " </work>\n" + " </humanTask>\n" + " </nodes>\n" + " <connections>\n" + " <connection from=\"1\" to=\"2\" />\n" + " </connections>\n" + " <in-ports>\n" + " <in-port type=\"DROOLS_DEFAULT\" nodeId=\"1\" nodeInType=\"DROOLS_DEFAULT\" />\n" + " </in-ports>\n" + " <out-ports>\n" + " <out-port type=\"DROOLS_DEFAULT\" nodeId=\"2\" nodeOutType=\"DROOLS_DEFAULT\" />\n" + " </out-ports>\n" + " </forEach>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <end id=\"3\" name=\"End\" />\n" + " </nodes>\n" + "\n" + " <connections>\n" + " <connection from=\"1\" to=\"4\" />\n" + " <connection from=\"4\" to=\"3\" />\n" + " </connections>\n" + "\n" + "</process>\n";
builder.addProcessFromXml(new StringReader(process));
KieSession session = createKieSession(builder.getPackages());
TestListWorkItemHandler handler = new TestListWorkItemHandler();
session.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
List<String> list = new ArrayList<String>();
list.add("one");
list.add("two");
list.add("three");
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("list", list);
session.startProcess("com.sample.ruleflow", parameters);
assertEquals(1, session.getProcessInstances().size());
assertEquals(3, handler.getWorkItems().size());
// session = getSerialisedStatefulSession( session );
// session.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
List<WorkItem> workItems = new ArrayList<WorkItem>(handler.getWorkItems());
handler.reset();
for (WorkItem workItem : workItems) {
session.getWorkItemManager().completeWorkItem(workItem.getId(), null);
}
assertEquals(1, session.getProcessInstances().size());
assertEquals(3, handler.getWorkItems().size());
session = getSerialisedStatefulKnowledgeSession(session);
for (WorkItem workItem : handler.getWorkItems()) {
session.getWorkItemManager().completeWorkItem(workItem.getId(), null);
}
assertEquals(0, session.getProcessInstances().size());
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class ProcessWorkItemTest method testWorkItem.
@Test
public void testWorkItem() {
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" + " <variables>\n" + " <variable name=\"UserName\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>John Doe</value>\n" + " </variable>\n" + " <variable name=\"Person\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.ObjectDataType\" className=\"org.jbpm.integrationtests.test.Person\" />\n" + " </variable>\n" + " <variable name=\"MyObject\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </variable>\n" + " <variable name=\"Number\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.IntegerDataType\" />\n" + " </variable>\n" + " </variables>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <workItem id=\"2\" name=\"HumanTask\" >\n" + " <work name=\"Human Task\" >\n" + " <parameter name=\"ActorId\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>#{UserName}</value>\n" + " </parameter>\n" + " <parameter name=\"Content\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>#{Person.name}</value>\n" + " </parameter>\n" + " <parameter name=\"TaskName\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>Do something</value>\n" + " </parameter>\n" + " <parameter name=\"Priority\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " <parameter name=\"Comment\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " <parameter name=\"Attachment\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " </work>\n" + " <mapping type=\"in\" from=\"MyObject\" to=\"Attachment\" />" + " <mapping type=\"in\" from=\"Person.name\" to=\"Comment\" />" + " <mapping type=\"out\" from=\"Result\" to=\"MyObject\" />" + " <mapping type=\"out\" from=\"Result.length()\" to=\"Number\" />" + " </workItem>\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(ResourceFactory.newReaderResource(source), ResourceType.DRF);
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
KieSession ksession = kbase.newKieSession();
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("UserName", "John Doe");
Person person = new Person();
person.setName("John Doe");
parameters.put("Person", person);
WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.startProcess("org.drools.actions", parameters);
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
WorkItem workItem = handler.getWorkItem();
assertNotNull(workItem);
assertEquals("John Doe", workItem.getParameter("ActorId"));
assertEquals("John Doe", workItem.getParameter("Content"));
assertEquals("John Doe", workItem.getParameter("Comment"));
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
parameters = new HashMap<String, Object>();
parameters.put("UserName", "Jane Doe");
parameters.put("MyObject", "SomeString");
person = new Person();
person.setName("Jane Doe");
parameters.put("Person", person);
processInstance = (WorkflowProcessInstance) ksession.startProcess("org.drools.actions", parameters);
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
workItem = handler.getWorkItem();
assertNotNull(workItem);
assertEquals("Jane Doe", workItem.getParameter("ActorId"));
assertEquals("SomeString", workItem.getParameter("Attachment"));
assertEquals("Jane Doe", workItem.getParameter("Content"));
assertEquals("Jane Doe", workItem.getParameter("Comment"));
Map<String, Object> results = new HashMap<String, Object>();
results.put("Result", "SomeOtherString");
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), results);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
assertEquals("SomeOtherString", processInstance.getVariable("MyObject"));
assertEquals(15, processInstance.getVariable("Number"));
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class ProcessServiceEJBIntegrationTest method testStartProcessAndGetWorkItems.
@Test
public void testStartProcessAndGetWorkItems() {
assertNotNull(deploymentService);
KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
boolean isDeployed = deploymentService.isDeployed(deploymentUnit.getIdentifier());
assertTrue(isDeployed);
assertNotNull(processService);
long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId);
ProcessInstance pi = processService.getProcessInstance(processInstanceId);
assertNotNull(pi);
Collection<NodeInstanceDesc> activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstanceId, new QueryContext());
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
assertEquals("Write a Document", activeNodes.iterator().next().getName());
List<WorkItem> wis = processService.getWorkItemByProcessInstance(processInstanceId);
assertNotNull(wis);
assertEquals(1, wis.size());
assertEquals("Human Task", wis.get(0).getName());
assertEquals("Write a Document", wis.get(0).getParameter("NodeName"));
processService.abortProcessInstance(processInstanceId);
pi = processService.getProcessInstance(processInstanceId);
assertNull(pi);
}
Aggregations