Search in sources :

Example 41 with Pageable

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

the class PageableHandlerMethodArgumentResolverUnitTests method returnsCorrectPageSizeForOneIndexParameters.

// DATACMNS-761
@Test
public void returnsCorrectPageSizeForOneIndexParameters() {
    PageableHandlerMethodArgumentResolver resolver = getResolver();
    resolver.setOneIndexedParameters(true);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("size", "10");
    Pageable result = resolver.resolveArgument(supportedMethodParameter, null, new ServletWebRequest(request), null);
    assertThat(result.getPageSize()).isEqualTo(10);
}
Also used : Pageable(org.springframework.data.domain.Pageable) PageableHandlerMethodArgumentResolver(org.springframework.data.web.PageableHandlerMethodArgumentResolver) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) Test(org.junit.Test)

Example 42 with Pageable

use of org.springframework.data.domain.Pageable in project goci by EBISPOT.

the class SolrIndexer method mapAllTraits.

private int mapAllTraits(ExecutorService taskExecutor, Collection<String> pubmedIds) throws InterruptedException {
    // Sort sort = new Sort(new Sort.Order("trait"));
    if (runTraits) {
        Pageable pager = new PageRequest(0, pageSize);
        if (!pubmedIds.isEmpty()) {
            int totalElements = 0;
            for (String pmid : pubmedIds) {
                Page<DiseaseTrait> diseaseTraitPage = diseaseTraitRepository.findByStudiesPublicationIdPubmedId(pmid, pager);
                CountDownLatch latch = new CountDownLatch(diseaseTraitPage.getTotalPages());
                taskExecutor.execute(new TraitThread(diseaseTraitPage.getContent(), latch, pager.getPageNumber()));
                if (sysOutLogging) {
                    System.out.println("mapping " + diseaseTraitPage.getTotalPages() + " disease trait pages");
                }
                while (diseaseTraitPage.hasNext()) {
                    if (maxPages != -1 && diseaseTraitPage.getNumber() >= maxPages - 1) {
                        break;
                    }
                    pager = pager.next();
                    diseaseTraitPage = diseaseTraitRepository.findByStudiesPublicationIdPubmedId(pmid, pager);
                    taskExecutor.execute(new TraitThread(diseaseTraitPage.getContent(), latch, pager.getPageNumber()));
                }
                totalElements += diseaseTraitPage.getTotalElements();
                latch.await();
            }
            return totalElements;
        } else {
            Page<DiseaseTrait> diseaseTraitPage = diseaseTraitRepository.findAll(pager);
            CountDownLatch latch = new CountDownLatch(diseaseTraitPage.getTotalPages());
            taskExecutor.execute(new TraitThread(diseaseTraitPage.getContent(), latch, pager.getPageNumber()));
            if (sysOutLogging) {
                System.out.println("mapping " + diseaseTraitPage.getTotalPages() + " disease trait pages");
            }
            while (diseaseTraitPage.hasNext()) {
                if (maxPages != -1 && diseaseTraitPage.getNumber() >= maxPages - 1) {
                    break;
                }
                pager = pager.next();
                diseaseTraitPage = diseaseTraitRepository.findAll(pager);
                taskExecutor.execute(new TraitThread(diseaseTraitPage.getContent(), latch, pager.getPageNumber()));
            }
            latch.await();
            return (int) diseaseTraitPage.getTotalElements();
        }
    } else {
        return 0;
    }
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait)

Example 43 with Pageable

use of org.springframework.data.domain.Pageable in project goci by EBISPOT.

the class SolrIndexer method mapStudies.

/**
 * If no publication ids are provided all studies will be mapped
 * @param pubmedIds
 * @return
 */
