List of usage examples for org.springframework.data.domain PageImpl PageImpl
public PageImpl(List<T> content, Pageable pageable, long total)
From source file:org.venice.piazza.common.hibernate.dao.job.JobDaoImpl.java
public Page<JobEntity> getJobListByStatus(String status, Pagination pagination) { // Query//from ww w . j ava 2s. c om String queryString = String.format(STATUS_JOB_QUERY, Direction.fromString(pagination.getOrder())); Query query = entityManager.createNativeQuery(queryString, JobEntity.class); query.setParameter(1, status); query.setParameter(2, pagination.getSortBy()); query.setParameter(3, pagination.getPerPage()); query.setParameter(4, pagination.getPage() * pagination.getPerPage()); List<JobEntity> results = query.getResultList(); // Count query = entityManager.createNativeQuery(STATUS_JOB_QUERY_COUNT); query.setParameter(1, status); long count = ((BigInteger) query.getSingleResult()).longValue(); return new PageImpl<JobEntity>(results, null, count); }
From source file:com.alliander.osgp.acceptancetests.devicemanagement.FindDevicesSteps.java
@DomainStep("a device (.*) with ownerid (.*) and ownername (.*)") public void andADevice(final String deviceIdentification, final String ownerId, final String ownerName) throws UnknownHostException { this.ownerOrganisation = new Organisation(ownerId, ownerName, ORGANISATION_PREFIX, PlatformFunctionGroup.ADMIN); this.device = new DeviceBuilder().withDeviceIdentification(deviceIdentification) .withNetworkAddress(InetAddress.getLocalHost()).build(); this.device.addAuthorization(this.ownerOrganisation, DeviceFunctionGroup.OWNER); this.pageRequest = new PageRequest(DEFAULT_PAGE, DEFAULT_PAGESIZE, Sort.Direction.DESC, "creationTime"); final List<Device> devicesList = new ArrayList<Device>(); devicesList.add(this.device); this.devices = new PageImpl<Device>(devicesList, this.pageRequest, devicesList.size()); when(this.deviceRepositoryMock.findAll(this.pageRequest)).thenReturn(this.devices); when(this.ssldRepositoryMock.findByDeviceIdentification(any(String.class))).thenReturn(null); when(this.ssldRepositoryMock.findOne(any(Long.class))).thenReturn(null); final List<DeviceAuthorization> authorizations = new ArrayList<>(); authorizations.add(new DeviceAuthorizationBuilder().withDevice(this.device) .withOrganisation(this.organisation).withFunctionGroup(DeviceFunctionGroup.OWNER).build()); when(this.deviceAuthorizationRepositoryMock.findByOrganisationAndDevice(this.organisation, this.device)) .thenReturn(authorizations); }
From source file:br.com.joaops.smt.service.SystemUserServiceImpl.java
@Transactional(readOnly = true) @Override/*from w w w .j av a 2 s .c o m*/ public Page<SystemUserDto> searchAllUsers(Pageable p) { List<SystemUserDto> usersDto = new ArrayList<>(); Page<SystemUser> systemUsers = repository.findAll(p); for (SystemUser systemUser : systemUsers) { SystemUserDto userDto = new SystemUserDto(); mapper.map(systemUser, userDto); usersDto.add(userDto); } Page<SystemUserDto> page = null; if (!usersDto.isEmpty()) { page = new PageImpl<>(usersDto, p, usersDto.size()); } return page; }
From source file:siddur.solidtrust.image.ImageController.java
@RequestMapping(value = "/image/manage") @Transactional(readOnly = true)// w w w. ja v a2s . co m public String manage(@RequestParam(value = "type", required = false, defaultValue = "0") int type, @RequestParam(value = "daterange", required = false) String daterange, @RequestParam(value = "page", required = false, defaultValue = "1") Integer pageIndex, Model model) throws Exception { int pageSize = 8; Pageable pageable = new PageRequest(pageIndex - 1, pageSize); Page<ImageProduct> page = null; if (type == 0) { List<ImageProduct> list = em.createQuery("from ImageProduct", ImageProduct.class) .setFirstResult((pageIndex - 1) * pageSize).setMaxResults(pageSize).getResultList(); long count = em.createQuery("select count(ip) from ImageProduct ip", Long.class).getSingleResult(); page = new PageImpl<ImageProduct>(list, pageable, count); } else if (type == 1) { if (daterange.equals("")) { type = 0; } else { model.addAttribute("daterange", daterange); String[] dates = daterange.split(" - "); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); Date from = formatter.parse(dates[0]); Date to = formatter.parse(dates[1]); to = DateUtils.addDays(to, 1); List<ImageProduct> list = em .createQuery("from ImageProduct ip where ip.createdAt between :from and :to", ImageProduct.class) .setParameter("from", from).setParameter("to", to) .setFirstResult((pageIndex - 1) * pageSize).setMaxResults(pageSize).getResultList(); long count = em.createQuery( "select count(ip) from ImageProduct ip where ip.createdAt between :from and :to", Long.class).setParameter("from", from).setParameter("to", to).getSingleResult(); page = new PageImpl<ImageProduct>(list, pageable, count); } } if (page != null) model.addAttribute("page", page); model.addAttribute("type", type); return "image/manage"; }
From source file:eu.trentorise.game.api.rest.MainController.java
@RequestMapping(method = RequestMethod.GET, value = "/state/{gameId}", produces = { "application/json" }) @ApiOperation(value = "Get player states", notes = "Get the state of players in a game filter by optional player name") @ApiImplicitParams({//from w w w.j av a 2s.c o m @ApiImplicitParam(name = "page", dataType = "integer", paramType = "query", value = "Results page you want to retrieve "), @ApiImplicitParam(name = "size", dataType = "integer", paramType = "query", value = "Number of records per page."), }) public Page<PlayerStateDTO> readPlayerState(@PathVariable String gameId, @ApiIgnore Pageable pageable, @RequestParam(required = false) String playerFilter) { try { gameId = URLDecoder.decode(gameId, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("gameId is not UTF-8 encoded"); } List<PlayerStateDTO> resList = new ArrayList<PlayerStateDTO>(); Page<PlayerState> page = null; if (playerFilter == null) { page = playerSrv.loadStates(gameId, pageable); } else { page = playerSrv.loadStates(gameId, playerFilter, pageable); } for (PlayerState ps : page) { resList.add(converter.convertPlayerState(ps)); } PageImpl<PlayerStateDTO> res = new PageImpl<PlayerStateDTO>(resList, pageable, page.getTotalElements()); return res; }
From source file:org.venice.piazza.common.hibernate.dao.service.ServiceDaoImpl.java
public Page<ServiceEntity> getServiceListByUser(String userName, Pagination pagination) { // Query/*from w w w . j av a2 s .c o m*/ String queryString = String.format(USERNAME_SERVICE_QUERY, Direction.fromString(pagination.getOrder())); Query query = entityManager.createNativeQuery(queryString, ServiceEntity.class); query.setParameter(1, String.format(WILDCARD_STRING_QUERY, userName)); query.setParameter(2, pagination.getSortBy()); query.setParameter(3, pagination.getPerPage()); query.setParameter(4, pagination.getPage() * pagination.getPerPage()); List<ServiceEntity> results = query.getResultList(); // Count query = entityManager.createNativeQuery(USERNAME_SERVICE_QUERY_COUNT); query.setParameter(1, String.format(WILDCARD_STRING_QUERY, userName)); long count = ((BigInteger) query.getSingleResult()).longValue(); return new PageImpl<ServiceEntity>(results, null, count); }
From source file:com.sample.ecommerce.util.ElasticSearchUtil.java
private Page<List> pageOf(Map<String, Object> searchResponse, Pageable pageable) { Page<List> page = null; List<Map<String, Object>> list = resultsOf(searchResponse); if (list != null) { Integer noOfRecords = (Integer) ((Map<String, Object>) searchResponse.get("hits")).get("total"); page = new PageImpl(list, pageable, noOfRecords); }// w w w. j av a 2 s .c o m return page; }
From source file:org.terasoluna.gfw.web.pagination.PaginationInfoTest.java
@Test public void testGetLastUrl() { List<String> mockedList = new ArrayList<String>(); PageRequest pageable = new PageRequest(2, 2); page = new PageImpl<String>(mockedList, pageable, 4L); PaginationInfo info = new PaginationInfo(page, pathTmpl, queryTmpl, 0); // expected/* w w w. j a v a2 s. c om*/ String expectedURL = "terasoluna?value=test&page=1&size=2"; // run String lastURL = info.getLastUrl(); // assert assertThat(lastURL, is(expectedURL)); }
From source file:eu.trentorise.game.api.rest.platform.DomainMainController.java
@RequestMapping(method = RequestMethod.GET, value = "/state/{gameId}", produces = { "application/json" }) @ApiOperation(value = "Get player states", notes = "Get the state of players in a game filter by optional player name") @ApiImplicitParams({// w ww . j a v a2 s . c o m @ApiImplicitParam(name = "page", dataType = "integer", paramType = "query", value = "Results page you want to retrieve "), @ApiImplicitParam(name = "size", dataType = "integer", paramType = "query", value = "Number of records per page."), }) public Page<PlayerStateDTO> readPlayerState(@PathVariable String domain, @PathVariable String gameId, @ApiIgnore Pageable pageable, @RequestParam(required = false) String playerFilter) { try { gameId = URLDecoder.decode(gameId, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("gameId is not UTF-8 encoded"); } List<PlayerStateDTO> resList = new ArrayList<PlayerStateDTO>(); Page<PlayerState> page = null; if (playerFilter == null) { page = playerSrv.loadStates(gameId, pageable); } else { page = playerSrv.loadStates(gameId, playerFilter, pageable); } for (PlayerState ps : page) { resList.add(converter.convertPlayerState(ps)); } PageImpl<PlayerStateDTO> res = new PageImpl<PlayerStateDTO>(resList, pageable, page.getTotalElements()); return res; }
From source file:com.jiwhiz.rest.site.PublicBlogRestControllerTest.java
@Test public void getBlogApprovedCommentPosts_ShouldReturnApprovedComments() throws Exception { BlogPost blog = getTestSinglePublishedBlogPost(); Page<CommentPost> page = new PageImpl<CommentPost>(getTestApprovedCommentPostList(), new PageRequest(0, 10), 2);//from w ww . java 2 s . co m when(blogPostRepositoryMock.findOne(BLOG_ID)).thenReturn(blog); when(commentPostRepositoryMock.findByBlogPostAndStatusOrderByCreatedTimeAsc(any(BlogPost.class), eq(CommentStatusType.APPROVED), any(Pageable.class))).thenReturn(page); mockMvc.perform(get(API_ROOT + URL_SITE_BLOGS_BLOG_COMMENTS, BLOG_ID)).andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON)) .andExpect(jsonPath("$._embedded.commentPostList", hasSize(2))) .andExpect(jsonPath("$._embedded.commentPostList[0].id", is(COMMENTS_1_ID))) .andExpect(jsonPath("$._embedded.commentPostList[0].content", is(COMMENTS_1_CONTENT))) .andExpect(jsonPath("$._embedded.commentPostList[1].id", is(COMMENTS_2_ID))) .andExpect(jsonPath("$._embedded.commentPostList[1].content", is(COMMENTS_2_CONTENT))) .andExpect(jsonPath("$._links.self.templated", is(true))) .andExpect(jsonPath("$._links.self.href", endsWith("/comments{?page,size,sort}"))); verify(blogPostRepositoryMock, times(1)).findOne(BLOG_ID); verifyNoMoreInteractions(blogPostRepositoryMock); verify(commentPostRepositoryMock, times(1)).findByBlogPostAndStatusOrderByCreatedTimeAsc( any(BlogPost.class), eq(CommentStatusType.APPROVED), any(Pageable.class)); verifyNoMoreInteractions(commentPostRepositoryMock); }