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;
}
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;
}
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();
}
}
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());
}
}
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);
}
Aggregations