Search in sources :

Example 41 with TaskData

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());
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) ArrayList(java.util.ArrayList) TaskDataList(org.kie.server.api.model.taskassigning.TaskDataList) TaskData(org.kie.server.api.model.taskassigning.TaskData) Test(org.junit.Test)

Example 42 with TaskData

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;
}
Also used : KieServicesException(org.kie.server.api.exception.KieServicesException) Created(org.kie.api.task.model.Status.Created) QueryService(org.jbpm.services.api.query.QueryService) Date(java.util.Date) QueryResultMapper(org.jbpm.services.api.query.QueryResultMapper) LocalDateTime(java.time.LocalDateTime) AbstractTaskAssigningQueryMapper(org.kie.server.services.taskassigning.runtime.query.AbstractTaskAssigningQueryMapper) Reserved(org.kie.api.task.model.Status.Reserved) HashMap(java.util.HashMap) STATUS(org.kie.server.api.model.taskassigning.QueryParamName.STATUS) TaskAssigningTaskDataWithPotentialOwnersQueryMapper(org.kie.server.services.taskassigning.runtime.query.TaskAssigningTaskDataWithPotentialOwnersQueryMapper) ClassUtils.isPrimitiveWrapper(org.apache.commons.lang3.ClassUtils.isPrimitiveWrapper) QueryParam(org.jbpm.services.api.query.model.QueryParam) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) InProgress(org.kie.api.task.model.Status.InProgress) ArrayList(java.util.ArrayList) TaskData(org.kie.server.api.model.taskassigning.TaskData) PAGE(org.kie.server.api.model.taskassigning.QueryParamName.PAGE) Map(java.util.Map) PAGE_SIZE(org.kie.server.api.model.taskassigning.QueryParamName.PAGE_SIZE) UserTaskService(org.jbpm.services.api.UserTaskService) KieContainerStatus(org.kie.server.api.model.KieContainerStatus) Suspended(org.kie.api.task.model.Status.Suspended) FROM_LAST_MODIFICATION_DATE(org.kie.server.api.model.taskassigning.QueryParamName.FROM_LAST_MODIFICATION_DATE) StatusConverter(org.kie.server.api.model.taskassigning.util.StatusConverter) Ready(org.kie.api.task.model.Status.Ready) TASK_INPUT_VARIABLES_MODE(org.kie.server.api.model.taskassigning.QueryParamName.TASK_INPUT_VARIABLES_MODE) TaskInputVariablesReadMode(org.kie.server.api.model.taskassigning.TaskInputVariablesReadMode) Predicate(java.util.function.Predicate) QueryContext(org.kie.api.runtime.query.QueryContext) QueryMapperRegistry(org.jbpm.services.api.query.QueryMapperRegistry) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) KieServerRegistry(org.kie.server.services.api.KieServerRegistry) TO_TASK_ID(org.kie.server.api.model.taskassigning.QueryParamName.TO_TASK_ID) List(java.util.List) TaskAssigningTaskDataSummaryQueryMapper(org.kie.server.services.taskassigning.runtime.query.TaskAssigningTaskDataSummaryQueryMapper) FROM_TASK_ID(org.kie.server.api.model.taskassigning.QueryParamName.FROM_TASK_ID) Optional(java.util.Optional) Status(org.kie.api.task.model.Status) LocalDateTimeValue(org.kie.server.api.model.taskassigning.LocalDateTimeValue) KieContainerStatus(org.kie.server.api.model.KieContainerStatus) Status(org.kie.api.task.model.Status) QueryContext(org.kie.api.runtime.query.QueryContext) TaskData(org.kie.server.api.model.taskassigning.TaskData) Predicate(java.util.function.Predicate) AbstractTaskAssigningQueryMapper(org.kie.server.services.taskassigning.runtime.query.AbstractTaskAssigningQueryMapper) QueryParam(org.jbpm.services.api.query.model.QueryParam)

