ExplorationFilter.java

  1. /*
  2.  * Copyright 2024 Global Crop Diversity Trust
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *   http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */

  16. package org.gringlobal.service.filter;

  17. import com.querydsl.core.types.Predicate;
  18. import org.apache.commons.collections4.CollectionUtils;
  19. import org.genesys.blocks.model.filters.NumberFilter;
  20. import org.genesys.blocks.model.filters.StringFilter;
  21. import org.genesys.blocks.model.filters.TemporalFilter;
  22. import org.gringlobal.model.Exploration;
  23. import org.gringlobal.model.QExploration;

  24. import java.util.Date;
  25. import java.util.List;
  26. import java.util.Set;

  27. public class ExplorationFilter extends CooperatorOwnedModelFilter<ExplorationFilter, Exploration> {
  28.    
  29.     private static final long serialVersionUID = 8588489474890118470L;

  30.     /** The began date. */
  31.     public TemporalFilter<Date> beganDate;

  32.     /** The exploration number. */
  33.     public Set<String> explorationNumber;

  34.     /** The finished date. */
  35.     public TemporalFilter<Date> finishedDate;

  36.     /** The fiscal year. */
  37.     public NumberFilter<Integer> fiscalYear;

  38.     /** The funding amount. */
  39.     public NumberFilter<Double> fundingAmount;

  40.     /** The funding source. */
  41.     public StringFilter fundingSource;

  42.     /** The host cooperator. */
  43.     public CooperatorFilter hostCooperator;

  44.     /** The note. */
  45.     public StringFilter note;

  46.     /** The permits. */
  47.     public StringFilter permits;

  48.     /** The restrictions. */
  49.     public StringFilter restrictions;

  50.     /** The target species. */
  51.     public Set<String> targetSpecies;

  52.     /** The title. */
  53.     public StringFilter title;

  54.     @Override
  55.     public List<Predicate> collectPredicates() {
  56.         return collectPredicates(QExploration.exploration);
  57.     }

  58.     /**
  59.      * Builds the query.
  60.      *
  61.      * @param exploration the exploration
  62.      * @return the predicate
  63.      */
  64.     public List<Predicate> collectPredicates(QExploration exploration) {
  65.         final List<Predicate> predicates = super.collectPredicates(exploration, exploration._super);

  66.         if (beganDate != null) {
  67.             predicates.add(beganDate.buildQuery(exploration.beganDate));
  68.         }
  69.         if (CollectionUtils.isNotEmpty(explorationNumber)) {
  70.             predicates.add(exploration.explorationNumber.in(explorationNumber));
  71.         }
  72.         if (finishedDate != null) {
  73.             predicates.add(finishedDate.buildQuery(exploration.finishedDate));
  74.         }
  75.         if (fiscalYear != null) {
  76.             predicates.add(fiscalYear.buildQuery(exploration.fiscalYear));
  77.         }
  78.         if (fundingAmount != null) {
  79.             predicates.add(fundingAmount.buildQuery(exploration.fundingAmount));
  80.         }
  81.         if (fundingSource != null) {
  82.             predicates.add(fundingSource.buildQuery(exploration.fundingSource));
  83.         }
  84.         if (hostCooperator != null) {
  85.             predicates.addAll(hostCooperator.collectPredicates(exploration.hostCooperator()));
  86.         }
  87.         if (note != null) {
  88.             predicates.add(note.buildQuery(exploration.note));
  89.         }
  90.         if (permits != null) {
  91.             predicates.add(permits.buildQuery(exploration.permits));
  92.         }
  93.         if (restrictions != null) {
  94.             predicates.add(restrictions.buildQuery(exploration.restrictions));
  95.         }
  96.         if (CollectionUtils.isNotEmpty(targetSpecies)) {
  97.             predicates.add(exploration.targetSpecies.in(targetSpecies));
  98.         }
  99.         if (title != null) {
  100.             predicates.add(title.buildQuery(exploration.title));
  101.         }
  102.        
  103.         return predicates;
  104.     }
  105. }