SourceDescriptorFilter.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.querydsl.core.types.Predicate;
  18. import lombok.EqualsAndHashCode;
  19. import lombok.Getter;
  20. import lombok.Setter;
  21. import lombok.experimental.Accessors;
  22. import org.apache.commons.collections4.CollectionUtils;
  23. import org.genesys.blocks.model.filters.NumberFilter;
  24. import org.genesys.blocks.model.filters.StringFilter;
  25. import org.gringlobal.model.QSourceDescriptor;
  26. import org.gringlobal.model.SourceDescriptor;
  27. import org.gringlobal.model.SourceDescriptorLang;

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

  30. /**
  31.  * The Class SourceDescriptorFilter.
  32.  */
  33. @Getter
  34. @Setter
  35. @EqualsAndHashCode(callSuper = true)
  36. @Accessors(fluent = true)
  37. public class SourceDescriptorFilter extends TranslatedEntityFilter<SourceDescriptorFilter, SourceDescriptor> implements IFullTextFilter {

  38.     private static final long serialVersionUID = 6943037238215920110L;

  39.     /** Any text. */
  40.     public String _text;

  41.     /** The categoryCode. */
  42.     public Set<String> categoryCode;

  43.     /** The codedName. */
  44.     public Set<String> codedName;

  45.     /** The dataTypeCode. */
  46.     public Set<String> dataTypeCode;

  47.     /** The description from {@link SourceDescriptorLang}. */
  48.     public StringFilter description;

  49.     /** The title from {@link SourceDescriptorLang}. */
  50.     public StringFilter title;

  51.     /** is coded. */
  52.     public Boolean coded;

  53.     /** The maxLength. */
  54.     public NumberFilter<Integer> maxLength;

  55.     /** The note. */
  56.     public StringFilter note;

  57.     /** The numericFormat. */
  58.     public Set<String> numericFormat;

  59.     /** The numericMaximum. */
  60.     public NumberFilter<Double> numericMaximum;

  61.     /** The numericMinimum. */
  62.     public NumberFilter<Double> numericMinimum;

  63.     /** The ontologyUrl. */
  64.     public Set<String> ontologyUrl;

  65.     /** The originalValueFormat. */
  66.     public Set<String> originalValueFormat;

  67.     /** The originalValueTypeCode. */
  68.     public Set<String> originalValueTypeCode;

  69.     @Override
  70.     public List<Predicate> collectPredicates() {
  71.         return collectPredicates(QSourceDescriptor.sourceDescriptor);
  72.     }

  73.     /**
  74.      * Collect predicates.
  75.      *
  76.      * @param sourceDescriptor the source descriptor
  77.      * @return the list
  78.      */
  79.     public List<Predicate> collectPredicates(QSourceDescriptor sourceDescriptor) {
  80.         final List<Predicate> predicates = super.collectPredicates(sourceDescriptor);

  81.         if (CollectionUtils.isNotEmpty(codedName)) {
  82.             predicates.add(sourceDescriptor.codedName.in(codedName));
  83.         }
  84.         if (CollectionUtils.isNotEmpty(dataTypeCode)) {
  85.             predicates.add(sourceDescriptor.dataTypeCode.in(dataTypeCode));
  86.         }
  87.         if (CollectionUtils.isNotEmpty(categoryCode)) {
  88.             predicates.add(sourceDescriptor.categoryCode.in(categoryCode));
  89.         }
  90.         if (description != null) {
  91.             predicates.add(description.buildQuery(sourceDescriptor.langs.any().description));
  92.         }
  93.         if (title != null) {
  94.             predicates.add(title.buildQuery(sourceDescriptor.langs.any().title));
  95.         }
  96.         if (coded != null) {
  97.             predicates.add(sourceDescriptor.isCoded.eq(convertToString(coded)));
  98.         }
  99.         if (maxLength != null) {
  100.             predicates.add(maxLength.buildQuery(sourceDescriptor.maxLength));
  101.         }
  102.         if (note != null) {
  103.             predicates.add(note.buildQuery(sourceDescriptor.note));
  104.         }
  105.         if (CollectionUtils.isNotEmpty(numericFormat)) {
  106.             predicates.add(sourceDescriptor.numericFormat.in(numericFormat));
  107.         }
  108.         if (numericMaximum != null) {
  109.             predicates.add(numericMaximum.buildQuery(sourceDescriptor.numericMaximum));
  110.         }
  111.         if (numericMinimum != null) {
  112.             predicates.add(numericMinimum.buildQuery(sourceDescriptor.numericMaximum));
  113.         }
  114.         if (CollectionUtils.isNotEmpty(ontologyUrl)) {
  115.             predicates.add(sourceDescriptor.ontologyUrl.in(ontologyUrl));
  116.         }
  117.         if (CollectionUtils.isNotEmpty(originalValueFormat)) {
  118.             predicates.add(sourceDescriptor.originalValueFormat.in(originalValueFormat));
  119.         }
  120.         if (CollectionUtils.isNotEmpty(originalValueTypeCode)) {
  121.             predicates.add(sourceDescriptor.originalValueTypeCode.in(originalValueTypeCode));
  122.         }

  123.         return predicates;
  124.     }

  125.     @Override
  126.     public String get_text() {
  127.         return _text;
  128.     }
  129. }