Search in sources :

Example 31 with BooleanBuilder

use of com.querydsl.core.BooleanBuilder in project kylo by Teradata.

the class DefaultAlertCriteria method orFilter.

protected BooleanBuilder orFilter(QJpaAlert alert) {
    BooleanBuilder globalFilter = new BooleanBuilder();
    if (StringUtils.isNotBlank(getOrFilter())) {
        Lists.newArrayList(StringUtils.split(getOrFilter(), ",")).stream().forEach(filter -> {
            filter = StringUtils.trim(filter);
            if (filter != null) {
                BooleanBuilder booleanBuilder = new BooleanBuilder();
                List<Predicate> preds = new ArrayList<>();
                try {
                    Alert.State state = Alert.State.valueOf(filter.toUpperCase());
                    preds.add(alert.state.eq(state));
                } catch (IllegalArgumentException e) {
                }
                preds.add(alert.typeString.like(filter.concat("%")));
                preds.add(alert.subtype.like(filter.concat("%")));
                booleanBuilder.andAnyOf(preds.toArray(new Predicate[preds.size()]));
                globalFilter.and(booleanBuilder);
            }
        });
    }
    return globalFilter;
}
Also used : BooleanBuilder(com.querydsl.core.BooleanBuilder) ArrayList(java.util.ArrayList) JpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert) Alert(com.thinkbiganalytics.alerts.api.Alert) QJpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.QJpaAlert) Predicate(com.querydsl.core.types.Predicate)

Example 32 with BooleanBuilder

use of com.querydsl.core.BooleanBuilder in project kylo by Teradata.

the class DefaultAlertCriteria method filter.

protected List<Predicate> filter(QJpaAlert alert) {
    List<Predicate> preds = new ArrayList<>();
    if (getStates().size() > 0) {
        preds.add(alert.state.in(getStates()));
    }
    if (getLevels().size() > 0) {
        preds.add(alert.level.in(getLevels()));
    }
    if (getAfterTime() != null) {
        preds.add(alert.createdTime.gt(getAfterTime()));
    }
    if (getBeforeTime() != null) {
        preds.add(alert.createdTime.lt(getBeforeTime()));
    }
    if (getAfterTime() != null) {
        preds.add(alert.createdTime.gt(getAfterTime()));
    }
    if (getBeforeTime() != null) {
        preds.add(alert.createdTime.lt(getBeforeTime()));
    }
    if (!isIncludeCleared()) {
        preds.add(alert.cleared.isFalse());
    }
    if (getTypes().size() > 0) {
        BooleanBuilder likes = new BooleanBuilder();
        getTypes().stream().map(uri -> alert.typeString.like(uri.toASCIIString().concat("%"))).forEach(pred -> likes.or(pred));
        preds.add(likes);
    }
    if (getSubtypes().size() > 0) {
        preds.add(alert.subtype.in(getSubtypes()));
    }
    return preds;
}
Also used : JpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert) BooleanBuilder(com.querydsl.core.BooleanBuilder) QueryBase(com.querydsl.core.support.QueryBase) Projections(com.querydsl.core.types.Projections) JPAQueryFactory(com.querydsl.jpa.impl.JPAQueryFactory) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) JPAQuery(com.querydsl.jpa.impl.JPAQuery) AlertSummary(com.thinkbiganalytics.alerts.api.AlertSummary) BaseAlertCriteria(com.thinkbiganalytics.alerts.api.core.BaseAlertCriteria) List(java.util.List) Lists(com.google.common.collect.Lists) Alert(com.thinkbiganalytics.alerts.api.Alert) DefaultAlertSummary(com.thinkbiganalytics.metadata.jpa.alerts.DefaultAlertSummary) Predicate(com.querydsl.core.types.Predicate) QJpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.QJpaAlert) BooleanBuilder(com.querydsl.core.BooleanBuilder) ArrayList(java.util.ArrayList) Predicate(com.querydsl.core.types.Predicate)

