Search in sources :

Example 1 with Sort

use of org.springframework.data.domain.Sort in project goci by EBISPOT.

the class StudyController method findSort.

// Find correct sorting type and direction
private Sort findSort(String sortType) {
    // Default sort by date
    Sort sort = sortByPublicationDateDesc();
    Map<String, Sort> sortTypeMap = new HashMap<>();
    sortTypeMap.put("authorsortasc", sortByAuthorAsc());
    sortTypeMap.put("authorsortdesc", sortByAuthorDesc());
    sortTypeMap.put("titlesortasc", sortByTitleAsc());
    sortTypeMap.put("titlesortdesc", sortByTitleDesc());
    sortTypeMap.put("publicationdatesortasc", sortByPublicationDateAsc());
    sortTypeMap.put("publicationdatesortdesc", sortByPublicationDateDesc());
    sortTypeMap.put("pubmedsortasc", sortByPubmedIdAsc());
    sortTypeMap.put("pubmedsortdesc", sortByPubmedIdDesc());
    sortTypeMap.put("publicationsortasc", sortByPublicationAsc());
    sortTypeMap.put("publicationsortdesc", sortByPublicationDesc());
    sortTypeMap.put("efotraitsortasc", sortByEfoTraitAsc());
    sortTypeMap.put("efotraitsortdesc", sortByEfoTraitDesc());
    sortTypeMap.put("diseasetraitsortasc", sortByDiseaseTraitAsc());
    sortTypeMap.put("diseasetraitsortdesc", sortByDiseaseTraitDesc());
    sortTypeMap.put("curatorsortasc", sortByCuratorAsc());
    sortTypeMap.put("curatorsortdesc", sortByCuratorDesc());
    sortTypeMap.put("curationstatussortasc", sortByCurationStatusAsc());
    sortTypeMap.put("curationstatussortdesc", sortByCurationStatusDesc());
    if (sortType != null && !sortType.isEmpty()) {
        sort = sortTypeMap.get(sortType);
    }
    return sort;
}
Also used : HashMap(java.util.HashMap) Sort(org.springframework.data.domain.Sort)

Example 2 with Sort

use of org.springframework.data.domain.Sort in project goci by EBISPOT.

the class SolrIndexer method mapAssociations.

Integer mapAssociations() {
    Sort sort = new Sort(new Sort.Order("id"));
    Pageable pager = new PageRequest(0, pageSize, sort);
    Page<Association> associationPage = associationService.findPublishedAssociations(pager);
    associationMapper.map(associationPage.getContent());
    while (associationPage.hasNext()) {
        if (maxPages != -1 && associationPage.getNumber() >= maxPages - 1) {
            break;
        }
        pager = pager.next();
        associationPage = associationService.findPublishedAssociations(pager);
        associationMapper.map(associationPage.getContent());
        if (sysOutLogging) {
            System.out.print(".");
        }
    }
    return (int) associationPage.getTotalElements();
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Association(uk.ac.ebi.spot.goci.model.Association) Sort(org.springframework.data.domain.Sort)

Example 3 with Sort

use of org.springframework.data.domain.Sort in project goci by EBISPOT.

the class SolrIndexer method mapStudies.

Integer mapStudies() {
    Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "publicationDate"));
    Pageable pager = new PageRequest(0, pageSize, sort);
    Page<Study> studyPage = studyService.findPublishedStudies(pager);
    studyMapper.map(studyPage.getContent());
    while (studyPage.hasNext()) {
        if (maxPages != -1 && studyPage.getNumber() >= maxPages - 1) {
            break;
        }
        pager = pager.next();
        studyPage = studyService.findPublishedStudies(pager);
        studyMapper.map(studyPage.getContent());
        if (sysOutLogging) {
            System.out.print(".");
        }
    }
    return (int) studyPage.getTotalElements();
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort)

Example 4 with Sort

use of org.springframework.data.domain.Sort in project springboot_op by SnailFastGo.

the class UserController method curPage.

@RequestMapping(value = "/curpage")
public List<UserEntity> curPage(int page) {
    UserEntity user = new UserEntity();
    user.setSize(2);
    user.setPage(page);
    user.setSort("desc");
    Sort.Direction direction = Sort.Direction.DESC;
    Sort sort = new Sort(direction, "name");
    PageRequest pageRequest = new PageRequest(user.getPage() - 1, user.getSize(), sort);
    List<UserEntity> res = userService.curPage(pageRequest);
    return res;
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Sort(org.springframework.data.domain.Sort) UserEntity(com.myspringboot.entity.UserEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Sort

use of org.springframework.data.domain.Sort in project sic by belluccifranco.

the class PedidoServiceImpl method buscarConCriteria.

@Override
public List<Pedido> buscarConCriteria(BusquedaPedidoCriteria criteria) {
    //Fecha
    if (criteria.isBuscaPorFecha() == true & (criteria.getFechaDesde() == null | criteria.getFechaHasta() == null)) {
        throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_pedido_fechas_busqueda_invalidas"));
    }
    if (criteria.isBuscaPorFecha() == true) {
        Calendar cal = new GregorianCalendar();
        cal.setTime(criteria.getFechaDesde());
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        criteria.setFechaDesde(cal.getTime());
        cal.setTime(criteria.getFechaHasta());
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        criteria.setFechaHasta(cal.getTime());
    }
    //Empresa
    if (criteria.getEmpresa() == null) {
        throw new EntityNotFoundException(ResourceBundle.getBundle("Mensajes").getString("mensaje_empresa_no_existente"));
    }
    //Cliente
    if (criteria.isBuscaCliente() == true && criteria.getCliente() == null) {
        throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_cliente_vacio_razonSocial"));
    }
    //Usuario
    if (criteria.isBuscaUsuario() == true && criteria.getUsuario() == null) {
        throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_usuario_vacio_nombre"));
    }
    QPedido qpedido = QPedido.pedido;
    BooleanBuilder builder = new BooleanBuilder();
    builder.and(qpedido.empresa.eq(criteria.getEmpresa()).and(qpedido.eliminado.eq(false)));
    if (criteria.isBuscaPorFecha() == true) {
        FormatterFechaHora formateadorFecha = new FormatterFechaHora(FormatterFechaHora.FORMATO_FECHAHORA_INTERNACIONAL);
        DateExpression<Date> fDesde = Expressions.dateTemplate(Date.class, "convert({0}, datetime)", formateadorFecha.format(criteria.getFechaDesde()));
        DateExpression<Date> fHasta = Expressions.dateTemplate(Date.class, "convert({0}, datetime)", formateadorFecha.format(criteria.getFechaHasta()));
        builder.and(qpedido.fecha.between(fDesde, fHasta));
    }
    if (criteria.isBuscaCliente() == true) {
        builder.and(qpedido.cliente.eq(criteria.getCliente()));
    }
    if (criteria.isBuscaUsuario() == true) {
        builder.and(qpedido.usuario.eq(criteria.getUsuario()));
    }
    if (criteria.isBuscaPorNroPedido() == true) {
        builder.and(qpedido.nroPedido.eq(criteria.getNroPedido()));
    }
    List<Pedido> pedidos = new ArrayList<>();
    pedidoRepository.findAll(builder, new Sort(Sort.Direction.DESC, "fecha")).iterator().forEachRemaining(pedidos::add);
    return this.calcularTotalActualDePedidos(pedidos);
}
Also used : FormatterFechaHora(sic.util.FormatterFechaHora) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) RenglonPedido(sic.modelo.RenglonPedido) QPedido(sic.modelo.QPedido) Pedido(sic.modelo.Pedido) EstadoPedido(sic.modelo.EstadoPedido) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList) EntityNotFoundException(javax.persistence.EntityNotFoundException) QPedido(sic.modelo.QPedido) Date(java.util.Date) BusinessServiceException(sic.service.BusinessServiceException) BooleanBuilder(com.querydsl.core.BooleanBuilder) Sort(org.springframework.data.domain.Sort)

Aggregations

Sort (org.springframework.data.domain.Sort)16 PageRequest (org.springframework.data.domain.PageRequest)7 Pageable (org.springframework.data.domain.Pageable)6 BooleanBuilder (com.querydsl.core.BooleanBuilder)5 ArrayList (java.util.ArrayList)5 EntityNotFoundException (javax.persistence.EntityNotFoundException)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Calendar (java.util.Calendar)2 Date (java.util.Date)2 GregorianCalendar (java.util.GregorianCalendar)2 Proveedor (sic.modelo.Proveedor)2 BusinessServiceException (sic.service.BusinessServiceException)2 FormatterFechaHora (sic.util.FormatterFechaHora)2 DiseaseTrait (uk.ac.ebi.spot.goci.model.DiseaseTrait)2 Study (uk.ac.ebi.spot.goci.model.Study)2 UserEntity (com.myspringboot.entity.UserEntity)1 LocalDate (java.time.LocalDate)1 HashMap (java.util.HashMap)1 Person (org.apache.ignite.springdata.misc.Person)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1