CitationFilter.java
/*
* Copyright 2024 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 com.querydsl.core.types.Predicate;
import org.apache.commons.collections4.CollectionUtils;
import org.genesys.blocks.model.filters.NumberFilter;
import org.genesys.blocks.model.filters.StringFilter;
import org.gringlobal.model.Citation;
import org.gringlobal.model.QCitation;
import java.util.List;
import java.util.Set;
/**
* Filters for {@link Citation}
*/
public class CitationFilter extends CooperatorOwnedModelFilter<CitationFilter, Citation> {
private static final long serialVersionUID = 1674550807816705624L;
/** The accession. */
public AccessionFilter accession;
/** The taxonomyFamily */
public TaxonomyFamilyFilter taxonomyFamily;
/** The taxonomyGenus */
public TaxonomyGenusFilter taxonomyGenus;
/** The taxonomySpecies */
public TaxonomySpeciesFilter taxonomySpecies;
/** The method. */
public MethodFilter method;
/** The literature. */
public LiteratureFilter literature;
/** The author name */
public StringFilter authorName;
/** The citation title */
public StringFilter citationTitle;
/** The description */
public StringFilter description;
/** The doi reference */
public StringFilter doiReference;
/** The note */
public StringFilter note;
/** The title */
public StringFilter title;
/** The url */
public StringFilter url;
/** The type code */
public Set<String> typeCode;
/** The unique key */
public NumberFilter<Integer> uniqueKey;
/** The citation year */
public NumberFilter<Integer> citationYear;
/**
* Builds the query.
*
* @return the predicate
*/
@Override
public List<Predicate> collectPredicates() {
return collectPredicates(QCitation.citation);
}
/**
* Builds the query.
*
* @param citation the citation
* @return the predicate
*/
public List<Predicate> collectPredicates(QCitation citation) {
final List<Predicate> predicates = super.collectPredicates(citation, citation._super);
if (accession != null) {
predicates.addAll(accession.collectPredicates(citation.accession()));
}
if (taxonomyFamily != null) {
predicates.addAll(taxonomyFamily.collectPredicates(citation.taxonomyFamily()));
}
if (taxonomyGenus != null) {
predicates.addAll(taxonomyGenus.collectPredicates(citation.taxonomyGenus()));
}
if (taxonomySpecies != null) {
predicates.addAll(taxonomySpecies.collectPredicates(citation.taxonomySpecies()));
}
if (method != null) {
predicates.addAll(method.collectPredicates(citation.method()));
}
if (literature != null) {
predicates.addAll(literature.collectPredicates(citation.literature()));
}
if (authorName != null) {
predicates.add(authorName.buildQuery(citation.authorName));
}
if (citationTitle != null) {
predicates.add(citationTitle.buildQuery(citation.citationTitle));
}
if (description != null) {
predicates.add(description.buildQuery(citation.description));
}
if (doiReference != null) {
predicates.add(doiReference.buildQuery(citation.doiReference));
}
if (note != null) {
predicates.add(note.buildQuery(citation.note));
}
if (title != null) {
predicates.add(title.buildQuery(citation.title));
}
if (CollectionUtils.isNotEmpty(typeCode)) {
predicates.add(citation.typeCode.in(typeCode));
}
if (url != null) {
predicates.add(url.buildQuery(citation.url));
}
if (uniqueKey != null) {
predicates.add(uniqueKey.buildQuery(citation.uniqueKey));
}
if (citationYear != null) {
predicates.add(citationYear.buildQuery(citation.citationYear));
}
return predicates;
}
}