LiteratureFilter.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.StringFilter;
import org.gringlobal.model.Literature;
import org.gringlobal.model.QLiterature;

import java.util.List;
import java.util.Set;

/**
 * Filters for {@link Literature}
 */
public class LiteratureFilter extends CooperatorOwnedModelFilter<LiteratureFilter, Literature> {

	private static final long serialVersionUID = -8648077227162344334L;

	/** The abbreviation */
	public Set<String> abbreviation;
	/** The standard abbreviation */
	public Set<String> standardAbbreviation;
	/** The publication year */
	public Set<String> publicationYear;
	/** The literature type code */
	public Set<String> literatureTypeCode;

	/** The editor author name */
	public StringFilter editorAuthorName;
	/** The note */
	public StringFilter note;
	/** The publisher location */
	public StringFilter publisherLocation;
	/** The publisher name */
	public StringFilter publisherName;
	/** The reference title */
	public StringFilter referenceTitle;
	/** The url */
	public StringFilter url;

	/**
	 * Builds the query.
	 *
	 * @return the predicate
	 */
	@Override
	public List<Predicate> collectPredicates() {
		return collectPredicates(QLiterature.literature);
	}

	/**
	 * Builds the query.
	 *
	 * @param literature the literature
	 * @return the predicate
	 */
	public List<Predicate> collectPredicates(QLiterature literature) {
		final List<Predicate> predicates = super.collectPredicates(literature, literature._super);

		if (CollectionUtils.isNotEmpty(abbreviation)) {
			predicates.add(literature.abbreviation.in(abbreviation));
		}
		if (CollectionUtils.isNotEmpty(standardAbbreviation)) {
			predicates.add(literature.standardAbbreviation.in(standardAbbreviation));
		}
		if (CollectionUtils.isNotEmpty(publicationYear)) {
			predicates.add(literature.publicationYear.in(publicationYear));
		}
		if (CollectionUtils.isNotEmpty(literatureTypeCode)) {
			predicates.add(literature.literatureTypeCode.in(literatureTypeCode));
		}

		if (editorAuthorName != null) {
			predicates.add(editorAuthorName.buildQuery(literature.editorAuthorName));
		}
		if (note != null) {
			predicates.add(note.buildQuery(literature.note));
		}
		if (publisherLocation != null) {
			predicates.add(publisherLocation.buildQuery(literature.publisherLocation));
		}
		if (publisherName != null) {
			predicates.add(publisherName.buildQuery(literature.publisherName));
		}
		if (referenceTitle != null) {
			predicates.add(referenceTitle.buildQuery(literature.referenceTitle));
		}
		if (url != null) {
			predicates.add(url.buildQuery(literature.url));
		}

		return predicates;
	}
}