Search in sources :

Example 21 with TaskInstance

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

the class ConvertUtils method convertToTaskInstanceList.

public static TaskInstanceList convertToTaskInstanceList(Collection<UserTaskInstanceDesc> instances) {
    if (instances == null) {
        return new TaskInstanceList(new org.kie.server.api.model.instance.TaskInstance[0]);
    }
    List<TaskInstance> taskInstances = new ArrayList<TaskInstance>(instances.size());
    for (UserTaskInstanceDesc task : instances) {
        org.kie.server.api.model.instance.TaskInstance instance = convertToTask(task);
        taskInstances.add(instance);
    }
    return new TaskInstanceList(taskInstances);
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) ArrayList(java.util.ArrayList) TaskInstance(org.kie.server.api.model.instance.TaskInstance) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) TaskInstanceList(org.kie.server.api.model.instance.TaskInstanceList)

Example 22 with TaskInstance

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

the class UserTaskServiceBase method getTask.

public String getTask(String containerId, Number taskId, boolean withInput, boolean withOutput, boolean withAssignments, String marshallingType) {
    containerId = context.getContainerId(containerId, new ByTaskIdContainerLocator(taskId.longValue()));
    Task task = userTaskService.getTask(containerId, taskId.longValue());
    if (task == null) {
        throw new TaskNotFoundException("No task found with id " + taskId);
    }
    TaskInstance.Builder builder = TaskInstance.builder();
    builder.id(task.getId()).name(task.getName()).subject(task.getSubject()).description(task.getDescription()).priority(task.getPriority()).taskType(task.getTaskType()).formName(((InternalTask) task).getFormName()).status(task.getTaskData().getStatus().name()).actualOwner(getOrgEntityIfNotNull(task.getTaskData().getActualOwner())).createdBy(getOrgEntityIfNotNull(task.getTaskData().getCreatedBy())).createdOn(task.getTaskData().getCreatedOn()).activationTime(task.getTaskData().getActivationTime()).expirationTime(task.getTaskData().getExpirationTime()).skippable(task.getTaskData().isSkipable()).workItemId(task.getTaskData().getWorkItemId()).processInstanceId(task.getTaskData().getProcessInstanceId()).parentId(task.getTaskData().getParentId()).processId(task.getTaskData().getProcessId()).containerId(task.getTaskData().getDeploymentId());
    if (Boolean.TRUE.equals(withInput)) {
        Map<String, Object> variables = userTaskService.getTaskInputContentByTaskId(containerId, taskId.longValue());
        builder.inputData(variables);
    }
    if (Boolean.TRUE.equals(withOutput)) {
        Map<String, Object> variables = userTaskService.getTaskOutputContentByTaskId(containerId, taskId.longValue());
        builder.outputData(variables);
    }
    if (Boolean.TRUE.equals(withAssignments)) {
        builder.potentialOwners(orgEntityAsList(task.getPeopleAssignments().getPotentialOwners()));
        builder.excludedOwners(orgEntityAsList(((InternalPeopleAssignments) task.getPeopleAssignments()).getExcludedOwners()));
        builder.businessAdmins(orgEntityAsList(task.getPeopleAssignments().getBusinessAdministrators()));
    }
    TaskInstance taskInstance = builder.build();
    logger.debug("About to marshal task '{}' representation {}", taskId, taskInstance);
    String response = marshallerHelper.marshal(containerId, marshallingType, taskInstance);
    return response;
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) ByTaskIdContainerLocator(org.kie.server.services.jbpm.locator.ByTaskIdContainerLocator) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException)

Example 23 with TaskInstance

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

the class UserTaskServiceBase method update.

