use of org.springframework.data.domain.PageRequest in project ocvn by devgateway.
the class MongoUtil method processRepositoryItemsPaginated.
public static <T, ID extends Serializable> void processRepositoryItemsPaginated(MongoRepository<T, ID> repository, Consumer<? super T> action, Consumer<String> logMessage) {
int pageNumber = 0;
AtomicInteger processedCount = new AtomicInteger(0);
Page<T> page;
do {
page = repository.findAll(new PageRequest(pageNumber++, BATCH_SIZE));
page.getContent().forEach(action);
processedCount.addAndGet(page.getNumberOfElements());
logMessage.accept("Processed " + processedCount.get() + " items");
} while (!page.isLast());
}
use of org.springframework.data.domain.PageRequest in project ocvn by devgateway.
the class OcdsController method ocdsReleases.
/**
* Returns a list of OCDS Releases, order by Id, using pagination
*
* @return the release data
*/
@ApiOperation(value = "Resturns all available releases, filtered by the given criteria.")
@RequestMapping(value = "/api/ocds/release/all", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
@JsonView(Views.Public.class)
public List<Release> ocdsReleases(@ModelAttribute @Valid final YearFilterPagingRequest releaseRequest) {
Pageable pageRequest = new PageRequest(releaseRequest.getPageNumber(), releaseRequest.getPageSize(), Direction.ASC, "id");
List<Release> find = mongoTemplate.find(query(getYearFilterCriteria(releaseRequest, "planning.bidPlanProjectDateApprove").andOperator(getDefaultFilterCriteria(releaseRequest))).with(pageRequest), Release.class);
return find;
}
use of org.springframework.data.domain.PageRequest in project ocvn by devgateway.
the class ExcelGenerator method getExcelDownload.
/**
* Method that returns a byte array with excel export.
*
* @param filter
* @return
* @throws IOException
*/
@Cacheable
public byte[] getExcelDownload(final YearFilterPagingRequest filter) throws IOException {
PageRequest pageRequest = new PageRequest(filter.getPageNumber(), filter.getPageSize(), Sort.Direction.ASC, "id");
List<Release> releases = mongoTemplate.find(query(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE)).with(pageRequest), Release.class);
ExcelFile releaseExcelFile = new ReleaseExportFile(releases);
Workbook workbook = releaseExcelFile.createWorkbook();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
workbook.write(baos);
byte[] bytes = baos.toByteArray();
return bytes;
}
Aggregations