use of org.kie.server.api.model.taskassigning.TaskData in project droolsjbpm-integration by kiegroup.
the class TaskAssigningRuntimeServiceQueryHelperTest method readTaskDataSummary.
@Test
public void readTaskDataSummary() {
List<TaskData> invocation0 = mockTasks();
List<TaskData> invocation1 = Arrays.asList(mockTaskData(4L), mockTaskData(5L));
List<TaskData> invocation2 = Collections.singletonList(mockTaskData(6L));
doAnswer(new Answer() {
private int invocations = 0;
public Object answer(InvocationOnMock invocation) {
switch(invocations++) {
case 0:
return invocation0;
case 1:
return invocation1;
case 2:
return invocation2;
default:
return Collections.emptyList();
}
}
}).when(helper).executeQuery(eq(queryService), anyString(), any(TaskAssigningTaskDataWithPotentialOwnersQueryMapper.class), any(), any());
List<TaskData> result = helper.readTasksDataSummary(0, Collections.emptyList(), 10);
assertEquals(TASK1_ID, result.get(0).getTaskId(), 0);
assertEquals(TASK2_ID, result.get(1).getTaskId(), 0);
assertEquals(TASK3_ID, result.get(2).getTaskId(), 0);
assertEquals(4L, result.get(3).getTaskId(), 0);
assertEquals(5L, result.get(4).getTaskId(), 0);
assertEquals(6L, result.get(5).getTaskId(), 0);
}
use of org.kie.server.api.model.taskassigning.TaskData in project droolsjbpm-integration by kiegroup.
the class TaskAssigningRuntimeServiceQueryHelperTest method prepareQuery.
private Map<String, Object> prepareQuery(TaskInputVariablesReadMode readMode) {
Map<String, Object> params = mockQueryParams(readMode);
List<TaskData> taskDataList = mockTasks();
doReturn(taskDataList).when(helper).executeQuery(eq(queryService), anyString(), any(TaskAssigningTaskDataWithPotentialOwnersQueryMapper.class), any(), any());
KieContainerInstanceImpl container = mock(KieContainerInstanceImpl.class);
when(container.getStatus()).thenReturn(KieContainerStatus.STARTED);
when(registry.getContainer(CONTAINER_ID)).thenReturn(container);
return params;
}
use of org.kie.server.api.model.taskassigning.TaskData in project droolsjbpm-integration by kiegroup.
the class TaskAssigningRuntimeServiceQueryHelperTest method mockTaskData.
private TaskData mockTaskData(Long taskId, Status status, boolean hasPlanningTask, String containerId) {
TaskData taskData = TaskData.builder().taskId(taskId).status(status.name()).containerId(containerId).build();
if (hasPlanningTask) {
PlanningTask planningTask = PlanningTask.builder().taskId(taskId).build();
taskData.setPlanningTask(planningTask);
}
return taskData;
}
use of org.kie.server.api.model.taskassigning.TaskData in project droolsjbpm-integration by kiegroup.
the class TaskUtilTest method fromTaskData.
private void fromTaskData(Map<String, Object> inputData, Set<Object> expectedSkills, Set<Object> expectedAffinities) {
Set<OrganizationalEntity> potentialOwners = new HashSet<>();
potentialOwners.add(OE_1);
potentialOwners.add(OE_2);
TaskData taskData = TaskData.builder().taskId(TASK_ID).processInstanceId(PROCESS_INSTANCE_ID).processId(PROCESS_ID).containerId(CONTAINER_ID).name(NAME).priority(PRIORITY).status(STATUS).inputData(inputData).potentialOwners(potentialOwners).build();
Task task = TaskUtil.fromTaskData(taskData);
assertEquals(TASK_ID, task.getId(), 0);
assertEquals(PROCESS_INSTANCE_ID, task.getProcessInstanceId(), 0);
assertEquals(PROCESS_ID, task.getProcessId());
assertEquals(CONTAINER_ID, task.getContainerId());
assertEquals(NAME, task.getName());
assertEquals(PRIORITY, task.getPriority(), 0);
assertEquals(STATUS, task.getStatus());
assertEquals(inputData, task.getInputData());
assertEquals(potentialOwners.size(), task.getPotentialOwners().size(), 2);
User user = task.getPotentialOwners().stream().filter(u -> OE_1.getName().equals(u.getEntityId()) && u.isUser()).map(u -> (User) u).findFirst().orElse(null);
assertNotNull(user);
Group group = task.getPotentialOwners().stream().filter(g -> OE_2.getName().equals(g.getEntityId()) && !g.isUser()).map(g -> (Group) g).findFirst().orElse(null);
assertNotNull(group);
assertEquals(expectedSkills, task.getLabelValues(SKILLS.name()));
assertEquals(expectedAffinities, task.getLabelValues(AFFINITIES.name()));
}
use of org.kie.server.api.model.taskassigning.TaskData 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);
}
}
Aggregations