TSK-429: added task update to and integration test to task rest service.
This commit is contained in:
parent
1d05470aff
commit
6e075bce6b
|
@ -434,7 +434,6 @@ public interface QueryMapper {
|
|||
+ "<if test='custom16In != null'>AND t.CUSTOM_16 IN(<foreach item='item' collection='custom16In' separator=',' >#{item}</foreach>)</if> "
|
||||
+ "<if test='custom16Like != null'>AND (<foreach item='item' collection='custom16Like' separator=' OR '>UPPER(t.CUSTOM_16) LIKE #{item}</foreach>)</if> "
|
||||
+ "</where>"
|
||||
+ "<if test='!orderBy.isEmpty()'>ORDER BY <foreach item='item' collection='orderBy' separator=',' >${item}</foreach></if> "
|
||||
+ "<if test=\"_databaseId == 'db2'\">with UR </if> "
|
||||
+ "</script>")
|
||||
Long countQueryTasks(TaskQueryImpl taskQuery);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
-- TASK TABLE (ID , CREATED , CLAIMED , COMPLETED , modified , planned , due , name , creator , description , note , priority, state , classification_category , classification_key, classification_id , workbasket_id , workbasket_key, domain , business_process_id, parent_business_process_id, owner , por_company , por_system , por_system_instance, por_type , por_value , is_read, is_transferred, custom_attributes, custom1, custom2, custom3, custom4, custom5, custom6, custom7, custom8, custom9, custom10, custom11, custom12, custom13, custom14, custom15, custom16
|
||||
-- TASK TABLE (ID , CREATED , CLAIMED , COMPLETED , modified , planned , due , name , creator , description , note , priority, state , classification_category , classification_key, classification_id , workbasket_id , workbasket_key, domain , business_process_id, parent_business_process_id, owner , por_company , por_system , por_system_instance, por_type , por_value , is_read, is_transferred, custom_attributes, custom1, custom2, custom3, custom4, custom5, custom6, custom7, custom8, custom9, custom10, custom11, custom12, custom13, custom14, custom15, custom16
|
||||
INSERT INTO TASKANA.TASK VALUES('TKI:000000000000000000000000000000000000', '2018-01-29 15:55:00', '2018-01-30 15:55:00', null , '2018-01-30 15:55:00', '2018-01-29 15:55:00', '2018-01-30 15:55:00', 'Task99' , 'creator_user_id' , 'Lorem ipsum was n Quatsch dolor sit amet.', 'Some custom Note' , 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 , null , null , null , null , null , null , null , null , null , null , null , null , null , 'abc' , null , null );
|
||||
INSERT INTO TASKANA.TASK VALUES('TKI:000000000000000000000000000000000001', '2018-01-29 15:55:01', '2018-01-30 15:55:00', null , '2018-01-30 15:55:01', '2018-01-29 15:55:00', '2018-01-30 15:55:00', 'Task01' , 'creator_user_id' , 'Lorem ipsum was n Quatsch dolor sit amet.', 'Some custom Note' , 2 , '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 , 'pqr' , null , null , null , null , null , null , null , null , null , null , null , null , 'abc' , null , null );
|
||||
INSERT INTO TASKANA.TASK VALUES('TKI:000000000000000000000000000000000002', '2018-01-29 15:55:02', '2018-01-30 15:55:00', null , '2018-01-30 15:55:02', '2018-01-29 15:55:00', '2018-01-30 15:55:00', 'Task02' , 'creator_user_id' , 'Lorem ipsum was n Quatsch t. Aber stimmt.', 'Some custom Note' , 2 , '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 , null , null , null , null , null , null , null , null , null , null , null , null , null , 'abc' , null , null );
|
||||
|
@ -72,3 +72,5 @@ INSERT INTO TASKANA.TASK VALUES('TKI:000000000000000000000000000000000062', '201
|
|||
INSERT INTO TASKANA.TASK VALUES('TKI:000000000000000000000000000000000063', '2018-01-29 15:55:22', null , null , '2018-01-29 15:55:22', '2018-01-29 15:55:00', '2018-01-30 15:55:00', 'Widerruf' , 'creator_user_id' , 'Widerruf' , null , 2 , 'READY' , 'EXTERN' , 'L1060' , 'CLI:200000000000000000000000000000000017', 'WBI:100000000000000000000000000000000015' , 'USER_3_2' , 'DOMAIN_B', 'PI_0000000000022' , 'DOC_0000000000000000022' , null , '00' , 'PASystem' , '00' , 'SDNR' , '11223344' , false , false , null , null , null , null , null , null , null , null , null , null , null , null , null , null , 'abc' , null , null );
|
||||
INSERT INTO TASKANA.TASK VALUES('TKI:000000000000000000000000000000000064', '2018-01-29 15:55:23', null , null , '2018-01-29 15:55:23', '2018-01-29 15:55:00', '2018-01-30 15:55:00', 'Widerruf' , 'creator_user_id' , 'Widerruf' , null , 2 , 'READY' , 'EXTERN' , 'L1060' , 'CLI:200000000000000000000000000000000017', 'WBI:100000000000000000000000000000000015' , 'USER_3_2' , 'DOMAIN_B', 'PI_0000000000020' , 'DOC_0000000000000000021' , null , '00' , 'PASystem' , '00' , 'SDNR' , '11223344' , false , false , null , null , null , null , null , null , null , null , null , null , null , null , null , null , 'abc' , null , null );
|
||||
INSERT INTO TASKANA.TASK VALUES('TKI:000000000000000000000000000000000065', '2018-01-29 15:55:24', null , null , '2018-01-29 15:55:24', '2018-01-29 15:55:00', '2018-01-30 15:55:00', 'Widerruf' , 'creator_user_id' , 'Widerruf' , null , 2 , 'READY' , 'EXTERN' , 'L1060' , 'CLI:200000000000000000000000000000000017', 'WBI:100000000000000000000000000000000015' , 'USER_3_2' , 'DOMAIN_B', 'PI_0000000000024' , 'DOC_0000000000000000024' , null , '00' , 'PASystem' , '00' , 'SDNR' , '11223344' , false , false , null , null , null , null , null , null , null , null , null , null , null , null , null , null , 'abc' , null , null );
|
||||
-- Tasks for TaskControllerIntTest
|
||||
INSERT INTO TASKANA.TASK VALUES('TKI:100000000000000000000000000000000000', '2018-01-29 15:55:00', '2018-01-30 15:55:00', null , '2018-01-30 15:55:00', '2018-01-29 15:55:00', '2018-01-30 15:55:00', 'Dynamikänderung' , 'creator_user_id' , 'Desc Dynamikänderung' , 'Some custom Note' , 1 , 'CLAIMED' , 'AUTOMATIC' , 'T6310' , 'CLI:100000000000000000000000000000000004', 'WBI:100000000000000000000000000000000004' , 'TEAMLEAD_1' , 'DOMAIN_A', 'BPI21' , 'PBPI21' , 'user_3_1' , 'MyCompany1', 'MySystem1', 'MyInstance1' , 'MyType1', '00000001' , true , false , null , null , null , null , null , null , null , null , null , null , null , null , null , null , 'abc' , null , null );
|
||||
|
|
|
@ -1,12 +1,19 @@
|
|||
package pro.taskana.rest;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
@ -51,7 +58,7 @@ public class TaskControllerIntTest {
|
|||
new ParameterizedTypeReference<PagedResources<TaskSummaryResource>>() {
|
||||
});
|
||||
assertNotNull(response.getBody().getLink(Link.REL_SELF));
|
||||
assertEquals(22, response.getBody().getContent().size());
|
||||
assertEquals(23, response.getBody().getContent().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -65,7 +72,7 @@ public class TaskControllerIntTest {
|
|||
new ParameterizedTypeReference<PagedResources<TaskSummaryResource>>() {
|
||||
});
|
||||
assertNotNull(response.getBody().getLink(Link.REL_SELF));
|
||||
assertEquals(70, response.getBody().getContent().size());
|
||||
assertEquals(71, response.getBody().getContent().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -87,26 +94,25 @@ public class TaskControllerIntTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testGetLastPageSortedByDue() {
|
||||
RestTemplate template = getRestTemplate();
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Authorization", "Basic YWRtaW46YWRtaW4="); // Role Admin
|
||||
HttpEntity<String> request = new HttpEntity<String>(headers);
|
||||
ResponseEntity<PagedResources<TaskSummaryResource>> response = template.exchange(
|
||||
"http://127.0.0.1:" + port + "/v1/tasks?sortBy=due&order=desc&page=14&pageSize=5", HttpMethod.GET,
|
||||
"http://127.0.0.1:" + port + "/v1/tasks?sortBy=por.value&order=desc&page=15&pageSize=5", HttpMethod.GET,
|
||||
request,
|
||||
new ParameterizedTypeReference<PagedResources<TaskSummaryResource>>() {
|
||||
});
|
||||
assertEquals(5, response.getBody().getContent().size());
|
||||
assertTrue(response.getBody().getLink(Link.REL_LAST).getHref().contains("page=14"));
|
||||
assertEquals("TKI:000000000000000000000000000000000004",
|
||||
assertEquals(1, response.getBody().getContent().size());
|
||||
assertTrue(response.getBody().getLink(Link.REL_LAST).getHref().contains("page=15"));
|
||||
assertEquals("TKI:100000000000000000000000000000000000",
|
||||
response.getBody().getContent().iterator().next().getTaskId());
|
||||
assertNotNull(response.getBody().getLink(Link.REL_SELF));
|
||||
assertTrue(response.getBody()
|
||||
.getLink(Link.REL_SELF)
|
||||
.getHref()
|
||||
.endsWith("/v1/tasks?sortBy=due&order=desc&page=14&pageSize=5"));
|
||||
.endsWith("/v1/tasks?sortBy=por.value&order=desc&page=15&pageSize=5"));
|
||||
assertNotNull(response.getBody().getLink("allTasks"));
|
||||
assertTrue(response.getBody()
|
||||
.getLink("allTasks")
|
||||
|
@ -129,15 +135,14 @@ public class TaskControllerIntTest {
|
|||
request,
|
||||
new ParameterizedTypeReference<PagedResources<TaskSummaryResource>>() {
|
||||
});
|
||||
int size = response.getBody().getContent().size();
|
||||
assertEquals(22, response.getBody().getContent().size());
|
||||
assertEquals(23, response.getBody().getContent().size());
|
||||
|
||||
response = template.exchange(
|
||||
"http://127.0.0.1:" + port + "/v1/tasks?sortBy=due&order=desc&page=5&pageSize=5", HttpMethod.GET,
|
||||
"http://127.0.0.1:" + port + "/v1/tasks?sortBy=por.value&order=desc&page=5&pageSize=5", HttpMethod.GET,
|
||||
request,
|
||||
new ParameterizedTypeReference<PagedResources<TaskSummaryResource>>() {
|
||||
});
|
||||
assertEquals(2, response.getBody().getContent().size());
|
||||
assertEquals(3, response.getBody().getContent().size());
|
||||
assertTrue(response.getBody().getLink(Link.REL_LAST).getHref().contains("page=5"));
|
||||
assertEquals("TKI:000000000000000000000000000000000023",
|
||||
response.getBody().getContent().iterator().next().getTaskId());
|
||||
|
@ -145,7 +150,7 @@ public class TaskControllerIntTest {
|
|||
assertTrue(response.getBody()
|
||||
.getLink(Link.REL_SELF)
|
||||
.getHref()
|
||||
.endsWith("/v1/tasks?sortBy=due&order=desc&page=5&pageSize=5"));
|
||||
.endsWith("/v1/tasks?sortBy=por.value&order=desc&page=5&pageSize=5"));
|
||||
assertNotNull(response.getBody().getLink("allTasks"));
|
||||
assertTrue(response.getBody()
|
||||
.getLink("allTasks")
|
||||
|
@ -157,7 +162,6 @@ public class TaskControllerIntTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testGetQueryByPorSecondPageSortedByType() {
|
||||
RestTemplate template = getRestTemplate();
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
@ -165,18 +169,20 @@ public class TaskControllerIntTest {
|
|||
HttpEntity<String> request = new HttpEntity<String>(headers);
|
||||
ResponseEntity<PagedResources<TaskSummaryResource>> response = template.exchange(
|
||||
"http://127.0.0.1:" + port
|
||||
+ "/v1/tasks?porCompany=00&porSystem=PASystem&porInstance=00&porType=VNR&porValue=22334455&sortBy=porType&order=asc&page=2&pageSize=5",
|
||||
+ "/v1/tasks?por.company=00&por.system=PASystem&por.instance=00&por.type=VNR&por.value=22334455&sortBy=por.type&order=asc&page=2&pageSize=5",
|
||||
HttpMethod.GET,
|
||||
request,
|
||||
new ParameterizedTypeReference<PagedResources<TaskSummaryResource>>() {
|
||||
});
|
||||
assertEquals(5, response.getBody().getContent().size());
|
||||
assertEquals("USER_1_1", response.getBody().getContent().iterator().next().getTaskId());
|
||||
assertEquals(1, response.getBody().getContent().size());
|
||||
assertEquals("TKI:000000000000000000000000000000000013",
|
||||
response.getBody().getContent().iterator().next().getTaskId());
|
||||
assertNotNull(response.getBody().getLink(Link.REL_SELF));
|
||||
assertTrue(response.getBody()
|
||||
.getLink(Link.REL_SELF)
|
||||
.getHref()
|
||||
.endsWith("/v1/tasks?sortBy=due&order=desc&page=2&pageSize=5"));
|
||||
.endsWith(
|
||||
"/v1/tasks?por.company=00&por.system=PASystem&por.instance=00&por.type=VNR&por.value=22334455&sortBy=por.type&order=asc&page=2&pageSize=5"));
|
||||
assertNotNull(response.getBody().getLink("allTasks"));
|
||||
assertTrue(response.getBody()
|
||||
.getLink("allTasks")
|
||||
|
@ -184,10 +190,62 @@ public class TaskControllerIntTest {
|
|||
.endsWith("/v1/tasks"));
|
||||
assertNotNull(response.getBody().getLink(Link.REL_FIRST));
|
||||
assertNotNull(response.getBody().getLink(Link.REL_LAST));
|
||||
assertNotNull(response.getBody().getLink(Link.REL_NEXT));
|
||||
assertNotNull(response.getBody().getLink(Link.REL_PREVIOUS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAndUpdateTask() throws IOException {
|
||||
URL url = new URL("http://127.0.0.1:" + port + "/v1/tasks/TKI:100000000000000000000000000000000000");
|
||||
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
con.setRequestProperty("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x");
|
||||
assertEquals(200, con.getResponseCode());
|
||||
|
||||
BufferedReader in = new BufferedReader(
|
||||
new InputStreamReader(con.getInputStream()));
|
||||
String inputLine;
|
||||
StringBuffer content = new StringBuffer();
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
content.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
con.disconnect();
|
||||
String originalTask = content.toString();
|
||||
|
||||
con = (HttpURLConnection) url.openConnection();
|
||||
con.setRequestMethod("PUT");
|
||||
con.setDoOutput(true);
|
||||
con.setRequestProperty("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x");
|
||||
con.setRequestProperty("Content-Type", "application/json");
|
||||
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(con.getOutputStream()));
|
||||
out.write(content.toString());
|
||||
out.flush();
|
||||
out.close();
|
||||
assertEquals(200, con.getResponseCode());
|
||||
con.disconnect();
|
||||
|
||||
url = new URL("http://127.0.0.1:" + port + "/v1/tasks/TKI:100000000000000000000000000000000000");
|
||||
con = (HttpURLConnection) url.openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
con.setRequestProperty("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x");
|
||||
assertEquals(200, con.getResponseCode());
|
||||
|
||||
in = new BufferedReader(
|
||||
new InputStreamReader(con.getInputStream()));
|
||||
content = new StringBuffer();
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
content.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
con.disconnect();
|
||||
String updatedTask = content.toString();
|
||||
|
||||
assertNotEquals(
|
||||
originalTask.substring(originalTask.indexOf("modified"), originalTask.indexOf("modified") + 30),
|
||||
updatedTask.substring(updatedTask.indexOf("modified"), updatedTask.indexOf("modified") + 30));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a REST template which is capable of dealing with responses in HAL format
|
||||
*
|
||||
|
@ -200,6 +258,7 @@ public class TaskControllerIntTest {
|
|||
|
||||
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
|
||||
converter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json"));
|
||||
// converter.setSupportedMediaTypes(ImmutableList.of(MediaTypes.HAL_JSON));
|
||||
converter.setObjectMapper(mapper);
|
||||
|
||||
RestTemplate template = new RestTemplate(Collections.<HttpMessageConverter<?>> singletonList(converter));
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.springframework.util.MultiValueMap;
|
|||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
@ -30,7 +31,9 @@ import pro.taskana.TaskQuery;
|
|||
import pro.taskana.TaskService;
|
||||
import pro.taskana.TaskState;
|
||||
import pro.taskana.TaskSummary;
|
||||
import pro.taskana.exceptions.AttachmentPersistenceException;
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.ConcurrencyException;
|
||||
import pro.taskana.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.exceptions.InvalidOwnerException;
|
||||
import pro.taskana.exceptions.InvalidStateException;
|
||||
|
@ -81,6 +84,9 @@ public class TaskController extends AbstractPagingController {
|
|||
@Autowired
|
||||
private TaskService taskService;
|
||||
|
||||
@Autowired
|
||||
private TaskResourceAssembler taskResourceAssembler;
|
||||
|
||||
@GetMapping
|
||||
@Transactional(readOnly = true, rollbackFor = Exception.class)
|
||||
public ResponseEntity<PagedResources<TaskSummaryResource>> getTasks(
|
||||
|
@ -120,7 +126,6 @@ public class TaskController extends AbstractPagingController {
|
|||
public ResponseEntity<TaskResource> getTask(@PathVariable String taskId)
|
||||
throws TaskNotFoundException, NotAuthorizedException {
|
||||
Task task = taskService.getTask(taskId);
|
||||
TaskResourceAssembler taskResourceAssembler = new TaskResourceAssembler();
|
||||
ResponseEntity<TaskResource> result = new ResponseEntity<>(taskResourceAssembler.toResource(task),
|
||||
HttpStatus.OK);
|
||||
return result;
|
||||
|
@ -133,7 +138,6 @@ public class TaskController extends AbstractPagingController {
|
|||
// TODO verify user
|
||||
taskService.claim(taskId);
|
||||
Task updatedTask = taskService.getTask(taskId);
|
||||
TaskResourceAssembler taskResourceAssembler = new TaskResourceAssembler();
|
||||
ResponseEntity<TaskResource> result = new ResponseEntity<>(taskResourceAssembler.toResource(updatedTask),
|
||||
HttpStatus.OK);
|
||||
return result;
|
||||
|
@ -145,7 +149,6 @@ public class TaskController extends AbstractPagingController {
|
|||
throws TaskNotFoundException, InvalidOwnerException, InvalidStateException, NotAuthorizedException {
|
||||
taskService.completeTask(taskId, true);
|
||||
Task updatedTask = taskService.getTask(taskId);
|
||||
TaskResourceAssembler taskResourceAssembler = new TaskResourceAssembler();
|
||||
ResponseEntity<TaskResource> result = new ResponseEntity<>(taskResourceAssembler.toResource(updatedTask),
|
||||
HttpStatus.OK);
|
||||
return result;
|
||||
|
@ -157,7 +160,6 @@ public class TaskController extends AbstractPagingController {
|
|||
throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException,
|
||||
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException {
|
||||
Task createdTask = taskService.createTask(task);
|
||||
TaskResourceAssembler taskResourceAssembler = new TaskResourceAssembler();
|
||||
ResponseEntity<TaskResource> result = new ResponseEntity<>(taskResourceAssembler.toResource(createdTask),
|
||||
HttpStatus.CREATED);
|
||||
return result;
|
||||
|
@ -168,12 +170,33 @@ public class TaskController extends AbstractPagingController {
|
|||
public ResponseEntity<TaskResource> transferTask(@PathVariable String taskId, @PathVariable String workbasketKey)
|
||||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException {
|
||||
Task updatedTask = taskService.transfer(taskId, workbasketKey);
|
||||
TaskResourceAssembler taskResourceAssembler = new TaskResourceAssembler();
|
||||
ResponseEntity<TaskResource> result = new ResponseEntity<>(taskResourceAssembler.toResource(updatedTask),
|
||||
HttpStatus.OK);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PutMapping(path = "/{taskId}")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseEntity<TaskResource> updateTask(
|
||||
@PathVariable(value = "taskId") String taskId,
|
||||
@RequestBody TaskResource taskResource) throws TaskNotFoundException, WorkbasketNotFoundException,
|
||||
ClassificationNotFoundException, InvalidArgumentException, ConcurrencyException, InvalidWorkbasketException,
|
||||
NotAuthorizedException, AttachmentPersistenceException {
|
||||
ResponseEntity<TaskResource> result;
|
||||
if (taskId.equals(taskResource.getTaskId())) {
|
||||
Task task = taskResourceAssembler.toModel(taskResource);
|
||||
task = taskService.updateTask(task);
|
||||
result = ResponseEntity.ok(taskResourceAssembler.toResource(task));
|
||||
} else {
|
||||
throw new InvalidArgumentException(
|
||||
"TaskId ('" + taskId
|
||||
+ "') is not identical with the taskId of to object in the payload which should be updated. ID=('"
|
||||
+ taskResource.getTaskId() + "')");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private TaskQuery applyFilterParams(TaskQuery taskQuery, MultiValueMap<String, String> params)
|
||||
throws NotAuthorizedException, InvalidArgumentException {
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import pro.taskana.TaskState;
|
|||
import pro.taskana.impl.ObjectReference;
|
||||
|
||||
/**
|
||||
* Resource class for {@link pro.taskana.WorkbasketSummary}.
|
||||
* Resource class for {@link pro.taskana.Task}.
|
||||
*/
|
||||
public class TaskResource extends ResourceSupport {
|
||||
|
||||
|
|
|
@ -1,18 +1,26 @@
|
|||
package pro.taskana.rest.resource.mapper;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.hateoas.mvc.ResourceAssemblerSupport;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import pro.taskana.ClassificationService;
|
||||
import pro.taskana.ClassificationSummary;
|
||||
import pro.taskana.impl.ClassificationImpl;
|
||||
import pro.taskana.rest.ClassificationController;
|
||||
import pro.taskana.rest.resource.ClassificationSummaryResource;
|
||||
|
||||
/**
|
||||
* Resource assembler for {@link ClassificationSummaryResource}.
|
||||
*/
|
||||
@Component
|
||||
public class ClassificationSummaryResourceAssembler
|
||||
extends ResourceAssemblerSupport<ClassificationSummary, ClassificationSummaryResource> {
|
||||
|
||||
@Autowired
|
||||
private ClassificationService classificationService;
|
||||
|
||||
public ClassificationSummaryResourceAssembler() {
|
||||
super(ClassificationController.class, ClassificationSummaryResource.class);
|
||||
}
|
||||
|
@ -27,4 +35,14 @@ public class ClassificationSummaryResourceAssembler
|
|||
return resource;
|
||||
}
|
||||
|
||||
public ClassificationSummary toModel(ClassificationSummaryResource resource) {
|
||||
ClassificationImpl classification = (ClassificationImpl) classificationService
|
||||
.newClassification(
|
||||
resource.getKey(), resource.getDomain(),
|
||||
resource.getType());
|
||||
classification.setId(resource.getClassificationId());
|
||||
BeanUtils.copyProperties(resource, classification);
|
||||
return classification.asSummary();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,20 +1,33 @@
|
|||
package pro.taskana.rest.resource.mapper;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.hateoas.mvc.ResourceAssemblerSupport;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import pro.taskana.Task;
|
||||
import pro.taskana.TaskService;
|
||||
import pro.taskana.impl.TaskImpl;
|
||||
import pro.taskana.rest.TaskController;
|
||||
import pro.taskana.rest.resource.TaskResource;
|
||||
|
||||
/**
|
||||
* Resource assembler for {@link TaskResource}.
|
||||
*/
|
||||
@Component
|
||||
public class TaskResourceAssembler
|
||||
extends ResourceAssemblerSupport<Task, TaskResource> {
|
||||
|
||||
private WorkbasketSummaryResourceAssembler workbasketAssembler = new WorkbasketSummaryResourceAssembler();
|
||||
private ClassificationSummaryResourceAssembler classificationAssembler = new ClassificationSummaryResourceAssembler();
|
||||
@Autowired
|
||||
private TaskService taskService;
|
||||
|
||||
@Autowired
|
||||
private ClassificationSummaryResourceAssembler classificationAssembler;
|
||||
|
||||
@Autowired
|
||||
private WorkbasketSummaryResourceAssembler workbasketAssembler;
|
||||
|
||||
public TaskResourceAssembler() {
|
||||
super(TaskController.class, TaskResource.class);
|
||||
|
@ -46,4 +59,28 @@ public class TaskResourceAssembler
|
|||
return resource;
|
||||
}
|
||||
|
||||
public Task toModel(TaskResource resource) {
|
||||
TaskImpl task = (TaskImpl) taskService.newTask(resource.getWorkbasketSummaryResource().getWorkbasketId());
|
||||
task.setId(resource.getTaskId());
|
||||
BeanUtils.copyProperties(resource, task);
|
||||
if (resource.getCreated() != null) {
|
||||
task.setCreated(Instant.parse(resource.getCreated()));
|
||||
}
|
||||
if (resource.getModified() != null) {
|
||||
task.setModified(Instant.parse(resource.getModified().toString()));
|
||||
}
|
||||
if (resource.getClaimed() != null) {
|
||||
task.setClaimed(Instant.parse(resource.getClaimed().toString()));
|
||||
}
|
||||
if (resource.getCompleted() != null) {
|
||||
task.setCompleted(Instant.parse(resource.getCompleted().toString()));
|
||||
}
|
||||
if (resource.getDue() != null) {
|
||||
task.setDue(Instant.parse(resource.getDue().toString()));
|
||||
}
|
||||
task.setClassificationSummary(classificationAssembler.toModel(resource.getClassificationSummaryResource()));
|
||||
task.setWorkbasketSummary(workbasketAssembler.toModel(resource.getWorkbasketSummaryResource()));
|
||||
return task;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +1,26 @@
|
|||
package pro.taskana.rest.resource.mapper;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.hateoas.mvc.ResourceAssemblerSupport;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import pro.taskana.WorkbasketService;
|
||||
import pro.taskana.WorkbasketSummary;
|
||||
import pro.taskana.impl.WorkbasketImpl;
|
||||
import pro.taskana.rest.WorkbasketController;
|
||||
import pro.taskana.rest.resource.WorkbasketSummaryResource;
|
||||
|
||||
/**
|
||||
* @author HH
|
||||
*/
|
||||
@Component
|
||||
public class WorkbasketSummaryResourceAssembler
|
||||
extends ResourceAssemblerSupport<WorkbasketSummary, WorkbasketSummaryResource> {
|
||||
|
||||
@Autowired
|
||||
private WorkbasketService workbasketService;
|
||||
|
||||
public WorkbasketSummaryResourceAssembler() {
|
||||
super(WorkbasketController.class, WorkbasketSummaryResource.class);
|
||||
}
|
||||
|
@ -26,4 +34,12 @@ public class WorkbasketSummaryResourceAssembler
|
|||
return resource;
|
||||
}
|
||||
|
||||
public WorkbasketSummary toModel(WorkbasketSummaryResource resource) {
|
||||
WorkbasketImpl workbasket = (WorkbasketImpl) workbasketService
|
||||
.newWorkbasket(resource.getKey(), resource.getDomain());
|
||||
workbasket.setId(resource.getWorkbasketId());
|
||||
BeanUtils.copyProperties(resource, workbasket);
|
||||
return workbasket.asSummary();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue