diff --git a/lib/taskana-core/src/main/java/pro/taskana/WorkbasketQuery.java b/lib/taskana-core/src/main/java/pro/taskana/WorkbasketQuery.java index 97c456003..ed4f589de 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/WorkbasketQuery.java +++ b/lib/taskana-core/src/main/java/pro/taskana/WorkbasketQuery.java @@ -120,14 +120,15 @@ public interface WorkbasketQuery extends BaseQuery { 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 { */ 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.
@@ -187,4 +199,34 @@ public interface WorkbasketQuery extends BaseQuery { */ 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); + } diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketQueryImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketQueryImpl.java index 1faae0fdb..2a82b5656 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketQueryImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketQueryImpl.java @@ -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 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 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) { diff --git a/lib/taskana-core/src/main/java/pro/taskana/model/mappings/QueryMapper.java b/lib/taskana-core/src/main/java/pro/taskana/model/mappings/QueryMapper.java index 58ff1b875..f49b44927 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/model/mappings/QueryMapper.java +++ b/lib/taskana-core/src/main/java/pro/taskana/model/mappings/QueryMapper.java @@ -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 " + "LEFT OUTER JOIN WORKBASKET_ACCESS_LIST a on w.KEY = a.WORKBASKET_KEY " + "" - + "AND w.OWNER IN(#{item}) " + + "AND w.OWNER IN(#{item}) " + + "AND (UPPER(w.OWNER) LIKE #{item}) " + "AND UPPER(w.KEY) IN(#{item}) " + "AND (UPPER(w.KEY) LIKE #{item}) " + "AND UPPER(w.NAME) IN(#{item}) " @@ -171,7 +172,7 @@ public interface QueryMapper { + "AND w.CREATED < #{createdBefore} " + "AND w.MODIFIED > #{modifiedAfter} " + "AND w.MODIFIED < #{modifiedBefore} " - + "AND UPPER(w.DESCRIPTION) like #{descriptionLike} " + + "AND (UPPER(w.DESCRIPTION) LIKE #{item}) " + "AND a.ACCESS_ID IN(#{item}) AND PERM_READ = 1 " + "AND " + "PERM_OPEN " @@ -322,7 +323,8 @@ public interface QueryMapper { @Select("