Example 43 with TaskData

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));
}
Also used : KieServicesException(org.kie.server.api.exception.KieServicesException) Created(org.kie.api.task.model.Status.Created) QueryService(org.jbpm.services.api.query.QueryService) Date(java.util.Date) QueryResultMapper(org.jbpm.services.api.query.QueryResultMapper) LocalDateTime(java.time.LocalDateTime) AbstractTaskAssigningQueryMapper(org.kie.server.services.taskassigning.runtime.query.AbstractTaskAssigningQueryMapper) Reserved(org.kie.api.task.model.Status.Reserved) HashMap(java.util.HashMap) STATUS(org.kie.server.api.model.taskassigning.QueryParamName.STATUS) TaskAssigningTaskDataWithPotentialOwnersQueryMapper(org.kie.server.services.taskassigning.runtime.query.TaskAssigningTaskDataWithPotentialOwnersQueryMapper) ClassUtils.isPrimitiveWrapper(org.apache.commons.lang3.ClassUtils.isPrimitiveWrapper) QueryParam(org.jbpm.services.api.query.model.QueryParam) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) InProgress(org.kie.api.task.model.Status.InProgress) ArrayList(java.util.ArrayList) TaskData(org.kie.server.api.model.taskassigning.TaskData) PAGE(org.kie.server.api.model.taskassigning.QueryParamName.PAGE) Map(java.util.Map) PAGE_SIZE(org.kie.server.api.model.taskassigning.QueryParamName.PAGE_SIZE) UserTaskService(org.jbpm.services.api.UserTaskService) KieContainerStatus(org.kie.server.api.model.KieContainerStatus) Suspended(org.kie.api.task.model.Status.Suspended) FROM_LAST_MODIFICATION_DATE(org.kie.server.api.model.taskassigning.QueryParamName.FROM_LAST_MODIFICATION_DATE) StatusConverter(org.kie.server.api.model.taskassigning.util.StatusConverter) Ready(org.kie.api.task.model.Status.Ready) TASK_INPUT_VARIABLES_MODE(org.kie.server.api.model.taskassigning.QueryParamName.TASK_INPUT_VARIABLES_MODE) TaskInputVariablesReadMode(org.kie.server.api.model.taskassigning.TaskInputVariablesReadMode) Predicate(java.util.function.Predicate) QueryContext(org.kie.api.runtime.query.QueryContext) QueryMapperRegistry(org.jbpm.services.api.query.QueryMapperRegistry) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) KieServerRegistry(org.kie.server.services.api.KieServerRegistry) TO_TASK_ID(org.kie.server.api.model.taskassigning.QueryParamName.TO_TASK_ID) List(java.util.List) TaskAssigningTaskDataSummaryQueryMapper(org.kie.server.services.taskassigning.runtime.query.TaskAssigningTaskDataSummaryQueryMapper) FROM_TASK_ID(org.kie.server.api.model.taskassigning.QueryParamName.FROM_TASK_ID) Optional(java.util.Optional) Status(org.kie.api.task.model.Status) LocalDateTimeValue(org.kie.server.api.model.taskassigning.LocalDateTimeValue) HashMap(java.util.HashMap) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) HashMap(java.util.HashMap) Map(java.util.Map) KieServicesException(org.kie.server.api.exception.KieServicesException)

Example 44 with TaskData

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);
}
Also used : PlanningItemList(org.kie.server.api.model.taskassigning.PlanningItemList) PlanningExecutionResult(org.kie.server.api.model.taskassigning.PlanningExecutionResult) StatusConverter.convertToString(org.kie.server.api.model.taskassigning.util.StatusConverter.convertToString) PlanningItem(org.kie.server.api.model.taskassigning.PlanningItem) TaskData(org.kie.server.api.model.taskassigning.TaskData)

Example 45 with TaskData

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);
}
Also used : PlanningTask(org.kie.server.api.model.taskassigning.PlanningTask) PlanningItemList(org.kie.server.api.model.taskassigning.PlanningItemList) PlanningExecutionResult(org.kie.server.api.model.taskassigning.PlanningExecutionResult) StatusConverter.convertToString(org.kie.server.api.model.taskassigning.util.StatusConverter.convertToString) PlanningItem(org.kie.server.api.model.taskassigning.PlanningItem) TaskData(org.kie.server.api.model.taskassigning.TaskData) Test(org.junit.Test)

Aggregations

TaskData (org.kie.server.api.model.taskassigning.TaskData)55 Test (org.junit.Test)30 PlanningTask (org.kie.server.api.model.taskassigning.PlanningTask)26 TaskAssigningSolution (org.kie.server.services.taskassigning.core.model.TaskAssigningSolution)14 TaskUtil.fromTaskData (org.kie.server.services.taskassigning.planning.util.TaskUtil.fromTaskData)13 PlanningExecutionResult (org.kie.server.api.model.taskassigning.PlanningExecutionResult)10 PlanningItemList (org.kie.server.api.model.taskassigning.PlanningItemList)10 Task (org.kie.server.services.taskassigning.core.model.Task)10 AddTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange)10 AddUserProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.AddUserProblemFactChange)10 AssignTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange)10 DisableUserProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange)10 ReleaseTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange)10 RemoveTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange)10 RemoveUserProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange)10 TaskPropertyChangeProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange)10 UserPropertyChangeProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange)10 ProblemFactChange (org.optaplanner.core.impl.solver.ProblemFactChange)10 PlanningItem (org.kie.server.api.model.taskassigning.PlanningItem)9 ArrayList (java.util.ArrayList)8