From 42d8739a672e3cce4311b17ffbdc31302f5c26c6 Mon Sep 17 00:00:00 2001 From: Marcel Lengl <52546181+LenglBoy@users.noreply.github.com> Date: Tue, 27 Feb 2018 11:27:25 +0100 Subject: [PATCH] TSK-226: Enable HATEOAS on REST at least for Workbasket --- .../rest/ClassificationController.java | 57 ++++++++++++------- .../pro/taskana/rest/RestConfiguration.java | 6 +- .../taskana/rest/WorkbasketController.java | 18 ++++-- .../rest/WorkbasketDefinitionController.java | 8 +-- .../pro/taskana/rest/query/TaskFilter.java | 4 -- .../rest/resource/WorkbasketDefinition.java | 1 - .../resource/mapper/ClassificationMapper.java | 29 +++++++++- .../mapper/WorkbasketAccessItemMapper.java | 33 ++++++++--- .../mapper/WorkbasketDefinitionMapper.java | 52 +++++++++++++---- .../resource/mapper/WorkbasketMapper.java | 21 +++++-- .../mapper/WorkbasketSummaryMapper.java | 12 ++-- .../WorkbasketAccessItemMapperTest.java | 21 ++++--- .../resource/mapper/WorkbasketMapperTest.java | 2 +- 13 files changed, 186 insertions(+), 78 deletions(-) diff --git a/rest/src/main/java/pro/taskana/rest/ClassificationController.java b/rest/src/main/java/pro/taskana/rest/ClassificationController.java index 01099ea00..396295fe5 100644 --- a/rest/src/main/java/pro/taskana/rest/ClassificationController.java +++ b/rest/src/main/java/pro/taskana/rest/ClassificationController.java @@ -22,6 +22,11 @@ import org.springframework.web.bind.annotation.RestController; import pro.taskana.Classification; import pro.taskana.ClassificationService; import pro.taskana.ClassificationSummary; +import pro.taskana.exceptions.ClassificationAlreadyExistException; +import pro.taskana.exceptions.ClassificationNotFoundException; +import pro.taskana.exceptions.NotAuthorizedException; +import pro.taskana.rest.resource.ClassificationResource; +import pro.taskana.rest.resource.mapper.ClassificationMapper; @RestController @RequestMapping(path = "/v1/classifications", produces = {MediaType.APPLICATION_JSON_VALUE}) @@ -30,6 +35,9 @@ public class ClassificationController { @Autowired private ClassificationService classificationService; + @Autowired + private ClassificationMapper classificationMapper; + @GetMapping @Transactional(readOnly = true, rollbackFor = Exception.class) public ResponseEntity> getClassifications() { @@ -42,52 +50,61 @@ public class ClassificationController { } } - @GetMapping(path = "/{classificationKey}") + @GetMapping(path = "/{classificationId}") @Transactional(readOnly = true, rollbackFor = Exception.class) - public ResponseEntity getClassification(@PathVariable String classificationKey) { + public ResponseEntity getClassification(@PathVariable String classificationId) { try { - Classification classification = classificationService.getClassification(classificationKey, ""); - return ResponseEntity.status(HttpStatus.OK).body(classification); - } catch (Exception e) { + Classification classification = classificationService.getClassification(classificationId); + return ResponseEntity.status(HttpStatus.OK).body(classificationMapper.toResource(classification)); + } catch (ClassificationNotFoundException e) { TransactionInterceptor.currentTransactionStatus().setRollbackOnly(); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); } } @GetMapping(path = "/{classificationKey}/{domain}") @Transactional(readOnly = true, rollbackFor = Exception.class) - public ResponseEntity getClassification(@PathVariable String classificationKey, + public ResponseEntity getClassification(@PathVariable String classificationKey, @PathVariable String domain) { try { Classification classification = classificationService.getClassification(classificationKey, domain); - return ResponseEntity.status(HttpStatus.OK).body(classification); - } catch (Exception e) { + return ResponseEntity.status(HttpStatus.OK).body(classificationMapper.toResource(classification)); + } catch (ClassificationNotFoundException e) { TransactionInterceptor.currentTransactionStatus().setRollbackOnly(); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); } } @PostMapping @Transactional(rollbackFor = Exception.class) - public ResponseEntity createClassification(@RequestBody Classification classification) { + public ResponseEntity createClassification( + @RequestBody ClassificationResource resource) { try { - classificationService.createClassification(classification); - return ResponseEntity.status(HttpStatus.CREATED).body(classification); - } catch (Exception e) { + Classification classification = classificationMapper.toModel(resource); + classification = classificationService.createClassification(classification); + return ResponseEntity.status(HttpStatus.CREATED).body(classificationMapper.toResource(classification)); + } catch (ClassificationAlreadyExistException e) { TransactionInterceptor.currentTransactionStatus().setRollbackOnly(); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + return ResponseEntity.status(HttpStatus.CONFLICT).build(); + } catch (NotAuthorizedException e) { + TransactionInterceptor.currentTransactionStatus().setRollbackOnly(); + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); } } @PutMapping @Transactional(rollbackFor = Exception.class) - public ResponseEntity updateClassification(@RequestBody Classification classification) { + public ResponseEntity updateClassification(@RequestBody ClassificationResource resource) { try { - classificationService.updateClassification(classification); - return ResponseEntity.status(HttpStatus.CREATED).body(classification); - } catch (Exception e) { + Classification classification = classificationMapper.toModel(resource); + classification = classificationService.updateClassification(classification); + return ResponseEntity.status(HttpStatus.OK).body(classificationMapper.toResource(classification)); + } catch (ClassificationNotFoundException e) { TransactionInterceptor.currentTransactionStatus().setRollbackOnly(); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); + } catch (NotAuthorizedException e) { + TransactionInterceptor.currentTransactionStatus().setRollbackOnly(); + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); } } } diff --git a/rest/src/main/java/pro/taskana/rest/RestConfiguration.java b/rest/src/main/java/pro/taskana/rest/RestConfiguration.java index f085b46a0..2049c805f 100644 --- a/rest/src/main/java/pro/taskana/rest/RestConfiguration.java +++ b/rest/src/main/java/pro/taskana/rest/RestConfiguration.java @@ -35,7 +35,7 @@ import pro.taskana.sampledata.SampleDataGenerator; @EnableTransactionManagement public class RestConfiguration { - private static final Logger logger = LoggerFactory.getLogger(RestApplication.class); + private static final Logger LOGGER = LoggerFactory.getLogger(RestApplication.class); @Bean @Primary @@ -80,8 +80,8 @@ public class RestConfiguration { @Bean @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) public TaskanaEngineConfiguration taskanaEngineConfiguration(DataSource dataSource) throws SQLException { - TaskanaEngineConfiguration taskanaEngineConfiguration = - new SpringTaskanaEngineConfiguration(dataSource, true, true); + TaskanaEngineConfiguration taskanaEngineConfiguration = new SpringTaskanaEngineConfiguration(dataSource, true, + true); new SampleDataGenerator(dataSource).generateSampleData(); diff --git a/rest/src/main/java/pro/taskana/rest/WorkbasketController.java b/rest/src/main/java/pro/taskana/rest/WorkbasketController.java index dc3a1b8cf..52a5f8313 100644 --- a/rest/src/main/java/pro/taskana/rest/WorkbasketController.java +++ b/rest/src/main/java/pro/taskana/rest/WorkbasketController.java @@ -18,7 +18,6 @@ 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; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -182,9 +181,16 @@ public class WorkbasketController { public ResponseEntity> getWorkbasketAuthorizations( @PathVariable(value = "workbasketId") String workbasketId) { List wbAuthorizations = workbasketService.getWorkbasketAuthorizations(workbasketId); - return new ResponseEntity<>(wbAuthorizations.stream() - .map(accItem -> workbasketAccessItemMapper.toResource(accItem)) - .collect(Collectors.toList()), HttpStatus.OK); + List result = new ArrayList<>(); + wbAuthorizations.stream() + .forEach(accItem -> { + try { + result.add(workbasketAccessItemMapper.toResource(accItem)); + } catch (NotAuthorizedException e) { + e.printStackTrace(); + } + }); + return new ResponseEntity<>(result, HttpStatus.OK); } @PostMapping(path = "/authorizations") @@ -216,7 +222,7 @@ public class WorkbasketController { } } - @RequestMapping(value = "/{workbasketId}/authorizations/", method = RequestMethod.PUT) + @PutMapping(value = "/{workbasketId}/authorizations/") public ResponseEntity setWorkbasketAuthorizations(@PathVariable(value = "workbasketId") String workbasketId, @RequestBody List workbasketAccessResourceItems) { try { @@ -263,7 +269,7 @@ public class WorkbasketController { @PutMapping(path = "/{workbasketId}/distributiontargets") @Transactional(rollbackFor = Exception.class) - public ResponseEntity setDistributionTargets( + public ResponseEntity setDistributionTargetsForWorkbasketId( @PathVariable(value = "workbasketId") String sourceWorkbasketId, @RequestBody List targetWorkbasketIds) { ResponseEntity result; diff --git a/rest/src/main/java/pro/taskana/rest/WorkbasketDefinitionController.java b/rest/src/main/java/pro/taskana/rest/WorkbasketDefinitionController.java index 7b6f80cab..0d0a3a89a 100644 --- a/rest/src/main/java/pro/taskana/rest/WorkbasketDefinitionController.java +++ b/rest/src/main/java/pro/taskana/rest/WorkbasketDefinitionController.java @@ -87,8 +87,7 @@ public class WorkbasketDefinitionController { */ @PostMapping(path = "/import") @Transactional(rollbackFor = Exception.class) - public ResponseEntity importWorkbaskets(@RequestBody List definitions) - throws InvalidArgumentException { + public ResponseEntity importWorkbaskets(@RequestBody List definitions) { try { // key: logical ID // value: system ID (in database) @@ -141,9 +140,7 @@ public class WorkbasketDefinitionController { // no verification necessary since the workbasket was already imported in step 1. idConversion.get(definition.workbasketResource.workbasketId), distributionTargets); } - return new ResponseEntity<>(HttpStatus.OK); - } catch (WorkbasketNotFoundException e) { TransactionInterceptor.currentTransactionStatus().setRollbackOnly(); return new ResponseEntity<>(HttpStatus.NOT_FOUND); @@ -153,6 +150,9 @@ public class WorkbasketDefinitionController { } catch (NotAuthorizedException e) { TransactionInterceptor.currentTransactionStatus().setRollbackOnly(); return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); + } catch (InvalidArgumentException e) { + TransactionInterceptor.currentTransactionStatus().setRollbackOnly(); + return new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED); } } diff --git a/rest/src/main/java/pro/taskana/rest/query/TaskFilter.java b/rest/src/main/java/pro/taskana/rest/query/TaskFilter.java index 31c364304..e788a5ce5 100644 --- a/rest/src/main/java/pro/taskana/rest/query/TaskFilter.java +++ b/rest/src/main/java/pro/taskana/rest/query/TaskFilter.java @@ -8,7 +8,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.MultiValueMap; -import pro.taskana.ClassificationService; import pro.taskana.TaskQuery; import pro.taskana.TaskService; import pro.taskana.TaskSummary; @@ -49,9 +48,6 @@ public class TaskFilter { @Autowired private TaskService taskService; - @Autowired - private ClassificationService classificationService; - public List getAll() throws NotAuthorizedException { return taskService.createTaskQuery().list(); } diff --git a/rest/src/main/java/pro/taskana/rest/resource/WorkbasketDefinition.java b/rest/src/main/java/pro/taskana/rest/resource/WorkbasketDefinition.java index 64c3e947f..cdeb6d780 100644 --- a/rest/src/main/java/pro/taskana/rest/resource/WorkbasketDefinition.java +++ b/rest/src/main/java/pro/taskana/rest/resource/WorkbasketDefinition.java @@ -26,5 +26,4 @@ public class WorkbasketDefinition extends ResourceSupport { this.distributionTargets = distributionTargets; this.authorizations = authorizations; } - } diff --git a/rest/src/main/java/pro/taskana/rest/resource/mapper/ClassificationMapper.java b/rest/src/main/java/pro/taskana/rest/resource/mapper/ClassificationMapper.java index d4c822531..97d29785b 100644 --- a/rest/src/main/java/pro/taskana/rest/resource/mapper/ClassificationMapper.java +++ b/rest/src/main/java/pro/taskana/rest/resource/mapper/ClassificationMapper.java @@ -1,5 +1,8 @@ package pro.taskana.rest.resource.mapper; +import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; +import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn; + import java.time.Instant; import org.springframework.beans.BeanUtils; @@ -8,8 +11,9 @@ import org.springframework.stereotype.Component; import pro.taskana.Classification; import pro.taskana.ClassificationService; -import pro.taskana.impl.ClassificationImpl; import pro.taskana.exceptions.NotAuthorizedException; +import pro.taskana.impl.ClassificationImpl; +import pro.taskana.rest.ClassificationController; import pro.taskana.rest.resource.ClassificationResource; @Component @@ -21,10 +25,10 @@ public class ClassificationMapper { public ClassificationResource toResource(Classification classification) { ClassificationResource resource = new ClassificationResource(); BeanUtils.copyProperties(classification, resource); - //need to be set by hand, because they are named different, or have different types + // need to be set by hand, because they are named different, or have different types resource.setClassificationId(classification.getId()); resource.setCreated(classification.getCreated().toString()); - return resource; + return addLinks(resource, classification); } public Classification toModel(ClassificationResource classificationResource) throws NotAuthorizedException { @@ -36,4 +40,23 @@ public class ClassificationMapper { classification.setCreated(Instant.parse(classificationResource.getCreated())); return classification; } + + private ClassificationResource addLinks(ClassificationResource resource, Classification classification) { + resource.add( + linkTo(methodOn(ClassificationController.class).getClassification(classification.getId())) + .withSelfRel()); + resource.add( + linkTo(methodOn(ClassificationController.class).getClassification(classification.getKey(), + classification.getDomain())) + .withRel("getClassificationByKeyAndDomain")); + resource.add( + linkTo(methodOn(ClassificationController.class).getClassifications()).withRel("getAllClassifications")); + resource.add( + linkTo(methodOn(ClassificationController.class).createClassification(resource)) + .withRel("createClassification")); + resource.add( + linkTo(methodOn(ClassificationController.class).updateClassification(resource)) + .withRel("updateClassification")); + return resource; + } } diff --git a/rest/src/main/java/pro/taskana/rest/resource/mapper/WorkbasketAccessItemMapper.java b/rest/src/main/java/pro/taskana/rest/resource/mapper/WorkbasketAccessItemMapper.java index b757d6865..f16fe697c 100644 --- a/rest/src/main/java/pro/taskana/rest/resource/mapper/WorkbasketAccessItemMapper.java +++ b/rest/src/main/java/pro/taskana/rest/resource/mapper/WorkbasketAccessItemMapper.java @@ -3,12 +3,15 @@ package pro.taskana.rest.resource.mapper; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn; +import java.util.Arrays; + import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import pro.taskana.WorkbasketAccessItem; import pro.taskana.WorkbasketService; +import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.impl.WorkbasketAccessItemImpl; import pro.taskana.rest.WorkbasketController; import pro.taskana.rest.resource.WorkbasketAccessItemResource; @@ -19,17 +22,13 @@ public class WorkbasketAccessItemMapper { @Autowired private WorkbasketService workbasketService; - public WorkbasketAccessItemResource toResource(WorkbasketAccessItem wbAccItem) { + public WorkbasketAccessItemResource toResource(WorkbasketAccessItem wbAccItem) throws NotAuthorizedException { WorkbasketAccessItemResource resource = new WorkbasketAccessItemResource(); BeanUtils.copyProperties(wbAccItem, resource); - //property is named different, so it needs to be set by hand + // property is named different, so it needs to be set by hand resource.setAccessItemId(wbAccItem.getId()); - // Add self-decription link to hateoas - resource.add( - linkTo(methodOn(WorkbasketController.class).getWorkbasketAuthorizations(wbAccItem.getWorkbasketId())) - .withSelfRel()); - return resource; + return addLinks(resource, wbAccItem); } public WorkbasketAccessItem toModel(WorkbasketAccessItemResource wbAccItemRecource) { @@ -41,4 +40,24 @@ public class WorkbasketAccessItemMapper { return wbAccItemModel; } + WorkbasketAccessItemResource addLinks(WorkbasketAccessItemResource resource, WorkbasketAccessItem wbAccItem) + throws NotAuthorizedException { + resource.add( + linkTo(methodOn(WorkbasketController.class).getWorkbasketAuthorizations(wbAccItem.getWorkbasketId())) + .withRel("getWorkbasketAuthorizations")); + resource.add( + linkTo(methodOn(WorkbasketController.class).createWorkbasketAuthorization(resource)) + .withRel("createWorkbasketAuthorization")); + resource.add( + linkTo(methodOn(WorkbasketController.class).updateWorkbasketAuthorization(wbAccItem.getId(), resource)) + .withRel("updateWorkbasketAuthorization")); + resource.add( + linkTo(methodOn(WorkbasketController.class).setWorkbasketAuthorizations(wbAccItem.getWorkbasketId(), + Arrays.asList(resource))) + .withRel("setWorkbasketAuthorizations")); + resource.add( + linkTo(methodOn(WorkbasketController.class).deleteWorkbasketAuthorization(wbAccItem.getId())) + .withRel("deleteWorkbasketAuthorization")); + return resource; + } } diff --git a/rest/src/main/java/pro/taskana/rest/resource/mapper/WorkbasketDefinitionMapper.java b/rest/src/main/java/pro/taskana/rest/resource/mapper/WorkbasketDefinitionMapper.java index 0b81a4d8d..96492a81c 100644 --- a/rest/src/main/java/pro/taskana/rest/resource/mapper/WorkbasketDefinitionMapper.java +++ b/rest/src/main/java/pro/taskana/rest/resource/mapper/WorkbasketDefinitionMapper.java @@ -1,5 +1,10 @@ package pro.taskana.rest.resource.mapper; +import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; +import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn; + +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -12,6 +17,7 @@ import pro.taskana.WorkbasketService; import pro.taskana.WorkbasketSummary; import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.WorkbasketNotFoundException; +import pro.taskana.rest.WorkbasketDefinitionController; import pro.taskana.rest.resource.WorkbasketAccessItemResource; import pro.taskana.rest.resource.WorkbasketDefinition; @@ -29,21 +35,45 @@ public class WorkbasketDefinitionMapper { /** * maps the distro targets to their id to remove overhead. - * @param basket {@link Workbasket} which will be converted - * @return a {@link WorkbasketDefinition}, containing the {@code basket}, - * its ditribution targets and its authorizations - * @throws NotAuthorizedException if the user is not authorized - * @throws WorkbasketNotFoundException if {@code basket} is an unknown workbasket + * + * @param basket + * {@link Workbasket} which will be converted + * @return a {@link WorkbasketDefinition}, containing the {@code basket}, its ditribution targets and its + * authorizations + * @throws NotAuthorizedException + * if the user is not authorized + * @throws WorkbasketNotFoundException + * if {@code basket} is an unknown workbasket */ public WorkbasketDefinition toResource(Workbasket basket) throws NotAuthorizedException, WorkbasketNotFoundException { - List authorizations = workbasketService.getWorkbasketAuthorizations( - basket.getKey()).stream() - .map(workbasketAccessItemMapper::toResource) - .collect(Collectors.toList()); - Set distroTargets = workbasketService.getDistributionTargets(basket.getId()).stream() + List authorizations = new ArrayList<>(); + workbasketService.getWorkbasketAuthorizations( + basket.getKey()) + .stream() + .forEach(t -> { + try { + authorizations.add(workbasketAccessItemMapper.toResource(t)); + } catch (NotAuthorizedException e) { + e.printStackTrace(); + } + }); + Set distroTargets = workbasketService.getDistributionTargets(basket.getId()) + .stream() .map(WorkbasketSummary::getId) .collect(Collectors.toSet()); - return new WorkbasketDefinition(workbasketMapper.toResource(basket), distroTargets, authorizations); + WorkbasketDefinition resource = new WorkbasketDefinition(workbasketMapper.toResource(basket), distroTargets, + authorizations); + return addLinks(resource, basket); + } + + private WorkbasketDefinition addLinks(WorkbasketDefinition resource, Workbasket workbasket) { + resource.add( + linkTo(methodOn(WorkbasketDefinitionController.class).exportWorkbaskets(workbasket.getDomain())) + .withRel("exportWorkbaskets")); + resource.add( + linkTo(methodOn(WorkbasketDefinitionController.class).importWorkbaskets(Arrays.asList(resource))) + .withRel("importWorkbaskets")); + return resource; } } diff --git a/rest/src/main/java/pro/taskana/rest/resource/mapper/WorkbasketMapper.java b/rest/src/main/java/pro/taskana/rest/resource/mapper/WorkbasketMapper.java index df26c6bd6..33330db22 100644 --- a/rest/src/main/java/pro/taskana/rest/resource/mapper/WorkbasketMapper.java +++ b/rest/src/main/java/pro/taskana/rest/resource/mapper/WorkbasketMapper.java @@ -22,17 +22,15 @@ public class WorkbasketMapper { @Autowired private WorkbasketService workbasketService; - public WorkbasketResource toResource(Workbasket wb) { + public WorkbasketResource toResource(Workbasket wb) throws NotAuthorizedException { WorkbasketResource resource = new WorkbasketResource(); BeanUtils.copyProperties(wb, resource); - //need to be set by hand, since name or type is different + // need to be set by hand, since name or type is different resource.setWorkbasketId(wb.getId()); resource.setModified(wb.getModified().toString()); resource.setCreated(wb.getCreated().toString()); - // Add self-decription link to hateoas - resource.add(linkTo(methodOn(WorkbasketController.class).getWorkbasket(wb.getId())).withSelfRel()); - return resource; + return addLinks(resource, wb); } public Workbasket toModel(WorkbasketResource wbResource) throws NotAuthorizedException { @@ -44,4 +42,17 @@ public class WorkbasketMapper { workbasket.setCreated(Instant.parse(wbResource.created)); return workbasket; } + + private WorkbasketResource addLinks(WorkbasketResource resource, Workbasket wb) throws NotAuthorizedException { + resource.add(linkTo(methodOn(WorkbasketController.class).getWorkbasket(wb.getId())).withSelfRel()); + resource + .add(linkTo(methodOn(WorkbasketController.class).createWorkbasket(resource)).withRel("createWorkbasket")); + resource + .add(linkTo(methodOn(WorkbasketController.class).updateWorkbasket(wb.getId(), resource)) + .withRel("updateWorkbasket")); + resource + .add(linkTo(methodOn(WorkbasketController.class).deleteWorkbasket(wb.getId())) + .withRel("deleteWorkbasket")); + return resource; + } } diff --git a/rest/src/main/java/pro/taskana/rest/resource/mapper/WorkbasketSummaryMapper.java b/rest/src/main/java/pro/taskana/rest/resource/mapper/WorkbasketSummaryMapper.java index 7ebc8d675..8085691aa 100644 --- a/rest/src/main/java/pro/taskana/rest/resource/mapper/WorkbasketSummaryMapper.java +++ b/rest/src/main/java/pro/taskana/rest/resource/mapper/WorkbasketSummaryMapper.java @@ -16,12 +16,16 @@ public class WorkbasketSummaryMapper { public WorkbasketSummaryResource toResource(WorkbasketSummary summary) { WorkbasketSummaryResource resource = new WorkbasketSummaryResource(); BeanUtils.copyProperties(summary, resource); - //named different so needs to be set by hand + // named different so needs to be set by hand resource.setWorkbasketId(summary.getId()); - // Add self reference - resource.add(linkTo(methodOn(WorkbasketController.class).getWorkbasket(summary.getId())).withSelfRel()); - return resource; + return addLinks(resource, summary); } + private WorkbasketSummaryResource addLinks(WorkbasketSummaryResource resource, WorkbasketSummary summary) { + resource.add(linkTo(WorkbasketController.class).slash(summary.getId()).withSelfRel()); + resource.add(linkTo(methodOn(WorkbasketController.class).getDistributionTargetsForWorkbasketId(summary.getId())) + .withRel("getDistributionTargetsForWorkbasketId")); + return resource; + } } diff --git a/rest/src/test/java/pro/taskana/rest/resource/mapper/WorkbasketAccessItemMapperTest.java b/rest/src/test/java/pro/taskana/rest/resource/mapper/WorkbasketAccessItemMapperTest.java index 92d3703bf..ce9d58ed5 100644 --- a/rest/src/test/java/pro/taskana/rest/resource/mapper/WorkbasketAccessItemMapperTest.java +++ b/rest/src/test/java/pro/taskana/rest/resource/mapper/WorkbasketAccessItemMapperTest.java @@ -10,6 +10,7 @@ import org.springframework.test.context.web.WebAppConfiguration; import pro.taskana.WorkbasketAccessItem; import pro.taskana.WorkbasketService; +import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.rest.RestApplication; import pro.taskana.rest.resource.WorkbasketAccessItemResource; @@ -18,12 +19,14 @@ import pro.taskana.rest.resource.WorkbasketAccessItemResource; @WebAppConfiguration public class WorkbasketAccessItemMapperTest { - @Autowired WorkbasketAccessItemMapper workbasketAccessItemMapper; - @Autowired WorkbasketService workbasketService; + @Autowired + WorkbasketAccessItemMapper workbasketAccessItemMapper; + @Autowired + WorkbasketService workbasketService; @Test - public void workBasketAccessItemToResourcePropertiesEqual() { - //given + public void workBasketAccessItemToResourcePropertiesEqual() throws NotAuthorizedException { + // given WorkbasketAccessItem accessItem = workbasketService.newWorkbasketAccessItem("1", "2"); accessItem.setPermDistribute(false); accessItem.setPermOpen(true); @@ -42,16 +45,16 @@ public class WorkbasketAccessItemMapperTest { accessItem.setPermCustom10(true); accessItem.setPermCustom11(true); accessItem.setPermCustom12(true); - //when + // when WorkbasketAccessItemResource resource = workbasketAccessItemMapper.toResource( accessItem); - //then + // then testEquality(accessItem, resource); } @Test public void workBasketAccessItemToModelPropertiesEqual() { - //given + // given WorkbasketAccessItemResource resource = new WorkbasketAccessItemResource(); resource.setAccessId("10"); resource.setAccessItemId("120"); @@ -73,9 +76,9 @@ public class WorkbasketAccessItemMapperTest { resource.setPermCustom10(false); resource.setPermCustom11(true); resource.setPermCustom12(false); - //when + // when WorkbasketAccessItem accessItem = workbasketAccessItemMapper.toModel(resource); - //then + // then testEquality(accessItem, resource); } diff --git a/rest/src/test/java/pro/taskana/rest/resource/mapper/WorkbasketMapperTest.java b/rest/src/test/java/pro/taskana/rest/resource/mapper/WorkbasketMapperTest.java index 4fa80df88..287948746 100644 --- a/rest/src/test/java/pro/taskana/rest/resource/mapper/WorkbasketMapperTest.java +++ b/rest/src/test/java/pro/taskana/rest/resource/mapper/WorkbasketMapperTest.java @@ -29,7 +29,7 @@ public class WorkbasketMapperTest { WorkbasketMapper workbasketMapper; @Test - public void workbasketToResource() { + public void workbasketToResource() throws NotAuthorizedException { // given Workbasket workbasket = workbasketService.newWorkbasket("1", "DOMAIN_A"); ((WorkbasketImpl) workbasket).setId("ID");