use of pro.taskana.rest.resource.WorkbasketSummaryResource 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);
}
use of pro.taskana.rest.resource.WorkbasketSummaryResource in project taskana by Taskana.
the class WorkbasketSummaryResourceAssembler method toResource.
@Override
public WorkbasketSummaryResource toResource(WorkbasketSummary workbasketSummary) {
WorkbasketSummaryResource resource = createResourceWithId(workbasketSummary.getId(), workbasketSummary);
BeanUtils.copyProperties(workbasketSummary, resource);
// named different so needs to be set by hand
resource.setWorkbasketId(workbasketSummary.getId());
return resource;
}
use of pro.taskana.rest.resource.WorkbasketSummaryResource in project taskana by Taskana.
the class WorkbasketSummaryResourcesAssembler method toResources.
public PagedResources<WorkbasketSummaryResource> toResources(List<WorkbasketSummary> workbasketSummaries, PageMetadata pageMetadata) {
WorkbasketSummaryResourceAssembler assembler = new WorkbasketSummaryResourceAssembler();
List<WorkbasketSummaryResource> resources = assembler.toResources(workbasketSummaries);
PagedResources<WorkbasketSummaryResource> pagedResources = new PagedResources<WorkbasketSummaryResource>(resources, pageMetadata);
UriComponentsBuilder original = getBuilderForOriginalUri();
pagedResources.add(new Link(original.toUriString()).withSelfRel());
if (pageMetadata != null) {
pagedResources.add(linkTo(WorkbasketController.class).withRel("allWorkbaskets"));
pagedResources.add(new Link(original.replaceQueryParam("page", 1).toUriString()).withRel(Link.REL_FIRST));
pagedResources.add(new Link(original.replaceQueryParam("page", pageMetadata.getTotalPages()).toUriString()).withRel(Link.REL_LAST));
if (pageMetadata.getNumber() > 1) {
pagedResources.add(new Link(original.replaceQueryParam("page", pageMetadata.getNumber() - 1).toUriString()).withRel(Link.REL_PREVIOUS));
}
if (pageMetadata.getNumber() < pageMetadata.getTotalPages()) {
pagedResources.add(new Link(original.replaceQueryParam("page", pageMetadata.getNumber() + 1).toUriString()).withRel(Link.REL_NEXT));
}
}
return pagedResources;
}
use of pro.taskana.rest.resource.WorkbasketSummaryResource in project taskana by Taskana.
the class WorkbasketSummaryMapperTest method workbasketSummaryToResource.
@Test
public void workbasketSummaryToResource() throws WorkbasketNotFoundException, NotAuthorizedException {
// given
WorkbasketSummaryImpl workbasketSummary = (WorkbasketSummaryImpl) workbasketService.newWorkbasket("1", "DOMAIN_A").asSummary();
workbasketSummary.setDescription("WorkbasketSummaryImplTes");
workbasketSummary.setId("1");
workbasketSummary.setName("WorkbasketSummary");
workbasketSummary.setOrgLevel1("Org1");
workbasketSummary.setOrgLevel2("Org2");
workbasketSummary.setOrgLevel3("Org3");
workbasketSummary.setOrgLevel4("Org4");
workbasketSummary.setOwner("Lars");
workbasketSummary.setType(WorkbasketType.PERSONAL);
// when
WorkbasketSummaryResource workbasketSummaryResource = workbasketSummaryMapper.toResource(workbasketSummary);
// then
Assert.assertEquals(workbasketSummary.getDescription(), workbasketSummaryResource.description);
Assert.assertEquals(workbasketSummary.getDomain(), workbasketSummaryResource.domain);
Assert.assertEquals(workbasketSummary.getId(), workbasketSummaryResource.workbasketId);
Assert.assertEquals(workbasketSummary.getKey(), workbasketSummaryResource.key);
Assert.assertEquals(workbasketSummary.getName(), workbasketSummaryResource.name);
Assert.assertEquals(workbasketSummary.getOrgLevel1(), workbasketSummaryResource.orgLevel1);
Assert.assertEquals(workbasketSummary.getOrgLevel2(), workbasketSummaryResource.orgLevel2);
Assert.assertEquals(workbasketSummary.getOrgLevel3(), workbasketSummaryResource.orgLevel3);
Assert.assertEquals(workbasketSummary.getOrgLevel4(), workbasketSummaryResource.orgLevel4);
Assert.assertEquals(workbasketSummary.getOwner(), workbasketSummaryResource.owner);
Assert.assertEquals(workbasketSummary.getType(), workbasketSummaryResource.type);
}
use of pro.taskana.rest.resource.WorkbasketSummaryResource in project taskana by Taskana.
the class WorkbasketSummaryMapper method toResource.
public WorkbasketSummaryResource toResource(WorkbasketSummary summary) throws WorkbasketNotFoundException, NotAuthorizedException {
WorkbasketSummaryResource resource = new WorkbasketSummaryResource();
BeanUtils.copyProperties(summary, resource);
// named different so needs to be set by hand
resource.setWorkbasketId(summary.getId());
return addLinks(resource, summary);
}
Aggregations