TSK-1943: added REST endpoint for force requesting changes on a Task
This commit is contained in:
parent
bbb01653f5
commit
6997d64083
|
@ -159,9 +159,10 @@ public interface TaskService {
|
|||
*
|
||||
* @param taskId the {@linkplain Task#getId() id} of the specified {@linkplain Task}
|
||||
* @return the {@linkplain Task} after changes have been requested
|
||||
* @throws InvalidTaskStateException cannot be thrown
|
||||
* @throws InvalidTaskStateException if the {@linkplain Task#getState() state} of the {@linkplain
|
||||
* Task} with taskId is one of the {@linkplain TaskState#END_STATES}
|
||||
* @throws TaskNotFoundException if the {@linkplain Task} with taskId wasn't found
|
||||
* @throws InvalidOwnerException if the {@linkplain Task} is claimed by another user
|
||||
* @throws InvalidOwnerException cannot be thrown
|
||||
* @throws NotAuthorizedException if the current user has no {@linkplain
|
||||
* WorkbasketPermission#READ} for the {@linkplain Workbasket} the {@linkplain Task} is in
|
||||
*/
|
||||
|
|
|
@ -106,6 +106,7 @@ include::{snippets}/TaskControllerRestDocTest/cancelClaimTaskDocTest/auto-sectio
|
|||
include::{snippets}/TaskControllerRestDocTest/forceCancelClaimTaskDocTest/auto-section.adoc[]
|
||||
include::{snippets}/TaskControllerRestDocTest/requestReviewTaskDocTest/auto-section.adoc[]
|
||||
include::{snippets}/TaskControllerRestDocTest/requestChangesTaskDocTest/auto-section.adoc[]
|
||||
include::{snippets}/TaskControllerRestDocTest/forceRequestChangesTaskDocTest/auto-section.adoc[]
|
||||
include::{snippets}/TaskControllerRestDocTest/completeTaskDocTest/auto-section.adoc[]
|
||||
include::{snippets}/TaskControllerRestDocTest/cancelTaskDocTest/auto-section.adoc[]
|
||||
include::{snippets}/TaskControllerRestDocTest/transferTaskDocTest/auto-section.adoc[]
|
||||
|
|
|
@ -49,6 +49,8 @@ public final class RestEndpoints {
|
|||
public static final String URL_TASKS_ID_REQUEST_REVIEW = API_V1 + "tasks/{taskId}/request-review";
|
||||
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 =
|
||||
API_V1 + "tasks/{taskId}/request-changes/force";
|
||||
public static final String URL_TASKS_ID_COMPLETE = API_V1 + "tasks/{taskId}/complete";
|
||||
public static final String URL_TASKS_ID_CANCEL = API_V1 + "tasks/{taskId}/cancel";
|
||||
public static final String URL_TASKS_ID_TRANSFER_WORKBASKET_ID =
|
||||
|
|
|
@ -245,6 +245,27 @@ public class TaskController {
|
|||
return ResponseEntity.ok(taskRepresentationModelAssembler.toModel(task));
|
||||
}
|
||||
|
||||
/**
|
||||
* This endpoint force requests changes on a Task.
|
||||
*
|
||||
* @param taskId the Id of the Task on which a review should be requested
|
||||
* @return the change requested Task
|
||||
* @throws InvalidTaskStateException if the Task with taskId is in an end state
|
||||
* @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 changes on a Task
|
||||
*/
|
||||
@PostMapping(path = RestEndpoints.URL_TASKS_ID_REQUEST_CHANGES_FORCE)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseEntity<TaskRepresentationModel> forceRequestChanges(@PathVariable String taskId)
|
||||
throws InvalidTaskStateException, TaskNotFoundException, InvalidOwnerException,
|
||||
NotAuthorizedException {
|
||||
Task task = taskService.forceRequestChanges(taskId);
|
||||
return ResponseEntity.ok(taskRepresentationModelAssembler.toModel(task));
|
||||
}
|
||||
|
||||
/**
|
||||
* This endpoint selects the first Task returned by the Task Query and claims it.
|
||||
*
|
||||
|
|
|
@ -1448,6 +1448,35 @@ class TaskControllerIntTest {
|
|||
assertThat(repModel.getState()).isEqualTo(TaskState.READY);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_ForceRequestChanges_When_CurrentUserIsNotTheOwner() {
|
||||
String url =
|
||||
restHelper.toUrl(RestEndpoints.URL_TASKS_ID, "TKI:000000000000000000000000000000000100");
|
||||
HttpEntity<Object> auth = new HttpEntity<>(RestHelper.generateHeadersForUser("user-1-1"));
|
||||
|
||||
// retrieve task from Rest Api
|
||||
ResponseEntity<TaskRepresentationModel> 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 changes
|
||||
String url2 =
|
||||
restHelper.toUrl(
|
||||
RestEndpoints.URL_TASKS_ID_REQUEST_CHANGES_FORCE,
|
||||
"TKI:000000000000000000000000000000000100");
|
||||
ResponseEntity<TaskRepresentationModel> requestedChangesResponse =
|
||||
TEMPLATE.exchange(url2, HttpMethod.POST, auth, TASK_MODEL_TYPE);
|
||||
|
||||
assertThat(requestedChangesResponse.getBody()).isNotNull();
|
||||
assertThat(requestedChangesResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
repModel = requestedChangesResponse.getBody();
|
||||
assertThat(repModel.getOwner()).isNull();
|
||||
assertThat(repModel.getState()).isEqualTo(TaskState.READY);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_UpdateTaskOwnerOfReadyTask() {
|
||||
final String url = restHelper.toUrl("/api/v1/tasks/TKI:000000000000000000000000000000000025");
|
||||
|
|
|
@ -102,6 +102,17 @@ class TaskControllerRestDocTest extends BaseRestDocTest {
|
|||
.andExpect(MockMvcResultMatchers.status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void forceRequestChangesTaskDocTest() throws Exception {
|
||||
mockMvc
|
||||
.perform(
|
||||
post(
|
||||
RestEndpoints.URL_TASKS_ID_REQUEST_CHANGES_FORCE,
|
||||
"TKI:000000000000000000000000000000000100")
|
||||
.headers(RestHelper.generateHeadersForUser("user-1-1")))
|
||||
.andExpect(MockMvcResultMatchers.status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void selectAndClaimTaskDocTest() throws Exception {
|
||||
mockMvc
|
||||
|
|
Loading…
Reference in New Issue