diff --git a/lib/taskana-core/src/main/java/pro/taskana/task/api/TaskService.java b/lib/taskana-core/src/main/java/pro/taskana/task/api/TaskService.java index d83214238c..5c18adae05 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/task/api/TaskService.java +++ b/lib/taskana-core/src/main/java/pro/taskana/task/api/TaskService.java @@ -471,6 +471,11 @@ Task terminateTask(String taskId) * Transfers a {@linkplain Task} to another {@linkplain Workbasket} while always setting * {@linkplain Task#isTransferred() isTransferred} to true. * + * @param taskId the {@linkplain Task#getId() id} of the {@linkplain Task} which should be + * transferred + * @param destinationWorkbasketId the {@linkplain Workbasket#getId() id} of the target {@linkplain + * Workbasket} + * @return the transferred {@linkplain Task} * @see #transfer(String, String, boolean) */ @SuppressWarnings("checkstyle:JavadocMethod") @@ -513,6 +518,13 @@ Task transfer(String taskId, String destinationWorkbasketId, boolean setTransfer * Transfers a {@linkplain Task} to another {@linkplain Workbasket} while always setting * {@linkplain Task#isTransferred isTransferred} . * + * @param taskId the {@linkplain Task#getId() id} of the {@linkplain Task} which should be + * transferred + * @param workbasketKey the {@linkplain Workbasket#getKey() key} of the target {@linkplain + * Workbasket} + * @param domain the {@linkplain Workbasket#getDomain() domain} of the target {@linkplain + * Workbasket} + * @return the transferred {@linkplain Task} * @see #transfer(String, String, String, boolean) */ @SuppressWarnings("checkstyle:JavadocMethod") @@ -553,6 +565,111 @@ Task transfer(String taskId, String workbasketKey, String domain, boolean setTra NotAuthorizedOnWorkbasketException, InvalidTaskStateException; + /** + * Transfers a {@linkplain Task} to another {@linkplain Workbasket} and set owner of task in the + * new workbasket to {@param owner} while always setting {@linkplain Task#isTransferred() + * isTransferred} to true. + * + * @param taskId the {@linkplain Task#getId() id} of the {@linkplain Task} which should be + * transferred + * @param destinationWorkbasketId the {@linkplain Workbasket#getId() id} of the target {@linkplain + * Workbasket} + * @param owner the owner of the transferred {@linkplain Task} in the new workbasket + * @return the transferred {@linkplain Task} + * @see #transferWithOwner(String, String, String, boolean) + */ + @SuppressWarnings("checkstyle:JavadocMethod") + default Task transferWithOwner(String taskId, String destinationWorkbasketId, String owner) + throws TaskNotFoundException, + WorkbasketNotFoundException, + NotAuthorizedOnWorkbasketException, + InvalidTaskStateException { + return transferWithOwner(taskId, destinationWorkbasketId, owner, true); + } + + /** + * Transfers a {@linkplain Task} to another {@linkplain Workbasket} and set owner. + * + *

The transfer resets {@linkplain Task#isRead() isRead} and sets {@linkplain + * Task#isTransferred() isTransferred} if setTransferFlag is true. + * + * @param taskId the {@linkplain Task#getId() id} of the {@linkplain Task} which should be + * transferred + * @param destinationWorkbasketId the {@linkplain Workbasket#getId() id} of the target {@linkplain + * Workbasket} + * @param owner the owner of the transferred {@linkplain Task} in the new workbasket + * @param setTransferFlag controls whether to set {@linkplain Task#isTransferred() isTransferred} + * to true or not + * @return the transferred {@linkplain Task} + * @throws TaskNotFoundException if the {@linkplain Task} with taskId wasn't found + * @throws WorkbasketNotFoundException if the target {@linkplain Workbasket} was not found + * @throws NotAuthorizedOnWorkbasketException if the current user has no {@linkplain + * WorkbasketPermission#READ} for the source {@linkplain Workbasket} or no {@linkplain + * WorkbasketPermission#TRANSFER} for the target {@linkplain Workbasket} + * @throws InvalidTaskStateException if the {@linkplain Task} is in one of the {@linkplain + * TaskState#END_STATES} + */ + Task transferWithOwner( + String taskId, String destinationWorkbasketId, String owner, boolean setTransferFlag) + throws TaskNotFoundException, + WorkbasketNotFoundException, + NotAuthorizedOnWorkbasketException, + InvalidTaskStateException; + + /** + * Transfers a {@linkplain Task} to another {@linkplain Workbasket} and set owner of task in new + * workbasket to {@param owner} while always setting {@linkplain Task#isTransferred isTransferred} + * . + * + * @param taskId the {@linkplain Task#getId() id} of the {@linkplain Task} which should be + * transferred + * @param workbasketKey the {@linkplain Workbasket#getKey() key} of the target {@linkplain + * Workbasket} + * @param domain the {@linkplain Workbasket#getDomain() domain} of the target {@linkplain + * Workbasket} + * @param owner the owner of the transferred {@linkplain Task} in the new workbasket + * @see #transferWithOwner(String, String, String, String, boolean) + */ + @SuppressWarnings("checkstyle:JavadocMethod") + default Task transferWithOwner(String taskId, String workbasketKey, String domain, String owner) + throws TaskNotFoundException, + WorkbasketNotFoundException, + NotAuthorizedOnWorkbasketException, + InvalidTaskStateException { + return transferWithOwner(taskId, workbasketKey, domain, owner, true); + } + + /** + * Transfers a {@linkplain Task} to another {@linkplain Workbasket} and set owner. + * + *

The transfer resets {@linkplain Task#isRead() isRead} and sets {@linkplain + * Task#isTransferred() isTransferred} if setTransferFlag is true. + * + * @param taskId the {@linkplain Task#getId() id} of the {@linkplain Task} which should be + * transferred + * @param workbasketKey the {@linkplain Workbasket#getKey() key} of the target {@linkplain + * Workbasket} + * @param domain the {@linkplain Workbasket#getDomain() domain} of the target {@linkplain + * Workbasket} + * @param owner the owner of the transferred {@linkplain Task} in the new workbasket + * @param setTransferFlag controls whether to set {@linkplain Task#isTransferred() isTransferred} + * or not + * @return the transferred {@linkplain Task} + * @throws TaskNotFoundException if the {@linkplain Task} with taskId was not found + * @throws WorkbasketNotFoundException if the target {@linkplain Workbasket} was not found + * @throws NotAuthorizedOnWorkbasketException if the current user has no {@linkplain + * WorkbasketPermission#READ} for the source {@linkplain Workbasket} or no {@linkplain + * WorkbasketPermission#TRANSFER} for the target {@linkplain Workbasket} + * @throws InvalidTaskStateException if the {@linkplain Task} is in one of the {@linkplain + * TaskState#END_STATES} + */ + Task transferWithOwner( + String taskId, String workbasketKey, String domain, String owner, boolean setTransferFlag) + throws TaskNotFoundException, + WorkbasketNotFoundException, + NotAuthorizedOnWorkbasketException, + InvalidTaskStateException; + /** * Transfers a List of {@linkplain Task Tasks} to another {@linkplain Workbasket} while always * setting {@linkplain Task#isTransferred isTransferred} to true. diff --git a/lib/taskana-core/src/main/java/pro/taskana/task/internal/TaskServiceImpl.java b/lib/taskana-core/src/main/java/pro/taskana/task/internal/TaskServiceImpl.java index 08e3baaac2..feb66d5a28 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/task/internal/TaskServiceImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/task/internal/TaskServiceImpl.java @@ -474,6 +474,27 @@ public Task transfer(String taskId, String workbasketKey, String domain, boolean return taskTransferrer.transfer(taskId, workbasketKey, domain, setTransferFlag); } + @Override + public Task transferWithOwner( + String taskId, String destinationWorkbasketId, String owner, boolean setTransferFlag) + throws TaskNotFoundException, + WorkbasketNotFoundException, + NotAuthorizedOnWorkbasketException, + InvalidTaskStateException { + return taskTransferrer.transferWithOwner( + taskId, destinationWorkbasketId, owner, setTransferFlag); + } + + @Override + public Task transferWithOwner( + String taskId, String workbasketKey, String domain, String owner, boolean setTransferFlag) + throws TaskNotFoundException, + WorkbasketNotFoundException, + NotAuthorizedOnWorkbasketException, + InvalidTaskStateException { + return taskTransferrer.transferWithOwner(taskId, workbasketKey, domain, owner, setTransferFlag); + } + @Override public Task setTaskRead(String taskId, boolean isRead) throws TaskNotFoundException, NotAuthorizedOnWorkbasketException { diff --git a/lib/taskana-core/src/main/java/pro/taskana/task/internal/TaskTransferrer.java b/lib/taskana-core/src/main/java/pro/taskana/task/internal/TaskTransferrer.java index e84c540b56..ad5be5a074 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/task/internal/TaskTransferrer.java +++ b/lib/taskana-core/src/main/java/pro/taskana/task/internal/TaskTransferrer.java @@ -60,7 +60,7 @@ Task transfer(String taskId, String destinationWorkbasketId, boolean setTransfer InvalidTaskStateException { WorkbasketSummary destinationWorkbasket = workbasketService.getWorkbasket(destinationWorkbasketId).asSummary(); - return transferSingleTask(taskId, destinationWorkbasket, setTransferFlag); + return transferSingleTask(taskId, destinationWorkbasket, null, setTransferFlag); } Task transfer( @@ -74,7 +74,7 @@ Task transfer( InvalidTaskStateException { WorkbasketSummary destinationWorkbasket = workbasketService.getWorkbasket(destinationWorkbasketKey, destinationDomain).asSummary(); - return transferSingleTask(taskId, destinationWorkbasket, setTransferFlag); + return transferSingleTask(taskId, destinationWorkbasket, null, setTransferFlag); } BulkOperationResults transfer( @@ -104,8 +104,34 @@ BulkOperationResults transfer( return transferMultipleTasks(taskIds, destinationWorkbasket, setTransferFlag); } + Task transferWithOwner( + String taskId, String destinationWorkbasketId, String owner, boolean setTransferFlag) + throws TaskNotFoundException, + WorkbasketNotFoundException, + NotAuthorizedOnWorkbasketException, + InvalidTaskStateException { + WorkbasketSummary destinationWorkbasket = + workbasketService.getWorkbasket(destinationWorkbasketId).asSummary(); + return transferSingleTask(taskId, destinationWorkbasket, owner, setTransferFlag); + } + + Task transferWithOwner( + String taskId, + String destinationWorkbasketKey, + String destinationDomain, + String owner, + boolean setTransferFlag) + throws TaskNotFoundException, + WorkbasketNotFoundException, + NotAuthorizedOnWorkbasketException, + InvalidTaskStateException { + WorkbasketSummary destinationWorkbasket = + workbasketService.getWorkbasket(destinationWorkbasketKey, destinationDomain).asSummary(); + return transferSingleTask(taskId, destinationWorkbasket, owner, setTransferFlag); + } + private Task transferSingleTask( - String taskId, WorkbasketSummary destinationWorkbasket, boolean setTransferFlag) + String taskId, WorkbasketSummary destinationWorkbasket, String owner, boolean setTransferFlag) throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedOnWorkbasketException, @@ -120,7 +146,7 @@ private Task transferSingleTask( WorkbasketSummary originWorkbasket = task.getWorkbasketSummary(); checkPreconditionsForTransferTask(task, destinationWorkbasket, originWorkbasket); - applyTransferValuesForTask(task, destinationWorkbasket, setTransferFlag); + applyTransferValuesForTask(task, destinationWorkbasket, owner, setTransferFlag); taskMapper.update(task); if (historyEventManager.isEnabled()) { createTransferredEvent( @@ -262,7 +288,7 @@ private void updateTransferableTasks( if (!taskSummariesWithSameGoalState.isEmpty()) { TaskImpl updateObject = new TaskImpl(); updateObject.setState(goalState); - applyTransferValuesForTask(updateObject, destinationWorkbasket, setTransferFlag); + applyTransferValuesForTask(updateObject, destinationWorkbasket, null, setTransferFlag); taskMapper.updateTransfered( taskSummariesWithSameGoalState.stream() .map(TaskSummary::getId) @@ -275,7 +301,8 @@ private void updateTransferableTasks( TaskSummaryImpl newSummary = (TaskSummaryImpl) oldSummary.copy(); newSummary.setId(oldSummary.getId()); newSummary.setExternalId(oldSummary.getExternalId()); - applyTransferValuesForTask(newSummary, destinationWorkbasket, setTransferFlag); + applyTransferValuesForTask( + newSummary, destinationWorkbasket, null, setTransferFlag); createTransferredEvent( oldSummary, @@ -289,11 +316,11 @@ private void updateTransferableTasks( } private void applyTransferValuesForTask( - TaskSummaryImpl task, WorkbasketSummary workbasket, boolean setTransferFlag) { + TaskSummaryImpl task, WorkbasketSummary workbasket, String owner, boolean setTransferFlag) { task.setRead(false); task.setTransferred(setTransferFlag); task.setState(getStateAfterTransfer(task)); - task.setOwner(null); + task.setOwner(owner); task.setWorkbasketSummary(workbasket); task.setDomain(workbasket.getDomain()); task.setModified(Instant.now()); diff --git a/lib/taskana-core/src/test/java/acceptance/task/transfer/TransferTaskAccTest.java b/lib/taskana-core/src/test/java/acceptance/task/transfer/TransferTaskAccTest.java index e0f37ed8f5..1925448d27 100644 --- a/lib/taskana-core/src/test/java/acceptance/task/transfer/TransferTaskAccTest.java +++ b/lib/taskana-core/src/test/java/acceptance/task/transfer/TransferTaskAccTest.java @@ -435,4 +435,73 @@ void should_NotSetTheTransferFlagWithinBulkTransfer_When_SetTransferFlagNotReque assertThat(transferredTasks).extracting(TaskSummary::isTransferred).containsOnly(false); } + + @WithAccessId(user = "teamlead-1") + @Test + void should_SetOwnerAndNotBeAuthorized_When_TransferringTask() throws Exception { + taskService.transferWithOwner( + "TKI:000000000000000000000000000000000021", + "WBI:100000000000000000000000000000000005", + "teamlead-1"); + + Task transferredTask = taskService.getTask("TKI:000000000000000000000000000000000021"); + assertThat(transferredTask).isNotNull(); + assertThat(transferredTask.isTransferred()).isTrue(); + assertThat(transferredTask.isRead()).isFalse(); + assertThat(transferredTask.getState()).isEqualTo(TaskState.READY); + assertThat(transferredTask.getOwner()).isEqualTo("teamlead-1"); + assertThat(transferredTask.getWorkbasketSummary().getId()) + .isEqualTo("WBI:100000000000000000000000000000000005"); + } + + @WithAccessId(user = "teamlead-1", groups = GROUP_1_DN) + @Test + void should_TransferTaskAndSetOwner_When_WorkbasketKeyAndDomainIsProvided() throws Exception { + taskService.transferWithOwner( + "TKI:200000000000000000000000000000000066", "USER-1-2", "DOMAIN_A", "teamlead-1"); + + Task transferredTask = taskService.getTask("TKI:200000000000000000000000000000000066"); + assertThat(transferredTask).isNotNull(); + assertThat(transferredTask.isTransferred()).isTrue(); + assertThat(transferredTask.isRead()).isFalse(); + assertThat(transferredTask.getState()).isEqualTo(TaskState.READY); + assertThat(transferredTask.getOwner()).isEqualTo("teamlead-1"); + assertThat(transferredTask.getWorkbasketSummary().getId()) + .isEqualTo("WBI:100000000000000000000000000000000007"); + } + + @WithAccessId(user = "admin") + @Test + void should_SetTransferFlagToFalse_When_WorkbasketIdGiven() throws Exception { + taskService.transferWithOwner( + "TKI:000000000000000000000000000000000010", + "WBI:100000000000000000000000000000000006", + "user-1-1", + false); + + Task transferredTask = taskService.getTask("TKI:000000000000000000000000000000000010"); + assertThat(transferredTask).isNotNull(); + assertThat(transferredTask.isTransferred()).isTrue(); + assertThat(transferredTask.isRead()).isFalse(); + assertThat(transferredTask.getState()).isEqualTo(TaskState.READY); + assertThat(transferredTask.getOwner()).isEqualTo("user-1-1"); + assertThat(transferredTask.getWorkbasketSummary().getId()) + .isEqualTo("WBI:100000000000000000000000000000000006"); + } + + @WithAccessId(user = "admin") + @Test + void should_SetTransferFlagToFalse_When_WorkbasketKeyAndDomainGiven() throws Exception { + taskService.transferWithOwner( + "TKI:000000000000000000000000000000000011", "USER-1-1", "DOMAIN_A", "user-1-1", false); + + Task transferredTask = taskService.getTask("TKI:000000000000000000000000000000000011"); + assertThat(transferredTask).isNotNull(); + assertThat(transferredTask.isTransferred()).isTrue(); + assertThat(transferredTask.isRead()).isFalse(); + assertThat(transferredTask.getState()).isEqualTo(TaskState.READY); + assertThat(transferredTask.getOwner()).isEqualTo("user-1-1"); + assertThat(transferredTask.getWorkbasketSummary().getId()) + .isEqualTo("WBI:100000000000000000000000000000000006"); + } } diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/task/rest/TaskController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/task/rest/TaskController.java index e373f7c3b9..9556533704 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/task/rest/TaskController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/task/rest/TaskController.java @@ -55,6 +55,7 @@ import pro.taskana.task.rest.models.TaskRepresentationModel; import pro.taskana.task.rest.models.TaskSummaryCollectionRepresentationModel; import pro.taskana.task.rest.models.TaskSummaryPagedRepresentationModel; +import pro.taskana.task.rest.models.TransferTaskRepresentationModel; import pro.taskana.workbasket.api.exceptions.NotAuthorizedOnWorkbasketException; import pro.taskana.workbasket.api.exceptions.WorkbasketNotFoundException; @@ -109,11 +110,12 @@ public ResponseEntity createTask( NotAuthorizedOnWorkbasketException { if (!taskRepresentationModel.getAttachments().stream() - .filter(att -> Objects.nonNull(att.getTaskId())) - .filter(att -> !att.getTaskId().equals(taskRepresentationModel.getTaskId())) - .collect(Collectors.toList()).isEmpty()) { + .filter(att -> Objects.nonNull(att.getTaskId())) + .filter(att -> !att.getTaskId().equals(taskRepresentationModel.getTaskId())) + .collect(Collectors.toList()) + .isEmpty()) { throw new InvalidArgumentException( - "An attachments' taskId must be empty or equal to the id of the task it belongs to"); + "An attachments' taskId must be empty or equal to the id of the task it belongs to"); } Task fromResource = taskRepresentationModelAssembler.toEntityModel(taskRepresentationModel); @@ -531,7 +533,8 @@ public ResponseEntity terminateTask(@PathVariable Strin * @title Transfer a Task to another Workbasket * @param taskId the Id of the Task which should be transferred * @param workbasketId the Id of the destination Workbasket - * @param setTransferFlag sets the tansfer flag of the task (default: true) + * @param transferTaskRepresentationModel sets the transfer flag of the Task (default: true) and + * Owner of task * @return the successfully transferred Task. * @throws TaskNotFoundException if the requested Task does not exist * @throws WorkbasketNotFoundException if the requested Workbasket does not exist @@ -544,13 +547,23 @@ public ResponseEntity terminateTask(@PathVariable Strin public ResponseEntity transferTask( @PathVariable String taskId, @PathVariable String workbasketId, - @RequestBody(required = false) Boolean setTransferFlag) + @RequestBody(required = false) + TransferTaskRepresentationModel transferTaskRepresentationModel) throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedOnWorkbasketException, InvalidTaskStateException { - Task updatedTask = - taskService.transfer(taskId, workbasketId, setTransferFlag == null || setTransferFlag); + Task updatedTask; + if (transferTaskRepresentationModel == null) { + updatedTask = taskService.transfer(taskId, workbasketId); + } else { + updatedTask = + taskService.transferWithOwner( + taskId, + workbasketId, + transferTaskRepresentationModel.getOwner(), + transferTaskRepresentationModel.getSetTransferFlag()); + } return ResponseEntity.ok(taskRepresentationModelAssembler.toModel(updatedTask)); } @@ -597,11 +610,12 @@ public ResponseEntity updateTask( } if (!taskRepresentationModel.getAttachments().stream() - .filter(att -> Objects.nonNull(att.getTaskId())) - .filter(att -> !att.getTaskId().equals(taskRepresentationModel.getTaskId())) - .collect(Collectors.toList()).isEmpty()) { + .filter(att -> Objects.nonNull(att.getTaskId())) + .filter(att -> !att.getTaskId().equals(taskRepresentationModel.getTaskId())) + .collect(Collectors.toList()) + .isEmpty()) { throw new InvalidArgumentException( - "An attachments' taskId must be empty or equal to the id of the task it belongs to"); + "An attachments' taskId must be empty or equal to the id of the task it belongs to"); } Task task = taskRepresentationModelAssembler.toEntityModel(taskRepresentationModel); diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/task/rest/models/TransferTaskRepresentationModel.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/task/rest/models/TransferTaskRepresentationModel.java new file mode 100644 index 0000000000..789ac47d18 --- /dev/null +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/task/rest/models/TransferTaskRepresentationModel.java @@ -0,0 +1,29 @@ +package pro.taskana.task.rest.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.beans.ConstructorProperties; + +public class TransferTaskRepresentationModel { + + /** The value to set the Task property owner. */ + @JsonProperty("owner") + private final String owner; + + /** The value to set the Task property setTransferFlag. */ + @JsonProperty("setTransferFlag") + private final Boolean setTransferFlag; + + @ConstructorProperties({"setTransferFlag", "owner"}) + public TransferTaskRepresentationModel(Boolean setTransferFlag, String owner) { + this.setTransferFlag = setTransferFlag == null || setTransferFlag; + this.owner = owner; + } + + public Boolean getSetTransferFlag() { + return setTransferFlag; + } + + public String getOwner() { + return owner; + } +} diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/task/rest/TaskControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/task/rest/TaskControllerIntTest.java index 3f964d5079..b3624519d7 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/task/rest/TaskControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/task/rest/TaskControllerIntTest.java @@ -54,6 +54,7 @@ import pro.taskana.task.rest.models.TaskSummaryCollectionRepresentationModel; import pro.taskana.task.rest.models.TaskSummaryPagedRepresentationModel; import pro.taskana.task.rest.models.TaskSummaryRepresentationModel; +import pro.taskana.task.rest.models.TransferTaskRepresentationModel; import pro.taskana.task.rest.routing.IntegrationTestTaskRouter; import pro.taskana.workbasket.rest.models.WorkbasketSummaryRepresentationModel; @@ -61,7 +62,6 @@ @TaskanaSpringBootTest class TaskControllerIntTest { - @Autowired TaskanaConfiguration taskanaConfiguration; private static final ParameterizedTypeReference TASK_SUMMARY_PAGE_MODEL_TYPE = new ParameterizedTypeReference<>() {}; private static final ParameterizedTypeReference @@ -71,6 +71,7 @@ class TaskControllerIntTest { private final RestHelper restHelper; private final DataSource dataSource; private final String schemaName; + @Autowired TaskanaConfiguration taskanaConfiguration; @Autowired TaskControllerIntTest( @@ -149,16 +150,16 @@ private ObjectReferenceRepresentationModel getObjectReferenceResourceSample() { private AttachmentRepresentationModel getAttachmentResourceSample() { AttachmentRepresentationModel attachmentRepresentationModel = - new AttachmentRepresentationModel(); + new AttachmentRepresentationModel(); attachmentRepresentationModel.setAttachmentId("A11010"); attachmentRepresentationModel.setObjectReference(getObjectReferenceResourceSample()); ClassificationSummaryRepresentationModel classificationSummaryRepresentationModel = - new ClassificationSummaryRepresentationModel(); - classificationSummaryRepresentationModel - .setClassificationId("CLI:100000000000000000000000000000000004"); + new ClassificationSummaryRepresentationModel(); + classificationSummaryRepresentationModel.setClassificationId( + "CLI:100000000000000000000000000000000004"); classificationSummaryRepresentationModel.setKey("L11010"); - attachmentRepresentationModel - .setClassificationSummary(classificationSummaryRepresentationModel); + attachmentRepresentationModel.setClassificationSummary( + classificationSummaryRepresentationModel); return attachmentRepresentationModel; } @@ -1550,16 +1551,16 @@ void should_CreateTaskWithError_When_SpecifyingAttachmentWrong() { String url = restHelper.toUrl(RestEndpoints.URL_TASKS); HttpEntity auth = - new HttpEntity<>( - taskRepresentationModel, RestHelper.generateHeadersForUser("teamlead-1")); + new HttpEntity<>( + taskRepresentationModel, RestHelper.generateHeadersForUser("teamlead-1")); ThrowingCallable httpCall = - () -> TEMPLATE.exchange(url, HttpMethod.POST, auth, TASK_MODEL_TYPE); + () -> TEMPLATE.exchange(url, HttpMethod.POST, auth, TASK_MODEL_TYPE); assertThatThrownBy(httpCall) - .extracting(HttpStatusCodeException.class::cast) - .extracting(HttpStatusCodeException::getStatusCode) - .isEqualTo(HttpStatus.BAD_REQUEST); + .extracting(HttpStatusCodeException.class::cast) + .extracting(HttpStatusCodeException::getStatusCode) + .isEqualTo(HttpStatus.BAD_REQUEST); } @Test @@ -1789,13 +1790,12 @@ void should_ChangeValueOfModified_When_UpdatingTask() { @Test void should_ThrowError_When_UpdatingTaskWithBadAttachment() { String url = - restHelper.toUrl(RestEndpoints.URL_TASKS_ID, - "TKI:100000000000000000000000000000000000"); + restHelper.toUrl(RestEndpoints.URL_TASKS_ID, "TKI:100000000000000000000000000000000000"); HttpEntity httpEntityWithoutBody = - new HttpEntity<>(RestHelper.generateHeadersForUser("teamlead-1")); + new HttpEntity<>(RestHelper.generateHeadersForUser("teamlead-1")); ResponseEntity responseGet = - TEMPLATE.exchange(url, HttpMethod.GET, httpEntityWithoutBody, TASK_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, httpEntityWithoutBody, TASK_MODEL_TYPE); final TaskRepresentationModel originalTask = responseGet.getBody(); @@ -1803,17 +1803,16 @@ void should_ThrowError_When_UpdatingTaskWithBadAttachment() { attachmentRepresentationModel.setTaskId(originalTask.getTaskId() + "wrongId"); originalTask.setAttachments(Lists.newArrayList(attachmentRepresentationModel)); - HttpEntity httpEntity = - new HttpEntity<>(originalTask, RestHelper.generateHeadersForUser("teamlead-1")); + new HttpEntity<>(originalTask, RestHelper.generateHeadersForUser("teamlead-1")); ThrowingCallable httpCall = - () -> TEMPLATE.exchange(url, HttpMethod.PUT, httpEntity, TASK_MODEL_TYPE); + () -> TEMPLATE.exchange(url, HttpMethod.PUT, httpEntity, TASK_MODEL_TYPE); assertThatThrownBy(httpCall) - .extracting(HttpStatusCodeException.class::cast) - .extracting(HttpStatusCodeException::getStatusCode) - .isEqualTo(HttpStatus.BAD_REQUEST); + .extracting(HttpStatusCodeException.class::cast) + .extracting(HttpStatusCodeException::getStatusCode) + .isEqualTo(HttpStatus.BAD_REQUEST); } } @@ -1963,33 +1962,36 @@ void should_ThrowException_When_UpdatingTaskOwnerOfClaimedTask() { @TestInstance(Lifecycle.PER_CLASS) class TransferTasks { @TestFactory - Stream should_SetTransferFlagDependentOnRequestBody_When_TransferringTask() { - Iterator iterator = Arrays.asList(true, false).iterator(); + Stream should_SetTransferFlagAndOwnerDependentOnBody_When_TransferTask() { + Iterator> iterator = + Arrays.asList(Pair.of(false, "user-1-1"), Pair.of(true, "user-1-1")).iterator(); String url = restHelper.toUrl( RestEndpoints.URL_TASKS_ID_TRANSFER_WORKBASKET_ID, "TKI:000000000000000000000000000000000003", "WBI:100000000000000000000000000000000006"); - ThrowingConsumer test = - setTransferFlag -> { - HttpEntity auth = + ThrowingConsumer> test = + pair -> { + HttpEntity auth = new HttpEntity<>( - setTransferFlag.toString(), RestHelper.generateHeadersForUser("admin")); + new TransferTaskRepresentationModel(pair.getLeft(), pair.getRight()), + RestHelper.generateHeadersForUser("admin")); ResponseEntity response = TEMPLATE.exchange(url, HttpMethod.POST, auth, TASK_MODEL_TYPE); assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getWorkbasketSummary().getWorkbasketId()) .isEqualTo("WBI:100000000000000000000000000000000006"); - assertThat(response.getBody().isTransferred()).isEqualTo(setTransferFlag); + assertThat(response.getBody().isTransferred()).isEqualTo(pair.getLeft()); + assertThat(response.getBody().getOwner()).isEqualTo(pair.getRight()); }; return DynamicTest.stream(iterator, c -> "for setTransferFlag: " + c, test); } @Test - void should_SetTransferFlagToTrue_When_TransferringWithoutRequestBody() { + void should_SetTransferFlagToTrueAndOwnerToNull_When_TransferringWithoutRequestBody() { String url = restHelper.toUrl( RestEndpoints.URL_TASKS_ID_TRANSFER_WORKBASKET_ID, @@ -2004,6 +2006,7 @@ void should_SetTransferFlagToTrue_When_TransferringWithoutRequestBody() { assertThat(response.getBody().getWorkbasketSummary().getWorkbasketId()) .isEqualTo("WBI:100000000000000000000000000000000006"); assertThat(response.getBody().isTransferred()).isTrue(); + assertThat(response.getBody().getOwner()).isNull(); } }