Java Code Examples for org.apache.deltaspike.data.api.criteria.Criteria#join()

The following examples show how to use org.apache.deltaspike.data.api.criteria.Criteria#join() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WalletBalanceRepository.java    From web-budget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Find the {@link WalletBalance} by a given filter
 *
 * @param filter to be used on the search process
 * @return a {@link List} of the {@link WalletBalance} found
 */
default List<WalletBalance> findByFilter(WalletBalanceFilter filter) {

    final Criteria<WalletBalance, WalletBalance> criteria = this.criteria();

    final List<Criteria<WalletBalance, WalletBalance>> restrictions = new ArrayList<>();

    if (filter.getReasonType() != null) {
        restrictions.add(this.criteria().eq(WalletBalance_.reasonType, filter.getReasonType()));
    }

    if (filter.getBalanceType() != null) {
        restrictions.add(this.criteria().eq(WalletBalance_.balanceType, filter.getBalanceType()));
    }

    if (filter.getOperationDate() != null) {

        final var start = filter.getOperationDate().atTime(0, 0);
        final var end = filter.getOperationDate().atTime(23, 59);

        restrictions.add(this.criteria().between(WalletBalance_.movementDateTime, start, end));
    }

    if (!restrictions.isEmpty()) {
        criteria.or(restrictions);
    }

    criteria.join(WalletBalance_.wallet,
            where(Wallet.class).eq(Wallet_.id, filter.getWallet().getId()));

    return criteria.getResultList();
}
 
Example 2
Source File: WalletBalanceRepository.java    From web-budget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Find the {@link WalletBalance} by a given filter
 *
 * @param filter to be used on the search process
 * @return a {@link List} of the {@link WalletBalance} found
 */
default List<WalletBalance> findByFilter(WalletBalanceFilter filter) {

    final Criteria<WalletBalance, WalletBalance> criteria = this.criteria();

    final List<Criteria<WalletBalance, WalletBalance>> restrictions = new ArrayList<>();

    if (filter.getReasonType() != null) {
        restrictions.add(this.criteria().eq(WalletBalance_.reasonType, filter.getReasonType()));
    }

    if (filter.getBalanceType() != null) {
        restrictions.add(this.criteria().eq(WalletBalance_.balanceType, filter.getBalanceType()));
    }

    if (filter.getOperationDate() != null) {

        final var start = filter.getOperationDate().atTime(0, 0);
        final var end = filter.getOperationDate().atTime(23, 59);

        restrictions.add(this.criteria().between(WalletBalance_.movementDateTime, start, end));
    }

    if (!restrictions.isEmpty()) {
        criteria.or(restrictions);
    }

    criteria.join(WalletBalance_.wallet,
            where(Wallet.class).eq(Wallet_.id, filter.getWallet().getId()));

    return criteria.getResultList();
}
 
Example 3
Source File: PeriodMovementRepository.java    From web-budget with GNU General Public License v3.0 4 votes vote down vote up
/**
 * This method is used to build the {@link Criteria} used to find the {@link PeriodMovement}
 *
 * @param filter the {@link PeriodMovementFilter}
 * @return the {@link Criteria} with the restrictions to find the {@link PeriodMovement}
 */
