Search in sources :

Example 51 with Pageable

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

the class UserServiceImpl method search.

@Override
public Page<UserDTO> search(String keyWord, List<Integer> jobTitles, List<Integer> skills, List<String> countries, String status, String role, String publishFlag, Integer page, Integer size) {
    Page<User> userPages = null;
    List<User> users = null;
    if (page == null)
        page = 0;
    if (size == null) {
        if (countries == null) {
            if (skills != null && jobTitles != null) {
                users = userDAO.findByKeywordAndJobAndSkill(keyWord, jobTitles, skills, status, role, publishFlag);
            } else if (skills != null) {
                users = userDAO.findByKeywordAndSkill(keyWord, skills, status, role, publishFlag);
            } else if (jobTitles != null) {
                users = userDAO.findByKeywordAndJob(keyWord, jobTitles, status, role, publishFlag);
            } else {
                users = userDAO.findByKeyword(keyWord, status, role, publishFlag);
            }
        } else {
            if (skills != null && jobTitles != null) {
                users = userDAO.findByKeywordAndJobAndSkillAndCountries(keyWord, jobTitles, skills, countries, status, role, publishFlag);
            } else if (skills != null) {
                users = userDAO.findByKeywordAndSkillAndCountries(keyWord, skills, countries, status, role, publishFlag);
            } else if (jobTitles != null) {
                users = userDAO.findByKeywordAndJobAndCountries(keyWord, jobTitles, countries, status, role, publishFlag);
            } else {
                users = userDAO.findByKeywordAndCountries(keyWord, countries, status, role, publishFlag);
            }
        }
        userPages = new PageImpl<User>(users);
    } else {
        Pageable pageable = new PageRequest(page, size);
        if (countries == null) {
            if (skills != null && jobTitles != null) {
                userPages = userDAO.findByKeywordAndJobAndSkill(keyWord, jobTitles, skills, status, role, publishFlag, pageable);
            } else if (skills != null) {
                userPages = userDAO.findByKeywordAndSkill(keyWord, skills, status, role, publishFlag, pageable);
            } else if (jobTitles != null) {
                userPages = userDAO.findByKeywordAndJob(keyWord, jobTitles, status, role, publishFlag, pageable);
            } else {
                userPages = userDAO.findByKeyword(keyWord, status, role, publishFlag, pageable);
            }
        } else {
            if (skills != null && jobTitles != null) {
                userPages = userDAO.findByKeywordAndJobAndSkillAndCountries(keyWord, jobTitles, skills, countries, status, role, publishFlag, pageable);
            } else if (skills != null) {
                userPages = userDAO.findByKeywordAndSkillAndCountries(keyWord, skills, countries, status, role, publishFlag, pageable);
            } else if (jobTitles != null) {
                userPages = userDAO.findByKeywordAndJobAndCountries(keyWord, jobTitles, countries, status, role, publishFlag, pageable);
            } else {
                userPages = userDAO.findByKeywordAndCountries(keyWord, countries, status, role, publishFlag, pageable);
            }
        }
    }
    Page<UserDTO> userDTOS = userPages.map(p -> userMapper.getUserDtoFromEntity(p));
    // mapUsersToUserDtos(users);
    return userDTOS;
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) User(org.c4sg.entity.User) Pageable(org.springframework.data.domain.Pageable) CreateUserDTO(org.c4sg.dto.CreateUserDTO) UserDTO(org.c4sg.dto.UserDTO)

Example 52 with Pageable

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

the class ProjectServiceImpl method search.

