Search in sources :

Example 1 with WorkbasketSummaryResourcesAssembler

use of pro.taskana.rest.resource.mapper.WorkbasketSummaryResourcesAssembler in project taskana by Taskana.

the class WorkbasketController method getWorkbaskets.

@GetMapping
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<PagedResources<WorkbasketSummaryResource>> getWorkbaskets(@RequestParam(value = "sortBy", defaultValue = "name", required = false) String sortBy, @RequestParam(value = "order", defaultValue = "asc", required = false) String order, @RequestParam(value = "name", required = false) String name, @RequestParam(value = "nameLike", required = false) String nameLike, @RequestParam(value = "key", required = false) String key, @RequestParam(value = "keyLike", required = false) String keyLike, @RequestParam(value = "descLike", required = false) String descLike, @RequestParam(value = "owner", required = false) String owner, @RequestParam(value = "ownerLike", required = false) String ownerLike, @RequestParam(value = "type", required = false) String type, @RequestParam(value = "requiredPermission", required = false) String requiredPermission, @RequestParam(value = "page", required = false) String page, @RequestParam(value = "pagesize", required = false) String pageSize) throws InvalidArgumentException {
    WorkbasketQuery query = workbasketService.createWorkbasketQuery();
    addSortingToQuery(query, sortBy, order);
    addAttributeFilter(query, name, nameLike, key, keyLike, descLike, owner, ownerLike, type);
    addAuthorizationFilter(query, requiredPermission);
    PageMetadata pageMetadata = null;
    List<WorkbasketSummary> workbasketSummaries = null;
    if (page != null && pageSize != null) {
        // paging
        long totalElements = query.count();
        pageMetadata = initPageMetadata(pageSize, page, totalElements);
        workbasketSummaries = query.listPage((int) pageMetadata.getNumber(), (int) pageMetadata.getSize());
    } else if (page == null && pageSize == null) {
        // not paging
        workbasketSummaries = query.list();
    } else {
        throw new InvalidArgumentException("Paging information is incomplete.");
    }
    WorkbasketSummaryResourcesAssembler assembler = new WorkbasketSummaryResourcesAssembler();
    PagedResources<WorkbasketSummaryResource> pagedResources = assembler.toResources(workbasketSummaries, pageMetadata);
    return new ResponseEntity<>(pagedResources, HttpStatus.OK);
}
Also used : PageMetadata(org.springframework.hateoas.PagedResources.PageMetadata) ResponseEntity(org.springframework.http.ResponseEntity) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) WorkbasketSummaryResourcesAssembler(pro.taskana.rest.resource.mapper.WorkbasketSummaryResourcesAssembler) WorkbasketQuery(pro.taskana.WorkbasketQuery) WorkbasketSummaryResource(pro.taskana.rest.resource.WorkbasketSummaryResource) WorkbasketSummary(pro.taskana.WorkbasketSummary) GetMapping(org.springframework.web.bind.annotation.GetMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

PageMetadata (org.springframework.hateoas.PagedResources.PageMetadata)1 ResponseEntity (org.springframework.http.ResponseEntity)1 Transactional (org.springframework.transaction.annotation.Transactional)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 WorkbasketQuery (pro.taskana.WorkbasketQuery)1 WorkbasketSummary (pro.taskana.WorkbasketSummary)1 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)1 WorkbasketSummaryResource (pro.taskana.rest.resource.WorkbasketSummaryResource)1 WorkbasketSummaryResourcesAssembler (pro.taskana.rest.resource.mapper.WorkbasketSummaryResourcesAssembler)1