ExplorationFilter.java

/*
 * Copyright 2026 Global Crop Diversity Trust
 * Licensed under the Apache License, Version 2.0
 * See LICENSE file in project root folder or http://www.apache.org/licenses/LICENSE-2.0
 */

package org.gringlobal.service.filter;

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

import org.genesys.blocks.model.filters.NumberFilter;
import org.genesys.blocks.model.filters.StringFilter;
import org.genesys.blocks.model.filters.TemporalFilter;

import org.gringlobal.model.Exploration;
import org.gringlobal.model.QExploration;

import com.querydsl.core.types.Predicate;
import org.apache.commons.collections4.CollectionUtils;

public class ExplorationFilter extends CooperatorOwnedModelFilter<ExplorationFilter, Exploration, QExploration> {

	private static final long serialVersionUID = 8588489474890118470L;

	/** The began date. */
	public TemporalFilter<Date> beganDate;

	/** The exploration number. */
	public Set<String> explorationNumber;

	/** The finished date. */
	public TemporalFilter<Date> finishedDate;

	/** The fiscal year. */
	public NumberFilter<Integer> fiscalYear;

	/** The funding amount. */
	public NumberFilter<Double> fundingAmount;

	/** The funding source. */
	public StringFilter fundingSource;

	/** The host cooperator. */
	public CooperatorFilter hostCooperator;

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

	/** The permits. */
	public StringFilter permits;

	/** The restrictions. */
	public StringFilter restrictions;

	/** The target species. */
	public Set<String> targetSpecies;

	/** The title. */
	public StringFilter title;

	@Override
	public List<Predicate> collectPredicates() {
		return collectPredicates(QExploration.exploration);
	}

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

		if (beganDate != null) {
			predicates.add(beganDate.buildQuery(exploration.beganDate));
		}
		if (CollectionUtils.isNotEmpty(explorationNumber)) {
			predicates.add(exploration.explorationNumber.in(explorationNumber));
		}
		if (finishedDate != null) {
			predicates.add(finishedDate.buildQuery(exploration.finishedDate));
		}
		if (fiscalYear != null) {
			predicates.add(fiscalYear.buildQuery(exploration.fiscalYear));
		}
		if (fundingAmount != null) {
			predicates.add(fundingAmount.buildQuery(exploration.fundingAmount));
		}
		if (fundingSource != null) {
			predicates.add(fundingSource.buildQuery(exploration.fundingSource));
		}
		if (hostCooperator != null) {
			predicates.add(hostCooperator.nestedPredicate(exploration.hostCooperator()));
		}
		if (note != null) {
			predicates.add(note.buildQuery(exploration.note));
		}
		if (permits != null) {
			predicates.add(permits.buildQuery(exploration.permits));
		}
		if (restrictions != null) {
			predicates.add(restrictions.buildQuery(exploration.restrictions));
		}
		if (CollectionUtils.isNotEmpty(targetSpecies)) {
			predicates.add(exploration.targetSpecies.in(targetSpecies));
		}
		if (title != null) {
			predicates.add(title.buildQuery(exploration.title));
		}

		return predicates;
	}
}