InventoryViabilityDataFilter.java

  1. /*
  2.  * Copyright 2021 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.fasterxml.jackson.annotation.JsonIgnoreProperties;
  18. import com.fasterxml.jackson.annotation.JsonUnwrapped;
  19. import com.querydsl.core.types.Predicate;
  20. import lombok.EqualsAndHashCode;
  21. import lombok.Getter;
  22. import lombok.Setter;
  23. import lombok.experimental.Accessors;
  24. import org.apache.commons.collections.CollectionUtils;
  25. import org.gringlobal.model.InventoryViabilityData;
  26. import org.gringlobal.model.QInventoryViabilityData;

  27. import java.util.List;
  28. import java.util.Set;

  29. /**
  30.  * Filters for {@link InventoryViabilityData}
  31.  */
  32. @Getter
  33. @Setter
  34. @EqualsAndHashCode(callSuper = true)
  35. @Accessors(fluent = true)
  36. public class InventoryViabilityDataFilter extends CooperatorOwnedModelFilter<InventoryViabilityDataFilter, InventoryViabilityData> {

  37.     private static final long serialVersionUID = -2982144698806187362L;

  38.     @JsonUnwrapped
  39.     @JsonIgnoreProperties({ "id", "ownedBy", "ownedDate", "createdBy", "createdDate", "modifiedBy", "modifiedDate" })
  40.     public InventoryViabilityFilter inventoryViabilityFilter;
  41.    
  42.     public Set<Long> inventoryViabilityId;
  43.    
  44.     /**
  45.      * Builds the query.
  46.      *
  47.      * @return the predicate
  48.      */
  49.     @Override
  50.     public List<Predicate> collectPredicates() {
  51.         return collectPredicates(QInventoryViabilityData.inventoryViabilityData);
  52.     }

  53.     /**
  54.      * Builds the query.
  55.      *
  56.      * @param inventoryViabilityData the inventoryViabilityData
  57.      * @return the predicate
  58.      */
  59.     public List<Predicate> collectPredicates(QInventoryViabilityData inventoryViabilityData) {
  60.         List<Predicate> predicates = super.collectPredicates(inventoryViabilityData, inventoryViabilityData._super);

  61.         // InventoryViabilityFilter
  62.         if (inventoryViabilityFilter != null) {
  63.             if (inventoryViabilityFilter.inventory != null) {
  64.                 predicates.addAll(inventoryViabilityFilter.inventory.collectPredicates(inventoryViabilityData.inventoryViability().inventory()));
  65.             }
  66.             if (inventoryViabilityFilter.inventoryViabilityRule != null) {
  67.                 predicates.addAll(inventoryViabilityFilter.inventoryViabilityRule.collectPredicates(inventoryViabilityData.inventoryViability().inventoryViabilityRule()));
  68.             }
  69.             if (inventoryViabilityFilter.testedDate != null) {
  70.                 predicates.add(inventoryViabilityFilter.testedDate.buildQuery(inventoryViabilityData.inventoryViability().testedDate));
  71.             }
  72.             if (CollectionUtils.isNotEmpty(inventoryViabilityFilter.vigorRatingCode)) {
  73.                 predicates.add(inventoryViabilityData.inventoryViability().vigorRatingCode.in(inventoryViabilityFilter.vigorRatingCode));
  74.             }
  75.             if (inventoryViabilityFilter.percentViable != null) {
  76.                 predicates.add(inventoryViabilityFilter.percentViable.buildQuery(inventoryViabilityData.inventoryViability().percentViable));
  77.             }
  78.             if (inventoryViabilityFilter.replicationCount != null) {
  79.                 predicates.add(inventoryViabilityFilter.replicationCount.buildQuery(inventoryViabilityData.inventoryViability().replicationCount));
  80.             }
  81.             if (inventoryViabilityFilter.totalTestedCount != null) {
  82.                 predicates.add(inventoryViabilityFilter.totalTestedCount.buildQuery(inventoryViabilityData.inventoryViability().totalTestedCount));
  83.             }
  84.         }
  85.        
  86.         if (CollectionUtils.isNotEmpty(inventoryViabilityId)) {
  87.             predicates.add(inventoryViabilityData.inventoryViability().id.in(inventoryViabilityId));
  88.         }
  89.         return predicates;
  90.     }
  91. }