Search in sources :

Example 1 with WorkItemInstance

use of org.kie.server.api.model.instance.WorkItemInstance in project droolsjbpm-integration by kiegroup.

the class ProcessServiceIntegrationTest method testWorkItemOperationComplete.

@Test
public void testWorkItemOperationComplete() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_EVALUATION, parameters);
    try {
        assertNotNull(processInstanceId);
        assertTrue(processInstanceId.longValue() > 0);
        // Completing human task so we can move in process flow to work item.
        // User task shouldn't be handled as work item because in such case it doesn't behave consistently:
        // i.e. leaving open tasks after finishing process instance.
        List<String> status = Arrays.asList(Status.Ready.toString());
        List<TaskSummary> taskList = taskClient.findTasksByStatusByProcessInstanceId(processInstanceId, status, 0, 10);
        assertEquals(1, taskList.size());
        TaskSummary taskSummary = taskList.get(0);
        taskClient.startTask(CONTAINER_ID, taskSummary.getId(), USER_YODA);
        taskClient.completeTask(CONTAINER_ID, taskSummary.getId(), USER_YODA, null);
        TaskInstance userTask = taskClient.findTaskById(taskSummary.getId());
        assertNotNull(userTask);
        assertEquals("Evaluate items?", userTask.getName());
        assertEquals(Status.Completed.toString(), userTask.getStatus());
        List<WorkItemInstance> workItems = processClient.getWorkItemByProcessInstance(CONTAINER_ID, processInstanceId);
        assertNotNull(workItems);
        assertEquals(1, workItems.size());
        WorkItemInstance workItemInstance = workItems.get(0);
        assertNotNull(workItemInstance);
        processClient.completeWorkItem(CONTAINER_ID, processInstanceId, workItemInstance.getId(), parameters);
        ProcessInstance processInstance = processClient.getProcessInstance(CONTAINER_ID, processInstanceId);
        assertNotNull(processInstance);
        assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED, processInstance.getState().intValue());
    } catch (Exception e) {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        throw e;
    } finally {
        changeUser(TestConfig.getUsername());
    }
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) HashMap(java.util.HashMap) WorkItemInstance(org.kie.server.api.model.instance.WorkItemInstance) KieServicesException(org.kie.server.api.exception.KieServicesException) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) Test(org.junit.Test)

Example 2 with WorkItemInstance

use of org.kie.server.api.model.instance.WorkItemInstance in project droolsjbpm-integration by kiegroup.

the class PerProcessInstanceWorkItemRestOnlyIntegrationTest method testGetWorkItemByProcessInstance.

@Test
public void testGetWorkItemByProcessInstance() throws Exception {
    Long processInstanceId = startProcess(CONTAINER_ID, PROCESS_ID);
    response = callGetWorkItemByProcessInstance(CONTAINER_ID, processInstanceId);
    Assert.assertEquals("Expected HTTP 200 to be returned as one work item should be returned.", Response.Status.OK.getStatusCode(), response.getStatus());
    WorkItemInstanceList result = response.readEntity(WorkItemInstanceList.class);
    Assert.assertEquals(1, result.getItems().size());
    WorkItemInstance workItem = result.getItems().get(0);
    Assert.assertEquals("Email", workItem.getName());
    Assert.assertEquals(processInstanceId, workItem.getProcessInstanceId());
}
Also used : WorkItemInstanceList(org.kie.server.api.model.instance.WorkItemInstanceList) JaxbLong(org.kie.server.api.model.type.JaxbLong) WorkItemInstance(org.kie.server.api.model.instance.WorkItemInstance) Test(org.junit.Test)

Example 3 with WorkItemInstance

use of org.kie.server.api.model.instance.WorkItemInstance in project droolsjbpm-integration by kiegroup.

the class RuntimeDataServiceIntegrationTest method testFindTasks.

@Test
public void testFindTasks() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("stringData", "waiting for signal");
    parameters.put("personData", createPersonInstance(USER_JOHN));
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK, parameters);
    ProcessInstance desc = processClient.getProcessInstance(CONTAINER_ID, processInstanceId);
    try {
        List<TaskSummary> tasks = taskClient.findTasks(USER_YODA, 0, 50);
        assertNotNull(tasks);
        TaskSummary taskSummary = null;
        for (TaskSummary t : tasks) {
            if (t.getProcessInstanceId().equals(processInstanceId)) {
                taskSummary = t;
                break;
            }
        }
        TaskSummary expectedTaskSummary = createDefaultTaskSummary(processInstanceId);
        assertTaskSummary(expectedTaskSummary, taskSummary);
        List<WorkItemInstance> workItems = processClient.getWorkItemByProcessInstance(CONTAINER_ID, processInstanceId);
        assertNotNull(workItems);
        assertEquals(1, workItems.size());
        Long workItemId = workItems.get(0).getId();
        TaskInstance expectedTaskInstance = TaskInstance.builder().name("First task").status(Status.Reserved.toString()).priority(0).actualOwner(USER_YODA).createdBy(USER_YODA).processId(PROCESS_ID_USERTASK).containerId(CONTAINER_ID).processInstanceId(processInstanceId).processType(WorkflowProcess.PROCESS_TYPE).correlationKey(desc.getCorrelationKey()).build();
        TaskInstance taskById = taskClient.findTaskById(taskSummary.getId());
        assertTaskInstance(expectedTaskInstance, taskById);
        assertEquals(workItemId, taskById.getWorkItemId());
        assertNull(taskById.getSlaCompliance());
        taskById = taskClient.findTaskById(taskSummary.getId(), true);
        assertTaskInstance(expectedTaskInstance, taskById);
        assertTrue(taskById.getSlaCompliance() == 0);
        assertEquals(workItemId, taskById.getWorkItemId());
        taskById = taskClient.findTaskByWorkItemId(workItems.get(0).getId());
        assertTaskInstance(expectedTaskInstance, taskById);
    } finally {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
    }
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) WorkItemInstance(org.kie.server.api.model.instance.WorkItemInstance) Test(org.junit.Test)

Example 4 with WorkItemInstance

use of org.kie.server.api.model.instance.WorkItemInstance in project droolsjbpm-integration by kiegroup.

the class ProcessServiceIntegrationTest method testWorkItemOperations.

@Test
public void testWorkItemOperations() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("person", createPersonInstance(USER_JOHN));
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_EVALUATION, parameters);
    try {
        assertNotNull(processInstanceId);
        assertTrue(processInstanceId.longValue() > 0);
        // Completing human task so we can move in process flow to work item.
        // User task shouldn't be handled as work item because in such case it doesn't behave consistently:
        // i.e. leaving open tasks after finishing process instance.
        List<String> status = Arrays.asList(Status.Ready.toString());
        List<TaskSummary> taskList = taskClient.findTasksByStatusByProcessInstanceId(processInstanceId, status, 0, 10);
        assertEquals(1, taskList.size());
        TaskSummary taskSummary = taskList.get(0);
        taskClient.startTask(CONTAINER_ID, taskSummary.getId(), USER_YODA);
        taskClient.completeTask(CONTAINER_ID, taskSummary.getId(), USER_YODA, null);
        TaskInstance userTask = taskClient.findTaskById(taskSummary.getId());
        assertNotNull(userTask);
        assertEquals("Evaluate items?", userTask.getName());
        assertEquals(Status.Completed.toString(), userTask.getStatus());
        List<WorkItemInstance> workItems = processClient.getWorkItemByProcessInstance(CONTAINER_ID, processInstanceId);
        assertNotNull(workItems);
        assertEquals(1, workItems.size());
        WorkItemInstance workItemInstance = workItems.get(0);
        assertNotNull(workItemInstance);
        assertEquals(processInstanceId, workItemInstance.getProcessInstanceId());
        assertEquals("Email", workItemInstance.getName());
        assertEquals(CONTAINER_ID, workItemInstance.getContainerId());
        assertEquals(0, workItemInstance.getState().intValue());
        assertEquals(5, workItemInstance.getParameters().size());
        assertNotNull(workItemInstance.getId());
        assertNotNull(workItemInstance.getNodeId());
        assertNotNull(workItemInstance.getProcessInstanceId());
        workItemInstance = processClient.getWorkItem(CONTAINER_ID, processInstanceId, workItemInstance.getId());
        assertNotNull(workItemInstance);
        assertEquals(processInstanceId, workItemInstance.getProcessInstanceId());
        assertEquals("Email", workItemInstance.getName());
        assertEquals(CONTAINER_ID, workItemInstance.getContainerId());
        assertEquals(0, workItemInstance.getState().intValue());
        assertEquals(5, workItemInstance.getParameters().size());
        assertNotNull(workItemInstance.getId());
        assertNotNull(workItemInstance.getNodeId());
        assertNotNull(workItemInstance.getProcessInstanceId());
        processClient.abortWorkItem(CONTAINER_ID, processInstanceId, workItemInstance.getId());
        ProcessInstance processInstance = processClient.getProcessInstance(CONTAINER_ID, processInstanceId);
        assertNotNull(processInstance);
        assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED, processInstance.getState().intValue());
    } catch (Exception e) {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        throw e;
    } finally {
        changeUser(TestConfig.getUsername());
    }
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) HashMap(java.util.HashMap) WorkItemInstance(org.kie.server.api.model.instance.WorkItemInstance) KieServicesException(org.kie.server.api.exception.KieServicesException) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) Test(org.junit.Test)

Example 5 with WorkItemInstance

use of org.kie.server.api.model.instance.WorkItemInstance in project droolsjbpm-integration by kiegroup.

the class RollingUpdateProcessServiceIntegrationTest method testCompleteWorkItemInNewProcessWithAlias.

@Test
public void testCompleteWorkItemInNewProcessWithAlias() throws Exception {
    Long oldPid = processClient.startProcess(CONTAINER_ALIAS, PROCESS_ID_EVALUATION);
    assertThat(oldPid).isNotNull().isGreaterThan(0);
    createExtraContainer();
    Long pid = processClient.startProcess(CONTAINER_ALIAS, PROCESS_ID_EVALUATION_2);
    assertThat(pid).isNotNull().isGreaterThan(0);
    List<TaskSummary> taskList = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
    assertThat(taskList).hasSize(2);
    // Complete task from the first (old) process
    taskList = taskClient.findTasksByStatusByProcessInstanceId(oldPid, null, 0, 10);
    TaskSummary taskSummary = taskList.get(0);
    taskClient.startTask(CONTAINER_ALIAS, taskSummary.getId(), USER_YODA);
    taskClient.completeTask(CONTAINER_ALIAS, taskSummary.getId(), USER_YODA, null);
    TaskInstance userTask = taskClient.getTaskInstance(CONTAINER_ALIAS, taskSummary.getId());
    assertThat(userTask).isNotNull();
    assertThat(userTask.getContainerId()).isEqualTo(CONTAINER_ID);
    assertThat(userTask.getName()).isEqualTo("Evaluate items?");
    assertThat(userTask.getStatus()).isEqualTo(Status.Completed.toString());
    // Complete tasks from the second (new) process - there are two tasks instead of one
    taskList = taskClient.findTasksByStatusByProcessInstanceId(pid, null, 0, 10);
    assertThat(taskList).hasSize(1);
    // First one - Evaluate items
    taskSummary = taskList.get(0);
    taskClient.startTask(CONTAINER_ALIAS, taskSummary.getId(), USER_YODA);
    taskClient.completeTask(CONTAINER_ALIAS, taskSummary.getId(), USER_YODA, null);
    userTask = taskClient.getTaskInstance(CONTAINER_ALIAS, taskSummary.getId());
    assertThat(userTask).isNotNull();
    assertThat(userTask.getContainerId()).isEqualTo(CONTAINER_ID_101);
    assertThat(userTask.getName()).isEqualTo("Evaluate items?");
    assertThat(userTask.getStatus()).isEqualTo(Status.Completed.toString());
    // Second one - Approve
    taskList = taskClient.findTasksByStatusByProcessInstanceId(pid, null, 0, 10);
    assertThat(taskList).hasSize(1);
    taskSummary = taskList.get(0);
    taskClient.startTask(CONTAINER_ALIAS, taskSummary.getId(), USER_YODA);
    taskClient.completeTask(CONTAINER_ALIAS, taskSummary.getId(), USER_YODA, null);
    userTask = taskClient.getTaskInstance(CONTAINER_ALIAS, taskSummary.getId());
    assertThat(userTask).isNotNull();
    assertThat(userTask.getContainerId()).isEqualTo(CONTAINER_ID_101);
    assertThat(userTask.getName()).isEqualTo("Approve");
    assertThat(userTask.getStatus()).isEqualTo(Status.Completed.toString());
    List<WorkItemInstance> workItems = processClient.getWorkItemByProcessInstance(CONTAINER_ALIAS, pid);
    assertThat(workItems).isNotNull().hasSize(1);
    WorkItemInstance workItemInstance = workItems.get(0);
    assertThat(workItemInstance).isNotNull();
    assertThat(workItemInstance.getContainerId()).isEqualTo(CONTAINER_ID_101);
    assertThat(workItemInstance.getName()).isEqualTo("Email");
    assertThat(workItemInstance.getState()).isEqualTo(WorkItem.PENDING);
    WorkItemInstance workItemInstance2 = processClient.getWorkItem(CONTAINER_ALIAS, pid, workItemInstance.getId());
    assertThat(workItemInstance2.getId()).isEqualTo(workItemInstance.getId());
    processClient.completeWorkItem(CONTAINER_ALIAS, pid, workItemInstance.getId(), null);
    ProcessInstance pi = processClient.getProcessInstance(CONTAINER_ALIAS, pid);
    assertThat(pi).isNotNull();
    assertThat(pi.getState()).isEqualTo(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED);
    pi = processClient.getProcessInstance(CONTAINER_ALIAS, oldPid);
    assertThat(pi).isNotNull();
    assertThat(pi.getState()).isEqualTo(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE);
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) TaskSummary(org.kie.server.api.model.instance.TaskSummary) WorkItemInstance(org.kie.server.api.model.instance.WorkItemInstance) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) Test(org.junit.Test)

Aggregations

WorkItemInstance (org.kie.server.api.model.instance.WorkItemInstance)9 Test (org.junit.Test)7 TaskInstance (org.kie.server.api.model.instance.TaskInstance)5 TaskSummary (org.kie.server.api.model.instance.TaskSummary)5 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)4 HashMap (java.util.HashMap)3 WorkItem (org.kie.api.runtime.process.WorkItem)2 KieServicesException (org.kie.server.api.exception.KieServicesException)2 WorkItemInstanceList (org.kie.server.api.model.instance.WorkItemInstanceList)2 JaxbLong (org.kie.server.api.model.type.JaxbLong)1