InventoryViabilityEnvFilter.java

/*
 * Copyright 2021 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.List;
import java.util.Set;

import com.querydsl.core.types.Predicate;
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.NumberFilter;
import org.gringlobal.model.InventoryViabilityEnvironment;
import org.gringlobal.model.QInventoryViabilityEnvironment;

/**
 * Filters for {@link InventoryViabilityEnvFilter}
 */
@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
@Accessors(fluent = true)
public class InventoryViabilityEnvFilter extends CooperatorOwnedModelFilter<InventoryViabilityEnvFilter, InventoryViabilityEnvironment> {

	private static final long serialVersionUID = -7778450411892182148L;
	public NumberFilter<Integer> lightHours;
	public NumberFilter<Integer> nmWaveLenght;
	public NumberFilter<Integer> lightPotency;
	public NumberFilter<Integer> lightGrades;
	public NumberFilter<Integer> darkGrades;
	public Set<String> lightPotencyUnitCode;
	public Set<String> gradesUnitCode;
	public Set<String> equipmentCode;

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

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

		if (lightHours != null) {
			predicates.add(lightHours.buildQuery(environment.lightHours));
		}
		if (nmWaveLenght != null) {
			predicates.add(nmWaveLenght.buildQuery(environment.nmWaveLenght));
		}
		if (lightPotency != null) {
			predicates.add(lightPotency.buildQuery(environment.lightPotency));
		}
		if (lightGrades != null) {
			predicates.add(lightGrades.buildQuery(environment.lightGrades));
		}
		if (darkGrades != null) {
			predicates.add(darkGrades.buildQuery(environment.darkGrades));
		}
		if (CollectionUtils.isNotEmpty(lightPotencyUnitCode)) {
			predicates.add(environment.lightPotencyUnitCode.in(lightPotencyUnitCode));
		}
		if (CollectionUtils.isNotEmpty(gradesUnitCode)) {
			predicates.add(environment.gradesUnitCode.in(gradesUnitCode));
		}
		if (CollectionUtils.isNotEmpty(equipmentCode)) {
			predicates.add(environment.equipmentCode.in(equipmentCode));
		}

		return predicates;
	}
}