Search in sources :

Example 26 with WorkbasketSummary

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

the class WorkbasketServiceImpl method getDistributionSources.

@Override
public List<WorkbasketSummary> getDistributionSources(String workbasketKey, String domain) throws NotAuthorizedException, WorkbasketNotFoundException {
    LOGGER.debug("entry to getDistributionSources(workbasketKey = {}, domain = {})", workbasketKey, domain);
    List<WorkbasketSummary> result = new ArrayList<>();
    try {
        taskanaEngine.openConnection();
        // check that source workbasket exists
        Workbasket workbasket = getWorkbasket(workbasketKey, domain);
        if (!taskanaEngine.isUserInRole(TaskanaRole.ADMIN, TaskanaRole.BUSINESS_ADMIN)) {
            checkAuthorization(workbasket.getId(), WorkbasketPermission.READ);
        }
        List<WorkbasketSummaryImpl> distributionSources = workbasketMapper.findDistributionSources(workbasket.getId());
        result.addAll(distributionSources);
        return result;
    } finally {
        taskanaEngine.returnConnection();
        if (LOGGER.isDebugEnabled()) {
            int numberOfResultObjects = result.size();
            LOGGER.debug("exit from getDistributionSources(workbasketId). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Workbasket(pro.taskana.Workbasket) WorkbasketSummary(pro.taskana.WorkbasketSummary)

Example 27 with WorkbasketSummary

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

the class WorkbasketQueryImpl method single.

@Override
public WorkbasketSummary single() {
    LOGGER.debug("entry to single(), this = {}", this);
    WorkbasketSummary workbasket = null;
    try {
        taskanaEngine.openConnection();
        handleCallerRolesAndAccessIds();
        workbasket = taskanaEngine.getSqlSession().selectOne(LINK_TO_MAPPER, this);
        return workbasket;
    } finally {
        taskanaEngine.returnConnection();
        LOGGER.debug("exit from single(). Returning result {} ", workbasket);
    }
}
Also used : WorkbasketSummary(pro.taskana.WorkbasketSummary)

Example 28 with WorkbasketSummary

use of pro.taskana.WorkbasketSummary 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 29 with WorkbasketSummary

use of pro.taskana.WorkbasketSummary 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 30 with WorkbasketSummary

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

the class WorkbasketServiceImplIntExplicitTest method testUpdateWorkbasket.

@WithAccessId(userName = "Elena", groupNames = { "businessadmin" })
@Test
public void testUpdateWorkbasket() throws Exception {
    Connection connection = dataSource.getConnection();
    taskanaEngineImpl.setConnection(connection);
    workBasketService = taskanaEngine.getWorkbasketService();
    String id0 = IdGenerator.generateWithPrefix("TWB");
    Workbasket workbasket0 = createTestWorkbasket(id0, "key0", "DOMAIN_A", "Superbasket", WorkbasketType.GROUP);
    workbasket0 = workBasketService.createWorkbasket(workbasket0);
    createWorkbasketWithSecurity(workbasket0, "Elena", true, true, false, false);
    String id1 = IdGenerator.generateWithPrefix("TWB");
    Workbasket workbasket1 = createTestWorkbasket(id1, "key1", "DOMAIN_A", "Megabasket", WorkbasketType.GROUP);
    workbasket1 = workBasketService.createWorkbasket(workbasket1);
    createWorkbasketWithSecurity(workbasket1, "Elena", true, true, false, false);
    String id2 = IdGenerator.generateWithPrefix("TWB");
    Workbasket workbasket2 = createTestWorkbasket(id2, "key2", "DOMAIN_A", "Hyperbasket", WorkbasketType.GROUP);
    workbasket2 = workBasketService.createWorkbasket(workbasket2);
    createWorkbasketWithSecurity(workbasket2, "Elena", true, true, false, false);
    List<String> distTargets = new ArrayList<>(Arrays.asList(workbasket0.getId(), workbasket1.getId()));
    Thread.sleep(SLEEP_TIME);
    workBasketService.setDistributionTargets(workbasket2.getId(), distTargets);
    String id3 = IdGenerator.generateWithPrefix("TWB");
    Workbasket workbasket3 = createTestWorkbasket(id3, "key3", "DOMAIN_A", "hm ... irgend ein basket", WorkbasketType.GROUP);
    workbasket3 = workBasketService.createWorkbasket(workbasket3);
    createWorkbasketWithSecurity(workbasket3, "Elena", true, true, false, false);
    List<String> newDistTargets = new ArrayList<>(Arrays.asList(workbasket3.getId()));
    Thread.sleep(SLEEP_TIME);
    workBasketService.setDistributionTargets(workbasket2.getId(), newDistTargets);
    Workbasket foundBasket = workBasketService.getWorkbasket(workbasket2.getId());
    List<WorkbasketSummary> distributionTargets = workBasketService.getDistributionTargets(foundBasket.getId());
    Assert.assertEquals(1, distributionTargets.size());
    Assert.assertEquals(workbasket3.getId(), distributionTargets.get(0).getId());
    Assert.assertNotEquals(workBasketService.getWorkbasket(id2).getCreated(), workBasketService.getWorkbasket(id2).getModified());
    Assert.assertEquals(workBasketService.getWorkbasket(id1).getCreated(), workBasketService.getWorkbasket(id1).getModified());
    Assert.assertEquals(workBasketService.getWorkbasket(id3).getCreated(), workBasketService.getWorkbasket(id3).getModified());
    connection.commit();
}
Also used : Connection(java.sql.Connection) ArrayList(java.util.ArrayList) Workbasket(pro.taskana.Workbasket) WorkbasketSummary(pro.taskana.WorkbasketSummary) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Aggregations

WorkbasketSummary (pro.taskana.WorkbasketSummary)66 Test (org.junit.Test)56 WorkbasketService (pro.taskana.WorkbasketService)53 AbstractAccTest (acceptance.AbstractAccTest)52 WithAccessId (pro.taskana.security.WithAccessId)51 ArrayList (java.util.ArrayList)15 Workbasket (pro.taskana.Workbasket)9 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)7 WorkbasketQuery (pro.taskana.WorkbasketQuery)5 Classification (pro.taskana.Classification)3 Task (pro.taskana.Task)3 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)3 WorkbasketNotFoundException (pro.taskana.exceptions.WorkbasketNotFoundException)3 Instant (java.time.Instant)2 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 PersistenceException (org.apache.ibatis.exceptions.PersistenceException)2 Ignore (org.junit.Ignore)2