TSK-287 add ownerLike, orderByDescription and orderByOwner to WorkbasketQuery

This commit is contained in:
BerndBreier 2018-02-14 11:11:27 +01:00
parent acac30b687
commit 9408142e57
4 changed files with 124 additions and 25 deletions

View File

@ -120,14 +120,15 @@ public interface WorkbasketQuery extends BaseQuery<WorkbasketSummary> {
WorkbasketQuery modifiedBefore(Instant modifiedBefore);
/**
* Add your description to your query. It will be compared case-insensitively to the descriptions of workbaskets.
* You may use a wildcard like '%' to search generically.
* Add your description to your query. It will be compared case-insensitively to the descriptions of workbaskets
* using the LIKE operator. You may use a wildcard like '%' to search generically. If you specify multiple arguments
* they are combined with the OR keyword.
*
* @param description
* your description
* @return the query
*/
WorkbasketQuery descriptionLike(String description);
WorkbasketQuery descriptionLike(String... description);
/**
* Add the owners to your query.
@ -138,6 +139,17 @@ public interface WorkbasketQuery extends BaseQuery<WorkbasketSummary> {
*/
WorkbasketQuery ownerIn(String... owners);
/**
* Add the owners 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.
*
* @param owners
* the owners as Strings
* @return the query
*/
WorkbasketQuery ownerLike(String... owners);
/**
* Setting up the permission which should be granted on the result workbaskets and the users which should be
* checked. READ permission will always be checked by default.<br>
@ -187,4 +199,34 @@ public interface WorkbasketQuery extends BaseQuery<WorkbasketSummary> {
*/
WorkbasketQuery orderByKey(SortDirection sortDirection);
/**
* Sort the query result by description.
*
* @param sortDirection
* Determines whether the result is sorted in ascending or descending order. If sortDirection is null,
* the result is sorted in ascending order
* @return the query
*/
WorkbasketQuery orderByDescription(SortDirection sortDirection);
/**
* Sort the query result by owner.
*
* @param sortDirection
* Determines whether the result is sorted in ascending or descending order. If sortDirection is null,
* the result is sorted in ascending order
* @return the query
*/
WorkbasketQuery orderByOwner(SortDirection sortDirection);
/**
* Sort the query result by type.
*
* @param sortDirection
* Determines whether the result is sorted in ascending or descending order. If sortDirection is null,
* the result is sorted in ascending order
* @return the query
*/
WorkbasketQuery orderByType(SortDirection sortDirection);
}

View File

