Java Code Examples for org.apache.deltaspike.data.api.criteria.Criteria#or()
The following examples show how to use
org.apache.deltaspike.data.api.criteria.Criteria#or() .
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: CreditCardInvoiceRepository.java From web-budget with GNU General Public License v3.0 | 6 votes |
/** * Build the {@link Criteria} to search for {@link CreditCardInvoice} * * @param filter value * @param invoiceState to filter * @return the {@link Criteria} ready to search */ @SuppressWarnings("unchecked") default Criteria<CreditCardInvoice, CreditCardInvoice> buildCriteria(String filter, InvoiceState invoiceState) { final Criteria<CreditCardInvoice, CreditCardInvoice> criteria = this.criteria(); if (invoiceState != null) { criteria.eq(CreditCardInvoice_.invoiceState, invoiceState); } if (StringUtils.isNotBlank(filter)) { criteria.or( this.criteria().join(CreditCardInvoice_.card, where(Card.class) .likeIgnoreCase(Card_.name, this.likeAny(filter))), this.criteria().join(CreditCardInvoice_.financialPeriod, where(FinancialPeriod.class) .likeIgnoreCase(FinancialPeriod_.identification, this.likeAny(filter))) ); } criteria.orderAsc(CreditCardInvoice_.financialPeriod); return criteria; }
Example 2
Source File: CreditCardInvoiceRepository.java From web-budget with GNU General Public License v3.0 | 6 votes |
/** * Build the {@link Criteria} to search for {@link CreditCardInvoice} * * @param filter value * @param invoiceState to filter * @return the {@link Criteria} ready to search */ @SuppressWarnings("unchecked") default Criteria<CreditCardInvoice, CreditCardInvoice> buildCriteria(String filter, InvoiceState invoiceState) { final Criteria<CreditCardInvoice, CreditCardInvoice> criteria = this.criteria(); if (invoiceState != null) { criteria.eq(CreditCardInvoice_.invoiceState, invoiceState); } if (StringUtils.isNotBlank(filter)) { criteria.or( this.criteria().join(CreditCardInvoice_.card, where(Card.class) .likeIgnoreCase(Card_.name, this.likeAny(filter))), this.criteria().join(CreditCardInvoice_.financialPeriod, where(FinancialPeriod.class) .likeIgnoreCase(FinancialPeriod_.identification, this.likeAny(filter))) ); } criteria.orderAsc(CreditCardInvoice_.financialPeriod); return criteria; }
Example 3
Source File: DeltaSpikeRepository.java From library with Apache License 2.0 | 5 votes |
/** * Method used to apply the filters to the current query * * @param filter to be applied * @param active entity state indicating active or inactive (true or false) * @return {@link List} of all {@link Criteria} to be used as query filters */ default Criteria<T, T> applyFilters(String filter, Boolean active) { final Criteria<T, T> criteria = criteria(); if (isNotBlank(filter)) { criteria.or(this.getRestrictions(filter)); } if (active != null) { criteria.eq(this.getEntityStateProperty(), active); } return criteria; }
Example 4
Source File: DefaultRepository.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * Helper method to create {@link Criteria} instances, do not override this method or if you do this, keep in mind * that you are change a core behavior and problems here means problems in all queries inside de the application * * @param filter the filters provided by the {@link #getRestrictions(String)} * @param active the active property provided by the {@link #getEntityStateProperty()} * @return a new criteria ready to query */ default Criteria<T, T> buildCriteria(String filter, Boolean active) { final Criteria<T, T> criteria = criteria(); if (isNotBlank(filter)) { criteria.or(this.getRestrictions(filter)); } if (active != null) { criteria.eq(this.getEntityStateProperty(), active); } return criteria; }
Example 5
Source File: WalletBalanceRepository.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * 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 6
Source File: TransferenceRepository.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * Find all transference using a given filter * * @param filter used to search for {@link Transference} * @return a list of {@link Transference} found */ default List<Transference> findByFilter(TransferenceFilter filter) { final Criteria<Transference, Transference> criteria = this.criteria(); final List<Criteria<Transference, Transference>> restrictions = new ArrayList<>(); if (filter.getOriginWallet() != null) { restrictions.add(this.criteria().join(Transference_.origin, where(Wallet.class).eq(Wallet_.id, filter.getOriginWallet().getId()))); } if (filter.getDestinationWallet() != null) { restrictions.add(this.criteria().join(Transference_.destination, where(Wallet.class).eq(Wallet_.id, filter.getDestinationWallet().getId()))); } if (filter.getOperationDate() != null) { restrictions.add(this.criteria().eq(Transference_.transferDate, filter.getOperationDate())); } if (!restrictions.isEmpty()) { criteria.or(restrictions); } return criteria.getResultList(); }
Example 7
Source File: DefaultRepository.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * Helper method to create {@link Criteria} instances, do not override this method or if you do this, keep in mind * that you are change a core behavior and problems here means problems in all queries inside de the application * * @param filter the filters provided by the {@link #getRestrictions(String)} * @param active the active property provided by the {@link #getEntityStateProperty()} * @return a new criteria ready to query */ default Criteria<T, T> buildCriteria(String filter, Boolean active) { final Criteria<T, T> criteria = criteria(); if (isNotBlank(filter)) { criteria.or(this.getRestrictions(filter)); } if (active != null) { criteria.eq(this.getEntityStateProperty(), active); } return criteria; }
Example 8
Source File: WalletBalanceRepository.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * 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 9
Source File: TransferenceRepository.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * Find all transference using a given filter * * @param filter used to search for {@link Transference} * @return a list of {@link Transference} found */ default List<Transference> findByFilter(TransferenceFilter filter) { final Criteria<Transference, Transference> criteria = this.criteria(); final List<Criteria<Transference, Transference>> restrictions = new ArrayList<>(); if (filter.getOriginWallet() != null) { restrictions.add(this.criteria().join(Transference_.origin, where(Wallet.class).eq(Wallet_.id, filter.getOriginWallet().getId()))); } if (filter.getDestinationWallet() != null) { restrictions.add(this.criteria().join(Transference_.destination, where(Wallet.class).eq(Wallet_.id, filter.getDestinationWallet().getId()))); } if (filter.getOperationDate() != null) { restrictions.add(this.criteria().eq(Transference_.transferDate, filter.getOperationDate())); } if (!restrictions.isEmpty()) { criteria.or(restrictions); } return criteria.getResultList(); }
Example 10
Source File: PeriodMovementRepository.java From web-budget with GNU General Public License v3.0 | 4 votes |
/** * 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 11
Source File: FixedMovementRepository.java From web-budget with GNU General Public License v3.0 | 4 votes |
/** * Create and apply the filters to the {@link Criteria} * * @param filter to be used * @return the {@link Criteria} created to search for {@link FixedMovement} */ default Criteria<FixedMovement, FixedMovement> buildCriteria(FixedMovementFilter filter) { final Criteria<FixedMovement, FixedMovement> criteria = this.criteria(); if (filter.getFixedMovementState() != null) { criteria.eq(FixedMovement_.fixedMovementState, filter.getFixedMovementState()); } if (isNotBlank(filter.getValue())) { final String anyFilter = this.likeAny(filter.getValue()); final Set<Criteria<FixedMovement, FixedMovement>> restrictions = new HashSet<>(); restrictions.add(this.criteria().likeIgnoreCase(FixedMovement_.identification, anyFilter)); restrictions.add(this.criteria().likeIgnoreCase(FixedMovement_.description, anyFilter)); filter.valueToBigDecimal() .ifPresent(value -> restrictions.add(this.criteria().eq(PeriodMovement_.value, value))); criteria.or(restrictions); } return criteria; }
Example 12
Source File: PeriodMovementRepository.java From web-budget with GNU General Public License v3.0 | 4 votes |
/** * 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 13
Source File: FixedMovementRepository.java From web-budget with GNU General Public License v3.0 | 4 votes |
/** * Create and apply the filters to the {@link Criteria} * * @param filter to be used * @return the {@link Criteria} created to search for {@link FixedMovement} */ default Criteria<FixedMovement, FixedMovement> buildCriteria(FixedMovementFilter filter) { final Criteria<FixedMovement, FixedMovement> criteria = this.criteria(); if (filter.getFixedMovementState() != null) { criteria.eq(FixedMovement_.fixedMovementState, filter.getFixedMovementState()); } if (isNotBlank(filter.getValue())) { final String anyFilter = this.likeAny(filter.getValue()); final Set<Criteria<FixedMovement, FixedMovement>> restrictions = new HashSet<>(); restrictions.add(this.criteria().likeIgnoreCase(FixedMovement_.identification, anyFilter)); restrictions.add(this.criteria().likeIgnoreCase(FixedMovement_.description, anyFilter)); filter.valueToBigDecimal() .ifPresent(value -> restrictions.add(this.criteria().eq(PeriodMovement_.value, value))); criteria.or(restrictions); } return criteria; }