use of org.kie.server.api.model.taskassigning.TaskDataList in project droolsjbpm-integration by kiegroup.
the class TaskDataReader method readTasks.
/**
* Executes the {@link TaskAssigningRuntimeClient#findTasks(Long, List, LocalDateTime, Integer, Integer, TaskInputVariablesReadMode)}
* method and return all the results. The paging reading is managed internally by this method.
* <p>
* @param fromTaskId filters the tasks with taskId >= fromTaskId. If null no filtering is applied.
* @param status filters the tasks that are in one of the following status. If null or the empty list no filtering
* is applied.
* @param fromLastModificationDate filters the tasks with lastModificationDate >= fromLastModificationDate. If null
* no filtering is applied.
* @param pageSize sets the pageSize for the paged reading.
* @param taskInputVariablesReadMode establishes the tasks input variables reading mode.
* @return a list of TaskData with the jBPM tasks that met the filtering conditions. The potential owners of the task
* is properly loaded with all the elements. The task inputs data is loaded accordingly with the selected taskInputVariablesReadMode.
* @see TaskInputVariablesReadMode
*/
public Result readTasks(long fromTaskId, List<String> status, LocalDateTime fromLastModificationDate, int pageSize, TaskInputVariablesReadMode taskInputVariablesReadMode) {
final List<TaskData> result = new ArrayList<>();
boolean finished = false;
List<TaskData> partialResult;
TaskDataList taskDataList;
TaskData lastItem = null;
LocalDateTime queryTime = null;
long taskId = fromTaskId;
int nextPageSize = pageSize;
while (!finished) {
taskDataList = runtimeClient.findTasks(taskId, status, fromLastModificationDate, 0, nextPageSize, taskInputVariablesReadMode);
partialResult = new ArrayList<>(taskDataList.getItems());
if (queryTime == null) {
queryTime = taskDataList.getQueryTime();
}
if (partialResult.isEmpty()) {
finished = true;
} else {
if (lastItem == null || partialResult.size() > 1) {
lastItem = partialResult.remove(partialResult.size() - 1);
taskId = lastItem.getTaskId();
nextPageSize = pageSize;
result.addAll(partialResult);
} else {
// or it might be the case when some of them fall out of the pageSize.
if (lastItem.getTaskId().equals(partialResult.get(0).getTaskId())) {
if (partialResult.get(0).getPotentialOwners().isEmpty()) {
// no potential owners, check if a taskId+1 exists prior to exit.
result.add(partialResult.get(0));
lastItem = null;
taskId++;
nextPageSize = pageSize;
} else if (partialResult.get(0).getPotentialOwners().size() < nextPageSize) {
// the potential owners fits the page margins, we can exit.
result.add(partialResult.get(0));
finished = true;
} else {
// there might exists more potential owners and in the worst case we loaded only one element
// in last page. increase the page size to ensure we can fetch all.
nextPageSize = nextPageSize * 2;
}
} else {
// last item might have been disappeared from result since last query, retry.
lastItem = partialResult.get(0);
taskId = lastItem.getTaskId();
nextPageSize = pageSize;
}
}
}
}
return new Result(queryTime, result);
}
use of org.kie.server.api.model.taskassigning.TaskDataList in project droolsjbpm-integration by kiegroup.
the class TaskAssigningRuntimeDelegateTest method findTasks.
@Test
public void findTasks() {
List<String> status = Collections.singletonList(convertToString(Status.Ready));
List<Status> internalStatus = Collections.singletonList(Status.Ready);
LocalDateTime lastModificationDate = LocalDateTime.now();
TaskInputVariablesReadMode mode = TaskInputVariablesReadMode.READ_FOR_ALL;
TaskDataList taskDataList = new TaskDataList();
LocalDateTime queryTime = LocalDateTime.now();
taskDataList.setQueryTime(queryTime);
when(runtimeClient.findTasks(eq(0L), eq(status), eq(lastModificationDate), anyInt(), anyInt(), eq(mode))).thenReturn(taskDataList);
TaskAssigningRuntimeDelegate.FindTasksResult result = delegate.findTasks(internalStatus, lastModificationDate, mode);
verify(runtimeClient).findTasks(eq(0L), eq(status), eq(lastModificationDate), anyInt(), anyInt(), eq(mode));
assertTrue(result.getTasks().isEmpty());
assertEquals(queryTime, result.getQueryTime());
}
use of org.kie.server.api.model.taskassigning.TaskDataList in project droolsjbpm-integration by kiegroup.
the class TaskAssigningRuntimeResource method executeTasksQuery.
@ApiOperation(value = "Executes the task assigning integration query for returning the tasks information as a TaskDataList.", notes = "This operation is mainly intended for the tasks assigning integration implementation, third parties are recommended to use the queries described in the task assigning getting started guide.", response = TaskDataList.class)
@POST
@Path(TASK_ASSIGNING_QUERIES_TASK_DATA_URI)
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response executeTasksQuery(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "map with the query parameters", required = true, examples = @Example(value = { @ExampleProperty(mediaType = MediaType.APPLICATION_JSON, value = TASKS_QUERY_PARAMS_MAP_EXAMPLE_JSON), @ExampleProperty(mediaType = MediaType.APPLICATION_XML, value = TASKS_QUERY_PARAMS_MAP_EXAMPLE_XML) })) String payload) {
final Variant v = getVariant(headers);
// no container id available so only used to transfer conversation id if given by client
final Header conversationIdHeader = buildConversationIdHeader("", context, headers);
try {
String contentType = getContentType(headers);
@SuppressWarnings("unchecked") final Map<String, Object> queryParameters = marshallerHelper.unmarshal(payload, contentType, Map.class);
final LocalDateTime queryTime = LocalDateTime.now();
final List<TaskData> taskDataList = runtimeServiceBase.executeFindTasksQuery(queryParameters);
final TaskDataList result = new TaskDataList(taskDataList);
result.setQueryTime(queryTime);
return createCorrectVariant(result, headers, Response.Status.OK, conversationIdHeader);
} catch (Exception e) {
LOGGER.error("Unexpected error finding tasks {}", e.getMessage(), e);
return internalServerError(errorMessage(e), v, conversationIdHeader);
}
}
use of org.kie.server.api.model.taskassigning.TaskDataList in project droolsjbpm-integration by kiegroup.
the class TaskAssigningRuntimeClientImplTest method findTasksRest.
private void findTasksRest(TaskInputVariablesReadMode mode) {
queryParams = TaskAssigningRuntimeClientImpl.TaskQueryParamsBuilder.builder().fromTaskId(FROM_TASK_ID).status(STATUS).fromLastModificationDate(FROM_LAST_MODIFICATION_DATE).page(PAGE).pageSize(PAGE_SIZE).build();
if (mode == null) {
queryParams.put(QueryParamName.TASK_INPUT_VARIABLES_MODE, TaskInputVariablesReadMode.DONT_READ.name());
} else {
queryParams.put(QueryParamName.TASK_INPUT_VARIABLES_MODE, mode.name());
}
when(config.isRest()).thenReturn(true);
String expectedUri = SERVER_URL + "/" + TASK_ASSIGNING_RUNTIME_URI + "/" + TASK_ASSIGNING_QUERIES_TASK_DATA_URI;
doReturn(taskDataList).when(runtimeClient).makeHttpPostRequestAndCreateCustomResponse(eq(expectedUri), eq(queryParams), eq(TaskDataList.class));
TaskDataList result;
if (mode == null) {
result = runtimeClient.findTasks(FROM_TASK_ID, STATUS, FROM_LAST_MODIFICATION_DATE, PAGE, PAGE_SIZE);
} else {
result = runtimeClient.findTasks(FROM_TASK_ID, STATUS, FROM_LAST_MODIFICATION_DATE, PAGE, PAGE_SIZE, mode);
}
assertEquals(taskDataList, result);
}
use of org.kie.server.api.model.taskassigning.TaskDataList in project droolsjbpm-integration by kiegroup.
the class TaskAssigningRuntimeResourceTest method executeFindTasksQuery.
@Test
public void executeFindTasksQuery() {
Marshaller marshaller = MarshallerFactory.getMarshaller(XSTREAM, this.getClass().getClassLoader());
Map<String, Object> params = new HashMap<>();
params.put("param", "value");
String payload = marshaller.marshall(params);
List<TaskData> expectedResult = new ArrayList<>();
expectedResult.add(TaskData.builder().taskId(1L).name("SomeTask").build());
when(runtimeServiceBase.executeFindTasksQuery(eq(params))).thenReturn(expectedResult);
String rawResult = resource.executeTasksQuery(httpHeaders, payload).getEntity().toString();
TaskDataList unMarshalledResult = marshaller.unmarshall(rawResult, TaskDataList.class);
assertEquals(expectedResult, unMarshalledResult.getItems());
}
Aggregations