default Criteria<PeriodMovement, PeriodMovement> buildCriteria(PeriodMovementFilter filter) {

    final Criteria<PeriodMovement, PeriodMovement> criteria = this.criteria();

    // set the movement state filter if present
    if (filter.getPeriodMovementState() != null) {
        criteria.eq(PeriodMovement_.periodMovementState, filter.getPeriodMovementState());
    }

    // the movement type filter if present
    if (filter.getPeriodMovementType() != null) {
        criteria.eq(PeriodMovement_.periodMovementType, filter.getPeriodMovementType());
    }

    // now the OR filters, more generic
    if (isNotBlank(filter.getValue())) {

        final String anyFilter = this.likeAny(filter.getValue());

        final Set<Criteria<PeriodMovement, PeriodMovement>> restrictions = new HashSet<>();

        restrictions.add(this.criteria().eq(PeriodMovement_.code, anyFilter));
        restrictions.add(this.criteria().likeIgnoreCase(PeriodMovement_.description, anyFilter));
        restrictions.add(this.criteria().likeIgnoreCase(PeriodMovement_.identification, anyFilter));
        restrictions.add(this.criteria().join(PeriodMovement_.financialPeriod,
                where(FinancialPeriod.class).likeIgnoreCase(FinancialPeriod_.identification, anyFilter)));

        // if we can cast the value of the filter to decimal, use this as filter
        filter.valueToBigDecimal()
                .ifPresent(value -> restrictions.add(this.criteria().eq(PeriodMovement_.value, value)));

        criteria.or(restrictions);
    }

    // put the selected cost center as a filter
    if (filter.getCostCenter() != null) {
        criteria.join(PeriodMovement_.apportionments,
                where(Apportionment.class).join(Apportionment_.costCenter,
                        where(CostCenter.class).eq(CostCenter_.id, filter.getCostCenter().getId())));

        // if we have a cost center them check if we have a movement class to filter too
        if (filter.getMovementClass() != null) {
            criteria.join(PeriodMovement_.apportionments,
                    where(Apportionment.class).join(Apportionment_.movementClass,
                            where(MovementClass.class).eq(MovementClass_.id, filter.getMovementClass().getId())));
        }
    }

    // put the selected financial periods as a filter
    if (filter.getSelectedFinancialPeriods() != null && !filter.getSelectedFinancialPeriods().isEmpty()) {
        criteria.join(PeriodMovement_.financialPeriod, where(FinancialPeriod.class)
                .in(FinancialPeriod_.identification, filter.getSelectedFinancialPeriodsAsStringArray()));
    }

    return criteria;
}
 
Example 4
Source File: PeriodMovementRepository.java    From web-budget with GNU General Public License v3.0 4 votes vote down vote up
/**
 * This method is used to build the {@link Criteria} used to find the {@link PeriodMovement}
 *
 * @param filter the {@link PeriodMovementFilter}
 * @return the {@link Criteria} with the restrictions to find the {@link PeriodMovement}
 */
default Criteria<PeriodMovement, PeriodMovement> buildCriteria(PeriodMovementFilter filter) {

    final Criteria<PeriodMovement, PeriodMovement> criteria = this.criteria();

    // set the movement state filter if present
    if (filter.getPeriodMovementState() != null) {
        criteria.eq(PeriodMovement_.periodMovementState, filter.getPeriodMovementState());
    }

    // the movement type filter if present
    if (filter.getPeriodMovementType() != null) {
        criteria.eq(PeriodMovement_.periodMovementType, filter.getPeriodMovementType());
    }

    // now the OR filters, more generic
    if (isNotBlank(filter.getValue())) {

        final String anyFilter = this.likeAny(filter.getValue());

        final Set<Criteria<PeriodMovement, PeriodMovement>> restrictions = new HashSet<>();

        restrictions.add(this.criteria().eq(PeriodMovement_.code, anyFilter));
        restrictions.add(this.criteria().likeIgnoreCase(PeriodMovement_.description, anyFilter));
        restrictions.add(this.criteria().likeIgnoreCase(PeriodMovement_.identification, anyFilter));
        restrictions.add(this.criteria().join(PeriodMovement_.financialPeriod,
                where(FinancialPeriod.class).likeIgnoreCase(FinancialPeriod_.identification, anyFilter)));

        // if we can cast the value of the filter to decimal, use this as filter
        filter.valueToBigDecimal()
                .ifPresent(value -> restrictions.add(this.criteria().eq(PeriodMovement_.value, value)));

        criteria.or(restrictions);
    }

    // put the selected cost center as a filter
    if (filter.getCostCenter() != null) {
        criteria.join(PeriodMovement_.apportionments,
                where(Apportionment.class).join(Apportionment_.costCenter,
                        where(CostCenter.class).eq(CostCenter_.id, filter.getCostCenter().getId())));

        // if we have a cost center them check if we have a movement class to filter too
        if (filter.getMovementClass() != null) {
            criteria.join(PeriodMovement_.apportionments,
                    where(Apportionment.class).join(Apportionment_.movementClass,
                            where(MovementClass.class).eq(MovementClass_.id, filter.getMovementClass().getId())));
        }
    }

    // put the selected financial periods as a filter
    if (filter.getSelectedFinancialPeriods() != null && !filter.getSelectedFinancialPeriods().isEmpty()) {
        criteria.join(PeriodMovement_.financialPeriod, where(FinancialPeriod.class)
                .in(FinancialPeriod_.identification, filter.getSelectedFinancialPeriodsAsStringArray()));
    }

    return criteria;
}