From d4110731f75fdb323f5624a78a4371a86afec2a9 Mon Sep 17 00:00:00 2001 From: Martin Rojas Miguel Angel Date: Tue, 7 Aug 2018 14:49:15 +0200 Subject: [PATCH] TSK-644 make tasks attachments queryable --- .../src/main/java/pro/taskana/TaskQuery.java | 153 ++++++ .../java/pro/taskana/impl/TaskQueryImpl.java | 229 +++++++- .../taskana/mappings/AttachmentMapper.java | 6 +- .../pro/taskana/mappings/QueryMapper.java | 487 ++++++++++++------ .../acceptance/task/QueryTasksAccTest.java | 434 ++++++++++++---- .../task/QueryTasksWithPaginationAccTest.java | 12 + .../pro/taskana/impl/TaskQueryImplTest.java | 11 + .../src/test/resources/sql/attachment.sql | 29 +- 8 files changed, 1078 insertions(+), 283 deletions(-) diff --git a/lib/taskana-core/src/main/java/pro/taskana/TaskQuery.java b/lib/taskana-core/src/main/java/pro/taskana/TaskQuery.java index f8ff18815..003543231 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/TaskQuery.java +++ b/lib/taskana-core/src/main/java/pro/taskana/TaskQuery.java @@ -454,6 +454,99 @@ public interface TaskQuery extends BaseQuery { */ TaskQuery customAttributeLike(String num, String... searchArguments) throws InvalidArgumentException; + + /** + * Add the attachment classification keys for exact matching to your query. + * + * @param attachmentClassificationKeys + * the attachmentClassificationKeys values of the searched for tasks + * @return the query + */ + TaskQuery attachmentClassificationKeyIn(String... attachmentClassificationKeys); + + /** + * Add the attachment classification Keys 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 attachmentClassificationKey + * the attachmentClassificationKeys values of the searched for tasks + * @return the query + */ + TaskQuery attachmentClassificationKeyLike(String... attachmentClassificationKey); + + + /** + * Add the attachment classification Ids for exact matching to your query. + * + * @param attachmentClassificationId + * the attachmentClassificationId values of the searched for tasks + * @return the query + */ + TaskQuery attachmentClassificationIdIn(String... attachmentClassificationId); + + /** + * Add the values of attachment classification ids 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 attachmentClassificationId + * the attachmentClassificationId values of the searched-for tasks + * @return the query + */ + TaskQuery attachmentClassificationIdLike(String... attachmentClassificationId); + + /** + * Add the values of attachment channel for exact matching to your query. + * + * @param attachmentChannel + * the attachmentChannel values of the searched for tasks + * @return the query + */ + TaskQuery attachmentChannelIn(String... attachmentChannel); + + /** + * Add the values of attachment channel 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 attachmentChannel + * the attachmentChannel values of the searched-for tasks + * @return the query + */ + TaskQuery attachmentChannelLike(String... attachmentChannel); + + /** + * Add the values of reference values for exact matching to your query. + * + * @param referenceValue + * the referenceValue values of the searched for tasks + * @return the query + */ + TaskQuery attachmentReferenceValueIn(String... referenceValue); + + /** + * Add the values of reference values 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 referenceValue + * the referenceValue values of the searched-for tasks + * @return the query + */ + TaskQuery attachmentReferenceValueLike(String... referenceValue); + + + /** + * Add your received-dates to your query. + * + * @param receivedIn + * the {@link TimeInterval} within which the searched-for tasks attachment were received the last time. + * @return the query + */ + + TaskQuery attachmentReceivedWithin(TimeInterval... receivedIn); + /** * This method provides a query builder for quering the database. * @@ -715,4 +808,64 @@ public interface TaskQuery extends BaseQuery { * @return the query */ TaskQuery orderByWorkbasketId(SortDirection sortDirection); + + /** + * This method sorts the query result according to the attachment classification key. + * (Should only be used if there is one attachment per task in other case the result would be wrong.) + * + * @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 + */ + TaskQuery orderByAttachmentClassificationKey(SortDirection sortDirection); + + + /** + * This method sorts the query result according to the attachment classification id. + * (Should only be used if there is one attachment per task in other case the result would be wrong.) + * + * @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 + */ + TaskQuery orderByAttachmentClassificationId(SortDirection sortDirection); + + /** + * This method sorts the query result according to the attachment channel. + * (Should only be used if there is one attachment per task in other case the result would be wrong.) + * + * @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 + */ + TaskQuery orderByAttachmentChannel(SortDirection sortDirection); + + + + /** + * This method sorts the query result according to the attachment reference value. + * (Should only be used if there is one attachment per task in other case the result would be wrong.) + * + * @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 + */ + TaskQuery orderByAttachmentReference(SortDirection sortDirection); + + + /** + * This method sorts the query result according to the attachment received. + * (Should only be used if there is one attachment per task in other case the result would be wrong.) + * + * @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 + */ + TaskQuery orderByAttachmentReceived(SortDirection sortDirection); + } diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/TaskQueryImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskQueryImpl.java index d03dbc6d9..7b8108aea 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/TaskQueryImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskQueryImpl.java @@ -32,6 +32,7 @@ import pro.taskana.security.CurrentUserContext; public class TaskQueryImpl implements TaskQuery { private static final String LINK_TO_MAPPER = "pro.taskana.mappings.QueryMapper.queryTaskSummaries"; + private static final String LINK_TO_MAPPER_DB2 = "pro.taskana.mappings.QueryMapper.queryTaskSummariesDb2"; private static final String LINK_TO_COUNTER = "pro.taskana.mappings.QueryMapper.countQueryTasks"; private static final String LINK_TO_VALUEMAPPER = "pro.taskana.mappings.QueryMapper.queryTaskColumnValues"; private static final String TIME_INTERVAL = "TimeInterval "; @@ -108,6 +109,15 @@ public class TaskQueryImpl implements TaskQuery { private String[] custom15Like; private String[] custom16In; private String[] custom16Like; + private String[] attachmentClassificationKeyIn; + private String[] attachmentClassificationKeyLike; + private String[] attachmentClassificationIdIn; + private String[] attachmentClassificationIdLike; + private String[] attachmentChannelIn; + private String[] attachmentChannelLike; + private String[] attachmentReferenceIn; + private String[] attachmentReferenceLike; + private TimeInterval[] attachmentReceivedIn; private String[] accessIdIn; private boolean filterByAccessIdIn; private TimeInterval[] createdIn; @@ -119,6 +129,9 @@ public class TaskQueryImpl implements TaskQuery { private List orderBy; private List orderColumns; + private boolean joinWithAttachments = false; + private boolean addAttachmentColumnsToSelectClauseForOrdering = false; + TaskQueryImpl(TaskanaEngine taskanaEngine) { this.taskanaEngine = (TaskanaEngineImpl) taskanaEngine; this.taskService = (TaskServiceImpl) taskanaEngine.getTaskService(); @@ -558,9 +571,79 @@ public class TaskQueryImpl implements TaskQuery { return this; } + @Override + public TaskQuery attachmentClassificationKeyIn(String... attachmentClassificationKeys) { + joinWithAttachments = true; + this.attachmentClassificationKeyIn = attachmentClassificationKeys; + return this; + } + + @Override + public TaskQuery attachmentClassificationKeyLike(String... attachmentClassificationKey) { + joinWithAttachments = true; + this.attachmentClassificationKeyLike = attachmentClassificationKey; + return this; + } + + @Override + public TaskQuery attachmentClassificationIdIn(String... attachmentClassificationId) { + joinWithAttachments = true; + this.attachmentClassificationIdIn = attachmentClassificationId; + return this; + } + + @Override + public TaskQuery attachmentClassificationIdLike(String... attachmentClassificationId) { + joinWithAttachments = true; + this.attachmentClassificationIdLike = attachmentClassificationId; + return this; + } + + @Override + public TaskQuery attachmentChannelIn(String... attachmentChannel) { + joinWithAttachments = true; + this.attachmentChannelIn = attachmentChannel; + return this; + } + + @Override + public TaskQuery attachmentChannelLike(String... attachmentChannel) { + joinWithAttachments = true; + this.attachmentChannelLike = attachmentChannel; + return this; + } + + @Override + public TaskQuery attachmentReferenceValueIn(String... referenceValue) { + joinWithAttachments = true; + this.attachmentReferenceIn = referenceValue; + return this; + } + + @Override + public TaskQuery attachmentReferenceValueLike(String... referenceValue) { + joinWithAttachments = true; + this.attachmentReferenceLike = referenceValue; + return this; + } + + @Override + public TaskQuery attachmentReceivedWithin(TimeInterval... receivedIn) { + joinWithAttachments = true; + this.attachmentReceivedIn = receivedIn; + for (TimeInterval ti : receivedIn) { + if (!ti.isValid()) { + throw new IllegalArgumentException(TIME_INTERVAL + ti + IS_INVALID); + } + } + return this; + } + @Override public TaskQuery orderByClassificationKey(SortDirection sortDirection) { - return addOrderCriteria("CLASSIFICATION_KEY", sortDirection); + return this.taskanaEngine.sessionManager.getConfiguration().getDatabaseId().equals("db2") + ? addOrderCriteria("TCLASSIFICATION_KEY", sortDirection) + : addOrderCriteria("t.CLASSIFICATION_KEY", sortDirection); } @Override @@ -643,13 +726,53 @@ public class TaskQueryImpl implements TaskQuery { return addOrderCriteria("WORKBASKET_ID", sortDirection); } + @Override + public TaskQuery orderByAttachmentClassificationKey(SortDirection sortDirection) { + joinWithAttachments = true; + addAttachmentColumnsToSelectClauseForOrdering = true; + return this.taskanaEngine.sessionManager.getConfiguration().getDatabaseId().equals("db2") + ? addOrderCriteria("ACLASSIFICATION_KEY", sortDirection) + : addOrderCriteria("a.CLASSIFICATION_KEY", sortDirection); + } + + @Override + public TaskQuery orderByAttachmentClassificationId(SortDirection sortDirection) { + joinWithAttachments = true; + addAttachmentColumnsToSelectClauseForOrdering = true; + return this.taskanaEngine.sessionManager.getConfiguration().getDatabaseId().equals("db2") + ? addOrderCriteria("ACLASSIFICATION_ID", sortDirection) + : addOrderCriteria("a.CLASSIFICATION_ID", sortDirection); + } + + @Override + public TaskQuery orderByAttachmentChannel(SortDirection sortDirection) { + joinWithAttachments = true; + addAttachmentColumnsToSelectClauseForOrdering = true; + return addOrderCriteria("CHANNEL", sortDirection); + } + + @Override + public TaskQuery orderByAttachmentReference(SortDirection sortDirection) { + joinWithAttachments = true; + addAttachmentColumnsToSelectClauseForOrdering = true; + return addOrderCriteria("REF_VALUE", sortDirection); + } + + @Override + public TaskQuery orderByAttachmentReceived(SortDirection sortDirection) { + joinWithAttachments = true; + addAttachmentColumnsToSelectClauseForOrdering = true; + return addOrderCriteria("RECEIVED", sortDirection); + } + @Override public TaskQuery orderByNote(SortDirection sortDirection) { return addOrderCriteria("NOTE", sortDirection); } @Override - public TaskQuery orderByCustomAttribute(String number, SortDirection sortDirection) throws InvalidArgumentException { + public TaskQuery orderByCustomAttribute(String number, SortDirection sortDirection) + throws InvalidArgumentException { int num = 0; try { num = Integer.parseInt(number); @@ -737,7 +860,7 @@ public class TaskQueryImpl implements TaskQuery { checkOpenAndReadPermissionForSpecifiedWorkbaskets(); List tasks = new ArrayList<>(); setupAccessIds(); - tasks = taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this); + tasks = taskanaEngine.getSqlSession().selectList(getLinkToMapperScript(), this); if (LOGGER.isDebugEnabled()) { LOGGER.debug("mapper returned {} resulting Objects: {} ", tasks.size(), LoggerUtils.listToString(tasks)); @@ -754,6 +877,12 @@ public class TaskQueryImpl implements TaskQuery { } } + public String getLinkToMapperScript() { + return this.taskanaEngine.sessionManager.getConfiguration().getDatabaseId().equals("db2") + ? LINK_TO_MAPPER_DB2 + : LINK_TO_MAPPER; + } + private void setupAccessIds() { if (taskanaEngine.isUserInRole(TaskanaRole.ADMIN) || !filterByAccessIdIn) { this.accessIdIn = null; @@ -802,7 +931,8 @@ public class TaskQueryImpl implements TaskQuery { checkOpenAndReadPermissionForSpecifiedWorkbaskets(); setupAccessIds(); RowBounds rowBounds = new RowBounds(offset, limit); - List tasks = taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds); + List tasks = taskanaEngine.getSqlSession() + .selectList(getLinkToMapperScript(), this, rowBounds); result = taskService.augmentTaskSummariesByContainedSummaries(tasks); return result; } catch (PersistenceException e) { @@ -831,7 +961,7 @@ public class TaskQueryImpl implements TaskQuery { taskanaEngine.openConnection(); checkOpenAndReadPermissionForSpecifiedWorkbaskets(); setupAccessIds(); - TaskSummaryImpl taskSummaryImpl = taskanaEngine.getSqlSession().selectOne(LINK_TO_MAPPER, this); + TaskSummaryImpl taskSummaryImpl = taskanaEngine.getSqlSession().selectOne(getLinkToMapperScript(), this); if (taskSummaryImpl == null) { return null; } @@ -863,6 +993,23 @@ public class TaskQueryImpl implements TaskQuery { } } + public boolean isJoinWithAttachments() { + return joinWithAttachments; + } + + public void setJoinWithAttachments(boolean joinWithAttachments) { + this.joinWithAttachments = joinWithAttachments; + } + + public boolean isAddAttachmentColumnsToSelectClauseForOrdering() { + return addAttachmentColumnsToSelectClauseForOrdering; + } + + public void setAddAttachmentColumnsToSelectClauseForOrdering( + boolean addAttachmentColumnsToSelectClauseForOrdering) { + this.addAttachmentColumnsToSelectClauseForOrdering = addAttachmentColumnsToSelectClauseForOrdering; + } + private void checkOpenAndReadPermissionForSpecifiedWorkbaskets() { if (taskanaEngine.isUserInRole(TaskanaRole.ADMIN)) { LOGGER.debug("Skipping permissions check since user is in role ADMIN."); @@ -1221,6 +1368,78 @@ public class TaskQueryImpl implements TaskQuery { return columnName; } + public String[] getAttachmentClassificationKeyIn() { + return attachmentClassificationKeyIn; + } + + public void setAttachmentClassificationKeyIn(String[] attachmentClassificationKeyIn) { + this.attachmentClassificationKeyIn = attachmentClassificationKeyIn; + } + + public String[] getAttachmentClassificationKeyLike() { + return attachmentClassificationKeyLike; + } + + public void setAttachmentClassificationKeyLike(String[] attachmentClassificationKeyLike) { + this.attachmentClassificationKeyLike = attachmentClassificationKeyLike; + } + + public String[] getAttachmentClassificationIdIn() { + return attachmentClassificationIdIn; + } + + public void setAttachmentClassificationIdIn(String[] attachmentClassificationIdIn) { + this.attachmentClassificationIdIn = attachmentClassificationIdIn; + } + + public String[] getAttachmentClassificationIdLike() { + return attachmentClassificationIdLike; + } + + public void setAttachmentClassificationIdLike(String[] attachmentclassificationIdLike) { + this.attachmentClassificationIdLike = attachmentclassificationIdLike; + } + + public String[] getAttachmentChannelIn() { + return attachmentChannelIn; + } + + public void setAttachmentChannelIn(String[] attachmentChannelIn) { + this.attachmentChannelIn = attachmentChannelIn; + } + + public String[] getAttachmentChannelLike() { + return attachmentChannelLike; + } + + public void setAttachmentChannelLike(String[] attachmentChannelLike) { + this.attachmentChannelLike = attachmentChannelLike; + } + + public String[] getAttachmentReferenceIn() { + return attachmentReferenceIn; + } + + public void setAttachmentReferenceIn(String[] attachmentReferenceIn) { + this.attachmentReferenceIn = attachmentReferenceIn; + } + + public String[] getAttachmentReferenceLike() { + return attachmentReferenceLike; + } + + public void setAttachmentReferenceLike(String[] attachmentReferenceLike) { + this.attachmentReferenceLike = attachmentReferenceLike; + } + + public TimeInterval[] getAttachmentReceivedIn() { + return attachmentReceivedIn; + } + + public void setAttachmentReceivedIn(TimeInterval[] attachmentReceivedIn) { + this.attachmentReceivedIn = attachmentReceivedIn; + } + private TaskQuery addOrderCriteria(String columnName, SortDirection sortDirection) { String orderByDirection = " ASC"; if (sortDirection != null && SortDirection.DESCENDING.equals(sortDirection)) { diff --git a/lib/taskana-core/src/main/java/pro/taskana/mappings/AttachmentMapper.java b/lib/taskana-core/src/main/java/pro/taskana/mappings/AttachmentMapper.java index fea84bdc8..748accab4 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/mappings/AttachmentMapper.java +++ b/lib/taskana-core/src/main/java/pro/taskana/mappings/AttachmentMapper.java @@ -74,10 +74,10 @@ public interface AttachmentMapper { }) AttachmentImpl getAttachment(@Param("attachmentId") String attachmentId); - @Select("") @@ -96,7 +96,7 @@ public interface AttachmentMapper { @Result(property = "channel", column = "CHANNEL"), @Result(property = "received", column = "RECEIVED") }) - List findAttachmentSummariesByTaskIds(String[] taskIds); + List findAttachmentSummariesByTaskIds(@Param("taskIds") String[] taskIds); @Delete("DELETE FROM ATTACHMENT WHERE ID=#{attachmentId}") void deleteAttachment(@Param("attachmentId") String attachmentId); diff --git a/lib/taskana-core/src/main/java/pro/taskana/mappings/QueryMapper.java b/lib/taskana-core/src/main/java/pro/taskana/mappings/QueryMapper.java index 1d69f2fab..8e8236744 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/mappings/QueryMapper.java +++ b/lib/taskana-core/src/main/java/pro/taskana/mappings/QueryMapper.java @@ -28,123 +28,18 @@ public interface QueryMapper { String WORKBASKET_FINDSUMMARYBYKEY = "pro.taskana.mappings.WorkbasketMapper.findSummaryByKey"; @Select("") @Results(value = {@Result(property = "taskId", column = "ID"), @Result(property = "created", column = "CREATED"), @@ -274,48 +176,259 @@ public interface QueryMapper { @Result(property = "custom16", column = "CUSTOM_16")}) List queryTaskSummaries(TaskQueryImpl taskQuery); - @Select("") + @Results(value = {@Result(property = "taskId", column = "ID"), + @Result(property = "created", column = "CREATED"), + @Result(property = "claimed", column = "CLAIMED"), + @Result(property = "completed", column = "COMPLETED"), + @Result(property = "modified", column = "MODIFIED"), + @Result(property = "planned", column = "PLANNED"), + @Result(property = "due", column = "DUE"), + @Result(property = "name", column = "NAME"), + @Result(property = "creator", column = "CREATOR"), + @Result(property = "note", column = "NOTE"), + @Result(property = "priority", column = "PRIORITY"), + @Result(property = "state", column = "STATE"), + @Result(property = "workbasketSummaryImpl.domain", column = "DOMAIN"), + @Result(property = "workbasketSummaryImpl.key", column = "WORKBASKET_KEY"), + @Result(property = "workbasketSummaryImpl.id", column = "WORKBASKET_ID"), + @Result(property = "classificationSummaryImpl.key", column = "CLASSIFICATION_KEY"), + @Result(property = "classificationSummaryImpl.id", column = "CLASSIFICATION_ID"), + @Result(property = "classificationSummaryImpl.domain", column = "DOMAIN"), + @Result(property = "classificationSummaryImpl.category", column = "CLASSIFICATION_CATEGORY"), + @Result(property = "businessProcessId", column = "BUSINESS_PROCESS_ID"), + @Result(property = "parentBusinessProcessId", column = "PARENT_BUSINESS_PROCESS_ID"), + @Result(property = "owner", column = "OWNER"), + @Result(property = "primaryObjRef.company", column = "POR_COMPANY"), + @Result(property = "primaryObjRef.system", column = "POR_SYSTEM"), + @Result(property = "primaryObjRef.systemInstance", column = "POR_INSTANCE"), + @Result(property = "primaryObjRef.type", column = "POR_TYPE"), + @Result(property = "primaryObjRef.value", column = "POR_VALUE"), + @Result(property = "isRead", column = "IS_READ"), + @Result(property = "isTransferred", column = "IS_TRANSFERRED"), + @Result(property = "custom1", column = "CUSTOM_1"), + @Result(property = "custom2", column = "CUSTOM_2"), + @Result(property = "custom3", column = "CUSTOM_3"), + @Result(property = "custom4", column = "CUSTOM_4"), + @Result(property = "custom5", column = "CUSTOM_5"), + @Result(property = "custom6", column = "CUSTOM_6"), + @Result(property = "custom7", column = "CUSTOM_7"), + @Result(property = "custom8", column = "CUSTOM_8"), + @Result(property = "custom9", column = "CUSTOM_9"), + @Result(property = "custom10", column = "CUSTOM_10"), + @Result(property = "custom11", column = "CUSTOM_11"), + @Result(property = "custom12", column = "CUSTOM_12"), + @Result(property = "custom13", column = "CUSTOM_13"), + @Result(property = "custom14", column = "CUSTOM_14"), + @Result(property = "custom15", column = "CUSTOM_15"), + @Result(property = "custom16", column = "CUSTOM_16")}) + List queryTaskSummariesDb2(TaskQueryImpl taskQuery); + + @Select( + "") @Results({@Result(property = "id", column = "ID"), @Result(property = "key", column = "KEY"), @Result(property = "category", column = "CATEGORY"), @@ -499,7 +612,10 @@ public interface QueryMapper { @Select("") List queryTaskColumnValues(TaskQueryImpl taskQuery); @@ -1006,7 +1176,6 @@ public interface QueryMapper { + "AND w.CUSTOM_1 IN(#{item}) " + "AND (UPPER(w.CUSTOM_1) LIKE #{item}) " + "AND w.CUSTOM_2 IN(#{item}) " - + "AND (UPPER(w.CUSTOM_2) LIKE #{item}) " + "AND w.CUSTOM_3 IN(#{item}) " + "AND (UPPER(w.CUSTOM_3) LIKE #{item}) " + "AND w.CUSTOM_4 IN(#{item}) " diff --git a/lib/taskana-core/src/test/java/acceptance/task/QueryTasksAccTest.java b/lib/taskana-core/src/test/java/acceptance/task/QueryTasksAccTest.java index 3942f2d07..641e09b06 100644 --- a/lib/taskana-core/src/test/java/acceptance/task/QueryTasksAccTest.java +++ b/lib/taskana-core/src/test/java/acceptance/task/QueryTasksAccTest.java @@ -23,6 +23,7 @@ import pro.taskana.Task; import pro.taskana.TaskQuery; import pro.taskana.TaskService; import pro.taskana.TaskSummary; +import pro.taskana.TimeInterval; import pro.taskana.exceptions.AttachmentPersistenceException; import pro.taskana.exceptions.ClassificationNotFoundException; import pro.taskana.exceptions.ConcurrencyException; @@ -70,6 +71,37 @@ public class QueryTasksAccTest extends AbstractAccTest { assertEquals(3, columnValueList.size()); } + + @WithAccessId( + userName = "teamlead_1", + groupNames = {"admin"}) + @Test + public void testQueryTaskValuesForColumnNameOnAttachments() { + TaskService taskService = taskanaEngine.getTaskService(); + List columnValueList = taskService.createTaskQuery() + .attachmentReferenceValueIn("val4") + .listValues("CHANNEL", null); + assertNotNull(columnValueList); + assertEquals(2, columnValueList.size()); + + columnValueList = taskService.createTaskQuery() + .listValues("REF_VALUE", null); + assertNotNull(columnValueList); + assertEquals(6, columnValueList.size()); + + columnValueList = taskService.createTaskQuery() + .orderByAttachmentClassificationId(desc) + .listValues("a.CLASSIFICATION_ID", null); + assertNotNull(columnValueList); + assertEquals(11, columnValueList.size()); + + columnValueList = taskService.createTaskQuery() + .orderByClassificationKey(desc) + .listValues("t.CLASSIFICATION_KEY", null); + assertNotNull(columnValueList); + assertEquals(7, columnValueList.size()); + } + @WithAccessId( userName = "teamlead_1", groupNames = {"group_1", "group_2"}) @@ -166,8 +198,8 @@ public class QueryTasksAccTest extends AbstractAccTest { assertThat(result3.size(), equalTo(70)); List result4 = taskService.createTaskQuery() - .classificationKeyNotIn("L1050", "L1060", "T2100") - .list(); + .classificationKeyNotIn("L1050", "L1060", "T2100") + .list(); assertThat(result4.size(), equalTo(6)); } @@ -561,8 +593,8 @@ public class QueryTasksAccTest extends AbstractAccTest { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .customAttributeLike("11", "%") - .list(); + .customAttributeLike("11", "%") + .list(); assertThat(results.size(), equalTo(3)); String[] ids = results.stream() @@ -577,8 +609,8 @@ public class QueryTasksAccTest extends AbstractAccTest { .collect(Collectors.toList()) .toArray(new String[0]); List results2 = taskService.createTaskQuery() - .customAttributeIn("11", ids) - .list(); + .customAttributeIn("11", ids) + .list(); assertThat(results2.size(), equalTo(3)); } @@ -591,8 +623,8 @@ public class QueryTasksAccTest extends AbstractAccTest { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .customAttributeLike("12", "%") - .list(); + .customAttributeLike("12", "%") + .list(); assertThat(results.size(), equalTo(3)); String[] ids = results.stream() @@ -607,8 +639,8 @@ public class QueryTasksAccTest extends AbstractAccTest { .collect(Collectors.toList()) .toArray(new String[0]); List results2 = taskService.createTaskQuery() - .customAttributeIn("12", ids) - .list(); + .customAttributeIn("12", ids) + .list(); assertThat(results2.size(), equalTo(3)); } @@ -621,8 +653,8 @@ public class QueryTasksAccTest extends AbstractAccTest { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .customAttributeLike("13", "%") - .list(); + .customAttributeLike("13", "%") + .list(); assertThat(results.size(), equalTo(3)); String[] ids = results.stream() @@ -637,8 +669,8 @@ public class QueryTasksAccTest extends AbstractAccTest { .collect(Collectors.toList()) .toArray(new String[0]); List results2 = taskService.createTaskQuery() - .customAttributeIn("13", ids) - .list(); + .customAttributeIn("13", ids) + .list(); assertThat(results2.size(), equalTo(3)); } @@ -651,8 +683,8 @@ public class QueryTasksAccTest extends AbstractAccTest { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .customAttributeLike("14", "%") - .list(); + .customAttributeLike("14", "%") + .list(); assertThat(results.size(), equalTo(47)); String[] ids = results.stream() @@ -667,8 +699,8 @@ public class QueryTasksAccTest extends AbstractAccTest { .collect(Collectors.toList()) .toArray(new String[0]); List results2 = taskService.createTaskQuery() - .customAttributeIn("14", ids) - .list(); + .customAttributeIn("14", ids) + .list(); assertThat(results2.size(), equalTo(47)); } @@ -681,8 +713,8 @@ public class QueryTasksAccTest extends AbstractAccTest { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .customAttributeLike("15", "%") - .list(); + .customAttributeLike("15", "%") + .list(); assertThat(results.size(), equalTo(3)); String[] ids = results.stream() @@ -697,8 +729,8 @@ public class QueryTasksAccTest extends AbstractAccTest { .collect(Collectors.toList()) .toArray(new String[0]); List results2 = taskService.createTaskQuery() - .customAttributeIn("15", ids) - .list(); + .customAttributeIn("15", ids) + .list(); assertThat(results2.size(), equalTo(3)); } @@ -711,8 +743,8 @@ public class QueryTasksAccTest extends AbstractAccTest { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .customAttributeLike("16", "%") - .list(); + .customAttributeLike("16", "%") + .list(); assertThat(results.size(), equalTo(3)); String[] ids = results.stream() @@ -727,8 +759,8 @@ public class QueryTasksAccTest extends AbstractAccTest { .collect(Collectors.toList()) .toArray(new String[0]); List results2 = taskService.createTaskQuery() - .customAttributeIn("16", ids) - .list(); + .customAttributeIn("16", ids) + .list(); assertThat(results2.size(), equalTo(3)); } @@ -823,8 +855,8 @@ public class QueryTasksAccTest extends AbstractAccTest { public void testQueryForCreatorIn() { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .creatorIn("creator_user_id2", "creator_user_id3") - .list(); + .creatorIn("creator_user_id2", "creator_user_id3") + .list(); assertEquals(4, results.size()); } @@ -834,8 +866,8 @@ public class QueryTasksAccTest extends AbstractAccTest { public void testQueryForCreatorLike() { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .creatorLike("ersTeLlEr%") - .list(); + .creatorLike("ersTeLlEr%") + .list(); assertEquals(3, results.size()); } @@ -845,8 +877,8 @@ public class QueryTasksAccTest extends AbstractAccTest { public void testQueryForNoteLike() { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .noteLike("Some%") - .list(); + .noteLike("Some%") + .list(); assertEquals(6, results.size()); } @@ -856,8 +888,8 @@ public class QueryTasksAccTest extends AbstractAccTest { public void testQueryForClassificationCategoryIn() { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .classificationCategoryIn("MANUAL", "AUTOMATIC") - .list(); + .classificationCategoryIn("MANUAL", "AUTOMATIC") + .list(); assertEquals(4, results.size()); } @@ -867,8 +899,8 @@ public class QueryTasksAccTest extends AbstractAccTest { public void testQueryForClassificationCategoryLike() { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .classificationCategoryLike("AUTO%") - .list(); + .classificationCategoryLike("AUTO%") + .list(); assertEquals(1, results.size()); } @@ -878,8 +910,8 @@ public class QueryTasksAccTest extends AbstractAccTest { public void testQueryForPrimaryObjectReferenceCompanyLike() { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .primaryObjectReferenceCompanyLike("My%") - .list(); + .primaryObjectReferenceCompanyLike("My%") + .list(); assertEquals(6, results.size()); } @@ -889,8 +921,8 @@ public class QueryTasksAccTest extends AbstractAccTest { public void testQueryForPrimaryObjectReferenceSystemLike() { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .primaryObjectReferenceSystemLike("My%") - .list(); + .primaryObjectReferenceSystemLike("My%") + .list(); assertEquals(6, results.size()); } @@ -900,8 +932,8 @@ public class QueryTasksAccTest extends AbstractAccTest { public void testQueryForPrimaryObjectReferenceSystemInstanceLike() { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .primaryObjectReferenceSystemInstanceLike("My%") - .list(); + .primaryObjectReferenceSystemInstanceLike("My%") + .list(); assertEquals(6, results.size()); } @@ -911,8 +943,8 @@ public class QueryTasksAccTest extends AbstractAccTest { public void testQueryForPrimaryObjectReferenceTypeLike() { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .primaryObjectReferenceTypeLike("My%") - .list(); + .primaryObjectReferenceTypeLike("My%") + .list(); assertEquals(6, results.size()); } @@ -922,8 +954,8 @@ public class QueryTasksAccTest extends AbstractAccTest { public void testQueryForReadEquals() { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .readEquals(true) - .list(); + .readEquals(true) + .list(); assertEquals(25, results.size()); } @@ -933,8 +965,8 @@ public class QueryTasksAccTest extends AbstractAccTest { public void testQueryForTransferredEquals() { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .transferredEquals(true) - .list(); + .transferredEquals(true) + .list(); assertEquals(2, results.size()); } @@ -944,8 +976,8 @@ public class QueryTasksAccTest extends AbstractAccTest { public void testQueryForBusinessProcessIdIn() { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .businessProcessIdIn("PI_0000000000003", "BPI21") - .list(); + .businessProcessIdIn("PI_0000000000003", "BPI21") + .list(); assertEquals(8, results.size()); } @@ -955,19 +987,98 @@ public class QueryTasksAccTest extends AbstractAccTest { public void testQueryForBusinessProcessIdLike() { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .businessProcessIdLike("pI_%") - .list(); + .businessProcessIdLike("pI_%") + .list(); assertEquals(66, results.size()); } + @WithAccessId( + userName = "admin") + @Test + public void testQueryForAttachmentClassificationKeyIn() { + TaskService taskService = taskanaEngine.getTaskService(); + List results = taskService.createTaskQuery() + .attachmentClassificationKeyIn("L110102") + .list(); + assertEquals(1, results.size()); + assertEquals("TKI:000000000000000000000000000000000002", + results.get(0).getTaskId()); + } + + @WithAccessId( + userName = "admin") + @Test + public void testQueryForAttachmentClassificationKeyLike() { + TaskService taskService = taskanaEngine.getTaskService(); + List results = taskService.createTaskQuery() + .attachmentClassificationKeyLike("%10102") + .list(); + assertEquals(1, results.size()); + assertEquals("TKI:000000000000000000000000000000000002", + results.get(0).getTaskId()); + } + + @WithAccessId( + userName = "admin") + @Test + public void testQueryForAttachmentclassificationIdIn() { + TaskService taskService = taskanaEngine.getTaskService(); + List results = taskService.createTaskQuery() + .attachmentClassificationIdIn("CLI:000000000000000000000000000000000002") + .list(); + assertEquals(1, results.size()); + assertEquals("TKI:000000000000000000000000000000000001", + results.get(0).getTaskId()); + } + + @WithAccessId( + userName = "admin") + @Test + public void testQueryForAttachmentChannelLike() { + TaskService taskService = taskanaEngine.getTaskService(); + List results = taskService.createTaskQuery() + .attachmentChannelLike("%6") + .list(); + assertEquals(2, results.size()); + } + + @WithAccessId( + userName = "admin") + @Test + public void testQueryForAttachmentReferenceIn() { + TaskService taskService = taskanaEngine.getTaskService(); + List results = taskService.createTaskQuery() + .attachmentReferenceValueIn("val4") + .list(); + assertEquals(6, results.size()); + assertEquals(1, results.get(5).getAttachmentSummaries().size()); + } + + @WithAccessId( + userName = "admin") + @Test + public void testQueryForAttachmentReceivedIn() { + TaskService taskService = taskanaEngine.getTaskService(); + TimeInterval interval = new TimeInterval( + getInstant("2018-01-30T12:00:00"), + getInstant("2018-01-31T12:00:00")); + List results = taskService.createTaskQuery() + .attachmentReceivedWithin(interval) + .orderByWorkbasketId(desc) + .list(); + assertEquals(2, results.size()); + assertEquals("TKI:000000000000000000000000000000000001", results.get(0).getTaskId()); + assertEquals("TKI:000000000000000000000000000000000011", results.get(1).getTaskId()); + } + @WithAccessId( userName = "admin") @Test public void testQueryForOrderByCreatorDesc() { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .orderByCreator(desc) - .list(); + .orderByCreator(desc) + .list(); assertEquals("user_1_1", results.get(0).getCreator()); } @@ -977,10 +1088,10 @@ public class QueryTasksAccTest extends AbstractAccTest { public void testQueryForOrderByWorkbasketIdDesc() { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .orderByWorkbasketId(desc) - .list(); + .orderByWorkbasketId(desc) + .list(); assertEquals("WBI:100000000000000000000000000000000015", - results.get(0).getWorkbasketSummary().getId()); + results.get(0).getWorkbasketSummary().getId()); } @WithAccessId( @@ -989,8 +1100,8 @@ public class QueryTasksAccTest extends AbstractAccTest { public void testQueryForOrderByCustom1Asc() throws InvalidArgumentException { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .orderByCustomAttribute("1", asc) - .list(); + .orderByCustomAttribute("1", asc) + .list(); assertEquals("custom1", results.get(0).getCustomAttribute("1")); } @@ -1000,8 +1111,8 @@ public class QueryTasksAccTest extends AbstractAccTest { public void testQueryForOrderByCustom2Desc() throws InvalidArgumentException { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .orderByCustomAttribute("2", desc) - .list(); + .orderByCustomAttribute("2", desc) + .list(); assertEquals("custom2", results.get(0).getCustomAttribute("2")); } @@ -1011,8 +1122,8 @@ public class QueryTasksAccTest extends AbstractAccTest { public void testQueryForOrderByCustom3Asc() throws InvalidArgumentException { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .orderByCustomAttribute("3", asc) - .list(); + .orderByCustomAttribute("3", asc) + .list(); assertEquals("custom3", results.get(0).getCustomAttribute("3")); } @@ -1022,19 +1133,19 @@ public class QueryTasksAccTest extends AbstractAccTest { public void testQueryForOrderByCustom4Desc() throws InvalidArgumentException { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .orderByCustomAttribute("4", desc) - .list(); + .orderByCustomAttribute("4", desc) + .list(); assertEquals("rty", results.get(0).getCustomAttribute("4")); } @WithAccessId( userName = "admin") @Test - public void testQueryForOrderByCustom5Asc() throws InvalidArgumentException { + public void testQueryForOrderByCustom5Asc() throws InvalidArgumentException { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .orderByCustomAttribute("5", asc) - .list(); + .orderByCustomAttribute("5", asc) + .list(); assertEquals("al", results.get(0).getCustomAttribute("5")); } @@ -1044,30 +1155,30 @@ public class QueryTasksAccTest extends AbstractAccTest { public void testQueryForOrderByCustom6Desc() throws InvalidArgumentException { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .orderByCustomAttribute("6", desc) - .list(); + .orderByCustomAttribute("6", desc) + .list(); assertEquals("vvg", results.get(0).getCustomAttribute("6")); } @WithAccessId( userName = "admin") @Test - public void testQueryForOrderByCustom7Asc() throws InvalidArgumentException { + public void testQueryForOrderByCustom7Asc() throws InvalidArgumentException { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .orderByCustomAttribute("7", asc) - .list(); + .orderByCustomAttribute("7", asc) + .list(); assertEquals("custom7", results.get(0).getCustomAttribute("7")); } @WithAccessId( - userName = "admin") + userName = "admin") @Test - public void testQueryForOrderByCustom8Desc() throws InvalidArgumentException { + public void testQueryForOrderByCustom8Desc() throws InvalidArgumentException { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .orderByCustomAttribute("8", desc) - .list(); + .orderByCustomAttribute("8", desc) + .list(); assertEquals("lnp", results.get(0).getCustomAttribute("8")); } @@ -1077,96 +1188,213 @@ public class QueryTasksAccTest extends AbstractAccTest { public void testQueryForOrderByCustom9Asc() throws InvalidArgumentException { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .orderByCustomAttribute("9", asc) - .list(); + .orderByCustomAttribute("9", asc) + .list(); assertEquals("bbq", results.get(0).getCustomAttribute("9")); } @WithAccessId( - userName = "admin") + userName = "admin") @Test public void testQueryForOrderByCustom10Desc() throws InvalidArgumentException { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .orderByCustomAttribute("10", desc) - .list(); + .orderByCustomAttribute("10", desc) + .list(); assertEquals("ert", results.get(0).getCustomAttribute("10")); } @WithAccessId( - userName = "admin") + userName = "admin") @Test public void testQueryForOrderByCustom11Desc() throws InvalidArgumentException { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .orderByCustomAttribute("11", desc) - .list(); + .orderByCustomAttribute("11", desc) + .list(); assertEquals("ert", results.get(0).getCustomAttribute("11")); } @WithAccessId( - userName = "admin") + userName = "admin") @Test public void testQueryForOrderByCustom12Asc() throws InvalidArgumentException { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .orderByCustomAttribute("12", asc) - .list(); + .orderByCustomAttribute("12", asc) + .list(); assertEquals("custom12", results.get(0).getCustomAttribute("12")); } @WithAccessId( - userName = "admin") + userName = "admin") @Test public void testQueryForOrderByCustom13Desc() throws InvalidArgumentException { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .orderByCustomAttribute("13", desc) - .list(); + .orderByCustomAttribute("13", desc) + .list(); assertEquals("ert", results.get(0).getCustomAttribute("13")); } @WithAccessId( - userName = "admin") + userName = "admin") @Test public void testQueryForOrderByCustom14Asc() throws InvalidArgumentException { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .orderByCustomAttribute("14", asc) - .list(); + .orderByCustomAttribute("14", asc) + .list(); assertEquals("abc", results.get(0).getCustomAttribute("14")); } @WithAccessId( - userName = "admin") + userName = "admin") @Test public void testQueryForOrderByCustom15Desc() throws InvalidArgumentException { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .orderByCustomAttribute("15", desc) - .list(); + .orderByCustomAttribute("15", desc) + .list(); assertEquals("ert", results.get(0).getCustomAttribute("15")); } @WithAccessId( - userName = "admin") + userName = "admin") @Test public void testQueryForOrderByCustom16Asc() throws InvalidArgumentException { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .orderByCustomAttribute("16", asc) - .list(); + .orderByCustomAttribute("16", asc) + .list(); assertEquals("custom16", results.get(0).getCustomAttribute("16")); } @WithAccessId( - userName = "admin") + userName = "admin") @Test public void testQueryForOrderWithDirectionNull() { TaskService taskService = taskanaEngine.getTaskService(); List results = taskService.createTaskQuery() - .orderByPrimaryObjectReferenceSystemInstance(null) - .list(); + .orderByPrimaryObjectReferenceSystemInstance(null) + .list(); assertEquals("00", results.get(0).getPrimaryObjRef().getSystemInstance()); } + + @WithAccessId( + userName = "admin") + @Test + public void testQueryForOrderByAttachmentClassificationIdAsc() { + TaskService taskService = taskanaEngine.getTaskService(); + List results = taskService.createTaskQuery() + .idIn("TKI:000000000000000000000000000000000010", "TKI:000000000000000000000000000000000011", + "TKI:000000000000000000000000000000000012") + .orderByAttachmentClassificationId(asc) + .list(); + assertEquals("TKI:000000000000000000000000000000000011", results.get(0).getTaskId()); + assertEquals("TKI:000000000000000000000000000000000010", results.get(results.size() - 1).getTaskId()); + } + + @WithAccessId( + userName = "admin") + @Test + public void testQueryForOrderByAttachmentClassificationIdDesc() { + TaskService taskService = taskanaEngine.getTaskService(); + List results = taskService.createTaskQuery() + .idIn("TKI:000000000000000000000000000000000010", "TKI:000000000000000000000000000000000011", + "TKI:000000000000000000000000000000000012") + .orderByAttachmentClassificationId(desc) + .list(); + assertEquals("TKI:000000000000000000000000000000000010", results.get(0).getTaskId()); + assertEquals("TKI:000000000000000000000000000000000011", results.get(results.size() - 1).getTaskId()); + } + + @WithAccessId( + userName = "admin") + @Test + public void testQueryForOrderByAttachmentClassificationKeyAsc() { + + TaskService taskService = taskanaEngine.getTaskService(); + List results = taskService.createTaskQuery() + .idIn("TKI:000000000000000000000000000000000010", "TKI:000000000000000000000000000000000011", + "TKI:000000000000000000000000000000000012") + .orderByAttachmentClassificationKey(asc) + .list(); + + assertEquals("TKI:000000000000000000000000000000000010", results.get(0).getTaskId()); + assertEquals("TKI:000000000000000000000000000000000012", results.get(results.size() - 1).getTaskId()); + } + + @WithAccessId( + userName = "admin") + @Test + public void testQueryForOrderByAttachmentClassificationKeyDesc() { + + TaskService taskService = taskanaEngine.getTaskService(); + List results = taskService.createTaskQuery() + .idIn("TKI:000000000000000000000000000000000010", "TKI:000000000000000000000000000000000011", + "TKI:000000000000000000000000000000000012") + .orderByAttachmentClassificationKey(desc) + .list(); + + assertEquals("TKI:000000000000000000000000000000000012", results.get(0).getTaskId()); + assertEquals("TKI:000000000000000000000000000000000010", results.get(results.size() - 1).getTaskId()); + } + + @WithAccessId( + userName = "admin") + @Test + public void testQueryForOrderByAttachmentRefValueDesc() { + + TaskService taskService = taskanaEngine.getTaskService(); + List results = taskService.createTaskQuery() + .idIn("TKI:000000000000000000000000000000000010", "TKI:000000000000000000000000000000000011", + "TKI:000000000000000000000000000000000012") + .orderByAttachmentReference(desc) + .list(); + + assertEquals("TKI:000000000000000000000000000000000012", results.get(0).getTaskId()); + assertEquals("TKI:000000000000000000000000000000000010", results.get(results.size() - 1).getTaskId()); + } + + @WithAccessId( + userName = "admin") + @Test + public void testQueryForOrderByAttachmentChannelAscAndReferenceDesc() { + + TaskService taskService = taskanaEngine.getTaskService(); + List results = taskService.createTaskQuery() + .idIn("TKI:000000000000000000000000000000000010", "TKI:000000000000000000000000000000000011", + "TKI:000000000000000000000000000000000012") + .orderByAttachmentChannel(asc) + .orderByAttachmentReference(desc) + .list(); + + assertEquals("TKI:000000000000000000000000000000000012", results.get(0).getTaskId()); + assertEquals("TKI:000000000000000000000000000000000010", results.get(results.size() - 1).getTaskId()); + } + + @WithAccessId( + userName = "admin") + @Test + public void testQueryForAttachmentLikeCHAndOrderByClassificationKeyDescAndAsc() { + + TaskService taskService = taskanaEngine.getTaskService(); + List results = taskService.createTaskQuery() + .attachmentChannelLike("CH%") + .orderByClassificationKey(desc) + .list(); + + assertEquals("T2000", results.get(0).getClassificationSummary().getKey()); + assertEquals("L1050", results.get(results.size() - 1).getClassificationSummary().getKey()); + + results = taskService.createTaskQuery() + .attachmentChannelLike("CH%") + .orderByClassificationKey(asc) + .list(); + + assertEquals("L1050", results.get(0).getClassificationSummary().getKey()); + assertEquals("T2000", results.get(results.size() - 1).getClassificationSummary().getKey()); + } + } diff --git a/lib/taskana-core/src/test/java/acceptance/task/QueryTasksWithPaginationAccTest.java b/lib/taskana-core/src/test/java/acceptance/task/QueryTasksWithPaginationAccTest.java index c7acdd24f..d79630e71 100644 --- a/lib/taskana-core/src/test/java/acceptance/task/QueryTasksWithPaginationAccTest.java +++ b/lib/taskana-core/src/test/java/acceptance/task/QueryTasksWithPaginationAccTest.java @@ -181,4 +181,16 @@ public class QueryTasksWithPaginationAccTest extends AbstractAccTest { assertThat(count, equalTo(22L)); } + @WithAccessId( + userName = "teamlead_1", + groupNames = {"group_1"}) + @Test + public void testCountOfTaskQueryWithAttachmentChannelFilter() { + TaskService taskService = taskanaEngine.getTaskService(); + long count = taskService.createTaskQuery() + .attachmentChannelIn("ch6") + .count(); + assertThat(count, equalTo(2L)); + } + } diff --git a/lib/taskana-core/src/test/java/pro/taskana/impl/TaskQueryImplTest.java b/lib/taskana-core/src/test/java/pro/taskana/impl/TaskQueryImplTest.java index fdee0a931..5d1d12373 100644 --- a/lib/taskana-core/src/test/java/pro/taskana/impl/TaskQueryImplTest.java +++ b/lib/taskana-core/src/test/java/pro/taskana/impl/TaskQueryImplTest.java @@ -7,7 +7,9 @@ import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.List; +import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionManager; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -36,6 +38,9 @@ public class TaskQueryImplTest { @Mock private SqlSession sqlSession; + @Mock + private SqlSessionManager sqlSessionManager; + @Mock ClassificationServiceImpl classificationService; @@ -45,6 +50,12 @@ public class TaskQueryImplTest { @Before public void setup() { when(taskanaEngine.getTaskService()).thenReturn(taskServiceMock); + + Configuration configuration = new org.apache.ibatis.session.Configuration(); + configuration.setDatabaseId("h2"); + this.taskanaEngine.sessionManager = sqlSessionManager; + when(taskanaEngine.sessionManager.getConfiguration()).thenReturn(configuration); + taskQueryImpl = new TaskQueryImpl(taskanaEngine); } diff --git a/lib/taskana-core/src/test/resources/sql/attachment.sql b/lib/taskana-core/src/test/resources/sql/attachment.sql index 7bbb67746..8a98deb73 100644 --- a/lib/taskana-core/src/test/resources/sql/attachment.sql +++ b/lib/taskana-core/src/test/resources/sql/attachment.sql @@ -1,16 +1,19 @@ -- ATTACHMENT TABLE (ID , task_ID , CREATED , MODIFIED , classif key, classif Id , refCompany, ref sys, ref inst,ref type, ref val, channel,received, custAtts) INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000000','TKI:000000000000000000000000000000000000', '2018-01-29 15:55:00', '2018-01-30 15:55:00', 'L1050' , 'CLI:100000000000000000000000000000000003', 'novatec' , 'novasys', 'nvinst', 'typ1', 'val1', 'ch1', null, null); -INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000001','TKI:000000000000000000000000000000000001', '2018-01-29 15:55:01', '2018-01-30 15:55:00', 'L10303' , 'CLI:000000000000000000000000000000000002', 'novatec' , 'novasys', 'nvinst', 'typ1', 'val1', 'ch1', null, null); -INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000002','TKI:000000000000000000000000000000000001', '2018-01-29 15:55:02', '2018-01-30 15:55:00', 'L1050' , 'CLI:000000000000000000000000000000000003', 'novatec' , 'novasys', 'nvinst', 'typ1', 'val1', 'ch1', null, null); -INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000003','TKI:000000000000000000000000000000000002', '2018-01-29 15:55:03', null , 'L11010' , 'CLI:000000000000000000000000000000000004', 'novatec' , 'novasys', 'nvinst', 'typ1', 'val1', 'ch1', null, null); -INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000004','TKI:000000000000000000000000000000000002', '2018-01-29 15:55:04', null , 'L110102' , 'CLI:000000000000000000000000000000000005', 'novatec' , 'novasys', 'nvinst', 'typ1', 'val1', 'ch1', null, null); -INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000005','TKI:000000000000000000000000000000000002', '2018-01-29 15:55:05', null , 'L110105' , 'CLI:000000000000000000000000000000000006', 'novatec' , 'novasys', 'nvinst', 'typ1', 'val1', 'ch1', null, null); -INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000006','TKI:000000000000000000000000000000000002', '2018-01-29 15:55:06', null , 'L110107' , 'CLI:000000000000000000000000000000000007', 'novatec' , 'novasys', 'nvinst', 'typ1', 'val1', 'ch1', null, null); -INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000007','TKI:000000000000000000000000000000000002', '2018-01-29 15:55:07', null , 'L12010' , 'CLI:100000000000000000000000000000000008', 'novatec' , 'novasys', 'nvinst', 'typ1', 'val1', 'ch1', null, null); -INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000008','TKI:000000000000000000000000000000000008', '2018-01-29 15:55:08', null , 'L140101' , 'CLI:000000000000000000000000000000000009', 'novatec' , 'novasys', 'nvinst', 'typ1', 'val1', 'ch1', null, null); -INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000009','TKI:000000000000000000000000000000000000', '2018-01-29 15:55:00', '2018-01-30 15:55:00', 'L1050' , 'CLI:100000000000000000000000000000000003', 'novatec' , 'novasys', 'nvinst', 'typ1', 'val1', 'ch1', null, null); -INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000010','TKI:000000000000000000000000000000000053', '2018-01-29 15:55:00', '2018-01-30 15:55:00', 'L1050' , 'CLI:100000000000000000000000000000000003', 'novatec' , 'novasys', 'nvinst', 'typ1', 'val1', 'ch1', null, null); -INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000011','TKI:000000000000000000000000000000000053', '2018-01-29 15:55:00', '2018-01-30 15:55:00', 'L1050' , 'CLI:100000000000000000000000000000000003', 'novatec' , 'novasys', 'nvinst', 'typ1', 'val1', 'ch1', null, null); -INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000012','TKI:000000000000000000000000000000000054', '2018-01-29 15:55:00', '2018-01-30 15:55:00', 'L1050' , 'CLI:100000000000000000000000000000000003', 'novatec' , 'novasys', 'nvinst', 'typ1', 'val1', 'ch1', null, null); -INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000013','TKI:000000000000000000000000000000000055', '2018-01-29 15:55:00', '2018-01-30 15:55:00', 'L1050' , 'CLI:100000000000000000000000000000000003', 'novatec' , 'novasys', 'nvinst', 'typ1', 'val1', 'ch1', null, null); +INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000001','TKI:000000000000000000000000000000000001', '2018-01-29 15:55:01', '2018-01-30 15:55:00', 'L10303' , 'CLI:000000000000000000000000000000000002', 'novatec' , 'novasys', 'nvinst', 'typ2', 'val1', 'ch2', '2018-01-30 12:00:00', null); +INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000002','TKI:000000000000000000000000000000000001', '2018-01-29 15:55:02', '2018-01-30 15:55:00', 'L1050' , 'CLI:000000000000000000000000000000000003', 'novatec' , 'novasys', 'nvinst', 'typ2', 'val2', 'ch2', null, null); +INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000003','TKI:000000000000000000000000000000000002', '2018-01-29 15:55:03', null , 'L11010' , 'CLI:000000000000000000000000000000000004', 'novatec' , 'novasys', 'nvinst', 'typ2', 'val2', 'ch3', null, null); +INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000004','TKI:000000000000000000000000000000000002', '2018-01-29 15:55:04', null , 'L110102' , 'CLI:000000000000000000000000000000000005', 'novatec' , 'novasys', 'nvinst', 'typ3', 'val2', 'ch4', null, null); +INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000005','TKI:000000000000000000000000000000000002', '2018-01-29 15:55:05', null , 'L110105' , 'CLI:000000000000000000000000000000000006', 'novatec' , 'novasys', 'nvinst', 'typ3', 'val2', 'ch5', '2018-02-01 12:00:00', null); +INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000006','TKI:000000000000000000000000000000000002', '2018-01-29 15:55:06', null , 'L110107' , 'CLI:000000000000000000000000000000000007', 'novatec' , 'novasys', 'nvinst', 'typ3', 'val2', 'ch6', null, null); +INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000007','TKI:000000000000000000000000000000000002', '2018-01-29 15:55:07', null , 'L12010' , 'CLI:100000000000000000000000000000000008', 'novatec' , 'novasys', 'nvinst', 'typ3', 'val3', 'ch6', null, null); +INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000008','TKI:000000000000000000000000000000000008', '2018-01-29 15:55:08', null , 'L140101' , 'CLI:000000000000000000000000000000000009', 'novatec' , 'novasys', 'nvinst', 'typ3', 'val3', 'ch6', null, null); +INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000009','TKI:000000000000000000000000000000000000', '2018-01-29 15:55:00', '2018-01-30 15:55:00', 'L1050' , 'CLI:100000000000000000000000000000000003', 'novatec' , 'novasys', 'nvinst', 'typ3', 'val4', 'ch7', null, null); +INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000010','TKI:000000000000000000000000000000000052', '2018-01-29 15:55:00', '2018-01-30 15:55:00', 'L1050' , 'CLI:100000000000000000000000000000000003', 'novatec' , 'novasys', 'nvinst', 'typ4', 'val4', 'ch7', null, null); +INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000011','TKI:000000000000000000000000000000000053', '2018-01-29 15:55:00', '2018-01-30 15:55:00', 'L1050' , 'CLI:100000000000000000000000000000000003', 'novatec' , 'novasys', 'nvinst', 'typ4', 'val4', 'ch7', null, null); +INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000012','TKI:000000000000000000000000000000000054', '2018-01-29 15:55:00', '2018-01-30 15:55:00', 'L1050' , 'CLI:100000000000000000000000000000000003', 'novatec' , 'novasys', 'nvinst', 'typ5', 'val4', 'ch7', null, null); +INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000013','TKI:000000000000000000000000000000000055', '2018-01-29 15:55:00', '2018-01-30 15:55:00', 'L1050' , 'CLI:100000000000000000000000000000000003', 'novatec' , 'novasys', 'nvinst', 'typ5', 'val4', 'ch7', null, null); +INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000014','TKI:000000000000000000000000000000000010', '2018-01-29 15:55:00', '2018-01-30 15:55:00', 'L1051' , 'CLI:100000000000000000000000000000000004', 'novatec' , 'novasys', 'nvinst', 'typ5', 'val4', 'ch8', null, null); +INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000015','TKI:000000000000000000000000000000000011', '2018-01-29 15:55:00', '2018-01-30 15:55:00', 'L1052' , 'CLI:100000000000000000000000000000000002', 'novatec' , 'novasys', 'nvinst', 'typ5', 'val5', 'ch8', '2018-01-30 12:00:00', null); +INSERT INTO ATTACHMENT VALUES('TAI:000000000000000000000000000000000016','TKI:000000000000000000000000000000000012', '2018-01-29 15:55:00', '2018-01-30 15:55:00', 'L1053' , 'CLI:100000000000000000000000000000000003', 'novatec' , 'novasys', 'nvinst', 'typ5', 'val6', 'ch8', null, null);