Skip to content

Commit

Permalink
Closes #2491: Set Owner of Task when Transferring
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesrdi authored and gitgoodjhe committed Aug 9, 2024
1 parent d0f5c41 commit 9ea82b7
Show file tree
Hide file tree
Showing 16 changed files with 1,033 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
INSERT INTO TASK VALUES('TKI:000000000000000000000000000000000000', 'ETI:000000000000000000000000000000000000', RELATIVE_DATE(-1) , RELATIVE_DATE(0) , null , RELATIVE_DATE(0) , RELATIVE_DATE(0) , RELATIVE_DATE(-1) , RELATIVE_DATE(0) , 'Task99' , 'creator_user_id' , 'Lorem ipsum was n Quatsch dolor sit amet.', 'Some custom Note' , 1 , -1 , 'CLAIMED' , 'MANUAL' , 'T2000' , 'CLI:100000000000000000000000000000000016', 'WBI:100000000000000000000000000000000006' , 'USER-1-1' , 'DOMAIN_A', 'BPI21' , 'PBPI21' , 'user-1-1' , 'MyCompany1', 'MySystem1', 'MyInstance1' , 'MyType1', 'MyValue1' , true , false , null , 'NONE' , null , 'custom1' , 'custom2' , 'custom3' , 'custom4' , 'custom5' , 'custom6' , 'custom7' , 'custom8' , 'custom9' , 'custom10' , 'custom11' , 'custom12' , 'custom13' , 'abc' , 'custom15' , 'custom16' , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 3 );
INSERT INTO TASK VALUES('TKI:000000000000000000000000000000000001', 'ETI:000000000000000000000000000000000001', RELATIVE_DATE(-2) , RELATIVE_DATE(0) , null , RELATIVE_DATE(0) , null , RELATIVE_DATE(-2) , RELATIVE_DATE(0) , 'Task01' , 'creator_user_id' , 'Lorem ipsum was n Quatsch dolor sit amet.', 'Some custom Note' , 2 , -1 , 'CLAIMED' , 'EXTERN' , 'L110102' , 'CLI:100000000000000000000000000000000005', 'WBI:100000000000000000000000000000000006' , 'USER-1-1' , 'DOMAIN_A', 'BPI21' , 'PBPI21' , 'user-1-1' , 'MyCompany1', 'MySystem1', 'MyInstance1' , 'MyType1', 'MyValue1' , true , false , null , 'NONE' , null , 'pqr' , null , null , null , null , null , null , null , null , null , null , null , null , 'abc' , null , null , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 2 );
INSERT INTO TASK VALUES('TKI:000000000000000000000000000000000002', 'ETI:000000000000000000000000000000000002', RELATIVE_DATE(-2) , RELATIVE_DATE(0) , null , RELATIVE_DATE(0) , RELATIVE_DATE(0) , RELATIVE_DATE(-2) , RELATIVE_DATE(0) , 'Task02' , 'creator_user_id' , 'Lorem ipsum was n Quatsch t. Aber stimmt.', 'Some custom Note' , 2 , -1 , 'CLAIMED' , 'MANUAL' , 'T2000' , 'CLI:100000000000000000000000000000000016', 'WBI:100000000000000000000000000000000006' , 'USER-1-1' , 'DOMAIN_A', 'BPI21' , 'PBPI21' , 'user-1-1' , 'MyCompany1', 'MySystem1', 'MyInstance1' , 'MyType1', 'MyValue1' , true , false , null , 'NONE' , null , null , null , null , null , null , null , null , null , null , null , null , null , null , 'abc' , null , null , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 2 );
INSERT INTO TASK VALUES('TKI:000000000000000000000000000000000003', 'ETI:000000000000000000000000000000000003','2018-02-01 12:00:00', null , null , '2018-02-01 12:00:00', RELATIVE_DATE(0) , RELATIVE_DATE(-2) , RELATIVE_DATE(0) , 'Widerruf' , 'creator_user_id' , 'Widerruf' , null , 2 , -1 , 'READY' , 'EXTERN' , 'L1050' , 'CLI:100000000000000000000000000000000003', 'WBI:100000000000000000000000000000000001' , 'GPK_KSC' , 'DOMAIN_A', 'PI_0000000000003' , 'DOC_0000000000000000003' , null , '00' , 'PASystem' , '00' , 'VNR' , '11223344' , false , false , null , 'NONE' , null , 'efg' , null , null , null , null , null , null , null , null , null , null , null , null , 'abc' , null , null , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 );
INSERT INTO TASK VALUES('TKI:000000000000000000000000000000000003', 'ETI:000000000000000000000000000000000003','2018-02-01 12:00:00', null , null , '2018-02-01 12:00:00', RELATIVE_DATE(0) , RELATIVE_DATE(-2) , RELATIVE_DATE(0) , 'Widerruf' , 'creator_user_id' , 'Widerruf' , null , 2 , -1 , 'READY' , 'EXTERN' , 'L1050' , 'CLI:100000000000000000000000000000000003', 'WBI:100000000000000000000000000000000001' , 'GPK_KSC' , 'DOMAIN_A', 'PI_0000000000003' , 'DOC_0000000000000000003' , null , '00' , 'PASystem' , '00' , 'VNR' , '11223344' , false , false , null , 'NONE' , null , 'efg' , null , null , null , null , null , null , null , null , null , null , null , null , 'abc' , null , null , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 0 );
INSERT INTO TASK VALUES('TKI:000000000000000000000000000000000004', 'ETI:000000000000000000000000000000000004', RELATIVE_DATE(-3) , null , null , RELATIVE_DATE(0) , RELATIVE_DATE(0) , RELATIVE_DATE(-3) , RELATIVE_DATE(0) , 'Widerruf' , 'creator_user_id' , 'Widerruf' , null , 2 , -1 , 'READY' , 'EXTERN' , 'L1050' , 'CLI:100000000000000000000000000000000003', 'WBI:100000000000000000000000000000000001' , 'GPK_KSC' , 'DOMAIN_A', 'PI_0000000000004' , 'DOC_0000000000000000004' , null , '00' , 'PASystem' , '00' , 'VNR' , '11223344' , false , false , null , 'NONE' , null , null , 'ade' , null , null , null , '074' , '' , null , null , null , null , null , null , 'abc' , null , null , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 1 );
INSERT INTO TASK VALUES('TKI:000000000000000000000000000000000005', 'ETI:000000000000000000000000000000000005', RELATIVE_DATE(-4) , null , null , RELATIVE_DATE(0) , RELATIVE_DATE(-3) , RELATIVE_DATE(-4) , RELATIVE_DATE(0) , 'Widerruf' , 'creator_user_id' , 'Widerruf' , null , 2 , -1 , 'READY' , 'EXTERN' , 'L1050' , 'CLI:100000000000000000000000000000000003', 'WBI:100000000000000000000000000000000001' , 'GPK_KSC' , 'DOMAIN_A', 'PI_0000000000005' , 'DOC_0000000000000000005' , null , '00' , 'PASystem' , '00' , 'VNR' , '11223344' , false , false , null , 'NONE' , null , null , null , null , null , null , '074' , '' , null , null , null , null , null , null , 'abc' , null , null , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 0 );
INSERT INTO TASK VALUES('TKI:000000000000000000000000000000000006', 'ETI:000000000000000000000000000000000006', RELATIVE_DATE(-5) , null , null , RELATIVE_DATE(0) , RELATIVE_DATE(-3) , RELATIVE_DATE(-5) , RELATIVE_DATE(0) , 'Widerruf' , 'creator_user_id' , 'Widerruf' , null , 2000 , -1 , 'READY' , 'EXTERN' , 'L1050' , 'CLI:100000000000000000000000000000000003', 'WBI:100000000000000000000000000000000001' , 'GPK_KSC' , 'DOMAIN_A', 'PI_0000000000006' , 'DOC_0000000000000000006' , null , '00' , 'PASystem' , '00' , 'VNR' , '11223344' , false , false , null , 'NONE' , null , null , null , null , null , null , '075' , '' , null , null , null , null , null , null , 'abc' , null , null , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 0 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,156 @@ Stream<DynamicTest> should_CreateTransferredHistoryEvents_When_TaskBulkTransfer(
return DynamicTest.stream(testCases.iterator(), Triplet::getLeft, test);
}

@WithAccessId(user = "admin")
@TestFactory
Stream<DynamicTest> should_CreateTransferredHistoryEvent_When_TaskIsTransferredWithOwner() {
List<Quadruple<String, String, String, Consumer<String>>> testCases =
List.of(
/*
The workbasketId of the source Workbasket is parametrized. Putting the tested Tasks
into the same Workbasket would result in changes to the test data. This would require
changing tests that already use the tested Tasks. That's why workbasketId is
parametrized.
*/
Quadruple.of(
"Using WorkbasketId; Task doesn't have an Attachment"
+ " or any secondary Object References",
"TKI:000000000000000000000000000000000005",
"WBI:100000000000000000000000000000000001",
wrap(
(String taskId) ->
taskService.transferWithOwner(
taskId, "WBI:100000000000000000000000000000000007", "user-1-2"))),
Quadruple.of(
"Using WorkbasketId; Task has Attachment and secondary Object Reference",
"TKI:000000000000000000000000000000000001",
"WBI:100000000000000000000000000000000006",
wrap(
(String taskId) ->
taskService.transferWithOwner(
taskId, "WBI:100000000000000000000000000000000007", "user-1-2"))),
Quadruple.of(
"Using WorkbasketKey and Domain",
"TKI:000000000000000000000000000000000006",
"WBI:100000000000000000000000000000000001",
wrap(
(String taskId) ->
taskService.transferWithOwner(
taskId, "USER-1-2", "DOMAIN_A", "user-1-2"))));
ThrowingConsumer<Quadruple<String, String, String, Consumer<String>>> test =
q -> {
String taskId = q.getSecond();
Consumer<String> transferMethod = q.getFourth();

TaskHistoryQueryMapper taskHistoryQueryMapper = getHistoryQueryMapper();

List<TaskHistoryEvent> events =
taskHistoryQueryMapper.queryHistoryEvents(
(TaskHistoryQueryImpl) historyService.createTaskHistoryQuery().taskIdIn(taskId));

assertThat(events).isEmpty();

transferMethod.accept(taskId);

events =
taskHistoryQueryMapper.queryHistoryEvents(
(TaskHistoryQueryImpl) historyService.createTaskHistoryQuery().taskIdIn(taskId));

assertThat(events).hasSize(1);
String sourceWorkbasketId = q.getThird();
assertTransferHistoryEvent(
events.get(0).getId(),
sourceWorkbasketId,
"WBI:100000000000000000000000000000000007",
"admin");
};
return DynamicTest.stream(testCases.iterator(), Quadruple::getFirst, test);
}

@WithAccessId(user = "admin")
@TestFactory
Stream<DynamicTest> should_CreateTransferredHistoryEvents_When_TaskBulkTransferWithOwner() {
List<Triplet<String, Map<String, String>, Consumer<List<String>>>> testCases =
List.of(
/*
The workbasketId of the source Workbasket is parametrized. Putting the tested Tasks
into the same Workbasket would result in changes to the test data. This would require
changing tests that already use the tested Tasks. That's why workbasketId is
parametrized.
*/
Triplet.of(
"Using WorkbasketId",
Map.ofEntries(
Map.entry(
"TKI:000000000000000000000000000000000010",
"WBI:100000000000000000000000000000000001"),
Map.entry(
"TKI:000000000000000000000000000000000011",
"WBI:100000000000000000000000000000000001"),
Map.entry(
"TKI:000000000000000000000000000000000012",
"WBI:100000000000000000000000000000000001")),
wrap(
(List<String> taskIds) ->
taskService.transferTasksWithOwner(
"WBI:100000000000000000000000000000000007", taskIds, "user-1-2"))),
Triplet.of(
"Using WorkbasketKey and Domain",
Map.ofEntries(
Map.entry(
"TKI:000000000000000000000000000000000013",
"WBI:100000000000000000000000000000000001"),
Map.entry(
"TKI:000000000000000000000000000000000014",
"WBI:100000000000000000000000000000000001"),
Map.entry(
"TKI:000000000000000000000000000000000015",
"WBI:100000000000000000000000000000000001")),
wrap(
(List<String> taskIds) ->
taskService.transferTasksWithOwner(
"USER-1-2", "DOMAIN_A", taskIds, "user-1-2"))));
ThrowingConsumer<Triplet<String, Map<String, String>, Consumer<List<String>>>> test =
t -> {
Map<String, String> taskIds = t.getMiddle();
Consumer<List<String>> transferMethod = t.getRight();

TaskHistoryQueryMapper taskHistoryQueryMapper = getHistoryQueryMapper();

List<TaskHistoryEvent> events =
taskHistoryQueryMapper.queryHistoryEvents(
(TaskHistoryQueryImpl)
historyService
.createTaskHistoryQuery()
.taskIdIn(taskIds.keySet().toArray(new String[0])));

assertThat(events).isEmpty();

transferMethod.accept(new ArrayList<>(taskIds.keySet()));

events =
taskHistoryQueryMapper.queryHistoryEvents(
(TaskHistoryQueryImpl)
historyService
.createTaskHistoryQuery()
.taskIdIn(taskIds.keySet().toArray(new String[0])));

assertThat(events)
.extracting(TaskHistoryEvent::getTaskId)
.containsExactlyInAnyOrderElementsOf(taskIds.keySet());

for (TaskHistoryEvent event : events) {
assertTransferHistoryEvent(
event.getId(),
taskIds.get(event.getTaskId()),
"WBI:100000000000000000000000000000000007",
"admin");
}
};

return DynamicTest.stream(testCases.iterator(), Triplet::getLeft, test);
}

private void assertTransferHistoryEvent(
String eventId, String expectedOldValue, String expectedNewValue, String expectedUser)
throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import pro.taskana.common.api.TaskanaEngine;
import pro.taskana.common.api.exceptions.InvalidArgumentException;
import pro.taskana.common.api.exceptions.SystemException;
import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.task.api.TaskService;
import pro.taskana.task.api.exceptions.NotAuthorizedOnTaskCommentException;
import pro.taskana.task.api.exceptions.TaskCommentNotFoundException;
Expand Down Expand Up @@ -172,7 +171,7 @@ void should_FailToDeleteTaskComment_When_TaskCommentIdIsNull() throws Exception
void should_FailToDeleteTaskComment_When_CommentIdDoesNotExist() throws Exception {

ThrowingCallable call = () -> taskService.deleteTaskComment("non existing task comment id");
TaskCommentNotFoundException e = catchThrowableOfType(call, TaskCommentNotFoundException.class);
TaskCommentNotFoundException e = catchThrowableOfType(TaskCommentNotFoundException.class, call);
assertThat(e.getTaskCommentId()).isEqualTo("non existing task comment id");
}
}
Loading

0 comments on commit 9ea82b7

Please sign in to comment.