public Page<ProjectDTO> search(String keyWord, List<Integer> jobTitles, List<Integer> skills, String status, String remote, Integer page, Integer size) {
    Page<Project> projectPages = null;
    List<Project> projects = null;
    if (page == null) {
        page = 0;
    }
    if (size == null) {
        if (skills != null && jobTitles != null) {
            projects = projectDAO.findByKeywordAndJobAndSkill(keyWord, jobTitles, skills, status, remote);
        } else if (skills != null) {
            projects = projectDAO.findByKeywordAndSkill(keyWord, skills, status, remote);
        } else if (jobTitles != null) {
            projects = projectDAO.findByKeywordAndJob(keyWord, jobTitles, status, remote);
        } else {
            projects = projectDAO.findByKeyword(keyWord, status, remote);
        }
        projectPages = new PageImpl<Project>(projects);
    } else {
        Pageable pageable = new PageRequest(page, size);
        if (skills != null && jobTitles != null) {
            projectPages = projectDAO.findByKeywordAndJobAndSkill(keyWord, jobTitles, skills, status, remote, pageable);
        } else if (skills != null) {
            projectPages = projectDAO.findByKeywordAndSkill(keyWord, skills, status, remote, pageable);
        } else if (jobTitles != null) {
            projectPages = projectDAO.findByKeywordAndJob(keyWord, jobTitles, status, remote, pageable);
        } else {
            projectPages = projectDAO.findByKeyword(keyWord, status, remote, pageable);
        }
    }
    return projectPages.map(p -> projectMapper.getProjectDtoFromEntity(p));
}
Also used : UserProject(org.c4sg.entity.UserProject) Project(org.c4sg.entity.Project) PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable)

Example 53 with Pageable

use of org.springframework.data.domain.Pageable in project java-chassis by ServiceComb.

the class TestSchemeInterfaceJaxrs method testRestTransport.

public void testRestTransport() throws Exception {
    List<String> contents = new ArrayList<>();
    contents.add("hello");
    Sort sort = Sort.by(new String[0]);
    Pageable pageable = PageRequest.of(1, 10, sort);
    Page<String> pages = new PageImpl<>(contents, pageable, 1);
    Page<String> result = jaxrs.interfaceModel(pages);
    TestMgr.check("hello", result.stream().findFirst().get());
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) Pageable(org.springframework.data.domain.Pageable) ArrayList(java.util.ArrayList) Sort(org.springframework.data.domain.Sort)

Example 54 with Pageable

use of org.springframework.data.domain.Pageable in project java-chassis by ServiceComb.

the class TestPageResponseTypeProcessor method deserialize.

@Test
public void deserialize() throws IOException {
    Json.mapper().registerModule(new SpringDataModule());
    Sort sort = Sort.by(Direction.ASC, "name");
    Pageable pageable = PageRequest.of(1, 10, sort);
    Page<String> page = new PageImpl<>(Arrays.asList("c1", "c2"), pageable, 2);
    String json = Json.mapper().writeValueAsString(page);
    Assert.assertEquals("{\"content\":[\"c1\",\"c2\"],\"pageable\":{\"pageNumber\":1,\"pageSize\":10,\"sort\":{\"properties\":[\"name\"]},\"offset\":10,\"paged\":true,\"unpaged\":false},\"empty\":false,\"first\":false,\"last\":true,\"number\":1,\"numberOfElements\":2,\"size\":10,\"sort\":{\"properties\":[\"name\"]},\"totalElements\":12,\"totalPages\":2}", json);
    Page<?> page2 = Json.mapper().readValue(json, Page.class);
    Assert.assertEquals(json, Json.mapper().writeValueAsString(page2));
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) Test(org.junit.Test)

Example 55 with Pageable

use of org.springframework.data.domain.Pageable in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method findByAttribute.

/**
 * Find dto by idm attribute
 *
 * @param idmAttributeName
 * @param value
 * @param context
 * @return
 */
protected DTO findByAttribute(String idmAttributeName, String value, SynchronizationContext context) {
    CorrelationFilter filter = this.getEntityFilter(context);
    filter.setProperty(idmAttributeName);
    filter.setValue(value);
    @SuppressWarnings("unchecked") ReadWriteDtoService<DTO, BaseFilter> service = (ReadWriteDtoService<DTO, BaseFilter>) getService();
    List<DTO> entities = service.find((BaseFilter) filter, (Pageable) null).getContent();
    if (CollectionUtils.isEmpty(entities)) {
        return null;
    }
    if (entities.size() > 1) {
        throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_CORRELATION_TO_MANY_RESULTS, ImmutableMap.of("correlationAttribute", idmAttributeName, "value", value));
    }
    if (entities.size() == 1) {
        return entities.get(0);
    }
    return null;
}
Also used : Pageable(org.springframework.data.domain.Pageable) CorrelationFilter(eu.bcvsolutions.idm.core.api.dto.filter.CorrelationFilter) ReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) BaseFilter(eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter)

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