Example 33 with BooleanBuilder

use of com.querydsl.core.BooleanBuilder in project sic by belluccifranco.

the class ProductoServiceImpl method buscarProductos.

@Override
public Page<Producto> buscarProductos(BusquedaProductoCriteria criteria) {
    // Empresa
    if (criteria.getEmpresa() == null) {
        throw new EntityNotFoundException(ResourceBundle.getBundle("Mensajes").getString("mensaje_empresa_no_existente"));
    }
    // Rubro
    if (criteria.isBuscarPorRubro() == true && criteria.getRubro() == null) {
        throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_producto_vacio_rubro"));
    }
    // Proveedor
    if (criteria.isBuscarPorProveedor() == true && criteria.getProveedor() == null) {
        throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_producto_vacio_proveedor"));
    }
    QProducto qproducto = QProducto.producto;
    BooleanBuilder builder = new BooleanBuilder();
    builder.and(qproducto.empresa.eq(criteria.getEmpresa()).and(qproducto.eliminado.eq(false)));
    if (criteria.isBuscarPorCodigo() == true && criteria.isBuscarPorDescripcion() == true) {
        builder.and(qproducto.codigo.containsIgnoreCase(criteria.getCodigo()).or(this.buildPredicadoDescripcion(criteria.getDescripcion(), qproducto)));
    } else {
        if (criteria.isBuscarPorCodigo() == true) {
            builder.and(qproducto.codigo.containsIgnoreCase(criteria.getCodigo()));
        }
        if (criteria.isBuscarPorDescripcion() == true) {
            builder.and(this.buildPredicadoDescripcion(criteria.getDescripcion(), qproducto));
        }
    }
    if (criteria.isBuscarPorRubro() == true) {
        builder.and(qproducto.rubro.eq(criteria.getRubro()));
    }
    if (criteria.isBuscarPorProveedor()) {
        builder.and(qproducto.proveedor.eq(criteria.getProveedor()));
    }
    if (criteria.isListarSoloFaltantes() == true) {
        builder.and(qproducto.cantidad.loe(qproducto.cantMinima)).and(qproducto.ilimitado.eq(false));
    }
    int pageNumber = 0;
    int pageSize = Integer.MAX_VALUE;
    if (criteria.getPageable() != null) {
        pageNumber = criteria.getPageable().getPageNumber();
        pageSize = criteria.getPageable().getPageSize();
    }
    Pageable pageable = new PageRequest(pageNumber, pageSize, new Sort(Sort.Direction.ASC, "descripcion"));
    return productoRepository.findAll(builder, pageable);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) BusinessServiceException(sic.service.BusinessServiceException) Pageable(org.springframework.data.domain.Pageable) BooleanBuilder(com.querydsl.core.BooleanBuilder) Sort(org.springframework.data.domain.Sort) EntityNotFoundException(javax.persistence.EntityNotFoundException) QProducto(sic.modelo.QProducto)

Example 34 with BooleanBuilder

use of com.querydsl.core.BooleanBuilder in project sic by belluccifranco.

the class ClienteServiceImpl method buscarClientes.

