Search in sources :

Example 1 with TaskInstance

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

the class UserTaskServicesClientImpl method getTaskInstance.

@Override
public TaskInstance getTaskInstance(String containerId, Long taskId, boolean withInputs, boolean withOutputs, boolean withAssignments) {
    TaskInstance result = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(TASK_INSTANCE_ID, taskId);
        StringBuilder queryString = new StringBuilder();
        queryString.append("?withInputData").append("=").append(withInputs).append("&withOutputData").append("=").append(withOutputs).append("&withAssignments").append("=").append(withAssignments);
        result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), TASK_URI + "/" + TASK_INSTANCE_GET_URI, valuesMap) + queryString.toString(), TaskInstance.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("UserTaskService", "getTask", marshaller.getFormat().getType(), new Object[] { containerId, taskId, withInputs, withOutputs, withAssignments })));
        ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM", containerId).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        result = deserialize(response.getResult(), TaskInstance.class);
    }
    return result;
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) TaskInstance(org.kie.server.api.model.instance.TaskInstance) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) CommandScript(org.kie.server.api.commands.CommandScript)

Example 2 with TaskInstance

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

the class UserTaskServicesClientImpl method getTaskInstance.

@Override
public TaskInstance getTaskInstance(String containerId, Long taskId) {
    TaskInstance result = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(TASK_INSTANCE_ID, taskId);
        result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), TASK_URI + "/" + TASK_INSTANCE_GET_URI, valuesMap), TaskInstance.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("UserTaskService", "getTask", marshaller.getFormat().getType(), new Object[] { containerId, taskId, false, false, false })));
        ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM", containerId).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        result = deserialize(response.getResult(), TaskInstance.class);
    }
    return result;
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) TaskInstance(org.kie.server.api.model.instance.TaskInstance) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) CommandScript(org.kie.server.api.commands.CommandScript)

Example 3 with TaskInstance

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

the class UserTaskServicesClientImpl method findTaskById.

@Override
public TaskInstance findTaskById(Long taskId, boolean withSLA) {
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(TASK_INSTANCE_ID, taskId);
        return makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_URI + "/" + TASK_GET_URI + "?withSLA=" + withSLA, valuesMap), TaskInstance.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getTaskById", new Object[] { taskId, withSLA })));
        ServiceResponse<TaskInstance> response = (ServiceResponse<TaskInstance>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        return response.getResult();
    }
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) TaskInstance(org.kie.server.api.model.instance.TaskInstance) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) CommandScript(org.kie.server.api.commands.CommandScript)

Example 4 with TaskInstance

use of org.kie.server.api.model.instance.TaskInstance 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 5 with TaskInstance

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

the class TaskSearchServiceIntegrationTest method testFindTaskInstanceWithSearchService.

private void testFindTaskInstanceWithSearchService(TaskQueryFilterSpec filter, Long taskInstanceId) {
    List<Long> resultsIds = new ArrayList<>();
    List<TaskInstance> results = queryClient.findHumanTasksWithFilters(QUERY_NAME, filter, 0, 100);
    for (TaskInstance res : results) {
        resultsIds.add(res.getId());
        Assertions.assertThat(res.getInputData()).isNullOrEmpty();
        Assertions.assertThat(res.getOutputData()).isNullOrEmpty();
    }
    Assertions.assertThat(results).isNotNull();
    Assertions.assertThat(results).isNotEmpty();
    Assertions.assertThat(resultsIds).contains(taskInstanceId);
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) ArrayList(java.util.ArrayList)

Aggregations

TaskInstance (org.kie.server.api.model.instance.TaskInstance)44 Test (org.junit.Test)29 TaskSummary (org.kie.server.api.model.instance.TaskSummary)27 HashMap (java.util.HashMap)24 OrgEntities (org.kie.server.api.model.admin.OrgEntities)8 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)7 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)6 QueryDefinition (org.kie.server.api.model.definition.QueryDefinition)5 WorkItemInstance (org.kie.server.api.model.instance.WorkItemInstance)5 ArrayList (java.util.ArrayList)4 CommandScript (org.kie.server.api.commands.CommandScript)4 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)4 KieServerCommand (org.kie.server.api.model.KieServerCommand)4 ServiceResponse (org.kie.server.api.model.ServiceResponse)4 Calendar (java.util.Calendar)3 Date (java.util.Date)3 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)3 UserTaskInstanceWithVarsDesc (org.jbpm.services.api.model.UserTaskInstanceWithVarsDesc)3 QueryFilterSpecBuilder (org.kie.server.api.util.QueryFilterSpecBuilder)3 ApiOperation (io.swagger.annotations.ApiOperation)2