diff --git a/history/taskana-simplehistory-provider/src/main/java/pro/taskana/simplehistory/impl/WorkbasketHistoryQueryImpl.java b/history/taskana-simplehistory-provider/src/main/java/pro/taskana/simplehistory/impl/WorkbasketHistoryQueryImpl.java index 2e3bc5fa7..952265d6f 100644 --- a/history/taskana-simplehistory-provider/src/main/java/pro/taskana/simplehistory/impl/WorkbasketHistoryQueryImpl.java +++ b/history/taskana-simplehistory-provider/src/main/java/pro/taskana/simplehistory/impl/WorkbasketHistoryQueryImpl.java @@ -9,8 +9,10 @@ import org.slf4j.LoggerFactory; import pro.taskana.common.api.TimeInterval; import pro.taskana.common.api.exceptions.InvalidArgumentException; +import pro.taskana.common.api.exceptions.SystemException; import pro.taskana.simplehistory.impl.workbasket.WorkbasketHistoryQuery; import pro.taskana.simplehistory.impl.workbasket.WorkbasketHistoryQueryColumnName; +import pro.taskana.spi.history.api.events.workbasket.WorkbasketHistoryCustomField; import pro.taskana.spi.history.api.events.workbasket.WorkbasketHistoryEvent; public class WorkbasketHistoryQueryImpl implements WorkbasketHistoryQuery { @@ -256,30 +258,6 @@ public class WorkbasketHistoryQueryImpl implements WorkbasketHistoryQuery { return this; } - @Override - public WorkbasketHistoryQuery custom1In(String... custom1) { - this.custom1In = toUpperCopy(custom1); - return this; - } - - @Override - public WorkbasketHistoryQuery custom2In(String... custom2) { - this.custom2In = toUpperCopy(custom2); - return this; - } - - @Override - public WorkbasketHistoryQuery custom3In(String... custom3) { - this.custom3In = toUpperCopy(custom3); - return this; - } - - @Override - public WorkbasketHistoryQuery custom4In(String... custom4) { - this.custom4In = toUpperCopy(custom4); - return this; - } - @Override public WorkbasketHistoryQuery orgLevel1In(String... orgLevel1) { this.orgLevel1In = toUpperCopy(orgLevel1); @@ -304,6 +282,50 @@ public class WorkbasketHistoryQueryImpl implements WorkbasketHistoryQuery { return this; } + @Override + public WorkbasketHistoryQuery customAttributeIn( + WorkbasketHistoryCustomField customField, String... searchArguments) { + switch (customField) { + case CUSTOM_1: + custom1In = toUpperCopy(searchArguments); + break; + case CUSTOM_2: + custom2In = toUpperCopy(searchArguments); + break; + case CUSTOM_3: + custom3In = toUpperCopy(searchArguments); + break; + case CUSTOM_4: + custom4In = toUpperCopy(searchArguments); + break; + default: + throw new SystemException("Unknown customField '" + customField + "'"); + } + return this; + } + + @Override + public WorkbasketHistoryQuery customAttributeLike( + WorkbasketHistoryCustomField customField, String... searchArguments) { + switch (customField) { + case CUSTOM_1: + custom1Like = toUpperCopy(searchArguments); + break; + case CUSTOM_2: + custom2Like = toUpperCopy(searchArguments); + break; + case CUSTOM_3: + custom3Like = toUpperCopy(searchArguments); + break; + case CUSTOM_4: + custom4Like = toUpperCopy(searchArguments); + break; + default: + throw new SystemException("Unknown customField '" + customField + "'"); + } + return this; + } + @Override public WorkbasketHistoryQuery workbasketIdLike(String... workbasketId) { this.workbasketIdLike = toUpperCopy(workbasketId); @@ -346,30 +368,6 @@ public class WorkbasketHistoryQueryImpl implements WorkbasketHistoryQuery { return this; } - @Override - public WorkbasketHistoryQuery custom1Like(String... custom1) { - this.custom1Like = toUpperCopy(custom1); - return this; - } - - @Override - public WorkbasketHistoryQuery custom2Like(String... custom2) { - this.custom2Like = toUpperCopy(custom2); - return this; - } - - @Override - public WorkbasketHistoryQuery custom3Like(String... custom3) { - this.custom3Like = toUpperCopy(custom3); - return this; - } - - @Override - public WorkbasketHistoryQuery custom4Like(String... custom4) { - this.custom4Like = toUpperCopy(custom4); - return this; - } - @Override public WorkbasketHistoryQuery orgLevel1Like(String... orgLevel1) { this.orgLevel1Like = toUpperCopy(orgLevel1); diff --git a/history/taskana-simplehistory-provider/src/main/java/pro/taskana/simplehistory/impl/workbasket/WorkbasketHistoryQuery.java b/history/taskana-simplehistory-provider/src/main/java/pro/taskana/simplehistory/impl/workbasket/WorkbasketHistoryQuery.java index 26cc66da6..21fcae27f 100644 --- a/history/taskana-simplehistory-provider/src/main/java/pro/taskana/simplehistory/impl/workbasket/WorkbasketHistoryQuery.java +++ b/history/taskana-simplehistory-provider/src/main/java/pro/taskana/simplehistory/impl/workbasket/WorkbasketHistoryQuery.java @@ -3,6 +3,7 @@ package pro.taskana.simplehistory.impl.workbasket; import pro.taskana.common.api.BaseQuery; import pro.taskana.common.api.TimeInterval; import pro.taskana.common.api.exceptions.InvalidArgumentException; +import pro.taskana.spi.history.api.events.workbasket.WorkbasketHistoryCustomField; import pro.taskana.spi.history.api.events.workbasket.WorkbasketHistoryEvent; /** HistoryQuery for generating dynamic sql. */ @@ -82,39 +83,6 @@ public interface WorkbasketHistoryQuery */ WorkbasketHistoryQuery ownerIn(String... owner); - - /** - * Add your custom1 to your query. - * - * @param custom1 as String - * @return the query - */ - WorkbasketHistoryQuery custom1In(String... custom1); - - /** - * Add your custom2 to your query. - * - * @param custom2 as String - * @return the query - */ - WorkbasketHistoryQuery custom2In(String... custom2); - - /** - * Add your custom3 to your query. - * - * @param custom3 as String - * @return the query - */ - WorkbasketHistoryQuery custom3In(String... custom3); - - /** - * Add your custom4 to your query. - * - * @param custom4 as String - * @return the query - */ - WorkbasketHistoryQuery custom4In(String... custom4); - /** * Add your orgLevel1 to your query. * @@ -147,6 +115,28 @@ public interface WorkbasketHistoryQuery */ WorkbasketHistoryQuery orgLevel4In(String... orgLevel4); + /** + * Add the values of custom attributes for exact matching to your query. + * + * @param customField identifies which custom attribute is affected. + * @param searchArguments the customField values of the searched for tasks + * @return the query + */ + WorkbasketHistoryQuery customAttributeIn( + WorkbasketHistoryCustomField customField, String... searchArguments); + + /** + * Add the values of custom attributes for pattern matching to your query. They 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 customField identifies which custom attribute is affected. + * @param searchArguments the customField values of the searched-for tasks + * @return the query + */ + WorkbasketHistoryQuery customAttributeLike( + WorkbasketHistoryCustomField customField, String... searchArguments); + /** * Add your workbasketId to your query. It will be compared in SQL with an LIKE. If you use a * wildcard like % then it will be transmitted to the database. @@ -210,42 +200,6 @@ public interface WorkbasketHistoryQuery */ WorkbasketHistoryQuery ownerLike(String... owner); - /** - * Add your custom1 to your query. It will be compared in SQL with an LIKE. If you use a wildcard - * like % then it will be transmitted to the database. - * - * @param custom1 as String - * @return the query - */ - WorkbasketHistoryQuery custom1Like(String... custom1); - - /** - * Add your custom2 to your query. It will be compared in SQL with an LIKE. If you use a wildcard - * like % then it will be transmitted to the database. - * - * @param custom2 as String - * @return the query - */ - WorkbasketHistoryQuery custom2Like(String... custom2); - - /** - * Add your custom3 to your query. It will be compared in SQL with an LIKE. If you use a wildcard - * like % then it will be transmitted to the database. - * - * @param custom3 as String - * @return the query - */ - WorkbasketHistoryQuery custom3Like(String... custom3); - - /** - * Add your custom4 to your query. It will be compared in SQL with an LIKE. If you use a wildcard - * like % then it will be transmitted to the database. - * - * @param custom4 as String - * @return the query - */ - WorkbasketHistoryQuery custom4Like(String... custom4); - /** * Add your orgLevel1 to your query. It will be compared in SQL with an LIKE. If you use a * wildcard like % then it will be transmitted to the database. diff --git a/history/taskana-simplehistory-provider/src/test/java/acceptance/query/QueryWorkbasketHistoryAccTest.java b/history/taskana-simplehistory-provider/src/test/java/acceptance/query/QueryWorkbasketHistoryAccTest.java index 0ebfad688..586d31bb0 100644 --- a/history/taskana-simplehistory-provider/src/test/java/acceptance/query/QueryWorkbasketHistoryAccTest.java +++ b/history/taskana-simplehistory-provider/src/test/java/acceptance/query/QueryWorkbasketHistoryAccTest.java @@ -13,6 +13,7 @@ import pro.taskana.common.api.TimeInterval; import pro.taskana.simplehistory.impl.SimpleHistoryServiceImpl; import pro.taskana.simplehistory.impl.workbasket.WorkbasketHistoryQuery; import pro.taskana.simplehistory.impl.workbasket.WorkbasketHistoryQueryColumnName; +import pro.taskana.spi.history.api.events.workbasket.WorkbasketHistoryCustomField; import pro.taskana.spi.history.api.events.workbasket.WorkbasketHistoryEvent; import pro.taskana.spi.history.api.events.workbasket.WorkbasketHistoryEventType; @@ -55,7 +56,7 @@ class QueryWorkbasketHistoryAccTest extends AbstractAccTest { .createWorkbasketHistoryQuery() .eventTypeIn(WorkbasketHistoryEventType.CREATED.getName()) .domainLike("%A") - .custom1In("custom1", "otherCustom1") + .customAttributeIn(WorkbasketHistoryCustomField.CUSTOM_1, "otherCustom1") .orderByCreated(SortDirection.DESCENDING); List results = query.list(); @@ -66,7 +67,7 @@ class QueryWorkbasketHistoryAccTest extends AbstractAccTest { assertThat(results) .extracting(WorkbasketHistoryEvent::getUserId) .containsOnly("claudia", "peter", "sven"); - assertThat(query.count()).isEqualTo(6); + assertThat(results).hasSize(3); } @Test @@ -96,8 +97,7 @@ class QueryWorkbasketHistoryAccTest extends AbstractAccTest { void should_ReturnSingleHistoryEvent_When_UsingSingleMethod() { WorkbasketHistoryEvent single = historyService.createWorkbasketHistoryQuery().userIdIn("peter").single(); - assertThat(single.getEventType()) - .isEqualTo(WorkbasketHistoryEventType.CREATED.getName()); + assertThat(single.getEventType()).isEqualTo(WorkbasketHistoryEventType.CREATED.getName()); single = historyService @@ -150,16 +150,32 @@ class QueryWorkbasketHistoryAccTest extends AbstractAccTest { returnValues = historyService.createWorkbasketHistoryQuery().keyIn("soRt003").list(); assertThat(returnValues).hasSize(5); - returnValues = historyService.createWorkbasketHistoryQuery().custom1In("custom1").list(); + returnValues = + historyService + .createWorkbasketHistoryQuery() + .customAttributeIn(WorkbasketHistoryCustomField.CUSTOM_1, "custom1") + .list(); assertThat(returnValues).hasSize(5); - returnValues = historyService.createWorkbasketHistoryQuery().custom2In("custom2").list(); + returnValues = + historyService + .createWorkbasketHistoryQuery() + .customAttributeIn(WorkbasketHistoryCustomField.CUSTOM_2, "custom2") + .list(); assertThat(returnValues).hasSize(5); - returnValues = historyService.createWorkbasketHistoryQuery().custom3In("custom3").list(); + returnValues = + historyService + .createWorkbasketHistoryQuery() + .customAttributeIn(WorkbasketHistoryCustomField.CUSTOM_3, "custom3") + .list(); assertThat(returnValues).hasSize(5); - returnValues = historyService.createWorkbasketHistoryQuery().custom4In("custom4").list(); + returnValues = + historyService + .createWorkbasketHistoryQuery() + .customAttributeIn(WorkbasketHistoryCustomField.CUSTOM_4, "custom4") + .list(); assertThat(returnValues).hasSize(5); returnValues = historyService.createWorkbasketHistoryQuery().orgLevel1In("orgLevel1").list(); @@ -185,8 +201,7 @@ class QueryWorkbasketHistoryAccTest extends AbstractAccTest { .list(); assertThat(returnValues).hasSize(10); - returnValues = - historyService.createWorkbasketHistoryQuery().eventTypeLike("C%").list(); + returnValues = historyService.createWorkbasketHistoryQuery().eventTypeLike("C%").list(); assertThat(returnValues).hasSize(6); returnValues = historyService.createWorkbasketHistoryQuery().userIdLike("p%", "c%").list(); @@ -204,7 +219,11 @@ class QueryWorkbasketHistoryAccTest extends AbstractAccTest { returnValues = historyService.createWorkbasketHistoryQuery().ownerLike("adm%").list(); assertThat(returnValues).hasSize(10); - returnValues = historyService.createWorkbasketHistoryQuery().custom1Like("other%").list(); + returnValues = + historyService + .createWorkbasketHistoryQuery() + .customAttributeLike(WorkbasketHistoryCustomField.CUSTOM_1, "other%") + .list(); assertThat(returnValues).hasSize(5); returnValues = historyService.createWorkbasketHistoryQuery().orgLevel1Like("org%").list();