use of org.kie.server.api.model.taskassigning.TaskData 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());
}
use of org.kie.server.api.model.taskassigning.TaskData in project droolsjbpm-integration by kiegroup.
the class TaskAssigningRuntimeServiceQueryHelper method executeFindTasksQuery.
public List<TaskData> executeFindTasksQuery(Map<String, Object> params) {
List<QueryParam> queryParams = buildQueryParams(params);
Integer page = params.containsKey(PAGE) ? (Integer) params.get(PAGE) : 0;
Integer pageSize = params.containsKey(PAGE_SIZE) ? (Integer) params.get(PAGE_SIZE) : 10;
String loadVariablesMode = (String) params.get(TASK_INPUT_VARIABLES_MODE);
QueryContext queryContext = new QueryContext(page * pageSize, pageSize, AbstractTaskAssigningQueryMapper.TASK_QUERY_COLUMN.TASK_ID.columnName(), true);
AbstractTaskAssigningQueryMapper<TaskData> resultMapper = (AbstractTaskAssigningQueryMapper<TaskData>) QueryMapperRegistry.get().mapperFor(TaskAssigningTaskDataWithPotentialOwnersQueryMapper.NAME, null);
List<TaskData> result = executeQuery(queryService, TASK_ASSIGNING_TASKS_WITH_POTENTIAL_OWNERS_AND_PLANNING_TASK, resultMapper, queryContext, queryParams.toArray(new QueryParam[0]));
Optional<Predicate<TaskData>> loadInputVariables = Optional.empty();
if (TaskInputVariablesReadMode.READ_FOR_ALL.name().equals(loadVariablesMode)) {
loadInputVariables = Optional.of(taskData -> true);
} else if (TaskInputVariablesReadMode.READ_FOR_ACTIVE_TASKS_WITH_NO_PLANNING_ENTITY.name().equals(loadVariablesMode)) {
final Predicate<TaskData> isActive = taskData -> {
if (taskData.getPlanningTask() != null) {
return false;
}
Status taskStatus = StatusConverter.convertFromString(taskData.getStatus());
return taskStatus == Created || taskStatus == Ready || taskStatus == Reserved || taskStatus == InProgress || taskStatus == Suspended;
};
loadInputVariables = Optional.of(isActive);
}
loadInputVariables.ifPresent(taskDataPredicate -> result.stream().filter(taskDataPredicate).forEach(taskData -> taskData.setInputData(readTaskVariables(taskData))));
return result;
}
use of org.kie.server.api.model.taskassigning.TaskData in project droolsjbpm-integration by kiegroup.
the class TaskAssigningRuntimeServiceQueryHelper method readTaskVariables.
private Map<String, Object> readTaskVariables(TaskData taskData) {
KieContainerInstanceImpl container = registry.getContainer(taskData.getContainerId());
if (container == null || (container.getStatus() != KieContainerStatus.STARTED && container.getStatus() != KieContainerStatus.DEACTIVATED)) {
throw new KieServicesException("Container " + taskData.getContainerId() + " is not available to serve requests");
}
Map<String, Object> variables = userTaskService.getTaskInputContentByTaskId(taskData.getContainerId(), taskData.getTaskId());
variables = variables == null ? new HashMap<>() : variables;
return variables.entrySet().stream().filter(entry -> isSimpleTypeValue(entry.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
use of org.kie.server.api.model.taskassigning.TaskData in project droolsjbpm-integration by kiegroup.
the class TaskAssigningRuntimeServiceBaseTest method executePlanningWithTaskInInProgressOrSuspendedStatusWithActualOwnerChanged.
private void executePlanningWithTaskInInProgressOrSuspendedStatusWithActualOwnerChanged(Status status) {
TaskData taskData = mockTaskData(TASK_ID, status, PREVIOUS_ASSIGNED_USER_ID_CHANGED, null);
List<TaskData> taskDataList = Collections.singletonList(taskData);
PlanningItem planningItem = mockPlanningItem(TASK_ID, CONTAINER_ID, ASSIGNED_USER_ID);
PlanningItemList planningItemList = new PlanningItemList(Collections.singletonList(planningItem));
prepareExecution(taskDataList, CONTAINER_ID);
PlanningExecutionResult result = serviceBase.executePlanning(planningItemList, USER_ID);
verify(userTaskService, never()).execute(eq(CONTAINER_ID), any());
String errorMessage = String.format(TASK_MODIFIED_ERROR_MSG_2, planningItem.getPlanningTask().getTaskId(), PREVIOUS_ASSIGNED_USER_ID_CHANGED, ASSIGNED_USER_ID);
assertHasError(result, PlanningExecutionResult.ErrorCode.TASK_MODIFIED_SINCE_PLAN_CALCULATION_ERROR, errorMessage, CONTAINER_ID);
}
use of org.kie.server.api.model.taskassigning.TaskData in project droolsjbpm-integration by kiegroup.
the class TaskAssigningRuntimeServiceBaseTest method executePlanningWithTaskInReservedStatusWithPlanningTaskButReassigned.
@Test
public void executePlanningWithTaskInReservedStatusWithPlanningTaskButReassigned() {
PlanningTask planningTask = mockPlanningTask(TASK_ID, PREVIOUS_ASSIGNED_USER_ID);
TaskData taskData = mockTaskData(TASK_ID, Reserved, PREVIOUS_ASSIGNED_USER_ID_CHANGED, planningTask);
List<TaskData> taskDataList = Collections.singletonList(taskData);
PlanningItem planningItem = mockPlanningItem(TASK_ID, CONTAINER_ID, ASSIGNED_USER_ID);
PlanningItemList planningItemList = new PlanningItemList(Collections.singletonList(planningItem));
prepareExecution(taskDataList, CONTAINER_ID);
PlanningExecutionResult result = serviceBase.executePlanning(planningItemList, USER_ID);
verify(userTaskService, never()).execute(eq(CONTAINER_ID), any());
String errorMessage = String.format(TASK_MODIFIED_ERROR_MSG_1, taskData.getTaskId(), PREVIOUS_ASSIGNED_USER_ID_CHANGED, PREVIOUS_ASSIGNED_USER_ID);
assertHasError(result, PlanningExecutionResult.ErrorCode.TASK_MODIFIED_SINCE_PLAN_CALCULATION_ERROR, errorMessage, CONTAINER_ID);
}
Aggregations