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;
}
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();
}
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);
}
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);
}
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());
}
Aggregations