@Override
public Page<Cliente> buscarClientes(BusquedaClienteCriteria criteria) {
    if (criteria.getEmpresa() == null) {
        throw new EntityNotFoundException(ResourceBundle.getBundle("Mensajes").getString("mensaje_empresa_no_existente"));
    }
    QCliente qcliente = QCliente.cliente;
    BooleanBuilder builder = new BooleanBuilder();
    if (criteria.isBuscaPorRazonSocial()) {
        String[] terminos = criteria.getRazonSocial().split(" ");
        BooleanBuilder rsPredicate = new BooleanBuilder();
        for (String termino : terminos) {
            rsPredicate.and(qcliente.razonSocial.containsIgnoreCase(termino));
        }
        builder.or(rsPredicate);
    }
    if (criteria.isBuscaPorNombreFantasia()) {
        String[] terminos = criteria.getNombreFantasia().split(" ");
        BooleanBuilder nfPredicate = new BooleanBuilder();
        for (String termino : terminos) {
            nfPredicate.and(qcliente.nombreFantasia.containsIgnoreCase(termino));
        }
        builder.or(nfPredicate);
    }
    if (criteria.isBuscaPorId_Fiscal()) {
        String[] terminos = criteria.getIdFiscal().split(" ");
        BooleanBuilder idPredicate = new BooleanBuilder();
        for (String termino : terminos) {
            idPredicate.and(qcliente.idFiscal.containsIgnoreCase(termino));
        }
        builder.or(idPredicate);
    }
    if (criteria.isBuscaPorLocalidad() == true) {
        builder.and(qcliente.localidad.eq(criteria.getLocalidad()));
    }
    if (criteria.isBuscaPorProvincia() == true) {
        builder.and(qcliente.localidad.provincia.eq(criteria.getProvincia()));
    }
    if (criteria.isBuscaPorPais() == true) {
        builder.and(qcliente.localidad.provincia.pais.eq(criteria.getPais()));
    }
    builder.and(qcliente.empresa.eq(criteria.getEmpresa()).and(qcliente.eliminado.eq(false)));
    Page<Cliente> page = clienteRepository.findAll(builder, criteria.getPageable());
    page.getContent().forEach(c -> {
        c.setSaldoCuentaCorriente(cuentaCorrienteService.getSaldoCuentaCorriente(true, new Date(), c.getId_Cliente()));
    });
    return page;
}
Also used : BooleanBuilder(com.querydsl.core.BooleanBuilder) QCliente(sic.modelo.QCliente) EntityNotFoundException(javax.persistence.EntityNotFoundException) QCliente(sic.modelo.QCliente) Cliente(sic.modelo.Cliente) Date(java.util.Date)

Example 35 with BooleanBuilder

use of com.querydsl.core.BooleanBuilder in project querydsl by querydsl.

the class PathBuilderTest method getByExample.

@SuppressWarnings("unchecked")
private <T> BooleanBuilder getByExample(T entity) {
    PathBuilder<T> entityPath = new PathBuilder<T>((Class<T>) entity.getClass(), "entity");
    BooleanBuilder conditions = new BooleanBuilder();
    Map<String, Object> beanMap = new BeanMap(entity);
    for (Map.Entry<String, Object> entry : beanMap.entrySet()) {
        if (!entry.getKey().equals("class")) {
            if (entry.getValue() != null) {
                conditions.and(entityPath.get(entry.getKey()).eq(entry.getValue()));
            }
        }
    }
    return conditions;
}
Also used : BeanMap(com.querydsl.core.util.BeanMap) BooleanBuilder(com.querydsl.core.BooleanBuilder) BeanMap(com.querydsl.core.util.BeanMap) Map(java.util.Map)

Aggregations

BooleanBuilder (com.querydsl.core.BooleanBuilder)41 Predicate (com.querydsl.core.types.Predicate)12 ArrayList (java.util.ArrayList)10 JPAQuery (com.querydsl.jpa.impl.JPAQuery)8 QJpaAlert (com.thinkbiganalytics.metadata.jpa.alerts.QJpaAlert)8 Sort (org.springframework.data.domain.Sort)8 List (java.util.List)7 QJpaOpsManagerFeed (com.thinkbiganalytics.metadata.jpa.feed.QJpaOpsManagerFeed)6 Map (java.util.Map)6 Pageable (org.springframework.data.domain.Pageable)6 Alert (com.thinkbiganalytics.alerts.api.Alert)5 Test (org.junit.Test)5 JpaAlert (com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert)4 HashMap (java.util.HashMap)4 Collectors (java.util.stream.Collectors)4 EntityNotFoundException (javax.persistence.EntityNotFoundException)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Service (org.springframework.stereotype.Service)4 Expression (com.querydsl.core.types.Expression)3 Projections (com.querydsl.core.types.Projections)3