use of org.openlmis.stockmanagement.web.Pagination 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());
}
Aggregations