List of usage examples for org.springframework.data.domain PageImpl PageImpl
public PageImpl(List<T> content, Pageable pageable, long total)
From source file:com.excilys.ebi.bank.dao.impl.OperationDaoImpl.java
private Page<Operation> buildPage(JPQLQuery countQuery, JPQLQuery query, Pageable pageable) { long count = countQuery.count(); return count > 0 ? new PageImpl<Operation>(query.list(operation), pageable, count) : new PageImpl<Operation>(new ArrayList<Operation>(), pageable, 0); }
From source file:edu.zipcloud.cloudstreetmarket.core.services.CommunityServiceImpl.java
@Override public Page<UserDTO> getLeaders(Pageable pageable) { Page<User> users = userRepository.findAll(pageable); List<UserDTO> result = users.getContent().stream().map(u -> hideSensitiveInformation(new UserDTO(u))) .collect(Collectors.toCollection(LinkedList::new)); return new PageImpl<>(result, pageable, users.getTotalElements()); }
From source file:cz.jirutka.spring.data.jdbc.BaseJdbcRepository.java
@Override public Page<T> findAll(Pageable page) { String query = sqlGenerator.selectAll(table, page); return new PageImpl<>(jdbcOps.query(query, rowMapper), page, count()); }
From source file:am.ik.categolj2.api.entry.EntryRestController.java
Page<EntryResource> toResourcePage(Page<Entry> page, Pageable pageable, boolean isFormatted) { List<EntryResource> resources = page.getContent().stream().map(entry -> toResource(entry, isFormatted)) .collect(Collectors.toList()); return new PageImpl<>(resources, pageable, page.getTotalElements()); }
From source file:com.jiwhiz.rest.site.WebsiteRestControllerTest.java
@Test public void getLatestBlogPost_ShouldReturnBlogPost() throws Exception { BlogPost blog = getTestSinglePublishedBlogPost(); when(blogPostRepositoryMock.findByPublishedIsTrueOrderByPublishedTimeDesc(any(Pageable.class))) .thenReturn(new PageImpl<BlogPost>(Arrays.asList(blog), new PageRequest(0, 1), 1)); mockMvc.perform(get(API_ROOT + URL_SITE_LATEST_BLOG)).andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON)).andExpect(jsonPath("$.id", is(BLOG_ID))) .andExpect(jsonPath("$.title", is(BLOG_TITLE))) .andExpect(jsonPath("$._links.self.href", endsWith(URL_SITE_BLOGS + "/" + BLOG_ID))) .andExpect(jsonPath("$._links.comments.templated", is(true))) .andExpect(jsonPath("$._links.comments.href", endsWith(URL_SITE_BLOGS + "/" + BLOG_ID + "/comments{?page,size,sort}"))) .andExpect(jsonPath("$._links.author.href", endsWith(URL_SITE_PROFILES + "/" + blog.getAuthor().getUserId()))); }
From source file:org.oncoblocks.centromere.sql.GenericJdbcRepository.java
/** * {@link RepositoryOperations#findAll}/*from w w w. j ava2 s. c o m*/ */ public Page<T> find(Iterable<QueryCriteria> queryCriterias, Pageable pageable) { SqlBuilder sqlBuilder = getSqlBuilder(); List<Condition> conditionList = new ArrayList<>(); for (QueryCriteria criteria : queryCriterias) { if (criteria != null) conditionList.add(getConditionFromQueryCriteria(criteria)); } sqlBuilder.where(and(conditionList.toArray(new Condition[] {}))); if (pageable.getSort() != null) sqlBuilder.orderBy(pageable.getSort()); sqlBuilder.limit(pageable); List<T> objects = jdbcTemplate.query(sqlBuilder.toSql(), sqlBuilder.getQueryParameterValues().toArray(), rowMapper); Long rowCount = count(queryCriterias); return new PageImpl<>(objects, pageable, rowCount); }
From source file:it.reply.orchestrator.controller.DeploymentControllerTest.java
@Test public void getPagedDeployments() throws Exception { List<Deployment> deployments = ControllerTestUtils.createDeployments(5, true); Pageable pageable = new PageRequest(1, 2, new Sort(Direction.DESC, AbstractResourceEntity.CREATED_COLUMN_NAME)); Mockito.when(deploymentService.getDeployments(pageable)) .thenReturn(new PageImpl<Deployment>(deployments, pageable, deployments.size())); mockMvc.perform(get("/deployments?page=1&size=2").accept(MediaType.APPLICATION_JSON) .header(HttpHeaders.AUTHORIZATION, OAuth2AccessToken.BEARER_TYPE + " <access token>")) .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andDo(document("deployment-paged", preprocessResponse(prettyPrint()), links(atomLinks(), linkWithRel("first").description("Hyperlink to the first page"), linkWithRel("prev").description("Hyperlink to the previous page"), linkWithRel("self").description("Self-referencing hyperlink"), linkWithRel("next").description("Self-referencing hyperlink"), linkWithRel("last").description("Hyperlink to the last page")), responseFields(fieldWithPath("links[]").ignored(), fieldWithPath("content").ignored(), fieldWithPath("page.").ignored()))); // .andExpect(jsonPath("$.content", org.hamcrest.Matchers.hasSize(1))); }
From source file:aiai.ai.launchpad.experiment.ExperimentService.java
Slice<Task> findTasks(Pageable pageable, Experiment experiment, ExperimentFeature feature, String[] params) { if (experiment == null || feature == null) { return Page.empty(); } else {/*from ww w .j av a 2s .c o m*/ if (isEmpty(params)) { if (true) throw new IllegalStateException("Not implemented yet"); return null; // return taskRepository.findByIsCompletedIsTrueAndFeatureId(pageable, feature.getId()); } else { List<Task> selected = findTaskWithFilter(experiment, feature.getId(), params); List<Task> subList = selected.subList((int) pageable.getOffset(), (int) Math.min(selected.size(), pageable.getOffset() + pageable.getPageSize())); //noinspection UnnecessaryLocalVariable final PageImpl<Task> page = new PageImpl<>(subList, pageable, selected.size()); return page; } } }
From source file:org.lightadmin.core.web.RepositoryScopedSearchController.java
private Page<?> selectPage(List<Object> items, Pageable pageable) { final List<Object> itemsOnPage = items.subList(pageable.getOffset(), Math.min(items.size(), pageable.getOffset() + pageable.getPageSize())); return new PageImpl(itemsOnPage, pageable, items.size()); }