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 Feb 27, 2024
1 parent d126fbf commit 7eaf0d1
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 71 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,23 +65,18 @@ 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),
"sameParentId");
historyService.create(eventToBeCleaned2);
Expand All @@ -93,22 +88,16 @@ void should_NotCleanHistoryEventsUntilDate_When_MinimumAgeNotReached() throws Ex
}

private TaskHistoryEvent createTaskHistoryEvent(
String workbasketKey,
String taskId,
String type,
String previousWorkbasketId,
String userid,
String details,
Instant created,
String parentBusinessProcessId) {
TaskHistoryEvent historyEvent = new TaskHistoryEvent();
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 +129,69 @@ 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",

Instant.now().minus(20, ChronoUnit.DAYS),
"sameParentId");
historyService.create(eventToBeCleaned5);
TaskHistoryEvent eventToBeCleaned6 =
createTaskHistoryEvent(

"taskId3",
TaskHistoryEventType.DELETED.getName(),

"someUserId",

Instant.now().minus(20, ChronoUnit.DAYS),
"sameParentId");
historyService.create(eventToBeCleaned6);
HistoryCleanupJob job = new HistoryCleanupJob(taskanaEngine, null, null);
job.run();

Expand All @@ -196,34 +205,34 @@ 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),
"sameParentId");
historyService.create(eventToBeCleaned3);
Expand All @@ -241,45 +250,45 @@ 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),
"sameParentId");
historyService.create(eventToBeCleaned4);
Expand All @@ -296,34 +305,34 @@ 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),
"toBeIgnored3");
historyService.create(toBeIgnored3);
Expand Down Expand Up @@ -355,12 +364,12 @@ void should_NotCleanEvents_When_NoCreatedEventsForParentBusinessProcessIdExist()
.map(
pair ->
createTaskHistoryEvent(
"wbKey1",

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

"someUserId",
"someDetails",

Instant.now().minus(20, ChronoUnit.DAYS),
parentBusinessId))
.toList();
Expand Down Expand Up @@ -406,45 +415,45 @@ 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),
"sameParentId");
historyService.create(eventToBeCleaned4);
Expand Down

0 comments on commit 7eaf0d1

Please sign in to comment.