Skip to content

Commit

Permalink
Closes Taskana#2506 - fix deleting DELETED history events by the clea…
Browse files Browse the repository at this point in the history
…nup job
  • Loading branch information
ryzheboka committed Mar 7, 2024
1 parent d57d5c2 commit ea51a19
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> taskIdsToDeleteHistoryEventsFor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,17 @@ 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),
"sameParentId");
historyService.create(eventToBeCleaned);
TaskHistoryEvent eventToBeCleaned2 =
createTaskHistoryEvent(
"wbKey1",
"taskId1",
TaskHistoryEventType.COMPLETED.getName(),
"wbKey2",
"someUserId",
"someDetails",
Instant.now().minus(5, ChronoUnit.DAYS),
Expand All @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -140,49 +132,66 @@ void should_CleanHistoryEventsUntilDate_When_SameParentBusinessTrueAndEventsQual

TaskHistoryEvent eventToBeCleaned =
createTaskHistoryEvent(
"wbKey1",
"taskId1",
TaskHistoryEventType.CREATED.getName(),
"wbKey2",

"someUserId",
"someDetails",
Instant.now().minus(20, ChronoUnit.DAYS),
"sameParentId");
historyService.create(eventToBeCleaned);
TaskHistoryEvent eventToBeCleaned2 =
createTaskHistoryEvent(
"wbKey1",

"taskId1",
TaskHistoryEventType.COMPLETED.getName(),
"wbKey2",

"someUserId",
"someDetails",
Instant.now().minus(20, ChronoUnit.DAYS),
"sameParentId");
historyService.create(eventToBeCleaned2);
TaskHistoryEvent eventToBeCleaned3 =
createTaskHistoryEvent(
"wbKey1",

"taskId2",
TaskHistoryEventType.CREATED.getName(),
"wbKey2",

"someUserId",
"someDetails",
Instant.now().minus(20, ChronoUnit.DAYS),
"sameParentId");
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();

Expand All @@ -196,32 +205,32 @@ void should_NotCleanHistoryEvents_When_SameParentBusinessTrueAndActiveTaskInPare

TaskHistoryEvent eventToBeCleaned =
createTaskHistoryEvent(
"wbKey1",

"taskId1",
TaskHistoryEventType.CREATED.getName(),
"wbKey2",

"someUserId",
"someDetails",
Instant.now().minus(20, ChronoUnit.DAYS),
"sameParentId");
historyService.create(eventToBeCleaned);
TaskHistoryEvent eventToBeCleaned2 =
createTaskHistoryEvent(
"wbKey1",

"taskId1",
TaskHistoryEventType.COMPLETED.getName(),
"wbKey2",

"someUserId",
"someDetails",
Instant.now().minus(20, ChronoUnit.DAYS),
"sameParentId");
historyService.create(eventToBeCleaned2);
TaskHistoryEvent eventToBeCleaned3 =
createTaskHistoryEvent(
"wbKey1",

"taskId2",
TaskHistoryEventType.CREATED.getName(),
"wbKey2",

"someUserId",
"someDetails",
Instant.now().minus(1, ChronoUnit.DAYS),
Expand All @@ -241,43 +250,43 @@ void should_NotCleanHistoryEvents_When_SameParentBusinessTrueAndActiveTaskInPare
throws Exception {
TaskHistoryEvent eventToBeCleaned =
createTaskHistoryEvent(
"wbKey1",

"taskId1",
TaskHistoryEventType.CREATED.getName(),
"wbKey2",

"someUserId",
"someDetails",
Instant.now().minus(20, ChronoUnit.DAYS),
"sameParentId");
historyService.create(eventToBeCleaned);
TaskHistoryEvent eventToBeCleaned2 =
createTaskHistoryEvent(
"wbKey1",

"taskId1",
TaskHistoryEventType.COMPLETED.getName(),
"wbKey2",

"someUserId",
"someDetails",
Instant.now().minus(20, ChronoUnit.DAYS),
"sameParentId");
historyService.create(eventToBeCleaned2);
TaskHistoryEvent eventToBeCleaned3 =
createTaskHistoryEvent(
"wbKey1",

"taskId2",
TaskHistoryEventType.CREATED.getName(),
"wbKey2",

"someUserId",
"someDetails",
Instant.now().minus(3, ChronoUnit.DAYS),
"sameParentId");
historyService.create(eventToBeCleaned3);
TaskHistoryEvent eventToBeCleaned4 =
createTaskHistoryEvent(
"wbKey1",

"taskId2",
TaskHistoryEventType.CANCELLED.getName(),
"wbKey2",

"someUserId",
"someDetails",
Instant.now().minus(5, ChronoUnit.DAYS),
Expand All @@ -296,32 +305,32 @@ void should_NotCleanEvents_When_NoCreatedEventsForParentBusinessProcessIdExist()
throws Exception {
TaskHistoryEvent toBeIgnored1 =
createTaskHistoryEvent(
"wbKey1",

"taskId1",
TaskHistoryEventType.CANCELLED.getName(),
"wbKey2",

"someUserId",
"someDetails",
Instant.now().minus(20, ChronoUnit.DAYS),
"toBeIgnored1");
historyService.create(toBeIgnored1);
TaskHistoryEvent toBeIgnored2 =
createTaskHistoryEvent(
"wbKey1",

"taskId2",
TaskHistoryEventType.COMPLETED.getName(),
"wbKey2",

"someUserId",
"someDetails",
Instant.now().minus(20, ChronoUnit.DAYS),
"toBeIgnored2");
historyService.create(toBeIgnored2);
TaskHistoryEvent toBeIgnored3 =
createTaskHistoryEvent(
"wbKey1",

"taskId3",
TaskHistoryEventType.TERMINATED.getName(),
"wbKey2",

"someUserId",
"someDetails",
Instant.now().minus(20, ChronoUnit.DAYS),
Expand Down Expand Up @@ -355,10 +364,10 @@ void should_NotCleanEvents_When_NoCreatedEventsForParentBusinessProcessIdExist()
.map(
pair ->
createTaskHistoryEvent(
"wbKey1",

pair.getLeft(),
pair.getRight().getName(),
"wbKey2",

"someUserId",
"someDetails",
Instant.now().minus(20, ChronoUnit.DAYS),
Expand Down Expand Up @@ -406,43 +415,43 @@ 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");
historyService.create(eventToBeCleaned);
TaskHistoryEvent eventToBeCleaned2 =
createTaskHistoryEvent(
"wbKey1",

"taskId1",
TaskHistoryEventType.COMPLETED.getName(),
"wbKey2",

"someUserId",
"someDetails",
Instant.now().minus(20, ChronoUnit.DAYS),
"sameParentId");
historyService.create(eventToBeCleaned2);
TaskHistoryEvent eventToBeCleaned3 =
createTaskHistoryEvent(
"wbKey1",

"taskId2",
TaskHistoryEventType.CREATED.getName(),
"wbKey2",

"someUserId",
"someDetails",
Instant.now().minus(20, ChronoUnit.DAYS),
"sameParentId");
historyService.create(eventToBeCleaned3);
TaskHistoryEvent eventToBeCleaned4 =
createTaskHistoryEvent(
"wbKey1",

"taskId2",
TaskHistoryEventType.TERMINATED.getName(),
"wbKey2",

"someUserId",
"someDetails",
Instant.now().minus(5, ChronoUnit.DAYS),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void should_DeleteTaskComment_For_TaskCommentId() throws Exception {
taskService.deleteTaskComment(comment1.getId());

List<TaskComment> taskCommentsAfterDeletion = taskService.getTaskComments(task1.getId());
assertThat(taskCommentsAfterDeletion).hasSize(0);
assertThat(taskCommentsAfterDeletion).isEmpty();
}

@WithAccessId(user = "user-1-2", groups = "user-1-1")
Expand Down Expand Up @@ -129,7 +129,7 @@ void should_FailToDeleteTaskComment_When_UserHasNoAuthorization() throws Excepti
});
List<TaskComment> taskCommentsAfterDeletionWithAdmin =
taskService.getTaskComments(task1.getId());
assertThat(taskCommentsAfterDeletionWithAdmin).hasSize(0);
assertThat(taskCommentsAfterDeletionWithAdmin).isEmpty();
}

@WithAccessId(user = "admin")
Expand All @@ -146,7 +146,7 @@ void should_DeleteTaskComment_When_UserIsInAdministrativeRole() throws Exception
taskService.deleteTaskComment(comment1.getId());

List<TaskComment> taskCommentsAfterDeletion = taskService.getTaskComments(task1.getId());
assertThat(taskCommentsAfterDeletion).hasSize(0);
assertThat(taskCommentsAfterDeletion).isEmpty();
}

@WithAccessId(user = "user-1-1")
Expand Down

0 comments on commit ea51a19

Please sign in to comment.