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;
}
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));
}
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());
}
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));
}
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;
}
Aggregations