TaxonomyGenusFilter.java
/*
* Copyright 2020 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gringlobal.service.filter;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.apache.commons.collections4.CollectionUtils;
import org.genesys.blocks.model.filters.StringFilter;
import org.gringlobal.model.QTaxonomyGenus;
import org.gringlobal.model.TaxonomyGenus;
import com.querydsl.core.types.Predicate;
/**
* Filters for {@link TaxonomyGenus}
*/
@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
@Accessors(fluent = true)
public class TaxonomyGenusFilter extends CooperatorOwnedModelFilter<TaxonomyGenusFilter, TaxonomyGenus> implements IFullTextFilter {
private static final long serialVersionUID = -3011099784670137730L;
/** Any text. */
public String _text;
/** Is current version */
public Boolean current;
/** The genus authority */
public StringFilter genusAuthority;
/** The genus name */
public StringFilter genusName;
/** The hybrid code */
public Set<String> hybridCode;
/** The note */
public StringFilter note;
/** The qualifying code */
public Set<String> qualifyingCode;
/** The section name */
public StringFilter sectionName;
/** The series name */
public StringFilter seriesName;
/** The subgenus name */
public StringFilter subgenusName;
/** The subsection name */
public StringFilter subsectionName;
/** The subseries name */
public StringFilter subseriesName;
/** The taxonomy family */
public TaxonomyFamilyFilter taxonomyFamily;
/**
* Builds the query.
*
* @return the predicate
*/
@Override
public List<Predicate> collectPredicates() {
return collectPredicates(QTaxonomyGenus.taxonomyGenus);
}
/**
* Builds the query.
*
* @param taxonomyGenus the taxonomyGenus
* @return the predicate
*/
public List<Predicate> collectPredicates(QTaxonomyGenus taxonomyGenus) {
final List<Predicate> predicates = super.collectPredicates(taxonomyGenus, taxonomyGenus._super);
if (current != null) { //FIXME need to test
if (current) {
predicates.add(taxonomyGenus.id.eq(taxonomyGenus.currentTaxonomyGenus().id));
} else {
predicates.add(taxonomyGenus.id.ne(taxonomyGenus.currentTaxonomyGenus().id));
}
}
if (genusAuthority != null) {
predicates.add(genusAuthority.buildQuery(taxonomyGenus.genusAuthority));
}
if (genusName != null) {
predicates.add(genusName.buildQuery(taxonomyGenus.genusName));
}
if (CollectionUtils.isNotEmpty(hybridCode)) {
predicates.add(taxonomyGenus.hybridCode.in(hybridCode));
}
if (note != null) {
predicates.add(note.buildQuery(taxonomyGenus.note));
}
if (CollectionUtils.isNotEmpty(qualifyingCode)) {
predicates.add(taxonomyGenus.qualifyingCode.in(qualifyingCode));
}
if (sectionName != null) {
predicates.add(sectionName.buildQuery(taxonomyGenus.sectionName));
}
if (seriesName != null) {
predicates.add(seriesName.buildQuery(taxonomyGenus.seriesName));
}
if (subgenusName != null) {
predicates.add(subgenusName.buildQuery(taxonomyGenus.subgenusName));
}
if (subsectionName != null) {
predicates.add(subsectionName.buildQuery(taxonomyGenus.subsectionName));
}
if (subseriesName != null) {
predicates.add(subseriesName.buildQuery(taxonomyGenus.subseriesName));
}
if (taxonomyFamily != null) {
predicates.addAll(taxonomyFamily.collectPredicates(taxonomyGenus.taxonomyFamily()));
}
return predicates;
}
@Override
public String get_text() {
return _text;
}
/**
* Id.
*
* @return the sets the
*/
public synchronized Set<Long> id() {
if (id == null) {
id = new HashSet<>();
}
return id;
}
/**
* Genus name filter.
*
* @return the string filter
*/
public synchronized StringFilter genusName() {
return this.genusName == null ? this.genusName = new StringFilter() : this.genusName;
}
}