LangModelFilter.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.genesys.server.service.filter;

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

import org.apache.commons.collections4.CollectionUtils;
import org.genesys.blocks.model.filters.AuditedVersionedModelFilter;
import org.genesys.server.model.impl.LangModel;
import org.genesys.server.model.impl.QLangModel;

import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.dsl.EntityPathBase;

public abstract class LangModelFilter<T extends LangModelFilter<T, R>, R extends LangModel<R, ?>> extends AuditedVersionedModelFilter<T, R> {

  	/** The created by. */
	public Set<Long> entityId;

	public Set<String> languageTag;

	/**
	 * Collects list of filter predicates
	 *
	 * @param instance the instance of Q-type of <em>R</em>
	 * @param auditedVersionedModel the audited versioned model
	 * @return list of predicates
	 */
	
	protected List<Predicate> collectPredicates(final EntityPathBase<R> instance, final QLangModel langModel) {
		List<Predicate> predicates = super.collectPredicates(instance, langModel._super);
		if (CollectionUtils.isNotEmpty(entityId)) {
			predicates.add(langModel.entity().id.in(entityId));
		}
		if (CollectionUtils.isNotEmpty(languageTag)) {
			predicates.add(langModel.languageTag.in(languageTag));
		}
    return predicates;
  }
}