List of usage examples for org.springframework.data.domain PageImpl PageImpl
public PageImpl(List<T> content, Pageable pageable, long total)
From source file:org.openlmis.fulfillment.service.OrderServiceTest.java
@Test public void shouldFindOrderIfMatchedSupplyingAndRequestingFacilitiesAndProgram() { Order order = generateOrder();/* w ww . j a v a2 s . c o m*/ Pageable pageable = new PageRequest(0, 10); UserDto user = new UserDataBuilder().build(); PermissionStrings.Handler handler = mock(PermissionStrings.Handler.class); when(handler.getFacilityIds(ORDERS_EDIT, ORDERS_VIEW, SHIPMENTS_EDIT, SHIPMENTS_VIEW)) .thenReturn(newHashSet(order.getSupplyingFacilityId())); when(handler.getFacilityIds(PODS_MANAGE, PODS_VIEW)) .thenReturn(newHashSet(order.getRequestingFacilityId())); when(permissionService.getPermissionStrings(user.getId())).thenReturn(handler); OrderSearchParams params = new OrderSearchParams(order.getSupplyingFacilityId(), order.getRequestingFacilityId(), order.getProgramId(), order.getProcessingPeriodId(), Sets.newHashSet(order.getStatus().toString()), null, null); when(orderRepository.searchOrders(params, asSet(order.getProcessingPeriodId()), pageable, newHashSet(order.getSupplyingFacilityId()), newHashSet(order.getRequestingFacilityId()))) .thenReturn(new PageImpl<>(Collections.singletonList(order), pageable, 1)); when(authenticationHelper.getCurrentUser()).thenReturn(user); Page<Order> receivedOrders = orderService.searchOrders(params, pageable); assertEquals(1, receivedOrders.getContent().size()); assertEquals(receivedOrders.getContent().get(0).getSupplyingFacilityId(), order.getSupplyingFacilityId()); assertEquals(receivedOrders.getContent().get(0).getRequestingFacilityId(), order.getRequestingFacilityId()); assertEquals(receivedOrders.getContent().get(0).getProgramId(), order.getProgramId()); verify(orderRepository, atLeastOnce()).searchOrders(anyObject(), anyObject(), anyObject(), anySet(), anySet()); }
From source file:es.fdi.reservas.reserva.business.boundary.ReservaService.java
public Page<Reserva> getReservasPaginadas(PageRequest pageRequest, Long sala) { List<Reserva> lista = reserva_repository.findByEspacioId(sala); Page<Reserva> pagina = new PageImpl<Reserva>(lista, pageRequest, 5); return pagina; }
From source file:com.ethlo.geodata.GeodataServiceImpl.java
@Override public Page<GeoLocation> findChildren(long locationId, Pageable pageable) { final Node node = nodes.get(locationId); final long total = node.getChildren().size(); final List<Long> ids = node.getChildren().stream().skip(pageable.getOffset()).limit(pageable.getPageSize()) .map(Node::getId).collect(Collectors.toList()); final List<GeoLocation> content = findByIds(ids).stream().filter(Objects::nonNull) .collect(Collectors.toList()); content.sort((a, b) -> a.getName().compareTo(b.getName())); return new PageImpl<>(content, pageable, total); }
From source file:nu.yona.server.analysis.service.ActivityService.java
@Transactional public Page<DayActivityOverviewDto<DayActivityWithBuddiesDto>> getUserDayActivityOverviewsWithBuddies( UUID userId, Pageable pageable) { UUID userAnonymizedId = userService.getUserAnonymizedId(userId); UserAnonymizedDto userAnonymized = userAnonymizedService.getUserAnonymized(userAnonymizedId); Interval interval = getInterval(getCurrentDayDate(userAnonymized), pageable, ChronoUnit.DAYS); Set<BuddyDto> buddies = buddyService.getBuddiesOfUserThatAcceptedSending(userId); List<DayActivityOverviewDto<DayActivityWithBuddiesDto>> dayActivityOverviews = getUserDayActivityOverviewsWithBuddies( userAnonymizedId, interval, buddies); return new PageImpl<>(dayActivityOverviews, pageable, getTotalPageableItems(buddies, ChronoUnit.DAYS)); }
From source file:org.openlmis.fulfillment.service.OrderServiceTest.java
@Test public void shouldNotCheckPermissionWhenCrossServiceRequest() { Order order = generateOrder();//from www. j a va2s . c o m Pageable pageable = new PageRequest(0, 10); OrderSearchParams params = new OrderSearchParams(order.getSupplyingFacilityId(), order.getRequestingFacilityId(), order.getProgramId(), order.getProcessingPeriodId(), Sets.newHashSet(order.getStatus().toString()), null, null); when(orderRepository.searchOrders(params, asSet(order.getProcessingPeriodId()), pageable)) .thenReturn(new PageImpl<>(Collections.singletonList(order), pageable, 1)); when(authenticationHelper.getCurrentUser()).thenReturn(null); Page<Order> receivedOrders = orderService.searchOrders(params, pageable); assertEquals(receivedOrders.getContent().get(0).getSupplyingFacilityId(), order.getSupplyingFacilityId()); assertEquals(receivedOrders.getContent().get(0).getRequestingFacilityId(), order.getRequestingFacilityId()); assertEquals(receivedOrders.getContent().get(0).getProgramId(), order.getProgramId()); verify(orderRepository, atLeastOnce()).searchOrders(anyObject(), anyObject(), anyObject()); verify(permissionService, never()).getPermissionStrings(anyObject()); }
From source file:com.ethlo.geodata.GeodataServiceImpl.java
@Override public Page<Country> findCountries(Pageable pageable) { final List<Country> content = geoNamesRepository.getCountries().values().stream().skip(pageable.getOffset()) .limit(pageable.getPageSize()).collect(Collectors.toList()); return new PageImpl<>(content, pageable, geoNamesRepository.getCountries().size()); }
From source file:uk.ac.ebi.ep.controller.BrowseTaxonomyController.java
@RequestMapping(value = FILTER_BY_FACETS, method = RequestMethod.GET) public String filterByFacets(@ModelAttribute("searchModel") SearchModel searchModel, @RequestParam(value = "taxId", required = true) Long taxId, @RequestParam(value = "organismName", required = false) String organismName, Model model, HttpServletRequest request, HttpSession session, RedirectAttributes attributes) { List<Species> species = enzymePortalService.findSpeciesByTaxId(taxId); List<Compound> compouds = enzymePortalService.findCompoundsByTaxId(taxId); List<Disease> diseases = enzymePortalService.findDiseasesByTaxId(taxId); List<EcNumber> enzymeFamilies = enzymePortalService.findEnzymeFamiliesByTaxId(taxId); SearchFilters filters = new SearchFilters(); filters.setSpecies(species);/*w ww . java 2 s .c o m*/ filters.setCompounds(compouds); filters.setDiseases(diseases); filters.setEcNumbers(enzymeFamilies); SearchParams searchParams = searchModel.getSearchparams(); searchParams.setText(organismName); searchParams.setSize(SEARCH_PAGESIZE); searchModel.setSearchparams(searchParams); SearchResults searchResults = new SearchResults(); searchResults.setSearchfilters(filters); searchModel.setSearchresults(searchResults); SearchParams searchParameters = searchModel.getSearchparams(); String compound_autocompleteFilter = request.getParameter("searchparams.compounds"); String specie_autocompleteFilter = request.getParameter("_ctempList_selected"); String diseases_autocompleteFilter = request.getParameter("_DtempList_selected"); // Filter: List<String> specieFilter = searchParameters.getSpecies(); List<String> compoundFilter = searchParameters.getCompounds(); List<String> diseaseFilter = searchParameters.getDiseases(); List<Integer> ecFilter = searchParameters.getEcFamilies(); //remove empty string in the filter to avoid unsual behavior of the filter facets if (specieFilter.contains("")) { specieFilter.remove(""); } if (compoundFilter.contains("")) { compoundFilter.remove(""); } if (diseaseFilter.contains("")) { diseaseFilter.remove(""); } //to ensure that the seleted item is used in species filter, add the selected to the list. this is a workaround. different JS were used for auto complete and normal filter if ((specie_autocompleteFilter != null && StringUtils.hasLength(specie_autocompleteFilter) == true) && StringUtils.isEmpty(compound_autocompleteFilter) && StringUtils.isEmpty(diseases_autocompleteFilter)) { specieFilter.add(specie_autocompleteFilter); } if ((diseases_autocompleteFilter != null && StringUtils.hasLength(diseases_autocompleteFilter) == true) && StringUtils.isEmpty(compound_autocompleteFilter) && StringUtils.isEmpty(specie_autocompleteFilter)) { diseaseFilter.add(diseases_autocompleteFilter); } //both from auto complete and normal selection. selected items are displayed on top the list and returns back to the orignial list when not selected. //SearchResults searchResults = resultSet; List<Species> defaultSpeciesList = searchResults.getSearchfilters().getSpecies(); resetSelectedSpecies(defaultSpeciesList); searchParameters.getSpecies().stream().forEach((selectedItems) -> { defaultSpeciesList.stream() .filter((theSpecies) -> (selectedItems.equals(theSpecies.getScientificname()))) .forEach((theSpecies) -> { theSpecies.setSelected(true); }); }); List<Compound> defaultCompoundList = searchResults.getSearchfilters().getCompounds(); resetSelectedCompounds(defaultCompoundList); searchParameters.getCompounds().stream().forEach((SelectedCompounds) -> { defaultCompoundList.stream().filter((theCompound) -> (SelectedCompounds.equals(theCompound.getName()))) .forEach((theCompound) -> { theCompound.setSelected(true); }); }); List<Disease> defaultDiseaseList = searchResults.getSearchfilters().getDiseases(); resetSelectedDisease(defaultDiseaseList); searchParameters.getDiseases().stream().forEach((selectedDisease) -> { defaultDiseaseList.stream().filter((disease) -> (selectedDisease.equals(disease.getName()))) .forEach((disease) -> { disease.setSelected(true); }); }); List<EcNumber> defaultEcNumberList = searchResults.getSearchfilters().getEcNumbers(); resetSelectedEcNumber(defaultEcNumberList); searchParameters.getEcFamilies().stream().forEach((selectedEcFamily) -> { defaultEcNumberList.stream().filter((ec) -> (selectedEcFamily.equals(ec.getEc()))).forEach((ec) -> { ec.setSelected(true); }); }); Pageable pageable = new PageRequest(0, SEARCH_PAGESIZE, Sort.Direction.ASC, "function", "entryType"); Page<UniprotEntry> page = new PageImpl<>(new ArrayList<>(), pageable, 0); //specie only if (specieFilter.isEmpty() && compoundFilter.isEmpty() && diseaseFilter.isEmpty()) { page = enzymePortalService.filterBySpecie(taxId, pageable); } //specie only if (!specieFilter.isEmpty() && compoundFilter.isEmpty() && diseaseFilter.isEmpty()) { page = enzymePortalService.filterBySpecie(taxId, pageable); } // compounds only if (!compoundFilter.isEmpty() && diseaseFilter.isEmpty()) { page = enzymePortalService.filterBySpecieAndCompounds(taxId, compoundFilter, pageable); } // disease only if (compoundFilter.isEmpty() && !diseaseFilter.isEmpty()) { page = enzymePortalService.filterBySpecieAndDiseases(taxId, diseaseFilter, pageable); } //ec only if (compoundFilter.isEmpty() && diseaseFilter.isEmpty() && !ecFilter.isEmpty()) { page = enzymePortalService.filterBySpecieAndEc(taxId, ecFilter, pageable); } //compound and diseases if (!compoundFilter.isEmpty() && !diseaseFilter.isEmpty() && ecFilter.isEmpty()) { page = enzymePortalService.filterBySpecieAndCompoundsAndDiseases(taxId, compoundFilter, diseaseFilter, pageable); } //compound and ec if (!compoundFilter.isEmpty() && !ecFilter.isEmpty() && diseaseFilter.isEmpty()) { page = enzymePortalService.filterBySpecieAndCompoundsAndEc(taxId, compoundFilter, ecFilter, pageable); } //disease and ec if (!ecFilter.isEmpty() && !diseaseFilter.isEmpty() && compoundFilter.isEmpty()) { page = enzymePortalService.filterBySpecieAndDiseasesAndEc(taxId, diseaseFilter, ecFilter, pageable); } //disease and compounds and ec if (!ecFilter.isEmpty() && !diseaseFilter.isEmpty() && !compoundFilter.isEmpty()) { page = enzymePortalService.filterBySpecieAndCompoundsAndDiseasesAndEc(taxId, compoundFilter, diseaseFilter, ecFilter, pageable); } model.addAttribute("searchFilter", filters); List<UniprotEntry> result = page.getContent(); int current = page.getNumber() + 1; int begin = Math.max(1, current - 5); int end = Math.min(begin + 10, page.getTotalPages()); model.addAttribute("page", page); model.addAttribute("beginIndex", begin); model.addAttribute("endIndex", end); model.addAttribute("currentIndex", current); model.addAttribute("organismName", organismName); model.addAttribute("taxId", taxId); model.addAttribute("summaryEntries", result); searchResults.setTotalfound(page.getTotalElements()); searchResults.setSearchfilters(filters); searchResults.setSummaryentries(result); searchModel.setSearchresults(searchResults); model.addAttribute("searchModel", searchModel); model.addAttribute("searchConfig", searchConfig); String searchKey = getSearchKey(searchModel.getSearchparams()); cacheSearch(session.getServletContext(), searchKey, searchResults); setLastSummaries(session, searchResults.getSummaryentries()); clearHistory(session); addToHistory(session, searchModel.getSearchparams().getType(), searchKey); return RESULT; }
From source file:com.luna.common.repository.support.SimpleBaseRepository.java
@Override public Page<M> findAll(final Pageable pageable) { return new PageImpl<M>(repositoryHelper.<M>findAll(findAllQL, pageable), pageable, repositoryHelper.count(countAllQL)); }
From source file:com.uni.dao.etc.UniJpaRepository.java
/** * Reads the given {@link TypedQuery} into a {@link Page} applying the given {@link Pageable} and * {@link Specification}./*from ww w . ja v a 2 s. co m*/ * * @param query must not be {@literal null}. * @param spec can be {@literal null}. * @param pageable can be {@literal null}. * @return */ private Page<T> readPage(TypedQuery<T> query, Pageable pageable, Specification<T> spec) { query.setFirstResult(pageable.getOffset()); query.setMaxResults(pageable.getPageSize()); Long total = QueryUtils.executeCountQuery(getCountQuery(spec)); List<T> content = total > pageable.getOffset() ? query.getResultList() : Collections.<T>emptyList(); return new PageImpl<T>(content, pageable, total); }
From source file:com.thinkbiganalytics.metadata.modeshape.BaseJcrProvider.java
@Override public Page<T> findPage(Pageable pageable, String filter) { int count = findCount(filter); if (count > 0) { StringBuilder bldr = startBaseQuery(); appendJoins(bldr, pageable, filter); appendFilter(bldr, filter);// ww w.ja v a2 s . c o m appendSort(bldr, pageable); appendOffset(bldr, pageable); String query = bldr.toString(); List<T> list = find(query); return new PageImpl<>(list, pageable, count); } else { return new PageImpl<T>(Collections.emptyList()); } }