From 5f4923fe0a931ec290a4025deda6ad0dcd85b239 Mon Sep 17 00:00:00 2001 From: Mustapha Zorgati <15628173+mustaphazorgati@users.noreply.github.com> Date: Thu, 11 Aug 2022 16:45:03 +0200 Subject: [PATCH] TSK-1943: added REST endpoint for force requesting a review on a Task --- .../src/docs/asciidoc/rest-api.adoc | 1 + .../taskana/common/rest/RestEndpoints.java | 2 ++ .../pro/taskana/task/rest/TaskController.java | 21 ++++++++++++++ .../task/rest/TaskControllerIntTest.java | 29 +++++++++++++++++++ .../task/rest/TaskControllerRestDocTest.java | 11 +++++++ 5 files changed, 64 insertions(+) diff --git a/rest/taskana-rest-spring/src/docs/asciidoc/rest-api.adoc b/rest/taskana-rest-spring/src/docs/asciidoc/rest-api.adoc index 16dd780cd..50bacd5af 100644 --- a/rest/taskana-rest-spring/src/docs/asciidoc/rest-api.adoc +++ b/rest/taskana-rest-spring/src/docs/asciidoc/rest-api.adoc @@ -105,6 +105,7 @@ include::{snippets}/TaskControllerRestDocTest/selectAndClaimTaskDocTest/auto-sec include::{snippets}/TaskControllerRestDocTest/cancelClaimTaskDocTest/auto-section.adoc[] include::{snippets}/TaskControllerRestDocTest/forceCancelClaimTaskDocTest/auto-section.adoc[] include::{snippets}/TaskControllerRestDocTest/requestReviewTaskDocTest/auto-section.adoc[] +include::{snippets}/TaskControllerRestDocTest/forceRequestReviewTaskDocTest/auto-section.adoc[] include::{snippets}/TaskControllerRestDocTest/requestChangesTaskDocTest/auto-section.adoc[] include::{snippets}/TaskControllerRestDocTest/forceRequestChangesTaskDocTest/auto-section.adoc[] include::{snippets}/TaskControllerRestDocTest/completeTaskDocTest/auto-section.adoc[] diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/common/rest/RestEndpoints.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/common/rest/RestEndpoints.java index 191c676cd..1245cd418 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/common/rest/RestEndpoints.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/common/rest/RestEndpoints.java @@ -47,6 +47,8 @@ public final class RestEndpoints { public static final String URL_TASKS_ID_CLAIM_FORCE = API_V1 + "tasks/{taskId}/claim/force"; public static final String URL_TASKS_ID_SELECT_AND_CLAIM = API_V1 + "tasks/select-and-claim"; public static final String URL_TASKS_ID_REQUEST_REVIEW = API_V1 + "tasks/{taskId}/request-review"; + public static final String URL_TASKS_ID_REQUEST_REVIEW_FORCE = + API_V1 + "tasks/{taskId}/request-review/force"; public static final String URL_TASKS_ID_REQUEST_CHANGES = API_V1 + "tasks/{taskId}/request-changes"; public static final String URL_TASKS_ID_REQUEST_CHANGES_FORCE = 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 01de9e924..9e3bf85e1 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 @@ -224,6 +224,27 @@ public class TaskController { return ResponseEntity.ok(taskRepresentationModelAssembler.toModel(task)); } + /** + * This endpoint force request a review on the specified Task. + * + * @param taskId taskId the id of the relevant Task + * @return the Task after a review has been requested + * @throws InvalidTaskStateException if the state of the Task with taskId is not CLAIMED + * @throws TaskNotFoundException if the Task with taskId wasn't found + * @throws InvalidOwnerException cannot be thrown + * @throws NotAuthorizedException if the current user has no READ permissions for the Workbasket + * the Task is in + * @title Force request a review on a Task + */ + @PostMapping(path = RestEndpoints.URL_TASKS_ID_REQUEST_REVIEW_FORCE) + @Transactional(rollbackFor = Exception.class) + public ResponseEntity forceRequestReview(@PathVariable String taskId) + throws InvalidTaskStateException, TaskNotFoundException, InvalidOwnerException, + NotAuthorizedException { + Task task = taskService.forceRequestReview(taskId); + return ResponseEntity.ok(taskRepresentationModelAssembler.toModel(task)); + } + /** * This endpoint request changes on the specified Task. * 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 147670f62..fd27aee1c 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 @@ -1420,6 +1420,35 @@ class TaskControllerIntTest { assertThat(repModel.getState()).isEqualTo(TaskState.READY_FOR_REVIEW); } + @Test + void should_ForceRequestReview_When_CurrentUserIsNotTheOwner() { + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS_ID, "TKI:000000000000000000000000000000000101"); + HttpEntity auth = new HttpEntity<>(RestHelper.generateHeadersForUser("user-1-1")); + + // retrieve task from Rest Api + ResponseEntity getTaskResponse = + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_MODEL_TYPE); + assertThat(getTaskResponse.getBody()).isNotNull(); + TaskRepresentationModel repModel = getTaskResponse.getBody(); + assertThat(repModel.getState()).isEqualTo(TaskState.CLAIMED); + assertThat(repModel.getOwner()).isEqualTo("user-1-2"); + + // request review + String url2 = + restHelper.toUrl( + RestEndpoints.URL_TASKS_ID_REQUEST_REVIEW_FORCE, + "TKI:000000000000000000000000000000000101"); + ResponseEntity requestReviewResponse = + TEMPLATE.exchange(url2, HttpMethod.POST, auth, TASK_MODEL_TYPE); + + assertThat(requestReviewResponse.getBody()).isNotNull(); + assertThat(requestReviewResponse.getStatusCode()).isEqualTo(HttpStatus.OK); + repModel = requestReviewResponse.getBody(); + assertThat(repModel.getOwner()).isNull(); + assertThat(repModel.getState()).isEqualTo(TaskState.READY_FOR_REVIEW); + } + @Test void should_RequestChangesOnATask() { String url = diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/task/rest/TaskControllerRestDocTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/task/rest/TaskControllerRestDocTest.java index baf1f9e5a..dee27db4a 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/task/rest/TaskControllerRestDocTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/task/rest/TaskControllerRestDocTest.java @@ -91,6 +91,17 @@ class TaskControllerRestDocTest extends BaseRestDocTest { .andExpect(MockMvcResultMatchers.status().isOk()); } + @Test + void forceRequestReviewTaskDocTest() throws Exception { + mockMvc + .perform( + post( + RestEndpoints.URL_TASKS_ID_REQUEST_REVIEW_FORCE, + "TKI:000000000000000000000000000000000101") + .headers(RestHelper.generateHeadersForUser("user-1-2"))) + .andExpect(MockMvcResultMatchers.status().isOk()); + } + @Test void requestChangesTaskDocTest() throws Exception { mockMvc