Search in sources :

Example 46 with Pageable

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

the class AssociationControllerTest method viewStudySnps.

@Test
public void viewStudySnps() throws Exception {
    SnpAssociationTableView snpAssociationTableView = new SnpAssociationTableView();
    LastViewedAssociation lastViewedAssociation = new LastViewedAssociation();
    Pageable pagination = new PageRequest(0, 100);
    List<Association> list = new ArrayList<Association>();
    list.add(ASSOCIATION);
    Page<Association> returnPage = new PageImpl<Association>(list, pagination, list.size());
    when(associationRepository.findByStudyId(STUDY.getId(), pagination)).thenReturn(returnPage);
    when(snpAssociationTableViewService.createSnpAssociationTableView(ASSOCIATION)).thenReturn(snpAssociationTableView);
    when(associationOperationsService.getLastViewedAssociation(Matchers.anyLong())).thenReturn(lastViewedAssociation);
    when(studyRepository.findOne(Matchers.anyLong())).thenReturn(STUDY);
    mockMvc.perform(get("/studies/1234/associations").accept(MediaType.TEXT_HTML_VALUE)).andExpect(status().isOk()).andExpect(model().attribute("snpAssociationTableViews", hasSize(1))).andExpect(model().attribute("snpAssociationTableViews", instanceOf(Collection.class))).andExpect(model().attribute("lastViewedAssociation", instanceOf(LastViewedAssociation.class))).andExpect(model().attribute("totalAssociations", 1L)).andExpect(model().attributeExists("study")).andExpect(view().name("study_association"));
    verify(associationRepository, times(1)).findByStudyId(STUDY.getId(), pagination);
    verify(snpAssociationTableViewService, times(1)).createSnpAssociationTableView(ASSOCIATION);
    verify(associationOperationsService, times(1)).getLastViewedAssociation(Matchers.anyLong());
    verify(studyRepository, times(1)).findOne(Matchers.anyLong());
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) LastViewedAssociation(uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation) PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) LastViewedAssociation(uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation) Association(uk.ac.ebi.spot.goci.model.Association) ArrayList(java.util.ArrayList) SnpAssociationTableView(uk.ac.ebi.spot.goci.curation.model.SnpAssociationTableView) Test(org.junit.Test)

Example 47 with Pageable

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

the class VetController method findPaginated.

private Page<Vet> findPaginated(int page) {
    int pageSize = 5;
    Pageable pageable = PageRequest.of(page - 1, pageSize);
    return vets.findAll(pageable);
}
Also used : Pageable(org.springframework.data.domain.Pageable)

Example 48 with Pageable

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

the class OwnerController method findPaginatedForOwnersLastName.

private Page<Owner> findPaginatedForOwnersLastName(int page, String lastname) {
    int pageSize = 5;
    Pageable pageable = PageRequest.of(page - 1, pageSize);
    return owners.findByLastName(lastname, pageable);
}
Also used : Pageable(org.springframework.data.domain.Pageable)

Example 49 with Pageable

use of org.springframework.data.domain.Pageable in project fastjson by alibaba.

the class Issue2752 method test_for_issue.

public void test_for_issue() {
    Pageable pageRequest = new PageRequest(0, 10, new Sort(new Sort.Order("id, desc")));
    SerializeConfig config = new SerializeConfig();
    config.register(new MyModule());
    String result = JSON.toJSONString(pageRequest, config);
    assertTrue(result.indexOf("\"property\":\"id, desc\"") != -1);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig) Sort(org.springframework.data.domain.Sort)

Example 50 with Pageable

use of org.springframework.data.domain.Pageable in project c4sg-services by Code4SocialGood.

the class OrganizationServiceImpl method findByCriteria.

public Page<OrganizationDTO> findByCriteria(String keyWord, List<String> countries, Boolean open, String status, List<String> categories, Integer page, Integer size) {
    Page<Organization> organizationPages;
    List<Organization> organizations = null;
    if (page == null)
        page = 0;
    if (size == null) {
        if (countries == null || countries.isEmpty()) {
            if (open == null) {
                if (categories != null) {
                    organizations = organizationDAO.findByCriteria(keyWord, open, status, categories);
                } else {
                    organizations = organizationDAO.findByCriteriaNoCategoriesFilter(keyWord, open, status);
                }
            } else {
                if (categories == null) {
                    organizations = organizationDAO.findByCriteriaAndOpenNoCategoriesFilter(keyWord, open, status);
                } else {
                    organizations = organizationDAO.findByCriteriaAndOpen(keyWord, open, status, categories);
                }
            }
        } else {
            if (open == null) {
                if (categories != null) {
                    organizations = organizationDAO.findByCriteriaAndCountries(keyWord, countries, open, status, categories);
                }
            } else {
                organizations = organizationDAO.findByCriteriaAndCountriesAndOpen(keyWord, countries, open, status, categories);
            }
        }
        organizationPages = new PageImpl<>(organizations);
        return organizationPages.map(o -> organizationMapper.getOrganizationDtoFromEntity(o));
    }
    Pageable pageable = new PageRequest(page, size);
    if (countries == null || countries.isEmpty()) {
        if (open == null) {
            if (categories == null) {
                organizationPages = organizationDAO.findByCriteriaNoCategoriesFilter(keyWord, open, status, pageable);
            } else {
                organizationPages = organizationDAO.findByCriteria(keyWord, open, status, categories, pageable);
            }
        } else {
            if (categories == null) {
                organizationPages = organizationDAO.findByCriteriaAndOpenNoCategoriesFilter(keyWord, open, status, pageable);
            } else {
                organizationPages = organizationDAO.findByCriteriaAndOpen(keyWord, open, status, categories, pageable);
            }
        }
    } else if (open == null) {
        organizationPages = organizationDAO.findByCriteriaAndCountries(keyWord, countries, open, status, categories, pageable);
    } else {
        organizationPages = organizationDAO.findByCriteriaAndCountriesAndOpen(keyWord, countries, open, status, categories, pageable);
    }
    return organizationPages.map(o -> organizationMapper.getOrganizationDtoFromEntity(o));
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Organization(org.c4sg.entity.Organization) UserOrganization(org.c4sg.entity.UserOrganization) Pageable(org.springframework.data.domain.Pageable)

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