Is there a easy way do query task or process?


#1

I think camunda not yet provide a good solution for query task or process.
If i need query task in multile process. I must use a cycle to do it.
Just like below code.

 @NotNull
    @Override
    public Set<ApplicationApprovalTask> getTheApplicationApprovalTask(Set<String> processInstanceIds, Long userId, PageAndSize pageAndSize) {
        Set<ApplicationApprovalTask> tasks = new HashSet<>(16);
        User user = userService.getUserIfNotExistsThenThrowException(userId);

        processInstanceIds.forEach(o -> {
            Optional<Set<Task>> result  = getApplicationApprovalTask(user, o);
        });
        
        return null;
    }

    private Optional<Set<Task>> getApplicationApprovalTask(User user, String processInstanceId) {
        List<Task> tasks = taskService
                .createTaskQuery()
                .processInstanceId(processInstanceId)
                .taskDescriptionLike(BaseSignUpProjectProcessConstants.APPLICATION_APPROVAL_TASK_PREFIX + "%")
                .taskAssignee(String.valueOf(user.getId()))
                .list();

        Department department = user.getDepartmentOfJoined();
        boolean emptyResult = tasks == null || tasks.isEmpty();

        if (  emptyResult && department != null ) {
            tasks = taskService
                    .createTaskQuery()
                    .processInstanceId(processInstanceId)
                    .taskDefinitionKeyLike(BaseSignUpProjectProcessConstants.APPLICATION_APPROVAL_TASK_PREFIX + "%")
                    .taskCandidateGroup(String.valueOf(department.getId()))
                    .list();

            if (tasks == null || tasks.isEmpty()) {
                return  Optional.empty();
            }else {
                return Optional.of( new HashSet<>(tasks));
            }
        }else {
            return Optional.empty();
        }
    }

Actully this is a stupid implementation. I want a query tool that can be easly to do query just like use sql to query it.


#2

Consider using a business key instead of a processInstanceId and you’ll be able to make a query like this

List<Task> list = taskService.createTaskQuery()
    .processInstanceBusinessKeyIn("someKey", "someOtherKey")
    .taskDefinitionKey("SomeTaskDef")
    .list();