TSK-1387: TaskQuery now supports combining multiple values for objectreference
This commit is contained in:
parent
4fd7423575
commit
fa19359795
|
|
@ -4,6 +4,7 @@ import pro.taskana.common.api.BaseQuery;
|
||||||
import pro.taskana.common.api.KeyDomain;
|
import pro.taskana.common.api.KeyDomain;
|
||||||
import pro.taskana.common.api.TimeInterval;
|
import pro.taskana.common.api.TimeInterval;
|
||||||
import pro.taskana.common.api.exceptions.InvalidArgumentException;
|
import pro.taskana.common.api.exceptions.InvalidArgumentException;
|
||||||
|
import pro.taskana.task.api.models.ObjectReference;
|
||||||
import pro.taskana.task.api.models.TaskSummary;
|
import pro.taskana.task.api.models.TaskSummary;
|
||||||
|
|
||||||
/** TaskQuery for generating dynamic sql. */
|
/** TaskQuery for generating dynamic sql. */
|
||||||
|
|
@ -203,14 +204,27 @@ public interface TaskQuery extends BaseQuery<TaskSummary, TaskQueryColumnName> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the owner for pattern matching to your query. It will be compared in SQL with the LIKE
|
* Add the owner for pattern matching to your query. It will be compared in SQL with the LIKE
|
||||||
* operator. You may use a wildcard like % to specify the pattern. If you specify multiple
|
* operator. You may use a wildcard like % to specify the pattern.
|
||||||
* arguments they are combined with the OR keyword.
|
*
|
||||||
|
* <p>If you specify multiple arguments they are combined with the OR keyword.</p>
|
||||||
*
|
*
|
||||||
* @param owners the owners of the searched tasks
|
* @param owners the owners of the searched tasks
|
||||||
* @return the query
|
* @return the query
|
||||||
*/
|
*/
|
||||||
TaskQuery ownerLike(String... owners);
|
TaskQuery ownerLike(String... owners);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the {@link ObjectReference} to exact match to your query. Each individual value has to
|
||||||
|
* match. Fields with the value 'null' will be ignored.
|
||||||
|
* The id of each ObjectReference will be ignored
|
||||||
|
*
|
||||||
|
* <p>If you specify multiple arguments they are combined with the OR keyword.</p>
|
||||||
|
*
|
||||||
|
* @param objectReferences the combined values which are searched together.
|
||||||
|
* @return the query
|
||||||
|
*/
|
||||||
|
TaskQuery primaryObjectReferenceIn(ObjectReference... objectReferences);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the companies of the primary object reference for exact matching to your query.
|
* Add the companies of the primary object reference for exact matching to your query.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import pro.taskana.task.api.TaskQuery;
|
||||||
import pro.taskana.task.api.TaskQueryColumnName;
|
import pro.taskana.task.api.TaskQueryColumnName;
|
||||||
import pro.taskana.task.api.TaskState;
|
import pro.taskana.task.api.TaskState;
|
||||||
import pro.taskana.task.api.WildcardSearchField;
|
import pro.taskana.task.api.WildcardSearchField;
|
||||||
|
import pro.taskana.task.api.models.ObjectReference;
|
||||||
import pro.taskana.task.api.models.TaskSummary;
|
import pro.taskana.task.api.models.TaskSummary;
|
||||||
import pro.taskana.task.internal.models.TaskSummaryImpl;
|
import pro.taskana.task.internal.models.TaskSummaryImpl;
|
||||||
import pro.taskana.workbasket.api.WorkbasketPermission;
|
import pro.taskana.workbasket.api.WorkbasketPermission;
|
||||||
|
|
@ -80,6 +81,7 @@ public class TaskQueryImpl implements TaskQuery {
|
||||||
private String[] ownerLike;
|
private String[] ownerLike;
|
||||||
private Boolean isRead;
|
private Boolean isRead;
|
||||||
private Boolean isTransferred;
|
private Boolean isTransferred;
|
||||||
|
private ObjectReference[] objectReferences;
|
||||||
private String[] porCompanyIn;
|
private String[] porCompanyIn;
|
||||||
private String[] porCompanyLike;
|
private String[] porCompanyLike;
|
||||||
private String[] porSystemIn;
|
private String[] porSystemIn;
|
||||||
|
|
@ -307,6 +309,12 @@ public class TaskQueryImpl implements TaskQuery {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TaskQuery primaryObjectReferenceIn(ObjectReference... objectReferences) {
|
||||||
|
this.objectReferences = objectReferences;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TaskQuery primaryObjectReferenceCompanyIn(String... companies) {
|
public TaskQuery primaryObjectReferenceCompanyIn(String... companies) {
|
||||||
this.porCompanyIn = companies;
|
this.porCompanyIn = companies;
|
||||||
|
|
@ -445,11 +453,6 @@ public class TaskQueryImpl implements TaskQuery {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TaskQuery selectAndClaimEquals(boolean selectAndClaim) {
|
|
||||||
this.selectAndClaim = selectAndClaim;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TaskQuery parentBusinessProcessIdIn(String... parentBusinessProcessIds) {
|
public TaskQuery parentBusinessProcessIdIn(String... parentBusinessProcessIds) {
|
||||||
this.parentBusinessProcessIdIn = parentBusinessProcessIds;
|
this.parentBusinessProcessIdIn = parentBusinessProcessIds;
|
||||||
|
|
@ -897,6 +900,11 @@ public class TaskQueryImpl implements TaskQuery {
|
||||||
return addOrderCriteria("RECEIVED", sortDirection);
|
return addOrderCriteria("RECEIVED", sortDirection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TaskQuery selectAndClaimEquals(boolean selectAndClaim) {
|
||||||
|
this.selectAndClaim = selectAndClaim;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TaskSummary> list() {
|
public List<TaskSummary> list() {
|
||||||
List<TaskSummary> result = new ArrayList<>();
|
List<TaskSummary> result = new ArrayList<>();
|
||||||
|
|
@ -1675,6 +1683,10 @@ public class TaskQueryImpl implements TaskQuery {
|
||||||
+ taskanaEngine
|
+ taskanaEngine
|
||||||
+ ", taskService="
|
+ ", taskService="
|
||||||
+ taskService
|
+ taskService
|
||||||
|
+ ", orderBy="
|
||||||
|
+ orderBy
|
||||||
|
+ ", orderColumns="
|
||||||
|
+ orderColumns
|
||||||
+ ", columnName="
|
+ ", columnName="
|
||||||
+ columnName
|
+ columnName
|
||||||
+ ", nameIn="
|
+ ", nameIn="
|
||||||
|
|
@ -1729,6 +1741,8 @@ public class TaskQueryImpl implements TaskQuery {
|
||||||
+ isRead
|
+ isRead
|
||||||
+ ", isTransferred="
|
+ ", isTransferred="
|
||||||
+ isTransferred
|
+ isTransferred
|
||||||
|
+ ", objectReferences="
|
||||||
|
+ Arrays.toString(objectReferences)
|
||||||
+ ", porCompanyIn="
|
+ ", porCompanyIn="
|
||||||
+ Arrays.toString(porCompanyIn)
|
+ Arrays.toString(porCompanyIn)
|
||||||
+ ", porCompanyLike="
|
+ ", porCompanyLike="
|
||||||
|
|
@ -1861,10 +1875,6 @@ public class TaskQueryImpl implements TaskQuery {
|
||||||
+ Arrays.toString(plannedIn)
|
+ Arrays.toString(plannedIn)
|
||||||
+ ", dueIn="
|
+ ", dueIn="
|
||||||
+ Arrays.toString(dueIn)
|
+ Arrays.toString(dueIn)
|
||||||
+ ", orderBy="
|
|
||||||
+ orderBy
|
|
||||||
+ ", orderColumns="
|
|
||||||
+ orderColumns
|
|
||||||
+ ", wildcardSearchFieldIn="
|
+ ", wildcardSearchFieldIn="
|
||||||
+ Arrays.toString(wildcardSearchFieldIn)
|
+ Arrays.toString(wildcardSearchFieldIn)
|
||||||
+ ", wildcardSearchValueLike="
|
+ ", wildcardSearchValueLike="
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,14 @@ public interface TaskQueryMapper {
|
||||||
+ "<if test='ownerLike != null'>AND (<foreach item='item' collection='ownerLike' separator=' OR '>UPPER(t.OWNER) LIKE #{item}</foreach>)</if> "
|
+ "<if test='ownerLike != null'>AND (<foreach item='item' collection='ownerLike' separator=' OR '>UPPER(t.OWNER) LIKE #{item}</foreach>)</if> "
|
||||||
+ "<if test='isRead != null'>AND t.IS_READ = #{isRead}</if> "
|
+ "<if test='isRead != null'>AND t.IS_READ = #{isRead}</if> "
|
||||||
+ "<if test='isTransferred != null'>AND t.IS_TRANSFERRED = #{isTransferred}</if> "
|
+ "<if test='isTransferred != null'>AND t.IS_TRANSFERRED = #{isTransferred}</if> "
|
||||||
|
+ "<if test='objectReferences != null'>"
|
||||||
|
+ "AND (<foreach item='item' collection='objectReferences' separator=' OR '> "
|
||||||
|
+ "<if test='item.company != null'>t.POR_COMPANY = #{item.company} </if>"
|
||||||
|
+ "<if test='item.system != null'> <if test='item.company != null'>AND</if> t.POR_SYSTEM = #{item.system} </if>"
|
||||||
|
+ "<if test='item.systemInstance != null'> <if test='item.company != null or item.system != null'>AND</if> t.POR_INSTANCE = #{item.systemInstance} </if>"
|
||||||
|
+ "<if test='item.type != null'> <if test='item.company != null or item.system != null or item.systemInstance != null'>AND</if> t.POR_TYPE = #{item.type} </if>"
|
||||||
|
+ "<if test='item.value != null'> <if test='item.company != null or item.system != null or item.systemInstance != null or item.type != null'>AND</if> t.POR_VALUE = #{item.value} </if>"
|
||||||
|
+ "</foreach>)</if>"
|
||||||
+ "<if test='porCompanyIn != null'>AND t.POR_COMPANY IN(<foreach item='item' collection='porCompanyIn' separator=',' >#{item}</foreach>)</if> "
|
+ "<if test='porCompanyIn != null'>AND t.POR_COMPANY IN(<foreach item='item' collection='porCompanyIn' separator=',' >#{item}</foreach>)</if> "
|
||||||
+ "<if test='porCompanyLike != null'>AND (<foreach item='item' collection='porCompanyLike' separator=' OR '>UPPER(t.POR_COMPANY) LIKE #{item}</foreach>)</if> "
|
+ "<if test='porCompanyLike != null'>AND (<foreach item='item' collection='porCompanyLike' separator=' OR '>UPPER(t.POR_COMPANY) LIKE #{item}</foreach>)</if> "
|
||||||
+ "<if test='porSystemIn != null'>AND t.POR_SYSTEM IN(<foreach item='item' collection='porSystemIn' separator=',' >#{item}</foreach>)</if> "
|
+ "<if test='porSystemIn != null'>AND t.POR_SYSTEM IN(<foreach item='item' collection='porSystemIn' separator=',' >#{item}</foreach>)</if> "
|
||||||
|
|
@ -268,6 +276,14 @@ public interface TaskQueryMapper {
|
||||||
+ "<if test='ownerLike != null'>AND (<foreach item='item' collection='ownerLike' separator=' OR '>UPPER(OWNER) LIKE #{item}</foreach>)</if> "
|
+ "<if test='ownerLike != null'>AND (<foreach item='item' collection='ownerLike' separator=' OR '>UPPER(OWNER) LIKE #{item}</foreach>)</if> "
|
||||||
+ "<if test='isRead != null'>AND IS_READ = #{isRead}</if> "
|
+ "<if test='isRead != null'>AND IS_READ = #{isRead}</if> "
|
||||||
+ "<if test='isTransferred != null'>AND IS_TRANSFERRED = #{isTransferred}</if> "
|
+ "<if test='isTransferred != null'>AND IS_TRANSFERRED = #{isTransferred}</if> "
|
||||||
|
+ "<if test='objectReferences != null'>"
|
||||||
|
+ "AND (<foreach item='item' collection='objectReferences' separator=' OR '> "
|
||||||
|
+ "<if test='item.company != null'>t.POR_COMPANY = #{item.company} </if>"
|
||||||
|
+ "<if test='item.system != null'> <if test='item.company != null'>AND</if> t.POR_SYSTEM = #{item.system} </if>"
|
||||||
|
+ "<if test='item.systemInstance != null'> <if test='item.company != null or item.system != null'>AND</if> t.POR_INSTANCE = #{item.systemInstance} </if>"
|
||||||
|
+ "<if test='item.type != null'> <if test='item.company != null or item.system != null or item.systemInstance != null'>AND</if> t.POR_TYPE = #{item.type} </if>"
|
||||||
|
+ "<if test='item.value != null'> <if test='item.company != null or item.system != null or item.systemInstance != null or item.type != null'>AND</if> t.POR_VALUE = #{item.value} </if>"
|
||||||
|
+ "</foreach>)</if>"
|
||||||
+ "<if test='porCompanyIn != null'>AND POR_COMPANY IN(<foreach item='item' collection='porCompanyIn' separator=',' >#{item}</foreach>)</if> "
|
+ "<if test='porCompanyIn != null'>AND POR_COMPANY IN(<foreach item='item' collection='porCompanyIn' separator=',' >#{item}</foreach>)</if> "
|
||||||
+ "<if test='porCompanyLike != null'>AND (<foreach item='item' collection='porCompanyLike' separator=' OR '>UPPER(POR_COMPANY) LIKE #{item}</foreach>)</if> "
|
+ "<if test='porCompanyLike != null'>AND (<foreach item='item' collection='porCompanyLike' separator=' OR '>UPPER(POR_COMPANY) LIKE #{item}</foreach>)</if> "
|
||||||
+ "<if test='porSystemIn != null'>AND POR_SYSTEM IN(<foreach item='item' collection='porSystemIn' separator=',' >#{item}</foreach>)</if> "
|
+ "<if test='porSystemIn != null'>AND POR_SYSTEM IN(<foreach item='item' collection='porSystemIn' separator=',' >#{item}</foreach>)</if> "
|
||||||
|
|
|
||||||
|
|
@ -10,31 +10,108 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import pro.taskana.common.internal.security.JaasExtension;
|
import pro.taskana.common.internal.security.JaasExtension;
|
||||||
import pro.taskana.common.internal.security.WithAccessId;
|
import pro.taskana.common.internal.security.WithAccessId;
|
||||||
import pro.taskana.task.api.TaskService;
|
import pro.taskana.task.api.TaskService;
|
||||||
|
import pro.taskana.task.api.models.ObjectReference;
|
||||||
import pro.taskana.task.api.models.TaskSummary;
|
import pro.taskana.task.api.models.TaskSummary;
|
||||||
|
|
||||||
/** Acceptance test for all "query tasks by object reference" scenarios. */
|
/** Acceptance test for all "query tasks by object reference" scenarios. */
|
||||||
@ExtendWith(JaasExtension.class)
|
@ExtendWith(JaasExtension.class)
|
||||||
class QueryTasksByObjectReferenceAccTest extends AbstractAccTest {
|
class QueryTasksByObjectReferenceAccTest extends AbstractAccTest {
|
||||||
|
|
||||||
QueryTasksByObjectReferenceAccTest() {
|
private static final TaskService TASK_SERVICE = taskanaEngine.getTaskService();
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
@WithAccessId(user = "admin")
|
@WithAccessId(user = "admin")
|
||||||
@Test
|
@Test
|
||||||
void testQueryTasksByExcactValueOfObjectReference() {
|
void testQueryTasksByExcactValueOfObjectReference() {
|
||||||
TaskService taskService = taskanaEngine.getTaskService();
|
|
||||||
List<TaskSummary> results =
|
List<TaskSummary> results =
|
||||||
taskService.createTaskQuery().primaryObjectReferenceValueIn("11223344", "22334455").list();
|
TASK_SERVICE.createTaskQuery().primaryObjectReferenceValueIn("11223344", "22334455").list();
|
||||||
assertThat(results).hasSize(33);
|
assertThat(results).hasSize(33);
|
||||||
}
|
}
|
||||||
|
|
||||||
@WithAccessId(user = "admin")
|
@WithAccessId(user = "admin")
|
||||||
@Test
|
@Test
|
||||||
void testQueryTasksByExcactValueAndTypeOfObjectReference() {
|
void should_ApplyObjectReferencesFilter_When_ValueIsSet() {
|
||||||
TaskService taskService = taskanaEngine.getTaskService();
|
ObjectReference objectReference = new ObjectReference();
|
||||||
|
objectReference.setValue("11223344");
|
||||||
List<TaskSummary> results =
|
List<TaskSummary> results =
|
||||||
taskService
|
TASK_SERVICE.createTaskQuery().primaryObjectReferenceIn(objectReference).list();
|
||||||
|
assertThat(results).hasSize(21);
|
||||||
|
}
|
||||||
|
|
||||||
|
@WithAccessId(user = "admin")
|
||||||
|
@Test
|
||||||
|
void should_ApplyObjectReferencesFilter_When_TypeIsSet() {
|
||||||
|
ObjectReference objectReference = new ObjectReference();
|
||||||
|
objectReference.setType("SDNR");
|
||||||
|
List<TaskSummary> results =
|
||||||
|
TASK_SERVICE.createTaskQuery().primaryObjectReferenceIn(objectReference).list();
|
||||||
|
assertThat(results).hasSize(45);
|
||||||
|
}
|
||||||
|
|
||||||
|
@WithAccessId(user = "admin")
|
||||||
|
@Test
|
||||||
|
void should_ApplyObjectReferencesFilter_When_CompanyIsSet() {
|
||||||
|
ObjectReference objectReference = new ObjectReference();
|
||||||
|
objectReference.setCompany("MyCompany1");
|
||||||
|
List<TaskSummary> results =
|
||||||
|
TASK_SERVICE.createTaskQuery().primaryObjectReferenceIn(objectReference).list();
|
||||||
|
assertThat(results).hasSize(7);
|
||||||
|
}
|
||||||
|
|
||||||
|
@WithAccessId(user = "admin")
|
||||||
|
@Test
|
||||||
|
void should_ApplyObjectReferencesFilter_When_SystemIsSet() {
|
||||||
|
ObjectReference objectReference = new ObjectReference();
|
||||||
|
objectReference.setSystem("MySystem1");
|
||||||
|
List<TaskSummary> results =
|
||||||
|
TASK_SERVICE.createTaskQuery().primaryObjectReferenceIn(objectReference).list();
|
||||||
|
assertThat(results).hasSize(7);
|
||||||
|
}
|
||||||
|
|
||||||
|
@WithAccessId(user = "admin")
|
||||||
|
@Test
|
||||||
|
void should_ApplyObjectReferencesFilter_When_SystemInstanceIsSet() {
|
||||||
|
ObjectReference objectReference = new ObjectReference();
|
||||||
|
objectReference.setSystemInstance("MyInstance1");
|
||||||
|
List<TaskSummary> results =
|
||||||
|
TASK_SERVICE.createTaskQuery().primaryObjectReferenceIn(objectReference).list();
|
||||||
|
assertThat(results).hasSize(7);
|
||||||
|
}
|
||||||
|
|
||||||
|
@WithAccessId(user = "admin")
|
||||||
|
@Test
|
||||||
|
void should_ApplyObjectReferencesFilter_When_MultipleObjectReferencesExist() {
|
||||||
|
ObjectReference objectReference = new ObjectReference();
|
||||||
|
objectReference.setType("SDNR");
|
||||||
|
ObjectReference objectReference1 = new ObjectReference();
|
||||||
|
objectReference1.setValue("11223344");
|
||||||
|
List<TaskSummary> results =
|
||||||
|
TASK_SERVICE.createTaskQuery()
|
||||||
|
.primaryObjectReferenceIn(objectReference, objectReference1)
|
||||||
|
.list();
|
||||||
|
assertThat(results).hasSize(56);
|
||||||
|
}
|
||||||
|
|
||||||
|
@WithAccessId(user = "admin")
|
||||||
|
@Test
|
||||||
|
void should_ApplyObjectReferencesFilter_When_MultipleFieldsAreSet() {
|
||||||
|
ObjectReference objectReference = new ObjectReference();
|
||||||
|
objectReference.setCompany("00");
|
||||||
|
objectReference.setSystem("PASyste2");
|
||||||
|
objectReference.setSystemInstance("00");
|
||||||
|
objectReference.setType("VNR");
|
||||||
|
objectReference.setValue("67890123");
|
||||||
|
List<TaskSummary> results =
|
||||||
|
TASK_SERVICE.createTaskQuery()
|
||||||
|
.primaryObjectReferenceIn(objectReference)
|
||||||
|
.list();
|
||||||
|
assertThat(results).hasSize(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@WithAccessId(user = "admin")
|
||||||
|
@Test
|
||||||
|
void testQueryTasksByExcactValueAndTypeOfObjectReference() {
|
||||||
|
List<TaskSummary> results =
|
||||||
|
TASK_SERVICE
|
||||||
.createTaskQuery()
|
.createTaskQuery()
|
||||||
.primaryObjectReferenceTypeIn("SDNR")
|
.primaryObjectReferenceTypeIn("SDNR")
|
||||||
.primaryObjectReferenceValueIn("11223344")
|
.primaryObjectReferenceValueIn("11223344")
|
||||||
|
|
@ -45,9 +122,8 @@ class QueryTasksByObjectReferenceAccTest extends AbstractAccTest {
|
||||||
@WithAccessId(user = "admin")
|
@WithAccessId(user = "admin")
|
||||||
@Test
|
@Test
|
||||||
void testQueryTasksByValueLikeOfObjectReference() {
|
void testQueryTasksByValueLikeOfObjectReference() {
|
||||||
TaskService taskService = taskanaEngine.getTaskService();
|
|
||||||
List<TaskSummary> results =
|
List<TaskSummary> results =
|
||||||
taskService.createTaskQuery().primaryObjectReferenceValueLike("%567%").list();
|
TASK_SERVICE.createTaskQuery().primaryObjectReferenceValueLike("%567%").list();
|
||||||
assertThat(results).hasSize(10);
|
assertThat(results).hasSize(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue