use of org.springframework.data.domain.Pageable in project openlmis-stockmanagement by OpenLMIS.
the class StockCardService method search.
/**
* Find stock card page by parameters. Allowed multiple id parameters.
*
* @param ids collection of ids for batch fetch
* @param pageable pagination and sorting parameters
* @return page of filtered stock cards.
*/
public Page<StockCardDto> search(@NotNull Collection<UUID> ids, Pageable pageable) {
OAuth2Authentication authentication = (OAuth2Authentication) SecurityContextHolder.getContext().getAuthentication();
Page<StockCard> page;
if (!authentication.isClientOnly()) {
UserDto user = authenticationHelper.getCurrentUser();
LOGGER.info("list of ids:" + ids);
PermissionStrings.Handler handler = permissionService.getPermissionStrings(user.getId());
Set<PermissionStringDto> permissionStrings = handler.get();
LOGGER.info("list of permission strings:" + permissionStrings);
Set<UUID> facilityIds = new HashSet<>();
Set<UUID> programIds = new HashSet<>();
permissionStrings.stream().filter(permissionString -> STOCK_CARDS_VIEW.equalsIgnoreCase(permissionString.getRightName())).forEach(permission -> {
facilityIds.add(permission.getFacilityId());
programIds.add(permission.getProgramId());
});
LOGGER.info("list of facility ids:" + facilityIds);
LOGGER.info("list of program ids:" + programIds);
if (isEmpty(ids)) {
page = cardRepository.findByFacilityIdInAndProgramIdIn(facilityIds, programIds, pageable);
} else {
page = cardRepository.findByFacilityIdInAndProgramIdInAndIdIn(facilityIds, programIds, ids, pageable);
}
} else {
if (isEmpty(ids)) {
page = cardRepository.findAll(pageable);
} else {
page = cardRepository.findByIdIn(ids, pageable);
}
}
return Pagination.getPage(createDtos(page.getContent()), pageable, page.getTotalElements());
}
use of org.springframework.data.domain.Pageable in project thingsboard by thingsboard.
the class JpaAuditLogDao method findAuditLogs.
private List<AuditLog> findAuditLogs(UUID tenantId, EntityId entityId, CustomerId customerId, UserId userId, TimePageLink pageLink) {
Specification<AuditLogEntity> timeSearchSpec = JpaAbstractSearchTimeDao.getTimeSearchPageSpec(pageLink, "id");
Specification<AuditLogEntity> fieldsSpec = getEntityFieldsSpec(tenantId, entityId, customerId, userId);
Sort.Direction sortDirection = pageLink.isAscOrder() ? Sort.Direction.ASC : Sort.Direction.DESC;
Pageable pageable = new PageRequest(0, pageLink.getLimit(), sortDirection, ID_PROPERTY);
return DaoUtil.convertDataList(auditLogRepository.findAll(where(timeSearchSpec).and(fieldsSpec), pageable).getContent());
}
use of org.springframework.data.domain.Pageable in project spring-data-commons by spring-projects.
the class PageableHandlerMethodArgumentResolver method resolveArgument.
/*
* (non-Javadoc)
* @see org.springframework.web.method.support.HandlerMethodArgumentResolver#resolveArgument(org.springframework.core.MethodParameter, org.springframework.web.method.support.ModelAndViewContainer, org.springframework.web.context.request.NativeWebRequest, org.springframework.web.bind.support.WebDataBinderFactory)
*/
@Override
public Pageable resolveArgument(MethodParameter methodParameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) {
assertPageableUniqueness(methodParameter);
Optional<Pageable> defaultOrFallback = getDefaultFromAnnotationOrFallback(methodParameter).toOptional();
String pageString = webRequest.getParameter(getParameterNameToUse(pageParameterName, methodParameter));
String pageSizeString = webRequest.getParameter(getParameterNameToUse(sizeParameterName, methodParameter));
Optional<Integer> page = parseAndApplyBoundaries(pageString, Integer.MAX_VALUE, true);
Optional<Integer> pageSize = parseAndApplyBoundaries(pageSizeString, maxPageSize, false);
if (!(page.isPresent() && pageSize.isPresent()) && !defaultOrFallback.isPresent()) {
return Pageable.unpaged();
}
int p = page.orElseGet(() -> defaultOrFallback.map(Pageable::getPageNumber).orElseThrow(IllegalStateException::new));
int ps = pageSize.orElseGet(() -> defaultOrFallback.map(Pageable::getPageSize).orElseThrow(IllegalStateException::new));
// Limit lower bound
ps = ps < 1 ? defaultOrFallback.map(Pageable::getPageSize).orElseThrow(IllegalStateException::new) : ps;
// Limit upper bound
ps = ps > maxPageSize ? maxPageSize : ps;
Sort sort = sortResolver.resolveArgument(methodParameter, mavContainer, webRequest, binderFactory);
return PageRequest.of(p, ps, sort.isSorted() ? sort : defaultOrFallback.map(Pageable::getSort).orElseGet(Sort::unsorted));
}
use of org.springframework.data.domain.Pageable in project spring-data-commons by spring-projects.
the class PagedResourcesAssemblerArgumentResolver method findMatchingPageableParameter.
/**
* Returns finds the {@link MethodParameter} for a {@link Pageable} instance matching the given
* {@link MethodParameter} requesting a {@link PagedResourcesAssembler}.
*
* @param parameter must not be {@literal null}.
* @return
*/
@Nullable
private static MethodParameter findMatchingPageableParameter(MethodParameter parameter) {
MethodParameters parameters = new MethodParameters(parameter.getMethod());
List<MethodParameter> pageableParameters = parameters.getParametersOfType(Pageable.class);
Qualifier assemblerQualifier = parameter.getParameterAnnotation(Qualifier.class);
if (pageableParameters.isEmpty()) {
return null;
}
if (pageableParameters.size() == 1) {
MethodParameter pageableParameter = pageableParameters.get(0);
MethodParameter matchingParameter = returnIfQualifiersMatch(pageableParameter, assemblerQualifier);
if (matchingParameter == null) {
LOGGER.info(SUPERFLOUS_QUALIFIER, PagedResourcesAssembler.class.getSimpleName(), Pageable.class.getName());
}
return pageableParameter;
}
if (assemblerQualifier == null) {
throw new IllegalStateException(PARAMETER_AMBIGUITY);
}
for (MethodParameter pageableParameter : pageableParameters) {
MethodParameter matchingParameter = returnIfQualifiersMatch(pageableParameter, assemblerQualifier);
if (matchingParameter != null) {
return matchingParameter;
}
}
throw new IllegalStateException(PARAMETER_AMBIGUITY);
}
use of org.springframework.data.domain.Pageable in project spring-data-commons by spring-projects.
the class RepositoryFactorySupportUnitTests method createsRepositoryInstanceWithCustomIntermediateRepository.
@Test
public void createsRepositoryInstanceWithCustomIntermediateRepository() {
CustomRepository repository = factory.getRepository(CustomRepository.class);
Pageable pageable = PageRequest.of(0, 10);
when(backingRepo.findAll(pageable)).thenReturn(new PageImpl<>(Collections.emptyList()));
repository.findAll(pageable);
verify(backingRepo, times(1)).findAll(pageable);
}
Aggregations