Integer mapStudies(Collection<String> pubmedIds) {
    if (runStudies) {
        Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "publicationId.publicationDate"));
        Pageable pager = new PageRequest(0, pageSize);
        Page<Study> studyPage = null;
        int totalElements = 0;
        if (!pubmedIds.isEmpty()) {
            for (String pmid : pubmedIds) {
                studyPage = studyService.findPublishedStudiesByPublicationId(pmid, pager);
                totalElements += _mapPagedStudies(pmid, studyPage, pager);
            }
        } else {
            studyPage = studyService.findPublishedStudies(pager);
            totalElements = _mapPagedStudies(null, studyPage, pager);
        }
        return totalElements;
    } else {
        return 0;
    }
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort)

Example 44 with Pageable

use of org.springframework.data.domain.Pageable in project goci by EBISPOT.

the class SolrIndexer method mapAllAssociations.

@Transactional
private int mapAllAssociations(ExecutorService taskExecutor, Collection<String> pubmedIds) throws InterruptedException {
    // Sort sort = new Sort(new Sort.Order("id"));
    if (runAssociations) {
        Pageable pager = new PageRequest(0, pageSize);
        if (!pubmedIds.isEmpty()) {
            int totalElements = 0;
            for (String pmid : pubmedIds) {
                Page<Association> associationPage = associationService.findPublishedAssociationsPublicationId(pmid, pager);
                CountDownLatch latch = new CountDownLatch(associationPage.getTotalPages());
                taskExecutor.execute(new AssociationThread(associationPage.getContent(), latch, pager.getPageNumber()));
                if (sysOutLogging) {
                    System.out.println("mapping " + associationPage.getTotalPages() + " association pages");
                }
                while (associationPage.hasNext()) {
                    if (maxPages != -1 && associationPage.getNumber() >= maxPages - 1) {
                        break;
                    }
                    pager = pager.next();
                    associationPage = associationService.findPublishedAssociationsPublicationId(pmid, pager);
                    taskExecutor.execute(new AssociationThread(associationPage.getContent(), latch, pager.getPageNumber()));
                }
                latch.await();
                totalElements += associationPage.getTotalElements();
            }
            return totalElements;
        } else {
            Page<Association> associationPage = associationService.findPublishedAssociations(pager);
            CountDownLatch latch = new CountDownLatch(associationPage.getTotalPages());
            taskExecutor.execute(new AssociationThread(associationPage.getContent(), latch, pager.getPageNumber()));
            if (sysOutLogging) {
                System.out.println("mapping " + associationPage.getTotalPages() + " association pages");
            }
            while (associationPage.hasNext()) {
                if (maxPages != -1 && associationPage.getNumber() >= maxPages - 1) {
                    break;
                }
                pager = pager.next();
                associationPage = associationService.findPublishedAssociations(pager);
                taskExecutor.execute(new AssociationThread(associationPage.getContent(), latch, pager.getPageNumber()));
            }
            latch.await();
            return (int) associationPage.getTotalElements();
        }
    } else {
        return 0;
    }
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Association(uk.ac.ebi.spot.goci.model.Association) Transactional(javax.transaction.Transactional)

Example 45 with Pageable

use of org.springframework.data.domain.Pageable in project goci by EBISPOT.

the class SolrIndexer method mapAssociations.

Integer mapAssociations(Collection<String> pubmedIds) {
    if (runAssociations) {
        Sort sort = new Sort(new Sort.Order("id"));
        Pageable pager = new PageRequest(0, pageSize);
        Page<Association> associationPage = null;
        int totalElements = 0;
        if (!pubmedIds.isEmpty()) {
            for (String pmid : pubmedIds) {
                associationPage = associationService.findPublishedAssociationsPublicationId(pmid, pager);
                totalElements += _mapPagedAssociations(pmid, associationPage, pager);
            }
        } else {
            associationPage = associationService.findPublishedAssociations(pager);
            totalElements = _mapPagedAssociations(null, associationPage, pager);
        }
        return totalElements;
    } else {
        return 0;
    }
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Association(uk.ac.ebi.spot.goci.model.Association) Sort(org.springframework.data.domain.Sort)

Aggregations

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