Commit 71b046b7 authored by Matija Obreza's avatar Matija Obreza
Browse files

Filters updated to use JPA paths

parent 96d88513
......@@ -24,11 +24,9 @@ import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.model.filters.AuditedVersionedModelFilter;
import org.genesys.blocks.model.filters.StringFilter;
import org.genesys.common.model.QPartner;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import com.querydsl.jpa.JPAExpressions;
/**
* The Class DatasetFilter.
......@@ -46,6 +44,8 @@ public class DatasetFilter extends AuditedVersionedModelFilter {
/** The accession identifier. */
public AccessionIdentifierFilter accessionIdentifier;
public DescriptorFilter descriptor;
/** The title. */
public StringFilter title;
......@@ -78,11 +78,14 @@ public class DatasetFilter extends AuditedVersionedModelFilter {
and.and(description.buildQuery(dataset.description));
}
if (owner != null) {
and.and(dataset.owner.in(JPAExpressions.selectFrom(QPartner.partner).where(owner.buildQuery())));
and.and(owner.buildQuery(dataset.owner));
}
if (accessionIdentifier != null) {
and.and(accessionIdentifier.buildQuery(dataset.accessionIdentifiers));
}
if (descriptor != null) {
and.and(descriptor.buildQuery(dataset.descriptors.any()));
}
if (CollectionUtils.isNotEmpty(language)) {
and.and(dataset.language.in(language));
}
......
......@@ -25,6 +25,7 @@ import org.genesys.blocks.model.filters.AuditedVersionedModelFilter;
import org.genesys.blocks.model.filters.NumberFilter;
import org.genesys.blocks.model.filters.StringFilter;
import org.genesys.catalog.model.traits.Descriptor.Category;
import org.genesys.catalog.model.traits.QDescriptor;
import org.genesys.catalog.model.traits.QDescriptorList;
import org.genesys.common.model.QPartner;
......@@ -94,53 +95,57 @@ public class DescriptorFilter extends AuditedVersionedModelFilter {
* @return the predicate
*/
public Predicate buildQuery() {
return buildQuery(descriptor);
}
public Predicate buildQuery(QDescriptor descriptorPath) {
final BooleanBuilder and = new BooleanBuilder();
super.buildQuery(descriptor._super._super, and);
super.buildQuery(descriptorPath._super._super, and);
if ((crop != null) && !crop.isEmpty()) {
and.and(descriptor.crop.in(crop));
and.and(descriptorPath.crop.in(crop));
}
if ((category != null) && !category.isEmpty()) {
and.and(descriptor.category.in(category));
and.and(descriptorPath.category.in(category));
}
if (key != null) {
and.and(descriptor.key.eq(key));
and.and(descriptorPath.key.eq(key));
}
if ((publisher != null) && !publisher.isEmpty()) {
and.and(descriptor.publisher.in(publisher));
and.and(descriptorPath.publisher.in(publisher));
}
if (published != null) {
and.and(descriptor.published.eq(published));
and.and(descriptorPath.published.eq(published));
}
if (integerOnly != null) {
and.and(descriptor.integerOnly.eq(integerOnly));
and.and(descriptorPath.integerOnly.eq(integerOnly));
}
if (title != null) {
and.and(title.buildQuery(descriptor.title));
and.and(title.buildQuery(descriptorPath.title));
}
if (description != null) {
and.and(description.buildQuery(descriptor.description));
and.and(description.buildQuery(descriptorPath.description));
}
if (columnName != null) {
and.and(columnName.buildQuery(descriptor.columnName));
and.and(columnName.buildQuery(descriptorPath.columnName));
}
if ((uom != null) && !uom.isEmpty()) {
and.and(descriptor.uom.in(uom));
and.and(descriptorPath.uom.in(uom));
}
if (bibliographicCitation != null) {
and.and(bibliographicCitation.buildQuery(descriptor.bibliographicCitation));
and.and(bibliographicCitation.buildQuery(descriptorPath.bibliographicCitation));
}
if (owner != null) {
and.and(descriptor.owner.in(JPAExpressions.selectFrom(QPartner.partner).where(owner.buildQuery())));
and.and(descriptorPath.owner.in(JPAExpressions.selectFrom(QPartner.partner).where(owner.buildQuery())));
}
if (minValue != null) {
and.and(minValue.buildQuery(descriptor.minValue));
and.and(minValue.buildQuery(descriptorPath.minValue));
}
if (maxValue != null) {
and.and(maxValue.buildQuery(descriptor.maxValue));
and.and(maxValue.buildQuery(descriptorPath.maxValue));
}
if (list != null) {
and.and(descriptor.descriptorLists.any().in(JPAExpressions.selectFrom(QDescriptorList.descriptorList).where(list.buildQuery())));
and.and(descriptorPath.descriptorLists.any().in(JPAExpressions.selectFrom(QDescriptorList.descriptorList).where(list.buildQuery())));
}
if (StringUtils.isNotBlank(_text)) {
......@@ -148,14 +153,14 @@ public class DescriptorFilter extends AuditedVersionedModelFilter {
and.andAnyOf(
ArrayUtils.addAll(
FilterHelpers.equalsAny(_text,
descriptor.crop, descriptor.versionTag, descriptor.publisher,
descriptor.owner.shortName,
descriptor.descriptorLists.any().publisher, descriptor.descriptorLists.any().versionTag, descriptor.descriptorLists.any().crop
descriptorPath.crop, descriptorPath.versionTag, descriptorPath.publisher,
descriptorPath.owner.shortName,
descriptorPath.descriptorLists.any().publisher, descriptorPath.descriptorLists.any().versionTag, descriptorPath.descriptorLists.any().crop
),
FilterHelpers.containsAll(_text,
descriptor.title, descriptor.description, descriptor.bibliographicCitation,
descriptor.owner.name,
descriptor.descriptorLists.any().title
descriptorPath.title, descriptorPath.description, descriptorPath.bibliographicCitation,
descriptorPath.owner.name,
descriptorPath.descriptorLists.any().title
)
)
);
......@@ -164,4 +169,5 @@ public class DescriptorFilter extends AuditedVersionedModelFilter {
return and;
}
}
......@@ -23,11 +23,9 @@ import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.model.filters.AuditedVersionedModelFilter;
import org.genesys.blocks.model.filters.StringFilter;
import org.genesys.common.model.QPartner;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import com.querydsl.jpa.JPAExpressions;
/**
* The Class DescriptorListFilter.
......@@ -89,7 +87,7 @@ public class DescriptorListFilter extends AuditedVersionedModelFilter {
and.and(bibliographicCitation.buildQuery(descriptorList.bibliographicCitation));
}
if (owner != null) {
and.and(descriptorList.owner.in(JPAExpressions.selectFrom(QPartner.partner).where(owner.buildQuery())));
and.and(owner.buildQuery(descriptorList.owner));
}
if (StringUtils.isNotBlank(_text)) {
......
......@@ -22,6 +22,7 @@ import java.util.Set;
import org.apache.commons.collections4.CollectionUtils;
import org.genesys.blocks.model.filters.AuditedVersionedModelFilter;
import org.genesys.blocks.model.filters.StringFilter;
import org.genesys.common.model.QPartner;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
......@@ -51,20 +52,24 @@ public class PartnerFilter extends AuditedVersionedModelFilter {
* @return the predicate
*/
public Predicate buildQuery() {
return buildQuery(partner);
}
public Predicate buildQuery(QPartner partnerPath) {
final BooleanBuilder and = new BooleanBuilder();
super.buildQuery(partner._super._super, and);
super.buildQuery(partnerPath._super._super, and);
if (CollectionUtils.isNotEmpty(shortName)) {
and.and(partner.shortName.in(shortName));
and.and(partnerPath.shortName.in(shortName));
}
if (name != null) {
and.and(name.buildQuery(partner.name));
and.and(name.buildQuery(partnerPath.name));
}
if (description != null) {
and.and(description.buildQuery(partner.description));
and.and(description.buildQuery(partnerPath.description));
}
if (CollectionUtils.isNotEmpty(wiewsCodes)) {
and.and(partner.wiewsCodes.any().in(wiewsCodes));
and.and(partnerPath.wiewsCodes.any().in(wiewsCodes));
}
return and;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment