Search in sources :

Example 71 with Pageable

use of org.springframework.data.domain.Pageable in project spring-data-mongodb by spring-projects.

the class AbstractMongoQueryUnitTests method slicedExecutionShouldRetainSort.

// DATAMONGO-1057
@Test
void slicedExecutionShouldRetainSort() {
    MongoQueryFake query = createQueryForMethod("findByLastname", String.class, Pageable.class);
    Pageable page1 = PageRequest.of(0, 10, Sort.Direction.DESC, "bar");
    Pageable page2 = page1.next();
    query.execute(new Object[] { "fake", page1 });
    query.execute(new Object[] { "fake", page2 });
    ArgumentCaptor<Query> captor = ArgumentCaptor.forClass(Query.class);
    verify(executableFind, times(2)).as(Person.class);
    verify(withQueryMock, times(2)).matching(captor.capture());
    Document expectedSortObject = new Document().append("bar", -1);
    assertThat(captor.getAllValues().get(0).getSortObject()).isEqualTo(expectedSortObject);
    assertThat(captor.getAllValues().get(1).getSortObject()).isEqualTo(expectedSortObject);
}
Also used : Pageable(org.springframework.data.domain.Pageable) BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) FindWithQuery(org.springframework.data.mongodb.core.ExecutableFindOperation.FindWithQuery) UpdateWithQuery(org.springframework.data.mongodb.core.ExecutableUpdateOperation.UpdateWithQuery) Query(org.springframework.data.mongodb.core.query.Query) Document(org.bson.Document) Test(org.junit.jupiter.api.Test)

Example 72 with Pageable

use of org.springframework.data.domain.Pageable in project oc-explorer by devgateway.

the class OcdsController method ocdsReleasesCount.

/**
 * Returns a list of OCDS Releases, order by Id, using pagination
 *
 * @return the release data
 */
