Search in sources :

Example 26 with PageRequest

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());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 27 with PageRequest

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;
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Release(org.devgateway.ocds.persistence.mongo.Release) ApiOperation(io.swagger.annotations.ApiOperation) JsonView(com.fasterxml.jackson.annotation.JsonView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 28 with PageRequest

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;
}
Also used : ReleaseExportFile(org.devgateway.ocds.persistence.mongo.excel.ReleaseExportFile) PageRequest(org.springframework.data.domain.PageRequest) ExcelFile(org.devgateway.ocds.persistence.mongo.excel.ExcelFile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Release(org.devgateway.ocds.persistence.mongo.Release) Workbook(org.apache.poi.ss.usermodel.Workbook) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

PageRequest (org.springframework.data.domain.PageRequest)28 Pageable (org.springframework.data.domain.Pageable)7 Sort (org.springframework.data.domain.Sort)7 Test (org.junit.Test)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Person (org.apache.ignite.springdata.misc.Person)3 List (java.util.List)2 Cache (javax.cache.Cache)2 Release (org.devgateway.ocds.persistence.mongo.Release)2 Query (org.springframework.data.mongodb.core.query.Query)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Book (org.springside.examples.bootapi.domain.Book)2 City (sample.data.jpa.domain.City)2 City (sample.data.rest.domain.City)2 JsonView (com.fasterxml.jackson.annotation.JsonView)1 UserEntity (com.myspringboot.entity.UserEntity)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 HashSet (java.util.HashSet)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1