From 07d5475fea8b3b01a95b779ae0a4ccdee6febfcd Mon Sep 17 00:00:00 2001 From: ryzheboka <25465835+ryzheboka@users.noreply.github.com> Date: Tue, 27 Feb 2024 12:49:07 +0100 Subject: [PATCH] Closes #2506 - fix deleting DELETED history events by the cleanup job --- .../impl/jobs/HistoryCleanupJob.java | 3 +- .../jobs/HistoryCleanupJobAccTest.java | 95 ++++++++----------- .../delete/DeleteTaskCommentAccTest.java | 6 +- 3 files changed, 47 insertions(+), 57 deletions(-) diff --git a/history/taskana-simplehistory-provider/src/main/java/pro/taskana/simplehistory/impl/jobs/HistoryCleanupJob.java b/history/taskana-simplehistory-provider/src/main/java/pro/taskana/simplehistory/impl/jobs/HistoryCleanupJob.java index 4c58490f14..75e9ec7d74 100644 --- a/history/taskana-simplehistory-provider/src/main/java/pro/taskana/simplehistory/impl/jobs/HistoryCleanupJob.java +++ b/history/taskana-simplehistory-provider/src/main/java/pro/taskana/simplehistory/impl/jobs/HistoryCleanupJob.java @@ -72,7 +72,8 @@ public void execute() { .eventTypeIn( TaskHistoryEventType.COMPLETED.getName(), TaskHistoryEventType.CANCELLED.getName(), - TaskHistoryEventType.TERMINATED.getName()) + TaskHistoryEventType.TERMINATED.getName(), + TaskHistoryEventType.DELETED.getName()) .list(); Set taskIdsToDeleteHistoryEventsFor; diff --git a/lib/taskana-core-test/src/test/java/acceptance/jobs/HistoryCleanupJobAccTest.java b/lib/taskana-core-test/src/test/java/acceptance/jobs/HistoryCleanupJobAccTest.java index 0031e78b82..31a01c5b7b 100644 --- a/lib/taskana-core-test/src/test/java/acceptance/jobs/HistoryCleanupJobAccTest.java +++ b/lib/taskana-core-test/src/test/java/acceptance/jobs/HistoryCleanupJobAccTest.java @@ -65,10 +65,8 @@ void after() throws Exception { void should_NotCleanHistoryEventsUntilDate_When_MinimumAgeNotReached() throws Exception { TaskHistoryEvent eventToBeCleaned = createTaskHistoryEvent( - "wbKey1", "taskId1", TaskHistoryEventType.CREATED.getName(), - "wbKey2", "someUserId", "someDetails", Instant.now().minus(20, ChronoUnit.DAYS), @@ -76,10 +74,8 @@ void should_NotCleanHistoryEventsUntilDate_When_MinimumAgeNotReached() throws Ex historyService.create(eventToBeCleaned); TaskHistoryEvent eventToBeCleaned2 = createTaskHistoryEvent( - "wbKey1", "taskId1", TaskHistoryEventType.COMPLETED.getName(), - "wbKey2", "someUserId", "someDetails", Instant.now().minus(5, ChronoUnit.DAYS), @@ -93,10 +89,8 @@ void should_NotCleanHistoryEventsUntilDate_When_MinimumAgeNotReached() throws Ex } private TaskHistoryEvent createTaskHistoryEvent( - String workbasketKey, String taskId, String type, - String previousWorkbasketId, String userid, String details, Instant created, @@ -105,10 +99,8 @@ private TaskHistoryEvent createTaskHistoryEvent( historyEvent.setId(IdGenerator.generateWithPrefix(IdGenerator.ID_PREFIX_TASK_HISTORY_EVENT)); historyEvent.setUserId(userid); historyEvent.setDetails(details); - historyEvent.setWorkbasketKey(workbasketKey); historyEvent.setTaskId(taskId); historyEvent.setEventType(type); - historyEvent.setOldValue(previousWorkbasketId); historyEvent.setCreated(created); historyEvent.setParentBusinessProcessId(parentBusinessProcessId); return historyEvent; @@ -140,10 +132,8 @@ void should_CleanHistoryEventsUntilDate_When_SameParentBusinessTrueAndEventsQual TaskHistoryEvent eventToBeCleaned = createTaskHistoryEvent( - "wbKey1", "taskId1", TaskHistoryEventType.CREATED.getName(), - "wbKey2", "someUserId", "someDetails", Instant.now().minus(20, ChronoUnit.DAYS), @@ -151,10 +141,8 @@ void should_CleanHistoryEventsUntilDate_When_SameParentBusinessTrueAndEventsQual historyService.create(eventToBeCleaned); TaskHistoryEvent eventToBeCleaned2 = createTaskHistoryEvent( - "wbKey1", "taskId1", TaskHistoryEventType.COMPLETED.getName(), - "wbKey2", "someUserId", "someDetails", Instant.now().minus(20, ChronoUnit.DAYS), @@ -162,10 +150,8 @@ void should_CleanHistoryEventsUntilDate_When_SameParentBusinessTrueAndEventsQual historyService.create(eventToBeCleaned2); TaskHistoryEvent eventToBeCleaned3 = createTaskHistoryEvent( - "wbKey1", "taskId2", TaskHistoryEventType.CREATED.getName(), - "wbKey2", "someUserId", "someDetails", Instant.now().minus(20, ChronoUnit.DAYS), @@ -173,16 +159,31 @@ void should_CleanHistoryEventsUntilDate_When_SameParentBusinessTrueAndEventsQual historyService.create(eventToBeCleaned3); TaskHistoryEvent eventToBeCleaned4 = createTaskHistoryEvent( - "wbKey1", "taskId2", TaskHistoryEventType.CANCELLED.getName(), - "wbKey2", "someUserId", "someDetails", Instant.now().minus(20, ChronoUnit.DAYS), "sameParentId"); historyService.create(eventToBeCleaned4); - + TaskHistoryEvent eventToBeCleaned5 = + createTaskHistoryEvent( + "taskId3", + TaskHistoryEventType.CREATED.getName(), + "someUserId", + "someDetails", + Instant.now().minus(20, ChronoUnit.DAYS), + "sameParentId"); + historyService.create(eventToBeCleaned5); + TaskHistoryEvent eventToBeCleaned6 = + createTaskHistoryEvent( + "taskId3", + TaskHistoryEventType.DELETED.getName(), + "someUserId", + "someDetails", + Instant.now().minus(20, ChronoUnit.DAYS), + "sameParentId"); + historyService.create(eventToBeCleaned6); HistoryCleanupJob job = new HistoryCleanupJob(taskanaEngine, null, null); job.run(); @@ -193,13 +194,10 @@ void should_CleanHistoryEventsUntilDate_When_SameParentBusinessTrueAndEventsQual @WithAccessId(user = "admin") void should_NotCleanHistoryEvents_When_SameParentBusinessTrueAndActiveTaskInParentBusiness() throws Exception { - TaskHistoryEvent eventToBeCleaned = createTaskHistoryEvent( - "wbKey1", "taskId1", TaskHistoryEventType.CREATED.getName(), - "wbKey2", "someUserId", "someDetails", Instant.now().minus(20, ChronoUnit.DAYS), @@ -207,10 +205,8 @@ void should_NotCleanHistoryEvents_When_SameParentBusinessTrueAndActiveTaskInPare historyService.create(eventToBeCleaned); TaskHistoryEvent eventToBeCleaned2 = createTaskHistoryEvent( - "wbKey1", "taskId1", TaskHistoryEventType.COMPLETED.getName(), - "wbKey2", "someUserId", "someDetails", Instant.now().minus(20, ChronoUnit.DAYS), @@ -218,10 +214,8 @@ void should_NotCleanHistoryEvents_When_SameParentBusinessTrueAndActiveTaskInPare historyService.create(eventToBeCleaned2); TaskHistoryEvent eventToBeCleaned3 = createTaskHistoryEvent( - "wbKey1", "taskId2", TaskHistoryEventType.CREATED.getName(), - "wbKey2", "someUserId", "someDetails", Instant.now().minus(1, ChronoUnit.DAYS), @@ -241,10 +235,8 @@ void should_NotCleanHistoryEvents_When_SameParentBusinessTrueAndActiveTaskInPare throws Exception { TaskHistoryEvent eventToBeCleaned = createTaskHistoryEvent( - "wbKey1", "taskId1", TaskHistoryEventType.CREATED.getName(), - "wbKey2", "someUserId", "someDetails", Instant.now().minus(20, ChronoUnit.DAYS), @@ -252,10 +244,8 @@ void should_NotCleanHistoryEvents_When_SameParentBusinessTrueAndActiveTaskInPare historyService.create(eventToBeCleaned); TaskHistoryEvent eventToBeCleaned2 = createTaskHistoryEvent( - "wbKey1", "taskId1", TaskHistoryEventType.COMPLETED.getName(), - "wbKey2", "someUserId", "someDetails", Instant.now().minus(20, ChronoUnit.DAYS), @@ -263,10 +253,8 @@ void should_NotCleanHistoryEvents_When_SameParentBusinessTrueAndActiveTaskInPare historyService.create(eventToBeCleaned2); TaskHistoryEvent eventToBeCleaned3 = createTaskHistoryEvent( - "wbKey1", "taskId2", TaskHistoryEventType.CREATED.getName(), - "wbKey2", "someUserId", "someDetails", Instant.now().minus(3, ChronoUnit.DAYS), @@ -274,10 +262,8 @@ void should_NotCleanHistoryEvents_When_SameParentBusinessTrueAndActiveTaskInPare historyService.create(eventToBeCleaned3); TaskHistoryEvent eventToBeCleaned4 = createTaskHistoryEvent( - "wbKey1", "taskId2", TaskHistoryEventType.CANCELLED.getName(), - "wbKey2", "someUserId", "someDetails", Instant.now().minus(5, ChronoUnit.DAYS), @@ -296,10 +282,8 @@ void should_NotCleanEvents_When_NoCreatedEventsForParentBusinessProcessIdExist() throws Exception { TaskHistoryEvent toBeIgnored1 = createTaskHistoryEvent( - "wbKey1", "taskId1", TaskHistoryEventType.CANCELLED.getName(), - "wbKey2", "someUserId", "someDetails", Instant.now().minus(20, ChronoUnit.DAYS), @@ -307,10 +291,8 @@ void should_NotCleanEvents_When_NoCreatedEventsForParentBusinessProcessIdExist() historyService.create(toBeIgnored1); TaskHistoryEvent toBeIgnored2 = createTaskHistoryEvent( - "wbKey1", "taskId2", TaskHistoryEventType.COMPLETED.getName(), - "wbKey2", "someUserId", "someDetails", Instant.now().minus(20, ChronoUnit.DAYS), @@ -318,10 +300,8 @@ void should_NotCleanEvents_When_NoCreatedEventsForParentBusinessProcessIdExist() historyService.create(toBeIgnored2); TaskHistoryEvent toBeIgnored3 = createTaskHistoryEvent( - "wbKey1", "taskId3", TaskHistoryEventType.TERMINATED.getName(), - "wbKey2", "someUserId", "someDetails", Instant.now().minus(20, ChronoUnit.DAYS), @@ -355,10 +335,10 @@ void should_NotCleanEvents_When_NoCreatedEventsForParentBusinessProcessIdExist() .map( pair -> createTaskHistoryEvent( - "wbKey1", + pair.getLeft(), pair.getRight().getName(), - "wbKey2", + "someUserId", "someDetails", Instant.now().minus(20, ChronoUnit.DAYS), @@ -406,49 +386,58 @@ void setup() throws Exception { void should_CleanHistoryEventsUntilDate_When_SameParentBusinessFalse() throws Exception { TaskHistoryEvent eventToBeCleaned = createTaskHistoryEvent( - "wbKey1", "taskId1", TaskHistoryEventType.CREATED.getName(), - "wbKey2", "someUserId", "someDetails", Instant.now().minus(20, ChronoUnit.DAYS), - "sameParentId"); + "someParentId1"); historyService.create(eventToBeCleaned); TaskHistoryEvent eventToBeCleaned2 = createTaskHistoryEvent( - "wbKey1", "taskId1", TaskHistoryEventType.COMPLETED.getName(), - "wbKey2", "someUserId", "someDetails", Instant.now().minus(20, ChronoUnit.DAYS), - "sameParentId"); + "someParentId1"); historyService.create(eventToBeCleaned2); TaskHistoryEvent eventToBeCleaned3 = createTaskHistoryEvent( - "wbKey1", "taskId2", TaskHistoryEventType.CREATED.getName(), - "wbKey2", "someUserId", "someDetails", Instant.now().minus(20, ChronoUnit.DAYS), - "sameParentId"); + "someParentId2"); historyService.create(eventToBeCleaned3); TaskHistoryEvent eventToBeCleaned4 = createTaskHistoryEvent( - "wbKey1", "taskId2", TaskHistoryEventType.TERMINATED.getName(), - "wbKey2", "someUserId", "someDetails", Instant.now().minus(5, ChronoUnit.DAYS), - "sameParentId"); + "someParentId2"); historyService.create(eventToBeCleaned4); - + TaskHistoryEvent eventToBeCleaned5 = + createTaskHistoryEvent( + "taskId3", + TaskHistoryEventType.CREATED.getName(), + "someUserId", + "someDetails", + Instant.now().minus(20, ChronoUnit.DAYS), + "someParentId3"); + historyService.create(eventToBeCleaned5); + TaskHistoryEvent eventToBeCleaned6 = + createTaskHistoryEvent( + "taskId3", + TaskHistoryEventType.DELETED.getName(), + "someUserId", + "someDetails", + Instant.now().minus(20, ChronoUnit.DAYS), + "someParentId3"); + historyService.create(eventToBeCleaned6); HistoryCleanupJob job = new HistoryCleanupJob(taskanaEngine, null, null); job.run(); diff --git a/lib/taskana-core-test/src/test/java/acceptance/taskcomment/delete/DeleteTaskCommentAccTest.java b/lib/taskana-core-test/src/test/java/acceptance/taskcomment/delete/DeleteTaskCommentAccTest.java index 80c27e5808..85c809c6d9 100644 --- a/lib/taskana-core-test/src/test/java/acceptance/taskcomment/delete/DeleteTaskCommentAccTest.java +++ b/lib/taskana-core-test/src/test/java/acceptance/taskcomment/delete/DeleteTaskCommentAccTest.java @@ -83,7 +83,7 @@ void should_DeleteTaskComment_For_TaskCommentId() throws Exception { taskService.deleteTaskComment(comment1.getId()); List taskCommentsAfterDeletion = taskService.getTaskComments(task1.getId()); - assertThat(taskCommentsAfterDeletion).hasSize(0); + assertThat(taskCommentsAfterDeletion).isEmpty(); } @WithAccessId(user = "user-1-2", groups = "user-1-1") @@ -129,7 +129,7 @@ void should_FailToDeleteTaskComment_When_UserHasNoAuthorization() throws Excepti }); List taskCommentsAfterDeletionWithAdmin = taskService.getTaskComments(task1.getId()); - assertThat(taskCommentsAfterDeletionWithAdmin).hasSize(0); + assertThat(taskCommentsAfterDeletionWithAdmin).isEmpty(); } @WithAccessId(user = "admin") @@ -146,7 +146,7 @@ void should_DeleteTaskComment_When_UserIsInAdministrativeRole() throws Exception taskService.deleteTaskComment(comment1.getId()); List taskCommentsAfterDeletion = taskService.getTaskComments(task1.getId()); - assertThat(taskCommentsAfterDeletion).hasSize(0); + assertThat(taskCommentsAfterDeletion).isEmpty(); } @WithAccessId(user = "user-1-1")