@ApiOperation(value = "Counts releases, filter by given criteria")
@RequestMapping(value = "/api/ocds/release/count", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
@JsonView(Views.Public.class)
@Cacheable
public Long ocdsReleasesCount(@ModelAttribute @Valid final YearFilterPagingRequest releaseRequest) {
    Pageable pageRequest = new PageRequest(releaseRequest.getPageNumber(), releaseRequest.getPageSize(), Direction.ASC, "id");
    Query query = query(getYearDefaultFilterCriteria(releaseRequest, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE)).with(pageRequest);
    return mongoTemplate.count(query, Release.class);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Query(org.springframework.data.mongodb.core.query.Query) Cacheable(org.springframework.cache.annotation.Cacheable) ApiOperation(io.swagger.annotations.ApiOperation) JsonView(com.fasterxml.jackson.annotation.JsonView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 73 with Pageable

use of org.springframework.data.domain.Pageable in project summer by foxsugar.

the class GameUserService method getRebateDetails1.

public int getRebateDetails1(KafkaMsgKey msgKey, long userId, String date, int index) {
    // sendMsg(msgKey, new ResponseVo("userService", "getRebateDetails", rebateDetailService.rebateDetailDao.findAllByAgentId(userId)));
    // LocalDate localDate = LocalDate.now();
    // String date = localDate.minusDays(7).toString();
    String d1 = date + " 00:00:00";
    String d2 = date + " 23:59:59";
    Date date1 = DateUtil.convert2DateTime(d1);
    Date date2 = DateUtil.convert2DateTime(d2);
    // 创建时间降序排序
    Sort sort = new Sort(Sort.Direction.DESC, "date");
    Pageable pageable = new PageRequest(index, 30, sort);
    sendMsg(msgKey, new ResponseVo("userService", "getRebateDetails1", rebateDetailService.rebateDetailDao.findAllByAgentIdAndDateAfterAndDateBefore(userId, date1, date2, pageable)));
    return 0;
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) LocalDate(java.time.LocalDate) ResponseVo(com.code.server.constant.response.ResponseVo)

Example 74 with Pageable

use of org.springframework.data.domain.Pageable in project Saturn by vipshop.

the class JobOverviewController method getJobOverviewByStatusAndPage.

private JobOverviewVo getJobOverviewByStatusAndPage(String namespace, JobStatus jobStatus, Map<String, Object> condition, int page, int size) throws SaturnJobConsoleException {
    JobOverviewVo jobOverviewVo = new JobOverviewVo();
    try {
        preHandleStatusAndCondition(condition, jobStatus);
        List<JobConfig4DB> unSystemJobs = jobService.getUnSystemJobsWithCondition(namespace, condition, page, size);
        if (unSystemJobs == null || unSystemJobs.isEmpty()) {
            jobOverviewVo.setJobs(Lists.<JobOverviewJobVo>newArrayList());
            jobOverviewVo.setTotalNumber(0);
            return jobOverviewVo;
        }
        Pageable pageable = PageableUtil.generatePageble(page, size);
        // 当 jobStatus 为null时,底层取数据已经做了分页,此处无需再次分页
        List<JobConfig4DB> targetJobs = jobStatus == null ? unSystemJobs : getJobSubListByPage(unSystemJobs, pageable);
        List<JobOverviewJobVo> jobOverviewList = updateJobOverviewDetail(namespace, targetJobs, jobStatus);
        jobOverviewVo.setJobs(jobOverviewList);
        jobOverviewVo.setTotalNumber(jobService.countUnSystemJobsWithCondition(namespace, condition));
    } catch (SaturnJobConsoleException e) {
        throw e;
    } catch (Exception e) {
        throw new SaturnJobConsoleException(e);
    }
    return jobOverviewVo;
}
Also used : Pageable(org.springframework.data.domain.Pageable) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 75 with Pageable

use of org.springframework.data.domain.Pageable in project kylo by Teradata.

the class OpsManagerFeedRepositoryTest method findAll_TwoPages.

@WithMockJaasUser(username = "dladmin", password = "secret", authorities = { "admin", "user" })
@Test
public void findAll_TwoPages() throws Exception {
    JpaOpsManagerFeed feed1 = new JpaOpsManagerFeed(OpsManagerFeedId.create(), "feed1-name");
    repo.save(feed1);
    BaseFeed.FeedId feed1Id = new BaseFeed.FeedId(feed1.getId().getUuid());
    JpaFeedOpsAclEntry acl1 = new JpaFeedOpsAclEntry(feed1Id, "admin", JpaFeedOpsAclEntry.PrincipalType.GROUP);
    aclRepo.save(acl1);
    JpaOpsManagerFeed feed2 = new JpaOpsManagerFeed(OpsManagerFeedId.create(), "feed2-name");
    repo.save(feed2);
    BaseFeed.FeedId feed2Id = new BaseFeed.FeedId(feed2.getId().getUuid());
    JpaFeedOpsAclEntry acl2 = new JpaFeedOpsAclEntry(feed2Id, "user", JpaFeedOpsAclEntry.PrincipalType.GROUP);
    aclRepo.save(acl2);
    JpaOpsManagerFeed feed3 = new JpaOpsManagerFeed(OpsManagerFeedId.create(), "feed3-name");
    repo.save(feed3);
    BaseFeed.FeedId feed3Id = new BaseFeed.FeedId(feed3.getId().getUuid());
    JpaFeedOpsAclEntry acl3 = new JpaFeedOpsAclEntry(feed3Id, "NON_MATCHING", JpaFeedOpsAclEntry.PrincipalType.GROUP);
    aclRepo.save(acl3);
    JpaOpsManagerFeed feed4 = new JpaOpsManagerFeed(OpsManagerFeedId.create(), "feed4-name");
    repo.save(feed4);
    BaseFeed.FeedId feed4Id = new BaseFeed.FeedId(feed4.getId().getUuid());
    JpaFeedOpsAclEntry acl4 = new JpaFeedOpsAclEntry(feed4Id, "user", JpaFeedOpsAclEntry.PrincipalType.GROUP);
    aclRepo.save(acl4);
    JpaOpsManagerFeed feed5 = new JpaOpsManagerFeed(OpsManagerFeedId.create(), "feed5-name");
    repo.save(feed5);
    BaseFeed.FeedId feed5Id = new BaseFeed.FeedId(feed5.getId().getUuid());
    JpaFeedOpsAclEntry acl5 = new JpaFeedOpsAclEntry(feed5Id, "NON_MATCHING", JpaFeedOpsAclEntry.PrincipalType.GROUP);
    aclRepo.save(acl5);
    JpaOpsManagerFeed feed6 = new JpaOpsManagerFeed(OpsManagerFeedId.create(), "feed6-name");
    repo.save(feed6);
    BaseFeed.FeedId feed6Id = new BaseFeed.FeedId(feed6.getId().getUuid());
    JpaFeedOpsAclEntry acl6 = new JpaFeedOpsAclEntry(feed6Id, "user", JpaFeedOpsAclEntry.PrincipalType.GROUP);
    aclRepo.save(acl6);
    Pageable page1Request = new PageRequest(0, 2);
    Page<JpaOpsManagerFeed> page1 = repo.findAll(page1Request);
    Assert.assertEquals(0, page1.getNumber());
    Assert.assertEquals(2, page1.getNumberOfElements());
    Assert.assertEquals(2, page1.getTotalPages());
    Assert.assertEquals(4, page1.getTotalElements());
    Pageable page2Request = new PageRequest(1, 2);
    Page<JpaOpsManagerFeed> page2 = repo.findAll(page2Request);
    Assert.assertEquals(1, page2.getNumber());
    Assert.assertEquals(2, page2.getNumberOfElements());
    Assert.assertEquals(2, page2.getTotalPages());
    Assert.assertEquals(4, page2.getTotalElements());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) BaseFeed(com.thinkbiganalytics.metadata.core.feed.BaseFeed) JpaFeedOpsAclEntry(com.thinkbiganalytics.metadata.jpa.feed.security.JpaFeedOpsAclEntry) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockJaasUser(com.thinkbiganalytics.test.security.WithMockJaasUser)

Aggregations

Pageable (org.springframework.data.domain.Pageable)172 PageRequest (org.springframework.data.domain.PageRequest)91 Sort (org.springframework.data.domain.Sort)79 Test (org.junit.Test)39 PageImpl (org.springframework.data.domain.PageImpl)24 Collectors (java.util.stream.Collectors)17 Page (org.springframework.data.domain.Page)16 ArrayList (java.util.ArrayList)14 Autowired (org.springframework.beans.factory.annotation.Autowired)14 GetMapping (org.springframework.web.bind.annotation.GetMapping)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 List (java.util.List)11 UUID (java.util.UUID)10 ApiOperation (io.swagger.annotations.ApiOperation)9 Calendar (java.util.Calendar)9 Test (org.junit.jupiter.api.Test)9 java.util (java.util)8 Lists (com.google.common.collect.Lists)7 Map (java.util.Map)6 Transactional (org.springframework.transaction.annotation.Transactional)6