Hi.
I need to query for tasks by many optional (using OR) queries with required (using AND) subqueries.
For example:
TaskQuery tq1 = taskService.createTaskQuery().taskAssignee(“u1”);
TaskQuery tq2 = taskService.createTaskQuery().taskDefinitionKey(“make-purchase”).processDefinitionKey(“purchasing”).tenantIdIn(“t1”);
I need that whether the whole tq1 be true or the tq2. Like:
select * from tasks where (assignee = u1) OR (taskDefinitionKey = “make-purchase” AND processDefinitionKey = “purchasing” AND tenantID in (“t1”));
I realized that this is not possible now because of the mybatis task implementation of the selectTaskByQueryCriteriaSql sql:
<sql id="selectTaskByQueryCriteriaSql">
....
<foreach collection="queries" item="query" index="i">
<choose>
<when test="i == 0">
<bind name="queryType" value="'and'" />
</when>
<otherwise>
<bind name="queryType" value="'or'" />
</otherwise>
</choose>
and ( <<<<<<<---- THIS HARDCODED AND
....
There is a hardcoded ‘and’ that makes all queries required.
So I made my own mybatis configuration like that:
<sql id="selectTaskByOrQueryCriteriaSql">
....
<foreach collection="queries" item="query" index="i">
<choose>
<when test="i == 0">
<bind name="queryType" value="'and'" />
</when>
<otherwise>
<bind name="queryType" value="'or'" />
</otherwise>
</choose>
or ( <<<<<<<<<<---- My hardcoded OR
....
The problem is that I need to extend the FilterService class in order to call a custom TaskQueryImpl that calls the findTasksByOrQueryCriteria that I created.
It seems to me that this solution is too fragile because is bounded to much on the Camunda implementation.
I don’t want to implement an endpoint to ask for tasks, because I want to use the Camunda builtin endpoints though.