List of usage examples for org.springframework.data.domain PageImpl PageImpl
public PageImpl(List<T> content, Pageable pageable, long total)
From source file:com.wiiyaya.framework.provider.repository.BaseDaoImpl.java
@Override public Page<T> findAll(Predicate predicate, Pageable pageable) { JPQLQuery countQuery = createWhereQuery(predicate); JPQLQuery query = querydsl.applyPagination(pageable, createWhereQuery(predicate)); Long total = countQuery.count(); List<T> content = total > pageable.getOffset() ? query.list(path) : Collections.<T>emptyList(); return new PageImpl<T>(content, pageable, total); }
From source file:com.jiwhiz.rest.admin.CommentRestControllerTest.java
@Test public void getCommentPosts_ShouldReturnAllCommentPosts() throws Exception { Page<CommentPost> page = new PageImpl<CommentPost>(getTestApprovedCommentPostList(), new PageRequest(0, 10), 2);/*w ww . j ava2s.c o m*/ when(commentPostRepositoryMock.findAll(any(Pageable.class))).thenReturn(page); mockMvc.perform(get(API_ROOT + URL_ADMIN_COMMENTS + "?page=1&size=10")).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.href", endsWith(URL_ADMIN_COMMENTS + "{?page,size,sort}"))); }
From source file:org.terasoluna.gfw.functionaltest.app.el.ElListOfSimpleValueDefaultTrimController.java
@RequestMapping(value = "6_16/search", method = RequestMethod.GET) public String nestedJavaBeanQueryString(ListForm listForm, @PageableDefault Pageable pageable, Model model) { // Create Dummy Data List<String> dummyList = new ArrayList<String>(); for (int i = 1; i <= 10; i++) { dummyList.add("Dummy"); }/*w ww.jav a 2s . c o m*/ Page<String> dummyPage = new PageImpl<String>(dummyList, pageable, 100); model.addAttribute("page", dummyPage); String listA0String = Objects.toString(listForm.getListA().get(0)); String listA1String = Objects.toString(listForm.getListA().get(1)); String listA2String = Objects.toString(listForm.getListA().get(2)); String listBString = Objects.toString(listForm.getListB()); String listCString = Objects.toString(listForm.getListC()); model.addAttribute("listA0String", listA0String); model.addAttribute("listA1String", listA1String); model.addAttribute("listA2String", listA2String); model.addAttribute("listBString", listBString); model.addAttribute("listCString", listCString); String listA0StringItem = Objects.toString(listForm.getItem().getListA().get(0)); String listA1StringItem = Objects.toString(listForm.getItem().getListA().get(1)); String listA2StringItem = Objects.toString(listForm.getItem().getListA().get(2)); String listBStringItem = Objects.toString(listForm.getItem().getListB()); String listCStringItem = Objects.toString(listForm.getItem().getListC()); model.addAttribute("listA0StringItem", listA0StringItem); model.addAttribute("listA1StringItem", listA1StringItem); model.addAttribute("listA2StringItem", listA2StringItem); model.addAttribute("listBStringItem", listBStringItem); model.addAttribute("listCStringItem", listCStringItem); return "el/listOfSimpleValueDefaultTrimQueryOutput"; }
From source file:org.terasoluna.gfw.functionaltest.app.el.ElMapOfSimpleValueDefaultTrimController.java
@RequestMapping(value = "6_17/search", method = RequestMethod.GET) public String nestedJavaBeanQueryString(MapForm mapForm, @PageableDefault Pageable pageable, Model model) { // Create Dummy Data List<String> dummyList = new ArrayList<String>(); for (int i = 1; i <= 10; i++) { dummyList.add("Dummy"); }/* ww w . j av a 2 s.c o m*/ Page<String> dummyPage = new PageImpl<String>(dummyList, pageable, 100); model.addAttribute("page", dummyPage); String mapA0String = Objects.toString(mapForm.getMapA().get("a")); String mapA1String = Objects.toString(mapForm.getMapA().get("b")); String mapA2String = Objects.toString(mapForm.getMapA().get("c")); model.addAttribute("mapA0String", mapA0String); model.addAttribute("mapA1String", mapA1String); model.addAttribute("mapA2String", mapA2String); String mapA0StringItem = Objects.toString(mapForm.getItem().getMapA().get("d")); String mapA1StringItem = Objects.toString(mapForm.getItem().getMapA().get("e")); String mapA2StringItem = Objects.toString(mapForm.getItem().getMapA().get("f")); model.addAttribute("mapA0StringItem", mapA0StringItem); model.addAttribute("mapA1StringItem", mapA1StringItem); model.addAttribute("mapA2StringItem", mapA2StringItem); return "el/mapOfSimpleValueDefaultTrimQueryOutput"; }
From source file:org.terasoluna.tourreservation.domain.service.tourinfo.TourInfoServiceImplTest.java
/** * searchTourInfo return one object pattern */// www. j a v a 2 s . co m @Test public void testSearchTourInfo01() { TourInfoSearchCriteria criteria = new TourInfoSearchCriteria(); Pageable pageable = new PageRequest(0, 10); List<TourInfo> mockedList = new ArrayList<TourInfo>(); TourInfo info = new TourInfo(); Arrival a = new Arrival(); a.setArrCode("1234"); info.setArrival(a); Departure departure = new Departure(); departure.setDepCode("5678"); info.setDeparture(departure); info.setTourCode("12345678"); mockedList.add(info); Page<TourInfo> page = new PageImpl<TourInfo>(mockedList, pageable, 1L); when(tourInfoRepository.findPageBySearchCriteria(criteria, pageable)).thenReturn(mockedList); when(tourInfoRepository.countBySearchCriteria(criteria)).thenReturn(1L); // run Page<TourInfo> result = tourInfoService.searchTour(criteria, pageable); // assert assertThat(result, is(page)); }
From source file:br.com.joaops.smt.service.SystemModuleServiceImpl.java
@Transactional(readOnly = true) @Override/*from w ww. java 2 s. c om*/ public Page<SystemModuleDto> searchAllModules(Pageable p) { List<SystemModuleDto> moduleDtos = new ArrayList<>(); Page<SystemModule> modules = repository.findAll(p); for (SystemModule module : modules) { SystemModuleDto moduleDto = new SystemModuleDto(); mapper.map(module, moduleDto); moduleDtos.add(moduleDto); } Page<SystemModuleDto> page = null; if (!moduleDtos.isEmpty()) { page = new PageImpl<>(moduleDtos, p, moduleDtos.size()); } return page; }
From source file:org.terasoluna.gfw.web.pagination.PaginationInfoTest.java
@Before public void setup() { // Note://from www.j a v a 2 s. com // The page property of PageRequest is 0 start. // For example: // // 0(1 page) : 1-5 // 1(2 page) : 6-10 // 2(3 page) : 11-15 // 3(4 page) : 16-20 // 4(5 page) : 21-25 // 5(6 page) : 26-30 // 6(7 page) : 31-35 // ... PageRequest pageable = new PageRequest(5, 5); // set up the Page object for test. // // current page : 6 page (26-30) // total page : 7 page (total : 31) // (not first page and not last page) // 5 dummy record for 6 page(26-30) List<String> mockedList = new ArrayList<String>(); mockedList.add("terasoluna"); mockedList.add("terasoluna"); mockedList.add("terasoluna"); mockedList.add("terasoluna"); mockedList.add("terasoluna"); page = new PageImpl<String>(mockedList, pageable, 31L); }
From source file:com.yqboots.security.web.controller.SessionController.java
@PreAuthorize(SecurityPermissions.SESSION_READ) @RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }) public String list(@ModelAttribute(WebKeys.SEARCH_FORM) final SearchForm<String> searchForm, @PageableDefault final Pageable pageable, final ModelMap model) { if (StringUtils.isBlank(searchForm.getCriterion()) || !userManager.hasUser(searchForm.getCriterion())) { model.addAttribute(WebKeys.PAGE, new PageImpl<SessionInformation>(new ArrayList<>(), pageable, 0)); return VIEW_HOME; }// w w w. j a v a2 s. c o m final User user = userManager.findUser(searchForm.getCriterion()); model.addAttribute(WebKeys.PAGE, new PageImpl<>(sessionRegistry.getAllSessions(user, true))); return VIEW_HOME; }
From source file:com.github.markserrano.jsonquery.jpa.service.FilterService.java
@Override public Page<T> readAndCount(BooleanBuilder builder, Pageable page, Class<T> clazz, OrderSpecifier order) { Page<T> pageImpl = new PageImpl<T>(read(builder, page, clazz, order), page, count(builder, clazz, order)); return pageImpl; }
From source file:com.jiwhiz.rest.user.UserCommentRestControllerTest.java
@Test public void getCurrentUserComments_ShouldReturnAllCommentsByUser() throws Exception { UserAccount user = getTestLoggedInUserWithAdminRole(); Page<CommentPost> page = new PageImpl<CommentPost>(getTestUserCommentPostList(), new PageRequest(0, 10), 2); when(userAccountServiceMock.getCurrentUser()).thenReturn(user); when(commentPostRepositoryMock.findByAuthorOrderByCreatedTimeDesc(any(UserAccount.class), any(Pageable.class))).thenReturn(page); mockMvc.perform(get(API_ROOT + URL_USER_COMMENTS)).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[1].id", is(COMMENTS_2_ID))); }