@ -45,8 +45,9 @@ public class WorkbasketQueryImpl implements WorkbasketQuery {
private Instant createdBefore;
private Instant modifiedAfter;
private Instant modifiedBefore;
private String descriptionLike;
private String[] owner;
private String[] descriptionLike;
private String[] ownerIn;
private String[] ownerLike;
private TaskanaEngineImpl taskanaEngineImpl;
private List<String> orderBy;
@ -122,14 +123,20 @@ public class WorkbasketQueryImpl implements WorkbasketQuery {
}
@Override
public WorkbasketQuery descriptionLike(String description) {
this.descriptionLike = description.toUpperCase();
public WorkbasketQuery descriptionLike(String... description) {
this.descriptionLike = toUpperCopy(description);
return this;
}
@Override
public WorkbasketQuery ownerIn(String... owners) {
this.owner = owners;
this.ownerIn = owners;
return this;
}
@Override
public WorkbasketQuery ownerLike(String... owners) {
this.ownerLike = toUpperCopy(owners);
return this;
}
@ -143,6 +150,21 @@ public class WorkbasketQueryImpl implements WorkbasketQuery {
return addOrderCriteria("KEY", sortDirection);
}
@Override
public WorkbasketQuery orderByDescription(SortDirection sortDirection) {
return addOrderCriteria("DESCRIPTION", sortDirection);
}
@Override
public WorkbasketQuery orderByOwner(SortDirection sortDirection) {
return addOrderCriteria("OWNER", sortDirection);
}
@Override
public WorkbasketQuery orderByType(SortDirection sortDirection) {
return addOrderCriteria("TYPE", sortDirection);
}
@Override
public WorkbasketQuery accessIdsHavePermission(WorkbasketAuthorization permission, String... accessIds)
throws InvalidArgumentException {
@ -298,12 +320,16 @@ public class WorkbasketQueryImpl implements WorkbasketQuery {
return modifiedBefore;
}
public String getDescriptionLike() {
public String[] getDescriptionLike() {
return descriptionLike;
}
public String[] getOwner() {
return owner;
public String[] getOwnerIn() {
return ownerIn;
}
public String[] getOwnerLike() {
return ownerLike;
}
public List<String> getOrderBy() {
@ -354,11 +380,13 @@ public class WorkbasketQueryImpl implements WorkbasketQuery {
builder.append(", modifiedBefore=");
builder.append(modifiedBefore);
builder.append(", descriptionLike=");
builder.append(descriptionLike);
builder.append(", owner=");
builder.append(Arrays.toString(owner));
builder.append(", taskanaEngineImpl=");
builder.append(taskanaEngineImpl);
builder.append(Arrays.toString(descriptionLike));
builder.append(", ownerIn=");
builder.append(Arrays.toString(ownerIn));
builder.append(", ownerLike=");
builder.append(Arrays.toString(ownerLike));
builder.append(", orderBy=");
builder.append(orderBy);
builder.append("]");
return builder.toString();
}
@ -374,12 +402,16 @@ public class WorkbasketQueryImpl implements WorkbasketQuery {
}
}
private String[] toUpperCopy(String... source) {
String[] target = new String[source.length];
for (int i = 0; i < source.length; i++) {
target[i] = source[i].toUpperCase();
static String[] toUpperCopy(String... source) {
if (source == null || source.length == 0) {
return null;
} else {
String[] target = new String[source.length];
for (int i = 0; i < source.length; i++) {
target[i] = source[i].toUpperCase();
}
return target;
}
return target;
}
private WorkbasketQuery addOrderCriteria(String colName, SortDirection sortDirection) {

View File

@ -159,7 +159,8 @@ public interface QueryMapper {
+ "SELECT DISTINCT w.ID, w.KEY, w.NAME, w.DOMAIN, W.TYPE, w.DESCRIPTION, w.OWNER, w.ORG_LEVEL_1, w.ORG_LEVEL_2, w.ORG_LEVEL_3, w.ORG_LEVEL_4 from WORKBASKET w "
+ "<if test='accessId != null'>LEFT OUTER JOIN WORKBASKET_ACCESS_LIST a on w.KEY = a.WORKBASKET_KEY</if> "
+ "<where>"
+ "<if test='owner != null'>AND w.OWNER IN(<foreach item='item' collection='owner' separator=',' >#{item}</foreach>)</if> "
+ "<if test='ownerIn != null'>AND w.OWNER IN(<foreach item='item' collection='ownerIn' separator=',' >#{item}</foreach>)</if> "
+ "<if test='ownerLike != null'>AND (<foreach item='item' collection='ownerLike' separator=' OR ' >UPPER(w.OWNER) LIKE #{item}</foreach>)</if> "
+ "<if test='keyIn != null'>AND UPPER(w.KEY) IN(<foreach item='item' collection='keyIn' separator=',' >#{item}</foreach>)</if> "
+ "<if test='keyLike != null'>AND (<foreach item='item' collection='keyLike' separator=' OR ' >UPPER(w.KEY) LIKE #{item}</foreach>)</if> "
+ "<if test='nameIn != null'>AND UPPER(w.NAME) IN(<foreach item='item' collection='nameIn' separator=',' >#{item}</foreach>)</if> "
@ -171,7 +172,7 @@ public interface QueryMapper {
+ "<if test='createdBefore != null'>AND w.CREATED &lt; #{createdBefore}</if> "
+ "<if test='modifiedAfter != null'>AND w.MODIFIED &gt; #{modifiedAfter}</if> "
+ "<if test='modifiedBefore != null'>AND w.MODIFIED &lt; #{modifiedBefore}</if> "
+ "<if test='descriptionLike != null'>AND UPPER(w.DESCRIPTION) like #{descriptionLike}</if> "
+ "<if test='descriptionLike != null'>AND (<foreach item='item' collection='descriptionLike' separator=' OR '>UPPER(w.DESCRIPTION) LIKE #{item}</foreach>)</if> "
+ "<if test='accessId != null'>AND a.ACCESS_ID IN(<foreach item='item' collection='accessId' separator=',' >#{item}</foreach>) AND PERM_READ = 1 </if> "
+ "<if test='authorization != null'>AND "
+ "<if test=\"authorization.name().equals('OPEN')\">PERM_OPEN</if> "
@ -322,7 +323,8 @@ public interface QueryMapper {
@Select("<script>SELECT COUNT(ID) from WORKBASKET w"
+ "<if test='accessId != null'>LEFT OUTER JOIN WORKBASKET_ACCESS_LIST a on w.KEY = a.WORKBASKET_KEY</if> "
+ "<where>"
+ "<if test='owner != null'>AND w.OWNER IN(<foreach item='item' collection='owner' separator=',' >#{item}</foreach>)</if> "
+ "<if test='ownerIn != null'>AND w.OWNER IN(<foreach item='item' collection='ownerIn' separator=',' >#{item}</foreach>)</if> "
+ "<if test='ownerLike != null'>AND (<foreach item='item' collection='ownerLike' separator=' OR ' >UPPER(w.OWNER) LIKE #{item}</foreach>)</if> "
+ "<if test='keyIn != null'>AND UPPER(w.KEY) IN(<foreach item='item' collection='keyIn' separator=',' >#{item}</foreach>)</if> "
+ "<if test='keyLike != null'>AND (<foreach item='item' collection='keyLike' separator=' OR ' >UPPER(w.KEY) LIKE #{item}</foreach>)</if> "
+ "<if test='nameIn != null'>AND UPPER(w.NAME) IN(<foreach item='item' collection='nameIn' separator=',' >#{item}</foreach>)</if> "
@ -334,7 +336,7 @@ public interface QueryMapper {
+ "<if test='createdBefore != null'>AND w.CREATED &lt; #{createdBefore}</if> "
+ "<if test='modifiedAfter != null'>AND w.MODIFIED &gt; #{modifiedAfter}</if> "
+ "<if test='modifiedBefore != null'>AND w.MODIFIED &lt; #{modifiedBefore}</if> "
+ "<if test='descriptionLike != null'>AND UPPER(w.DESCRIPTION) like #{descriptionLike}</if> "
+ "<if test='descriptionLike != null'>AND (<foreach item='item' collection='descriptionLike' separator=' OR '>UPPER(w.DESCRIPTION) LIKE #{item}</foreach>)</if> "
+ "<if test='accessId != null'>AND a.ACCESS_ID IN(<foreach item='item' collection='accessId' separator=',' >#{item}</foreach>) AND PERM_READ = 1 </if> "
+ "<if test='authorization != null'>AND "
+ "<if test=\"authorization.name().equals('OPEN')\">PERM_OPEN</if> "

View File

@ -94,6 +94,29 @@ public class QueryWorkbasketAccTest extends AbstractAccTest {
Assert.assertEquals(2L, results.size());
}
@Test
public void testQueryWorkbasketByDescription()
throws SQLException, NotAuthorizedException, InvalidArgumentException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
List<WorkbasketSummary> results = workbasketService.createWorkbasketQuery()
.descriptionLike("%consectetur%", "%gruppen%")
.orderByType(desc)
.orderByDescription(asc)
.list();
Assert.assertEquals(11L, results.size());
}
@Test
public void testQueryWorkbasketByOwnerLike()
throws SQLException, NotAuthorizedException, InvalidArgumentException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
List<WorkbasketSummary> results = workbasketService.createWorkbasketQuery()
.ownerLike("%an%", "%te%")
.orderByOwner(asc)
.list();
Assert.assertEquals(3L, results.size());
}
@Test
public void testQueryWorkbasketByKey()
throws SQLException, NotAuthorizedException, InvalidArgumentException {