TSK-378: Add pagination to WorkbasketController.
This commit is contained in:
parent
6d3e99ccb5
commit
2c62de91d7
|
|
@ -5,6 +5,8 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.hateoas.PagedResources;
|
||||||
|
import org.springframework.hateoas.PagedResources.PageMetadata;
|
||||||
import org.springframework.hateoas.Resources;
|
import org.springframework.hateoas.Resources;
|
||||||
import org.springframework.hateoas.config.EnableHypermediaSupport;
|
import org.springframework.hateoas.config.EnableHypermediaSupport;
|
||||||
import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType;
|
import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType;
|
||||||
|
|
@ -43,8 +45,8 @@ import pro.taskana.rest.resource.WorkbasketSummaryResource;
|
||||||
import pro.taskana.rest.resource.mapper.DistributionTargetListMapper;
|
import pro.taskana.rest.resource.mapper.DistributionTargetListMapper;
|
||||||
import pro.taskana.rest.resource.mapper.WorkbasketAccessItemListMapper;
|
import pro.taskana.rest.resource.mapper.WorkbasketAccessItemListMapper;
|
||||||
import pro.taskana.rest.resource.mapper.WorkbasketAccessItemMapper;
|
import pro.taskana.rest.resource.mapper.WorkbasketAccessItemMapper;
|
||||||
import pro.taskana.rest.resource.mapper.WorkbasketListMapper;
|
|
||||||
import pro.taskana.rest.resource.mapper.WorkbasketMapper;
|
import pro.taskana.rest.resource.mapper.WorkbasketMapper;
|
||||||
|
import pro.taskana.rest.resource.mapper.WorkbasketSummaryResourceAssembler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller for all {@link Workbasket} related endpoints.
|
* Controller for all {@link Workbasket} related endpoints.
|
||||||
|
|
@ -68,9 +70,6 @@ public class WorkbasketController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private WorkbasketMapper workbasketMapper;
|
private WorkbasketMapper workbasketMapper;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private WorkbasketListMapper workbasketListMapper;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DistributionTargetListMapper distributionTargetListMapper;
|
private DistributionTargetListMapper distributionTargetListMapper;
|
||||||
|
|
||||||
|
|
@ -82,7 +81,7 @@ public class WorkbasketController {
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@Transactional(readOnly = true, rollbackFor = Exception.class)
|
@Transactional(readOnly = true, rollbackFor = Exception.class)
|
||||||
public ResponseEntity<Resources<WorkbasketSummaryResource>> getWorkbaskets(
|
public ResponseEntity<PagedResources<WorkbasketSummaryResource>> getWorkbaskets(
|
||||||
@RequestParam(value = "sortBy", defaultValue = "name", required = false) String sortBy,
|
@RequestParam(value = "sortBy", defaultValue = "name", required = false) String sortBy,
|
||||||
@RequestParam(value = "order", defaultValue = "asc", required = false) String order,
|
@RequestParam(value = "order", defaultValue = "asc", required = false) String order,
|
||||||
@RequestParam(value = "name", required = false) String name,
|
@RequestParam(value = "name", required = false) String name,
|
||||||
|
|
@ -95,14 +94,23 @@ public class WorkbasketController {
|
||||||
@RequestParam(value = "type", required = false) String type,
|
@RequestParam(value = "type", required = false) String type,
|
||||||
@RequestParam(value = "requiredPermission", required = false) String requiredPermission)
|
@RequestParam(value = "requiredPermission", required = false) String requiredPermission)
|
||||||
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidArgumentException {
|
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidArgumentException {
|
||||||
|
|
||||||
WorkbasketQuery query = workbasketService.createWorkbasketQuery();
|
WorkbasketQuery query = workbasketService.createWorkbasketQuery();
|
||||||
addSortingToQuery(query, sortBy, order);
|
addSortingToQuery(query, sortBy, order);
|
||||||
addAttributeFilter(query, name, nameLike, key, keyLike, descLike, owner, ownerLike, type);
|
addAttributeFilter(query, name, nameLike, key, keyLike, descLike, owner, ownerLike, type);
|
||||||
addAuthorizationFilter(query, requiredPermission);
|
addAuthorizationFilter(query, requiredPermission);
|
||||||
List<WorkbasketSummary> workbasketSummaries = query.list();
|
List<WorkbasketSummary> workbasketSummaries = query.list();
|
||||||
Resources<WorkbasketSummaryResource> workbasketListResource = workbasketListMapper
|
|
||||||
.toResource(workbasketSummaries);
|
// Iterable<? extends WorkbasketSummary> workbasketSummaries2 = query.list();
|
||||||
return new ResponseEntity<>(workbasketListResource, HttpStatus.OK);
|
|
||||||
|
WorkbasketSummaryResourceAssembler assembler = new WorkbasketSummaryResourceAssembler();
|
||||||
|
List<WorkbasketSummaryResource> resources = assembler.toResources(workbasketSummaries);
|
||||||
|
PageMetadata pageMetadata = new PageMetadata(5, 1, workbasketSummaries.size(), 4);
|
||||||
|
PagedResources<WorkbasketSummaryResource> pagedResources = new PagedResources<WorkbasketSummaryResource>(
|
||||||
|
resources,
|
||||||
|
pageMetadata);
|
||||||
|
|
||||||
|
return new ResponseEntity<>(pagedResources, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(path = "/{workbasketId}")
|
@GetMapping(path = "/{workbasketId}")
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package pro.taskana.rest.resource.mapper;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.hateoas.mvc.ResourceAssemblerSupport;
|
||||||
|
|
||||||
|
import pro.taskana.WorkbasketSummary;
|
||||||
|
import pro.taskana.rest.WorkbasketController;
|
||||||
|
import pro.taskana.rest.resource.WorkbasketSummaryResource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author HH
|
||||||
|
*/
|
||||||
|
public class WorkbasketSummaryResourceAssembler
|
||||||
|
extends ResourceAssemblerSupport<WorkbasketSummary, WorkbasketSummaryResource> {
|
||||||
|
|
||||||
|
public WorkbasketSummaryResourceAssembler() {
|
||||||
|
super(WorkbasketController.class, WorkbasketSummaryResource.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WorkbasketSummaryResource toResource(WorkbasketSummary workbasketSummary) {
|
||||||
|
WorkbasketSummaryResource resource = createResourceWithId(workbasketSummary.getId(), workbasketSummary);
|
||||||
|
BeanUtils.copyProperties(workbasketSummary, resource);
|
||||||
|
// named different so needs to be set by hand
|
||||||
|
resource.setWorkbasketId(workbasketSummary.getId());
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue