SourceDescriptorFilter.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 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.genesys.blocks.model.filters.StringFilter;
- import org.gringlobal.model.QSourceDescriptor;
- import org.gringlobal.model.SourceDescriptor;
- import org.gringlobal.model.SourceDescriptorLang;
- import java.util.List;
- import java.util.Set;
- /**
- * The Class SourceDescriptorFilter.
- */
- @Getter
- @Setter
- @EqualsAndHashCode(callSuper = true)
- @Accessors(fluent = true)
- public class SourceDescriptorFilter extends TranslatedEntityFilter<SourceDescriptorFilter, SourceDescriptor> implements IFullTextFilter {
- private static final long serialVersionUID = 6943037238215920110L;
- /** Any text. */
- public String _text;
- /** The categoryCode. */
- public Set<String> categoryCode;
- /** The codedName. */
- public Set<String> codedName;
- /** The dataTypeCode. */
- public Set<String> dataTypeCode;
- /** The description from {@link SourceDescriptorLang}. */
- public StringFilter description;
- /** The title from {@link SourceDescriptorLang}. */
- public StringFilter title;
- /** is coded. */
- public Boolean coded;
- /** The maxLength. */
- public NumberFilter<Integer> maxLength;
- /** The note. */
- public StringFilter note;
- /** The numericFormat. */
- public Set<String> numericFormat;
- /** The numericMaximum. */
- public NumberFilter<Double> numericMaximum;
- /** The numericMinimum. */
- public NumberFilter<Double> numericMinimum;
- /** The ontologyUrl. */
- public Set<String> ontologyUrl;
- /** The originalValueFormat. */
- public Set<String> originalValueFormat;
- /** The originalValueTypeCode. */
- public Set<String> originalValueTypeCode;
- @Override
- public List<Predicate> collectPredicates() {
- return collectPredicates(QSourceDescriptor.sourceDescriptor);
- }
- /**
- * Collect predicates.
- *
- * @param sourceDescriptor the source descriptor
- * @return the list
- */
- public List<Predicate> collectPredicates(QSourceDescriptor sourceDescriptor) {
- final List<Predicate> predicates = super.collectPredicates(sourceDescriptor);
- if (CollectionUtils.isNotEmpty(codedName)) {
- predicates.add(sourceDescriptor.codedName.in(codedName));
- }
- if (CollectionUtils.isNotEmpty(dataTypeCode)) {
- predicates.add(sourceDescriptor.dataTypeCode.in(dataTypeCode));
- }
- if (CollectionUtils.isNotEmpty(categoryCode)) {
- predicates.add(sourceDescriptor.categoryCode.in(categoryCode));
- }
- if (description != null) {
- predicates.add(description.buildQuery(sourceDescriptor.langs.any().description));
- }
- if (title != null) {
- predicates.add(title.buildQuery(sourceDescriptor.langs.any().title));
- }
- if (coded != null) {
- predicates.add(sourceDescriptor.isCoded.eq(convertToString(coded)));
- }
- if (maxLength != null) {
- predicates.add(maxLength.buildQuery(sourceDescriptor.maxLength));
- }
- if (note != null) {
- predicates.add(note.buildQuery(sourceDescriptor.note));
- }
- if (CollectionUtils.isNotEmpty(numericFormat)) {
- predicates.add(sourceDescriptor.numericFormat.in(numericFormat));
- }
- if (numericMaximum != null) {
- predicates.add(numericMaximum.buildQuery(sourceDescriptor.numericMaximum));
- }
- if (numericMinimum != null) {
- predicates.add(numericMinimum.buildQuery(sourceDescriptor.numericMaximum));
- }
- if (CollectionUtils.isNotEmpty(ontologyUrl)) {
- predicates.add(sourceDescriptor.ontologyUrl.in(ontologyUrl));
- }
- if (CollectionUtils.isNotEmpty(originalValueFormat)) {
- predicates.add(sourceDescriptor.originalValueFormat.in(originalValueFormat));
- }
- if (CollectionUtils.isNotEmpty(originalValueTypeCode)) {
- predicates.add(sourceDescriptor.originalValueTypeCode.in(originalValueTypeCode));
- }
- return predicates;
- }
- @Override
- public String get_text() {
- return _text;
- }
- }