Search in sources :

Example 1 with PAGE

use of org.kie.server.api.model.taskassigning.QueryParamName.PAGE 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)

Aggregations

LocalDateTime (java.time.LocalDateTime)1 ZoneId (java.time.ZoneId)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 ClassUtils.isPrimitiveWrapper (org.apache.commons.lang3.ClassUtils.isPrimitiveWrapper)1 UserTaskService (org.jbpm.services.api.UserTaskService)1 QueryMapperRegistry (org.jbpm.services.api.query.QueryMapperRegistry)1 QueryResultMapper (org.jbpm.services.api.query.QueryResultMapper)1 QueryService (org.jbpm.services.api.query.QueryService)1 QueryParam (org.jbpm.services.api.query.model.QueryParam)1 QueryContext (org.kie.api.runtime.query.QueryContext)1 Status (org.kie.api.task.model.Status)1 Created (org.kie.api.task.model.Status.Created)1 InProgress (org.kie.api.task.model.Status.InProgress)1