Search in sources :

Example 6 with WorkbasketAccessItemResource

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

the class WorkbasketDefinitionMapper method toResource.

/**
 * maps the distro targets to their id to remove overhead.
 *
 * @param basket
 *            {@link Workbasket} which will be converted
 * @return a {@link WorkbasketDefinition}, containing the {@code basket}, its distribution targets and its
 *         authorizations
 * @throws NotAuthorizedException
 *             if the user is not authorized
 * @throws WorkbasketNotFoundException
 *             if {@code basket} is an unknown workbasket
 */
public WorkbasketDefinition toResource(Workbasket basket) throws NotAuthorizedException, WorkbasketNotFoundException {
    List<WorkbasketAccessItemResource> authorizations = new ArrayList<>();
    for (WorkbasketAccessItem accessItem : workbasketService.getWorkbasketAccessItems(basket.getKey())) {
        authorizations.add(workbasketAccessItemMapper.toResource(accessItem));
    }
    Set<String> distroTargets = workbasketService.getDistributionTargets(basket.getId()).stream().map(WorkbasketSummary::getId).collect(Collectors.toSet());
    WorkbasketDefinition resource = new WorkbasketDefinition(workbasketMapper.toResource(basket), distroTargets, authorizations);
    return addLinks(resource, basket);
}
Also used : WorkbasketDefinition(pro.taskana.rest.resource.WorkbasketDefinition) WorkbasketAccessItemResource(pro.taskana.rest.resource.WorkbasketAccessItemResource) WorkbasketAccessItem(pro.taskana.WorkbasketAccessItem) ArrayList(java.util.ArrayList)

Aggregations

WorkbasketAccessItemResource (pro.taskana.rest.resource.WorkbasketAccessItemResource)6 WorkbasketAccessItem (pro.taskana.WorkbasketAccessItem)5 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)2 WorkbasketDefinition (pro.taskana.rest.resource.WorkbasketDefinition)2 HashMap (java.util.HashMap)1 Resources (org.springframework.hateoas.Resources)1 ResponseEntity (org.springframework.http.ResponseEntity)1 Transactional (org.springframework.transaction.annotation.Transactional)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 Workbasket (pro.taskana.Workbasket)1 DomainNotFoundException (pro.taskana.exceptions.DomainNotFoundException)1 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)1 InvalidWorkbasketException (pro.taskana.exceptions.InvalidWorkbasketException)1 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)1 WorkbasketAlreadyExistException (pro.taskana.exceptions.WorkbasketAlreadyExistException)1 WorkbasketNotFoundException (pro.taskana.exceptions.WorkbasketNotFoundException)1 WorkbasketResource (pro.taskana.rest.resource.WorkbasketResource)1