CooperatorAttachmentFilter.java
/*
* Copyright 2023 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 com.querydsl.core.types.dsl.EntityPathBase;
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.genesys.blocks.model.filters.TemporalFilter;
import org.genesys.filerepository.model.RepositoryFile;
import org.gringlobal.model.CooperatorAttachment;
import org.gringlobal.model.QCooperatorAttachment;
import java.util.Date;
import java.util.List;
import java.util.Set;
/**
* {@link CooperatorAttachment} match by sample filters.
*
* @param <T> the generic type
* @param <R> the generic type
*/
@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
@Accessors(fluent = true)
public abstract class CooperatorAttachmentFilter<T extends CooperatorAttachmentFilter<T, R, Q>, R extends CooperatorAttachment, Q extends EntityPathBase<R>> extends CooperatorOwnedModelFilter<T, R, Q> {
private static final long serialVersionUID = 6533500500863588278L;
/** The title. */
public StringFilter title;
/** The virtual path. */
public Set<String> virtualPath;
/** The thumbnail virtual path. */
public Set<String> thumbnailVirtualPath;
/** The content type. */
public Set<String> contentType;
/** Is web visible. */
public Boolean webVisible;
/** The sort order. */
public NumberFilter<Integer> sortOrder;
/** The note. */
public StringFilter note;
/** The {@link RepositoryFile} identifier. */
public Set<Long> repositoryFileId;
/** The attachment cooperator. */
public CooperatorFilter attachCooperator;
/** The attachment date. */
public TemporalFilter<Date> attachDate;
/** The attachment date code. */
public Set<String> attachDateCode;
/** The category code. */
public Set<String> categoryCode;
/** The copyright information. */
public StringFilter copyrightInformation;
/** The description. */
public StringFilter description;
/** The description code. */
public Set<String> descriptionCode;
/** Does it actually have a file? */
public Boolean hasFile;
protected List<Predicate> collectSuperPredicates(final Q instance, final QCooperatorAttachment cooperatorAttachment) {
List<Predicate> predicates = super.collectSuperPredicates(instance, cooperatorAttachment._super);
if (title != null) {
predicates.add(title.buildQuery(cooperatorAttachment.title));
}
if (CollectionUtils.isNotEmpty(virtualPath)) {
predicates.add(cooperatorAttachment.virtualPath.in(virtualPath));
}
if (CollectionUtils.isNotEmpty(thumbnailVirtualPath)) {
predicates.add(cooperatorAttachment.thumbnailVirtualPath.in(thumbnailVirtualPath));
}
if (CollectionUtils.isNotEmpty(contentType)) {
predicates.add(cooperatorAttachment.contentType.in(contentType));
}
if (webVisible != null) {
predicates.add(cooperatorAttachment.isWebVisible.eq(convertToString(webVisible)));
}
if (sortOrder != null) {
predicates.add(sortOrder.buildQuery(cooperatorAttachment.sortOrder));
}
if (note != null) {
predicates.add(note.buildQuery(cooperatorAttachment.note));
}
if (CollectionUtils.isNotEmpty(repositoryFileId)) {
predicates.add(cooperatorAttachment.repositoryFile().id.in(repositoryFileId));
}
if (hasFile != null) {
predicates.add(hasFile ? cooperatorAttachment.repositoryFile().isNotNull() : cooperatorAttachment.repositoryFile().isNull());
}
if (attachCooperator != null) {
predicates.add(attachCooperator.nestedPredicate(cooperatorAttachment.attachCooperator()));
}
if (attachDate != null) {
predicates.add(attachDate.buildQuery(cooperatorAttachment.attachDate));
}
if (CollectionUtils.isNotEmpty(attachDateCode)) {
predicates.add(cooperatorAttachment.attachDateCode.in(attachDateCode));
}
if (CollectionUtils.isNotEmpty(categoryCode)) {
predicates.add(cooperatorAttachment.categoryCode.in(categoryCode));
}
if (copyrightInformation != null) {
predicates.add(copyrightInformation.buildQuery(cooperatorAttachment.copyrightInformation));
}
if (description != null) {
predicates.add(description.buildQuery(cooperatorAttachment.description));
}
if (CollectionUtils.isNotEmpty(descriptionCode)) {
predicates.add(cooperatorAttachment.descriptionCode.in(descriptionCode));
}
return predicates;
}
}