Search in sources :

Example 61 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 62 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 63 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)

Example 64 with PageRequest

use of org.springframework.data.domain.PageRequest in project ignite by apache.

the class IgniteSpringDataQueriesSelfTest method testQueryFields.

/**
 */
public void testQueryFields() {
    List<String> persons = repo.selectField("^[a-z]+$", new PageRequest(1, 7, Sort.Direction.DESC, "secondName"));
    assertEquals(7, persons.size());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest)

Example 65 with PageRequest

use of org.springframework.data.domain.PageRequest in project ignite by apache.

the class IgniteSpringDataQueriesSelfTest method testSliceOfCacheEntries.

/**
 */
public void testSliceOfCacheEntries() {
    Slice<Cache.Entry<Integer, Person>> slice = repo2.findBySecondNameIsNot("lastName18", new PageRequest(3, 4));
    assertEquals(4, slice.getSize());
    for (Cache.Entry<Integer, Person> entry : slice) assertFalse("lastName18".equals(entry.getValue().getSecondName()));
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Person(org.apache.ignite.springdata.misc.Person) Cache(javax.cache.Cache)

Aggregations

PageRequest (org.springframework.data.domain.PageRequest)106 Sort (org.springframework.data.domain.Sort)29 Pageable (org.springframework.data.domain.Pageable)25 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)14 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)9 Transactional (org.springframework.transaction.annotation.Transactional)9 UUID (java.util.UUID)8 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)7 ApiOperation (io.swagger.annotations.ApiOperation)7 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)6 IdmTreeNode (eu.bcvsolutions.idm.core.model.entity.IdmTreeNode)6 List (java.util.List)6 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)5 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)5 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)5 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)5 PageImpl (org.springframework.data.domain.PageImpl)5