Search in sources :

Example 1 with MarkerDTO

use of com.arnaugarcia.uplace.service.dto.MarkerDTO 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)

Aggregations

Marker (com.arnaugarcia.uplace.domain.Marker)1 Photo (com.arnaugarcia.uplace.domain.Photo)1 PropertyRepository (com.arnaugarcia.uplace.repository.PropertyRepository)1 MarkerDTO (com.arnaugarcia.uplace.service.dto.MarkerDTO)1 TransformMarkerToMarkerDTO.markerToMarkerDTO (com.arnaugarcia.uplace.service.util.TransformMarkerToMarkerDTO.markerToMarkerDTO)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 PageRequest (org.springframework.data.domain.PageRequest)1 Pageable (org.springframework.data.domain.Pageable)1 Service (org.springframework.stereotype.Service)1 Transactional (org.springframework.transaction.annotation.Transactional)1