Search in sources :

Example 91 with PageRequest

use of org.springframework.data.domain.PageRequest in project uplace.es by Uplace.

the class MarkerService method getAllMarkers.

@Transactional(readOnly = true)
public List<MarkerDTO> getAllMarkers() {
    List<Marker> markerList = propertyRepository.findAllMarkers();
    List<MarkerDTO> markerDTOS = markerList.parallelStream().map(markerToMarkerDTO).collect(Collectors.toList());
    // This can be made with JPA 1.7 findTop or inner join query
    Pageable limit = new PageRequest(0, 1);
    markerDTOS.parallelStream().forEach((markerDTO -> {
        List<Photo> photos = propertyRepository.findThumbnailByReference(markerDTO.getPropertyReference(), limit);
        if (!photos.isEmpty())
            markerDTO.setPhoto(photos.get(0));
    }));
    /*markerDTOList.parallelStream().forEach((markerDTO -> {
            if (markerDTO.getDate() != null) {
                LocalDate localDate =  markerDTO.getDate().toLocalDate();
                LocalDate today = LocalDate.now();
                Period period = Period.between(localDate, today);
                if (period.getMonths() >= 1) {
                    markerDTO.setNew(false);
                } else {
                    markerDTO.setNew(true);
                }
            } else {
                markerDTO.setNew(false);
            }
        }));
        List<MarkerDTO> result = markerDTOList.parallelStream()
            .filter(markerDTO -> Objects.nonNull(markerDTO.getLatitude()))
            .filter(markerDTO -> markerDTO.getLatitude() > 0)
            .filter(markerDTO -> Objects.nonNull(markerDTO.getLongitude()))
            .filter(markerDTO -> markerDTO.getLongitude() > 0)
            .collect(Collectors.toList());*/
    return markerDTOS;
}
Also used : Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Marker(com.arnaugarcia.uplace.domain.Marker) PageRequest(org.springframework.data.domain.PageRequest) PropertyRepository(com.arnaugarcia.uplace.repository.PropertyRepository) Collectors(java.util.stream.Collectors) Photo(com.arnaugarcia.uplace.domain.Photo) List(java.util.List) Service(org.springframework.stereotype.Service) Pageable(org.springframework.data.domain.Pageable) MarkerDTO(com.arnaugarcia.uplace.service.dto.MarkerDTO) Transactional(org.springframework.transaction.annotation.Transactional) TransformMarkerToMarkerDTO.markerToMarkerDTO(com.arnaugarcia.uplace.service.util.TransformMarkerToMarkerDTO.markerToMarkerDTO) PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) List(java.util.List) Marker(com.arnaugarcia.uplace.domain.Marker) MarkerDTO(com.arnaugarcia.uplace.service.dto.MarkerDTO) TransformMarkerToMarkerDTO.markerToMarkerDTO(com.arnaugarcia.uplace.service.util.TransformMarkerToMarkerDTO.markerToMarkerDTO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 92 with PageRequest

use of org.springframework.data.domain.PageRequest in project oc-explorer by devgateway.

the class SortableJpaRepositoryDataProvider method iterator.

/**
 * @see SortableDataProvider#iterator(long, long)
 */
@Override
public Iterator<? extends T> iterator(final long first, final long count) {
    int page = (int) ((double) first / WebConstants.PAGE_SIZE);
    Page<T> findAll = jpaRepository.findAll(filterState.getSpecification(), new PageRequest(page, WebConstants.PAGE_SIZE, translateSort()));
    return findAll.iterator();
}
Also used : PageRequest(org.springframework.data.domain.PageRequest)

Example 93 with PageRequest

use of org.springframework.data.domain.PageRequest in project oc-explorer by devgateway.

the class OcdsController method flaggedOcdsReleases.

/**
 * Returns a list of OCDS FlaggedReleases, order by Id, using pagination
 *
 * @return the release data
 */
@ApiOperation(value = "Resturns all available releases with flags, filtered by the given criteria.")
@RequestMapping(value = "/api/flaggedRelease/all", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
@JsonView(Views.Internal.class)
public List<FlaggedRelease> flaggedOcdsReleases(@ModelAttribute @Valid final YearFilterPagingRequest releaseRequest) {
    Pageable pageRequest = new PageRequest(releaseRequest.getPageNumber(), releaseRequest.getPageSize(), Direction.DESC, MongoConstants.FieldNames.FLAGS_TOTAL_FLAGGED);
    Query query = query(getYearDefaultFilterCriteria(releaseRequest, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).and(MongoConstants.FieldNames.FLAGS_TOTAL_FLAGGED).gt(0)).with(pageRequest);
    return mongoTemplate.find(query, FlaggedRelease.class);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Query(org.springframework.data.mongodb.core.query.Query) ApiOperation(io.swagger.annotations.ApiOperation) JsonView(com.fasterxml.jackson.annotation.JsonView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 94 with PageRequest

use of org.springframework.data.domain.PageRequest in project oc-explorer 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");
    Query query = query(getYearDefaultFilterCriteria(releaseRequest, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE)).with(pageRequest);
    return mongoTemplate.find(query, Release.class);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Query(org.springframework.data.mongodb.core.query.Query) ApiOperation(io.swagger.annotations.ApiOperation) JsonView(com.fasterxml.jackson.annotation.JsonView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 95 with PageRequest

use of org.springframework.data.domain.PageRequest in project oc-explorer 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)

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