use of org.drools.core.process.instance.WorkItemManager in project jbpm by kiegroup.
the class RetrySyncWorkItemByMemoryTest method workItemRecoveryTestByMemory.
@Test
public void workItemRecoveryTestByMemory() {
manager = createRuntimeManager("org/jbpm/test/functional/workitem/retry-workitem-memory.bpmn2");
RuntimeEngine runtimeEngine = getRuntimeEngine(EmptyContext.get());
KieSession kieSession = runtimeEngine.getKieSession();
WorkItemManager workItemManager = (org.drools.core.process.instance.WorkItemManager) kieSession.getWorkItemManager();
workItemManager.registerWorkItemHandler("ExceptionWorkitem", new ExceptionWorkItemHandler());
workItemManager.registerWorkItemHandler("NoExceptionWorkitem", new NoExceptionWorkItemHandler());
ProcessInstance pi = kieSession.startProcess(RETRY_WORKITEM_MEMORY_PROCESS_ID);
org.junit.Assert.assertEquals(pi.getState(), 1);
org.kie.api.runtime.process.WorkflowProcessInstance p = (org.kie.api.runtime.process.WorkflowProcessInstance) kieSession.getProcessInstance(pi.getId());
Collection<NodeInstance> nis = ((org.kie.api.runtime.process.WorkflowProcessInstance) p).getNodeInstances();
retryWorkItem(workItemManager, nis);
org.junit.Assert.assertEquals(p.getState(), 2);
}
use of org.drools.core.process.instance.WorkItemManager in project jbpm by kiegroup.
the class WorkitemAssignmentTest method testWorkitemAssignment.
@Test
public void testWorkitemAssignment() {
manager = createRuntimeManager("org/jbpm/test/functional/workitem/workitemAssignmentTest.bpmn2");
RuntimeEngine runtimeEngine = getRuntimeEngine(EmptyContext.get());
KieSession kieSession = runtimeEngine.getKieSession();
WorkItemManager workItemManager = (org.drools.core.process.instance.WorkItemManager) kieSession.getWorkItemManager();
workItemManager.registerWorkItemHandler("SampleUserWorkitem", new UserAssignmentWorkitemHandler());
Map<String, Object> initEmptyVars = new HashMap<String, Object>();
initEmptyVars.put("firstName", "initValue");
initEmptyVars.put("lastName", "initValue");
ProcessInstance pi = kieSession.startProcess("workitemassignmenttest", initEmptyVars);
// values should be from initial state when process instance started -- "initValue", "initValue"
String varFirstNameOrig = (String) ((WorkflowProcessInstance) pi).getVariable("firstName");
String varLasttNameOrig = (String) ((WorkflowProcessInstance) pi).getVariable("lastName");
assertEquals("initValue", varFirstNameOrig);
assertEquals("initValue", varLasttNameOrig);
// advance process execution past first user task
// it will then go through the custom workitem and
// get into the second user task
TaskService taskService = runtimeEngine.getTaskService();
assertProcessInstanceActive(pi.getId());
assertNodeTriggered(pi.getId(), "myFirstUserTask");
assertNodeActive(pi.getId(), kieSession, "myFirstUserTask");
List<TaskSummary> firstTasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, firstTasks.size());
TaskSummary firstTaskSummary = firstTasks.get(0);
taskService.start(firstTaskSummary.getId(), "john");
taskService.complete(firstTaskSummary.getId(), "john", null);
// get process instance again to get updated process var values which were set
// by the assignments in custom workitem handler
ProcessInstance processInstance = kieSession.getProcessInstance(pi.getId());
String varFirstName = (String) ((WorkflowProcessInstance) processInstance).getVariable("firstName");
String varLasttName = (String) ((WorkflowProcessInstance) processInstance).getVariable("lastName");
assertNotNull(varFirstName);
assertNotNull(varLasttName);
assertEquals(UserAssignmentWorkitemHandler.fnameStr, varFirstName);
assertEquals(UserAssignmentWorkitemHandler.lnameStr, varLasttName);
// make sure we passed the custom workitem
assertNodeTriggered(pi.getId(), "SampleUserWorkitem");
assertNodeActive(pi.getId(), kieSession, "mySecondUserTask");
List<TaskSummary> secondTasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, secondTasks.size());
// advance paste the second user task to complete the process instance
TaskSummary secondTaskSummary = secondTasks.get(0);
taskService.start(secondTaskSummary.getId(), "john");
taskService.complete(secondTaskSummary.getId(), "john", null);
assertProcessInstanceCompleted(processInstance.getId());
// now we can check audit service to see process vars
// and how they chaged throughout process execution
AuditService auditService = runtimeEngine.getAuditService();
List<? extends VariableInstanceLog> firstNameVars = auditService.findVariableInstances(processInstance.getId(), "firstName");
List<? extends VariableInstanceLog> lastNameVars = auditService.findVariableInstances(processInstance.getId(), "lastName");
assertNotNull(firstNameVars);
assertNotNull(lastNameVars);
assertEquals(2, firstNameVars.size());
assertEquals("initValue", firstNameVars.get(0).getValue());
assertEquals(UserAssignmentWorkitemHandler.fnameStr, firstNameVars.get(1).getValue());
assertEquals(2, lastNameVars.size());
assertEquals("initValue", lastNameVars.get(0).getValue());
assertEquals(UserAssignmentWorkitemHandler.lnameStr, lastNameVars.get(1).getValue());
}
use of org.drools.core.process.instance.WorkItemManager in project drools by kiegroup.
the class GetWorkItemCommand method execute.
public WorkItem execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
final WorkItem workItem = ((WorkItemManager) ksession.getWorkItemManager()).getWorkItem(workItemId);
if (this.outIdentifier != null) {
((RegistryContext) context).lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, workItem);
}
return workItem;
}
use of org.drools.core.process.instance.WorkItemManager in project jbpm by kiegroup.
the class ProtobufProcessMarshaller method readWorkItems.
public void readWorkItems(MarshallerReaderContext context) throws IOException {
ProtobufMessages.ProcessData _pdata = (ProtobufMessages.ProcessData) context.parameterObject;
InternalWorkingMemory wm = context.wm;
for (JBPMMessages.WorkItem _workItem : _pdata.getExtension(JBPMMessages.workItem)) {
WorkItem workItem = readWorkItem(context, _workItem);
((WorkItemManager) wm.getWorkItemManager()).internalAddWorkItem((org.drools.core.process.instance.WorkItem) workItem);
}
}
use of org.drools.core.process.instance.WorkItemManager in project jbpm by kiegroup.
the class RetrySyncWorkItemByJPATest method workItemRecoveryTestByJPA.
@Test
public void workItemRecoveryTestByJPA() {
manager = createRuntimeManager("org/jbpm/test/functional/workitem/retry-workitem-jpa.bpmn2");
RuntimeEngine runtimeEngine = getRuntimeEngine(EmptyContext.get());
KieSession kieSession = runtimeEngine.getKieSession();
WorkItemManager workItemManager = (org.drools.core.process.instance.WorkItemManager) kieSession.getWorkItemManager();
workItemManager.registerWorkItemHandler("ExceptionWorkitem", new ExceptionWorkItemHandler());
ProcessInstance pi = kieSession.startProcess(RETRY_WORKITEM_JPA_PROCESS_ID);
TaskService taskService = runtimeEngine.getTaskService();
assertProcessInstanceActive(pi.getId());
assertNodeTriggered(pi.getId(), "lockingNode");
assertNodeActive(pi.getId(), kieSession, "lockingNode");
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, tasks.size());
TaskSummary taskSummary = tasks.get(0);
taskService.start(taskSummary.getId(), "john");
taskService.complete(taskSummary.getId(), "john", null);
ProcessInstance processInstance = (org.kie.api.runtime.process.WorkflowProcessInstance) kieSession.getProcessInstance(pi.getId());
Collection<NodeInstance> nis = ((org.kie.api.runtime.process.WorkflowProcessInstance) processInstance).getNodeInstances();
retryWorkItem(workItemManager, nis);
assertProcessInstanceCompleted(processInstance.getId());
}
Aggregations