List of usage examples for org.springframework.data.domain Page hasContent
boolean hasContent();
From source file:cn.guoyukun.spring.jpa.plugin.serivce.BaseMovableService.java
public M findNextByWeight(Integer weight) { Pageable pageable = new PageRequest(0, 1); Map<String, Object> searchParams = Maps.newHashMap(); searchParams.put("weight_gt", weight); Sort sort = new Sort(Sort.Direction.ASC, "weight"); Page<M> page = findAll(Searchable.newSearchable(searchParams).addSort(sort).setPage(pageable)); if (page.hasContent()) { return page.getContent().get(0); }//from w ww. j ava 2s .co m return null; }
From source file:uk.urchinly.wabi.expose.DownloadController.java
@RequestMapping(method = RequestMethod.GET, value = "/assets/user/{userId}") public Page<Asset> getUserAssets(@PathVariable String userId, @PageableDefault(page = 0, size = 20) Pageable pageable) { Page<Asset> assets = this.assetMongoRepository.findByUserId(userId, pageable); for (Asset asset : assets) { this.rabbitTemplate.convertAndSend(MessagingConstants.USAGE_ROUTE, new UsageEvent("view asset", asset.toString())); }// w ww . j av a 2 s. c o m if (!assets.hasContent()) { logger.debug("Download assets failed for userId {}, no asset found.", userId); } return assets; }
From source file:ca.uhn.fhir.jpa.term.BaseHapiTerminologySvc.java
private void processReindexing() { if (System.currentTimeMillis() < myNextReindexPass) { return;//from w ww. j a v a2 s.c o m } TransactionTemplate tt = new TransactionTemplate(myTransactionMgr); tt.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRES_NEW); tt.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus theArg0) { int maxResult = 1000; Page<TermConcept> resources = myConceptDao .findResourcesRequiringReindexing(new PageRequest(0, maxResult)); if (resources.hasContent() == false) { myNextReindexPass = System.currentTimeMillis() + DateUtils.MILLIS_PER_MINUTE; return; } ourLog.info("Indexing {} / {} concepts", resources.getContent().size(), resources.getTotalElements()); int count = 0; StopWatch stopwatch = new StopWatch(); for (TermConcept resourceTable : resources) { saveConcept(resourceTable); count++; } ourLog.info("Indexed {} / {} concepts in {}ms - Avg {}ms / resource", new Object[] { count, resources.getContent().size(), stopwatch.getMillis(), stopwatch.getMillisPerOperation(count) }); } }); }
From source file:com.ethlo.geodata.GeodataServiceImpl.java
@Override public GeoLocation findbyCoordinate(Coordinates point, int distance) { GeoLocation location = findWithin(point, distance); // Fall back to nearest match if (location == null) { final Page<GeoLocationDistance> nearest = findNear(point, distance, new PageRequest(0, 1)); location = nearest.hasContent() ? nearest.getContent().get(0).getLocation() : null; }/*from ww w . jav a 2 s . c om*/ if (location != null) { return location; } throw new EmptyResultDataAccessException( "Cannot find a location for position lat=" + point.getLat() + ", lng=" + point.getLng(), 1); }
From source file:com.sap.csc.poc.ems.service.admin.entitlement.EntitlementServiceImpl.java
@Override @RequestMapping(value = "entitlements/search", method = RequestMethod.GET) public ResponseEntity<Page<EntitlementInfo>> search( // Keyword @RequestParam(value = "keyword", required = false) String keyword, // Page//from www. j a v a2s . c o m @RequestParam(value = "page", required = false, defaultValue = PageConstant.DEFAULT_PAGE_INDEX) Integer page, // Size @RequestParam(value = "size", required = false, defaultValue = PageConstant.DEFAULT_PAGE_SIZE) Integer size, // Sort @RequestParam(value = "sort", required = false, defaultValue = PageConstant.DEFAULT_SORT) String sort) { Page<EntitlementInfo> entitlementPage = entitlementHeaderRepository .search(keyword, new PageRequest(page, size, StringUtils.isBlank(sort) // Search with default sort ? new Sort(Direction.DESC, EntitlementHeader_.updateOn.getName()) // Search with custom sort : new Sort(Arrays.asList(sort.split(",")).stream().map(order -> order.split(" ")) .map(order -> new Order(Direction.fromString(order[1]), order[0])) .collect(Collectors.toList())))) // Convert to dto .map(entitlement -> new EntitlementInfo(entitlement)); if (entitlementPage.hasContent()) { return new ResponseEntity<>(entitlementPage, HttpStatus.OK); } else { return new ResponseEntity<>(entitlementPage, HttpStatus.NO_CONTENT); } }
From source file:com.excilys.ebi.bank.web.controller.account.operations.OperationsTableConverter.java
@Override public OperationsTable convert(Page<Operation> source) { /*/* ww w .j a va 2 s .co m*/ * For the brave souls who get this far: You are the chosen ones, the * valiant knights of programming who toil away, without rest, fixing * our most awful code. To you, true saviors, kings of men, I say this: * never gonna give you up, never gonna let you down, never gonna run * around and desert you. Never gonna make you cry, never gonna say * goodbye. Never gonna tell a lie and hurt you. */ OperationsTable table = new OperationsTable(); table.setNumber(source.getNumber()); table.setNumberOfElements(source.getNumberOfElements()); table.setSize(source.getSize()); table.setTotalElements(source.getTotalElements()); table.setTotalPages(source.getTotalPages()); table.setHasContent(source.hasContent()); table.setHasNextPage(source.hasNextPage()); table.setHasPreviousPage(source.hasPreviousPage()); table.setFirstPage(source.isFirstPage()); table.setLastPage(source.isLastPage()); table.setStartIndex(source.getTotalElements() > 0 ? source.getSize() * source.getNumber() + 1 : 0); table.setPageIndex(source.getTotalElements() > 0 ? source.getNumber() + 1 : 0); table.setEndIndex(source.getSize() * source.getNumber() + source.getNumberOfElements()); for (Operation operation : source.getContent()) { OperationsLine line = new OperationsLine(); line.setAmount(operation.getAmount()); line.setDate(operation.getDate().toString("MM/dd/yyyy")); line.setName(operation.getName()); line.setStatus(operation.getStatus().getId()); table.getLines().add(line); } for (int i = 0; i < source.getSize() - source.getNumberOfElements(); i++) { table.getEmptyLines().add(StringUtils.EMPTY); } return table; }
From source file:com.github.vanroy.springdata.jest.JestElasticsearchTemplateTests.java
@Test public void shouldReturnResultsWithScanAndScrollForGivenSearchQuery() { //given//from w w w . j a v a2s . co m List<IndexQuery> entities = createSampleEntitiesWithMessage("Test message", 30); // when elasticsearchTemplate.bulkIndex(entities); elasticsearchTemplate.refresh(SampleEntity.class); // then SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withIndices(INDEX_NAME) .withTypes(TYPE_NAME).withPageable(new PageRequest(0, 10)).build(); String scrollId = elasticsearchTemplate.scan(searchQuery, 1000, false); List<SampleEntity> sampleEntities = new ArrayList<SampleEntity>(); boolean hasRecords = true; while (hasRecords) { Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 5000L, SampleEntity.class); if (page.hasContent()) { sampleEntities.addAll(page.getContent()); } else { hasRecords = false; } } elasticsearchTemplate.clearScroll(scrollId); assertThat(sampleEntities.size(), is(equalTo(30))); }
From source file:com.github.vanroy.springdata.jest.JestElasticsearchTemplateTests.java
@Test public void shouldReturnResultsWithScanAndScrollForGivenCriteriaQueryAndClass() { //given//w w w .j a v a 2s . c o m List<IndexQuery> entities = createSampleEntitiesWithMessage("Test message", 30); // when elasticsearchTemplate.bulkIndex(entities); elasticsearchTemplate.refresh(SampleEntity.class); // then CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria()); criteriaQuery.setPageable(new PageRequest(0, 10)); String scrollId = elasticsearchTemplate.scan(criteriaQuery, 1000, false, SampleEntity.class); List<SampleEntity> sampleEntities = new ArrayList<SampleEntity>(); boolean hasRecords = true; while (hasRecords) { Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 5000L, SampleEntity.class); if (page.hasContent()) { sampleEntities.addAll(page.getContent()); } else { hasRecords = false; } } elasticsearchTemplate.clearScroll(scrollId); assertThat(sampleEntities.size(), is(equalTo(30))); }
From source file:com.github.vanroy.springdata.jest.JestElasticsearchTemplateTests.java
@Test public void shouldReturnResultsWithScanAndScrollForGivenSearchQueryAndClass() { //given/*from w ww . j a va 2s. c om*/ List<IndexQuery> entities = createSampleEntitiesWithMessage("Test message", 30); // when elasticsearchTemplate.bulkIndex(entities); elasticsearchTemplate.refresh(SampleEntity.class); // then SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()) .withPageable(new PageRequest(0, 10)).build(); String scrollId = elasticsearchTemplate.scan(searchQuery, 1000, false, SampleEntity.class); List<SampleEntity> sampleEntities = new ArrayList<SampleEntity>(); boolean hasRecords = true; while (hasRecords) { Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 5000L, SampleEntity.class); if (page.hasContent()) { sampleEntities.addAll(page.getContent()); } else { hasRecords = false; } } elasticsearchTemplate.clearScroll(scrollId); assertThat(sampleEntities.size(), is(equalTo(30))); }
From source file:com.github.vanroy.springdata.jest.JestElasticsearchTemplateTests.java
@Test public void shouldReturnResultsWithScanAndScrollForGivenCriteriaQuery() { //given//from w w w .j av a2s.c o m List<IndexQuery> entities = createSampleEntitiesWithMessage("Test message", 30); // when elasticsearchTemplate.bulkIndex(entities); elasticsearchTemplate.refresh(SampleEntity.class); // then CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria()); criteriaQuery.addIndices(INDEX_NAME); criteriaQuery.addTypes(TYPE_NAME); criteriaQuery.setPageable(new PageRequest(0, 10)); String scrollId = elasticsearchTemplate.scan(criteriaQuery, 1000, false); List<SampleEntity> sampleEntities = new ArrayList<>(); boolean hasRecords = true; while (hasRecords) { Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 5000L, SampleEntity.class); if (page.hasContent()) { sampleEntities.addAll(page.getContent()); } else { hasRecords = false; } } elasticsearchTemplate.clearScroll(scrollId); assertThat(sampleEntities.size(), is(equalTo(30))); assertThat(sampleEntities, containsInAnyOrder( entities.stream().map(IndexQuery::getObject).map(Matchers::equalTo).collect(Collectors.toList()))); }