public void update(String containerId, Number taskId, String userId, String payload, String marshallerType) {
    containerId = context.getContainerId(containerId, new ByTaskIdContainerLocator(taskId.longValue()));
    userId = getUser(userId);
    logger.debug("About to unmarshal task instances from payload: '{}'", payload);
    TaskInstance updatedTask = marshallerHelper.unmarshal(containerId, payload, marshallerType, TaskInstance.class);
    logger.debug("About to update task with id '{}' as user '{}' with data {}", taskId, userId, updatedTask);
    UserTaskInstanceDesc task = new UserTaskInstanceDesc(taskId.longValue(), updatedTask.getName(), updatedTask.getDescription(), updatedTask.getPriority(), updatedTask.getExpirationDate(), updatedTask.getFormName());
    userTaskService.updateTask(containerId, taskId.longValue(), userId, task, updatedTask.getInputData(), updatedTask.getOutputData());
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) ByTaskIdContainerLocator(org.kie.server.services.jbpm.locator.ByTaskIdContainerLocator) UserTaskInstanceDesc(org.jbpm.kie.services.impl.model.UserTaskInstanceDesc)

Example 24 with TaskInstance

use of org.kie.server.api.model.instance.TaskInstance in project businessautomation-cop by redhat-cop.

the class KieQueryTest method testGetAllTaskInputInstancesWithVariables.

/**
 * Basic AdvancedQuery Example Finding Tasks with a InputVariable + Value
 */
@Test
public void testGetAllTaskInputInstancesWithVariables() {
    // Source File : src/main/resources/query-definitions.json
    QueryDefinition query = queryServicesClient.getQuery(TestWorkflowConstant.QUERIES.ALL_TASKS_WITH_INPUT_VARS);
    assertNotNull(query);
    assertTrue(StringUtils.isNotBlank(query.getExpression()));
    // start process instance
    Long processInstanceId = processServicesClient.startProcess(containerId, TestWorkflowConstant.PROCESS_ID.SAMPLE_PROCESS_ID, this.getParams());
    assertNotNull(processInstanceId);
    TaskSummary task = this.assertTaskInstance(processInstanceId, 1, TestWorkflowConstant.SAMPLE_PROCESS_DATA.TASK_OWNER, "Test Task");
    // Obtain Task Instances via the Internal Java API
    List<UserTaskInstanceWithVarsDesc> tins = queryService.query(TestWorkflowConstant.QUERIES.ALL_TASKS_WITH_INPUT_VARS, UserTaskInstanceWithVarsQueryMapper.get(), new QueryContext(), QueryParam.in(COLUMN_TASK_STATUS, TestWorkflowConstant.getActiveTaskStatuses()));
    assertNotNull(tins);
    assertEquals(1, tins.size());
    assertEquals(this.getParams().get("myVar"), tins.get(0).getVariables().get("myTaskInputVar"));
    // User FilterSpec builder to filter SQL results
    QueryFilterSpecBuilder builder = new QueryFilterSpecBuilder();
    builder.in(COLUMN_TASK_STATUS, TestWorkflowConstant.getActiveTaskStatuses());
    // Obtain Task Instances via the External Java API QueryServices
    List<TaskInstance> taskInstanceLogs = queryServicesClient.query(TestWorkflowConstant.QUERIES.ALL_TASKS_WITH_INPUT_VARS, QUERY_MAP_TASK_WITH_VARS, builder.get(), 0, 1000, TaskInstance.class);
    assertNotNull(taskInstanceLogs);
    assertEquals(1, taskInstanceLogs.size());
    assertEquals(this.getParams().get("myVar"), taskInstanceLogs.get(0).getInputData().get("myTaskInputVar"));
}
Also used : QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) QueryFilterSpecBuilder(org.kie.server.api.util.QueryFilterSpecBuilder) TaskInstance(org.kie.server.api.model.instance.TaskInstance) TaskSummary(org.kie.server.api.model.instance.TaskSummary) UserTaskInstanceWithVarsDesc(org.jbpm.services.api.model.UserTaskInstanceWithVarsDesc) QueryContext(org.kie.internal.query.QueryContext) Test(org.junit.Test)

Example 25 with TaskInstance

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

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