use of org.jbpm.workflow.instance.node.WorkItemNodeInstance in project jbpm-work-items by kiegroup.
the class JavaHandlerWorkItemHandler method executeWorkItem.
@SuppressWarnings("unchecked")
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
String className = (String) workItem.getParameter("Class");
try {
Class<JavaHandler> c = (Class<JavaHandler>) Class.forName(className);
JavaHandler handler = c.newInstance();
ProcessContext kcontext = new ProcessContext(ksession);
WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.getProcessInstance(workItem.getProcessInstanceId());
kcontext.setProcessInstance(processInstance);
WorkItemNodeInstance nodeInstance = findNodeInstance(workItem.getId(), processInstance);
kcontext.setNodeInstance(nodeInstance);
Map<String, Object> results = handler.execute(kcontext);
manager.completeWorkItem(workItem.getId(), results);
return;
} catch (ClassNotFoundException cnfe) {
handleException(cnfe);
} catch (InstantiationException ie) {
handleException(ie);
} catch (IllegalAccessException iae) {
handleException(iae);
}
}
use of org.jbpm.workflow.instance.node.WorkItemNodeInstance in project jbpm by kiegroup.
the class AbstractWorkItemHandler method findWorkItemNodeInstance.
private WorkItemNodeInstance findWorkItemNodeInstance(long workItemId, Collection<NodeInstance> nodeInstances) {
for (NodeInstance nodeInstance : nodeInstances) {
if (nodeInstance instanceof WorkItemNodeInstance) {
WorkItemNodeInstance workItemNodeInstance = (WorkItemNodeInstance) nodeInstance;
WorkItem workItem = workItemNodeInstance.getWorkItem();
if (workItem != null && workItemId == workItem.getId()) {
return workItemNodeInstance;
}
}
if (nodeInstance instanceof NodeInstanceContainer) {
WorkItemNodeInstance result = findWorkItemNodeInstance(workItemId, ((NodeInstanceContainer) nodeInstance).getNodeInstances());
if (result != null) {
return result;
}
}
}
return null;
}
use of org.jbpm.workflow.instance.node.WorkItemNodeInstance in project jbpm by kiegroup.
the class ActivityTest method testUserTaskVerifyParameters.
@Test
public void testUserTaskVerifyParameters() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-UserTask.bpmn2");
KieSession ksession = createKnowledgeSession(kbase);
ksession.getEnvironment().set("deploymentId", "test-deployment-id");
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ProcessInstance processInstance = ksession.startProcess("UserTask");
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
ksession = restoreSession(ksession, true);
final WorkItem workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
assertEquals("john", workItem.getParameter("ActorId"));
final long pId = processInstance.getId();
ksession.execute(new ExecutableCommand<Void>() {
@Override
public Void execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
ProcessInstance processInstance = ksession.getProcessInstance(pId);
assertNotNull(processInstance);
NodeInstance nodeInstance = ((WorkflowProcessInstance) processInstance).getNodeInstance(((org.drools.core.process.instance.WorkItem) workItem).getNodeInstanceId());
assertNotNull(nodeInstance);
assertTrue(nodeInstance instanceof WorkItemNodeInstance);
String deploymentId = ((WorkItemNodeInstance) nodeInstance).getWorkItem().getDeploymentId();
long nodeInstanceId = ((WorkItemNodeInstance) nodeInstance).getWorkItem().getNodeInstanceId();
long nodeId = ((WorkItemNodeInstance) nodeInstance).getWorkItem().getNodeId();
assertEquals(((org.drools.core.process.instance.WorkItem) workItem).getDeploymentId(), deploymentId);
assertEquals(((org.drools.core.process.instance.WorkItem) workItem).getNodeId(), nodeId);
assertEquals(((org.drools.core.process.instance.WorkItem) workItem).getNodeInstanceId(), nodeInstanceId);
return null;
}
});
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
ksession.dispose();
}
use of org.jbpm.workflow.instance.node.WorkItemNodeInstance in project jbpm by kiegroup.
the class ProcessInstanceMigrationTest method testProcessInstanceMigrationWithGatewaysAndSameUniqueId.
@Test
public void testProcessInstanceMigrationWithGatewaysAndSameUniqueId() throws Exception {
PersistenceWorkItemHandler handler = new PersistenceWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", 5);
WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.startProcess("com.sample.BPMN2ProcessVersion3", params);
long pid = processInstance.getId();
assertEquals(1, processInstance.getNodeInstances().size());
Map<String, String> mapping = new HashMap<String, String>();
mapping.put("UserTask", "StartTask");
// upgrade to version to of the process
ExplicitUpgradeCommand c = new ExplicitUpgradeCommand(pid, mapping, "com.sample.BPMN2ProcessVersion4");
ksession.execute(c);
assertEquals("com.sample.BPMN2ProcessVersion4", ksession.getProcessInstance(pid).getProcessId());
assertEquals(1, processInstance.getNodeInstances().size());
NodeInstance current = processInstance.getNodeInstances().iterator().next();
handler.completeWorkItem(((WorkItemNodeInstance) current).getWorkItem(), ksession.getWorkItemManager());
handler.completeWorkItem(handler.getWorkItem("FirstPath"), ksession.getWorkItemManager());
handler.completeWorkItem(handler.getWorkItem("SecondPath"), ksession.getWorkItemManager());
List<? extends VariableInstanceLog> vars = engine.getAuditService().findVariableInstances(pid, "x");
assertNotNull(vars);
assertEquals(2, vars.size());
assertEquals("10", vars.get(1).getValue());
assertDefinitionChanged(pid, "com.sample.BPMN2ProcessVersion4", true);
}
use of org.jbpm.workflow.instance.node.WorkItemNodeInstance in project jbpm by kiegroup.
the class RuntimeDataServiceImplTest method testGetAuditTaskByStatus.
@Test
public void testGetAuditTaskByStatus() throws Exception {
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId);
ProcessInstance instance = processService.getProcessInstance(processInstanceId);
assertNotNull(instance);
Collection<NodeInstance> activeNodes = ((WorkflowProcessInstanceImpl) instance).getNodeInstances();
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
NodeInstance node = activeNodes.iterator().next();
assertNotNull(node);
assertTrue(node instanceof WorkItemNodeInstance);
Long workItemId = ((WorkItemNodeInstance) node).getWorkItemId();
assertNotNull(workItemId);
List<String> statuses = new ArrayList();
statuses.add(Status.Reserved.toString());
Map<String, Object> params = new HashMap<String, Object>();
params.put("statuses", statuses);
QueryFilter queryFilter = new QueryFilter();
queryFilter.setParams(params);
List<AuditTask> auditTasks = runtimeDataService.getAllAuditTaskByStatus("salaboy", queryFilter);
assertNotNull(auditTasks);
assertEquals(1, auditTasks.size());
assertEquals("Write a Document", auditTasks.get(0).getName());
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
}
Aggregations