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.TimeInterval;
|
||||
import pro.taskana.common.api.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.task.api.models.ObjectReference;
|
||||
import pro.taskana.task.api.models.TaskSummary;
|
||||
|
||||
/** 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
|
||||
* operator. You may use a wildcard like % to specify the pattern. If you specify multiple
|
||||
* arguments they are combined with the OR keyword.
|
||||
* operator. You may use a wildcard like % to specify the pattern.
|
||||
*
|
||||
* <p>If you specify multiple arguments they are combined with the OR keyword.</p>
|
||||
*
|
||||
* @param owners the owners of the searched tasks
|
||||
* @return the query
|
||||
*/
|
||||
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.
|
||||
*
|
||||
|
|
|
@ -26,6 +26,7 @@ import pro.taskana.task.api.TaskQuery;
|
|||
import pro.taskana.task.api.TaskQueryColumnName;
|
||||
import pro.taskana.task.api.TaskState;
|
||||
import pro.taskana.task.api.WildcardSearchField;
|
||||
import pro.taskana.task.api.models.ObjectReference;
|
||||
import pro.taskana.task.api.models.TaskSummary;
|
||||
import pro.taskana.task.internal.models.TaskSummaryImpl;
|
||||
import pro.taskana.workbasket.api.WorkbasketPermission;
|
||||
|
@ -80,6 +81,7 @@ public class TaskQueryImpl implements TaskQuery {
|
|||
private String[] ownerLike;
|
||||
private Boolean isRead;
|
||||
private Boolean isTransferred;
|
||||
private ObjectReference[] objectReferences;
|
||||
private String[] porCompanyIn;
|
||||
private String[] porCompanyLike;
|
||||
private String[] porSystemIn;
|
||||
|
@ -307,6 +309,12 @@ public class TaskQueryImpl implements TaskQuery {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskQuery primaryObjectReferenceIn(ObjectReference... objectReferences) {
|
||||
this.objectReferences = objectReferences;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskQuery primaryObjectReferenceCompanyIn(String... companies) {
|
||||
this.porCompanyIn = companies;
|
||||
|
@ -445,11 +453,6 @@ public class TaskQueryImpl implements TaskQuery {
|
|||
return this;
|
||||
}
|
||||
|
||||
public TaskQuery selectAndClaimEquals(boolean selectAndClaim) {
|
||||
this.selectAndClaim = selectAndClaim;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskQuery parentBusinessProcessIdIn(String... parentBusinessProcessIds) {
|
||||
this.parentBusinessProcessIdIn = parentBusinessProcessIds;
|
||||
|
@ -897,6 +900,11 @@ public class TaskQueryImpl implements TaskQuery {
|
|||
return addOrderCriteria("RECEIVED", sortDirection);
|
||||
}
|
||||
|
||||
public TaskQuery selectAndClaimEquals(boolean selectAndClaim) {
|
||||
this.selectAndClaim = selectAndClaim;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TaskSummary> list() {
|
||||
List<TaskSummary> result = new ArrayList<>();
|
||||
|
@ -1675,6 +1683,10 @@ public class TaskQueryImpl implements TaskQuery {
|
|||
+ taskanaEngine
|
||||
+ ", taskService="
|
||||
+ taskService
|
||||
+ ", orderBy="
|
||||
+ orderBy
|
||||
+ ", orderColumns="
|
||||
+ orderColumns
|
||||
+ ", columnName="
|
||||
+ columnName
|
||||
+ ", nameIn="
|
||||
|
@ -1729,6 +1741,8 @@ public class TaskQueryImpl implements TaskQuery {
|
|||
+ isRead
|
||||
+ ", isTransferred="
|
||||
+ isTransferred
|
||||
+ ", objectReferences="
|
||||
+ Arrays.toString(objectReferences)
|
||||
+ ", porCompanyIn="
|
||||
+ Arrays.toString(porCompanyIn)
|
||||
+ ", porCompanyLike="
|
||||
|
@ -1861,10 +1875,6 @@ public class TaskQueryImpl implements TaskQuery {
|
|||
+ Arrays.toString(plannedIn)
|
||||
+ ", dueIn="
|
||||
+ Arrays.toString(dueIn)
|
||||
+ ", orderBy="
|
||||
+ orderBy
|
||||
+ ", orderColumns="
|
||||
+ orderColumns
|
||||
+ ", wildcardSearchFieldIn="
|
||||
+ Arrays.toString(wildcardSearchFieldIn)
|
||||
+ ", 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='isRead != null'>AND t.IS_READ = #{isRead}</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='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> "
|
||||
|
@ -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='isRead != null'>AND IS_READ = #{isRead}</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='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> "
|
||||
|
|
|
@ -10,31 +10,108 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
|||
import pro.taskana.common.internal.security.JaasExtension;
|
||||
import pro.taskana.common.internal.security.WithAccessId;
|
||||
import pro.taskana.task.api.TaskService;
|
||||
import pro.taskana.task.api.models.ObjectReference;
|
||||
import pro.taskana.task.api.models.TaskSummary;
|
||||
|
||||
/** Acceptance test for all "query tasks by object reference" scenarios. */
|
||||
@ExtendWith(JaasExtension.class)
|
||||
class QueryTasksByObjectReferenceAccTest extends AbstractAccTest {
|
||||
|
||||
QueryTasksByObjectReferenceAccTest() {
|
||||
super();
|
||||
}
|
||||
private static final TaskService TASK_SERVICE = taskanaEngine.getTaskService();
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void testQueryTasksByExcactValueOfObjectReference() {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
List<TaskSummary> results =
|
||||
taskService.createTaskQuery().primaryObjectReferenceValueIn("11223344", "22334455").list();
|
||||
TASK_SERVICE.createTaskQuery().primaryObjectReferenceValueIn("11223344", "22334455").list();
|
||||
assertThat(results).hasSize(33);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void testQueryTasksByExcactValueAndTypeOfObjectReference() {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
void should_ApplyObjectReferencesFilter_When_ValueIsSet() {
|
||||
ObjectReference objectReference = new ObjectReference();
|
||||
objectReference.setValue("11223344");
|
||||
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()
|
||||
.primaryObjectReferenceTypeIn("SDNR")
|
||||
.primaryObjectReferenceValueIn("11223344")
|
||||
|
@ -45,9 +122,8 @@ class QueryTasksByObjectReferenceAccTest extends AbstractAccTest {
|
|||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void testQueryTasksByValueLikeOfObjectReference() {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
List<TaskSummary> results =
|
||||
taskService.createTaskQuery().primaryObjectReferenceValueLike("%567%").list();
|
||||
TASK_SERVICE.createTaskQuery().primaryObjectReferenceValueLike("%567%").list();
|
||||
assertThat(results).hasSize(10);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue