Search in sources :

Example 6 with WorkItemManager

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);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItemManager(org.drools.core.process.instance.WorkItemManager) NodeInstance(org.kie.api.runtime.process.NodeInstance) Test(org.junit.Test)

Example 7 with WorkItemManager

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());
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkItemManager(org.drools.core.process.instance.WorkItemManager) AuditService(org.kie.api.runtime.manager.audit.AuditService) Test(org.junit.Test)

Example 8 with WorkItemManager

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;
}
Also used : ExecutionResultImpl(org.drools.core.runtime.impl.ExecutionResultImpl) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.kie.internal.command.RegistryContext) WorkItem(org.drools.core.process.instance.WorkItem) WorkItemManager(org.drools.core.process.instance.WorkItemManager)

Example 9 with WorkItemManager

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);
    }
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) ProtobufMessages(org.drools.core.marshalling.impl.ProtobufMessages) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.drools.core.process.instance.WorkItemManager)

Example 10 with WorkItemManager

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());
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) TaskService(org.kie.api.task.TaskService) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItemManager(org.drools.core.process.instance.WorkItemManager) NodeInstance(org.kie.api.runtime.process.NodeInstance) Test(org.junit.Test)

Aggregations

WorkItemManager (org.drools.core.process.instance.WorkItemManager)13 KieSession (org.kie.api.runtime.KieSession)8 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)6 WorkItem (org.drools.core.process.instance.WorkItem)4 Test (org.junit.Test)4 WorkItem (org.kie.api.runtime.process.WorkItem)4 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)3 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)3 WorkItemNotFoundException (org.jbpm.services.api.WorkItemNotFoundException)3 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)3 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)3 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)3 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)3 SessionNotFoundException (org.kie.internal.runtime.manager.SessionNotFoundException)3 HashMap (java.util.HashMap)2 WorkItemHandlerNotFoundException (org.drools.core.WorkItemHandlerNotFoundException)2 ExecutionResultImpl (org.drools.core.runtime.impl.ExecutionResultImpl)2 ProcessInstance (org.jbpm.process.instance.ProcessInstance)2 NodeInstance (org.kie.api.runtime.process.NodeInstance)2 TaskService (org.kie.api.task.TaskService)2