Search in sources :

Example 1 with WorkbasketQuery

use of pro.taskana.WorkbasketQuery in project taskana by Taskana.

the class QueryWorkbasketAccTest method testQueryAllForBusinessAdminMultipleTimes.

@WithAccessId(userName = "teamlead_1", groupNames = { "businessadmin" })
@Test
public void testQueryAllForBusinessAdminMultipleTimes() {
    WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
    WorkbasketQuery query = workbasketService.createWorkbasketQuery();
    long count = query.count();
    assertTrue(count == 24);
    List<WorkbasketSummary> workbaskets = query.list();
    assertNotNull(workbaskets);
    assertEquals(count, workbaskets.size());
    workbaskets = query.list();
    assertNotNull(workbaskets);
    assertEquals(count, workbaskets.size());
}
Also used : WorkbasketService(pro.taskana.WorkbasketService) WorkbasketQuery(pro.taskana.WorkbasketQuery) WorkbasketSummary(pro.taskana.WorkbasketSummary) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 2 with WorkbasketQuery

use of pro.taskana.WorkbasketQuery 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)

Example 3 with WorkbasketQuery

use of pro.taskana.WorkbasketQuery in project taskana by Taskana.

the class WorkbasketDefinitionController method exportWorkbaskets.

@GetMapping
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<List<WorkbasketDefinition>> exportWorkbaskets(@RequestParam(required = false) String domain) {
    try {
        WorkbasketQuery workbasketQuery = workbasketService.createWorkbasketQuery();
        List<WorkbasketSummary> workbasketSummaryList = domain != null ? workbasketQuery.domainIn(domain).list() : workbasketQuery.list();
        List<WorkbasketDefinition> basketExports = new ArrayList<>();
        for (WorkbasketSummary summary : workbasketSummaryList) {
            Workbasket workbasket = workbasketService.getWorkbasket(summary.getId());
            basketExports.add(workbasketDefinitionMapper.toResource(workbasket));
        }
        return new ResponseEntity<>(basketExports, HttpStatus.OK);
    } catch (WorkbasketNotFoundException e) {
        TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    } catch (NotAuthorizedException e) {
        TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
        return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
    }
}
Also used : WorkbasketDefinition(pro.taskana.rest.resource.WorkbasketDefinition) ResponseEntity(org.springframework.http.ResponseEntity) WorkbasketQuery(pro.taskana.WorkbasketQuery) ArrayList(java.util.ArrayList) WorkbasketNotFoundException(pro.taskana.exceptions.WorkbasketNotFoundException) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) Workbasket(pro.taskana.Workbasket) WorkbasketSummary(pro.taskana.WorkbasketSummary) GetMapping(org.springframework.web.bind.annotation.GetMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with WorkbasketQuery

use of pro.taskana.WorkbasketQuery in project taskana by Taskana.

the class QueryWorkbasketAccTest method testQueryAllForAdminMultipleTimes.

@WithAccessId(userName = "teamlead_1", groupNames = { "admin" })
@Test
public void testQueryAllForAdminMultipleTimes() {
    WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
    WorkbasketQuery query = workbasketService.createWorkbasketQuery();
    long count = query.count();
    assertTrue(count == 24);
    List<WorkbasketSummary> workbaskets = query.list();
    assertNotNull(workbaskets);
    assertEquals(count, workbaskets.size());
    workbaskets = query.list();
    assertNotNull(workbaskets);
    assertEquals(count, workbaskets.size());
}
Also used : WorkbasketService(pro.taskana.WorkbasketService) WorkbasketQuery(pro.taskana.WorkbasketQuery) WorkbasketSummary(pro.taskana.WorkbasketSummary) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 5 with WorkbasketQuery

use of pro.taskana.WorkbasketQuery in project taskana by Taskana.

the class QueryWorkbasketAccTest method testQueryAllForUserMultipleTimes.

@WithAccessId(userName = "teamlead_1", groupNames = { "group_1_1" })
@Test
public void testQueryAllForUserMultipleTimes() {
    WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
    WorkbasketQuery query = workbasketService.createWorkbasketQuery();
    long count = query.count();
    assertEquals(3, count);
    List<WorkbasketSummary> workbaskets = query.list();
    assertNotNull(workbaskets);
    assertEquals(count, workbaskets.size());
    workbaskets = query.list();
    assertNotNull(workbaskets);
    assertEquals(count, workbaskets.size());
}
Also used : WorkbasketService(pro.taskana.WorkbasketService) WorkbasketQuery(pro.taskana.WorkbasketQuery) WorkbasketSummary(pro.taskana.WorkbasketSummary) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Aggregations

WorkbasketQuery (pro.taskana.WorkbasketQuery)5 WorkbasketSummary (pro.taskana.WorkbasketSummary)5 AbstractAccTest (acceptance.AbstractAccTest)3 Test (org.junit.Test)3 WorkbasketService (pro.taskana.WorkbasketService)3 WithAccessId (pro.taskana.security.WithAccessId)3 ResponseEntity (org.springframework.http.ResponseEntity)2 Transactional (org.springframework.transaction.annotation.Transactional)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 ArrayList (java.util.ArrayList)1 PageMetadata (org.springframework.hateoas.PagedResources.PageMetadata)1 Workbasket (pro.taskana.Workbasket)1 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)1 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)1 WorkbasketNotFoundException (pro.taskana.exceptions.WorkbasketNotFoundException)1 WorkbasketDefinition (pro.taskana.rest.resource.WorkbasketDefinition)1 WorkbasketSummaryResource (pro.taskana.rest.resource.WorkbasketSummaryResource)1 WorkbasketSummaryResourcesAssembler (pro.taskana.rest.resource.mapper.WorkbasketSummaryResourcesAssembler)1