use of org.entando.entando.aps.system.services.page.model.PageSearchDto in project entando-core by entando.
the class PageServiceTest method mockPagedMetadata.
/**
* init mock for a multipaged request
*/
private void mockPagedMetadata(Page page, PageDto pageDto, String[] utilizers, int currPage, int lastPage, int pageSize, int totalSize) {
try {
when(pageManager.getDraftPage(page.getCode())).thenReturn(page);
when(pageTokenManager.encrypt(page.getCode())).thenReturn(PageMockHelper.TOKEN);
when(dtoBuilder.convert(any(IPage.class))).thenReturn(pageDto);
when(applicationContext.getBeanNamesForType((Class<?>) any())).thenReturn(PageMockHelper.UTILIZERS);
when(applicationContext.getBean(anyString())).thenReturn(pageUtilizer);
when(pageUtilizer.getPageUtilizers(page.getCode())).thenReturn(Arrays.asList(PageMockHelper.UTILIZERS));
when(pageUtilizer.getName()).thenReturn(PageMockHelper.UTILIZER_1).thenReturn(PageMockHelper.UTILIZER_2);
PageSearchRequest pageSearchRequest = new PageSearchRequest(PageMockHelper.PAGE_CODE);
pageSearchRequest.setPageSize(pageSize);
PageSearchDto pageSearchDto = new PageSearchDto(pageSearchRequest, Collections.singletonList(pageDto));
pageSearchDto.setPageSize(pageSize);
pageSearchDto.imposeLimits();
List<ComponentUsageEntity> componentUsageEntityList = Arrays.stream(utilizers).map(child -> new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE, child)).collect(Collectors.toList());
if (pageDto.getStatus().equals(IPageService.STATUS_ONLINE) && currPage == lastPage) {
componentUsageEntityList.add(new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE, page.getCode()));
}
PagedMetadata pagedMetadata = new PagedMetadata(pageSearchRequest, componentUsageEntityList, totalSize);
pagedMetadata.setPageSize(pageSize);
pagedMetadata.setPage(currPage);
pagedMetadata.imposeLimits();
when(pagedMetadataMapper.getPagedResult(any(), any())).thenReturn(pagedMetadata);
} catch (Exception e) {
Assert.fail("Mock Exception");
}
}
use of org.entando.entando.aps.system.services.page.model.PageSearchDto in project entando-core by entando.
the class PageSearchMapper method toPageSearchDto.
/**
* craetes a PageSearchDto starting from the received data
*
* @param request
* @param pages
* @return the created
*/
public PagedMetadata<PageDto> toPageSearchDto(PageSearchRequest request, List<PageDto> pages) {
BeanComparator<PageDto> comparator = new BeanComparator<>(request.getSort());
if (request.getDirection().equals(FieldSearchFilter.DESC_ORDER)) {
pages.sort(comparator.reversed());
} else {
pages.sort(comparator);
}
PageSearchDto result = new PageSearchDto(request, pages);
result.imposeLimits();
return result;
}
use of org.entando.entando.aps.system.services.page.model.PageSearchDto in project entando-core by entando.
the class PageService method getPagedResult.
private PagedMetadata<PageDto> getPagedResult(PageSearchRequest request, List<PageDto> pages) {
BeanComparator comparator = new BeanComparator(request.getSort());
if (request.getDirection().equals(FieldSearchFilter.DESC_ORDER)) {
Collections.sort(pages, comparator.reversed());
} else {
Collections.sort(pages, comparator);
}
PageSearchDto result = new PageSearchDto(request, pages);
result.imposeLimits();
return result;
}
Aggregations