Search in sources :

Example 1 with TaskSummaryResource

use of pro.taskana.rest.resource.TaskSummaryResource in project taskana by Taskana.

the class TaskController method getTasks.

@GetMapping
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<PagedResources<TaskSummaryResource>> getTasks(@RequestParam MultiValueMap<String, String> params) throws InvalidArgumentException, NotAuthorizedException {
    TaskQuery query = taskService.createTaskQuery();
    query = applyFilterParams(query, params);
    query = applySortingParams(query, params);
    PageMetadata pageMetadata = null;
    List<TaskSummary> taskSummaries = null;
    String page = params.getFirst(PAGING_PAGE);
    String pageSize = params.getFirst(PAGING_PAGE_SIZE);
    if (page != null && pageSize != null) {
        // paging
        long totalElements = query.count();
        pageMetadata = initPageMetadata(pageSize, page, totalElements);
        taskSummaries = query.listPage((int) pageMetadata.getNumber(), (int) pageMetadata.getSize());
    } else if (page == null && pageSize == null) {
        // not paging
        taskSummaries = query.list();
    } else {
        throw new InvalidArgumentException("Paging information is incomplete.");
    }
    TaskSummaryResourcesAssembler taskSummaryResourcesAssembler = new TaskSummaryResourcesAssembler();
    PagedResources<TaskSummaryResource> pagedResources = taskSummaryResourcesAssembler.toResources(taskSummaries, pageMetadata);
    return new ResponseEntity<>(pagedResources, HttpStatus.OK);
}
Also used : PageMetadata(org.springframework.hateoas.PagedResources.PageMetadata) TaskSummaryResourcesAssembler(pro.taskana.rest.resource.mapper.TaskSummaryResourcesAssembler) TaskSummaryResource(pro.taskana.rest.resource.TaskSummaryResource) ResponseEntity(org.springframework.http.ResponseEntity) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) TaskQuery(pro.taskana.TaskQuery) TaskSummary(pro.taskana.TaskSummary) GetMapping(org.springframework.web.bind.annotation.GetMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with TaskSummaryResource

use of pro.taskana.rest.resource.TaskSummaryResource in project taskana by Taskana.

the class TaskSummaryResourceAssembler method toResource.

@Override
public TaskSummaryResource toResource(TaskSummary taskSummary) {
    TaskSummaryResource resource = createResourceWithId(taskSummary.getTaskId(), taskSummary);
    BeanUtils.copyProperties(taskSummary, resource);
    if (taskSummary.getCreated() != null) {
        resource.setCreated(taskSummary.getCreated().toString());
    }
    if (taskSummary.getModified() != null) {
        resource.setModified(taskSummary.getModified().toString());
    }
    if (taskSummary.getClaimed() != null) {
        resource.setClaimed(taskSummary.getClaimed().toString());
    }
    if (taskSummary.getCompleted() != null) {
        resource.setCompleted(taskSummary.getCompleted().toString());
    }
    if (taskSummary.getDue() != null) {
        resource.setDue(taskSummary.getDue().toString());
    }
    resource.setClassificationSummaryResource(classificationAssembler.toResource(taskSummary.getClassificationSummary()));
    resource.setWorkbasketSummaryResource(workbasketAssembler.toResource(taskSummary.getWorkbasketSummary()));
    return resource;
}
Also used : TaskSummaryResource(pro.taskana.rest.resource.TaskSummaryResource)

Aggregations

TaskSummaryResource (pro.taskana.rest.resource.TaskSummaryResource)2 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 TaskQuery (pro.taskana.TaskQuery)1 TaskSummary (pro.taskana.TaskSummary)1 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)1 TaskSummaryResourcesAssembler (pro.taskana.rest.resource.mapper.TaskSummaryResourcesAssembler)1